mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-01 07:35:40 +00:00
widget: [API] split text widget Update from Layout
This commit introduces Update(gtx) functions for both Selectable and Editor, allowing their state to be updated explicitly prior to layout. This completes the transition that allows all Gio widgets to have their state updated ahead-of-time, ensuring that there is zero frame lag between an input event and the widget response to that event. Signed-off-by: Chris Waldon <christopher.waldon.dev@gmail.com>
This commit is contained in:
+12
-9
@@ -517,15 +517,10 @@ func (e *Editor) initBuffer() {
|
||||
e.text.WrapPolicy = e.WrapPolicy
|
||||
}
|
||||
|
||||
// Layout lays out the editor using the provided textMaterial as the paint material
|
||||
// for the text glyphs+caret and the selectMaterial as the paint material for the
|
||||
// selection rectangle.
|
||||
func (e *Editor) Layout(gtx layout.Context, lt *text.Shaper, font font.Font, size unit.Sp, textMaterial, selectMaterial op.CallOp) layout.Dimensions {
|
||||
// Update the state of the editor in response to input events.
|
||||
func (e *Editor) Update(gtx layout.Context) {
|
||||
e.initBuffer()
|
||||
e.text.Update(gtx, lt, font, size, e.processEvents)
|
||||
|
||||
dims := e.layout(gtx, textMaterial, selectMaterial)
|
||||
|
||||
e.processEvents(gtx)
|
||||
if e.focused {
|
||||
// Notify IME of selection if it changed.
|
||||
newSel := e.ime.selection
|
||||
@@ -551,8 +546,16 @@ func (e *Editor) Layout(gtx layout.Context, lt *text.Shaper, font font.Font, siz
|
||||
|
||||
e.updateSnippet(gtx, e.ime.start, e.ime.end)
|
||||
}
|
||||
}
|
||||
|
||||
return dims
|
||||
// Layout lays out the editor using the provided textMaterial as the paint material
|
||||
// for the text glyphs+caret and the selectMaterial as the paint material for the
|
||||
// selection rectangle.
|
||||
func (e *Editor) Layout(gtx layout.Context, lt *text.Shaper, font font.Font, size unit.Sp, textMaterial, selectMaterial op.CallOp) layout.Dimensions {
|
||||
e.Update(gtx)
|
||||
|
||||
e.text.Layout(gtx, lt, font, size)
|
||||
return e.layout(gtx, textMaterial, selectMaterial)
|
||||
}
|
||||
|
||||
// updateSnippet adds a key.SnippetOp if the snippet content or position
|
||||
|
||||
Reference in New Issue
Block a user