From 213c7d153b06d3e1211d1cdeae1e4f7833cb89f7 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Sun, 31 Oct 2021 14:21:36 -0500 Subject: REFACTOR: refactor everything to gui.Node struct Signed-off-by: Jeff Carr --- doc.go | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 doc.go (limited to 'doc.go') diff --git a/doc.go b/doc.go new file mode 100644 index 0000000..2b324c9 --- /dev/null +++ b/doc.go @@ -0,0 +1,72 @@ +/* +Package wit/gui implements a abstraction layer for Go visual elements in +a cross platform way. Right now, this abstraction is built on top of +the GUI toolkit 'andlabs/ui' which does the cross platform support. + +A quick overview of the features, some general design guidelines +and principles for how this package should generally work: + + * GUI elements are stored in a tree of nodes + * When in doubt, it's ok to guess. We will return something close. + * It tries to make your code simple + +Quick Start + +This section demonstrates how to quickly get started with spew. See the +sections below for further details on formatting and configuration options. + +To dump a variable with full newlines, indentation, type, and pointer +information use Dump, Fdump, or Sdump: + + package main + + import ( + "git.wit.org/wit/gui" + ) + + func main() { + gui.Main(initGUI) + } + + // This initializes the first window + func initGUI() { + gui.Config.Title = "WIT GUI Window 1" + gui.Config.Width = 640 + gui.Config.Height = 480 + node1 := gui.NewWindow() + addDemoTab(node1, "A Simple Tab Demo") + } + + func addDemoTab(n *gui.Node, title string) { + newNode := n.AddTab(title, nil) + + groupNode1 := newNode.AddGroup("group 1") + groupNode1.AddComboBox("demoCombo2", "more 1", "more 2", "more 3") + } + +Configuration Options + +Configuration of the GUI is handled by fields in the ConfigType type. For +convenience, all of the top-level functions use a global state available +via the gui.Config global. + +The following configuration options are available: + * Width + When creating a new window, this is the width + + * Height + When creating a new window, this is the height + + * Debug + When 'true' log more output + +GUI Usage + +Errors + +Since it is possible for custom Stringer/error interfaces to panic, spew +detects them and handles them internally by printing the panic information +inline with the output. Since spew is intended to provide deep pretty printing +capabilities on structures, it intentionally does not return any errors. +*/ +package gui -- cgit v1.2.3 From ae7a69b636bc145745ed8e2b30ab2adba166be74 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Thu, 4 Nov 2021 00:12:48 -0500 Subject: PANIC: remove almost all panic()s Signed-off-by: Jeff Carr --- box.go | 3 --- button.go | 2 -- doc.go | 5 +---- entry.go | 1 - new-structs.go | 6 ++---- window.go | 17 ++++++++++------- 6 files changed, 13 insertions(+), 21 deletions(-) (limited to 'doc.go') diff --git a/box.go b/box.go index 5953f54..65a8d39 100644 --- a/box.go +++ b/box.go @@ -38,9 +38,6 @@ func (n *Node) AddComboBox(title string, s ...string) *Node { }) box.Append(ecbox, false) - - // newNode.Dump() - // panic("junk") return newNode } diff --git a/button.go b/button.go index c1c1c73..ef73f73 100644 --- a/button.go +++ b/button.go @@ -43,8 +43,6 @@ func (n *Node) AddButton(name string, custom func(*Node)) *Node { log.Println("gui.AppendButton() Button Clicked. Running custom()") custom(newNode) }) - // panic("AppendButton") - // time.Sleep(3 * time.Second) return newNode } diff --git a/doc.go b/doc.go index 2b324c9..3f8bc64 100644 --- a/doc.go +++ b/doc.go @@ -64,9 +64,6 @@ GUI Usage Errors -Since it is possible for custom Stringer/error interfaces to panic, spew -detects them and handles them internally by printing the panic information -inline with the output. Since spew is intended to provide deep pretty printing -capabilities on structures, it intentionally does not return any errors. +Not sure about errors yet. To early to document them. This is a work in progress. */ package gui diff --git a/entry.go b/entry.go index 05db849..d215cd2 100644 --- a/entry.go +++ b/entry.go @@ -14,7 +14,6 @@ func (n *Node) NewLabel(text string) *Node { // n.Append(ui.NewLabel(text), false) newNode := n.makeNode(text, 333, 334) newNode.Dump() - // panic("node.NewLabel()") n.Append(newNode) return newNode diff --git a/new-structs.go b/new-structs.go index 62f826c..65b964f 100644 --- a/new-structs.go +++ b/new-structs.go @@ -99,7 +99,7 @@ func (n *Node) Dump() { log.Println("gui.Node.Dump() uiButton = ", n.uiButton) log.Println("gui.Node.Dump() uiText = ", n.uiText) if (n.id == "") { - panic("gui.Node.Dump() id == nil") + log.Println("THIS SHOULD NOT HAPPEN: gui.Node.Dump() id == nil") } } @@ -228,10 +228,9 @@ func (n *Node) AddTabNode(title string) *Node { } if (newNode.uiTab != nil) { - log.Println("wit/gui/ AddTabNode() Something went wrong tab == nil") + log.Println("ERROR: wit/gui/ AddTabNode() Something went wrong tab == nil") // TODO: try to find the tab or window and make them if need be // newNode.uiTab.Append(title, b.UiBox) - panic("newNode.uiTab") } return newNode @@ -244,7 +243,6 @@ func (n *Node) AddHorizontalBreak() *Node { n.uiBox.Append(tmp, false) } else { n.Dump() - // panic("AddHorizontalBreak") return nil } return n diff --git a/window.go b/window.go index f22e614..eb39e87 100644 --- a/window.go +++ b/window.go @@ -42,9 +42,8 @@ func initNode(title string, x int, y int) *Node { node.id = id if (Data.NodeMap[title] != nil) { - log.Println("Duplicate window name =", title) + log.Println("ERROR: Duplicate window name =", title) // TODO: just change the 'title' to something unique - // panic(fmt.Sprintf("Duplicate window name = %s\n", title)) return Data.NodeMap[title] } Data.NodeMap[title] = &node @@ -91,11 +90,15 @@ func (n *Node) uiNewWindow(title string, x int, y int) { w.SetBorderless(false) f := Config.Exit w.OnClosing(func(*ui.Window) bool { - if (Config.Debug) { - log.Println("ui.Window().OnClosing()") - } + log.Println("RUNNING the ui.Window().OnClosing() function") if (f != nil) { f(n) + } else { + n.Dump() + log.Println("gui.uiWindow().OnClosing() NOT SURE WHAT TO DO HERE") + // TODO: always do this here? // by default delete the node? + name := n.Name + delete(Data.NodeMap, name) } return true }) @@ -136,7 +139,7 @@ func NewWindow() *Node { if (uiW != nil) { uiW.Show() } - panic("check here to see if window is really alive") + log.Println("PROBABLY BAD ERROR: check here to see if window is really alive") return Data.NodeMap[title] } @@ -156,7 +159,7 @@ func NewWindow() *Node { n.uiWindow = window if(n.uiWindow == nil) { - panic("node.uiWindow == nil. This should never happen") + log.Println("ERROR: node.uiWindow == nil. This should never happen") } return n } -- cgit v1.2.3