summaryrefslogtreecommitdiff
path: root/toolkit/andlabs
diff options
context:
space:
mode:
Diffstat (limited to 'toolkit/andlabs')
-rw-r--r--toolkit/andlabs/demo.go7
-rw-r--r--toolkit/andlabs/dropdown.go74
-rw-r--r--toolkit/andlabs/main.go26
-rw-r--r--toolkit/andlabs/old/area.go136
-rw-r--r--toolkit/andlabs/old/color.go31
-rw-r--r--toolkit/andlabs/old/seperator.go25
-rw-r--r--toolkit/andlabs/old/structs.go273
-rw-r--r--toolkit/andlabs/old/table.go150
-rw-r--r--toolkit/andlabs/old/tableCallbacks.go108
-rw-r--r--toolkit/andlabs/slider.go19
-rw-r--r--toolkit/andlabs/spinbox.go38
-rw-r--r--toolkit/andlabs/spinner.go42
-rw-r--r--toolkit/andlabs/structs.go24
-rw-r--r--toolkit/andlabs/tab.go28
-rw-r--r--toolkit/andlabs/window.go13
15 files changed, 928 insertions, 66 deletions
diff --git a/toolkit/andlabs/demo.go b/toolkit/andlabs/demo.go
index 05451ea..1b097d7 100644
--- a/toolkit/andlabs/demo.go
+++ b/toolkit/andlabs/demo.go
@@ -14,9 +14,10 @@ func BlankWindow(w *ui.Window) *ui.Box {
return hbox
}
-func DemoNumbersPage(w *ui.Window) *Toolkit {
- var t Toolkit
+func (t *Toolkit) DemoNumbersPage() {
+ var w *ui.Window
+ w = t.uiWindow
t.uiBox = makeNumbersPage()
t.uiBox.SetPadded(true)
w.SetChild(t.uiBox)
@@ -27,8 +28,6 @@ func DemoNumbersPage(w *ui.Window) *Toolkit {
scs := spew.ConfigState{MaxDepth: 1}
scs.Dump(t)
}
-
- return &t
}
/*
diff --git a/toolkit/andlabs/dropdown.go b/toolkit/andlabs/dropdown.go
new file mode 100644
index 0000000..14cbf14
--- /dev/null
+++ b/toolkit/andlabs/dropdown.go
@@ -0,0 +1,74 @@
+package toolkit
+
+import "log"
+import "os"
+// import "time"
+
+import "github.com/andlabs/ui"
+import _ "github.com/andlabs/ui/winmanifest"
+
+import "github.com/davecgh/go-spew/spew"
+
+func (pt *Toolkit) NewDropdown(title string) *Toolkit {
+ // make new node here
+ log.Println("gui.Toolbox.NewDropdownCombobox()")
+ var newt Toolkit
+
+ if (pt.uiBox == nil) {
+ log.Println("gui.ToolboxNode.NewDropdown() node.UiBox == nil. I can't add a range UI element without a place to put it")
+ os.Exit(0)
+ return nil
+ }
+
+ s := ui.NewCombobox()
+ newt.uiCombobox = s
+ newt.uiBox = pt.uiBox
+ pt.uiBox.Append(s, false)
+
+ // initialize the index
+ newt.c = 0
+ newt.val = make(map[int]string)
+
+ s.OnSelected(func(spin *ui.Combobox) {
+ i := spin.Selected()
+ if (newt.val == nil) {
+ log.Println("make map didn't work")
+ os.Exit(0)
+ }
+ newt.text = newt.val[i]
+ val := newt.text
+ log.Println("gui.Toolbox.ui.Dropdown.OnChanged() val =", i, val)
+ if (DebugToolkit) {
+ log.Println("gui.Toolbox.ui.OnChanged() val =", i, val)
+ scs := spew.ConfigState{MaxDepth: 1}
+ scs.Dump(newt)
+ }
+ if (newt.OnChanged != nil) {
+ log.Println("gui.Toolbox.OnChanged() trying to run toolkit.OnChanged() entered val =", i, val)
+ newt.OnChanged(&newt)
+ return
+ }
+ if (newt.Custom != nil) {
+ log.Println("gui.Toolbox.OnChanged() Running toolkit.Custom()", i, val)
+ newt.Custom()
+ return
+ }
+ log.Println("gui.Toolbox.Dropdown.OnChanged() ENDED without finding any callback", i, val)
+ })
+
+ return &newt
+}
+
+func (t *Toolkit) AddDropdown(title string) {
+ t.uiCombobox.Append(title)
+ if (t.val == nil) {
+ log.Println("make map didn't work")
+ return
+ }
+ t.val[t.c] = title
+ t.c = t.c + 1
+}
+
+func (t Toolkit) SetDropdown(i int) {
+ t.uiCombobox.SetSelected(i)
+}
diff --git a/toolkit/andlabs/main.go b/toolkit/andlabs/main.go
new file mode 100644
index 0000000..cea0486
--- /dev/null
+++ b/toolkit/andlabs/main.go
@@ -0,0 +1,26 @@
+package toolkit
+
+import (
+ "log"
+
+ "github.com/andlabs/ui"
+ _ "github.com/andlabs/ui/winmanifest"
+)
+
+func Main(f func()) {
+ log.Println("Starting gui.Main() (using gtk via andlabs/ui)")
+ ui.Main(f)
+}
+
+// Other goroutines must use this to access the GUI
+//
+// You can not acess / process the GUI thread directly from
+// other goroutines. This is due to the nature of how
+// Linux, MacOS and Windows work (they all work differently. suprise. surprise.)
+//
+// For example: Queue(NewWindow())
+//
+func Queue(f func()) {
+ log.Println("Sending function to gui.Main() (using gtk via andlabs/ui)")
+ ui.QueueMain(f)
+}
diff --git a/toolkit/andlabs/old/area.go b/toolkit/andlabs/old/area.go
new file mode 100644
index 0000000..7c42c6c
--- /dev/null
+++ b/toolkit/andlabs/old/area.go
@@ -0,0 +1,136 @@
+package gui
+
+import "log"
+
+import "github.com/andlabs/ui"
+import _ "github.com/andlabs/ui/winmanifest"
+
+import "github.com/davecgh/go-spew/spew"
+
+func makeGenericArea(gb *GuiBox, newText *ui.AttributedString, custom func(*GuiButton)) {
+ // make this button just to get the default font (but don't display the button)
+ // There should be another way to do this (?)
+ var newB *GuiButton
+ newB = CreateFontButton(gb, "AREA")
+ newB.Box = gb
+ newB.Custom = custom
+
+ gw := gb.Window
+ // initialize the GuiArea{}
+ gw.Area = new(GuiArea)
+ gw.Area.Button = newB
+ gw.Area.Box = gb
+ gw.Area.UiAttrstr = newText
+ gw.Area.UiArea = ui.NewArea(gw.Area)
+
+ if (Config.Debug) {
+ spew.Dump(gw.Area.UiArea)
+ log.Println("DEBUGGING", Config.Debug)
+ } else {
+ log.Println("NOT DEBUGGING AREA mhAH.Button =", gw.Area.Button)
+ }
+}
+
+func AreaAppendText(newText *ui.AttributedString, what string, attrs ...ui.Attribute) {
+ start := len(newText.String())
+ end := start + len(what)
+ newText.AppendUnattributed(what)
+ for _, a := range attrs {
+ newText.SetAttribute(a, start, end)
+ }
+}
+
+func appendWithAttributes(newText *ui.AttributedString, what string, attrs ...ui.Attribute) {
+ start := len(newText.String())
+ end := start + len(what)
+ newText.AppendUnattributed(what)
+ for _, a := range attrs {
+ newText.SetAttribute(a, start, end)
+ }
+}
+
+func (ah GuiArea) Draw(a *ui.Area, p *ui.AreaDrawParams) {
+ tl := ui.DrawNewTextLayout(&ui.DrawTextLayoutParams{
+ String: ah.UiAttrstr,
+ DefaultFont: ah.Button.FB.Font(),
+ Width: p.AreaWidth,
+ Align: ui.DrawTextAlign(1),
+ })
+ p.Context.Text(tl, 0, 0)
+ defer tl.Free()
+}
+
+func (ah GuiArea) MouseEvent(a *ui.Area, me *ui.AreaMouseEvent) {
+ if (Config.Debug) {
+ log.Println("GOT MouseEvent() ah.Button =", ah.Button)
+ spew.Dump(me)
+ }
+ if (me.Down == 1) {
+ log.Println("GOT MOUSE DOWN")
+ log.Println("GOT MOUSE DOWN ah.Button =", ah.Button)
+ log.Println("GOT MOUSE UP ah.Button.FB =", ah.Button.FB)
+ }
+ if (me.Up == 1) {
+ log.Println("GOT MOUSE UP")
+ log.Println("GOT MOUSE UP ah.Button =", ah.Button)
+ log.Println("GOT MOUSE UP ah.Button.FB =", ah.Button.FB)
+ if (ah.Button.Custom != nil) {
+ ah.Button.Custom(ah.Button)
+ } else if (Data.MouseClick != nil) {
+ Data.MouseClick(ah.Button)
+ }
+ }
+}
+
+func (ah GuiArea) MouseCrossed(a *ui.Area, left bool) {
+ log.Println("GOT MouseCrossed()")
+}
+
+func (ah GuiArea) DragBroken(a *ui.Area) {
+ log.Println("GOT DragBroken()")
+}
+
+// TODO: fix KeyEvents
+func (ah GuiArea) KeyEvent(a *ui.Area, ke *ui.AreaKeyEvent) (handled bool) {
+ log.Println("GOT KeyEvent()")
+ if (ke.Key == 10) {
+ log.Println("GOT ENTER")
+ log.Println("GOT ENTER")
+ log.Println("GOT ENTER")
+ }
+ if (ke.Key == 32) {
+ log.Println("GOT ENTER")
+ log.Println("GOT ENTER")
+ log.Println("GOT ENTER")
+ }
+ spew.Dump(ke)
+ return false
+}
+
+func (b *GuiBox) ShowTextBox(newText *ui.AttributedString, custom func(*GuiButton), name string) {
+ log.Println("ShowTextBox() START")
+
+ gw := b.Window
+ if (gw == nil) {
+ log.Println("ShowTextBox() ERROR gw = nil")
+ return
+ }
+ log.Println("ShowTextBox() START gw =", gw)
+
+ /*
+ var newbox *GuiBox
+ newbox = new(GuiBox)
+ newbox.Window = gw
+ newbox.Name = name
+ hbox := ui.NewVerticalBox()
+ newbox.UiBox = hbox
+ */
+
+ // TODO: allow padded & axis here
+ b.UiBox.SetPadded(true)
+
+ // add(gw.BoxMap["MAINBOX"], newbox)
+
+ makeGenericArea(b, newText, custom)
+ b.UiBox.Append(b.Window.Area.UiArea, true)
+}
diff --git a/toolkit/andlabs/old/color.go b/toolkit/andlabs/old/color.go
new file mode 100644
index 0000000..cf4a362
--- /dev/null
+++ b/toolkit/andlabs/old/color.go
@@ -0,0 +1,31 @@
+package gui
+
+//
+// convert between 'standard' golang Color and andlabs/ui Color
+//
+
+// import "log"
+// import "fmt"
+import "image/color"
+
+import "github.com/andlabs/ui"
+import _ "github.com/andlabs/ui/winmanifest"
+
+func libuiColorToGOlangColor(rgba color.RGBA) ui.TableColor {
+ /* a hack to see if colors work differently on macos or windows
+ if (rgba.R == 72) {
+ log.Println("SETTING COLOR TO NIL")
+ log.Println("SETTING COLOR TO NIL")
+ log.Println("SETTING COLOR TO NIL")
+ return ui.TableColor{}
+ }
+ */
+ return ui.TableColor{float64(rgba.R) / 256, float64(rgba.G) / 256, float64(rgba.B) / 256, float64(rgba.A) / 256}
+}
+
+/*
+func golangColorGOlibuiColorTo (ui.TableColor) (rgba color.RGBA) {
+ color.RGBA{float64(, 100, 200, 100}
+ return ui.TableColor{float64(rgba.R) / 256, float64(rgba.G) / 256, float64(rgba.B) / 256, float64(rgba.A) / 256}
+}
+*/
diff --git a/toolkit/andlabs/old/seperator.go b/toolkit/andlabs/old/seperator.go
new file mode 100644
index 0000000..ca152a8
--- /dev/null
+++ b/toolkit/andlabs/old/seperator.go
@@ -0,0 +1,25 @@
+package gui
+
+import "log"
+import "os"
+
+import "github.com/andlabs/ui"
+import _ "github.com/andlabs/ui/winmanifest"
+
+func HorizontalBreak(box *GuiBox) {
+ log.Println("VerticalSeparator added to box =", box.Name)
+ tmp := ui.NewHorizontalSeparator()
+ if (box == nil) {
+ return
+ }
+ if (box.UiBox == nil) {
+ return
+ }
+ box.UiBox.Append(tmp, false)
+}
+
+func VerticalBreak(box *GuiBox) {
+ log.Println("VerticalSeparator added to box =", box.Name)
+ tmp := ui.NewVerticalSeparator()
+ box.UiBox.Append(tmp, false)
+}
diff --git a/toolkit/andlabs/old/structs.go b/toolkit/andlabs/old/structs.go
new file mode 100644
index 0000000..4a16438
--- /dev/null
+++ b/toolkit/andlabs/old/structs.go
@@ -0,0 +1,273 @@
+package gui
+
+import (
+ "image/color"
+
+ "github.com/andlabs/ui"
+// "golang.org/x/image/font"
+
+ // "github.com/davecgh/go-spew/spew"
+
+ // _ "github.com/andlabs/ui/winmanifest"
+)
+
+//
+// All GUI Data Structures and functions that are external
+// If you need cross platform support, these might only
+// be the safe way to interact with the GUI
+//
+var Data GuiData
+var Config GuiConfig
+
+type GuiConfig struct {
+ Title string
+ Width int
+ Height int
+ Exit func(*Node)
+
+ Debug bool
+ DebugNode bool
+ DebugTabs bool
+ DebugTable bool
+ DebugWindow bool
+ DebugToolkit bool
+
+ depth int
+ counter int // used to make unique ID's
+ prefix string
+}
+
+type GuiData struct {
+ // a fallback default function to handle mouse events
+ // if nothing else is defined to handle them
+ MouseClick func(*GuiButton)
+
+ // A map of all the entry boxes
+ // AllEntries []*GuiEntry
+ WindowMap map[string]*GuiWindow
+
+ // Store access to everything via binary tree's
+ NodeMap map[string]*Node
+ NodeArray []*Node
+ NodeSlice []*Node
+
+ // A map of all buttons everywhere on all
+ // windows, all tabs, across all goroutines
+ // This is "GLOBAL"
+ //
+ // This has to work this way because of how
+ // andlabs/ui & andlabs/libui work
+ AllButtons []*GuiButton
+// buttonMap map[*ui.Button]*GuiButton
+}
+
+/*
+type GuiTab struct {
+ Name string // field for human readable name
+ Number int // the andlabs/ui tab index
+ Window *GuiWindow // the parent Window
+}
+*/
+
+//
+// stores information on the 'window'
+//
+// This merges the concept of andlabs/ui *Window and *Tab
+//
+// More than one Window is not supported in a cross platform
+// sense & may never be. On Windows and MacOS, you have to have
+// 'tabs'. Even under Linux, more than one Window is currently
+// unstable
+//
+// This code will make a 'GuiWindow' regardless of if it is
+// a stand alone window (which is more or less working on Linux)
+// or a 'tab' inside a window (which is all that works on MacOS
+// and MSWindows.
+//
+// This struct keeps track of what is in the window so you
+// can destroy and replace it with something else
+//
+type GuiWindow struct {
+ Name string // field for human readable name
+ Width int
+ Height int
+ Axis int // does it add items to the X or Y axis
+ TabNumber *int // the andlabs/ui tab index
+
+ // the callback function to make the window contents
+ // MakeWindow func(*GuiBox) *GuiBox
+
+ // the components of the window
+ BoxMap map[string]*GuiBox
+ // EntryMap map[string]*GuiEntry
+
+ node *Node
+
+ // andlabs/ui abstraction mapping
+ UiWindow *ui.Window
+ UiTab *ui.Tab // if this != nil, the window is 'tabbed'
+}
+
+/*
+func (w *GuiWindow) Dump() {
+ log.Println("gui.GuiWindow.Dump() Name = ", w.Name)
+ log.Println("gui.GuiWindow.Dump() node = ", w.node)
+ log.Println("gui.GuiWindow.Dump() Width = ", w.Width)
+ log.Println("gui.GuiWindow.Dump() Height = ", w.Height)
+}
+*/
+
+// GuiBox is any type of ui.Hbox or ui.Vbox
+// There can be lots of these for each GuiWindow
+type GuiBox struct {
+ Name string // field for human readable name
+ Axis int // does it add items to the X or Y axis
+ Window *GuiWindow // the parent Window
+
+ node *Node
+
+ // andlabs/ui abstraction mapping
+ UiBox *ui.Box
+}
+
+func (b *GuiBox) Append(child ui.Control, x bool) {
+ if b.UiBox == nil {
+ // spew.Dump(b)
+ // b.Dump()
+ panic("GuiBox.Append() can't work. UiBox == nil")
+ return
+ }
+ b.UiBox.Append(child, x)
+}
+
+// Note: every mouse click is handled
+// as a 'Button' regardless of where
+// the user clicks it. You could probably
+// call this 'GuiMouseClick'
+type GuiButton struct {
+ Name string // field for human readable name
+ Box *GuiBox // what box the button click was in
+
+ // a callback function for the main application
+ Custom func(*GuiButton)
+ Values interface{}
+ Color color.RGBA
+
+ // andlabs/ui abstraction mapping
+ B *ui.Button
+ FB *ui.FontButton
+ CB *ui.ColorButton
+}
+
+/*
+//
+// AREA STRUCTURES START
+// AREA STRUCTURES START
+// AREA STRUCTURES START
+//
+type GuiArea struct {
+ Button *GuiButton // what button handles mouse events
+ Box *GuiBox
+
+ UiAttrstr *ui.AttributedString
+ UiArea *ui.Area
+}
+
+type FontString struct {
+ S string
+ Size int
+ F font.Face
+ W font.Weight
+}
+
+//
+// AREA STRUCTURES END
+// AREA STRUCTURES END
+// AREA STRUCTURES END
+//
+
+//
+// TABLE DATA STRUCTURES START
+// TABLE DATA STRUCTURES START
+// TABLE DATA STRUCTURES START
+//
+
+//
+// This is the structure that andlabs/ui uses to pass information
+// to the GUI. This is the "authoritative" data.
+//
+type TableData struct {
+ RowCount int // This is the number of 'rows' which really means data elements not what the human sees
+ RowWidth int // This is how wide each row is
+ Rows []RowData // This is all the table data by row
+ generatedColumnTypes []ui.TableValue // generate this dynamically
+
+ Cells [20]CellData
+ Human [20]HumanMap
+
+ Box *GuiBox
+
+ lastRow int
+ lastColumn int
+}
+
+//
+// This maps the andlabs/ui & libui components into a "human"
+// readable cell reference list. The reason is that there
+// are potentially 3 values for each cell. The Text, the Color
+// and an image. These are not always needed so the number
+// of fields varies between 1 and 3. Internally, the toolkit
+// GUI abstraction needs to list all of them, but it's then
+// hard to figure out which column goes with the columns that
+// you see when you visually are looking at it like a spreadsheet
+//
+// This makes a map so that we can say "give me the value at
+// row 4 and column 2" and find the fields that are needed
+//
+// TODO: re-add images and the progress bar (works in andlabs/ui)
+//
+type HumanCellData struct {
+ Name string // what kind of row is this?
+ Text string
+ TextID int
+ Color color.RGBA
+ ColorID int
+ Button *GuiButton
+}
+
+type HumanMap struct {
+ Name string // what kind of row is this?
+ TextID int
+ ColorID int
+}
+
+type TableColumnData struct {
+ Index int
+ CellType string
+ Heading string
+ Color string
+}
+
+type CellData struct {
+ Index int
+ HumanID int
+ Name string // what type of cell is this?
+}
+
+// hmm. will this stand the test of time?
+type RowData struct {
+ Name string // what kind of row is this?
+ Status string // status of the row?
+ //
+ // TODO: These may or may not be implementable
+ // depending on if it's possible to detect the bgcolor or what row is selected
+ // click func() // what function to call if the user clicks on it
+ // doubleclick func() // what function to call if the user double clicks on it
+ //
+ HumanData [20]HumanCellData
+}
+*/
+
+//
+// TABLE DATA STRUCTURES END
+//
diff --git a/toolkit/andlabs/old/table.go b/toolkit/andlabs/old/table.go
new file mode 100644
index 0000000..92ae871
--- /dev/null
+++ b/toolkit/andlabs/old/table.go
@@ -0,0 +1,150 @@
+// based off andlabs/ui/examples/table.go
+
+package gui
+
+import "log"
+
+import "github.com/andlabs/ui"
+import _ "github.com/andlabs/ui/winmanifest"
+
+// import "github.com/davecgh/go-spew/spew"
+
+func initRowBTcolor(mh *TableData, intBG int, cell TableColumnData) {
+ humanInt := cell.Index
+
+ // setup mapping from human readable indexes to internal libUI indexes
+ mh.Human[humanInt].Name = "BG"
+ mh.Human[humanInt].ColorID = intBG
+ mh.Human[humanInt].TextID = -1
+
+ mh.Cells[intBG].Name = "BG"
+ mh.Cells[intBG].HumanID = humanInt
+
+ log.Println("intBG, humanInt", intBG, humanInt)
+}
+
+func initRowButtonColumn(mh *TableData, buttonID int, junk string, cell TableColumnData) {
+ humanInt := cell.Index
+
+ // setup mapping from human readable indexes to internal libUI indexes
+ mh.Human[humanInt].Name = "BUTTON"
+ mh.Human[humanInt].ColorID = -1
+ mh.Human[humanInt].TextID = buttonID
+
+ mh.Cells[buttonID].Name = "BUTTON"
+ mh.Cells[buttonID].HumanID = humanInt
+
+ log.Println("buttonID, humanInt", buttonID, humanInt)
+}
+
+func initRowTextColorColumn(mh *TableData, stringID int, colorID int, junk string, color ui.TableColor, cell TableColumnData) {
+ humanInt := cell.Index
+
+ // setup mapping from human readable indexes to internal libUI indexes
+ mh.Human[humanInt].Name = "EDIT"
+ mh.Human[humanInt].ColorID = colorID
+ mh.Human[humanInt].TextID = stringID
+
+ // text for Column humanInt
+ mh.Cells[stringID].Name = "EDIT"
+ mh.Cells[stringID].HumanID = humanInt
+
+ mh.Cells[colorID].Name = "COLOR"
+ mh.Cells[colorID].HumanID = humanInt
+}
+
+func initRowTextColumn(mh *TableData, stringID int, junk string, cell TableColumnData) {
+ humanInt := cell.Index
+
+ // setup mapping from human readable indexes to internal libUI indexes
+ mh.Human[humanInt].Name = "EDIT"
+ mh.Human[humanInt].ColorID = -1
+ mh.Human[humanInt].TextID = stringID
+
+ mh.Cells[stringID].Name = "EDIT"
+ mh.Cells[stringID].HumanID = humanInt
+}
+
+func InitColumns(mh *TableData, parts []TableColumnData) {
+ tmpBTindex := 0
+ humanID := 0
+ for key, foo := range parts {
+ log.Println("key, foo =", key, foo)
+
+ parts[key].Index = humanID
+ humanID += 1
+
+ if (foo.CellType == "BG") {
+ mh.generatedColumnTypes = append(mh.generatedColumnTypes, ui.TableColor{})
+ initRowBTcolor (mh, tmpBTindex, parts[key])
+ tmpBTindex += 1
+ } else if (foo.CellType == "BUTTON") {
+ mh.generatedColumnTypes = append(mh.generatedColumnTypes, ui.TableString(""))
+ initRowButtonColumn (mh, tmpBTindex, parts[key].Heading, parts[key])
+ tmpBTindex += 1
+ } else if (foo.CellType == "TEXTCOLOR") {
+ mh.generatedColumnTypes = append(mh.generatedColumnTypes, ui.TableString(""))
+ mh.generatedColumnTypes = append(mh.generatedColumnTypes, ui.TableColor{})
+ initRowTextColorColumn(mh, tmpBTindex, tmpBTindex + 1, parts[key].Heading, ui.TableColor{0.0, 0, 0.9, 1}, parts[key])
+ tmpBTindex += 2
+ } else if (foo.CellType == "TEXT") {
+ mh.generatedColumnTypes = append(mh.generatedColumnTypes, ui.TableString(""))
+ initRowTextColumn (mh, tmpBTindex, parts[key].Heading, parts[key])
+ tmpBTindex += 1
+ } else {
+ panic("I don't know what this is in initColumnNames")
+ }
+ }
+}
+
+func AddTableTab(gw *GuiWindow, name string, rowcount int, parts []TableColumnData) *TableData {
+ node := NewWindow()
+ b := node.box
+ return b.AddTableBox(name, rowcount, parts)
+}
+
+func (b *GuiBox) AddTableBox(name string, rowcount int, parts []TableColumnData) *TableData {
+ mh := new(TableData)
+
+ mh.RowCount = rowcount
+ mh.Rows = make([]RowData, mh.RowCount)
+
+ InitColumns(mh, parts)
+
+ model := ui.NewTableModel(mh)
+ table := ui.NewTable(
+ &ui.TableParams{
+ Model: model,
+ RowBackgroundColorModelColumn: 0, // Row Background color is always index zero
+ })
+
+ tmpBTindex := 0
+ for key, foo := range parts {
+ log.Println(key, foo)
+ if (foo.CellType == "BG") {
+ } else if (foo.CellType == "BUTTON") {
+ tmpBTindex += 1
+ table.AppendButtonColumn(foo.Heading, tmpBTindex, ui.TableModelColumnAlwaysEditable)
+ } else if (foo.CellType == "TEXTCOLOR") {
+ tmpBTindex += 1
+ table.AppendTextColumn(foo.Heading, tmpBTindex, ui.TableModelColumnAlwaysEditable,
+ &ui.TableTextColumnOptionalParams{
+ ColorModelColumn: tmpBTindex + 1,
+ });
+ tmpBTindex += 1
+ } else if (foo.CellType == "TEXT") {
+ tmpBTindex += 1
+ table.AppendTextColumn(foo.Heading, tmpBTindex, ui.TableModelColumnAlwaysEditable, nil)
+ } else {
+ panic("I don't know what this is in initColumnNames")
+ }
+ }
+
+ // is this needed?
+ // gw.BoxMap[name] = box
+ mh.Box = b
+
+ b.UiBox.Append(table, true)
+
+ return mh
+}
diff --git a/toolkit/andlabs/old/tableCallbacks.go b/toolkit/andlabs/old/tableCallbacks.go
new file mode 100644
index 0000000..6eefd8d
--- /dev/null
+++ b/toolkit/andlabs/old/tableCallbacks.go
@@ -0,0 +1,108 @@
+package gui
+
+//
+// These functions are the hooks to the andlabs libui
+// They eventually feed information to the OS native GUI toolkits
+// and feed back user interaction with the GUI
+//
+
+import "log"
+// import "fmt"
+import "image/color"
+import "runtime"
+
+import "github.com/andlabs/ui"
+import _ "github.com/andlabs/ui/winmanifest"
+
+func (mh *TableData) NumRows(m *ui.TableModel) int {
+ if (Config.Debug) {
+ log.Println("NumRows = mh.RowCount = ", mh.RowCount, "(last Row & Column =", mh.lastRow, mh.lastColumn, ")")
+ }
+ return mh.RowCount
+}
+
+// FYI: this routine seems to be called around 10 to 100 times a second for each table
+func (mh *TableData) ColumnTypes(m *ui.TableModel) []ui.TableValue {
+ if (Config.DebugTable) {
+ log.Println("ColumnTypes = ", mh.generatedColumnTypes)
+ }
+ return mh.generatedColumnTypes
+}
+
+// TODO: Figure out why this is being called 1000 times a second (10 times for each row & column)
+//
+// Nevermind that TODO. Who gives a shit. This is a really smart way to treat the OS toolkits
+func (mh *TableData) CellValue(m *ui.TableModel, row, column int) ui.TableValue {
+ if (Config.DebugTable) {
+ log.Println("CellValue() row, column =", row, column)
+ }
+ mh.lastRow = row
+ mh.lastColumn = column
+ humanID := mh.Cells[column].HumanID
+ if (column == mh.Human[humanID].TextID) {
+ return ui.TableString(mh.Rows[row].HumanData[humanID].Text)
+ }
+ if (column == mh.Human[humanID].ColorID) {
+ if (column == 0) {
+ // ignore BG color on windows for now
+ if (runtime.GOOS == "windows") {
+ // TODO: fix colors on windows
+ // log.Println("CellValue() WINDOWS is BG COLOR row, column =", row, column)
+ // return nil
+ }
+
+ if (mh.Rows[row].HumanData[humanID].Color == color.RGBA{255, 255, 255, 255}) {
+ log.Println("CellValue() color.RGBA{255, 255, 255, 255} so return nil. row, column =", row, column)
+ return nil
+ }
+
+ bgcolor := libuiColorToGOlangColor(mh.Rows[row].HumanData[humanID].Color)
+ if (Config.Debug) {
+ log.Println("CellValue() BGCOLOR =", bgcolor)
+ }
+ return bgcolor
+ }
+ return libuiColorToGOlangColor(mh.Rows[row].HumanData[humanID].Color)
+ }
+ log.Println("CellValue() FAILURE")
+ log.Println("CellValue() FAILURE")
+ log.Println("CellValue() row, column = ", row, column)
+ log.Println("CellValue() FAILURE")
+ log.Println("CellValue() FAILURE")
+ log.Println("CellValue() mh.Cells", mh.Cells)
+ log.Println("CellValue() mh.Human", mh.Human)
+ panic("CellValue() not sure what sort of ui.TableValue to return in CellValue()")
+ return ui.TableString("")
+}
+
+func (mh *TableData) SetCellValue(m *ui.TableModel, row, column int, value ui.TableValue) {
+ log.Println("SetCellValue() START row=", row, "column=", column, "value=", value)
+
+ defaultSetCellValue(mh, row, column)
+
+ log.Println("mh.Cells[column].HumanID =", mh.Cells[column].HumanID)
+ // log.Println("mh.Rows[row].Cells[column].HumanID =", mh.Rows[row].Cells[column].HumanID)
+
+ humanID := mh.Cells[column].HumanID
+ log.Println("mh.Human[humanID].ColorID =", mh.Human[humanID].ColorID)
+ log.Println("mh.Human[humanID].TextID =", mh.Human[humanID].TextID)
+
+ log.Println("SetCellValue() END")
+}
+
+func defaultSetCellValue(mh *TableData, row int, column int) {
+ if (mh.Cells[column].Name == "BUTTON") {
+ humanID := mh.Cells[column].HumanID
+ log.Println("defaultSetCellValue() FOUND THE TABLE BUTTON ", row, humanID)
+
+ button := mh.Rows[row].HumanData[humanID].Button
+ if (button != nil) {
+ guiButtonClick(button)
+ return
+ }
+ log.Println("defaultSetCellValue() ERROR: UNKNOWN BUTTON IN TABLE")
+ if (Config.Debug) {
+ panic("defaultSetCellValue() GOT AN UNKNOWN BUTTON CLICK IN TABLE")
+ }
+ }
+}
diff --git a/toolkit/andlabs/slider.go b/toolkit/andlabs/slider.go
index 65cf531..05eaba4 100644
--- a/toolkit/andlabs/slider.go
+++ b/toolkit/andlabs/slider.go
@@ -11,11 +11,11 @@ import "github.com/davecgh/go-spew/spew"
// func NewSlider(b *ui.Box, name string *Toolkit {
func (t Toolkit) NewSlider(title string, x int, y int) *Toolkit {
// make new node here
- log.Println("gui.Toolbox.NewSpinbox()", x, y)
+ log.Println("gui.Toolkit.NewSpinbox()", x, y)
var newt Toolkit
if (t.uiBox == nil) {
- log.Println("gui.ToolboxNode.NewGroup() node.UiBox == nil. I can't add a range UI element without a place to put it")
+ log.Println("gui.ToolkitNode.NewGroup() node.UiBox == nil. I can't add a range UI element without a place to put it")
log.Println("probably could just make a box here?")
os.Exit(0)
return nil
@@ -28,16 +28,23 @@ func (t Toolkit) NewSlider(title string, x int, y int) *Toolkit {
s.OnChanged(func(spin *ui.Slider) {
i := spin.Value()
- log.Println("gui.Toolbox.ui.Slider.OnChanged() val =", i)
+ log.Println("gui.Toolkit.ui.Slider.OnChanged() val =", i)
if (DebugToolkit) {
- log.Println("gui.Toolbox.ui.OnChanged() val =", i)
+ log.Println("gui.Toolkit.ui.OnChanged() val =", i)
scs := spew.ConfigState{MaxDepth: 1}
scs.Dump(newt)
}
- if (t.OnChanged != nil) {
- log.Println("gui.Toolbox.OnChanged() entered val =", i)
+ if (newt.OnChanged != nil) {
+ log.Println("gui.Toolkit.OnChanged() trying to run toolkit.OnChanged() entered val =", i)
newt.OnChanged(&newt)
+ return
}
+ if (newt.Custom != nil) {
+ log.Println("gui.Toolkit.OnChanged() Running toolkit.Custom()")
+ newt.Custom()
+ return
+ }
+ log.Println("gui.Toolkit.OnChanged() ENDED without finding any callback")
})
return &newt
diff --git a/toolkit/andlabs/spinbox.go b/toolkit/andlabs/spinbox.go
deleted file mode 100644
index c47fab7..0000000
--- a/toolkit/andlabs/spinbox.go
+++ /dev/null
@@ -1,38 +0,0 @@
-package toolkit
-
-import "log"
-
-import "github.com/andlabs/ui"
-import _ "github.com/andlabs/ui/winmanifest"
-
-import "github.com/davecgh/go-spew/spew"
-
-func NewSpinbox(b *ui.Box, name string, x int, y int) *Toolkit {
- // make new node here
- log.Println("gui.Toolbox.NewSpinbox()", x, y)
- var t Toolkit
-
- if (b == nil) {
- log.Println("gui.ToolboxNode.NewSpinbox() node.UiBox == nil. I can't add a range UI element without a place to put it")
- return nil
- }
- spin := ui.NewSpinbox(x, y)
- t.uiSpinbox = spin
- t.uiBox = b
- t.uiBox.Append(spin, false)
-
- spin.OnChanged(func(spin *ui.Spinbox) {
- i := spin.Value()
- if (DebugToolkit) {
- log.Println("gui.Toolbox.ui.OnChanged() val =", i)
- scs := spew.ConfigState{MaxDepth: 1}
- scs.Dump(t)
- }
- if (t.OnChanged != nil) {
- log.Println("gui.Toolbox.OnChanged() entered val =", i)
- t.OnChanged(&t)
- }
- })
-
- return &t
-}
diff --git a/toolkit/andlabs/spinner.go b/toolkit/andlabs/spinner.go
new file mode 100644
index 0000000..12662e5
--- /dev/null
+++ b/toolkit/andlabs/spinner.go
@@ -0,0 +1,42 @@
+package toolkit
+
+import "log"
+import "os"
+
+import "github.com/andlabs/ui"
+import _ "github.com/andlabs/ui/winmanifest"
+
+import "github.com/davecgh/go-spew/spew"
+
+// func NewSlider(b *ui.Box, name string *Toolkit {
+func (t Toolkit) NewSpinner(title string, x int, y int) *Toolkit {
+ // make new node here
+ log.Println("gui.Toolkit.NewSpinner()", x, y)
+ var newt Toolkit
+
+ if (t.uiBox == nil) {
+ log.Println("gui.ToolkitNode.NewSpinner() node.UiBox == nil. I can't add a range UI element without a place to put it")
+ os.Exit(0)
+ return nil
+ }
+
+ s := ui.NewSpinbox(x, y)
+ newt.uiSpinbox = s
+ newt.uiBox = t.uiBox
+ t.uiBox.Append(s, false)
+
+ s.OnChanged(func(s *ui.Spinbox) {
+ i := s.Value()
+ if (DebugToolkit) {
+ log.Println("gui.Toolkit.ui.OnChanged() val =", i)
+ scs := spew.ConfigState{MaxDepth: 1}
+ scs.Dump(newt)
+ }
+ if (t.OnChanged != nil) {
+ log.Println("gui.Toolkit.OnChanged() entered val =", i)
+ newt.OnChanged(&newt)
+ }
+ })
+
+ return &newt
+}
diff --git a/toolkit/andlabs/structs.go b/toolkit/andlabs/structs.go
index a089a12..df34194 100644
--- a/toolkit/andlabs/structs.go
+++ b/toolkit/andlabs/structs.go
@@ -30,6 +30,7 @@ type Toolkit struct {
uiBox2 *ui.Box // temporary hack while implementing tabs
uiButton *ui.Button
uiControl *ui.Control
+ uiCombobox *ui.Combobox
uiEntry *ui.Entry
uiGroup *ui.Group
uiLabel *ui.Label
@@ -39,6 +40,13 @@ type Toolkit struct {
uiText *ui.EditableCombobox
uiWindow *ui.Window
UiWindowBad *ui.Window
+
+ // used as a counter to work around limitations of widgets like combobox
+ // this is probably fucked up and in many ways wrong because of unsafe goroutine threading
+ // but it's working for now due to the need for need for a correct interaction layer betten toolkits
+ c int
+ val map[int]string
+ text string
}
func (t *Toolkit) GetText() string {
@@ -53,6 +61,12 @@ func (t *Toolkit) GetText() string {
}
return t.uiEntry.Text()
}
+ if (t.uiCombobox != nil) {
+ if (DebugToolkit) {
+ log.Println("gui.Toolkit.GetText() =", t.text)
+ }
+ return t.text
+ }
return ""
}
@@ -131,6 +145,9 @@ func (t *Toolkit) Dump() {
if (t.uiButton != nil) {
log.Println("gui.Toolkit.Dump() uiButton =", t.uiButton)
}
+ if (t.uiCombobox != nil) {
+ log.Println("gui.Toolkit.Dump() uiCombobox =", t.uiCombobox)
+ }
if (t.uiWindow != nil) {
log.Println("gui.Toolkit.Dump() uiWindow =", t.uiWindow)
}
@@ -144,6 +161,11 @@ func (t *Toolkit) Dump() {
log.Println("gui.Toolkit.Dump() uiSlider =", t.uiSlider)
}
if (t.OnExit != nil) {
- log.Println("gui.Toolkit.Dump() uiExit =", t.OnExit)
+ log.Println("gui.Toolkit.Dump() OnExit =", t.OnExit)
+ }
+ if (t.Custom != nil) {
+ log.Println("gui.Toolkit.Dump() Custom =", t.Custom)
}
+ log.Println("gui.Toolkit.Dump() c =", t.c)
+ log.Println("gui.Toolkit.Dump() val =", t.val)
}
diff --git a/toolkit/andlabs/tab.go b/toolkit/andlabs/tab.go
index c068022..922515d 100644
--- a/toolkit/andlabs/tab.go
+++ b/toolkit/andlabs/tab.go
@@ -25,21 +25,21 @@ func (t *Toolkit) AddTab(name string) *Toolkit {
var w *ui.Window
var newt *Toolkit
- log.Println("gui.Toolbox.AddTab() sleep 3")
+ log.Println("gui.toolkit.AddTab() sleep 3")
w = t.uiWindow
if (w == nil) {
- log.Println("gui.Toolbox.NewTab() node.UiWindow == nil. I can't add a tab without a window")
+ log.Println("gui.toolkit.NewTab() node.UiWindow == nil. I can't add a tab without a window")
return nil
}
if (t.uiTab == nil) {
// this means you have to make a new tab
- log.Println("gui.Toolbox.NewTab() GOOD. This should be the first tab:", name)
+ log.Println("gui.toolkit.NewTab() GOOD. This should be the first tab:", name)
newt = newTab(w, name)
t.uiTab = newt.uiTab
} else {
- log.Println("gui.Toolbox.NewTab() GOOD. This should be an additional tab:", name)
+ log.Println("gui.toolkit.NewTab() GOOD. This should be an additional tab:", name)
newt = t.appendTab(name)
// this means you have to append a tab
}
@@ -88,17 +88,17 @@ func tabSetMargined(tab *ui.Tab) {
}
func newTab(w *ui.Window, name string) *Toolkit {
- log.Println("gui.Toolbox.NewTab() ADD", name)
+ log.Println("gui.toolkit.NewTab() ADD", name)
var t Toolkit
if (w == nil) {
- log.Println("gui.Toolbox.NewTab() node.UiWindow == nil. I can't add a tab without a window")
- log.Println("gui.Toolbox.NewTab() node.UiWindow == nil. I can't add a tab without a window")
- log.Println("gui.Toolbox.NewTab() node.UiWindow == nil. I can't add a tab without a window")
+ log.Println("gui.toolkit.NewTab() node.UiWindow == nil. I can't add a tab without a window")
+ log.Println("gui.toolkit.NewTab() node.UiWindow == nil. I can't add a tab without a window")
+ log.Println("gui.toolkit.NewTab() node.UiWindow == nil. I can't add a tab without a window")
time.Sleep(1 * time.Second)
return nil
}
- log.Println("gui.Toolbox.AddTab() START name =", name)
+ log.Println("gui.toolkit.AddTab() START name =", name)
// time.Sleep(2 * time.Second)
tab := ui.NewTab()
w.SetMargined(true)
@@ -117,17 +117,17 @@ func newTab(w *ui.Window, name string) *Toolkit {
}
func (t *Toolkit) appendTab(name string) *Toolkit {
- log.Println("gui.Toolbox.NewTab() ADD", name)
+ log.Println("gui.toolkit.NewTab() ADD", name)
var newT Toolkit
if (t.uiWindow == nil) {
- log.Println("gui.Toolbox.NewTab() node.UiWindow == nil. I can't add a tab without a window")
- log.Println("gui.Toolbox.NewTab() node.UiWindow == nil. I can't add a tab without a window")
- log.Println("gui.Toolbox.NewTab() node.UiWindow == nil. I can't add a tab without a window")
+ log.Println("gui.toolkit.NewTab() node.UiWindow == nil. I can't add a tab without a window")
+ log.Println("gui.toolkit.NewTab() node.UiWindow == nil. I can't add a tab without a window")
+ log.Println("gui.toolkit.NewTab() node.UiWindow == nil. I can't add a tab without a window")
time.Sleep(1 * time.Second)
return nil
}
- log.Println("gui.Toolbox.AddTab() START name =", name)
+ log.Println("gui.toolkit.AddTab() START name =", name)
hbox := ui.NewHorizontalBox() // this makes everything go along the horizon
// hbox := ui.NewVerticalBox()
diff --git a/toolkit/andlabs/window.go b/toolkit/andlabs/window.go
index f0357ed..f09a810 100644
--- a/toolkit/andlabs/window.go
+++ b/toolkit/andlabs/window.go
@@ -2,7 +2,6 @@ package toolkit
import (
"log"
- "os"
"github.com/andlabs/ui"
_ "github.com/andlabs/ui/winmanifest"
@@ -33,8 +32,6 @@ func NewWindow(title string, x int, y int) *Toolkit {
t.Custom()
}
log.Println("ui.Window().OnExit() Toolkit.OnExit is nil")
- t.Dump()
- os.Exit(0)
return true
})
w.SetMargined(true)
@@ -43,3 +40,13 @@ func NewWindow(title string, x int, y int) *Toolkit {
t.UiWindowBad = w // deprecate this as soon as possible
return &t
}
+
+func (t *Toolkit) SetWindowTitle(title string) {
+ log.Println("toolkit NewWindow", t.Name, "title", title)
+ win := t.uiWindow
+ if (win != nil) {
+ win.SetTitle(title)
+ } else {
+ log.Println("Setting the window title", title)
+ }
+}