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