mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-06 18:05:35 +00:00
widget: simplify Editor event flushing
Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
+5
-4
@@ -98,6 +98,11 @@ func (e *Editor) Events(gtx layout.Context) []EditorEvent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (e *Editor) processEvents(gtx layout.Context) {
|
func (e *Editor) processEvents(gtx layout.Context) {
|
||||||
|
// Flush events from before the previous Layout.
|
||||||
|
n := copy(e.events, e.events[e.prevEvents:])
|
||||||
|
e.events = e.events[:n]
|
||||||
|
e.prevEvents = n
|
||||||
|
|
||||||
if e.shaper == nil {
|
if e.shaper == nil {
|
||||||
// Can't process events without a shaper.
|
// Can't process events without a shaper.
|
||||||
return
|
return
|
||||||
@@ -234,10 +239,6 @@ func (e *Editor) Focused() bool {
|
|||||||
|
|
||||||
// Layout lays out the editor.
|
// Layout lays out the editor.
|
||||||
func (e *Editor) Layout(gtx layout.Context, sh text.Shaper, font text.Font, size unit.Value) layout.Dimensions {
|
func (e *Editor) Layout(gtx layout.Context, sh text.Shaper, font text.Font, size unit.Value) layout.Dimensions {
|
||||||
// Flush events from before the previous frame.
|
|
||||||
copy(e.events, e.events[e.prevEvents:])
|
|
||||||
e.events = e.events[:len(e.events)-e.prevEvents]
|
|
||||||
e.prevEvents = len(e.events)
|
|
||||||
textSize := fixed.I(gtx.Px(size))
|
textSize := fixed.I(gtx.Px(size))
|
||||||
if e.font != font || e.textSize != textSize {
|
if e.font != font || e.textSize != textSize {
|
||||||
e.invalidate()
|
e.invalidate()
|
||||||
|
|||||||
Reference in New Issue
Block a user