Removed WindowHandler.
This commit is contained in:
parent
f4963e909b
commit
969700f790
|
@ -9,7 +9,6 @@ type cSysData struct {
|
|||
spaced bool
|
||||
alternate bool // editable for Combobox, multi-select for listbox, password for lineedit
|
||||
handler AreaHandler // for Areas; TODO rename to areahandler
|
||||
winhandler WindowHandler // for Windows
|
||||
close func() bool // provided by each Window
|
||||
event func() // provided by each control
|
||||
}
|
||||
|
|
|
@ -73,15 +73,11 @@ func (a *keyboardArea) Key(e KeyEvent) (repaint bool) {
|
|||
return true
|
||||
}
|
||||
|
||||
type kbhandler struct{}
|
||||
func (kbhandler) Event(e Event, d interface{}) {
|
||||
}
|
||||
|
||||
var doKeyboard = flag.Bool("kb", false, "run keyboard test (overrides -areabounds)")
|
||||
func kbTest() {
|
||||
wid, ht, ah := mkkbArea()
|
||||
a := NewArea(wid, ht, ah)
|
||||
w := NewWindow("Hi", wid, ht, kbhandler{})
|
||||
w := NewWindow("Hi", wid, ht)
|
||||
w.Closing = func() bool { return true }
|
||||
w.Open(a)
|
||||
}
|
||||
|
|
49
test/main.go
49
test/main.go
|
@ -15,9 +15,6 @@ import (
|
|||
. "github.com/andlabs/ui"
|
||||
)
|
||||
|
||||
type nullwinhandler struct{}
|
||||
func (nullwinhandler) Event(Event, interface{}) {}
|
||||
|
||||
func die() bool {
|
||||
// TODO we want the bool return to happen before the Stop...
|
||||
Stop <- struct{}{}
|
||||
|
@ -28,14 +25,14 @@ var prefsizetest = flag.Bool("prefsize", false, "")
|
|||
func listboxPreferredSizeTest() *Window {
|
||||
lb := NewListbox("xxxxx", "y", "zzz")
|
||||
g := NewGrid(1, lb)
|
||||
w := NewWindow("Listbox Preferred Size Test", 300, 300, nullwinhandler{})
|
||||
w := NewWindow("Listbox Preferred Size Test", 300, 300)
|
||||
w.Open(g)
|
||||
return w
|
||||
}
|
||||
|
||||
var gridtest = flag.Bool("grid", false, "")
|
||||
func gridWindow() *Window {
|
||||
w := NewWindow("Grid Test", 400, 400, nullwinhandler{})
|
||||
w := NewWindow("Grid Test", 400, 400)
|
||||
b00 := NewButton("0,0")
|
||||
b01 := NewButton("0,1")
|
||||
b02 := NewButton("0,2")
|
||||
|
@ -250,16 +247,7 @@ func areaTest() {
|
|||
timedisp,
|
||||
sizeStack)
|
||||
layout.SetStretchy(0)
|
||||
w := NewWindow("Area Test", 100, 100, &areatestwinhandler{
|
||||
areahandler: areahandler,
|
||||
a: a,
|
||||
timedisp: timedisp,
|
||||
widthbox: widthbox,
|
||||
heightbox: heightbox,
|
||||
resize: resize,
|
||||
modaltest: modaltest,
|
||||
repainttest: repainttest,
|
||||
})
|
||||
w := NewWindow("Area Test", 100, 100)
|
||||
w.Closing = die
|
||||
w.Open(layout)
|
||||
go func() {
|
||||
|
@ -271,19 +259,6 @@ func areaTest() {
|
|||
}()
|
||||
}
|
||||
|
||||
type areatestwinhandler struct {
|
||||
areahandler *areaHandler
|
||||
a *Area
|
||||
timedisp *Label
|
||||
widthbox *LineEdit
|
||||
heightbox *LineEdit
|
||||
resize *Button
|
||||
modaltest *Button
|
||||
repainttest *Button
|
||||
}
|
||||
func (a *areatestwinhandler) Event(e Event, d interface{}) {
|
||||
}
|
||||
|
||||
var areabounds = flag.Bool("areabounds", false, "run area bounds test instead")
|
||||
func areaboundsTest() {
|
||||
img := image.NewRGBA(image.Rect(0, 0, 320, 240))
|
||||
|
@ -308,9 +283,7 @@ func areaboundsTest() {
|
|||
// middle purple
|
||||
r.Min.Y++
|
||||
draw.Draw(img, r, u(128, 0, 128), image.ZP, draw.Over)
|
||||
w := NewWindow("Area Bounds Test", 320, 240, &areatestwinhandler{
|
||||
a: a,
|
||||
})
|
||||
w := NewWindow("Area Bounds Test", 320, 240)
|
||||
w.Closing = die
|
||||
w.Open(a)
|
||||
}
|
||||
|
@ -367,7 +340,7 @@ type testwinhandler struct {
|
|||
|
||||
func runMainTest() {
|
||||
handler := new(testwinhandler)
|
||||
handler.w = NewWindow("Main Window", 320, 240, handler)
|
||||
handler.w = NewWindow("Main Window", 320, 240)
|
||||
handler.w.Closing = func() bool {
|
||||
println("window closed event received")
|
||||
return die()
|
||||
|
@ -441,7 +414,7 @@ func runMainTest() {
|
|||
bCenter: centerButton,
|
||||
// send: w.Send,
|
||||
}
|
||||
dh.w = NewWindow("Dialogs", 200, 200, dh)
|
||||
dh.w = NewWindow("Dialogs", 200, 200)
|
||||
dh.setUpEvents()
|
||||
if *dialogTest {
|
||||
s := NewVerticalStack(
|
||||
|
@ -482,13 +455,10 @@ func runMainTest() {
|
|||
NewButton("Button"),
|
||||
s)
|
||||
s.SetStretchy(4)
|
||||
NewWindow("Label Align Test", 500, 300, nullwinhandler{}).Open(s)
|
||||
NewWindow("Label Align Test", 500, 300).Open(s)
|
||||
}
|
||||
}
|
||||
|
||||
// TODO
|
||||
func (handler *testwinhandler) Event(Event,interface{}){}
|
||||
|
||||
func (handler *testwinhandler) setUpEvents() {
|
||||
handler.b.Clicked = func() {
|
||||
handler.w.SetTitle(fmt.Sprintf("%v | %s | %s | %s | %s",
|
||||
|
@ -563,12 +533,9 @@ type dialoghandler struct {
|
|||
bMsgBoxError *Button
|
||||
w *Window
|
||||
bCenter *Button
|
||||
send func(Event, interface{})
|
||||
// send func(Event, interface{})
|
||||
}
|
||||
|
||||
// == TODO ==
|
||||
func (handler *dialoghandler) Event(e Event, d interface{}) {}
|
||||
|
||||
func (handler *dialoghandler) setUpEvents() {
|
||||
handler.bMsgBox.Clicked = func() {
|
||||
// handler.send(CustomEvent, "DIALOG")
|
||||
|
|
|
@ -41,10 +41,10 @@ func spaceTest() {
|
|||
a2 := NewArea(w, h, ah)
|
||||
a3 := NewArea(w, h, ah)
|
||||
a4 := NewArea(w, h, ah)
|
||||
win := NewWindow("Stack", 250, 250, nullwinhandler{})
|
||||
win := NewWindow("Stack", 250, 250)
|
||||
win.SetSpaced(true)
|
||||
win.Open(f(a1, a2))
|
||||
win = NewWindow("Grid", 250, 250, nullwinhandler{})
|
||||
win = NewWindow("Grid", 250, 250)
|
||||
win.SetSpaced(true)
|
||||
g := NewGrid(ng, a3, a4)
|
||||
g.SetFilling(0, 0)
|
||||
|
|
27
window.go
27
window.go
|
@ -22,39 +22,15 @@ type Window struct {
|
|||
initHeight int
|
||||
shownOnce bool
|
||||
spaced bool
|
||||
handler WindowHandler
|
||||
}
|
||||
|
||||
// WindowHandler represents an event handler for a Window and all its child Controls.
|
||||
//
|
||||
// When an event on a Window or one of its child Controls comes in, the respect Window's handler's Event() method is called. The method call occurs on the main thread, and thus any call to any package ui method can be performed.
|
||||
//
|
||||
// Each Event() call takes two parameters: the event ID and a data argument. For most events, the data argument is a pointer to the Control that triggered the event.
|
||||
//
|
||||
// For Closing, the data argument is a pointer to a bool variable. If, after returning from Event, the value of this variable is true, the Window is closed; if false, the Window is not closed. The default value on entry to the function is [TODO].
|
||||
//
|
||||
// For any event >= CustomEvent, the data argument is the argument passed to the Window's SendEvent() method.
|
||||
type WindowHandler interface {
|
||||
Event(e Event, data interface{})
|
||||
}
|
||||
|
||||
// Event represents an event; see WindowHandler for details.
|
||||
// All event values >= CustomEvent are available for program use.
|
||||
type Event int
|
||||
const (
|
||||
Closing Event = iota // Window close
|
||||
Clicked // Button click
|
||||
CustomEvent = 5000 // very high number; higher than the package would ever need, anyway
|
||||
)
|
||||
|
||||
// NewWindow allocates a new Window with the given title and size. The window is not created until a call to Create() or Open().
|
||||
func NewWindow(title string, width int, height int, handler WindowHandler) *Window {
|
||||
func NewWindow(title string, width int, height int) *Window {
|
||||
return &Window{
|
||||
sysData: mksysdata(c_window),
|
||||
initTitle: title,
|
||||
initWidth: width,
|
||||
initHeight: height,
|
||||
handler: handler,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -109,7 +85,6 @@ func (w *Window) create(control Control, show bool) {
|
|||
panic("window already open")
|
||||
}
|
||||
w.sysData.spaced = w.spaced
|
||||
w.sysData.winhandler = w.handler
|
||||
w.sysData.close = w.Closing
|
||||
err := w.sysData.make(nil)
|
||||
if err != nil {
|
||||
|
|
Loading…
Reference in New Issue