Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions _examples/custom_frame.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ func layout(g *gocui.Gui) error {
}
v.Title = "v1"
v.Autoscroll = true
v.PaddingX = 1
fmt.Fprintln(v, "View with default frame color")
fmt.Fprintln(v, "It's connected to v2 with overlay RIGHT.\n")
if _, err = setCurrentViewOnTop(g, "v1"); err != nil {
Expand All @@ -66,6 +67,7 @@ func layout(g *gocui.Gui) error {
v.Wrap = true
v.FrameColor = gocui.ColorMagenta
v.FrameRunes = []rune{'═', '│'}
v.PaddingX = 1
fmt.Fprintln(v, "View with minimum frame customization and colored frame.")
fmt.Fprintln(v, "It's connected to v1 with overlay LEFT.\n")
fmt.Fprintln(v, "\033[35;1mInstructions:\033[0m")
Expand All @@ -83,6 +85,7 @@ func layout(g *gocui.Gui) error {
v.FrameColor = gocui.ColorCyan
v.TitleColor = gocui.ColorCyan
v.FrameRunes = []rune{'═', '║', '╔', '╗', '╚', '╝'}
v.PaddingX = 1
fmt.Fprintln(v, "View with basic frame customization and colored frame and title")
fmt.Fprintln(v, "It's not connected to any view.")
}
Expand All @@ -96,6 +99,7 @@ func layout(g *gocui.Gui) error {
v.TitleColor = gocui.ColorYellow
v.FrameColor = gocui.ColorRed
v.FrameRunes = []rune{'═', '║', '╔', '╗', '╚', '╝', '╠', '╣', '╦', '╩', '╬'}
v.PaddingX = 1
fmt.Fprintln(v, "View with fully customized frame and colored title differently.")
fmt.Fprintln(v, "It's connected to v3 with overlay LEFT.\n")
v.SetCursor(0, 3)
Expand Down
12 changes: 9 additions & 3 deletions view.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,12 @@ type View struct {
// []rune{'═','║','╔','╗','╚','╝','╠','╣','╦','╩','╬'}
FrameRunes []rune

// PaddingX specifies the horizontal padding (left and right) inside the frame.
PaddingX int

// PaddingY specifies the vertical padding (top and bottom) inside the frame.
PaddingY int

// If Wrap is true, the content that is written to this View is
// automatically wrapped when it is longer than its width. If true the
// view's x-origin will be ignored.
Expand Down Expand Up @@ -474,7 +480,7 @@ func (v *View) Height() int {
// view is made 1 larger on all sides. I'd like to clean this up at some point,
// but for now we live with this weirdness.
func (v *View) InnerWidth() int {
innerWidth := v.Width() - 2
innerWidth := v.Width() - 2 - 2*v.PaddingX
if innerWidth < 0 {
return 0
}
Expand All @@ -483,7 +489,7 @@ func (v *View) InnerWidth() int {
}

func (v *View) InnerHeight() int {
innerHeight := v.Height() - 2
innerHeight := v.Height() - 2 - 2*v.PaddingY
if innerHeight < 0 {
return 0
}
Expand Down Expand Up @@ -551,7 +557,7 @@ func (v *View) setCharacter(x, y int, ch string, fgColor, bgColor Attribute) {
ch = " "
}

tcellSetCell(v.x0+x+1, v.y0+y+1, ch, fgColor, bgColor, v.outMode)
tcellSetCell(v.x0+x+1+v.PaddingX, v.y0+y+1+v.PaddingY, ch, fgColor, bgColor, v.outMode)
}

// SetCursor sets the cursor position of the view at the given point,
Expand Down