diff options
| author | Jeff Carr <[email protected]> | 2024-01-13 22:02:12 -0600 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2024-01-13 22:02:12 -0600 |
| commit | 47b15946de10a75cda026a7317a90d4857b453c8 (patch) | |
| tree | ab6a8c085226263982d3b19f2913e540707af2a1 /common.go | |
| parent | 4ef8409eeadcd4a359b7593b5ea35f9f523bfb64 (diff) | |
work on hiding widgetsv0.12.5
When widgets are hidden, their state works exactly the same
as normal, but updates are not sent to the toolkits
Signed-off-by: Jeff Carr <[email protected]>
Diffstat (limited to 'common.go')
| -rw-r--r-- | common.go | 296 |
1 files changed, 187 insertions, 109 deletions
@@ -11,79 +11,91 @@ import ( // functions for handling text related GUI elements func (n *Node) Show() *Node { - if ! n.hidden { - a := newAction(n, widget.Show) - sendAction(a) - } + if ! n.Ready() { return n } + if ! n.Hidden() { return n } + + n.hidden = false + n.changed = true + + // inform the toolkits + sendAction(n, widget.Show) return n } func (n *Node) Hide() *Node { - if ! n.hidden { - a := newAction(n, widget.Hide) - sendAction(a) - } + if ! n.Ready() { return n } + if n.Hidden() { return n } + + n.hidden = true + n.changed = true + // inform the toolkits + sendAction(n, widget.Hide) return n } +// enables a widget so the user can see it and work/click/etc on it +// by default, widgets are enabled when they are created func (n *Node) Enable() *Node { - if ! n.hidden { - a := newAction(n, widget.Enable) - sendAction(a) - } - return n -} + if ! n.Ready() { return n } + // if n.enabled { return n } -func (n *Node) Disable() *Node { - if ! n.hidden { - a := newAction(n, widget.Disable) - sendAction(a) - } + n.enabled = true + n.changed = true + + // inform the toolkits + sendAction(n, widget.Enable) return n } -func (n *Node) Add(str string) { - log.Log(GUI, "gui.Add() value =", str) +// disables a widget so the user can see it, but can not +// interact or change it. +func (n *Node) Disable() *Node { + if ! n.Ready() { return n } + // if ! n.enabled { return n } - n.value = str + n.enabled = false + n.changed = true - if ! n.hidden { - a := newAction(n, widget.Add) - sendAction(a) - } + // inform the toolkits + sendAction(n, widget.Disable) + return n } -func (n *Node) AddText(str string) { + +// add a new text string to widgets that support +// multiple string values +// These must be unique. return false if the string already exists +func (n *Node) AddText(str string) bool { + if ! n.Ready() { return false } log.Log(CHANGE, "AddText() value =", str) n.value = str + // TODO: make sure these are unique + n.strings = append(n.strings, str) - if ! n.hidden { - a := newAction(n, widget.AddText) - sendAction(a) - } + // inform the toolkits + sendAction(n, widget.AddText) + return true } -func (n *Node) SetNext(w int, h int) { - n.NextW = w - n.NextH = h - log.Info("SetNext() w,h =", n.NextW, n.NextH) -} +// appends text to the existing text +// TODO: this is an experiement func (n *Node) AppendText(str string) { + if ! n.Ready() { return } tmp := widget.GetString(n.value) + str n.value = tmp + n.changed = true - if ! n.hidden { - a := newAction(n, widget.SetText) - sendAction(a) - } + // inform the toolkits + sendAction(n, widget.SetText) } // THESE TWO FUNCTIONS ARE TERRIBLY NAMED AND NEED TO BE FIXED // 5 seconds worth of ideas: // Value() ? // Progname() Reference() ? +// 2024/01/13 the names are starting to grow on me and make it clearer to code against // get a string from the widget func (n *Node) GetText() string { @@ -104,48 +116,31 @@ func (n *Node) GetBool() bool { } // should get the reference name used for programming and debugging -// myButton = myGroup.NewButton("hit ball", nil).SetName("HIT") -// myButton.GetName() should return "HIT" -// n = Find("HIT") should return myButton -func (n *Node) GetName() string { - if ! n.Ready() { return "" } - return n.progname -} +func (n *Node) SetProgName(s string) { + if ! n.Ready() { return } -/* -// string handling examples that might be helpful for normalizeInt() -isAlpha := regexp.MustCompile(`^[A-Za-z]+$`).MatchString + if n.progname == s { + // don't do anything since nothing changed + return + } -for _, username := range []string{"userone", "user2", "user-three"} { - if !isAlpha(username) { - log.Log(GUI, "%q is not valid\n", username) - } + n.changed = true + n.progname = s + return } -const alpha = "abcdefghijklmnopqrstuvwxyz" - -func alphaOnly(s string) bool { - for _, char := range s { - if !strings.Contains(alpha, strings.ToLower(string(char))) { - return false - } - } - return true -} +/* + TODO: ensure these are unique and make a way to look them up + myButton = myGroup.NewButton("hit ball", nil).SetName("HIT") + myButton.GetName() should return "HIT" + n = Find("HIT") should return myButton */ - -func normalizeInt(s string) string { - // reg, err := regexp.Compile("[^a-zA-Z0-9]+") - reg, err := regexp.Compile("[^0-9]+") - if err != nil { - log.Log(GUI, "normalizeInt() regexp.Compile() ERROR =", err) - return s - } - clean := reg.ReplaceAllString(s, "") - log.Log(GUI, "normalizeInt() s =", clean) - return clean +func (n *Node) GetProgName() string { + if ! n.Ready() { return "" } + return n.progname } +/* func commonCallback(n *Node) { // TODO: make all of this common code to all the widgets // This might be common everywhere finally (2023/03/01) @@ -156,79 +151,102 @@ func commonCallback(n *Node) { n.Custom() } } +*/ func (n *Node) Margin() *Node { + if ! n.Ready() { return n } + if n.margin { return n } + n.margin = true - if ! n.hidden { - a := newAction(n, widget.Margin) - sendAction(a) - } + n.changed = true + + // inform the toolkits + sendAction(n, widget.Margin) return n } func (n *Node) Unmargin() *Node { + if ! n.Ready() { return n } + if ! n.margin { return n } + n.margin = false - if ! n.hidden { - a := newAction(n, widget.Unmargin) - sendAction(a) - } + n.changed = true + + // inform the toolkits + sendAction(n, widget.Unmargin) return n } func (n *Node) Pad() *Node { + if ! n.Ready() { return n } + if n.pad == true { return n } // nothing changed + n.pad = true - if ! n.hidden { - a := newAction(n, widget.Pad) - sendAction(a) - } + n.changed = true + + // inform the toolkits + sendAction(n, widget.Pad) return n } func (n *Node) Unpad() *Node { + if ! n.Ready() { return n } + if n.pad == false { return n } // nothing changed + n.pad = false - if ! n.hidden { - a := newAction(n, widget.Unpad) - sendAction(a) - } + n.changed = true + + // inform the toolkits + sendAction(n, widget.Unpad) return n } func (n *Node) Expand() *Node { + if ! n.Ready() { return n } + if n.expand == true { return n } // nothing changed + n.expand = true - if ! n.hidden { - a := newAction(n, widget.Pad) - a.Expand = true - sendAction(a) - } + n.changed = true + + // inform the toolkits + sendAction(n, widget.SetExpand) return n } -// is this better? -// yes, this is better. it allows Internationalization very easily -// me.window = myGui.New2().Window("DNS and IPv6 Control Panel").Standard() -// myFunnyWindow = myGui.NewWindow("Hello").Standard().SetText("Hola") +func (n *Node) SetExpand(b bool) *Node { + if ! n.Ready() { return n } + if n.expand == b { return n } // nothing changed -/* -func (n *Node) Window(title string) *Node { - log.Warn("Window()", n) - return n.NewWindow(title) + n.expand = b + n.changed = true + + // inform the toolkits + sendAction(n, widget.SetExpand) + return n } -*/ -func (n *Node) ProgName() string { - if ! n.Ready() { return "" } - return n.progname +// is the widget currently viewable? +func (n *Node) Hidden() bool { + if ! n.Ready() { return false } + return n.hidden } func (n *Node) Ready() bool { if n == nil { log.Warn("Ready() got node == nil") - // TODO: figure out if you can identify the code trace to help find the root cause + // TODO: figure out if you can identify the code trace + // to help find the root cause return false } return true } +// +// +// DEPRECATE / REDO / SORT OUT THIS STUFF +// +// + // This should not really do anything. as per the docs, the "Standard()" way // should be the default way /* @@ -242,3 +260,63 @@ func (n *Node) SetMargin() *Node { return n } */ + +/* +func (n *Node) Window(title string) *Node { + log.Warn("Window()", n) + return n.NewWindow(title) +} +*/ + +/* +func (n *Node) Add(str string) { + log.Log(GUI, "gui.Add() value =", str) + + n.value = str + + // inform the toolkits + sendAction(n, widget.Add) +} +*/ + +/* +func (n *Node) SetNext(w int, h int) { + n.NextW = w + n.NextH = h + log.Info("SetNext() w,h =", n.NextW, n.NextH) +} +*/ + +/* +// string handling examples that might be helpful for normalizeInt() +isAlpha := regexp.MustCompile(`^[A-Za-z]+$`).MatchString + +for _, username := range []string{"userone", "user2", "user-three"} { + if !isAlpha(username) { + log.Log(GUI, "%q is not valid\n", username) + } +} + +const alpha = "abcdefghijklmnopqrstuvwxyz" + +func alphaOnly(s string) bool { + for _, char := range s { + if !strings.Contains(alpha, strings.ToLower(string(char))) { + return false + } + } + return true +} +*/ + +func normalizeInt(s string) string { + // reg, err := regexp.Compile("[^a-zA-Z0-9]+") + reg, err := regexp.Compile("[^0-9]+") + if err != nil { + log.Log(GUI, "normalizeInt() regexp.Compile() ERROR =", err) + return s + } + clean := reg.ReplaceAllString(s, "") + log.Log(GUI, "normalizeInt() s =", clean) + return clean +} |
