fix dropdown.Set() and place() on group

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2024-01-10 15:35:42 -06:00
parent fc9be41013
commit ba5ce49e7a
9 changed files with 183 additions and 123 deletions

View File

@ -245,7 +245,7 @@ func rawAction(a *widget.Action) {
case widget.SetText:
n.setText(a)
case widget.AddText:
n.setText(a)
n.addText(a)
case widget.Margin:
n.pad(widget.Unmargin)
case widget.Unmargin:

View File

@ -1,9 +1,6 @@
package main
import (
"github.com/andlabs/ui"
_ "github.com/andlabs/ui/winmanifest"
"go.wit.com/log"
"go.wit.com/gui/widget"
)
@ -71,88 +68,3 @@ func add(a *widget.Action) {
log.Log(ERROR, "add() error TODO: ", n.WidgetType, n.Name)
}
}
// This routine is very specific to this toolkit
// It's annoying and has to be copied to each widget when there are changes
// it could be 'simplfied' maybe or made to be more generic, but this is as far as I've gotten
// it's probably not worth working much more on this toolkit, the andlabs/ui has been great and got me here!
// but it's time to write direct GTK, QT, macos and windows toolkit plugins
// -- jcarr 2023/03/09
// Grid numbering examples by (X,Y)
// ---------
// -- (1) --
// -- (2) --
// ---------
//
// -----------------------------
// -- (1,1) -- (1,2) -- (1,3) --
// -- (2,1) -- (2,2) -- (2,3) --
// -----------------------------
// internally for andlabs/ui
// (x&y flipped and start at zero)
// -----------------------------
// -- (0,0) -- (1,0) -- (1,0) --
// -- (0,1) -- (1,1) -- (1,1) --
// -----------------------------
func (p *node) place(n *node) bool {
log.Log(INFO, "place() START", n.WidgetType, n.Name)
if (p.tk == nil) {
log.Log(ERROR, "p.tk == nil", p.Name, p.ParentId, p.WidgetType, p.tk)
log.Log(ERROR, "n = ", n.Name, n.ParentId, n.WidgetType, n.tk)
panic("p.tk == nil")
}
log.Log(INFO, "place() switch", p.WidgetType)
switch p.WidgetType {
case widget.Grid:
log.Log(INFO, "place() Grid try at Parent X,Y =", n.X, n.Y)
n.tk.gridX = n.AtW - 1
n.tk.gridY = n.AtH - 1
log.Log(INFO, "place() Grid try at gridX,gridY", n.tk.gridX, n.tk.gridY)
// at the very end, subtract 1 from X & Y since andlabs/ui starts counting at zero
p.tk.uiGrid.Append(n.tk.uiControl,
n.tk.gridX, n.tk.gridY, 1, 1,
false, ui.AlignFill, false, ui.AlignFill)
return true
case widget.Group:
if (p.tk.uiBox == nil) {
p.tk.uiGroup.SetChild(n.tk.uiControl)
log.Log(INFO, "place() hack Group to use this as the box?", n.Name, n.WidgetType)
p.tk.uiBox = n.tk.uiBox
} else {
p.tk.uiBox.Append(n.tk.uiControl, stretchy)
}
return true
case widget.Tab:
if (p.tk.uiTab == nil) {
log.Log(ERROR, "p.tk.uiTab == nil for n.WidgetId =", n.WidgetId, "p.tk =", p.tk)
panic("p.tk.uiTab == nil")
}
if (n.tk.uiControl == nil) {
log.Log(ERROR, "n.tk.uiControl == nil for n.WidgetId =", n.WidgetId, "n.tk =", n.tk)
panic("n.tk.uiControl == nil")
}
log.Log(ERROR, "CHECK LOGIC ON THIS. APPENDING directly into a window without a tab")
// log.Log(ERROR, "THIS SHOULD NEVER HAPPEN ??????? trying to place() node=", n.WidgetId, n.Name, n.Text, n.WidgetType)
// log.Log(ERROR, "THIS SHOULD NEVER HAPPEN ??????? trying to place() on parent=", p.WidgetId, p.Name, p.Text, p.WidgetType)
// panic("n.tk.uiControl == nil")
p.tk.uiTab.Append(n.Text, n.tk.uiControl)
p.tk.boxC += 1
return true
case widget.Box:
log.Log(INFO, "place() uiBox =", p.tk.uiBox)
log.Log(INFO, "place() uiControl =", n.tk.uiControl)
p.tk.uiBox.Append(n.tk.uiControl, stretchy)
p.tk.boxC += 1
return true
case widget.Window:
p.tk.uiWindow.SetChild(n.tk.uiControl)
return true
default:
log.Log(ERROR, "place() how? Parent =", p.WidgetId, p.WidgetType)
}
return false
}

27
andlabs/addText.go Normal file
View File

