TabContainer & Theme fixes to better show focused state of TabContainer and MenuBar
This commit is contained in:
parent
eb17dfec2e
commit
cdeb3be359
2
main.go
2
main.go
@ -21,7 +21,7 @@ var (
|
||||
)
|
||||
|
||||
var theme = ui.Theme{
|
||||
"StatusBar": tcell.Style{}.Foreground(tcell.ColorBlack).Background(tcell.ColorSilver),
|
||||
"StatusBar": tcell.Style{}.Foreground(tcell.ColorBlack).Background(tcell.ColorLightGray),
|
||||
}
|
||||
|
||||
var (
|
||||
|
10
ui/menu.go
10
ui/menu.go
@ -152,7 +152,12 @@ func (b *MenuBar) CursorRight() {
|
||||
|
||||
// Draw renders the MenuBar and its sub-menus.
|
||||
func (b *MenuBar) Draw(s tcell.Screen) {
|
||||
normalStyle := b.Theme.GetOrDefault("MenuBar")
|
||||
var normalStyle tcell.Style
|
||||
if b.focused {
|
||||
normalStyle = b.Theme.GetOrDefault("MenuBarFocused")
|
||||
} else {
|
||||
normalStyle = b.Theme.GetOrDefault("MenuBar")
|
||||
}
|
||||
|
||||
// Draw menus based on whether b.focused and which is selected
|
||||
DrawRect(s, b.x, b.y, b.width, 1, ' ', normalStyle)
|
||||
@ -160,7 +165,8 @@ func (b *MenuBar) Draw(s tcell.Screen) {
|
||||
for i, item := range b.menus {
|
||||
sty := normalStyle
|
||||
if b.focused && b.selected == i {
|
||||
sty = b.Theme.GetOrDefault("MenuBarSelected") // Use special style for selected item
|
||||
fg, bg, attr := normalStyle.Decompose()
|
||||
sty = tcell.Style{}.Foreground(bg).Background(fg).Attributes(attr)
|
||||
}
|
||||
|
||||
str := fmt.Sprintf(" %s ", item.Name)
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
15
ui/theme.go
15
ui/theme.go
@ -30,18 +30,17 @@ func (theme *Theme) GetOrDefault(key string) tcell.Style {
|
||||
// DefaultTheme uses only the first 16 colors present in most colored terminals.
|
||||
var DefaultTheme = Theme{
|
||||
"Normal": tcell.Style{}.Foreground(tcell.ColorSilver).Background(tcell.ColorBlack),
|
||||
"Button": tcell.Style{}.Foreground(tcell.ColorBlack).Background(tcell.ColorWhite),
|
||||
"Button": tcell.Style{}.Foreground(tcell.ColorBlack).Background(tcell.ColorSilver),
|
||||
"InputField": tcell.Style{}.Foreground(tcell.ColorSilver).Background(tcell.ColorBlack),
|
||||
"MenuBar": tcell.Style{}.Foreground(tcell.ColorBlack).Background(tcell.ColorSilver),
|
||||
"MenuBarSelected": tcell.Style{}.Foreground(tcell.ColorSilver).Background(tcell.ColorBlack),
|
||||
"MenuBar": tcell.Style{}.Foreground(tcell.ColorBlack).Background(tcell.ColorDarkGray),
|
||||
"MenuBarFocused": tcell.Style{}.Foreground(tcell.ColorBlack).Background(tcell.ColorLightGray),
|
||||
"Menu": tcell.Style{}.Foreground(tcell.ColorBlack).Background(tcell.ColorSilver),
|
||||
"MenuSelected": tcell.Style{}.Foreground(tcell.ColorSilver).Background(tcell.ColorBlack),
|
||||
"Tab": tcell.Style{}.Foreground(tcell.ColorSilver).Background(tcell.ColorBlack),
|
||||
"TabContainer": tcell.Style{}.Foreground(tcell.ColorSilver).Background(tcell.ColorBlack),
|
||||
"TabSelected": tcell.Style{}.Foreground(tcell.ColorBlack).Background(tcell.ColorSilver),
|
||||
"TabContainer": tcell.Style{}.Foreground(tcell.ColorGray).Background(tcell.ColorBlack),
|
||||
"TabContainerFocused": tcell.Style{}.Foreground(tcell.ColorSilver).Background(tcell.ColorBlack),
|
||||
"TextEdit": tcell.Style{}.Foreground(tcell.ColorSilver).Background(tcell.ColorBlack),
|
||||
"TextEditColumn": tcell.Style{}.Foreground(tcell.ColorBlack).Background(tcell.ColorGray),
|
||||
"TextEditSelected": tcell.Style{}.Foreground(tcell.ColorBlack).Background(tcell.ColorSilver),
|
||||
"Window": tcell.Style{}.Foreground(tcell.ColorBlack).Background(tcell.ColorSilver),
|
||||
"WindowHeader": tcell.Style{}.Foreground(tcell.ColorBlack).Background(tcell.ColorWhite),
|
||||
"Window": tcell.Style{}.Foreground(tcell.ColorBlack).Background(tcell.ColorDarkGray),
|
||||
"WindowHeader": tcell.Style{}.Foreground(tcell.ColorBlack).Background(tcell.ColorSilver),
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user