Migrated page2 from the libui test to ui.

This commit is contained in:
Pietro Gagliardi 2015-12-12 20:57:23 -05:00
parent 9da1e956b9
commit 53a1b6115d
2 changed files with 292 additions and 19 deletions

177
zy_page2_test.go Normal file
View File

@ -0,0 +1,177 @@
// 12 december 2015
package ui
var page2group *Group
var (
movingLabel *Label
movingBoxes [2]*Box
movingCurrent int
)
func moveLabel(*Button) {
from := movingCurrent
to := 0
if from == 0 {
to = 1
}
movingBoxes[from].Delete(0)
movingBoxes[to].Append(movingLabel, false)
movingCurrent = to
}
var moveBack int
const (
moveOutText = "Move Page 1 Out"
moveBackText = "Move Page 1 Back"
)
func movePage1(*Button) {
// TODO
}
func makePage2() *Box {
page2 := newVerticalBox()
group := newGroup("Moving Label")
page2group = group
page2.Append(group, false)
vbox := newVerticalBox()
group.SetChild(vbox)
hbox := newHorizontalBox()
button := NewButton("Move the Label!")
button.OnClicked(moveLabel)
hbox.Append(button, true)
hbox.Append(NewLabel(""), true)
vbox.Append(hbox, false)
hbox = newHorizontalBox()
movingBoxes[0] = newVerticalBox()
hbox.Append(movingBoxes[0], true)
movingBoxes[1] = newVerticalBox()
hbox.Append(movingBoxes[1], true)
vbox.Append(hbox, false)
movingCurrent = 0
movingLabel = NewLabel("This label moves!")
movingBoxes[movingCurrent].Append(movingLabel, false)
hbox = newHorizontalBox()
button = NewButton(moveOutText)
button.OnClicked(movePage1)
hbox.Append(button, false)
page2.Append(hbox, false)
moveBack = 0
hbox = newHorizontalBox()
hbox.Append(NewLabel("Label Alignment Test"), false)
button = NewButton("Open Menued Window")
button.OnClicked(func(*Button) {
w := NewWindow("Another Window", 100, 100, true)
b := NewVerticalBox()
b.Append(NewEntry(), false)
b.Append(NewButton("Button"), false)
b.SetPadded(true)
w.SetChild(b)
w.SetMargined(true)
w.Show()
})
hbox.Append(button, false)
button = NewButton("Open Menuless Window")
button.OnClicked(func(*Button) {
w := NewWindow("Another Window", 100, 100, true)
//TODO w.SetChild(makePage6())
w.SetMargined(true)
w.Show()
})
hbox.Append(button, false)
button = NewButton("Disabled Menued")
button.OnClicked(func(*Button) {
w := NewWindow("Another Window", 100, 100, true)
w.Disable()
w.Show()
})
hbox.Append(button, false)
button = NewButton("Disabled Menuless")
button.OnClicked(func(*Button) {
w := NewWindow("Another Window", 100, 100, false)
w.Disable()
w.Show()
})
hbox.Append(button, false)
page2.Append(hbox, false)
nestedBox := newHorizontalBox()
innerhbox := newHorizontalBox()
innerhbox.Append(NewButton("These"), false)
button = NewButton("buttons")
button.Disable()
innerhbox.Append(button, false)
nestedBox.Append(innerhbox, false)
innerhbox = newHorizontalBox()
innerhbox.Append(NewButton("are"), false)
innerhbox2 := newHorizontalBox()
button = NewButton("in")
button.Disable()
innerhbox2.Append(button, false)
innerhbox.Append(innerhbox2, false)
nestedBox.Append(innerhbox, false)
innerhbox = newHorizontalBox()
innerhbox2 = newHorizontalBox()
innerhbox2.Append(NewButton("nested"), false)
innerhbox3 := newHorizontalBox()
button = NewButton("boxes")
button.Disable()
innerhbox3.Append(button, false)
innerhbox2.Append(innerhbox3, false)
innerhbox.Append(innerhbox2, false)
nestedBox.Append(innerhbox, false)
page2.Append(nestedBox, false)
hbox = newHorizontalBox()
button = NewButton("Enable Nested Box")
button.OnClicked(func(*Button) {
nestedBox.Enable()
})
hbox.Append(button, false)
button = NewButton("Disable Nested Box")
button.OnClicked(func(*Button) {
nestedBox.Disable()
})
hbox.Append(button, false)
page2.Append(hbox, false)
disabledTab := newTab()
disabledTab.Append("Disabled", NewButton("Button"));
disabledTab.Append("Tab", NewLabel("Label"));
disabledTab.Disable()
page2.Append(disabledTab, true)
entry := NewEntry()
readonly := NewEntry()
entry.OnChanged(func(*Entry) {
readonly.SetText(entry.Text())
})
readonly.SetText("If you can see this, uiEntryReadOnly() isn't working properly.")
readonly.SetReadOnly(true)
if readonly.ReadOnly() {
readonly.SetText("")
}
page2.Append(entry, false)
page2.Append(readonly, false)
hbox = newHorizontalBox()
button = NewButton("Show Button 2")
button2 := NewButton("Button 2")
button.OnClicked(func(*Button) {
button2.Show()
})
button2.Hide()
hbox.Append(button, true)
hbox.Append(button2, false)
page2.Append(hbox, false)
return page2
}

