~eliasnaur/gio-patches

example/kitchen: update kitchen codebase v1 PROPOSED

metaclips: 1
 example/kitchen: update kitchen codebase

 3 files changed, 70 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/10046/mbox | git am -3
Learn more about email & git

[PATCH] example/kitchen: update kitchen codebase Export this patch

This updates the kitchen example codebase showing how to implement vertical and horizontal icon-text button using ButtonLayout
Signed-off-by: metaclips <utimichael9@gmail.com>
---
 example/go.mod             |  2 +-
 example/go.sum             |  4 +--
 example/kitchen/kitchen.go | 69 ++++++++++++++++++++++++++++++++++++--
 3 files changed, 70 insertions(+), 5 deletions(-)

diff --git a/example/go.mod b/example/go.mod
index 8ad8187..a84b628 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-20200322122032-5d7fbd761f4f
	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..7fc0309 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-20200322122032-5d7fbd761f4f h1:3yu2nIP3O6pAxif8ZwlcQO4YEBkfHOukSrflqC0Dhr4=
gioui.org v0.0.0-20200322122032-5d7fbd761f4f/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..b916d6b 100644
--- a/example/kitchen/kitchen.go
+++ b/example/kitchen/kitchen.go
@@ -19,6 +19,8 @@ import (

	"gioui.org/app"
	"gioui.org/app/headless"
	"gioui.org/font"
	"gioui.org/font/gofont"
	"gioui.org/io/system"
	"gioui.org/layout"
	"gioui.org/text"
@@ -27,8 +29,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 +37,18 @@ type scaledConfig struct {
	Scale float32
}

type iconAndTextButton struct {
	text            string
	textSize        unit.Value
	icon            *material.Icon
	iconSize        unit.Value
	iconTextHSpacer unit.Value
	iconTextVSpacer unit.Value
	button          *widget.Button
	padding         unit.Value
	axis            layout.Axis
}

func main() {
	flag.Parse()
	editor.SetText(longText)
@@ -118,6 +130,18 @@ var (
	topLabel = "Hello, Gio"
	icon     *material.Icon
	checkbox = new(widget.CheckBox)

	iconButtonLayout = iconAndTextButton{
		text:            "Horizontal button",
		textSize:        unit.Dp(14),
		icon:            icon,
		iconSize:        unit.Dp(56),
		padding:         unit.Dp(16),
		iconTextHSpacer: unit.Dp(5),
		iconTextVSpacer: unit.Dp(0),
		button:          new(widget.Button),
		axis:            layout.Horizontal,
	}
)

func kitchen(gtx *layout.Context, th *material.Theme) {
@@ -148,6 +172,47 @@ func kitchen(gtx *layout.Context, th *material.Theme) {
						th.IconButton(icon).Layout(gtx, iconButton)
					})
				}),
				layout.Rigid(func() {
					in.Layout(gtx, func() {
						for iconButtonLayout.button.Clicked(gtx) {
							if iconButtonLayout.axis == layout.Vertical {
								iconButtonLayout.axis = layout.Horizontal
								iconButtonLayout.text = "Horizontal button"
								iconButtonLayout.iconTextHSpacer = unit.Dp(5)
								iconButtonLayout.iconTextVSpacer = unit.Dp(0)
							} else {
								iconButtonLayout.axis = layout.Vertical
								iconButtonLayout.text = "Vertical button"
								iconButtonLayout.iconTextVSpacer = unit.Dp(5)
								iconButtonLayout.iconTextHSpacer = unit.Dp(0)
							}
						}

						th.ButtonLayout().Layout(gtx, iconButtonLayout.button, func() {
							iconAndLabel := layout.Flex{Axis: iconButtonLayout.axis, Alignment: layout.Middle}

							layIcon := layout.Rigid(func() {
								layout.Inset{Right: iconButtonLayout.iconTextHSpacer, Bottom: iconButtonLayout.iconTextVSpacer}.Layout(gtx, func() {
									size := gtx.Px(iconButtonLayout.iconSize) - 2*gtx.Px(iconButtonLayout.padding)
									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: iconButtonLayout.iconTextHSpacer, Top: iconButtonLayout.iconTextVSpacer}.Layout(gtx, func() {
									widget.Label{}.Layout(gtx, font.Default(), text.Font{}, iconButtonLayout.textSize, iconButtonLayout.text)
								})
							})

							iconAndLabel.Layout(gtx, layIcon, layLabel)
						})
					})
				}),
				layout.Rigid(func() {
					in.Layout(gtx, func() {
						for button.Clicked(gtx) {
-- 
2.21.1 (Apple Git-122.3)
Please mention ButtonLayout in the subject. For example:

example/kitchen: add ButtonLayout example

On Sun Mar 22, 2020 at 13:33, metaclips wrote:
View this thread in the archives