~eliasnaur/gio-patches

example/kitchen: add ButtonLayout example v1 PROPOSED

metaclips: 1
 example/kitchen: add ButtonLayout example

 3 files changed, 41 insertions(+), 5 deletions(-)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~eliasnaur/gio-patches/patches/10053/mbox | git am -3
Learn more about email & git

[PATCH v1] example/kitchen: add ButtonLayout example Export this patch

Updates the kitchen example codebase showing ButtonLayout functionality.
---
 example/go.mod             |  2 +-
 example/go.sum             |  4 ++--
 example/kitchen/kitchen.go | 40 ++++++++++++++++++++++++++++++++++++--
 3 files changed, 41 insertions(+), 5 deletions(-)

diff --git a/example/go.mod b/example/go.mod
index 8ad8187..366e3b4 100644
--- a/example/go.mod
+++ b/example/go.mod
@@ -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
diff --git a/example/go.sum b/example/go.sum
index 6255193..80c94b2 100644
--- a/example/go.sum
+++ b/example/go.sum
@@ -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=
diff --git a/example/kitchen/kitchen.go b/example/kitchen/kitchen.go
index 7755c62..50ff846 100644
--- a/example/kitchen/kitchen.go
+++ b/example/kitchen/kitchen.go
@@ -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) {
-- 
2.21.1 (Apple Git-122.3)
Thanks, merged!
View this thread in the archives