2014-02-11 17:57:03 -06:00
|
|
|
// 11 february 2014
|
2014-02-19 10:41:10 -06:00
|
|
|
package ui
|
2014-02-11 17:57:03 -06:00
|
|
|
|
2014-02-13 14:14:10 -06:00
|
|
|
import (
|
|
|
|
"fmt"
|
2014-02-19 10:41:10 -06:00
|
|
|
"testing"
|
2014-02-13 14:14:10 -06:00
|
|
|
)
|
|
|
|
|
2014-02-19 10:41:10 -06:00
|
|
|
func TestMain(t *testing.T) {
|
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")
|
|
|
|
s2 := NewStack(Horizontal, b, b2)
|
2014-02-13 11:26:43 -06:00
|
|
|
c := NewCheckbox("Check Me")
|
2014-02-14 11:16:27 -06:00
|
|
|
cb1 := NewCombobox(true, "You can edit me!", "Yes you can!", "Yes you will!")
|
|
|
|
cb2 := NewCombobox(false, "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")
|
|
|
|
s3 := NewStack(Horizontal, 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")
|
|
|
|
sincdec := NewStack(Horizontal, incButton, decButton)
|
|
|
|
s0 := NewStack(Vertical, s2, c, cb1, cb2, e, s3, pbar, sincdec)
|
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-02-15 17:36:14 -06:00
|
|
|
s1 := NewStack(Vertical, lb2, lb1)
|
2014-02-24 10:18:47 -06:00
|
|
|
s1.SetStretchy(0)
|
|
|
|
s1.SetStretchy(1)
|
2014-02-14 16:31:21 -06:00
|
|
|
s := NewStack(Horizontal, s1, s0)
|
2014-02-24 10:18:47 -06:00
|
|
|
s.SetStretchy(0)
|
|
|
|
s.SetStretchy(1)
|
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-02-12 10:29:20 -06:00
|
|
|
mainloop:
|
|
|
|
for {
|
|
|
|
select {
|
|
|
|
case <-w.Closing:
|
|
|
|
break mainloop
|
|
|
|
case <-b.Clicked:
|
2014-02-15 12:36:24 -06:00
|
|
|
err = w.SetTitle(fmt.Sprintf("%v | %s | %s | %s",
|
|
|
|
c.Checked(),
|
|
|
|
cb1.Selection(),
|
|
|
|
cb2.Selection(),
|
|
|
|
e.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:
|
|
|
|
cb1.Delete(1)
|
|
|
|
cb2.Delete(2)
|
2014-02-15 17:36:14 -06:00
|
|
|
lb1.Delete(3)
|
2014-02-15 17:14:43 -06:00
|
|
|
lb2.Delete(4)
|
2014-02-15 17:27:34 -06:00
|
|
|
case <-b3.Clicked:
|
|
|
|
MsgBox("List Info",
|
2014-02-15 17:36:14 -06:00
|
|
|
"cb1: %d %q\ncb2: %d %q\nlb1: %d %q\nlb2: %d %q",
|
2014-02-15 17:27:34 -06:00
|
|
|
cb1.SelectedIndex(), cb1.Selection(),
|
2014-02-15 17:36:14 -06:00
|
|
|
cb2.SelectedIndex(), cb2.Selection(),
|
|
|
|
lb1.SelectedIndices(), lb1.Selection(),
|
|
|
|
lb2.SelectedIndices(), lb2.Selection())
|
2014-02-24 23:48:23 -06:00
|
|
|
case <-incButton.Clicked:
|
|
|
|
prog++
|
|
|
|
if prog > 100 {
|
|
|
|
prog = 100
|
|
|
|
}
|
|
|
|
pbar.SetProgress(prog)
|
|
|
|
case <-decButton.Clicked:
|
|
|
|
prog--
|
|
|
|
if prog < 0 {
|
|
|
|
prog = 0
|
|
|
|
}
|
|
|
|
pbar.SetProgress(prog)
|
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
|
|
|
}
|