1
0
mirror of https://github.com/taigrr/wtf synced 2025-01-18 04:03:14 -08:00
wtf/view/text_widget.go
Chris Cummer d6208b4730 Add a focusable over-ride setting for widgets that are non-focusable by
default

For widgets that are non-focusable by default, you can now specify

    focusable: true

in their config to over-ride the default 'false' value.
2019-09-22 17:51:06 -07:00

57 lines
1.5 KiB
Go

package view
import (
"github.com/rivo/tview"
"github.com/wtfutil/wtf/cfg"
"github.com/wtfutil/wtf/wtf"
)
// TextWidget defines the data necessary to make a text widget
type TextWidget struct {
Base
View *tview.TextView
}
// NewTextWidget creates and returns an instance of TextWidget
func NewTextWidget(app *tview.Application, commonSettings *cfg.Common, defaultFocusable bool) TextWidget {
widget := TextWidget{
Base: NewBase(app, commonSettings, defaultFocusable),
}
widget.View = widget.createView(widget.bordered)
return widget
}
/* -------------------- Exported Functions -------------------- */
func (widget *TextWidget) TextView() *tview.TextView {
return widget.View
}
func (widget *TextWidget) Redraw(data func() (string, string, bool)) {
widget.app.QueueUpdateDraw(func() {
title, content, wrap := data()
widget.View.Clear()
widget.View.SetWrap(wrap)
widget.View.SetTitle(widget.ContextualTitle(title))
widget.View.SetText(content)
})
}
/* -------------------- Unexported Functions -------------------- */
func (widget *TextWidget) createView(bordered bool) *tview.TextView {
view := tview.NewTextView()
view.SetBackgroundColor(wtf.ColorFor(widget.commonSettings.Colors.Background))
view.SetBorder(bordered)
view.SetBorderColor(wtf.ColorFor(widget.BorderColor()))
view.SetDynamicColors(true)
view.SetTextColor(wtf.ColorFor(widget.commonSettings.Colors.Text))
view.SetTitleColor(wtf.ColorFor(widget.commonSettings.Colors.Title))
view.SetWrap(false)
return view
}