2019-05-22 20:35:00 -05:00
|
|
|
package gui
|
|
|
|
|
|
|
|
import "log"
|
|
|
|
|
|
|
|
import "github.com/andlabs/ui"
|
|
|
|
import _ "github.com/andlabs/ui/winmanifest"
|
|
|
|
|
|
|
|
import "github.com/davecgh/go-spew/spew"
|
|
|
|
|
2019-06-02 00:24:10 -05:00
|
|
|
func makeGenericArea(gb *GuiBox, newText *ui.AttributedString, custom func(*GuiButton)) {
|
2019-05-22 20:35:00 -05:00
|
|
|
// make this button just to get the default font (but don't display the button)
|
|
|
|
// There should be another way to do this (?)
|
2019-05-31 19:37:53 -05:00
|
|
|
var newB *GuiButton
|
2019-06-01 00:28:02 -05:00
|
|
|
newB = CreateFontButton(gb, "AREA")
|
|
|
|
newB.Box = gb
|
2019-06-02 17:19:53 -05:00
|
|
|
newB.Custom = custom
|
2019-05-31 19:37:53 -05:00
|
|
|
|
2019-06-01 15:41:45 -05:00
|
|
|
gw := gb.Window
|
2019-05-31 19:37:53 -05:00
|
|
|
// initialize the GuiArea{}
|
2019-06-01 15:41:45 -05:00
|
|
|
gw.Area = new(GuiArea)
|
|
|
|
gw.Area.Button = newB
|
|
|
|
gw.Area.Box = gb
|
|
|
|
gw.Area.UiAttrstr = newText
|
|
|
|
gw.Area.UiArea = ui.NewArea(gw.Area)
|
2019-05-22 20:35:00 -05:00
|
|
|
|
2019-06-02 17:49:52 -05:00
|
|
|
if (Config.Debug) {
|
2019-06-01 15:41:45 -05:00
|
|
|
spew.Dump(gw.Area.UiArea)
|
2019-06-02 17:49:52 -05:00
|
|
|
log.Println("DEBUGGING", Config.Debug)
|
2019-05-23 15:13:42 -05:00
|
|
|
} else {
|
2019-06-01 15:41:45 -05:00
|
|
|
log.Println("NOT DEBUGGING AREA mhAH.Button =", gw.Area.Button)
|
2019-05-23 15:13:42 -05:00
|
|
|
}
|
2019-05-22 20:35:00 -05:00
|
|
|
}
|
|
|
|
|
2019-05-29 13:25:25 -05:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-29 09:24:40 -05:00
|
|
|
func appendWithAttributes(newText *ui.AttributedString, what string, attrs ...ui.Attribute) {
|
|
|
|
start := len(newText.String())
|
2019-05-22 20:35:00 -05:00
|
|
|
end := start + len(what)
|
2019-05-29 09:24:40 -05:00
|
|
|
newText.AppendUnattributed(what)
|
2019-05-22 20:35:00 -05:00
|
|
|
for _, a := range attrs {
|
2019-05-29 09:24:40 -05:00
|
|
|
newText.SetAttribute(a, start, end)
|
2019-05-22 20:35:00 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-30 11:19:49 -05:00
|
|
|
func (ah GuiArea) Draw(a *ui.Area, p *ui.AreaDrawParams) {
|
2019-05-22 20:35:00 -05:00
|
|
|
tl := ui.DrawNewTextLayout(&ui.DrawTextLayoutParams{
|
2019-05-30 11:58:05 -05:00
|
|
|
String: ah.UiAttrstr,
|
2019-05-29 13:32:07 -05:00
|
|
|
DefaultFont: ah.Button.FB.Font(),
|
2019-05-22 20:35:00 -05:00
|
|
|
Width: p.AreaWidth,
|
|
|
|
Align: ui.DrawTextAlign(1),
|
|
|
|
})
|
|
|
|
p.Context.Text(tl, 0, 0)
|
|
|
|
defer tl.Free()
|
|
|
|
}
|
|
|
|
|
2019-05-30 11:19:49 -05:00
|
|
|
func (ah GuiArea) MouseEvent(a *ui.Area, me *ui.AreaMouseEvent) {
|
2019-06-02 17:49:52 -05:00
|
|
|
if (Config.Debug) {
|
2019-05-29 13:32:07 -05:00
|
|
|
log.Println("GOT MouseEvent() ah.Button =", ah.Button)
|
2019-05-23 15:44:53 -05:00
|
|
|
spew.Dump(me)
|
|
|
|
}
|
2019-05-22 20:35:00 -05:00
|
|
|
if (me.Down == 1) {
|
|
|
|
log.Println("GOT MOUSE DOWN")
|
2019-05-29 13:32:07 -05:00
|
|
|
log.Println("GOT MOUSE DOWN ah.Button =", ah.Button)
|
|
|
|
log.Println("GOT MOUSE UP ah.Button.FB =", ah.Button.FB)
|
2019-05-22 20:35:00 -05:00
|
|
|
}
|
|
|
|
if (me.Up == 1) {
|
|
|
|
log.Println("GOT MOUSE UP")
|
2019-05-29 13:07:14 -05:00
|
|
|
log.Println("GOT MOUSE UP ah.Button =", ah.Button)
|
2019-05-29 13:32:07 -05:00
|
|
|
log.Println("GOT MOUSE UP ah.Button.FB =", ah.Button.FB)
|
2019-06-02 17:19:53 -05:00
|
|
|
if (ah.Button.Custom != nil) {
|
|
|
|
ah.Button.Custom(ah.Button)
|
2019-06-02 00:24:10 -05:00
|
|
|
} else if (Data.MouseClick != nil) {
|
2019-06-01 04:58:49 -05:00
|
|
|
Data.MouseClick(ah.Button)
|
|
|
|
}
|
2019-05-22 20:35:00 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-30 11:19:49 -05:00
|
|
|
func (ah GuiArea) MouseCrossed(a *ui.Area, left bool) {
|
2019-05-22 20:35:00 -05:00
|
|
|
log.Println("GOT MouseCrossed()")
|
|
|
|
}
|
|
|
|
|
2019-05-30 11:19:49 -05:00
|
|
|
func (ah GuiArea) DragBroken(a *ui.Area) {
|
2019-05-22 20:35:00 -05:00
|
|
|
log.Println("GOT DragBroken()")
|
|
|
|
}
|
|
|
|
|
2019-06-01 00:28:02 -05:00
|
|
|
// TODO: fix KeyEvents
|
2019-05-30 11:19:49 -05:00
|
|
|
func (ah GuiArea) KeyEvent(a *ui.Area, ke *ui.AreaKeyEvent) (handled bool) {
|
2019-05-22 20:35:00 -05:00
|
|
|
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
|
|
|
|
}
|
2019-06-01 03:20:20 -05:00
|
|
|
|
2019-06-13 15:28:13 -05:00
|
|
|
func ShowTextBox(box *GuiBox, newText *ui.AttributedString, custom func(*GuiButton), name string) {
|
2019-06-01 03:20:20 -05:00
|
|
|
log.Println("ShowTextBox() START")
|
2019-06-13 15:28:13 -05:00
|
|
|
gw := box.Window
|
2019-06-01 03:20:20 -05:00
|
|
|
if (gw == nil) {
|
|
|
|
log.Println("ShowTextBox() ERROR gw = nil")
|
2019-06-13 15:28:13 -05:00
|
|
|
return
|
2019-06-01 03:20:20 -05:00
|
|
|
}
|
|
|
|
log.Println("ShowTextBox() START gw =", gw)
|
|
|
|
|
2019-06-13 15:28:13 -05:00
|
|
|
/*
|
2019-06-02 21:49:17 -05:00
|
|
|
var newbox *GuiBox
|
|
|
|
newbox = new(GuiBox)
|
|
|
|
newbox.Window = gw
|
2019-06-03 14:56:33 -05:00
|
|
|
newbox.Name = name
|
2019-06-02 21:49:17 -05:00
|
|
|
hbox := ui.NewVerticalBox()
|
|
|
|
newbox.UiBox = hbox
|
2019-06-01 03:20:20 -05:00
|
|
|
|
2019-06-02 21:49:17 -05:00
|
|
|
// TODO: allow padded & axis here
|
|
|
|
hbox.SetPadded(true)
|
2019-06-13 15:28:13 -05:00
|
|
|
*/
|
2019-06-01 03:20:20 -05:00
|
|
|
|
2019-06-13 15:28:13 -05:00
|
|
|
// add(gw.BoxMap["MAINBOX"], newbox)
|
2019-06-02 21:49:17 -05:00
|
|
|
|
2019-06-13 15:28:13 -05:00
|
|
|
makeGenericArea(box, newText, custom)
|
|
|
|
box.UiBox.Append(box.Window.Area.UiArea, true)
|
2019-06-01 03:20:20 -05:00
|
|
|
}
|