ウィジェットカタログ

入力処理とアクセシビリティ

自分では何も描かず、ポインタ、キーボード、ドラッグの扱いや支援技術への伝え方を子に加えるウィジェット。画像は無く、例のコードだけを載せる。

interact.GestureDetector

子へのタップ、ダブルタップ、右クリック、長押し、ドラッグ(開始・移動・終了)、ピンチを通知する。少し動いただけの押下はタップのままで、ドラッグにはならない。OnTapDownAt、OnTapAt、OnSecondaryTapAt は、位置とともに押していた修飾キーも渡すので、Shift や Ctrl を押しながらのクリックも扱える。

パッケージ github.com/bankai-tensei/gowaku/widgets/interact

自身では何も描画しないため、画像はありません。

interact.GestureDetector{
	OnTap:            func() { /* select */ },
	OnDoubleTap:      func() { /* open */ },
	OnSecondaryTapAt: func(layout.Tap) { /* a menu where the press was */ },
	OnLongPress:      func(_ geom.Offset, _ input.PointerDevice) { /* more choices */ },
	OnDragUpdate:     func(_, _ geom.Offset) { /* move by the delta */ },
	Child:            tile("Tap me", 120, 40),
}

interact.MouseRegion

ポインタの出入りを通知し、子の上でのカーソルの形を決める。

パッケージ github.com/bankai-tensei/gowaku/widgets/interact

自身では何も描画しないため、画像はありません。

interact.MouseRegion{
	Cursor:  input.CursorHand,
	OnEnter: func() { /* show the controls */ },
	OnExit:  func() { /* hide them */ },
	Child:   tile("Hover", 120, 40),
}

interact.Listener

子の上で起きたポインタのイベントをすべて渡す。ペンの筆圧も届くため、手描きの入力に使える。

パッケージ github.com/bankai-tensei/gowaku/widgets/interact

自身では何も描画しないため、画像はありません。

interact.Listener{
	OnPointer: func(e *core.PointerEvent) {
		switch e.Kind {
		case core.PointerDown:
			// start a stroke at e.Pos, as wide as e.Pressure for a pen
		case core.PointerMove:
			// add e.Pos to the stroke while one is going
		}
	},
	Child: basic.SizedBox{Width: 300, Height: 200},
}

interact.Focus

子がキーボード入力を受け取れるようにする。Tab キーは描画順にフォーカスを移す。

パッケージ github.com/bankai-tensei/gowaku/widgets/interact

自身では何も描画しないため、画像はありません。

interact.Focus{
	Enabled: true,
	OnKey: func(e *core.KeyEvent) bool {
		return e.Key == input.KeySpace // handled; false passes it on
	},
	OnShowFocus: func(_ bool) { /* show a FocusRing while true */ },
	Child:       tile("Focusable", 120, 40),
}

basic.IgnorePointer

ポインタを子に当てず、その下にあるものへ通す。

パッケージ github.com/bankai-tensei/gowaku/widgets/basic

自身では何も描画しないため、画像はありません。

basic.Stack{Children: []core.Widget{
	control.Button{Label: "Still clickable", OnPress: func() {}},
	basic.IgnorePointer{Child: basic.Container{Width: 160, Height: 30, Color: geom.RGBA(1, 1, 1, 0.2)}},
}}

interact.Draggable

子からデータをドラッグで持ち出す。同じウィンドウの中、別のウィンドウ、ほかのアプリへ渡せる。

パッケージ github.com/bankai-tensei/gowaku/widgets/interact

自身では何も描画しないため、画像はありません。

interact.Draggable{
	Data:      input.DragData{Text: "notes.txt"},
	Allowed:   input.DropCopy | input.DropMove,
	OnDragEnd: func(_ input.DropEffect) { /* remove the row on DropMove */ },
	Child:     tile("notes.txt", 120, 32),
}

interact.DragTarget

子にドロップされたテキストやファイルを受け取る。エクスプローラーやブラウザーなど、ほかのアプリからのドロップも受け付ける。

パッケージ github.com/bankai-tensei/gowaku/widgets/interact

自身では何も描画しないため、画像はありません。

interact.DragTarget{
	Kinds:   input.DataFiles,
	OnHover: func(_ bool) { /* light up while true */ },
	OnDrop:  func(_ input.DragData, _ geom.Offset) { /* open the files */ },
	Child:   tile("Drop files here", 240, 120),
}

interact.Semantics

子の意味を支援技術に伝え、スクリーンリーダーからの操作を受け付ける。標準のコントロールは、これを自前で備えている。

パッケージ github.com/bankai-tensei/gowaku/widgets/interact

自身では何も描画しないため、画像はありません。

interact.Semantics{
	Role: semantics.RoleButton, Label: "Play", Hint: "Plays the album from the start",
	OnTap: func() { /* play */ },
	Child: basic.Icon{Path: triangleIcon()},
}

interact.ExcludeSemantics

子を支援技術から隠す。Web の aria-hidden に当たる。アバターの頭文字のような、飾りにすぎないテキストに使う。画面への描画とポインタの扱いは変わらない。

パッケージ github.com/bankai-tensei/gowaku/widgets/interact

自身では何も描画しないため、画像はありません。

basic.Row{Size: layout.MainMin, Spacing: theme.Space8, Children: []core.Widget{
	// The initial only decorates; the name beside it is read.
	interact.ExcludeSemantics{Child: basic.Text{Content: "S"}},
	basic.Text{Content: "Sato Hana"},
}}

interact.FocusTraversalOrder

HTML の tabindex のように、Tab キーで移動する順番を決める。

パッケージ github.com/bankai-tensei/gowaku/widgets/interact

自身では何も描画しないため、画像はありません。

basic.Column{Children: []core.Widget{
	field.Input{Label: "Details", OnChange: func(string) {}},
	// Tab reaches the search field first, wherever it is painted.
	interact.FocusTraversalOrder{Order: 1, Child: field.Search{OnChange: func(string) {}}},
}}