2025-02-22 06:52:40 -06:00
|
|
|
// Copyright 2017-2025 WIT.COM Inc. All rights reserved.
|
|
|
|
// Use of this source code is governed by the GPL 3.0
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
2025-02-23 18:55:55 -06:00
|
|
|
// This model works for 99.9% of all windows
|
|
|
|
// This is the Default Standard Window Model
|
|
|
|
|
2025-02-22 06:52:40 -06:00
|
|
|
import (
|
|
|
|
"go.wit.com/lib/gadgets"
|
|
|
|
"go.wit.com/log"
|
|
|
|
|
|
|
|
"go.wit.com/gui"
|
|
|
|
)
|
|
|
|
|
2025-02-23 18:55:55 -06:00
|
|
|
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)
|
2025-02-22 06:52:40 -06:00
|
|
|
}
|
|
|
|
|
2025-02-23 18:55:55 -06:00
|
|
|
func (gw *GenericWindow) Hidden() bool {
|
|
|
|
if gw == nil {
|
2025-02-22 06:52:40 -06:00
|
|
|
return true
|
|
|
|
}
|
2025-02-23 18:55:55 -06:00
|
|
|
if gw.Win == nil {
|
2025-02-22 06:52:40 -06:00
|
|
|
return true
|
|
|
|
}
|
2025-02-23 18:55:55 -06:00
|
|
|
return gw.Win.Hidden()
|
2025-02-22 06:52:40 -06:00
|
|
|
}
|
|
|
|
|
2025-02-23 18:55:55 -06:00
|
|
|
func (gw *GenericWindow) Toggle() {
|
|
|
|
if gw.Hidden() {
|
|
|
|
gw.Show()
|
2025-02-22 06:52:40 -06:00
|
|
|
} else {
|
2025-02-23 18:55:55 -06:00
|
|
|
gw.Hide()
|
2025-02-22 06:52:40 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2025-02-23 18:55:55 -06:00
|
|
|
func (gw *GenericWindow) Show() {
|
|
|
|
if gw == nil {
|
2025-02-22 06:52:40 -06:00
|
|
|
return
|
|
|
|
}
|
2025-02-23 18:55:55 -06:00
|
|
|
if gw.Win == nil {
|
2025-02-22 06:52:40 -06:00
|
|
|
return
|
|
|
|
}
|
2025-02-23 18:55:55 -06:00
|
|
|
gw.Win.Show()
|
2025-02-22 06:52:40 -06:00
|
|
|
}
|
|
|
|
|
2025-02-23 18:55:55 -06:00
|
|
|
func (gw *GenericWindow) Hide() {
|
|
|
|
if gw == nil {
|
2025-02-22 06:52:40 -06:00
|
|
|
return
|
|
|
|
}
|
2025-02-23 18:55:55 -06:00
|
|
|
if gw.Win == nil {
|
2025-02-22 06:52:40 -06:00
|
|
|
return
|
|
|
|
}
|
2025-02-23 18:55:55 -06:00
|
|
|
gw.Win.Hide()
|
2025-02-22 06:52:40 -06:00
|
|
|
}
|
|
|
|
|
2025-02-23 18:55:55 -06:00
|
|
|
func (gw *GenericWindow) Disable() {
|
|
|
|
if gw == nil {
|
2025-02-22 06:52:40 -06:00
|
|
|
return
|
|
|
|
}
|
2025-02-23 18:55:55 -06:00
|
|
|
if gw.Shelf == nil {
|
2025-02-22 06:52:40 -06:00
|
|
|
return
|
|
|
|
}
|
2025-02-23 18:55:55 -06:00
|
|
|
gw.Shelf.Disable()
|
2025-02-22 06:52:40 -06:00
|
|
|
}
|
|
|
|
|
2025-02-23 18:55:55 -06:00
|
|
|
func (gw *GenericWindow) Enable() {
|
|
|
|
if gw == nil {
|
2025-02-22 06:52:40 -06:00
|
|
|
return
|
|
|
|
}
|
2025-02-23 18:55:55 -06:00
|
|
|
if gw.Shelf == nil {
|
2025-02-22 06:52:40 -06:00
|
|
|
return
|
|
|
|
}
|
2025-02-23 18:55:55 -06:00
|
|
|
gw.Shelf.Enable()
|
2025-02-22 06:52:40 -06:00
|
|
|
}
|
|
|
|
|
2025-02-23 18:55:55 -06:00
|
|
|
func NewGenericWindow(title string, grouptxt string) *GenericWindow {
|
|
|
|
gw := new(GenericWindow)
|
|
|
|
gw.Win = gadgets.RawBasicWindow(title)
|
|
|
|
gw.Win.Make()
|
2025-02-22 06:52:40 -06:00
|
|
|
|
2025-02-23 18:55:55 -06:00
|
|
|
gw.Win.Custom = func() {
|
2025-02-22 06:52:40 -06:00
|
|
|
log.Warn("Found Window close. setting hidden=true")
|
|
|
|
// sets the hidden flag to false so Toggle() works
|
2025-02-23 18:55:55 -06:00
|
|
|
gw.Win.Hide()
|
2025-02-22 06:52:40 -06:00
|
|
|
}
|
2025-02-23 18:55:55 -06:00
|
|
|
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)
|
|
|
|
|
2025-02-22 06:52:40 -06:00
|
|
|
gw.Show()
|
|
|
|
|
|
|
|
return gw
|
|
|
|
}
|