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:
+1
-1
@@ -3,7 +3,7 @@ module gioui.org/example
|
||||
go 1.13
|
||||
|
||||
require (
|
||||
gioui.org v0.0.0-20200229151555-bd7c7a108a9e
|
||||
gioui.org v0.0.0-20200323110338-38ed6d156935
|
||||
github.com/go-gl/gl v0.0.0-20190320180904-bf2b1f2f34d7
|
||||
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72
|
||||
github.com/google/go-github/v24 v24.0.1
|
||||
|
||||
+2
-2
@@ -1,7 +1,7 @@
|
||||
cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
|
||||
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
|
||||
gioui.org v0.0.0-20200229151555-bd7c7a108a9e h1:jLQovLMnxFQfBQw4QkeGYkwSgDd2W39x18PxXkc32to=
|
||||
gioui.org v0.0.0-20200229151555-bd7c7a108a9e/go.mod h1:AHI9rFr6AEEHCb8EPVtb/p5M+NMJRKH58IOp8O3Je04=
|
||||
gioui.org v0.0.0-20200323110338-38ed6d156935 h1:708NsNJ+loIe+kf1J04ynMEZXnQBVuk6A7hmQNhEl10=
|
||||
gioui.org v0.0.0-20200323110338-38ed6d156935/go.mod h1:AHI9rFr6AEEHCb8EPVtb/p5M+NMJRKH58IOp8O3Je04=
|
||||
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
|
||||
github.com/go-gl/gl v0.0.0-20190320180904-bf2b1f2f34d7 h1:SCYMcCJ89LjRGwEa0tRluNRiMjZHalQZrVrvTbPh+qw=
|
||||
github.com/go-gl/gl v0.0.0-20190320180904-bf2b1f2f34d7/go.mod h1:482civXOzJJCPzJ4ZOX/pwvXBWSnzD4OKMdH4ClKGbk=
|
||||
|
||||
@@ -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