2019-06-09 00:03:59 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2019-12-28 00:06:24 +00:00
|
|
|
"fmt"
|
|
|
|
|
2019-12-23 02:21:58 +00:00
|
|
|
"git.kirsle.net/go/render"
|
2019-12-28 00:06:24 +00:00
|
|
|
"git.kirsle.net/go/ui"
|
2019-06-09 00:03:59 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
mw, err := ui.NewMainWindow("UI Toolkit Demo")
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
leftFrame := ui.NewFrame("Left Frame")
|
|
|
|
leftFrame.Configure(ui.Config{
|
2019-12-28 00:06:24 +00:00
|
|
|
Width: 160,
|
2019-06-09 00:03:59 +00:00
|
|
|
BorderSize: 1,
|
|
|
|
BorderStyle: ui.BorderRaised,
|
|
|
|
Background: render.Grey,
|
|
|
|
})
|
|
|
|
mw.Pack(leftFrame, ui.Pack{
|
2019-12-29 05:47:46 +00:00
|
|
|
Side: ui.W,
|
|
|
|
FillY: true,
|
2019-06-09 00:03:59 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
mainFrame := ui.NewFrame("Main Frame")
|
|
|
|
mainFrame.Configure(ui.Config{
|
|
|
|
Background: render.RGBA(255, 255, 255, 180),
|
|
|
|
})
|
|
|
|
mw.Pack(mainFrame, ui.Pack{
|
2019-12-29 05:47:46 +00:00
|
|
|
Side: ui.W,
|
2019-06-09 00:03:59 +00:00
|
|
|
Expand: true,
|
|
|
|
PadX: 10,
|
|
|
|
})
|
|
|
|
|
|
|
|
label := ui.NewLabel(ui.Label{
|
|
|
|
Text: "Hello world",
|
|
|
|
})
|
|
|
|
leftFrame.Pack(label, ui.Pack{
|
2019-12-29 05:47:46 +00:00
|
|
|
Side: ui.N,
|
|
|
|
PadY: 12,
|
2019-12-28 00:06:24 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
// Draw some buttons in the left frame.
|
|
|
|
for i := 1; i <= 12; i++ {
|
|
|
|
i := i
|
|
|
|
|
|
|
|
btn := ui.NewButton(fmt.Sprintf("Button-%d", i), ui.NewLabel(ui.Label{
|
|
|
|
Text: fmt.Sprintf("Button #%d", i),
|
|
|
|
}))
|
|
|
|
btn.Handle(ui.Click, func(p render.Point) {
|
|
|
|
fmt.Printf("Button %d was clicked\n", i)
|
|
|
|
})
|
|
|
|
|
|
|
|
// Add the button to the MainWindow's event supervisor, so it may be
|
|
|
|
// clicked and interacted with.
|
|
|
|
mw.Add(btn)
|
|
|
|
|
|
|
|
leftFrame.Pack(btn, ui.Pack{
|
2019-12-29 05:47:46 +00:00
|
|
|
Side: ui.N,
|
|
|
|
FillX: true,
|
|
|
|
PadY: 2,
|
2019-12-28 00:06:24 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// Frame to show off check buttons.
|
|
|
|
mainFrame.Pack(radioButtonFrame(mw), ui.Pack{
|
2019-12-29 05:47:46 +00:00
|
|
|
Side: ui.N,
|
|
|
|
FillX: true,
|
|
|
|
PadY: 8,
|
2019-06-09 00:03:59 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
err = mw.MainLoop()
|
|
|
|
if err != nil {
|
|
|
|
panic("MainLoop:" + err.Error())
|
|
|
|
}
|
|
|
|
}
|
2019-12-28 00:06:24 +00:00
|
|
|
|
|
|
|
// Frame that shows off radio buttons.
|
|
|
|
func radioButtonFrame(mw *ui.MainWindow) *ui.Frame {
|
|
|
|
// The string variable that will be bound to the radio buttons.
|
|
|
|
// This could also be a global variable at the package level.
|
|
|
|
radioValue := "Red"
|
|
|
|
|
|
|
|
// Main frame.
|
|
|
|
frame := ui.NewFrame("radio button demo")
|
|
|
|
frame.Configure(ui.Config{
|
|
|
|
Background: render.RGBA(153, 255, 153, 255),
|
|
|
|
BorderSize: 1,
|
|
|
|
BorderStyle: ui.BorderRaised,
|
|
|
|
})
|
|
|
|
|
|
|
|
// Top row to show the label and current radiobutton bound value.
|
|
|
|
topFrame := ui.NewFrame("radio button label frame")
|
|
|
|
frame.Pack(topFrame, ui.Pack{
|
2019-12-29 05:47:46 +00:00
|
|
|
Side: ui.N,
|
|
|
|
FillX: true,
|
2019-12-28 00:06:24 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
// Draw the labels.
|
|
|
|
{
|
|
|
|
label := ui.NewLabel(ui.Label{
|
|
|
|
Text: "Radio buttons. Value:",
|
|
|
|
})
|
|
|
|
topFrame.Pack(label, ui.Pack{
|
2019-12-29 05:47:46 +00:00
|
|
|
Side: ui.W,
|
2019-12-28 00:06:24 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
valueLabel := ui.NewLabel(ui.Label{
|
|
|
|
TextVariable: &radioValue,
|
|
|
|
})
|
|
|
|
topFrame.Pack(valueLabel, ui.Pack{
|
2019-12-29 05:47:46 +00:00
|
|
|
Side: ui.W,
|
|
|
|
PadX: 4,
|
2019-12-28 00:06:24 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// The radio buttons themselves.
|
|
|
|
btnFrame := ui.NewFrame("radio button frame")
|
|
|
|
frame.Pack(btnFrame, ui.Pack{
|
2019-12-29 05:47:46 +00:00
|
|
|
Side: ui.N,
|
|
|
|
FillX: true,
|
2019-12-28 00:06:24 +00:00
|
|
|
})
|
|
|
|
{
|
|
|
|
colors := []string{"Red", "Green", "Blue", "Yellow"}
|
|
|
|
for _, color := range colors {
|
|
|
|
color := color
|
|
|
|
|
|
|
|
btn := ui.NewRadioButton("color:"+color, &radioValue, color, ui.NewLabel(ui.Label{
|
|
|
|
Text: color,
|
|
|
|
}))
|
|
|
|
mw.Add(btn)
|
|
|
|
btnFrame.Pack(btn, ui.Pack{
|
2019-12-29 05:47:46 +00:00
|
|
|
Side: ui.W,
|
|
|
|
PadX: 2,
|
2019-12-28 00:06:24 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return frame
|
|
|
|
}
|