mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-01 07:35:40 +00:00
widget: [API] add content widget parameter to Enum.Layout
To make the semantic relation between the enum widget and its content, the content must be laid out inside the enum clip rect. This is an API change. Users of Enum.Layout must provide a content widget. Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
+8
-3
@@ -7,6 +7,7 @@ import (
|
||||
|
||||
"gioui.org/gesture"
|
||||
"gioui.org/layout"
|
||||
"gioui.org/op"
|
||||
"gioui.org/op/clip"
|
||||
)
|
||||
|
||||
@@ -44,8 +45,11 @@ func (e *Enum) Hovered() (string, bool) {
|
||||
}
|
||||
|
||||
// Layout adds the event handler for key.
|
||||
func (e *Enum) Layout(gtx layout.Context, key string) layout.Dimensions {
|
||||
defer clip.Rect(image.Rectangle{Max: gtx.Constraints.Min}).Push(gtx.Ops).Pop()
|
||||
func (e *Enum) Layout(gtx layout.Context, key string, content layout.Widget) layout.Dimensions {
|
||||
m := op.Record(gtx.Ops)
|
||||
dims := content(gtx)
|
||||
c := m.Stop()
|
||||
defer clip.Rect(image.Rectangle{Max: dims.Size}).Push(gtx.Ops).Pop()
|
||||
|
||||
if index(e.values, key) == -1 {
|
||||
e.values = append(e.values, key)
|
||||
@@ -72,6 +76,7 @@ func (e *Enum) Layout(gtx layout.Context, key string) layout.Dimensions {
|
||||
}
|
||||
clk.Add(gtx.Ops)
|
||||
}
|
||||
c.Add(gtx.Ops)
|
||||
|
||||
return layout.Dimensions{Size: gtx.Constraints.Min}
|
||||
return dims
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user