View File

@ -2,28 +2,124 @@
package ui
import "testing"
import (
"flag"
"testing"
)
func TestIt(t *testing.T) {
err := Main(func() {
w := NewWindow("Hello", 320, 240, false)
w.OnClosing(func(w *Window) bool {
var (
nomenus = flag.Bool("nomenus", false, "No menus")
startspaced = flag.Bool("startspaced", false, "Start with spacing")
swaphv = flag.Bool("swaphv", false, "Swap horizontal and vertical boxes")
)
func xmain() {
if !*nomenus {
// TODO
}
w := newWindow("Main Window", 320, 240, true)
w.OnClosing(func(*Window) bool {
Quit()
return true
})
b := NewVerticalBox()
w.SetChild(b)
w.SetMargined(true)
button := NewButton("Click Me")
button.OnClicked(func(*Button) {
b.SetPadded(!b.Padded())
OnShouldQuit(func() bool {
// TODO
return true
})
b.Append(button, true)
b.Append(NewButton("Button 2"), false)
b.Append(NewButton("Button 3"), true)
mainbox := newHorizontalBox()
w.SetChild(mainbox)
outerTab := newTab()
mainbox.Append(outerTab, true)
mainTab := newTab()
outerTab.Append("Original", mainTab)
// TODO
mainTab.Append("Page 2", makePage2())
// TODO
if *startspaced {
setSpaced(true)
}
w.Show()
})
}
func TestIt(t *testing.T) {
err := Main(xmain)
if err != nil {
t.Fatal(err)
}
}
var (
spwindows []*Window
sptabs []*Tab
spgroups []*Group
spboxes []*Box
)
func newWindow(title string, width int, height int, hasMenubar bool) *Window {
w := NewWindow(title, width, height, hasMenubar)
spwindows = append(spwindows, w)
return w
}
func newTab() *Tab {
t := NewTab()
sptabs = append(sptabs, t)
return t
}
func newGroup(title string) *Group {
g := NewGroup(title)
spgroups = append(spgroups, g)
return g
}
func newHorizontalBox() *Box {
var b *Box
if *swaphv {
b = NewVerticalBox()
} else {
b = NewHorizontalBox()
}
spboxes = append(spboxes, b)
return b
}
func newVerticalBox() *Box {
var b *Box
if *swaphv {
b = NewHorizontalBox()
} else {
b = NewVerticalBox()
}
spboxes = append(spboxes, b)
return b
}
func setSpaced(spaced bool) {
for _, w := range spwindows {
w.SetMargined(spaced)
}
for _, t := range sptabs {
for i := 0; i < t.NumPages(); i++ {
t.SetMargined(i, spaced)
}
}
for _, g := range spgroups {
g.SetMargined(spaced)
}
for _, b := range spboxes {
b.SetPadded(spaced)
}
}