diff --git a/button.go b/button.go index bf36f23..24dcd49 100644 --- a/button.go +++ b/button.go @@ -88,3 +88,28 @@ func CreateFontButton(box *GuiBox, action string) *GuiButton { }) return &newGB } + +func CreateColorButton(box *GuiBox, custom func(*GuiButton), name string, values interface {}) *GuiButton { + // create a 'fake' button entry for the mouse clicks + var newCB GuiButton + newCB.Name = name + newCB.CB = ui.NewColorButton() + newCB.Box = box + newCB.Custom = custom + newCB.Values = values + + Data.AllButtons = append(Data.AllButtons, &newCB) + + newCB.CB.OnChanged(func (*ui.ColorButton) { + log.Println("ColorButton.OnChanged() START Color Button Click") + r, g, b, a := newCB.CB.Color() + log.Println("ColorButton.OnChanged() Color() =", r, g, b, a) + if (newCB.Custom != nil) { + newCB.Custom(&newCB) + } else if (Data.MouseClick != nil) { + Data.MouseClick(&newCB) + } + }) + box.UiBox.Append(newCB.CB, false) + return &newCB +} diff --git a/color.go b/color.go new file mode 100644 index 0000000..cf4a362 --- /dev/null +++ b/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/debug.go b/debug.go index a8cf03c..5c25248 100644 --- a/debug.go +++ b/debug.go @@ -41,15 +41,9 @@ func DumpBoxes() { log.Println("gui.DumpBoxes()\tWindow.UiTab =", window.UiTab) pages := window.UiTab.NumPages() log.Println("gui.DumpBoxes()\tWindow.UiTab.NumPages() =", pages) - for i := 0; i < pages; i++ { - log.Println("gui.DumpBoxes()\t\tWindow.UiTab.Margined(", i, ") =") - log.Println(window.UiTab.Margined(i)) - /* - if (window.UiTab.Margined(i)) { - window.UiTab.SetMargined(i, false) - } - */ - } + // for i := 0; i < pages; i++ { + // log.Println("gui.DumpBoxes()\t\tWindow.UiTab.Margined(", i, ") =", window.UiTab.Margined(i)) + // } // tmp := spew.NewDefaultConfig() // tmp.MaxDepth = 2 // tmp.Dump(window.UiTab) @@ -60,7 +54,7 @@ func DumpBoxes() { } } for i, window := range Data.Windows { - log.Println("gui.DumpBoxes() Data.Windows", i, "Name =", window.Name) + log.Println("gui.DumpBoxes() Data.Windows", i, "Name =", window.Name, "TabNumber =", window.TabNumber) for name, abox := range window.BoxMap { log.Printf("gui.DumpBoxes() \tBOX mapname=%-12s abox.Name=%-12s", name, abox.Name) if (name == "MAINBOX") { @@ -74,7 +68,7 @@ func DumpBoxes() { if (name == "DEBUG") { log.Println("\t\twatchGUI() BOX abox =", reflect.TypeOf(abox)) win := abox.Window - log.Println("\t\twatchGUI() BOX win =", reflect.TypeOf(win)) + log.Println("\t\twatchGUI() BOX win =", reflect.TypeOf(win)) area := win.Area log.Println("\t\twatchGUI() BOX area =", reflect.TypeOf(area), area.UiArea) // spew.Dump(area.UiArea) diff --git a/structs.go b/structs.go index 656ece3..d4f41f2 100644 --- a/structs.go +++ b/structs.go @@ -64,6 +64,7 @@ type GuiWindow struct { 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(*GuiWindow) *GuiBox @@ -100,10 +101,12 @@ type GuiButton struct { // 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 } // text entry fields diff --git a/tableCallbacks.go b/tableCallbacks.go index 954a832..966f173 100644 --- a/tableCallbacks.go +++ b/tableCallbacks.go @@ -29,18 +29,6 @@ func (mh *TableData) ColumnTypes(m *ui.TableModel) []ui.TableValue { return mh.generatedColumnTypes } -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} -} - // TODO: Figure out why this is being called 1000 times a second (10 times for each row & column) // Nevermind this 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 {