mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-03 16:35:36 +00:00
widget: update Editor dimensions after input
Fixes gio#162 Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
@@ -354,6 +354,7 @@ func (e *Editor) Layout(gtx layout.Context, sh text.Shaper, font text.Font, size
|
||||
|
||||
e.makeValid()
|
||||
e.processEvents(gtx)
|
||||
e.makeValid()
|
||||
|
||||
if viewSize := gtx.Constraints.Constrain(e.dims.Size); viewSize != e.viewSize {
|
||||
e.viewSize = viewSize
|
||||
|
||||
@@ -13,6 +13,8 @@ import (
|
||||
|
||||
"gioui.org/f32"
|
||||
"gioui.org/font/gofont"
|
||||
"gioui.org/io/event"
|
||||
"gioui.org/io/key"
|
||||
"gioui.org/layout"
|
||||
"gioui.org/op"
|
||||
"gioui.org/text"
|
||||
@@ -68,6 +70,35 @@ func TestEditor(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestEditorDimensions(t *testing.T) {
|
||||
e := new(Editor)
|
||||
tq := &testQueue{
|
||||
events: []event.Event{
|
||||
key.EditEvent{Text: "A"},
|
||||
},
|
||||
}
|
||||
gtx := layout.Context{
|
||||
Ops: new(op.Ops),
|
||||
Constraints: layout.Constraints{Max: image.Pt(100, 100)},
|
||||
Queue: tq,
|
||||
}
|
||||
cache := text.NewCache(gofont.Collection())
|
||||
fontSize := unit.Px(10)
|
||||
font := text.Font{}
|
||||
dims := e.Layout(gtx, cache, font, fontSize)
|
||||
if dims.Size.X == 0 {
|
||||
t.Errorf("EditEvent was not reflected in Editor width")
|
||||
}
|
||||
}
|
||||
|
||||
type testQueue struct {
|
||||
events []event.Event
|
||||
}
|
||||
|
||||
func (q *testQueue) Events(_ event.Tag) []event.Event {
|
||||
return q.events
|
||||
}
|
||||
|
||||
// assertCaret asserts that the editor caret is at a particular line
|
||||
// and column, and that the byte position matches as well.
|
||||
func assertCaret(t *testing.T, e *Editor, line, col, bytes int) {
|
||||
|
||||
Reference in New Issue
Block a user