ウィジェットカタログ

表示

文字、画像、数値を表示するウィジェット。操作は受け付けない。

basic.Text

文字列を Style の規則に従って行分割し、表示するウィジェット。和文の禁則処理、縦書き、両端揃えに対応する。Style.MaxLines で行数を制限すると、収まらない分を省略記号「…」で切り詰める。スクリーンリーダーは全文を読む。

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

basic.Textbasic.Text
themed(func(th *theme.Theme) core.Widget {
	return basic.SizedBox{Width: 340, Child: basic.Column{Size: layout.MainMin, Cross: layout.CrossStart, Spacing: theme.Space6, Children: []core.Widget{
		basic.Text{Content: "Large title", Style: th.Text.LargeTitle},
		basic.Text{Content: "Title", Style: th.Text.Title},
		basic.Text{Content: "Body text breaks into lines by the rules of its style, and the line height stays on an even grid."},
		basic.Text{Content: "Caption in the secondary ink", Style: colored(th.Text.Caption, th.Color.Ink2)},
		// MaxLines cuts the text short with an ellipsis.
		basic.Text{Content: "A one-line preview of a long message that does not fit in the row", Style: th.Text.Body.WithMaxLines(1)},
	}}}
})

basic.RichText

見た目の異なる区間を 1 つの段落に混在させて表示するウィジェット。ルビと傍点も付けられ、Background で検索の一致などに背景色を敷ける。Style.MaxLines は Text と同じく働く。

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

basic.RichTextbasic.RichText
themed(func(th *theme.Theme) core.Widget {
	c := &th.Color
	return basic.SizedBox{Width: 320, Child: basic.RichText{Style: colored(th.Text.Body, c.Ink).WithMaxLines(2), Spans: []text.Span{
		{Text: "Rich text mixes "},
		{Text: "accented", Style: colored(th.Text.Body, c.AccentInk)},
		{Text: ", "},
		{Text: "bold", Style: colored(th.Text.Body, c.Ink).WithWeight(700)},
		{Text: ", "},
		{Text: "large", Style: text.Style{Size: 20, Color: c.Ink}},
		{Text: ", "},
		{Text: "quiet", Style: colored(th.Text.Caption, c.Ink2)},
		{Text: " and "},
		{Text: "highlighted", Background: c.Warning.WithAlpha(0.35)},
		{Text: " runs in one paragraph that wraps, and stops after two lines with an ellipsis."},
	}}}
})

field.SelectionArea

配下の Text と RichText を、マウスとキーボードで選択してコピーできるようにする。選択は段落をまたぐことができ、ルビの部分は親文字だけがコピーされる。

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

field.SelectionAreafield.SelectionArea
themed(func(th *theme.Theme) core.Widget {
	return basic.SizedBox{Width: 380, Child: field.SelectionArea{Child: basic.Column{
		Size: layout.MainMin, Cross: layout.CrossStart, Spacing: theme.Space8, Children: []core.Widget{
			basic.Text{Content: "Upload failed", Style: th.Text.Title},
			basic.Text{Content: "dial tcp 192.0.2.10:443: i/o timeout"},
			basic.Text{Content: "Drag, double click or Ctrl+A, then Ctrl+C.", Style: colored(th.Text.Caption, th.Color.Ink2)},
		},
	}}}
})

basic.Icon

24 単位の格子の上に定義したベクター図形を描くアイコン。Label が無い場合は装飾として扱われる。よく使う 24 種の図形は icons パッケージにある(フォルダ、ファイル、検索、閉じる、山形、歯車、ごみ箱など)。

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

