mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-01 07:35:40 +00:00
widget: ensure empty editor makes space for caret
Prior to this change an editor with no content and a zero minimum constraint would return itself has having width zero. This prevented users from being able to see the editor when they moved focus to it, as it could not display its caret. This simple change ensures that, at minimum, the editor returns its dimensions to include the width of a caret. Signed-off-by: Chris Waldon <christopher.waldon.dev@gmail.com>
This commit is contained in:
@@ -36,6 +36,26 @@ var english = system.Locale{
|
||||
Direction: system.LTR,
|
||||
}
|
||||
|
||||
// TestEditorZeroDimensions ensures that an empty editor still reserves
|
||||
// space for displaying its caret when the constraints allow for it.
|
||||
func TestEditorZeroDimensions(t *testing.T) {
|
||||
gtx := layout.Context{
|
||||
Ops: new(op.Ops),
|
||||
Constraints: layout.Constraints{
|
||||
Max: image.Pt(100, 100),
|
||||
},
|
||||
Locale: english,
|
||||
}
|
||||
cache := text.NewCache(gofont.Collection())
|
||||
fontSize := unit.Px(10)
|
||||
font := text.Font{}
|
||||
e := new(Editor)
|
||||
dims := e.Layout(gtx, cache, font, fontSize, nil)
|
||||
if dims.Size.X < 1 || dims.Size.Y < 1 {
|
||||
t.Errorf("expected empty editor to occupy enough space to display cursor, but returned dimensions %v", dims)
|
||||
}
|
||||
}
|
||||
|
||||
func TestEditorConfigurations(t *testing.T) {
|
||||
gtx := layout.Context{
|
||||
Ops: new(op.Ops),
|
||||
|
||||
Reference in New Issue
Block a user