1
0
mirror of https://github.com/taigrr/wtf synced 2025-01-18 04:03:14 -08:00

Focusable widgets get their own border color

This commit is contained in:
Chris Cummer 2018-05-02 14:18:12 -07:00
parent 90ab57e1b2
commit 4727255df6
4 changed files with 43 additions and 28 deletions

View File

@ -5,29 +5,16 @@ import (
)
var Colors = map[string]tcell.Color{
"black": tcell.ColorBlack,
"maroon": tcell.ColorMaroon,
"green": tcell.ColorGreen,
"olive": tcell.ColorOlive,
"navy": tcell.ColorNavy,
"purple": tcell.ColorPurple,
"teal": tcell.ColorTeal,
"silver": tcell.ColorSilver,
"gray": tcell.ColorGray,
"red": tcell.ColorRed,
"lime": tcell.ColorLime,
"yellow": tcell.ColorYellow,
"blue": tcell.ColorBlue,
"fuchsia": tcell.ColorFuchsia,
"aqua": tcell.ColorAqua,
"white": tcell.ColorWhite,
"aliceblue": tcell.ColorAliceBlue,
"antiquewhite": tcell.ColorAntiqueWhite,
"aqua": tcell.ColorAqua,
"aquamarine": tcell.ColorAquaMarine,
"azure": tcell.ColorAzure,
"beige": tcell.ColorBeige,
"bisque": tcell.ColorBisque,
"black": tcell.ColorBlack,
"blanchedalmond": tcell.ColorBlanchedAlmond,
"blue": tcell.ColorBlue,
"blueviolet": tcell.ColorBlueViolet,
"brown": tcell.ColorBrown,
"burlywood": tcell.ColorBurlyWood,
@ -62,11 +49,15 @@ var Colors = map[string]tcell.Color{
"firebrick": tcell.ColorFireBrick,
"floralwhite": tcell.ColorFloralWhite,
"forestgreen": tcell.ColorForestGreen,
"fuchsia": tcell.ColorFuchsia,
"gainsboro": tcell.ColorGainsboro,
"ghostwhite": tcell.ColorGhostWhite,
"gold": tcell.ColorGold,
"goldenrod": tcell.ColorGoldenrod,
"gray": tcell.ColorGray,
"green": tcell.ColorGreen,
"greenyellow": tcell.ColorGreenYellow,
"grey": tcell.ColorGray,
"honeydew": tcell.ColorHoneydew,
"hotpink": tcell.ColorHotPink,
"indianred": tcell.ColorIndianRed,
@ -90,8 +81,10 @@ var Colors = map[string]tcell.Color{
"lightslategray": tcell.ColorLightSlateGray,
"lightsteelblue": tcell.ColorLightSteelBlue,
"lightyellow": tcell.ColorLightYellow,
"lime": tcell.ColorLime,
"limegreen": tcell.ColorLimeGreen,
"linen": tcell.ColorLinen,
"maroon": tcell.ColorMaroon,
"mediumaquamarine": tcell.ColorMediumAquamarine,
"mediumblue": tcell.ColorMediumBlue,
"mediumorchid": tcell.ColorMediumOrchid,
@ -106,7 +99,9 @@ var Colors = map[string]tcell.Color{
"mistyrose": tcell.ColorMistyRose,
"moccasin": tcell.ColorMoccasin,
"navajowhite": tcell.ColorNavajoWhite,
"navy": tcell.ColorNavy,
"oldlace": tcell.ColorOldLace,
"olive": tcell.ColorOlive,
"olivedrab": tcell.ColorOliveDrab,
"orange": tcell.ColorOrange,
"orangered": tcell.ColorOrangeRed,
@ -121,7 +116,9 @@ var Colors = map[string]tcell.Color{
"pink": tcell.ColorPink,
"plum": tcell.ColorPlum,
"powderblue": tcell.ColorPowderBlue,
"purple": tcell.ColorPurple,
"rebeccapurple": tcell.ColorRebeccaPurple,
"red": tcell.ColorRed,
"rosybrown": tcell.ColorRosyBrown,
"royalblue": tcell.ColorRoyalBlue,
"saddlebrown": tcell.ColorSaddleBrown,
@ -130,6 +127,7 @@ var Colors = map[string]tcell.Color{
"seagreen": tcell.ColorSeaGreen,
"seashell": tcell.ColorSeashell,
"sienna": tcell.ColorSienna,
"silver": tcell.ColorSilver,
"skyblue": tcell.ColorSkyblue,
"slateblue": tcell.ColorSlateBlue,
"slategray": tcell.ColorSlateGray,
@ -137,12 +135,15 @@ var Colors = map[string]tcell.Color{
"springgreen": tcell.ColorSpringGreen,
"steelblue": tcell.ColorSteelBlue,
"tan": tcell.ColorTan,
"teal": tcell.ColorTeal,
"thistle": tcell.ColorThistle,
"tomato": tcell.ColorTomato,
"turquoise": tcell.ColorTurquoise,
"violet": tcell.ColorViolet,
"wheat": tcell.ColorWheat,
"white": tcell.ColorWhite,
"whitesmoke": tcell.ColorWhiteSmoke,
"yellow": tcell.ColorYellow,
"yellowgreen": tcell.ColorYellowGreen,
}
@ -150,6 +151,6 @@ func ColorFor(label string) tcell.Color {
if _, ok := Colors[label]; ok {
return Colors[label]
} else {
return tcell.ColorBlue
return tcell.ColorGreen
}
}

View File

@ -42,13 +42,15 @@ func (tracker *FocusTracker) Refocus() {
/* -------------------- Unexported Functions -------------------- */
func (tracker *FocusTracker) blur(idx int) {
view := tracker.focusableAt(idx)
if view == nil {
widget := tracker.focusableAt(idx)
if widget == nil {
return
}
view := widget.TextView()
view.Blur()
view.SetBorderColor(ColorFor(Config.UString("wtf.colors.border.normal", "gray")))
view.SetBorderColor(ColorFor(widget.BorderColor()))
}
func (tracker *FocusTracker) decrement() {
@ -60,13 +62,15 @@ func (tracker *FocusTracker) decrement() {
}
func (tracker *FocusTracker) focus(idx int) {
view := tracker.focusableAt(idx)
if view == nil {
widget := tracker.focusableAt(idx)
if widget == nil {
return
}
view := widget.TextView()
tracker.App.SetFocus(view)
view.SetBorderColor(ColorFor(Config.UString("wtf.colors.border.focus", "gray")))
view.SetBorderColor(ColorFor(Config.UString("wtf.colors.border.focused", "gray")))
}
func (tracker *FocusTracker) focusables() []TextViewer {
@ -81,12 +85,12 @@ func (tracker *FocusTracker) focusables() []TextViewer {
return focusable
}
func (tracker *FocusTracker) focusableAt(idx int) *tview.TextView {
func (tracker *FocusTracker) focusableAt(idx int) TextViewer {
if idx < 0 || idx >= len(tracker.focusables()) {
return nil
}
return tracker.focusables()[idx].TextView()
return tracker.focusables()[idx]
}
func (tracker *FocusTracker) increment() {

View File

@ -9,6 +9,7 @@ type TextViewer interface {
Enabler
Scheduler
BorderColor() string
Focusable() bool
TextView() *tview.TextView

View File

@ -26,6 +26,7 @@ func NewTextWidget(name string, configKey string, focusable bool) TextWidget {
widget := TextWidget{
enabled: Config.UBool(fmt.Sprintf("wtf.mods.%s.enabled", configKey), false),
focusable: focusable,
Name: name,
RefreshInt: Config.UInt(fmt.Sprintf("wtf.mods.%s.refreshInterval", configKey)),
Position: Position{
@ -43,6 +44,14 @@ func NewTextWidget(name string, configKey string, focusable bool) TextWidget {
/* -------------------- Exported Functions -------------------- */
func (widget *TextWidget) BorderColor() string {
if widget.Focusable() {
return Config.UString("wtf.colors.border.focusable", "red")
}
return Config.UString("wtf.colors.border.normal", "gray")
}
func (widget *TextWidget) Disabled() bool {
return !widget.Enabled()
}
@ -69,7 +78,7 @@ func (widget *TextWidget) addView() {
view := tview.NewTextView()
view.SetBorder(true)
view.SetBorderColor(ColorFor(Config.UString("wtf.colors.border.normal")))
view.SetBorderColor(ColorFor(widget.BorderColor()))
view.SetDynamicColors(true)
view.SetTitle(widget.Name)
view.SetWrap(false)