Skip to content

Commit

Permalink
Use a different color for the title bar of the focused window
Browse files Browse the repository at this point in the history
  • Loading branch information
aarzilli committed Dec 14, 2018
1 parent aa087f1 commit 90d19e6
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 12 deletions.
18 changes: 13 additions & 5 deletions drawing.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,12 @@ func drawSymbol(out *command.Buffer, type_ label.SymbolType, content rect.Rect,
type drawableWindowHeader struct {
Header rect.Rect
Label rect.Rect
Hovered bool
Hovered bool // titlebar is hovered
Focused bool // window has focus
Title string

Dynamic bool
HeaderActive bool
HeaderActive bool // should display titlebar
Bounds rect.Rect
RowHeight int
LayoutWidth int
Expand Down Expand Up @@ -108,12 +109,19 @@ func (dwh *drawableWindowHeader) Draw(z *nstyle.Style, out *command.Buffer) {
var text textWidget

/* select correct header background and text color */
if dwh.Hovered {
switch {
case dwh.Focused:
background = &style.Header.Active
text.Text = style.Header.LabelActive
case dwh.Hovered:
background = &style.Header.Hover
text.Text = style.Header.LabelHover
default:
background = &style.Header.Normal
text.Text = style.Header.LabelNormal
}
if dwh.Hovered {
} else {
background = &style.Header.Active
text.Text = style.Header.LabelActive
}

/* draw header background */
Expand Down
6 changes: 3 additions & 3 deletions nucular.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,18 +301,17 @@ func panelBegin(ctx *context, win *Window, title string) {
layout.Height -= layout.FooterH

/* window header */
header_active := (win.idx != 0) && (win.flags&WindowTitle != 0)

var dwh drawableWindowHeader
dwh.Dynamic = layout.Flags&WindowDynamic != 0
dwh.Bounds = layout.Bounds
dwh.HeaderActive = header_active
dwh.HeaderActive = (win.idx != 0) && (win.flags&WindowTitle != 0)
dwh.LayoutWidth = layout.Width
dwh.Style = win.style()

var closeButton rect.Rect

if header_active {
if dwh.HeaderActive {
/* calculate header bounds */
dwh.Header.X = layout.Bounds.X
dwh.Header.Y = layout.Bounds.Y
Expand All @@ -331,6 +330,7 @@ func panelBegin(ctx *context, win *Window, title string) {
layout.Height -= layout.FooterH

dwh.Hovered = ctx.Input.Mouse.HoveringRect(dwh.Header)
dwh.Focused = win.toplevel()

/* window header title */
t := FontWidth(font, title)
Expand Down
12 changes: 8 additions & 4 deletions style/style.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ type ColorTable struct {
ColorText color.RGBA
ColorWindow color.RGBA
ColorHeader color.RGBA
ColorHeaderFocused color.RGBA
ColorBorder color.RGBA
ColorButton color.RGBA
ColorButtonHover color.RGBA
Expand Down Expand Up @@ -373,7 +374,7 @@ type Window struct {
MinSize image.Point
}

var defaultThemeTable = ColorTable{color.RGBA{175, 175, 175, 255}, color.RGBA{45, 45, 45, 255}, color.RGBA{40, 40, 40, 255}, color.RGBA{65, 65, 65, 255}, color.RGBA{50, 50, 50, 255}, color.RGBA{40, 40, 40, 255}, color.RGBA{35, 35, 35, 255}, color.RGBA{100, 100, 100, 255}, color.RGBA{120, 120, 120, 255}, color.RGBA{45, 45, 45, 255}, color.RGBA{45, 45, 45, 255}, color.RGBA{35, 35, 35, 255}, color.RGBA{38, 38, 38, 255}, color.RGBA{100, 100, 100, 255}, color.RGBA{120, 120, 120, 255}, color.RGBA{150, 150, 150, 255}, color.RGBA{38, 38, 38, 255}, color.RGBA{38, 38, 38, 255}, color.RGBA{175, 175, 175, 255}, color.RGBA{45, 45, 45, 255}, color.RGBA{120, 120, 120, 255}, color.RGBA{45, 45, 45, 255}, color.RGBA{255, 0, 0, 255}, color.RGBA{40, 40, 40, 255}, color.RGBA{100, 100, 100, 255}, color.RGBA{120, 120, 120, 255}, color.RGBA{150, 150, 150, 255}, color.RGBA{40, 40, 40, 255}}
var defaultThemeTable = ColorTable{color.RGBA{175, 175, 175, 255}, color.RGBA{45, 45, 45, 255}, color.RGBA{40, 40, 40, 255}, color.RGBA{40, 40, 40, 255}, color.RGBA{65, 65, 65, 255}, color.RGBA{50, 50, 50, 255}, color.RGBA{40, 40, 40, 255}, color.RGBA{35, 35, 35, 255}, color.RGBA{100, 100, 100, 255}, color.RGBA{120, 120, 120, 255}, color.RGBA{45, 45, 45, 255}, color.RGBA{45, 45, 45, 255}, color.RGBA{35, 35, 35, 255}, color.RGBA{38, 38, 38, 255}, color.RGBA{100, 100, 100, 255}, color.RGBA{120, 120, 120, 255}, color.RGBA{150, 150, 150, 255}, color.RGBA{38, 38, 38, 255}, color.RGBA{38, 38, 38, 255}, color.RGBA{175, 175, 175, 255}, color.RGBA{45, 45, 45, 255}, color.RGBA{120, 120, 120, 255}, color.RGBA{45, 45, 45, 255}, color.RGBA{255, 0, 0, 255}, color.RGBA{40, 40, 40, 255}, color.RGBA{100, 100, 100, 255}, color.RGBA{120, 120, 120, 255}, color.RGBA{150, 150, 150, 255}, color.RGBA{40, 40, 40, 255}}

func FromTable(table ColorTable, scaling float64) *Style {
var text *Text
Expand Down Expand Up @@ -808,7 +809,7 @@ func FromTable(table ColorTable, scaling float64) *Style {
win.Header.MaximizeSymbol = label.SymbolPlus
win.Header.Normal = MakeItemColor(table.ColorHeader)
win.Header.Hover = MakeItemColor(table.ColorHeader)
win.Header.Active = MakeItemColor(table.ColorHeader)
win.Header.Active = MakeItemColor(table.ColorHeaderFocused)
win.Header.LabelNormal = table.ColorText
win.Header.LabelHover = table.ColorText
win.Header.LabelActive = table.ColorText
Expand All @@ -822,7 +823,7 @@ func FromTable(table ColorTable, scaling float64) *Style {
*button = Button{}
button.Normal = MakeItemColor(table.ColorHeader)
button.Hover = MakeItemColor(table.ColorHeader)
button.Active = MakeItemColor(table.ColorHeader)
button.Active = MakeItemColor(table.ColorHeaderFocused)
button.BorderColor = color.RGBA{0, 0, 0, 0}
button.TextBackground = table.ColorHeader
button.TextNormal = table.ColorText
Expand All @@ -842,7 +843,7 @@ func FromTable(table ColorTable, scaling float64) *Style {
*button = Button{}
button.Normal = MakeItemColor(table.ColorHeader)
button.Hover = MakeItemColor(table.ColorHeader)
button.Active = MakeItemColor(table.ColorHeader)
button.Active = MakeItemColor(table.ColorHeaderFocused)
button.BorderColor = color.RGBA{0, 0, 0, 0}
button.TextBackground = table.ColorHeader
button.TextNormal = table.ColorText
Expand Down Expand Up @@ -934,6 +935,7 @@ var whiteThemeTable = ColorTable{
ColorText: color.RGBA{70, 70, 70, 255},
ColorWindow: color.RGBA{175, 175, 175, 255},
ColorHeader: color.RGBA{175, 175, 175, 255},
ColorHeaderFocused: color.RGBA{0xc3, 0x9a, 0x9a, 255},
ColorBorder: color.RGBA{0, 0, 0, 255},
ColorButton: color.RGBA{185, 185, 185, 255},
ColorButtonHover: color.RGBA{170, 170, 170, 255},
Expand Down Expand Up @@ -965,6 +967,7 @@ var redThemeTable = ColorTable{
ColorText: color.RGBA{190, 190, 190, 255},
ColorWindow: color.RGBA{30, 33, 40, 215},
ColorHeader: color.RGBA{181, 45, 69, 220},
ColorHeaderFocused: color.RGBA{0xb5, 0x0c, 0x2c, 0xdc},
ColorBorder: color.RGBA{51, 55, 67, 255},
ColorButton: color.RGBA{181, 45, 69, 255},
ColorButtonHover: color.RGBA{190, 50, 70, 255},
Expand Down Expand Up @@ -996,6 +999,7 @@ var darkThemeTable = ColorTable{
ColorText: color.RGBA{210, 210, 210, 255},
ColorWindow: color.RGBA{57, 67, 71, 255},
ColorHeader: color.RGBA{51, 51, 56, 220},
ColorHeaderFocused: color.RGBA{0x29, 0x29, 0x37, 0xdc},
ColorBorder: color.RGBA{46, 46, 46, 255},
ColorButton: color.RGBA{48, 83, 111, 255},
ColorButtonHover: color.RGBA{58, 93, 121, 255},
Expand Down

0 comments on commit 90d19e6

Please sign in to comment.