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:
Elias Naur
2021-11-29 17:13:39 +01:00
parent 665e23693f
commit ac97b9d6e1
3 changed files with 36 additions and 31 deletions
+16 -14
View File
@@ -58,20 +58,22 @@ func (e EditorStyle) Layout(gtx layout.Context) layout.Dimensions {
if h := dims.Size.Y; gtx.Constraints.Min.Y < h {
gtx.Constraints.Min.Y = h
}
dims = e.Editor.Layout(gtx, e.shaper, e.Font, e.TextSize)
disabled := gtx.Queue == nil
if e.Editor.Len() > 0 {
paint.ColorOp{Color: blendDisabledColor(disabled, e.SelectionColor)}.Add(gtx.Ops)
e.Editor.PaintSelection(gtx)
paint.ColorOp{Color: blendDisabledColor(disabled, e.Color)}.Add(gtx.Ops)
e.Editor.PaintText(gtx)
} else {
call.Add(gtx.Ops)
}
if !disabled {
paint.ColorOp{Color: e.Color}.Add(gtx.Ops)
e.Editor.PaintCaret(gtx)
}
dims = e.Editor.Layout(gtx, e.shaper, e.Font, e.TextSize, func(gtx layout.Context) layout.Dimensions {
disabled := gtx.Queue == nil
if e.Editor.Len() > 0 {
paint.ColorOp{Color: blendDisabledColor(disabled, e.SelectionColor)}.Add(gtx.Ops)
e.Editor.PaintSelection(gtx)
paint.ColorOp{Color: blendDisabledColor(disabled, e.Color)}.Add(gtx.Ops)
e.Editor.PaintText(gtx)
} else {
call.Add(gtx.Ops)
}
if !disabled {
paint.ColorOp{Color: e.Color}.Add(gtx.Ops)
e.Editor.PaintCaret(gtx)
}
return dims
})
return dims
}