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

Can focus/blur widgets (with focus border color)

This commit is contained in:
Chris Cummer
2018-04-17 04:03:02 -07:00
parent b335df6c9b
commit 912de2fa11
5 changed files with 122 additions and 24 deletions

View File

@@ -18,6 +18,7 @@ func CreateConfigDir() bool {
panic(err)
}
}
return true
}

60
wtf/focus_tracker.go Normal file
View File

@@ -0,0 +1,60 @@
package wtf
import (
"github.com/rivo/tview"
"github.com/senorprogrammer/wtf/color"
)
type FocusTracker struct {
App *tview.Application
Idx int
Widgets []TextViewer
}
/* -------------------- Exported Functions -------------------- */
func (tracker *FocusTracker) Next() {
tracker.blur(tracker.Idx)
tracker.increment()
tracker.focus(tracker.Idx)
}
func (tracker *FocusTracker) None() {
tracker.blur(tracker.Idx)
}
func (tracker *FocusTracker) Prev() {
tracker.blur(tracker.Idx)
tracker.decrement()
tracker.focus(tracker.Idx)
}
/* -------------------- Exported Functions -------------------- */
func (tracker *FocusTracker) blur(idx int) {
view := tracker.Widgets[idx].TextView()
view.Blur()
view.SetBorderColor(color.ColorFor(Config.UString("wtf.border.normal")))
}
func (tracker *FocusTracker) decrement() {
tracker.Idx = tracker.Idx - 1
if tracker.Idx < 0 {
tracker.Idx = len(tracker.Widgets) - 1
}
}
func (tracker *FocusTracker) focus(idx int) {
view := tracker.Widgets[idx].TextView()
tracker.App.SetFocus(view)
view.SetBorderColor(color.ColorFor(Config.UString("wtf.border.focus")))
}
func (tracker *FocusTracker) increment() {
tracker.Idx = tracker.Idx + 1
if tracker.Idx == len(tracker.Widgets) {
tracker.Idx = 0
}
}

View File

@@ -40,20 +40,20 @@ func NewTextWidget(name string, configKey string) TextWidget {
return widget
}
func (widget *TextWidget) addView() {
view := tview.NewTextView()
view.SetBorder(true)
view.SetBorderColor(color.ColorFor(Config.UString("wtf.border.normal")))
view.SetDynamicColors(true)
view.SetTitle(widget.Name)
view.SetWrap(false)
widget.View = view
}
/* -------------------- Exported Functions -------------------- */
//func (widget *TextWidget) SetBorder() {
//var colorName string
//if widget.View.HasFocus() {
//colorName = Config.UString("wtf.border.normal")
//} else {
//colorName = Config.UString("wtf.border.focus")
//}
//widget.View.SetBorderColor(color.ColorFor(colorName))
//}
func (widget *TextWidget) Disabled() bool {
return !widget.Enabled()
}
@@ -69,3 +69,18 @@ func (widget *TextWidget) RefreshInterval() int {
func (widget *TextWidget) TextView() *tview.TextView {
return widget.View
}
/* -------------------- Unexported Functions -------------------- */
func (widget *TextWidget) addView() {
view := tview.NewTextView()
view.SetBorder(true)
view.SetBorderColor(color.ColorFor(Config.UString("wtf.border.normal")))
view.SetDynamicColors(true)
view.SetTitle(widget.Name)
view.SetWrap(false)
widget.View = view
}