zntg/ui/examples/01_basic/basic.go
Sander Schobers ff51378aff Added button types.
Go image can be reconstructed from ui.Image/allg5.Bitmap.
Changed allg5.Scale from interface to struct.
2019-03-13 19:49:00 +01:00

58 lines
1.5 KiB
Go

package main
import (
"image/color"
"log"
"opslag.de/schobers/geom"
"opslag.de/schobers/zntg/allg5"
"opslag.de/schobers/zntg/ui"
"opslag.de/schobers/zntg/ui/allg5ui"
)
func run() error {
var render, err = allg5ui.NewRenderer(800, 600, allg5.NewDisplayOptions{})
if err != nil {
return err
}
defer render.Destroy()
err = render.RegisterFont("../resources/font/OpenSans-Regular.ttf", "default", 14)
if err != nil {
return err
}
plus, err := render.CreateImagePath("../resources/images/plus.png")
if err != nil {
return err
}
defer plus.Destroy()
var view = &ui.StackPanel{ContainerBase: ui.ContainerBase{
ControlBase: ui.ControlBase{Background: color.White},
Children: []ui.Control{
&ui.Label{Text: "Hello, world!"},
ui.Margin(ui.BuildIconButton(plus, "Contained", func(b *ui.Button) { b.Type = ui.ButtonTypeContained }), 8),
ui.Margin(ui.BuildIconButton(plus, "Icon", func(b *ui.Button) { b.Type = ui.ButtonTypeIcon }), 8),
ui.Margin(ui.BuildIconButton(plus, "Outlined", func(b *ui.Button) { b.Type = ui.ButtonTypeOutlined }), 8),
ui.Margin(ui.BuildIconButton(plus, "Text", func(b *ui.Button) { b.Type = ui.ButtonTypeText }), 8),
ui.Margin(ui.BuildButton("Quit", func(b *ui.Button) {
b.OnClick(func(ctx ui.Context, _ ui.Control, _ geom.PointF32, _ ui.MouseButton) {
ctx.Quit()
})
}), 8),
ui.Stretch(&ui.Label{Text: "Content"}),
&ui.Label{Text: "Status"},
},
}}
return ui.RunWait(render, ui.DefaultStyle(), view, true)
}
func main() {
var err = run()
if err != nil {
log.Fatal(err)
}
}