104 lines
2.8 KiB
Go
104 lines
2.8 KiB
Go
/*
|
|
Copyright © Brian Buller <brian@bullercodeworks.com>
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
in the Software without restriction, including without limitation the rights
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
all copies or substantial portions of the Software.
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
THE SOFTWARE.
|
|
*/
|
|
package main
|
|
|
|
import (
|
|
w "git.bullercodeworks.com/brian/tcell-widgets"
|
|
"github.com/gdamore/tcell"
|
|
)
|
|
|
|
type UiScreen struct {
|
|
ui *Ui
|
|
w, h int
|
|
|
|
widget w.Widget
|
|
ll *w.LinearLayout
|
|
log *w.Cli
|
|
alert *w.Alert
|
|
alertLayout *w.LinearLayout
|
|
|
|
widgets []w.Widget
|
|
cursor int
|
|
}
|
|
|
|
func (s *UiScreen) Init(ui *Ui) {
|
|
// Set up our log viewer
|
|
s.ui = ui
|
|
s.log = w.NewCli("log", ui.style)
|
|
|
|
s.ll = w.NewLinearLayout("top", ui.style)
|
|
s.ll.SetLogger(s.log.Log)
|
|
|
|
tf := w.NewTimeField("time-field", ui.style)
|
|
tf.SetLabel("Time")
|
|
s.ll.Add(tf)
|
|
ml := w.NewTopMenuLayout("menu", ui.style)
|
|
m := ml.Menu()
|
|
m.SetLabel("Widget Example")
|
|
ml.AddMenuItems(
|
|
m.CreateMenuItem("File", nil,
|
|
m.CreateMenuItem("Exit", func() bool {
|
|
ui.Exit()
|
|
return true
|
|
}),
|
|
),
|
|
)
|
|
ml.SetLogger(s.log.Log)
|
|
ml.SetWidget(s.ll)
|
|
|
|
ml.SetActive(true)
|
|
s.widget = ml
|
|
s.ll.Add(s.log)
|
|
|
|
// s.widgets = append(s.widgets, ml)
|
|
// s.widgets = append(s.widgets, s.log)
|
|
}
|
|
|
|
func (s *UiScreen) HandleResize(ev *tcell.EventResize) {
|
|
s.w, s.h = ev.Size()
|
|
s.widget.HandleResize(ev)
|
|
|
|
lgH := 20
|
|
s.log.SetPos(w.Coord{X: 0, Y: s.h - lgH - 1})
|
|
s.log.HandleResize(w.Coord{X: s.w, Y: lgH}.ResizeEvent())
|
|
}
|
|
|
|
func (s *UiScreen) HandleKey(ev *tcell.EventKey) bool {
|
|
if ev.Key() == tcell.KeyCtrlJ {
|
|
// Ctrl+J is the keypad 'Enter'
|
|
ev = tcell.NewEventKey(tcell.KeyEnter, 0, 0)
|
|
}
|
|
if ev.Key() == tcell.KeyF12 {
|
|
if s.ll.Contains(s.log) {
|
|
s.ll.Delete(s.log)
|
|
} else {
|
|
s.ll.Add(s.log)
|
|
}
|
|
}
|
|
return s.widget.HandleKey(ev)
|
|
}
|
|
func (s *UiScreen) HandleTime(ev *tcell.EventTime) {}
|
|
func (s *UiScreen) Draw() { s.widget.Draw(s.ui.tScreen) }
|
|
func (s *UiScreen) Log(txt string, args ...any) {}
|
|
|
|
func (s *UiScreen) Exit() {}
|