github.com/Seikaijyu/gio@v0.0.1/widget/widget_test.go (about)

     1  // SPDX-License-Identifier: Unlicense OR MIT
     2  
     3  package widget_test
     4  
     5  import (
     6  	"image"
     7  	"testing"
     8  
     9  	"github.com/Seikaijyu/gio/f32"
    10  	"github.com/Seikaijyu/gio/io/pointer"
    11  	"github.com/Seikaijyu/gio/io/router"
    12  	"github.com/Seikaijyu/gio/io/semantic"
    13  	"github.com/Seikaijyu/gio/io/system"
    14  	"github.com/Seikaijyu/gio/layout"
    15  	"github.com/Seikaijyu/gio/op"
    16  	"github.com/Seikaijyu/gio/widget"
    17  )
    18  
    19  func TestBool(t *testing.T) {
    20  	var (
    21  		ops op.Ops
    22  		r   router.Router
    23  		b   widget.Bool
    24  	)
    25  	gtx := layout.NewContext(&ops, system.FrameEvent{Queue: &r})
    26  	layout := func() {
    27  		b.Layout(gtx, func(gtx layout.Context) layout.Dimensions {
    28  			semantic.CheckBox.Add(gtx.Ops)
    29  			semantic.DescriptionOp("description").Add(gtx.Ops)
    30  			return layout.Dimensions{Size: image.Pt(100, 100)}
    31  		})
    32  	}
    33  	layout()
    34  	r.Frame(gtx.Ops)
    35  	r.Queue(
    36  		pointer.Event{
    37  			Source:   pointer.Touch,
    38  			Kind:     pointer.Press,
    39  			Position: f32.Pt(50, 50),
    40  		},
    41  		pointer.Event{
    42  			Source:   pointer.Touch,
    43  			Kind:     pointer.Release,
    44  			Position: f32.Pt(50, 50),
    45  		},
    46  	)
    47  	ops.Reset()
    48  	layout()
    49  	r.Frame(gtx.Ops)
    50  	tree := r.AppendSemantics(nil)
    51  	n := tree[0].Children[0].Desc
    52  	if n.Description != "description" {
    53  		t.Errorf("unexpected semantic description: %s", n.Description)
    54  	}
    55  	if n.Class != semantic.CheckBox {
    56  		t.Errorf("unexpected semantic class: %v", n.Class)
    57  	}
    58  	if !b.Value || !n.Selected {
    59  		t.Error("click did not select")
    60  	}
    61  }