reimplement the color button

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2019-06-05 10:01:36 -07:00
parent 9bfabef760
commit 999a8fd199
5 changed files with 64 additions and 23 deletions

View File

@ -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
}

31
color.go Normal file
View File

@ -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}
}
*/

View File

@ -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)

View File

@ -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

View File

@ -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 {