mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-03 08:25:34 +00:00
widget: [API] add content widget argument to Editor.Layout
To make the semantic relation between the editor and its content clear, the editor clip operation must cover the content. This change adds an explicit widget argument to editor, and lays it out inside the clip rect. This is an API change. Users of Editor.Layout must provide a content widget. Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
+7
-4
@@ -462,8 +462,8 @@ func (e *Editor) Focused() bool {
|
||||
return e.focused
|
||||
}
|
||||
|
||||
// Layout lays out the editor.
|
||||
func (e *Editor) Layout(gtx layout.Context, sh text.Shaper, font text.Font, size unit.Value) layout.Dimensions {
|
||||
// Layout lays out the editor. If content is not nil, it is laid out on top.
|
||||
func (e *Editor) Layout(gtx layout.Context, sh text.Shaper, font text.Font, size unit.Value, content layout.Widget) layout.Dimensions {
|
||||
textSize := fixed.I(gtx.Px(size))
|
||||
if e.font != font || e.textSize != textSize {
|
||||
e.invalidate()
|
||||
@@ -497,10 +497,10 @@ func (e *Editor) Layout(gtx layout.Context, sh text.Shaper, font text.Font, size
|
||||
}
|
||||
e.makeValid()
|
||||
|
||||
return e.layout(gtx)
|
||||
return e.layout(gtx, content)
|
||||
}
|
||||
|
||||
func (e *Editor) layout(gtx layout.Context) layout.Dimensions {
|
||||
func (e *Editor) layout(gtx layout.Context, content layout.Widget) layout.Dimensions {
|
||||
// Adjust scrolling for new viewport and layout.
|
||||
e.scrollRel(0, 0)
|
||||
|
||||
@@ -576,6 +576,9 @@ func (e *Editor) layout(gtx layout.Context) layout.Dimensions {
|
||||
e.caret.on = e.focused && (!blinking || dt%timePerBlink < timePerBlink/2)
|
||||
}
|
||||
|
||||
if content != nil {
|
||||
content(gtx)
|
||||
}
|
||||
return layout.Dimensions{Size: e.viewSize, Baseline: e.dims.Baseline}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user