TabContainer & Theme fixes to better show focused state of TabContainer and MenuBar

This commit is contained in:
Luke I. Wilson
2021-04-07 21:06:36 -05:00
parent eb17dfec2e
commit cdeb3be359
4 changed files with 38 additions and 27 deletions

View File

@@ -89,23 +89,29 @@ func (c *TabContainer) GetTab(idx int) *Tab {
// Draw will draws the border of the BoxContainer, then it draws its child component.
func (c *TabContainer) Draw(s tcell.Screen) {
var styFocused tcell.Style
if c.focused {
styFocused = c.Theme.GetOrDefault("TabContainerFocused")
} else {
styFocused = c.Theme.GetOrDefault("TabContainer")
}
// Draw outline
DrawRectOutlineDefault(s, c.x, c.y, c.width, c.height, c.Theme.GetOrDefault("TabContainer"))
DrawRectOutlineDefault(s, c.x, c.y, c.width, c.height, styFocused)
combinedTabLength := 0
for _, tab := range c.children {
combinedTabLength += len(tab.Name) + 2 // 2 for padding
for i := range c.children {
combinedTabLength += len(c.children[i].Name) + 2 // 2 for padding
}
combinedTabLength += len(c.children) - 1 // add for spacing between tabs
// Draw tabs
col := c.x + c.width/2 - combinedTabLength/2 - 1 // Starting column
col := c.x + c.width/2 - combinedTabLength/2 // Starting column
for i, tab := range c.children {
var sty tcell.Style
sty := styFocused
if c.selected == i {
sty = c.Theme.GetOrDefault("TabSelected")
} else {
sty = c.Theme.GetOrDefault("Tab")
fg, bg, attr := styFocused.Decompose()
sty = tcell.Style{}.Foreground(bg).Background(fg).Attributes(attr)
}
var dirty bool
@@ -121,7 +127,7 @@ func (c *TabContainer) Draw(s tcell.Screen) {
str := fmt.Sprintf(" %s ", name)
DrawStr(s, c.x+col, c.y, str, sty)
DrawStr(s, col, c.y, str, sty)
col += len(str) + 1 // Add one for spacing between tabs
}