forked from joejulian/gio
d5a0d2cf60
The input name better matches its purpose, in particular when we introduce input.Source. Signed-off-by: Elias Naur <mail@eliasnaur.com>
62 lines
1.2 KiB
Go
62 lines
1.2 KiB
Go
// SPDX-License-Identifier: Unlicense OR MIT
|
|
|
|
package widget_test
|
|
|
|
import (
|
|
"image"
|
|
"testing"
|
|
|
|
"gioui.org/app"
|
|
"gioui.org/f32"
|
|
"gioui.org/io/input"
|
|
"gioui.org/io/pointer"
|
|
"gioui.org/io/semantic"
|
|
"gioui.org/layout"
|
|
"gioui.org/op"
|
|
"gioui.org/widget"
|
|
)
|
|
|
|
func TestBool(t *testing.T) {
|
|
var (
|
|
ops op.Ops
|
|
r input.Router
|
|
b widget.Bool
|
|
)
|
|
gtx := app.NewContext(&ops, app.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")
|
|
}
|
|
}
|