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

@ -17,7 +17,7 @@ type Widget struct {
func NewWidget() *Widget {
widget := Widget{
TextWidget: wtf.NewTextWidget(" 👽 BambooHR ", "bamboohr"),
TextWidget: wtf.NewTextWidget(" 👽 BambooHR ", "bamboohr", false),
}
return &widget

View File

@ -19,7 +19,7 @@ type Widget struct {
func NewWidget() *Widget {
widget := Widget{
TextWidget: wtf.NewTextWidget(" 🕗 World Clocks ", "clocks"),
TextWidget: wtf.NewTextWidget(" 🕗 World Clocks ", "clocks", false),
}
return &widget

View File

@ -19,7 +19,7 @@ type Widget struct {
func NewWidget() *Widget {
widget := Widget{
TextWidget: wtf.NewTextWidget(" 🍿 Calendar ", "gcal"),
TextWidget: wtf.NewTextWidget(" 🍿 Calendar ", "gcal", false),
}
return &widget

View File

@ -20,7 +20,7 @@ type Widget struct {
func NewWidget() *Widget {
widget := Widget{
TextWidget: wtf.NewTextWidget(" Git ", "git"),
TextWidget: wtf.NewTextWidget(" Git ", "git", true),
Idx: 0,
}

View File

@ -20,7 +20,7 @@ type Widget struct {
func NewWidget() *Widget {
widget := Widget{
TextWidget: wtf.NewTextWidget(" Github ", "github"),
TextWidget: wtf.NewTextWidget(" Github ", "github", true),
Idx: 0,
}

View File

@ -17,7 +17,7 @@ type Widget struct {
func NewWidget() *Widget {
widget := Widget{
TextWidget: wtf.NewTextWidget("JIRA", "jira"),
TextWidget: wtf.NewTextWidget("JIRA", "jira", false),
}
return &widget

View File

@ -18,7 +18,7 @@ type Widget struct {
func NewWidget() *Widget {
widget := Widget{
TextWidget: wtf.NewTextWidget(" New Relic ", "newrelic"),
TextWidget: wtf.NewTextWidget(" New Relic ", "newrelic", false),
}
return &widget

View File

@ -18,7 +18,7 @@ type Widget struct {
func NewWidget() *Widget {
widget := Widget{
TextWidget: wtf.NewTextWidget(" ⏰ OpsGenie ", "opsgenie"),
TextWidget: wtf.NewTextWidget(" ⏰ OpsGenie ", "opsgenie", false),
}
return &widget

View File

@ -17,7 +17,7 @@ type Widget struct {
func NewWidget() *Widget {
widget := Widget{
TextWidget: wtf.NewTextWidget(" 🤺 Security ", "security"),
TextWidget: wtf.NewTextWidget(" 🤺 Security ", "security", false),
}
return &widget

View File

@ -19,7 +19,7 @@ type Widget struct {
func NewWidget() *Widget {
widget := Widget{
TextWidget: wtf.NewTextWidget(" 🎉 Status ", "status"),
TextWidget: wtf.NewTextWidget(" 🎉 Status ", "status", false),
Current: 0,
}

View File

@ -20,7 +20,7 @@ type Widget struct {
func NewWidget(builtAt, version string) *Widget {
widget := Widget{
TextWidget: wtf.NewTextWidget(" System ", "system"),
TextWidget: wtf.NewTextWidget(" System ", "system", false),
BuiltAt: builtAt,
Version: version,
}

View File

@ -19,7 +19,7 @@ type Widget struct {
func NewWidget() *Widget {
widget := Widget{
TextWidget: wtf.NewTextWidget(" 📄 Text File ", "textfile"),
TextWidget: wtf.NewTextWidget(" 📄 Text File ", "textfile", true),
FilePath: Config.UString("wtf.mods.textfile.filename"),
}

View File

@ -23,7 +23,7 @@ type Widget struct {
func NewWidget() *Widget {
widget := Widget{
TextWidget: wtf.NewTextWidget(" 📝 Todo ", "todo"),
TextWidget: wtf.NewTextWidget(" 📝 Todo ", "todo", true),
FilePath: Config.UString("wtf.mods.todo.filename"),
list: &List{selected: -1},

View File

@ -25,7 +25,7 @@ type Widget struct {
// NewWidget creates and returns a new instance of the weather Widget.
func NewWidget() *Widget {
widget := Widget{
TextWidget: wtf.NewTextWidget(" Weather ", "weather"),
TextWidget: wtf.NewTextWidget(" Weather ", "weather", true),
APIKey: os.Getenv("WTF_OWM_API_KEY"),
Idx: 0,
}

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
}