add GenericWindow()

This commit is contained in:
Jeff Carr 2025-02-23 01:36:42 -06:00
parent 69b0d4c013
commit 3a62f10d20
2 changed files with 69 additions and 79 deletions

View File

@ -51,7 +51,7 @@ func drawWindow(win *gadgets.BasicWindow) {
group1 := vbox.NewGroup("Zookeeper Settings") group1 := vbox.NewGroup("Zookeeper Settings")
grid := group1.NewGrid("buildOptions", 0, 0) grid := group1.NewGrid("buildOptions", 0, 0)
var hyperWin *genericWindow var hyperWin *GenericWindow
grid.NewButton("hypervisors", func() { grid.NewButton("hypervisors", func() {
if hyperWin != nil { if hyperWin != nil {
hyperWin.Toggle() hyperWin.Toggle()
@ -60,7 +60,7 @@ func drawWindow(win *gadgets.BasicWindow) {
hyperWin = makeHypervisorsWindow(me.cluster.H) hyperWin = makeHypervisorsWindow(me.cluster.H)
}) })
var testWin *genericWindow var testWin *GenericWindow
grid.NewButton("all defined droplets", func() { grid.NewButton("all defined droplets", func() {
if testWin != nil { if testWin != nil {
testWin.Toggle() testWin.Toggle()
@ -86,7 +86,7 @@ func drawWindow(win *gadgets.BasicWindow) {
}) })
/* /*
var test2 *genericWindow var test2 *GenericWindow
grid.NewButton("test2", func() { grid.NewButton("test2", func() {
if test2 != nil { if test2 != nil {
test2.Toggle() test2.Toggle()
@ -105,27 +105,17 @@ func findVersion(m *zoopb.Machine, pkgname string) string {
return zood.Version return zood.Version
} }
func makeDropletsWindow(pb *virtpb.Droplets) *genericWindow { func makeDropletsWindow(pb *virtpb.Droplets) *GenericWindow {
win := initGenericWindow("Droplets registered with Virtigo", "Buttons of things") win := NewGenericWindow("Droplets registered with Virtigo", "Buttons of things")
grid := win.group.RawGrid() grid := win.Group.RawGrid()
grid.NewButton("List", func() { grid.NewButton("Create", func() {
log.Info("list...") log.Info("todo: open create window here")
}) })
grid.NewButton("more", func() { grid.NewButton("Show All", func() {
log.Info("?") log.Info("todo")
})
grid.NextRow()
grid.NewButton("2nd row", func() {
log.Info("smore")
})
win.middle.NewButton("middle", func() {
log.Info("smore")
})
win.middle.NewButton("middle", func() {
log.Info("smore")
}) })
tbox := win.bottom.Box() // a vertical box (like a stack of books) tbox := win.Bottom.Box()
t := pb.NewTable("test 2") t := pb.NewTable("test 2")
t.SetParent(tbox) t.SetParent(tbox)
t.AddHostname() t.AddHostname()
@ -135,6 +125,9 @@ func makeDropletsWindow(pb *virtpb.Droplets) *genericWindow {
if d.Current.State == virtpb.DropletState_ON { if d.Current.State == virtpb.DropletState_ON {
return "ON" return "ON"
} }
if d.Current.State == virtpb.DropletState_OFF {
return "OFF"
}
return "UNKNOWN" return "UNKNOWN"
}) })
/* /*
@ -149,21 +142,14 @@ func makeDropletsWindow(pb *virtpb.Droplets) *genericWindow {
return win return win
} }
func makeHypervisorsWindow(pb *virtpb.Hypervisors) *genericWindow { func makeHypervisorsWindow(pb *virtpb.Hypervisors) *GenericWindow {
win := initGenericWindow("Hypervisors registered with Virtigo", "Buttons of things") win := NewGenericWindow("Hypervisors registered with Virtigo", "Buttons of things")
grid := win.group.RawGrid() grid := win.Group.RawGrid()
grid.NewButton("List", func() { grid.NewButton("List", func() {
log.Info("list...") log.Info("list...")
}) })
grid.NewButton("more", func() {
log.Info("?")
})
grid.NextRow()
grid.NewButton("smore", func() {
log.Info("smore")
})
tbox := win.bottom.Box() // a vertical box (like a stack of books) tbox := win.Bottom.Box() // a vertical box (like a stack of books)
t := pb.NewTable("test 2") t := pb.NewTable("test 2")
t.SetParent(tbox) t.SetParent(tbox)
t.AddHostname() t.AddHostname()

View File

@ -3,6 +3,9 @@
package main package main
// This model works for 99.9% of all windows
// This is the Default Standard Window Model
import ( import (
"go.wit.com/lib/gadgets" "go.wit.com/lib/gadgets"
"go.wit.com/log" "go.wit.com/log"
@ -10,93 +13,94 @@ import (
"go.wit.com/gui" "go.wit.com/gui"
) )
type genericWindow struct { type GenericWindow struct {
win *gadgets.BasicWindow // the window widget itself Win *gadgets.BasicWindow // the window widget itself
box *gui.Node // the overall shelf Shelf *gui.Node // the overall box: the shelf
shelf *gui.Node // the overall shelf Stack *gui.Node // the first box is a stack
stack *gui.Node // the first box is a shelf Top *gui.Node // the first item in the stack is always a shelf like box
top *gui.Node // the first item in the stack is always a box Group *gui.Node // the first item top box is always a group
group *gui.Node // the first item top box is always a group Middle *gui.Node // the middle box (shelf style)
middle *gui.Node // the middle box Bottom *gui.Node // the bottom box (stack style)
bottom *gui.Node // the bottom box of the repolist window
} }
func (r *genericWindow) Hidden() bool { func (gw *GenericWindow) Hidden() bool {
if r == nil { if gw == nil {
return true return true
} }
if r.win == nil { if gw.Win == nil {
return true return true
} }
return r.win.Hidden() return gw.Win.Hidden()
} }
func (r *genericWindow) Toggle() { func (gw *GenericWindow) Toggle() {
if r.Hidden() { if gw.Hidden() {
r.Show() gw.Show()
} else { } else {
r.Hide() gw.Hide()
} }
} }
func (r *genericWindow) Show() { func (gw *GenericWindow) Show() {
if r == nil { if gw == nil {
return return
} }
if r.win == nil { if gw.Win == nil {
return return
} }
r.win.Show() gw.Win.Show()
} }
func (r *genericWindow) Hide() { func (gw *GenericWindow) Hide() {
if r == nil { if gw == nil {
return return
} }
if r.win == nil { if gw.Win == nil {
return return
} }
r.win.Hide() gw.Win.Hide()
} }
func (r *genericWindow) Disable() { func (gw *GenericWindow) Disable() {
if r == nil { if gw == nil {
return return
} }
if r.box == nil { if gw.Shelf == nil {
return return
} }
r.box.Disable() gw.Shelf.Disable()
} }
func (r *genericWindow) Enable() { func (gw *GenericWindow) Enable() {
if r == nil { if gw == nil {
return return
} }
if r.box == nil { if gw.Shelf == nil {
return return
} }
r.box.Enable() gw.Shelf.Enable()
} }
func initGenericWindow(title string, grouptxt string) *genericWindow { func NewGenericWindow(title string, grouptxt string) *GenericWindow {
gw := new(genericWindow) gw := new(GenericWindow)
gw.win = gadgets.RawBasicWindow(title) gw.Win = gadgets.RawBasicWindow(title)
gw.win.Make() gw.Win.Make()
gw.win.Custom = func() { gw.Win.Custom = func() {
log.Warn("Found Window close. setting hidden=true") log.Warn("Found Window close. setting hidden=true")
// sets the hidden flag to false so Toggle() works // sets the hidden flag to false so Toggle() works
gw.win.Hide() gw.Win.Hide()
} }
gw.box = gw.win.Box() gw.Shelf = gw.Win.Box()
gw.shelf = gw.box // gw.Shelf.Vertical().SetProgName("ShelfBox")
gw.stack = gw.shelf.NewVerticalBox("STACKBOX") // a vertical box (like a stack of books) gw.Stack = gw.Shelf.NewVerticalBox("Stackbox")
gw.top = gw.stack.Box()
gw.group = gw.top.NewGroup(grouptxt) gw.Top = gw.Stack.NewVerticalBox("Stackbox")
gw.middle = gw.stack.Box() gw.Middle = gw.Stack.Box()
gw.middle.Vertical() gw.Bottom = gw.Stack.Box()
gw.bottom = gw.stack.Box()
gw.Group = gw.Top.NewGroup(grouptxt)
gw.Show() gw.Show()
return gw return gw