~eliasnaur/gio-patches

widget/material: add the possiblility to change button text alignement v1 PROPOSED

manur
manur: 2
 widget/material: add the possiblility to change button text alignement
 Typo fix

 2 files changed, 18 insertions(+), 16 deletions(-)
Please squash your fixes to previous patches.

On Fri Jan 3, 2020 at 8:36 PM, manur wrote:
Next
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/9426/mbox | git am -3
Learn more about email & git

[PATCH] widget/material: add the possiblility to change button text alignement Export this patch

manur
By adding a public variable to the Button struct will allow user to set the direction of the text within the button
User will be able to define them depending on there need instead of only centered text
Signed-off-by: manur <dever@alt.tf>
---
 widget/material/button.go | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/widget/material/button.go b/widget/material/button.go
index b1a440d..d630805 100644
--- a/widget/material/button.go
+++ b/widget/material/button.go
@@ -20,11 +20,12 @@ import (
type Button struct {
	Text string
	// Color is the text color.
	Color        color.RGBA
	Font         text.Font
	Background   color.RGBA
	CornerRadius unit.Value
	shaper       *text.Shaper
	Color          color.RGBA
	Font           text.Font
	Background     color.RGBA
	CornerRadius   unit.Value
	shaper         *text.Shaper
	TextAlignement layout.Direction
}

type IconButton struct {
@@ -43,7 +44,8 @@ func (t *Theme) Button(txt string) Button {
		Font: text.Font{
			Size: t.TextSize.Scale(14.0 / 16.0),
		},
		shaper: t.Shaper,
		shaper:         t.Shaper,
		TextAlignement: layout.Center,
	}
}

@@ -80,7 +82,7 @@ func (b Button) Layout(gtx *layout.Context, button *widget.Button) {
		layout.Stacked(func() {
			gtx.Constraints.Width.Min = hmin
			gtx.Constraints.Height.Min = vmin
			layout.Align(layout.Center).Layout(gtx, func() {
			layout.Align(b.TextAlignement).Layout(gtx, func() {
				layout.Inset{Top: unit.Dp(10), Bottom: unit.Dp(10), Left: unit.Dp(12), Right: unit.Dp(12)}.Layout(gtx, func() {
					paint.ColorOp{Color: col}.Add(gtx.Ops)
					widget.Label{}.Layout(gtx, b.shaper, b.Font, b.Text)
-- 
2.24.1

[PATCH] Typo fix Export this patch

manur
Signed-off-by: manur <dever@alt.tf>
---

This will allow to use button material in larger widget and be able to set alignment of text
In my case i've used the button to avoid rewriting the layout/click visual response for a file explorer (used in a list , the button will take all available space but centering it doesn't look good)


 widget/material/button.go | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/widget/material/button.go b/widget/material/button.go
index d630805..86ccd59 100644
--- a/widget/material/button.go
+++ b/widget/material/button.go
@@ -20,12 +20,12 @@ import (
type Button struct {
	Text string
	// Color is the text color.
	Color          color.RGBA
	Font           text.Font
	Background     color.RGBA
	CornerRadius   unit.Value
	shaper         *text.Shaper
	TextAlignement layout.Direction
	Color         color.RGBA
	Font          text.Font
	Background    color.RGBA
	CornerRadius  unit.Value
	shaper        *text.Shaper
	TextAlignment layout.Direction
}

type IconButton struct {
@@ -44,8 +44,8 @@ func (t *Theme) Button(txt string) Button {
		Font: text.Font{
			Size: t.TextSize.Scale(14.0 / 16.0),
		},
		shaper:         t.Shaper,
		TextAlignement: layout.Center,
		shaper:        t.Shaper,
		TextAlignment: layout.Center,
	}
}

@@ -82,7 +82,7 @@ func (b Button) Layout(gtx *layout.Context, button *widget.Button) {
		layout.Stacked(func() {
			gtx.Constraints.Width.Min = hmin
			gtx.Constraints.Height.Min = vmin
			layout.Align(b.TextAlignement).Layout(gtx, func() {
			layout.Align(b.TextAlignment).Layout(gtx, func() {
				layout.Inset{Top: unit.Dp(10), Bottom: unit.Dp(10), Left: unit.Dp(12), Right: unit.Dp(12)}.Layout(gtx, func() {
					paint.ColorOp{Color: col}.Add(gtx.Ops)
					widget.Label{}.Layout(gtx, b.shaper, b.Font, b.Text)
-- 
2.24.1
Please squash your fixes to previous patches.

On Fri Jan 3, 2020 at 8:36 PM, manur wrote:
View this thread in the archives