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:
parent
90ab57e1b2
commit
4727255df6
@ -5,29 +5,16 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var Colors = map[string]tcell.Color{
|
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,
|
"aliceblue": tcell.ColorAliceBlue,
|
||||||
"antiquewhite": tcell.ColorAntiqueWhite,
|
"antiquewhite": tcell.ColorAntiqueWhite,
|
||||||
|
"aqua": tcell.ColorAqua,
|
||||||
"aquamarine": tcell.ColorAquaMarine,
|
"aquamarine": tcell.ColorAquaMarine,
|
||||||
"azure": tcell.ColorAzure,
|
"azure": tcell.ColorAzure,
|
||||||
"beige": tcell.ColorBeige,
|
"beige": tcell.ColorBeige,
|
||||||
"bisque": tcell.ColorBisque,
|
"bisque": tcell.ColorBisque,
|
||||||
|
"black": tcell.ColorBlack,
|
||||||
"blanchedalmond": tcell.ColorBlanchedAlmond,
|
"blanchedalmond": tcell.ColorBlanchedAlmond,
|
||||||
|
"blue": tcell.ColorBlue,
|
||||||
"blueviolet": tcell.ColorBlueViolet,
|
"blueviolet": tcell.ColorBlueViolet,
|
||||||
"brown": tcell.ColorBrown,
|
"brown": tcell.ColorBrown,
|
||||||
"burlywood": tcell.ColorBurlyWood,
|
"burlywood": tcell.ColorBurlyWood,
|
||||||
@ -62,11 +49,15 @@ var Colors = map[string]tcell.Color{
|
|||||||
"firebrick": tcell.ColorFireBrick,
|
"firebrick": tcell.ColorFireBrick,
|
||||||
"floralwhite": tcell.ColorFloralWhite,
|
"floralwhite": tcell.ColorFloralWhite,
|
||||||
"forestgreen": tcell.ColorForestGreen,
|
"forestgreen": tcell.ColorForestGreen,
|
||||||
|
"fuchsia": tcell.ColorFuchsia,
|
||||||
"gainsboro": tcell.ColorGainsboro,
|
"gainsboro": tcell.ColorGainsboro,
|
||||||
"ghostwhite": tcell.ColorGhostWhite,
|
"ghostwhite": tcell.ColorGhostWhite,
|
||||||
"gold": tcell.ColorGold,
|
"gold": tcell.ColorGold,
|
||||||
"goldenrod": tcell.ColorGoldenrod,
|
"goldenrod": tcell.ColorGoldenrod,
|
||||||
|
"gray": tcell.ColorGray,
|
||||||
|
"green": tcell.ColorGreen,
|
||||||
"greenyellow": tcell.ColorGreenYellow,
|
"greenyellow": tcell.ColorGreenYellow,
|
||||||
|
"grey": tcell.ColorGray,
|
||||||
"honeydew": tcell.ColorHoneydew,
|
"honeydew": tcell.ColorHoneydew,
|
||||||
"hotpink": tcell.ColorHotPink,
|
"hotpink": tcell.ColorHotPink,
|
||||||
"indianred": tcell.ColorIndianRed,
|
"indianred": tcell.ColorIndianRed,
|
||||||
@ -90,8 +81,10 @@ var Colors = map[string]tcell.Color{
|
|||||||
"lightslategray": tcell.ColorLightSlateGray,
|
"lightslategray": tcell.ColorLightSlateGray,
|
||||||
"lightsteelblue": tcell.ColorLightSteelBlue,
|
"lightsteelblue": tcell.ColorLightSteelBlue,
|
||||||
"lightyellow": tcell.ColorLightYellow,
|
"lightyellow": tcell.ColorLightYellow,
|
||||||
|
"lime": tcell.ColorLime,
|
||||||
"limegreen": tcell.ColorLimeGreen,
|
"limegreen": tcell.ColorLimeGreen,
|
||||||
"linen": tcell.ColorLinen,
|
"linen": tcell.ColorLinen,
|
||||||
|
"maroon": tcell.ColorMaroon,
|
||||||
"mediumaquamarine": tcell.ColorMediumAquamarine,
|
"mediumaquamarine": tcell.ColorMediumAquamarine,
|
||||||
"mediumblue": tcell.ColorMediumBlue,
|
"mediumblue": tcell.ColorMediumBlue,
|
||||||
"mediumorchid": tcell.ColorMediumOrchid,
|
"mediumorchid": tcell.ColorMediumOrchid,
|
||||||
@ -106,7 +99,9 @@ var Colors = map[string]tcell.Color{
|
|||||||
"mistyrose": tcell.ColorMistyRose,
|
"mistyrose": tcell.ColorMistyRose,
|
||||||
"moccasin": tcell.ColorMoccasin,
|
"moccasin": tcell.ColorMoccasin,
|
||||||
"navajowhite": tcell.ColorNavajoWhite,
|
"navajowhite": tcell.ColorNavajoWhite,
|
||||||
|
"navy": tcell.ColorNavy,
|
||||||
"oldlace": tcell.ColorOldLace,
|
"oldlace": tcell.ColorOldLace,
|
||||||
|
"olive": tcell.ColorOlive,
|
||||||
"olivedrab": tcell.ColorOliveDrab,
|
"olivedrab": tcell.ColorOliveDrab,
|
||||||
"orange": tcell.ColorOrange,
|
"orange": tcell.ColorOrange,
|
||||||
"orangered": tcell.ColorOrangeRed,
|
"orangered": tcell.ColorOrangeRed,
|
||||||
@ -121,7 +116,9 @@ var Colors = map[string]tcell.Color{
|
|||||||
"pink": tcell.ColorPink,
|
"pink": tcell.ColorPink,
|
||||||
"plum": tcell.ColorPlum,
|
"plum": tcell.ColorPlum,
|
||||||
"powderblue": tcell.ColorPowderBlue,
|
"powderblue": tcell.ColorPowderBlue,
|
||||||
|
"purple": tcell.ColorPurple,
|
||||||
"rebeccapurple": tcell.ColorRebeccaPurple,
|
"rebeccapurple": tcell.ColorRebeccaPurple,
|
||||||
|
"red": tcell.ColorRed,
|
||||||
"rosybrown": tcell.ColorRosyBrown,
|
"rosybrown": tcell.ColorRosyBrown,
|
||||||
"royalblue": tcell.ColorRoyalBlue,
|
"royalblue": tcell.ColorRoyalBlue,
|
||||||
"saddlebrown": tcell.ColorSaddleBrown,
|
"saddlebrown": tcell.ColorSaddleBrown,
|
||||||
@ -130,6 +127,7 @@ var Colors = map[string]tcell.Color{
|
|||||||
"seagreen": tcell.ColorSeaGreen,
|
"seagreen": tcell.ColorSeaGreen,
|
||||||
"seashell": tcell.ColorSeashell,
|
"seashell": tcell.ColorSeashell,
|
||||||
"sienna": tcell.ColorSienna,
|
"sienna": tcell.ColorSienna,
|
||||||
|
"silver": tcell.ColorSilver,
|
||||||
"skyblue": tcell.ColorSkyblue,
|
"skyblue": tcell.ColorSkyblue,
|
||||||
"slateblue": tcell.ColorSlateBlue,
|
"slateblue": tcell.ColorSlateBlue,
|
||||||
"slategray": tcell.ColorSlateGray,
|
"slategray": tcell.ColorSlateGray,
|
||||||
@ -137,12 +135,15 @@ var Colors = map[string]tcell.Color{
|
|||||||
"springgreen": tcell.ColorSpringGreen,
|
"springgreen": tcell.ColorSpringGreen,
|
||||||
"steelblue": tcell.ColorSteelBlue,
|
"steelblue": tcell.ColorSteelBlue,
|
||||||
"tan": tcell.ColorTan,
|
"tan": tcell.ColorTan,
|
||||||
|
"teal": tcell.ColorTeal,
|
||||||
"thistle": tcell.ColorThistle,
|
"thistle": tcell.ColorThistle,
|
||||||
"tomato": tcell.ColorTomato,
|
"tomato": tcell.ColorTomato,
|
||||||
"turquoise": tcell.ColorTurquoise,
|
"turquoise": tcell.ColorTurquoise,
|
||||||
"violet": tcell.ColorViolet,
|
"violet": tcell.ColorViolet,
|
||||||
"wheat": tcell.ColorWheat,
|
"wheat": tcell.ColorWheat,
|
||||||
|
"white": tcell.ColorWhite,
|
||||||
"whitesmoke": tcell.ColorWhiteSmoke,
|
"whitesmoke": tcell.ColorWhiteSmoke,
|
||||||
|
"yellow": tcell.ColorYellow,
|
||||||
"yellowgreen": tcell.ColorYellowGreen,
|
"yellowgreen": tcell.ColorYellowGreen,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -150,6 +151,6 @@ func ColorFor(label string) tcell.Color {
|
|||||||
if _, ok := Colors[label]; ok {
|
if _, ok := Colors[label]; ok {
|
||||||
return Colors[label]
|
return Colors[label]
|
||||||
} else {
|
} else {
|
||||||
return tcell.ColorBlue
|
return tcell.ColorGreen
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -42,13 +42,15 @@ func (tracker *FocusTracker) Refocus() {
|
|||||||
/* -------------------- Unexported Functions -------------------- */
|
/* -------------------- Unexported Functions -------------------- */
|
||||||
|
|
||||||
func (tracker *FocusTracker) blur(idx int) {
|
func (tracker *FocusTracker) blur(idx int) {
|
||||||
view := tracker.focusableAt(idx)
|
widget := tracker.focusableAt(idx)
|
||||||
if view == nil {
|
if widget == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
view := widget.TextView()
|
||||||
view.Blur()
|
view.Blur()
|
||||||
view.SetBorderColor(ColorFor(Config.UString("wtf.colors.border.normal", "gray")))
|
|
||||||
|
view.SetBorderColor(ColorFor(widget.BorderColor()))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (tracker *FocusTracker) decrement() {
|
func (tracker *FocusTracker) decrement() {
|
||||||
@ -60,13 +62,15 @@ func (tracker *FocusTracker) decrement() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (tracker *FocusTracker) focus(idx int) {
|
func (tracker *FocusTracker) focus(idx int) {
|
||||||
view := tracker.focusableAt(idx)
|
widget := tracker.focusableAt(idx)
|
||||||
if view == nil {
|
if widget == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
view := widget.TextView()
|
||||||
|
|
||||||
tracker.App.SetFocus(view)
|
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 {
|
func (tracker *FocusTracker) focusables() []TextViewer {
|
||||||
@ -81,12 +85,12 @@ func (tracker *FocusTracker) focusables() []TextViewer {
|
|||||||
return focusable
|
return focusable
|
||||||
}
|
}
|
||||||
|
|
||||||
func (tracker *FocusTracker) focusableAt(idx int) *tview.TextView {
|
func (tracker *FocusTracker) focusableAt(idx int) TextViewer {
|
||||||
if idx < 0 || idx >= len(tracker.focusables()) {
|
if idx < 0 || idx >= len(tracker.focusables()) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return tracker.focusables()[idx].TextView()
|
return tracker.focusables()[idx]
|
||||||
}
|
}
|
||||||
|
|
||||||
func (tracker *FocusTracker) increment() {
|
func (tracker *FocusTracker) increment() {
|
||||||
|
@ -9,6 +9,7 @@ type TextViewer interface {
|
|||||||
Enabler
|
Enabler
|
||||||
Scheduler
|
Scheduler
|
||||||
|
|
||||||
|
BorderColor() string
|
||||||
Focusable() bool
|
Focusable() bool
|
||||||
TextView() *tview.TextView
|
TextView() *tview.TextView
|
||||||
|
|
||||||
|
@ -26,6 +26,7 @@ func NewTextWidget(name string, configKey string, focusable bool) TextWidget {
|
|||||||
widget := TextWidget{
|
widget := TextWidget{
|
||||||
enabled: Config.UBool(fmt.Sprintf("wtf.mods.%s.enabled", configKey), false),
|
enabled: Config.UBool(fmt.Sprintf("wtf.mods.%s.enabled", configKey), false),
|
||||||
focusable: focusable,
|
focusable: focusable,
|
||||||
|
|
||||||
Name: name,
|
Name: name,
|
||||||
RefreshInt: Config.UInt(fmt.Sprintf("wtf.mods.%s.refreshInterval", configKey)),
|
RefreshInt: Config.UInt(fmt.Sprintf("wtf.mods.%s.refreshInterval", configKey)),
|
||||||
Position: Position{
|
Position: Position{
|
||||||
@ -43,6 +44,14 @@ func NewTextWidget(name string, configKey string, focusable bool) TextWidget {
|
|||||||
|
|
||||||
/* -------------------- Exported Functions -------------------- */
|
/* -------------------- 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 {
|
func (widget *TextWidget) Disabled() bool {
|
||||||
return !widget.Enabled()
|
return !widget.Enabled()
|
||||||
}
|
}
|
||||||
@ -69,7 +78,7 @@ func (widget *TextWidget) addView() {
|
|||||||
view := tview.NewTextView()
|
view := tview.NewTextView()
|
||||||
|
|
||||||
view.SetBorder(true)
|
view.SetBorder(true)
|
||||||
view.SetBorderColor(ColorFor(Config.UString("wtf.colors.border.normal")))
|
view.SetBorderColor(ColorFor(widget.BorderColor()))
|
||||||
view.SetDynamicColors(true)
|
view.SetDynamicColors(true)
|
||||||
view.SetTitle(widget.Name)
|
view.SetTitle(widget.Name)
|
||||||
view.SetWrap(false)
|
view.SetWrap(false)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user