From 38a4e969beda577f282f98749fbef28e1bf83971 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Wed, 3 Jan 2024 18:38:53 -0600 Subject: [PATCH] move widget.go in this archive Signed-off-by: Jeff Carr --- andlabs/action.go | 2 +- andlabs/add.go | 2 +- andlabs/debug.go | 2 +- andlabs/delete.go | 2 +- andlabs/dropdown.go | 2 +- andlabs/main.go | 2 +- andlabs/setText.go | 2 +- andlabs/tab.go | 2 +- andlabs/widget.go | 2 +- gocui/add.go | 2 +- gocui/checkbox.go | 2 +- gocui/click.go | 2 +- gocui/debug.go | 2 +- gocui/keybindings.go | 2 +- gocui/main.go | 2 +- gocui/place.go | 2 +- gocui/plugin.go | 2 +- gocui/showStdout.go | 2 +- gocui/tab.go | 2 +- gocui/view.go | 2 +- gocui/widget.go | 2 +- nocui/action.go | 2 +- nocui/common.go | 2 +- nocui/event.go | 2 +- nocui/main.go | 2 +- nocui/stdin.go | 2 +- nocui/widget.go | 2 +- widget.go | 204 +++++++++++++++++++++++++++++++++++++++++++ 28 files changed, 231 insertions(+), 27 deletions(-) create mode 100644 widget.go diff --git a/andlabs/action.go b/andlabs/action.go index 82acd58..aedd8ae 100644 --- a/andlabs/action.go +++ b/andlabs/action.go @@ -3,7 +3,7 @@ package main import ( "strconv" "github.com/andlabs/ui" - "go.wit.com/gui/gui/toolkit" + "go.wit.com/gui/toolkits" ) func (n *node) show(b bool) { diff --git a/andlabs/add.go b/andlabs/add.go index d78101f..a402955 100644 --- a/andlabs/add.go +++ b/andlabs/add.go @@ -4,7 +4,7 @@ import ( "github.com/andlabs/ui" _ "github.com/andlabs/ui/winmanifest" - "go.wit.com/gui/gui/toolkit" + "go.wit.com/gui/toolkits" ) func actionDump(b bool, a *toolkit.Action) { diff --git a/andlabs/debug.go b/andlabs/debug.go index c2ab2a2..5e28dd0 100644 --- a/andlabs/debug.go +++ b/andlabs/debug.go @@ -2,7 +2,7 @@ package main import ( "strconv" - "go.wit.com/gui/gui/toolkit" + "go.wit.com/gui/toolkits" ) var defaultBehavior bool = true diff --git a/andlabs/delete.go b/andlabs/delete.go index 591d75e..7b6c2da 100644 --- a/andlabs/delete.go +++ b/andlabs/delete.go @@ -2,7 +2,7 @@ package main // if you include more than just this import // then your plugin might be doing something un-ideal (just a guess from 2023/02/27) -import "go.wit.com/gui/gui/toolkit" +import "go.wit.com/gui/toolkits" // delete the child widget from the parent // p = parent, c = child diff --git a/andlabs/dropdown.go b/andlabs/dropdown.go index 89cbf1a..c7a11e2 100644 --- a/andlabs/dropdown.go +++ b/andlabs/dropdown.go @@ -4,7 +4,7 @@ import ( "github.com/andlabs/ui" _ "github.com/andlabs/ui/winmanifest" - "go.wit.com/gui/gui/toolkit" + "go.wit.com/gui/toolkits" ) func (p *node) newDropdown(n *node) { diff --git a/andlabs/main.go b/andlabs/main.go index c1fc7ac..b135563 100644 --- a/andlabs/main.go +++ b/andlabs/main.go @@ -2,7 +2,7 @@ package main import ( "sync" - "go.wit.com/gui/gui/toolkit" + "go.wit.com/gui/toolkits" "github.com/andlabs/ui" // the _ means we only need this for the init() diff --git a/andlabs/setText.go b/andlabs/setText.go index 7452982..2c7fb62 100644 --- a/andlabs/setText.go +++ b/andlabs/setText.go @@ -1,7 +1,7 @@ package main import ( - "go.wit.com/gui/gui/toolkit" + "go.wit.com/gui/toolkits" ) func (n *node) setText(a *toolkit.Action) { diff --git a/andlabs/tab.go b/andlabs/tab.go index d075a51..34c3c0a 100644 --- a/andlabs/tab.go +++ b/andlabs/tab.go @@ -1,7 +1,7 @@ package main import ( - "go.wit.com/gui/gui/toolkit" + "go.wit.com/gui/toolkits" "github.com/andlabs/ui" _ "github.com/andlabs/ui/winmanifest" diff --git a/andlabs/widget.go b/andlabs/widget.go index cf05a9e..71082a6 100644 --- a/andlabs/widget.go +++ b/andlabs/widget.go @@ -1,7 +1,7 @@ package main import ( - "go.wit.com/gui/gui/toolkit" + "go.wit.com/gui/toolkits" ) // this is specific to the nocui toolkit diff --git a/gocui/add.go b/gocui/add.go index 8e87f86..35718b7 100644 --- a/gocui/add.go +++ b/gocui/add.go @@ -1,7 +1,7 @@ package main import ( - "go.wit.com/gui/gui/toolkit" + "go.wit.com/gui/toolkits" ) var fakeStartWidth int = me.FakeW diff --git a/gocui/checkbox.go b/gocui/checkbox.go index d8c6f4b..102d1e0 100644 --- a/gocui/checkbox.go +++ b/gocui/checkbox.go @@ -2,7 +2,7 @@ package main import ( // "github.com/awesome-gocui/gocui" - "go.wit.com/gui/gui/toolkit" + "go.wit.com/gui/toolkits" ) func (n *node) setCheckbox(b bool) { diff --git a/gocui/click.go b/gocui/click.go index 45823e3..fe7f672 100644 --- a/gocui/click.go +++ b/gocui/click.go @@ -3,7 +3,7 @@ package main import ( "fmt" "github.com/awesome-gocui/gocui" - "go.wit.com/gui/gui/toolkit" + "go.wit.com/gui/toolkits" ) // set isCurrent = false everywhere diff --git a/gocui/debug.go b/gocui/debug.go index db94e37..3d66f57 100644 --- a/gocui/debug.go +++ b/gocui/debug.go @@ -2,7 +2,7 @@ package main import ( "fmt" - "go.wit.com/gui/gui/toolkit" + "go.wit.com/gui/toolkits" ) func (n *node) dumpTree(draw bool) { diff --git a/gocui/keybindings.go b/gocui/keybindings.go index 2741800..be05336 100644 --- a/gocui/keybindings.go +++ b/gocui/keybindings.go @@ -7,7 +7,7 @@ package main import ( "os" "github.com/awesome-gocui/gocui" - "go.wit.com/gui/gui/toolkit" + "go.wit.com/gui/toolkits" ) func defaultKeybindings(g *gocui.Gui) error { diff --git a/gocui/main.go b/gocui/main.go index 2b0e06d..f8270d5 100644 --- a/gocui/main.go +++ b/gocui/main.go @@ -6,7 +6,7 @@ package main import ( "os" - "go.wit.com/gui/gui/toolkit" + "go.wit.com/gui/toolkits" ) // sets defaults and establishes communication diff --git a/gocui/place.go b/gocui/place.go index 1ed46bd..8c6499d 100644 --- a/gocui/place.go +++ b/gocui/place.go @@ -2,7 +2,7 @@ package main import ( "strings" - "go.wit.com/gui/gui/toolkit" + "go.wit.com/gui/toolkits" ) func (n *node) placeBox(startW int, startH int) { diff --git a/gocui/plugin.go b/gocui/plugin.go index 381880c..0ce00b8 100644 --- a/gocui/plugin.go +++ b/gocui/plugin.go @@ -3,7 +3,7 @@ package main import ( // if you include more than just this import // then your plugin might be doing something un-ideal (just a guess from 2023/02/27) - "go.wit.com/gui/gui/toolkit" + "go.wit.com/gui/toolkits" ) func action(a *toolkit.Action) { diff --git a/gocui/showStdout.go b/gocui/showStdout.go index 70f7cb7..6c4ab85 100644 --- a/gocui/showStdout.go +++ b/gocui/showStdout.go @@ -5,7 +5,7 @@ import ( "fmt" "github.com/awesome-gocui/gocui" - "go.wit.com/gui/gui/toolkit" + "go.wit.com/gui/toolkits" ) var outputW int = 180 diff --git a/gocui/tab.go b/gocui/tab.go index 2f909ae..d1b869b 100644 --- a/gocui/tab.go +++ b/gocui/tab.go @@ -4,7 +4,7 @@ package main import ( "strings" - "go.wit.com/gui/gui/toolkit" + "go.wit.com/gui/toolkits" ) func (w *guiWidget) Width() int { diff --git a/gocui/view.go b/gocui/view.go index 08117fc..74c1309 100644 --- a/gocui/view.go +++ b/gocui/view.go @@ -8,7 +8,7 @@ import ( "strings" "github.com/awesome-gocui/gocui" - "go.wit.com/gui/gui/toolkit" + "go.wit.com/gui/toolkits" ) func splitLines(s string) []string { diff --git a/gocui/widget.go b/gocui/widget.go index 87856e4..f48ed78 100644 --- a/gocui/widget.go +++ b/gocui/widget.go @@ -2,7 +2,7 @@ package main import ( "strconv" - "go.wit.com/gui/gui/toolkit" + "go.wit.com/gui/toolkits" ) func initWidget(n *node) *guiWidget { diff --git a/nocui/action.go b/nocui/action.go index 86645cd..b746c25 100644 --- a/nocui/action.go +++ b/nocui/action.go @@ -1,7 +1,7 @@ package main import ( - "go.wit.com/gui/gui/toolkit" + "go.wit.com/gui/toolkits" ) func (n *node) show(b bool) { diff --git a/nocui/common.go b/nocui/common.go index a8d9684..91b34dd 100644 --- a/nocui/common.go +++ b/nocui/common.go @@ -12,7 +12,7 @@ package main */ import ( - "go.wit.com/gui/gui/toolkit" + "go.wit.com/gui/toolkits" ) // this is the channel we send user events like diff --git a/nocui/event.go b/nocui/event.go index 17d262a..103e1b1 100644 --- a/nocui/event.go +++ b/nocui/event.go @@ -1,7 +1,7 @@ package main import ( - "go.wit.com/gui/gui/toolkit" + "go.wit.com/gui/toolkits" ) func (n *node) doWidgetClick() { diff --git a/nocui/main.go b/nocui/main.go index 15f2954..dfaf50c 100644 --- a/nocui/main.go +++ b/nocui/main.go @@ -2,7 +2,7 @@ package main import ( "sync" - "go.wit.com/gui/gui/toolkit" + "go.wit.com/gui/toolkits" ) var muAction sync.Mutex diff --git a/nocui/stdin.go b/nocui/stdin.go index f1c6537..2c16e24 100644 --- a/nocui/stdin.go +++ b/nocui/stdin.go @@ -7,7 +7,7 @@ import ( "strings" "strconv" - "go.wit.com/gui/gui/toolkit" + "go.wit.com/gui/toolkits" ) func simpleStdin() { diff --git a/nocui/widget.go b/nocui/widget.go index cf05a9e..71082a6 100644 --- a/nocui/widget.go +++ b/nocui/widget.go @@ -1,7 +1,7 @@ package main import ( - "go.wit.com/gui/gui/toolkit" + "go.wit.com/gui/toolkits" ) // this is specific to the nocui toolkit diff --git a/widget.go b/widget.go new file mode 100644 index 0000000..02dbe3f --- /dev/null +++ b/widget.go @@ -0,0 +1,204 @@ +package toolkit + +// passes information between the toolkit library (plugin) +// +// This is the only thing that is passed between the toolkit plugin +// +// what names should be used? This is not part of [[Graphical Widget]] +// Event() seems like a good name. +// Event is used too much: web dev, cloud, etc +// I'm using "Action". Maybe it should really be +// "Interaction" as per wikipedia [[User interface]] +// +// TODO: convert this to a protobuf (?) +// + +type WidgetType int // Button, Menu, Checkbox, etc. +type ActionType int // Add, SetText, Click, Hide, Append, Delete, etc + +type Action struct { + ActionType ActionType + WidgetType WidgetType + + WidgetId int + ParentId int + + Text string // what is visable to the user + Name string // a name useful for programming + + // This is how the values are passed back and forth + // values from things like checkboxes & dropdown's + B bool + I int + S string + + // This is used for things like a slider(0,100) + X int + Y int + + // This is for the grid size & widget position + W int + H int + AtW int + AtH int + + // Put space around elements to improve look & feel + Margin bool + + // Make widgets fill up the space available + Expand bool + + A any // switch to this or deprecate this? pros/cons? +} + +const ( + Unknown WidgetType = iota + Root // the master 'root' node of the binary tree + Flag // used to send configuration values to plugins + Window // in certain gui's (ncurses), these are tabs + Tab // internally, this is a window + Frame // deprecate? + Grid // like drawers in a chest + Group // like the 'Appetizers' section on a menu + Box // a vertical or horizontal stack of widgets + Button + Checkbox // select 'on' or 'off' + Dropdown + Combobox // dropdown with edit=true + Label + Textbox // is this a Label with edit=true + Slider // like a progress bar + Spinner // like setting the oven temperature + Separator // TODO + Image // TODO + Area // TODO + Form // TODO + Font // TODO + Color // TODO + Dialog // TODO + Stdout // can be used to capture and display log output +) + +const ( + Add ActionType = iota + Delete + Get + Set + GetText + SetText + AddText + Show + Hide + Enable + Disable + Margin + Unmargin + Pad + Unpad + Append + Move + Dump + User // the user did something (mouse, keyboard, etc) + InitToolkit // initializes the toolkit + CloseToolkit // closes the toolkit + UserQuit // the user closed the GUI + EnableDebug // open the debugging window +) + +func (s WidgetType) String() string { + switch s { + case Root: + return "Root" + case Flag: + return "Flag" + case Window: + return "Window" + case Tab: + return "Tab" + case Frame: + return "Frame" + case Grid: + return "Grid" + case Group: + return "Group" + case Box: + return "Box" + case Button: + return "Button" + case Checkbox: + return "Checkbox" + case Dropdown: + return "Dropdown" + case Combobox: + return "Combobox" + case Label: + return "Label" + case Textbox: + return "Textbox" + case Slider: + return "Slider" + case Spinner: + return "Spinner" + case Separator: + return "Separator" + case Image: + return "Image" + case Area: + return "Area" + case Form: + return "Form" + case Font: + return "Font" + case Color: + return "Color" + case Dialog: + return "Dialog" + case Stdout: + return "Stdout" + case Unknown: + return "Unknown" + } + return "WidgetType.String() Error" +} + +func (s ActionType) String() string { + switch s { + case Add: + return "Add" + case Delete: + return "Delete" + case Get: + return "Get" + case Set: + return "Set" + case GetText: + return "GetText" + case SetText: + return "SetText" + case AddText: + return "AddText" + case Show: + return "Show" + case Hide: + return "Hide" + case Enable: + return "Enable" + case Disable: + return "Disable" + case Margin: + return "Margin" + case Unmargin: + return "Unmargin" + case Pad: + return "Pad" + case Unpad: + return "Unpad" + case Append: + return "Append" + case Move: + return "Move" + case Dump: + return "Dump" + } + return "ActionType.String() Error" +}