CLEAN: remove GuiButton struct
This commit is contained in:
parent
51d324e805
commit
8c1c837879
41
area.go
41
area.go
|
@ -7,30 +7,14 @@ import _ "github.com/andlabs/ui/winmanifest"
|
||||||
|
|
||||||
import "github.com/davecgh/go-spew/spew"
|
import "github.com/davecgh/go-spew/spew"
|
||||||
|
|
||||||
func makeGenericArea(n *Node, newText *ui.AttributedString, custom func(*GuiButton)) {
|
|
||||||
// make this button just to get the default font (but don't display the button)
|
// make this button just to get the default font (but don't display the button)
|
||||||
// There should be another way to do this (?)
|
// There should be another way to do this (?)
|
||||||
var newB *GuiButton
|
func (n *Node) makeGenericArea(newText *ui.AttributedString, custom func(*Node)) {
|
||||||
newB = CreateFontButton(n, "AREA")
|
newNode := n.CreateFontButton("AREA")
|
||||||
newB.Custom = custom
|
newNode.custom = custom
|
||||||
|
|
||||||
/*
|
|
||||||
gw := n.window
|
|
||||||
// initialize the GuiArea{}
|
|
||||||
gw.Area.Button = newB
|
|
||||||
*/
|
|
||||||
area := new(GuiArea)
|
area := new(GuiArea)
|
||||||
|
newNode.uiArea = ui.NewArea(area)
|
||||||
// gw.Area.Box = gb
|
newNode.uiAttrstr = newText
|
||||||
n.uiAttrstr = newText
|
|
||||||
n.uiArea = ui.NewArea(area)
|
|
||||||
|
|
||||||
if (Config.Debug) {
|
|
||||||
spew.Dump(n.uiArea)
|
|
||||||
log.Println("DEBUGGING", Config.Debug)
|
|
||||||
} else {
|
|
||||||
log.Println("NOT DEBUGGING AREA mhAH.Button =", n.uiButton)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func AreaAppendText(newText *ui.AttributedString, what string, attrs ...ui.Attribute) {
|
func AreaAppendText(newText *ui.AttributedString, what string, attrs ...ui.Attribute) {
|
||||||
|
@ -54,7 +38,7 @@ func appendWithAttributes(newText *ui.AttributedString, what string, attrs ...ui
|
||||||
func (ah GuiArea) Draw(a *ui.Area, p *ui.AreaDrawParams) {
|
func (ah GuiArea) Draw(a *ui.Area, p *ui.AreaDrawParams) {
|
||||||
tl := ui.DrawNewTextLayout(&ui.DrawTextLayoutParams{
|
tl := ui.DrawNewTextLayout(&ui.DrawTextLayoutParams{
|
||||||
String: ah.UiAttrstr,
|
String: ah.UiAttrstr,
|
||||||
DefaultFont: ah.Button.FB.Font(),
|
DefaultFont: ah.N.uiFontButton.Font(),
|
||||||
Width: p.AreaWidth,
|
Width: p.AreaWidth,
|
||||||
Align: ui.DrawTextAlign(1),
|
Align: ui.DrawTextAlign(1),
|
||||||
})
|
})
|
||||||
|
@ -63,6 +47,7 @@ func (ah GuiArea) Draw(a *ui.Area, p *ui.AreaDrawParams) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ah GuiArea) MouseEvent(a *ui.Area, me *ui.AreaMouseEvent) {
|
func (ah GuiArea) MouseEvent(a *ui.Area, me *ui.AreaMouseEvent) {
|
||||||
|
/*
|
||||||
if (Config.Debug) {
|
if (Config.Debug) {
|
||||||
log.Println("GOT MouseEvent() ah.Button =", ah.Button)
|
log.Println("GOT MouseEvent() ah.Button =", ah.Button)
|
||||||
spew.Dump(me)
|
spew.Dump(me)
|
||||||
|
@ -82,6 +67,7 @@ func (ah GuiArea) MouseEvent(a *ui.Area, me *ui.AreaMouseEvent) {
|
||||||
Data.MouseClick(ah.Button)
|
Data.MouseClick(ah.Button)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ah GuiArea) MouseCrossed(a *ui.Area, left bool) {
|
func (ah GuiArea) MouseCrossed(a *ui.Area, left bool) {
|
||||||
|
@ -109,21 +95,14 @@ func (ah GuiArea) KeyEvent(a *ui.Area, ke *ui.AreaKeyEvent) (handled bool) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *Node) ShowTextBox(newText *ui.AttributedString, custom func(*GuiButton), name string) {
|
func (n *Node) ShowTextBox(newText *ui.AttributedString, custom func(*Node), name string) {
|
||||||
log.Println("ShowTextBox() START")
|
log.Println("ShowTextBox() START")
|
||||||
|
|
||||||
gw := n.Window
|
|
||||||
if (gw == nil) {
|
|
||||||
log.Println("ShowTextBox() ERROR gw = nil")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
log.Println("ShowTextBox() START gw =", gw)
|
|
||||||
|
|
||||||
// TODO: allow padded & axis here
|
// TODO: allow padded & axis here
|
||||||
n.uiBox.SetPadded(true)
|
n.uiBox.SetPadded(true)
|
||||||
|
|
||||||
// add(gw.BoxMap["MAINBOX"], newbox)
|
// add(gw.BoxMap["MAINBOX"], newbox)
|
||||||
|
|
||||||
makeGenericArea(n, newText, custom)
|
n.makeGenericArea(newText, custom)
|
||||||
n.uiBox.Append(n.area.UiArea, true)
|
n.uiBox.Append(n.area.UiArea, true)
|
||||||
}
|
}
|
||||||
|
|
49
button.go
49
button.go
|
@ -2,6 +2,7 @@ package gui
|
||||||
|
|
||||||
import "log"
|
import "log"
|
||||||
import "reflect"
|
import "reflect"
|
||||||
|
// import "image/color"
|
||||||
import "github.com/andlabs/ui"
|
import "github.com/andlabs/ui"
|
||||||
import _ "github.com/andlabs/ui/winmanifest"
|
import _ "github.com/andlabs/ui/winmanifest"
|
||||||
// import "github.com/davecgh/go-spew/spew"
|
// import "github.com/davecgh/go-spew/spew"
|
||||||
|
@ -45,44 +46,38 @@ func (n *Node) AddButton(name string, custom func(*Node)) *Node {
|
||||||
return newNode
|
return newNode
|
||||||
}
|
}
|
||||||
|
|
||||||
func CreateFontButton(n *Node, action string) *GuiButton {
|
func (n *Node) CreateFontButton(action string) *Node {
|
||||||
// create a 'fake' button entry for the mouse clicks
|
// create a 'fake' button entry for the mouse clicks
|
||||||
var newGB GuiButton
|
// var newGB GuiButton
|
||||||
newGB.Name = "FONT"
|
// newGB.Name = "FONT"
|
||||||
newGB.FB = ui.NewFontButton()
|
n.uiFontButton = ui.NewFontButton()
|
||||||
// newGB.Box = n.box
|
// newGB.Box = n.box
|
||||||
Data.AllButtons = append(Data.AllButtons, &newGB)
|
// Data.AllButtons = append(Data.AllButtons, &newGB)
|
||||||
|
|
||||||
newGB.FB.OnChanged(func (*ui.FontButton) {
|
n.uiFontButton.OnChanged(func (*ui.FontButton) {
|
||||||
log.Println("FontButton.OnChanged() START mouseClick(&newBM)", newGB)
|
log.Println("FontButton.OnChanged() START")
|
||||||
if (Data.MouseClick != nil) {
|
n.Dump()
|
||||||
Data.MouseClick(&newGB)
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
return &newGB
|
return n
|
||||||
}
|
}
|
||||||
|
|
||||||
func CreateColorButton(n *Node, custom func(*GuiButton), name string, values interface {}) *GuiButton {
|
func (n *Node) CreateColorButton(custom func(*Node), name string, values interface {}) *Node {
|
||||||
// create a 'fake' button entry for the mouse clicks
|
// create a 'fake' button entry for the mouse clicks
|
||||||
var newCB GuiButton
|
n.uiColorButton = ui.NewColorButton()
|
||||||
newCB.Name = name
|
n.custom = custom
|
||||||
newCB.CB = ui.NewColorButton()
|
n.values = values
|
||||||
// newCB.Box = n.box
|
|
||||||
newCB.Custom = custom
|
|
||||||
newCB.Values = values
|
|
||||||
|
|
||||||
Data.AllButtons = append(Data.AllButtons, &newCB)
|
n.uiColorButton.OnChanged(func (*ui.ColorButton) {
|
||||||
|
|
||||||
newCB.CB.OnChanged(func (*ui.ColorButton) {
|
|
||||||
log.Println("ColorButton.OnChanged() START Color Button Click")
|
log.Println("ColorButton.OnChanged() START Color Button Click")
|
||||||
r, g, b, a := newCB.CB.Color()
|
rgba := n.Color
|
||||||
|
r, g, b, a := rgba.R, rgba.G, rgba.B, rgba.A
|
||||||
log.Println("ColorButton.OnChanged() Color() =", r, g, b, a)
|
log.Println("ColorButton.OnChanged() Color() =", r, g, b, a)
|
||||||
if (newCB.Custom != nil) {
|
if (n.custom != nil) {
|
||||||
newCB.Custom(&newCB)
|
n.custom(n)
|
||||||
} else if (Data.MouseClick != nil) {
|
} else if (Data.MouseClick != nil) {
|
||||||
Data.MouseClick(&newCB)
|
Data.MouseClick(n)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
n.uiBox.Append(newCB.CB, false)
|
n.uiBox.Append(n.uiColorButton, false)
|
||||||
return &newCB
|
return n
|
||||||
}
|
}
|
||||||
|
|
2
gui.go
2
gui.go
|
@ -16,7 +16,7 @@ const Yaxis = 1 // box that is vertical
|
||||||
func init() {
|
func init() {
|
||||||
log.Println("gui.init() has been run")
|
log.Println("gui.init() has been run")
|
||||||
|
|
||||||
Data.buttonMap = make(map[*ui.Button]*GuiButton)
|
// Data.buttonMap = make(map[*ui.Button]*GuiButton)
|
||||||
Data.NodeMap = make(map[string]*Node)
|
Data.NodeMap = make(map[string]*Node)
|
||||||
|
|
||||||
Data.NodeSlice = make([]*Node, 0)
|
Data.NodeSlice = make([]*Node, 0)
|
||||||
|
|
|
@ -3,6 +3,7 @@ package gui
|
||||||
import (
|
import (
|
||||||
"log"
|
"log"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"image/color"
|
||||||
// "reflect"
|
// "reflect"
|
||||||
|
|
||||||
// "github.com/davecgh/go-spew/spew"
|
// "github.com/davecgh/go-spew/spew"
|
||||||
|
@ -45,15 +46,19 @@ type Node struct {
|
||||||
Width int
|
Width int
|
||||||
Height int
|
Height int
|
||||||
OnChanged func ()
|
OnChanged func ()
|
||||||
|
Color color.RGBA
|
||||||
|
|
||||||
parent *Node
|
parent *Node
|
||||||
children []*Node
|
children []*Node
|
||||||
|
|
||||||
area *GuiArea
|
area *GuiArea
|
||||||
custom func(*Node)
|
custom func(*Node)
|
||||||
|
values interface {}
|
||||||
|
|
||||||
uiControl *ui.Control
|
uiControl *ui.Control
|
||||||
uiButton *ui.Button
|
uiButton *ui.Button
|
||||||
|
uiFontButton *ui.FontButton
|
||||||
|
uiColorButton *ui.ColorButton
|
||||||
uiWindow *ui.Window
|
uiWindow *ui.Window
|
||||||
uiAttrstr *ui.AttributedString
|
uiAttrstr *ui.AttributedString
|
||||||
uiTab *ui.Tab
|
uiTab *ui.Tab
|
||||||
|
|
19
structs.go
19
structs.go
|
@ -38,7 +38,7 @@ type GuiConfig struct {
|
||||||
type GuiData struct {
|
type GuiData struct {
|
||||||
// a fallback default function to handle mouse events
|
// a fallback default function to handle mouse events
|
||||||
// if nothing else is defined to handle them
|
// if nothing else is defined to handle them
|
||||||
MouseClick func(*GuiButton)
|
MouseClick func(*Node)
|
||||||
|
|
||||||
// A map of all the entry boxes
|
// A map of all the entry boxes
|
||||||
AllEntries []*GuiEntry
|
AllEntries []*GuiEntry
|
||||||
|
@ -55,16 +55,19 @@ type GuiData struct {
|
||||||
//
|
//
|
||||||
// This has to work this way because of how
|
// This has to work this way because of how
|
||||||
// andlabs/ui & andlabs/libui work
|
// andlabs/ui & andlabs/libui work
|
||||||
AllButtons []*GuiButton
|
// AllButtons []*GuiButton
|
||||||
buttonMap map[*ui.Button]*GuiButton
|
// buttonMap map[*ui.Button]*GuiButton
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
type GuiTab struct {
|
type GuiTab struct {
|
||||||
Name string // field for human readable name
|
Name string // field for human readable name
|
||||||
Number int // the andlabs/ui tab index
|
Number int // the andlabs/ui tab index
|
||||||
// Window *GuiWindow // the parent Window
|
// Window *GuiWindow // the parent Window
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
// Note: every mouse click is handled
|
// Note: every mouse click is handled
|
||||||
// as a 'Button' regardless of where
|
// as a 'Button' regardless of where
|
||||||
// the user clicks it. You could probably
|
// the user clicks it. You could probably
|
||||||
|
@ -82,6 +85,7 @@ type GuiButton struct {
|
||||||
FB *ui.FontButton
|
FB *ui.FontButton
|
||||||
CB *ui.ColorButton
|
CB *ui.ColorButton
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
// text entry fields
|
// text entry fields
|
||||||
type GuiEntry struct {
|
type GuiEntry struct {
|
||||||
|
@ -90,7 +94,8 @@ type GuiEntry struct {
|
||||||
Last string // the last value
|
Last string // the last value
|
||||||
Normalize func(string) string // function to 'normalize' the data
|
Normalize func(string) string // function to 'normalize' the data
|
||||||
|
|
||||||
B *GuiButton
|
// B *GuiButton
|
||||||
|
N *Node
|
||||||
|
|
||||||
// andlabs/ui abstraction mapping
|
// andlabs/ui abstraction mapping
|
||||||
UiEntry *ui.Entry
|
UiEntry *ui.Entry
|
||||||
|
@ -102,7 +107,8 @@ type GuiEntry struct {
|
||||||
// AREA STRUCTURES START
|
// AREA STRUCTURES START
|
||||||
//
|
//
|
||||||
type GuiArea struct {
|
type GuiArea struct {
|
||||||
Button *GuiButton // what button handles mouse events
|
// Button *GuiButton // what button handles mouse events
|
||||||
|
N *Node // what button handles mouse events
|
||||||
|
|
||||||
UiAttrstr *ui.AttributedString
|
UiAttrstr *ui.AttributedString
|
||||||
UiArea *ui.Area
|
UiArea *ui.Area
|
||||||
|
@ -167,7 +173,8 @@ type HumanCellData struct {
|
||||||
TextID int
|
TextID int
|
||||||
Color color.RGBA
|
Color color.RGBA
|
||||||
ColorID int
|
ColorID int
|
||||||
Button *GuiButton
|
// Button *GuiButton
|
||||||
|
N *Node
|
||||||
}
|
}
|
||||||
|
|
||||||
type HumanMap struct {
|
type HumanMap struct {
|
||||||
|
|
|
@ -95,10 +95,12 @@ func defaultSetCellValue(mh *TableData, row int, column int) {
|
||||||
humanID := mh.Cells[column].HumanID
|
humanID := mh.Cells[column].HumanID
|
||||||
log.Println("defaultSetCellValue() FOUND THE TABLE BUTTON ", row, humanID)
|
log.Println("defaultSetCellValue() FOUND THE TABLE BUTTON ", row, humanID)
|
||||||
|
|
||||||
button := mh.Rows[row].HumanData[humanID].Button
|
n := mh.Rows[row].HumanData[humanID].N
|
||||||
if (button != nil) {
|
if (n != nil) {
|
||||||
// TODO: fixme. removed on Oct 31 2021
|
// TODO: fixme. removed on Oct 31 2021
|
||||||
// guiButtonClick(button)
|
if (n.OnChanged != nil) {
|
||||||
|
n.OnChanged()
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
log.Println("defaultSetCellValue() ERROR: UNKNOWN BUTTON IN TABLE")
|
log.Println("defaultSetCellValue() ERROR: UNKNOWN BUTTON IN TABLE")
|
||||||
|
|
Loading…
Reference in New Issue