Ported the test page 1 from libui.

This commit is contained in:
Pietro Gagliardi 2015-12-12 21:44:50 -05:00
parent 53a1b6115d
commit 38c3288c6b
3 changed files with 176 additions and 7 deletions

155
zy_page1_test.go Normal file
View File

@ -0,0 +1,155 @@
// 12 december 2015
package ui
var page1 *Box
func makePage1(w *Window) {
var xbutton *Button
page1 = newVerticalBox()
entry := NewEntry()
page1.Append(entry, false)
spaced := NewCheckbox("Spaced")
spaced.OnToggled(func(*Checkbox) {
setSpaced(spaced.Checked())
})
label := NewLabel("Label")
hbox := newHorizontalBox()
getButton := NewButton("Get Window Text")
getButton.OnClicked(func(*Button) {
entry.SetText(w.Title())
})
setButton := NewButton("Set Window Text")
setButton.OnClicked(func(*Button) {
w.SetTitle(entry.Text())
})
hbox.Append(getButton, true)
hbox.Append(setButton, true)
page1.Append(hbox, false)
hbox = newHorizontalBox()
getButton = NewButton("Get Button Text")
xbutton = getButton
getButton.OnClicked(func(*Button) {
entry.SetText(xbutton.Text())
})
setButton = NewButton("Set Button Text")
setButton.OnClicked(func(*Button) {
xbutton.SetText(entry.Text())
})
hbox.Append(getButton, true)
hbox.Append(setButton, true)
page1.Append(hbox, false)
hbox = newHorizontalBox()
getButton = NewButton("Get Checkbox Text")
getButton.OnClicked(func(*Button) {
entry.SetText(spaced.Text())
})
setButton = NewButton("Set Checkbox Text")
setButton.OnClicked(func(*Button) {
spaced.SetText(entry.Text())
})
hbox.Append(getButton, true)
hbox.Append(setButton, true)
page1.Append(hbox, false)
hbox = newHorizontalBox()
getButton = NewButton("Get Label Text")
getButton.OnClicked(func(*Button) {
entry.SetText(label.Text())
})
setButton = NewButton("Set Label Text")
setButton.OnClicked(func(*Button) {
label.SetText(entry.Text())
})
hbox.Append(getButton, true)
hbox.Append(setButton, true)
page1.Append(hbox, false)
hbox = newHorizontalBox()
getButton = NewButton("Get Group Text")
getButton.OnClicked(func(*Button) {
entry.SetText(page2group.Title())
})
setButton = NewButton("Set Group Text")
setButton.OnClicked(func(*Button) {
page2group.SetTitle(entry.Text())
})
hbox.Append(getButton, true)
hbox.Append(setButton, true)
page1.Append(hbox, false)
hbox = newHorizontalBox()
hbox.Append(spaced, true)
getButton = NewButton("On")
getButton.OnClicked(func(*Button) {
spaced.SetChecked(true)
})
hbox.Append(getButton, false)
getButton = NewButton("Off")
getButton.OnClicked(func(*Button) {
spaced.SetChecked(false)
})
hbox.Append(getButton, false)
getButton = NewButton("Show")
getButton.OnClicked(func(*Button) {
// TODO
})
hbox.Append(getButton, false)
page1.Append(hbox, false)
testBox := newHorizontalBox()
ybutton := NewButton("Button")
testBox.Append(ybutton, true)
getButton = NewButton("Show")
getButton.OnClicked(func(*Button) {
ybutton.Show()
})
testBox.Append(getButton, false)
getButton = NewButton("Hide")
getButton.OnClicked(func(*Button) {
ybutton.Hide()
})
testBox.Append(getButton, false)
getButton = NewButton("Enable")
getButton.OnClicked(func(*Button) {
ybutton.Enable()
})
testBox.Append(getButton, false)
getButton = NewButton("Disable")
getButton.OnClicked(func(*Button) {
ybutton.Disable()
})
testBox.Append(getButton, false)
page1.Append(testBox, false)
hbox = newHorizontalBox()
getButton = NewButton("Show")
getButton.OnClicked(func(*Button) {
testBox.Show()
})
hbox.Append(getButton, false)
getButton = NewButton("Hide")
getButton.OnClicked(func(*Button) {
testBox.Hide()
})
hbox.Append(getButton, false)
getButton = NewButton("Enable")
getButton.OnClicked(func(*Button) {
testBox.Enable()
})
hbox.Append(getButton, false)
getButton = NewButton("Disable")
getButton.OnClicked(func(*Button) {
testBox.Disable()
})
hbox.Append(getButton, false)
page1.Append(hbox, false)
page1.Append(label, false)
}

View File

@ -21,14 +21,24 @@ func moveLabel(*Button) {
movingCurrent = to
}
var moveBack int
var moveBack bool
const (
moveOutText = "Move Page 1 Out"
moveBackText = "Move Page 1 Back"
)
func movePage1(*Button) {
// TODO
func movePage1(b *Button) {
if moveBack {
mainbox.Delete(1)
mainTab.InsertAt("Page 1", 0, page1)
b.SetText(moveOutText)
moveBack = false
return
}
mainTab.Delete(0)
mainbox.Append(page1, true)
b.SetText(moveBackText)
moveBack = true
}
func makePage2() *Box {
@ -63,7 +73,7 @@ func makePage2() *Box {
button.OnClicked(movePage1)
hbox.Append(button, false)
page2.Append(hbox, false)
moveBack = 0
moveBack = false
hbox = newHorizontalBox()
hbox.Append(NewLabel("Label Alignment Test"), false)

View File

@ -13,6 +13,9 @@ var (
swaphv = flag.Bool("swaphv", false, "Swap horizontal and vertical boxes")
)
var mainbox *Box
var mainTab *Tab
func xmain() {
if !*nomenus {
// TODO
@ -29,16 +32,17 @@ func xmain() {
return true
})
mainbox := newHorizontalBox()
mainbox = newHorizontalBox()
w.SetChild(mainbox)
outerTab := newTab()
mainbox.Append(outerTab, true)
mainTab := newTab()
mainTab = newTab()
outerTab.Append("Original", mainTab)
// TODO
makePage1(w)
mainTab.Append("Page 1", page1)
mainTab.Append("Page 2", makePage2())