2019-03-05 20:52:18 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"image/color"
|
|
|
|
"log"
|
|
|
|
|
2020-05-15 07:20:44 +00:00
|
|
|
_ "opslag.de/schobers/zntg/sdlui" // import the renderer for the UI
|
|
|
|
// _ "opslag.de/schobers/zntg/allg5ui" // import the renderer for the UI
|
2020-05-12 20:46:58 +00:00
|
|
|
|
2019-03-05 20:52:18 +00:00
|
|
|
"opslag.de/schobers/geom"
|
|
|
|
"opslag.de/schobers/zntg/ui"
|
|
|
|
)
|
|
|
|
|
2019-07-22 18:02:57 +00:00
|
|
|
type basic struct {
|
|
|
|
ui.StackPanel
|
|
|
|
}
|
|
|
|
|
|
|
|
func (b *basic) Init(ctx ui.Context) error {
|
2020-05-15 13:42:24 +00:00
|
|
|
_, err := ctx.Fonts().CreateFontPath("default", "../resources/font/OpenSans-Regular.ttf", 14)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
_, err = ctx.Textures().CreateTexturePath("plus", "../resources/images/plus.png", true)
|
2020-05-15 12:44:55 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-07-22 18:02:57 +00:00
|
|
|
var style = ctx.Style()
|
|
|
|
var stretch = func(content ui.Control, margin float32) ui.Control {
|
|
|
|
return ui.BuildSpacing(content, func(s *ui.Spacing) {
|
|
|
|
s.Width = ui.Infinite()
|
|
|
|
s.Margin.Left = ui.Fixed(margin)
|
|
|
|
s.Margin.Top = ui.Fixed(margin)
|
|
|
|
s.Margin.Right = ui.Fixed(margin)
|
|
|
|
s.Margin.Bottom = ui.Fixed(margin)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
b.Background = color.White
|
|
|
|
b.Children = []ui.Control{
|
|
|
|
&ui.Label{Text: "Hello, world!"},
|
|
|
|
ui.BuildStackPanel(ui.OrientationHorizontal, func(p *ui.StackPanel) {
|
|
|
|
p.Children = []ui.Control{
|
2020-05-15 12:44:55 +00:00
|
|
|
stretch(ui.BuildIconButton("plus", "Contained", func(b *ui.Button) { b.Type = ui.ButtonTypeContained }), 8),
|
|
|
|
stretch(ui.BuildIconButton("plus", "Icon", func(b *ui.Button) { b.Type = ui.ButtonTypeIcon }), 8),
|
|
|
|
stretch(ui.BuildIconButton("plus", "Outlined", func(b *ui.Button) { b.Type = ui.ButtonTypeOutlined }), 8),
|
|
|
|
stretch(ui.BuildIconButton("plus", "Text", func(b *ui.Button) { b.Type = ui.ButtonTypeText }), 8),
|
2019-07-22 18:02:57 +00:00
|
|
|
}
|
|
|
|
}),
|
|
|
|
ui.BuildStackPanel(ui.OrientationHorizontal, func(p *ui.StackPanel) {
|
|
|
|
p.Children = []ui.Control{
|
|
|
|
&ui.Checkbox{},
|
|
|
|
ui.BuildCheckbox("Check me!", nil),
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
ui.Stretch(&ui.Label{Text: "Content"}),
|
|
|
|
ui.Margin(ui.StretchWidth(ui.BuildTextBox(func(b *ui.TextBox) {
|
|
|
|
b.Text = "Type here..."
|
|
|
|
})), 8),
|
|
|
|
ui.Margin(ui.BuildButton("Quit", func(b *ui.Button) {
|
|
|
|
b.OnClick(func(geom.PointF32, ui.MouseButton) {
|
|
|
|
ctx.Quit()
|
|
|
|
})
|
2020-05-15 14:39:53 +00:00
|
|
|
b.Tooltip = "Will quit the application"
|
2019-07-22 18:02:57 +00:00
|
|
|
}), 8),
|
|
|
|
ui.BuildLabel("Status...", func(l *ui.Label) {
|
|
|
|
l.Background = style.Palette.PrimaryDark
|
|
|
|
l.Font.Color = style.Palette.TextOnPrimary
|
|
|
|
}),
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2019-03-05 20:52:18 +00:00
|
|
|
func run() error {
|
2020-05-12 20:46:58 +00:00
|
|
|
var render, err = ui.NewRenderer("Basic Example", 800, 600)
|
2019-03-05 20:52:18 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer render.Destroy()
|
|
|
|
|
2020-05-15 12:44:55 +00:00
|
|
|
return ui.RunWait(render, ui.DefaultStyle(), &basic{}, true)
|
2019-03-05 20:52:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
var err = run()
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|