~eliasnaur/gio-patches

widget/material: Add ButtonLayout support to Widget v3 PROPOSED

metaclips: 1
 widget/material: Add ButtonLayout support to Widget

 1 files changed, 38 insertions(+), 0 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/10034/mbox | git am -3
Learn more about email & git

[PATCH v3] widget/material: Add ButtonLayout support to Widget Export this patch

This implements a ButtonLayout widget that allows widget insets to be drawn over button decoration
Fixes #43

Signed-off-by: metaclips <utimichael9@gmail.com>
---
 widget/material/button.go | 38 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)

diff --git a/widget/material/button.go b/widget/material/button.go
index 8cea790..524a8d4 100644
--- a/widget/material/button.go
+++ b/widget/material/button.go
@@ -38,6 +38,12 @@ type IconButton struct {
	Inset      layout.Inset
}

type ButtonLayout struct {
	Background color.RGBA
	Color      color.RGBA
	Padding    unit.Value
}

func (t *Theme) Button(txt string) Button {
	return Button{
		Text:       txt,
@@ -62,6 +68,14 @@ func (t *Theme) IconButton(icon *Icon) IconButton {
	}
}

func (t *Theme) ButtonLayout() ButtonLayout {
	return ButtonLayout{
		Background: t.Color.Primary,
		Color:      t.Color.InvText,
		Padding:    unit.Dp(16),
	}
}

func (b Button) Layout(gtx *layout.Context, button *widget.Button) {
	col := b.Color
	bgcol := b.Background
@@ -129,6 +143,30 @@ func (b IconButton) Layout(gtx *layout.Context, button *widget.Button) {
	)
}

func (b ButtonLayout) Layout(gtx *layout.Context, button *widget.Button, w layout.Widget) {
	layout.Stack{Alignment: layout.Center}.Layout(gtx,
		layout.Expanded(func() {
			rr := float32(gtx.Px(unit.Dp(4)))
			clip.Rect{
				Rect: f32.Rectangle{Max: f32.Point{
					X: float32(gtx.Constraints.Width.Min),
					Y: float32(gtx.Constraints.Height.Min),
				}},
				NE: rr, NW: rr, SE: rr, SW: rr,
			}.Op(gtx.Ops).Add(gtx.Ops)
			fill(gtx, b.Background)
			for _, c := range button.History() {
				drawInk(gtx, c)
			}
		}),
		layout.Stacked(func() {
			w()
			pointer.Ellipse(image.Rectangle{Max: gtx.Dimensions.Size}).Add(gtx.Ops)
			button.Layout(gtx)
		}),
	)
}

func toPointF(p image.Point) f32.Point {
	return f32.Point{X: float32(p.X), Y: float32(p.Y)}
}
-- 
2.21.1 (Apple Git-122.3)
Start with lowercase after the subject colon:

widget/material: add ButtonLayout

(drop "support to Widget", it is redundant)

On Thu Mar 19, 2020 at 17:29, metaclips wrote:
View this thread in the archives