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

Widget#focus now a thing

Widgets can inform whether or not they should get tab focus.

Widgets that provide additional functionality should return true.

Widgets that have no extra capability should return false.

This allows the FocusTracker to only tab through and focus on widgets
for which it provides value.
This commit is contained in:
Chris Cummer
2018-04-28 23:41:51 -07:00
parent 42559c396d
commit 037c90db85
17 changed files with 39 additions and 21 deletions

View File

@@ -35,10 +35,10 @@ func (tracker *FocusTracker) Prev() {
tracker.focus(tracker.Idx)
}
/* -------------------- Exported Functions -------------------- */
/* -------------------- Unexported Functions -------------------- */
func (tracker *FocusTracker) blur(idx int) {
view := tracker.Widgets[idx].TextView()
view := tracker.focusable()[idx].TextView()
view.Blur()
view.SetBorderColor(ColorFor(Config.UString("wtf.colors.border.normal", "gray")))
}
@@ -47,20 +47,32 @@ func (tracker *FocusTracker) decrement() {
tracker.Idx = tracker.Idx - 1
if tracker.Idx < 0 {
tracker.Idx = len(tracker.Widgets) - 1
tracker.Idx = len(tracker.focusable()) - 1
}
}
func (tracker *FocusTracker) focus(idx int) {
view := tracker.Widgets[idx].TextView()
view := tracker.focusable()[idx].TextView()
tracker.App.SetFocus(view)
view.SetBorderColor(ColorFor(Config.UString("wtf.colors.border.focus", "gray")))
}
func (tracker *FocusTracker) focusable() []TextViewer {
focusable := []TextViewer{}
for _, widget := range tracker.Widgets {
if widget.Focusable() {
focusable = append(focusable, widget)
}
}
return focusable
}
func (tracker *FocusTracker) increment() {
tracker.Idx = tracker.Idx + 1
if tracker.Idx == len(tracker.Widgets) {
if tracker.Idx == len(tracker.focusable()) {
tracker.Idx = 0
}
}

View File

@@ -9,7 +9,7 @@ type TextViewer interface {
Enabler
Scheduler
//Refresh()
Focusable() bool
TextView() *tview.TextView
Top() int

View File

@@ -13,6 +13,7 @@ var Config *config.Config
type TextWidget struct {
enabled bool
focusable bool
Name string
RefreshedAt time.Time
RefreshInt int
@@ -21,9 +22,10 @@ type TextWidget struct {
Position
}
func NewTextWidget(name string, configKey string) TextWidget {
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{
@@ -49,6 +51,10 @@ func (widget *TextWidget) Enabled() bool {
return widget.enabled
}
func (widget *TextWidget) Focusable() bool {
return widget.focusable
}
func (widget *TextWidget) RefreshInterval() int {
return widget.RefreshInt
}