Files
gio/widget/widget_test.go
T
Elias Naur 650ccea28d io/pointer: [API] rename PointerEvent.Type to Kind
Kind is the idiomatic field name for distinguishing a struct without
using separate types.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2023-10-06 19:11:08 -05:00

62 lines
1.2 KiB
Go

// 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,
Kind: pointer.Press,
Position: f32.Pt(50, 50),
},
pointer.Event{
Source: pointer.Touch,
Kind: 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")
}
}