~pierrec/giox

705a4bff9210a19c4961a2307b899e09e8fbef5d — pierre 9 months ago 29b4175
widgetx: added Inactive.Border and Input.NoUnfocus

Signed-off-by: pierre <pierre.curto@gmail.com>
3 files changed, 27 insertions(+), 10 deletions(-)

M widgetx/file.go
M widgetx/input.go
M widgetx/menu.go
M widgetx/file.go => widgetx/file.go +5 -0
@@ 972,6 972,11 @@ func (f *File) init() {
				},
				Background: f.Palettes.Main.Bg,
				Padding:    unit.Dp(4),
				Border: widget.Border{
					Color:        f.Palettes.Area.ContrastBg,
					CornerRadius: unit.Dp(4),
					Width:        unit.Dp(2),
				},
			},
		}
		f.shadow = Inactive{

M widgetx/input.go => widgetx/input.go +8 -4
@@ 9,10 9,11 @@ import (
)

type Input struct {
	Padding  unit.Value
	Leading  layout.Widget
	Trailing layout.Widget
	Editor   *widget.Editor
	Padding   unit.Value
	Leading   layout.Widget
	Trailing  layout.Widget
	Editor    *widget.Editor
	NoUnfocus bool // disables ESC to unfocus

	changed   bool
	submitted bool


@@ 52,6 53,9 @@ func (in *Input) Layout(gtx layout.Context, ed layout.Widget) layout.Dimensions 
				return layout.Dimensions{}
			}),
			layout.Flexed(1, func(gtx layout.Context) layout.Dimensions {
				if in.NoUnfocus {
					return ed(gtx)
				}
				spy, gtx := eventx.Enspy(gtx)
				dims := ed(gtx)
				// Catch the ESC key being pressed to release the widget's focus.

M widgetx/menu.go => widgetx/menu.go +14 -6
@@ 32,6 32,7 @@ type MenuPopup struct {
	List       ClickList
	Background color.NRGBA
	Padding    unit.Value
	Border     widget.Border
	click      widget.Clickable
	cache      []listCache
}


@@ 75,6 76,7 @@ func (bk *Inactive) Layout(gtx layout.Context) layout.Dimensions {
	return layout.Dimensions{Size: gtx.Constraints.Min}
}

// Changed returns whether or not the area was clicked or ESC was pressed.
func (bk *Inactive) Changed() bool {
	changed := bk.changed
	bk.changed = false


@@ 100,15 102,21 @@ func (pl *MenuPopup) Layout(gtx layout.Context, num int, el layout.ListElement) 
	gtx.Constraints.Min = image.Point{X: maxX}
	dims := layout.Stack{}.Layout(gtx,
		layout.Expanded(func(gtx layout.Context) layout.Dimensions {
			paint.FillShape(gtx.Ops, pl.Background, clip.Rect{Max: gtx.Constraints.Min}.Op())
			defer op.Save(gtx.Ops).Load()
			radius := gtx.Metric.Px(pl.Border.CornerRadius)
			r := image.Rectangle{Max: gtx.Constraints.Min}
			clip.UniformRRect(layout.FRect(r), float32(radius)).Add(gtx.Ops)
			paint.Fill(gtx.Ops, pl.Background)
			return layout.Dimensions{Size: gtx.Constraints.Min}
		}),
		layout.Stacked(func(gtx layout.Context) layout.Dimensions {
			return layout.UniformInset(pl.Padding).Layout(gtx, func(gtx layout.Context) layout.Dimensions {
				return pl.List.Layout(gtx, num, func(gtx layout.Context, idx int, click *widget.Clickable) layout.Dimensions {
					item := pl.cache[idx]
					item.call.Add(gtx.Ops)
					return item.dims
			return pl.Border.Layout(gtx, func(gtx layout.Context) layout.Dimensions {
				return layout.UniformInset(pl.Padding).Layout(gtx, func(gtx layout.Context) layout.Dimensions {
					return pl.List.Layout(gtx, num, func(gtx layout.Context, idx int, click *widget.Clickable) layout.Dimensions {
						item := pl.cache[idx]
						item.call.Add(gtx.Ops)
						return item.dims
					})
				})
			})
		}),