Skip to content

Commit

Permalink
Todo modal shows up much faster now, looks better
Browse files Browse the repository at this point in the history
  • Loading branch information
senorprogrammer committed Oct 1, 2018
1 parent ad86b24 commit 1596871
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 16 deletions.
9 changes: 6 additions & 3 deletions todo/widget.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ func (widget *Widget) load() {
}

func (widget *Widget) newItem() {
form := widget.modalForm("New:", "")
form := widget.modalForm("New Todo:", "")

saveFctn := func() {
text := form.GetFormItem(0).(*tview.InputField).GetText()
Expand Down Expand Up @@ -252,12 +252,15 @@ func (widget *Widget) modalFocus(form *tview.Form) {
frame := widget.modalFrame(form)
widget.pages.AddPage("modal", frame, false, true)
widget.app.SetFocus(frame)
widget.app.Draw()
}

func (widget *Widget) modalForm(lbl, text string) *tview.Form {
form := tview.NewForm().
SetButtonsAlign(tview.AlignCenter).
SetButtonTextColor(tview.Styles.PrimaryTextColor)
SetFieldBackgroundColor(wtf.ColorFor(wtf.Config.UString("wtf.colors.background", "black")))

form.SetButtonsAlign(tview.AlignCenter).
SetButtonTextColor(wtf.ColorFor(wtf.Config.UString("wtf.colors.text", "white")))

form.AddInputField(lbl, text, 60, nil, nil)

Expand Down
4 changes: 2 additions & 2 deletions wtf/bargraph.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,9 @@ func (widget *BarGraph) UpdateRefreshedAt() {
func (widget *BarGraph) addView() {
view := tview.NewTextView()

view.SetBackgroundColor(colorFor(Config.UString("wtf.colors.background", "black")))
view.SetBackgroundColor(ColorFor(Config.UString("wtf.colors.background", "black")))
view.SetBorder(true)
view.SetBorderColor(colorFor(widget.BorderColor()))
view.SetBorderColor(ColorFor(widget.BorderColor()))
view.SetDynamicColors(true)
view.SetTitle(widget.Name)
view.SetWrap(false)
Expand Down
6 changes: 3 additions & 3 deletions wtf/colors.go
Original file line number Diff line number Diff line change
Expand Up @@ -421,16 +421,16 @@ func ASCIItoTviewColors(text string) string {
text, replaceWithHexColorString), `[::b]`), `[-]`)
}

/* -------------------- Unexported Functions -------------------- */

func colorFor(label string) tcell.Color {
func ColorFor(label string) tcell.Color {
if _, ok := colors[label]; ok {
return colors[label]
}

return tcell.ColorGreen
}

/* -------------------- Unexported Functions -------------------- */

func replaceWithHexColorString(substring string) string {
colorID, err := strconv.Atoi(strings.Trim(
strings.Split(substring, ";")[2], "m"))
Expand Down
2 changes: 1 addition & 1 deletion wtf/display.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func NewDisplay(widgets []Wtfable) *Display {
}

display.build(widgets)
display.Grid.SetBackgroundColor(colorFor(Config.UString("wtf.colors.background", "black")))
display.Grid.SetBackgroundColor(ColorFor(Config.UString("wtf.colors.background", "black")))

return &display
}
Expand Down
4 changes: 2 additions & 2 deletions wtf/focus_tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func (tracker *FocusTracker) blur(idx int) {
view := widget.TextView()
view.Blur()

view.SetBorderColor(colorFor(widget.BorderColor()))
view.SetBorderColor(ColorFor(widget.BorderColor()))
}

func (tracker *FocusTracker) decrement() {
Expand All @@ -133,7 +133,7 @@ func (tracker *FocusTracker) focus(idx int) {
}

view := widget.TextView()
view.SetBorderColor(colorFor(Config.UString("wtf.colors.border.focused", "gray")))
view.SetBorderColor(ColorFor(Config.UString("wtf.colors.border.focused", "gray")))

tracker.App.SetFocus(view)
tracker.App.Draw()
Expand Down
9 changes: 4 additions & 5 deletions wtf/text_widget.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,32 +96,31 @@ func (widget *TextWidget) TextView() *tview.TextView {

/* -------------------- Unexported Functions -------------------- */


func (widget *TextWidget) addView(app *tview.Application, configKey string) {
view := tview.NewTextView()

view.SetBackgroundColor(colorFor(
view.SetBackgroundColor(ColorFor(
Config.UString(fmt.Sprintf("wtf.mods.%s.colors.background", configKey),
Config.UString("wtf.colors.background", "black"),
),
))

view.SetTextColor(colorFor(
view.SetTextColor(ColorFor(
Config.UString(
fmt.Sprintf("wtf.mods.%s.colors.text", configKey),
Config.UString("wtf.colors.text", "white"),
),
))

view.SetTitleColor(colorFor(
view.SetTitleColor(ColorFor(
Config.UString(
fmt.Sprintf("wtf.mods.%s.colors.title", configKey),
Config.UString("wtf.colors.title", "white"),
),
))

view.SetBorder(true)
view.SetBorderColor(colorFor(widget.BorderColor()))
view.SetBorderColor(ColorFor(widget.BorderColor()))
view.SetChangedFunc(func() {
app.Draw()
})
Expand Down

0 comments on commit 1596871

Please sign in to comment.