Updated example.
This commit is contained in:
parent
52d22e7a18
commit
06a38d8e4a
@ -11,6 +11,58 @@ import (
|
||||
"opslag.de/schobers/zntg/ui/allg5ui"
|
||||
)
|
||||
|
||||
type basic struct {
|
||||
ui.StackPanel
|
||||
|
||||
plus ui.Image
|
||||
}
|
||||
|
||||
func (b *basic) Init(ctx ui.Context) error {
|
||||
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{
|
||||
stretch(ui.BuildIconButton(b.plus, "Contained", func(b *ui.Button) { b.Type = ui.ButtonTypeContained }), 8),
|
||||
stretch(ui.BuildIconButton(b.plus, "Icon", func(b *ui.Button) { b.Type = ui.ButtonTypeIcon }), 8),
|
||||
stretch(ui.BuildIconButton(b.plus, "Outlined", func(b *ui.Button) { b.Type = ui.ButtonTypeOutlined }), 8),
|
||||
stretch(ui.BuildIconButton(b.plus, "Text", func(b *ui.Button) { b.Type = ui.ButtonTypeText }), 8),
|
||||
}
|
||||
}),
|
||||
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()
|
||||
})
|
||||
}), 8),
|
||||
ui.BuildLabel("Status...", func(l *ui.Label) {
|
||||
l.Background = style.Palette.PrimaryDark
|
||||
l.Font.Color = style.Palette.TextOnPrimary
|
||||
}),
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func run() error {
|
||||
var render, err = allg5ui.NewRenderer(800, 600, allg5.NewDisplayOptions{})
|
||||
if err != nil {
|
||||
@ -28,52 +80,7 @@ func run() error {
|
||||
}
|
||||
defer plus.Destroy()
|
||||
|
||||
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)
|
||||
})
|
||||
}
|
||||
|
||||
var style = ui.DefaultStyle()
|
||||
var view = ui.BuildStackPanel(ui.OrientationVertical, func(p *ui.StackPanel) {
|
||||
p.Background = color.White
|
||||
p.Children = []ui.Control{
|
||||
&ui.Label{Text: "Hello, world!"},
|
||||
ui.BuildStackPanel(ui.OrientationHorizontal, func(p *ui.StackPanel) {
|
||||
p.Children = []ui.Control{
|
||||
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),
|
||||
}
|
||||
}),
|
||||
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(ctx ui.Context, _ ui.Control, _ geom.PointF32, _ ui.MouseButton) {
|
||||
ctx.Quit()
|
||||
})
|
||||
}), 8),
|
||||
ui.BuildLabel("Status...", func(l *ui.Label) {
|
||||
l.Background = style.Palette.PrimaryDark
|
||||
l.Font.Color = style.Palette.TextOnPrimary
|
||||
}),
|
||||
}
|
||||
})
|
||||
|
||||
return ui.RunWait(render, style, view, true)
|
||||
return ui.RunWait(render, ui.DefaultStyle(), &basic{plus: plus}, true)
|
||||
}
|
||||
|
||||
func main() {
|
||||
|
Loading…
Reference in New Issue
Block a user