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

View File

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