mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-04 08:55:35 +00:00
example/kitchen: add ButtonLayout example
Updates the kitchen example codebase showing ButtonLayout functionality.
This commit is contained in:
@@ -19,6 +19,7 @@ import (
|
||||
|
||||
"gioui.org/app"
|
||||
"gioui.org/app/headless"
|
||||
"gioui.org/font/gofont"
|
||||
"gioui.org/io/system"
|
||||
"gioui.org/layout"
|
||||
"gioui.org/text"
|
||||
@@ -27,8 +28,6 @@ import (
|
||||
"gioui.org/widget/material"
|
||||
|
||||
"golang.org/x/exp/shiny/materialdesign/icons"
|
||||
|
||||
"gioui.org/font/gofont"
|
||||
)
|
||||
|
||||
var screenshot = flag.String("screenshot", "", "save a screenshot to a file and exit")
|
||||
@@ -37,6 +36,10 @@ type scaledConfig struct {
|
||||
Scale float32
|
||||
}
|
||||
|
||||
type iconAndTextButton struct {
|
||||
theme *material.Theme
|
||||
}
|
||||
|
||||
func main() {
|
||||
flag.Parse()
|
||||
editor.SetText(longText)
|
||||
@@ -109,6 +112,7 @@ var (
|
||||
}
|
||||
button = new(widget.Button)
|
||||
greenButton = new(widget.Button)
|
||||
iconTextButton = new(widget.Button)
|
||||
iconButton = new(widget.Button)
|
||||
radioButtonsGroup = new(widget.Enum)
|
||||
list = &layout.List{
|
||||
@@ -120,6 +124,33 @@ var (
|
||||
checkbox = new(widget.CheckBox)
|
||||
)
|
||||
|
||||
func (b iconAndTextButton) Layout(gtx *layout.Context, button *widget.Button, icon *material.Icon, word string) {
|
||||
b.theme.ButtonLayout().Layout(gtx, iconTextButton, func() {
|
||||
iconAndLabel := layout.Flex{Axis: layout.Horizontal, Alignment: layout.Middle}
|
||||
textIconSpacer := unit.Dp(5)
|
||||
|
||||
layIcon := layout.Rigid(func() {
|
||||
layout.Inset{Right: textIconSpacer}.Layout(gtx, func() {
|
||||
size := gtx.Px(unit.Dp(56)) - 2*gtx.Px(unit.Dp(16))
|
||||
if icon != nil {
|
||||
icon.Layout(gtx, unit.Px(float32(size)))
|
||||
gtx.Dimensions = layout.Dimensions{
|
||||
Size: image.Point{X: size, Y: size},
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
layLabel := layout.Rigid(func() {
|
||||
layout.Inset{Left: textIconSpacer}.Layout(gtx, func() {
|
||||
widget.Label{}.Layout(gtx, b.theme.Shaper, text.Font{}, b.theme.TextSize, word)
|
||||
})
|
||||
})
|
||||
|
||||
iconAndLabel.Layout(gtx, layIcon, layLabel)
|
||||
})
|
||||
}
|
||||
|
||||
func kitchen(gtx *layout.Context, th *material.Theme) {
|
||||
widgets := []func(){
|
||||
func() {
|
||||
@@ -148,6 +179,11 @@ func kitchen(gtx *layout.Context, th *material.Theme) {
|
||||
th.IconButton(icon).Layout(gtx, iconButton)
|
||||
})
|
||||
}),
|
||||
layout.Rigid(func() {
|
||||
in.Layout(gtx, func() {
|
||||
iconAndTextButton{th}.Layout(gtx, iconTextButton, icon, "Horizontal button")
|
||||
})
|
||||
}),
|
||||
layout.Rigid(func() {
|
||||
in.Layout(gtx, func() {
|
||||
for button.Clicked(gtx) {
|
||||
|
||||
Reference in New Issue
Block a user