@ -0,0 +1,27 @@
package main
import (
"go.wit.com/log"
"go.wit.com/gui/widget"
)
func (n *node) addText(a *widget.Action) {
log.Log(CHANGE, "addText() START with a.S =", a.S)
t := n.tk
if (t == nil) {
log.Log(ERROR, "addText error. tk == nil", n.Name, n.WidgetId)
actionDump(debugError, a)
return
}
log.Log(CHANGE, "addText() Attempt on", n.WidgetType, "with", a.S)
switch n.WidgetType {
case widget.Dropdown:
n.AddDropdownName(a.S)
case widget.Combobox:
t.AddComboboxName(a.S)
default:
log.Log(ERROR, "plugin Send() Don't know how to addText on", n.WidgetType, "yet", a.ActionType)
}
log.Log(CHANGE, "addText() END with a.S =", a.S)
}

View File

@ -10,7 +10,7 @@ func (p *node) newBox(n *node) {
newt := new(guiWidget)
var box *ui.Box
if (n.B) {
if (n.horizontal) {
box = ui.NewHorizontalBox()
} else {
box = ui.NewVerticalBox()
@ -23,3 +23,36 @@ func (p *node) newBox(n *node) {
n.tk = newt
p.place(n)
}
/*
rawBox -- hack to arbitrarily add a box in andlabs to work
around the problem that a "group" can not have one entry in it
TODO: fix this so that a box is "added on demand" that is,
if "go.wit.com/gui/gui" sends you a 2nd thing to add to a group,
automatically add a box then. The problem with this, is the macos, windows and linux gtk
will panic on a move when an chind object is disasociated from the group
I haven't had time to try to debug this, so, instead, it's just probably better to always
add a box here. There doesn't seem to be any real issue with forcing a box to be inserted
into the toolkits that is "outside" the binary tree of widgets. This only means, that on
a destroy of the tree, this box must be checked
even that is a probably not senario however since clicking on the close box in the toolkit
has the operating system destroy everything in the window. it may or may not be possible
to control that behavior. at this time, it's "undetermined" and the best course of action
is to detect the window is destroyed and then remove all the toolkit information
from all the nodes in the binary tree
TODO: handle user killing/closing a window using the OS
*/
func (n *node) rawBox() *ui.Box {
var box *ui.Box
if (n.horizontal) {
box = ui.NewHorizontalBox()
} else {
box = ui.NewVerticalBox()
}
box.SetPadded(true)
return box
}

View File

@ -3,6 +3,8 @@ package main
import (
"github.com/andlabs/ui"
_ "github.com/andlabs/ui/winmanifest"
"go.wit.com/log"
)
func (p *node) newCombobox(n *node) {
@ -17,7 +19,8 @@ func (p *node) newCombobox(n *node) {
newt.val = make(map[int]string)
cb.OnChanged(func(spin *ui.EditableCombobox) {
n.S = spin.Text()
n.A = spin.Text()
log.Warn("combobox changed =" + spin.Text() + ".")
n.doUserEvent()
})

94
andlabs/place.go Normal file
View File

@ -0,0 +1,94 @@
package main
import (
"github.com/andlabs/ui"
_ "github.com/andlabs/ui/winmanifest"
"go.wit.com/log"
"go.wit.com/gui/widget"
)
// This routine is very specific to this toolkit
// It's annoying and has to be copied to each widget when there are changes
// it could be 'simplfied' maybe or made to be more generic, but this is as far as I've gotten
// it's probably not worth working much more on this toolkit, the andlabs/ui has been great and got me here!
// but it's time to write direct GTK, QT, macos and windows toolkit plugins
// -- jcarr 2023/03/09
// Grid numbering examples by (X,Y)
// ---------
// -- (1) --
// -- (2) --
// ---------
//
// -----------------------------
// -- (1,1) -- (1,2) -- (1,3) --
// -- (2,1) -- (2,2) -- (2,3) --
// -----------------------------
// internally for andlabs/ui
// (x&y flipped and start at zero)
// -----------------------------
// -- (0,0) -- (1,0) -- (1,0) --
// -- (0,1) -- (1,1) -- (1,1) --
// -----------------------------
func (p *node) place(n *node) bool {
log.Log(INFO, "place() START", n.WidgetType, n.Name)
if (p.tk == nil) {
log.Log(ERROR, "p.tk == nil", p.Name, p.ParentId, p.WidgetType, p.tk)
log.Log(ERROR, "n = ", n.Name, n.ParentId, n.WidgetType, n.tk)
panic("p.tk == nil")
}
log.Log(INFO, "place() switch", p.WidgetType)
switch p.WidgetType {
case widget.Grid:
log.Log(INFO, "place() Grid try at Parent X,Y =", n.X, n.Y)
n.tk.gridX = n.AtW - 1
n.tk.gridY = n.AtH - 1
log.Log(INFO, "place() Grid try at gridX,gridY", n.tk.gridX, n.tk.gridY)
// at the very end, subtract 1 from X & Y since andlabs/ui starts counting at zero
p.tk.uiGrid.Append(n.tk.uiControl,
n.tk.gridX, n.tk.gridY, 1, 1,
false, ui.AlignFill, false, ui.AlignFill)
return true
case widget.Group:
if (p.tk.uiBox == nil) {
log.Log(WARN, "place() andlabs hack group to use add a box", n.Name, n.WidgetType, "horizontal =", n.horizontal)
p.tk.uiBox = n.rawBox()
p.tk.uiGroup.SetChild(p.tk.uiBox)
}
p.tk.uiBox.Append(n.tk.uiControl, stretchy)
return true
case widget.Tab:
if (p.tk.uiTab == nil) {
log.Log(ERROR, "p.tk.uiTab == nil for n.WidgetId =", n.WidgetId, "p.tk =", p.tk)
panic("p.tk.uiTab == nil")
}
if (n.tk.uiControl == nil) {
log.Log(ERROR, "n.tk.uiControl == nil for n.WidgetId =", n.WidgetId, "n.tk =", n.tk)
panic("n.tk.uiControl == nil")
}
log.Log(ERROR, "CHECK LOGIC ON THIS. APPENDING directly into a window without a tab")
// log.Log(ERROR, "THIS SHOULD NEVER HAPPEN ??????? trying to place() node=", n.WidgetId, n.Name, n.Text, n.WidgetType)
// log.Log(ERROR, "THIS SHOULD NEVER HAPPEN ??????? trying to place() on parent=", p.WidgetId, p.Name, p.Text, p.WidgetType)
// panic("n.tk.uiControl == nil")
p.tk.uiTab.Append(n.Text, n.tk.uiControl)
p.tk.boxC += 1
return true
case widget.Box:
log.Log(INFO, "place() uiBox =", p.tk.uiBox)
log.Log(INFO, "place() uiControl =", n.tk.uiControl)
p.tk.uiBox.Append(n.tk.uiControl, stretchy)
p.tk.boxC += 1
return true
case widget.Window:
p.tk.uiWindow.SetChild(n.tk.uiControl)
return true
default:
log.Log(ERROR, "place() how? Parent =", p.WidgetId, p.WidgetType)
}
return false
}

View File

@ -75,39 +75,28 @@ func (n *node) setText(a *widget.Action) {
log.Log(ERROR, "setText() unknown", a.ActionType, "on checkbox", n.Name)
}
case widget.Dropdown:
switch a.ActionType {
case widget.AddText:
n.AddDropdownName(a.S)
case widget.Set:
var orig int
var i int = -1
var s string
orig = t.uiCombobox.Selected()
log.Log(CHANGE, "try to set the Dropdown to", a.S, "from", orig)
// try to find the string
for i, s = range t.val {
log.Log(CHANGE, "i, s", i, s)
if (a.S == s) {
t.uiCombobox.SetSelected(i)
log.Log(CHANGE, "setText() Dropdown worked.", n.S)
return
}
}
log.Log(ERROR, "setText() Dropdown did not find:", a.S)
// if i == -1, then there are not any things in the menu to select
if (i == -1) {
var orig int
var i int = -1
var s string
orig = t.uiCombobox.Selected()
log.Log(CHANGE, "try to set the Dropdown to", a.S, "from", orig)
// try to find the string
for i, s = range t.val {
log.Log(CHANGE, "i, s", i, s)
if (a.S == s) {
t.uiCombobox.SetSelected(i)
log.Log(CHANGE, "setText() Dropdown worked.", n.S)
return
}
// if the string was never set, then set the dropdown to the last thing added to the menu
if (orig == -1) {
t.uiCombobox.SetSelected(i)
}
case widget.Get:
// t.S = t.s
case widget.GetText:
// t.S = t.s
default:
log.Log(ERROR, "setText() unknown", a.ActionType, "on checkbox", n.Name)
}
log.Log(ERROR, "setText() Dropdown did not find:", a.S)
// if i == -1, then there are not any things in the menu to select
if (i == -1) {
return
}
// if the string was never set, then set the dropdown to the last thing added to the menu
if (orig == -1) {
t.uiCombobox.SetSelected(i)
}
case widget.Combobox:
switch a.ActionType {

View File

@ -25,8 +25,9 @@ func newWindow(n *node) {
win.SetBorderless(canvas)
win.SetMargined(margin)
win.OnClosing(func(*ui.Window) bool {
n.show(false)
n.doUserEvent()
return true
return false
})
newt.uiWindow = win
newt.uiControl = win

View File

@ -98,6 +98,7 @@ func (n *node) doUserEvent() {
a.S = n.S
a.I = n.I
a.B = n.B
a.A = n.A
a.ActionType = widget.User
log.Log(INFO, "doUserEvent() START: send a user event to the callback channel")
callback <- a