mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-01 07:35:40 +00:00
widget: add semantic descriptions
Some semantic information is automatically extracted, but some must be provided by UI components. This change enriches the generic and material widgets with such information. Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
// SPDX-License-Identifier: Unlicense OR MIT
|
||||
|
||||
package widget_test
|
||||
|
||||
import (
|
||||
"image"
|
||||
"testing"
|
||||
|
||||
"gioui.org/f32"
|
||||
"gioui.org/io/pointer"
|
||||
"gioui.org/io/router"
|
||||
"gioui.org/io/semantic"
|
||||
"gioui.org/io/system"
|
||||
"gioui.org/layout"
|
||||
"gioui.org/op"
|
||||
"gioui.org/widget"
|
||||
)
|
||||
|
||||
func TestBool(t *testing.T) {
|
||||
var (
|
||||
ops op.Ops
|
||||
r router.Router
|
||||
b widget.Bool
|
||||
)
|
||||
gtx := layout.NewContext(&ops, system.FrameEvent{Queue: &r})
|
||||
layout := func() {
|
||||
b.Layout(gtx, func(gtx layout.Context) layout.Dimensions {
|
||||
semantic.CheckBox.Add(gtx.Ops)
|
||||
semantic.DescriptionOp("description").Add(gtx.Ops)
|
||||
return layout.Dimensions{Size: image.Pt(100, 100)}
|
||||
})
|
||||
}
|
||||
layout()
|
||||
r.Frame(gtx.Ops)
|
||||
r.Queue(
|
||||
pointer.Event{
|
||||
Source: pointer.Touch,
|
||||
Type: pointer.Press,
|
||||
Position: f32.Pt(50, 50),
|
||||
},
|
||||
pointer.Event{
|
||||
Source: pointer.Touch,
|
||||
Type: pointer.Release,
|
||||
Position: f32.Pt(50, 50),
|
||||
},
|
||||
)
|
||||
ops.Reset()
|
||||
layout()
|
||||
r.Frame(gtx.Ops)
|
||||
tree := r.AppendSemantics(nil)
|
||||
n := tree[0].Children[0].Desc
|
||||
if n.Description != "description" {
|
||||
t.Errorf("unexpected semantic description: %s", n.Description)
|
||||
}
|
||||
if n.Class != semantic.CheckBox {
|
||||
t.Errorf("unexpected semantic class: %v", n.Class)
|
||||
}
|
||||
if !b.Value || !n.Selected {
|
||||
t.Error("click did not select")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user