mirror of
https://github.com/jroimartin/gocui.git
synced 2025-04-24 13:48:51 +08:00
Merge pull request #40 from jesseduffield/add-title-prefix
This commit is contained in:
commit
fc7119a393
14
gui.go
14
gui.go
@ -1020,6 +1020,14 @@ func (g *Gui) drawTitle(v *View, fgColor, bgColor Attribute) error {
|
||||
}
|
||||
|
||||
tabs := v.Tabs
|
||||
prefix := v.TitlePrefix
|
||||
if prefix != "" {
|
||||
if len(v.FrameRunes) > 0 {
|
||||
prefix += string(v.FrameRunes[0])
|
||||
} else {
|
||||
prefix += "─"
|
||||
}
|
||||
}
|
||||
separator := " - "
|
||||
charIndex := 0
|
||||
currentTabStart := -1
|
||||
@ -1043,6 +1051,12 @@ func (g *Gui) drawTitle(v *View, fgColor, bgColor Attribute) error {
|
||||
str := strings.Join(tabs, separator)
|
||||
|
||||
x := v.x0 + 2
|
||||
for _, ch := range prefix {
|
||||
if err := g.SetRune(x, v.y0, ch, fgColor, bgColor); err != nil {
|
||||
return err
|
||||
}
|
||||
x += runewidth.RuneWidth(ch)
|
||||
}
|
||||
for i, ch := range str {
|
||||
if x < 0 {
|
||||
continue
|
||||
|
9
view.go
9
view.go
@ -122,6 +122,10 @@ type View struct {
|
||||
// If Frame is true, Title allows to configure a title for the view.
|
||||
Title string
|
||||
|
||||
// If non-empty, TitlePrefix is prepended to the title of a view regardless on
|
||||
// the the currently selected tab (if any.)
|
||||
TitlePrefix string
|
||||
|
||||
Tabs []string
|
||||
TabIndex int
|
||||
|
||||
@ -1348,7 +1352,10 @@ func (v *View) GetClickedTabIndex(x int) int {
|
||||
return 0
|
||||
}
|
||||
|
||||
charX := 1
|
||||
charX := len(v.TitlePrefix) + 1
|
||||
if v.TitlePrefix != "" {
|
||||
charX += 1
|
||||
}
|
||||
if x <= charX {
|
||||
return -1
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user