basic.Iconbasic.Icon
themed(func(th *theme.Theme) core.Widget {
	// The stock icons of package icons. Build them once and keep them, as
	// in InitState: each call makes a new path.
	set := []*paint.Path{
		icons.Folder(), icons.File(), icons.Document(), icons.Image(), icons.Search(), icons.Plus(),
		icons.Minus(), icons.Close(), icons.Check(), icons.ChevronLeft(), icons.ChevronRight(), icons.ChevronUp(),
		icons.ChevronDown(), icons.Settings(), icons.Trash(), icons.Edit(), icons.Copy(), icons.Home(),
		icons.Star(), icons.Info(), icons.Warning(), icons.Error(), icons.Menu(), icons.More(),
	}
	stock := make([]core.Widget, len(set))
	for i, p := range set {
		stock[i] = basic.Icon{Path: p, Color: th.Color.Ink2}
	}
	return basic.Column{Size: layout.MainMin, Cross: layout.CrossStart, Spacing: theme.Space20, Children: []core.Widget{
		basic.Row{Size: layout.MainMin, Spacing: theme.Space16, Cross: layout.CrossCenter, Children: []core.Widget{
			basic.Icon{Path: set[0], Color: th.Color.AccentInk, Label: "Folder"},
			basic.Icon{Path: set[18], Size: 32, Color: th.Color.Danger},
			basic.Icon{Path: set[8], Size: 16, Color: th.Color.Success},
			basic.Icon{Path: circleIcon(), Color: th.Color.Ink2}, // a path of your own
		}},
		basic.SizedBox{Width: 400, Child: basic.Wrap{Spacing: theme.Space16, RunSpacing: theme.Space16, Children: stock}},
	}}
})

basic.Image

画像を表示するウィジェット。Fit で枠への収め方、Radius で角丸、Quality で拡大縮小の補間方法を選ぶ。

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

basic.Imagebasic.Image
picture := photo() // paint.NewImage of an image.Image, made once and kept
return basic.Row{Size: layout.MainMin, Spacing: theme.Space16, Children: []core.Widget{
	basic.Image{Source: picture, Width: 160, Label: "Hills under a clear sky"},
	basic.Image{Source: picture, Width: 100, Height: 100, Fit: layout.FitCover, Radius: 50},
	basic.Image{Source: picture, Width: 48, Height: 48, Quality: paint.FilterNearest},
}}

basic.SVG

SVG 画像を正方形に収めて描画するウィジェット。Color は、アイコンセットが描画に使う currentColor の値になる。

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

basic.SVGbasic.SVG
	cloud, err := paint.ParseSVG([]byte(`<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<path d="M7 18h10a4 4 0 0 0 .5-7.97A6 6 0 0 0 6.1 9.5 4.5 4.5 0 0 0 7 18z"/></svg>`))
	if err != nil {
		panic(err)
	}
	return themed(func(th *theme.Theme) core.Widget {
		return basic.Row{Size: layout.MainMin, Spacing: theme.Space16, Children: []core.Widget{
			basic.SVG{Data: cloud, Label: "Cloud"},
			basic.SVG{Data: cloud, Size: 36, Color: th.Color.AccentInk},
			basic.SVG{Data: cloud, Size: 56, Color: th.Color.Ink2},
		}}
	})

basic.AnimatedImage

GIF、APNG、WebP のアニメーション画像を再生するウィジェット。動きを減らす設定が有効なときは、最初のフレームで止まる。

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

basic.AnimatedImagebasic.AnimatedImage
movie, err := paint.DecodeAnimation(bytes.NewReader(blinkGIF()))
if err != nil {
	panic(err)
}
return basic.AnimatedImage{Source: movie, Width: 96, Height: 96, Radius: 12, Quality: paint.FilterNearest, Label: "Blinking light"}

control.Badge

未読数、短い語、点で注意を促すバッジ。子を指定すると、その右上に重ねて表示される。

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

control.Badgecontrol.Badge
themed(func(th *theme.Theme) core.Widget {
	inbox := basic.Icon{Path: squareIcon(), Color: th.Color.Ink2}
	return basic.Row{Size: layout.MainMin, Spacing: theme.Space24, Cross: layout.CrossCenter, Children: []core.Widget{
		control.Badge{Count: 3, Child: inbox},
		control.Badge{Count: 120, Child: inbox},
		control.Badge{Dot: true, Child: inbox},
		control.Badge{Label: "New"},
		control.Badge{Count: 12, Quiet: true},
	}}
})

control.Card

1 つのまとまった内容を載せるカード。OnPress を指定すると、カード全体がボタンになる。

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

control.Cardcontrol.Card
basic.Row{Size: layout.MainMin, Spacing: theme.Space16, Cross: layout.CrossStart, Children: []core.Widget{
	basic.SizedBox{Width: 200, Child: control.Card{Label: "Summary", Child: basic.Column{
		Size: layout.MainMin, Cross: layout.CrossStart, Spacing: theme.Space6, Children: []core.Widget{
			basic.Text{Content: "Summary"},
			basic.Text{Content: "A plain card holds one piece of content."},
		},
	}}},
	basic.SizedBox{Width: 200, Child: control.Card{Label: "Open note", OnPress: func() {}, Child: basic.Column{
		Size: layout.MainMin, Cross: layout.CrossStart, Spacing: theme.Space6, Children: []core.Widget{
			basic.Text{Content: "Pressable"},
			basic.Text{Content: "With OnPress the whole card is a button."},
		},
	}}},
}}

