2014-02-11 17:57:03 -06:00
|
|
|
// 11 february 2014
|
2014-03-01 14:18:29 -06:00
|
|
|
package main
|
2014-02-11 17:57:03 -06:00
|
|
|
|
2014-02-13 14:14:10 -06:00
|
|
|
import (
|
|
|
|
"fmt"
|
2014-03-03 14:55:38 -06:00
|
|
|
"flag"
|
2014-03-04 22:10:48 -06:00
|
|
|
. "github.com/andlabs/ui"
|
2014-02-13 14:14:10 -06:00
|
|
|
)
|
|
|
|
|
2014-03-03 14:55:38 -06:00
|
|
|
var prefsizetest = flag.Bool("prefsize", false, "")
|
2014-03-03 12:58:20 -06:00
|
|
|
func listboxPreferredSizeTest() (*Window, error) {
|
|
|
|
lb := NewListbox(false, "xxxxx", "y", "zzz")
|
|
|
|
g := NewGrid(1, lb)
|
|
|
|
w := NewWindow("Listbox Preferred Size Test", 300, 300)
|
|
|
|
return w, w.Open(g)
|
|
|
|
}
|
|
|
|
|
2014-03-03 14:55:38 -06:00
|
|
|
var gridtest = flag.Bool("grid", false, "")
|
2014-02-25 17:40:36 -06:00
|
|
|
func gridWindow() (*Window, error) {
|
|
|
|
w := NewWindow("Grid Test", 400, 400)
|
|
|
|
b00 := NewButton("0,0")
|
|
|
|
b01 := NewButton("0,1")
|
|
|
|
b02 := NewButton("0,2")
|
|
|
|
l11 := NewListbox(true, "1,1")
|
|
|
|
b12 := NewButton("1,2")
|
|
|
|
l20 := NewLabel("2,0")
|
|
|
|
c21 := NewCheckbox("2,1")
|
|
|
|
l22 := NewLabel("2,2")
|
|
|
|
g := NewGrid(3,
|
|
|
|
b00, b01, b02,
|
|
|
|
Space(), l11, b12,
|
|
|
|
l20, c21, l22)
|
2014-02-25 20:54:13 -06:00
|
|
|
g.SetFilling(1, 2)
|
2014-02-26 06:01:02 -06:00
|
|
|
g.SetStretchy(1, 1)
|
2014-02-25 17:40:36 -06:00
|
|
|
return w, w.Open(g)
|
|
|
|
}
|
|
|
|
|
2014-03-08 20:59:03 -06:00
|
|
|
var macCrashTest = flag.Bool("maccrash", false, "attempt crash on Mac OS X on deleting too far (debug lack of panic on 32-bit)")
|
|
|
|
|
2014-03-09 09:41:07 -05:00
|
|
|
func invalidTest(c *Combobox, l *Listbox) {
|
|
|
|
x := func(what string ) {
|
|
|
|
if j := recover(); j == nil {
|
|
|
|
MsgBoxError("test", "%s: no panic", what)
|
|
|
|
panic("invalid test fail")
|
|
|
|
} else {
|
|
|
|
println("got", j.(error).Error())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func() {
|
|
|
|
defer x("Combobox.InsertBefore < 0"); c.InsertBefore("xxx", -5); panic(nil)
|
|
|
|
}()
|
|
|
|
func() {
|
|
|
|
defer x("Combobox.InsertBefore > len"); c.InsertBefore("xxx", c.Len() + 5); panic(nil)
|
|
|
|
}()
|
|
|
|
func() {
|
|
|
|
defer x("Combobox.Delete < 0"); c.Delete(-5); panic(nil)
|
|
|
|
}()
|
|
|
|
func() {
|
|
|
|
defer x("Listbox.Delete > len"); c.Delete(c.Len() + 5); panic(nil)
|
|
|
|
}()
|
|
|
|
// TODO
|
|
|
|
_ = l
|
|
|
|
MsgBox("test", "all working as intended")
|
|
|
|
}
|
|
|
|
|
|
|
|
var invalidBefore = flag.Bool("invalid", false, "run invalid test before opening window")
|
|
|
|
|
2014-03-01 14:18:29 -06:00
|
|
|
func myMain() {
|
2014-02-12 09:51:27 -06:00
|
|
|
w := NewWindow("Main Window", 320, 240)
|
2014-02-18 09:53:15 -06:00
|
|
|
w.Closing = Event()
|
2014-02-12 10:29:20 -06:00
|
|
|
b := NewButton("Click Me")
|
2014-02-15 17:14:43 -06:00
|
|
|
b2 := NewButton("Or Me")
|
2014-03-06 19:30:13 -06:00
|
|
|
s2 := NewHorizontalStack(b, b2)
|
2014-02-13 11:26:43 -06:00
|
|
|
c := NewCheckbox("Check Me")
|
2014-02-25 14:13:37 -06:00
|
|
|
cb1 := NewEditableCombobox("You can edit me!", "Yes you can!", "Yes you will!")
|
|
|
|
cb2 := NewCombobox("You can't edit me!", "No you can't!", "No you won't!")
|
2014-02-15 16:59:12 -06:00
|
|
|
e := NewLineEdit("Enter text here too")
|
|
|
|
l := NewLabel("This is a label")
|
2014-02-15 17:27:34 -06:00
|
|
|
b3 := NewButton("List Info")
|
2014-03-06 19:30:13 -06:00
|
|
|
s3 := NewHorizontalStack(l, b3)
|
2014-02-24 10:18:47 -06:00
|
|
|
s3.SetStretchy(0)
|
|
|
|
// s3.SetStretchy(1)
|
2014-02-24 23:48:23 -06:00
|
|
|
pbar := NewProgressBar()
|
|
|
|
prog := 0
|
|
|
|
incButton := NewButton("Inc")
|
|
|
|
decButton := NewButton("Dec")
|
2014-03-09 09:41:07 -05:00
|
|
|
invalidButton := NewButton("Run Invalid Test")
|
|
|
|
sincdec := NewHorizontalStack(incButton, decButton, invalidButton)
|
2014-02-25 14:06:51 -06:00
|
|
|
password := NewPasswordEdit()
|
2014-03-06 19:30:13 -06:00
|
|
|
s0 := NewVerticalStack(s2, c, cb1, cb2, e, s3, pbar, sincdec, Space(), password)
|
2014-02-25 14:38:04 -06:00
|
|
|
s0.SetStretchy(8)
|
2014-02-15 17:36:14 -06:00
|
|
|
lb1 := NewListbox(true, "Select One", "Or More", "To Continue")
|
2014-02-15 16:59:12 -06:00
|
|
|
lb2 := NewListbox(false, "Select", "Only", "One", "Please")
|
2014-02-15 16:52:33 -06:00
|
|
|
i := 0
|
|
|
|
doAdjustments := func() {
|
|
|
|
cb1.Append("append")
|
|
|
|
cb2.InsertBefore(fmt.Sprintf("before %d", i), 1)
|
2014-02-15 17:36:14 -06:00
|
|
|
lb1.InsertBefore(fmt.Sprintf("%d", i), 2)
|
2014-02-15 16:59:12 -06:00
|
|
|
lb2.Append("Please")
|
2014-02-15 16:52:33 -06:00
|
|
|
i++
|
|
|
|
}
|
|
|
|
doAdjustments()
|
2014-03-07 14:01:42 -06:00
|
|
|
cb1.Append("append multi 1", "append multi 2")
|
|
|
|
lb2.Append("append multi 1", "append multi 2")
|
2014-03-06 19:30:13 -06:00
|
|
|
s1 := NewVerticalStack(lb2, lb1)
|
2014-02-24 10:18:47 -06:00
|
|
|
s1.SetStretchy(0)
|
|
|
|
s1.SetStretchy(1)
|
2014-03-06 19:30:13 -06:00
|
|
|
s := NewHorizontalStack(s1, s0)
|
2014-02-24 10:18:47 -06:00
|
|
|
s.SetStretchy(0)
|
|
|
|
s.SetStretchy(1)
|
2014-03-09 09:41:07 -05:00
|
|
|
if *invalidBefore {
|
|
|
|
invalidTest(cb1, lb1)
|
|
|
|
}
|
2014-02-13 16:04:57 -06:00
|
|
|
err := w.Open(s)
|
2014-02-13 11:26:43 -06:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2014-03-03 14:55:38 -06:00
|
|
|
if *gridtest {
|
|
|
|
_, err := gridWindow()
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2014-02-25 17:40:36 -06:00
|
|
|
}
|
2014-03-03 14:55:38 -06:00
|
|
|
if *prefsizetest {
|
|
|
|
_, err = listboxPreferredSizeTest()
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2014-03-03 12:58:20 -06:00
|
|
|
}
|
2014-02-13 11:26:43 -06:00
|
|
|
|
2014-02-12 10:29:20 -06:00
|
|
|
mainloop:
|
|
|
|
for {
|
|
|
|
select {
|
|
|
|
case <-w.Closing:
|
|
|
|
break mainloop
|
|
|
|
case <-b.Clicked:
|
2014-02-25 14:06:51 -06:00
|
|
|
err = w.SetTitle(fmt.Sprintf("%v | %s | %s | %s | %s",
|
2014-02-15 12:36:24 -06:00
|
|
|
c.Checked(),
|
|
|
|
cb1.Selection(),
|
|
|
|
cb2.Selection(),
|
2014-02-25 14:06:51 -06:00
|
|
|
e.Text(),
|
|
|
|
password.Text()))
|
2014-02-12 17:14:37 -06:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2014-02-15 16:52:33 -06:00
|
|
|
doAdjustments()
|
2014-02-15 17:14:43 -06:00
|
|
|
case <-b2.Clicked:
|
2014-03-08 20:59:03 -06:00
|
|
|
if cb1.Len() > 1 {
|
|
|
|
cb1.Delete(1)
|
|
|
|
}
|
|
|
|
if cb2.Len() > 2 {
|
|
|
|
cb2.Delete(2)
|
|
|
|
}
|
|
|
|
if lb1.Len() > 3 || *macCrashTest {
|
|
|
|
lb1.Delete(3)
|
|
|
|
}
|
|
|
|
if lb2.Len() > 4 {
|
|
|
|
lb2.Delete(4)
|
|
|
|
}
|
2014-02-15 17:27:34 -06:00
|
|
|
case <-b3.Clicked:
|
|
|
|
MsgBox("List Info",
|
2014-03-08 15:42:57 -06:00
|
|
|
"cb1: %d %q (len %d)\ncb2: %d %q (len %d)\nlb1: %d %q (len %d)\nlb2: %d %q (len %d)",
|
|
|
|
cb1.SelectedIndex(), cb1.Selection(), cb1.Len(),
|
|
|
|
cb2.SelectedIndex(), cb2.Selection(), cb2.Len(),
|
|
|
|
lb1.SelectedIndices(), lb1.Selection(), lb1.Len(),
|
|
|
|
lb2.SelectedIndices(), lb2.Selection(), lb2.Len())
|
2014-02-24 23:48:23 -06:00
|
|
|
case <-incButton.Clicked:
|
|
|
|
prog++
|
|
|
|
if prog > 100 {
|
|
|
|
prog = 100
|
|
|
|
}
|
|
|
|
pbar.SetProgress(prog)
|
2014-03-07 14:01:42 -06:00
|
|
|
cb1.Append("append multi 1", "append multi 2")
|
|
|
|
lb2.Append("append multi 1", "append multi 2")
|
2014-02-24 23:48:23 -06:00
|
|
|
case <-decButton.Clicked:
|
|
|
|
prog--
|
|
|
|
if prog < 0 {
|
|
|
|
prog = 0
|
|
|
|
}
|
|
|
|
pbar.SetProgress(prog)
|
2014-03-09 09:41:07 -05:00
|
|
|
case <-invalidButton.Clicked:
|
|
|
|
invalidTest(cb1, lb1)
|
2014-02-12 10:29:20 -06:00
|
|
|
}
|
|
|
|
}
|
2014-02-12 20:28:58 -06:00
|
|
|
w.Hide()
|
2014-02-11 17:57:03 -06:00
|
|
|
}
|
2014-03-01 14:18:29 -06:00
|
|
|
|
|
|
|
func main() {
|
2014-03-03 14:55:38 -06:00
|
|
|
flag.Parse()
|
2014-03-01 14:18:29 -06:00
|
|
|
err := Go(myMain)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
}
|