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-01 00:28:02 -05:00
|
|
|
// THIS IS CLEAN
|
2019-05-29 11:54:46 -05:00
|
|
|
|
2019-06-01 23:15:55 -05:00
|
|
|
func makeGenericArea(gb *GuiBox, newText *ui.AttributedString) {
|
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-01 14:43:40 -05:00
|
|
|
newB.GW = gb.Window
|
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-05-23 15:13:42 -05:00
|
|
|
if (Data.Debug) {
|
2019-06-01 15:41:45 -05:00
|
|
|
spew.Dump(gw.Area.UiArea)
|
2019-05-23 15:13:42 -05:00
|
|
|
log.Println("DEBUGGING", Data.Debug)
|
|
|
|
} 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-05-23 15:44:53 -05:00
|
|
|
if (Data.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-01 04:58:49 -05:00
|
|
|
if (Data.MouseClick != nil) {
|
|
|
|
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
|
|
|
|
|
|
|
func ShowTextBox(gw *GuiWindow, newText *ui.AttributedString) *GuiBox {
|
|
|
|
log.Println("ShowTextBox() START")
|
|
|
|
if (gw == nil) {
|
|
|
|
log.Println("ShowTextBox() ERROR gw = nil")
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
log.Println("ShowTextBox() START gw =", gw)
|
|
|
|
|
2019-06-01 23:15:55 -05:00
|
|
|
box := InitGuiBox(gw, nil, ui.NewVerticalBox(), "SplashArea3")
|
2019-06-01 03:20:20 -05:00
|
|
|
|
2019-06-01 23:15:55 -05:00
|
|
|
makeGenericArea(box, newText)
|
|
|
|
box.UiBox.Append(box.Window.Area.UiArea, true)
|
2019-06-01 03:20:20 -05:00
|
|
|
|
2019-06-01 23:15:55 -05:00
|
|
|
return box
|
2019-06-01 03:20:20 -05:00
|
|
|
}
|