control.Disclosure

見出しを押すと下の内容が開閉するウィジェット。閉じている間は中身がレイアウトされず、Tab キーでの移動や支援技術からも飛ばされる。OnChange を指定すると開閉の状態を親が管理するようになり、いくつか並べてアコーディオンにできる。

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

control.Disclosurecontrol.Disclosure
control.Disclosure{Title: "Advanced", Child: basic.Text{Content: "Closed, the content is not laid out.", Style: note}},
control.Disclosure{Title: "Sync", Open: true, Child: basic.Text{
	Content: "Open starts it open. Without OnChange it keeps its own state.", Style: note,
}},
control.Disclosure{Title: "Notifications", Header: basic.Row{Size: layout.MainMin, Spacing: theme.Space6, Children: []core.Widget{
	basic.Text{Content: "Notifications", Style: th.Text.Headline}, control.Badge{Count: 3},
}}, Child: basic.Text{Content: "A header can hold a badge.", Style: note}},

interact.InteractiveViewer

子をパンとズームで表示するウィジェット。ドラッグで移動し、Ctrl+ホイールかピンチで、ポインタの位置を中心に拡大縮小する。WheelZooms を指定すると、画像ビューアのようにホイールだけでも拡大縮小する。矢印キーは動かせる余地があるときだけ使い、それ以外はアプリのショートカットに渡す。Keys で矢印キーを使わないことも、フォーカスを受け取らないこともできる。子のレイアウトは 1 度だけ行われ、中のボタンもそのまま押せる。ViewerController を使うと、外から表示を動かせる。

パッケージ github.com/bankai-tensei/gowaku/widgets/interact · 関連 interact.ViewerController, interact.ViewerBoundary, interact.ViewerKeys

interact.InteractiveViewerinteract.InteractiveViewer
var view interact.ViewerController
view.Fit(false) // once the viewer knows its size
return basic.SizedBox{Width: 440, Height: 280, Child: basic.Container{
	Radius: th.Radius.Control, Border: paint.Stroke{Width: 1, Color: th.Color.Hair},
	Child: interact.InteractiveViewer{
		Controller: &view, MinScale: 0.2, MaxScale: 6, BoundaryMargin: 16,
		DoubleTapZoom: true, Label: "Drawing", Child: drawing,
	},
}}

basic.Divider

内容の区切りに引く細い線。Indent で端に余白を空け、Axis で縦線にもできる。

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

basic.Dividerbasic.Divider
basic.SizedBox{Width: 300, Child: basic.Column{Size: layout.MainMin, Cross: layout.CrossStretch, Spacing: theme.Space12, Children: []core.Widget{
	basic.Text{Content: "Above the line"},
	basic.Divider{},
	basic.Text{Content: "Indented line below"},
	basic.Divider{Indent: theme.Space16},
	basic.Row{Size: layout.MainMin, Spacing: theme.Space12, Children: []core.Widget{
		basic.Text{Content: "Left"},
		basic.SizedBox{Height: 20, Child: basic.Divider{Axis: layout.Vertical}},
		basic.Text{Content: "Right"},
	}},
}}}

control.Sparkline

表のセルに収まる小さな折れ線グラフと棒グラフ。軸も凡例も描かない。NaN の値は欠損として途切れ、棒はゼロを基準に上下へ伸びる。描画時にメモリを割り当てない。

パッケージ github.com/bankai-tensei/gowaku/widgets/control · 関連 control.SparklineKind

control.Sparklinecontrol.Sparkline
basic.Row{Size: layout.MainMin, Cross: layout.CrossCenter, Spacing: theme.Space24, Children: []core.Widget{
	basic.SizedBox{Width: 140, Height: 28, Child: control.Sparkline{
		Data: trend, Fill: true, MarkLast: true, Label: "Temperature, now 21.4 degrees",
	}},
	basic.SizedBox{Width: 120, Height: 28, Child: control.Sparkline{Kind: control.SparklineBars, Data: change}},
}}