Line data Source code
1 : package styled
2 :
3 : import (
4 : "github.com/hajimehoshi/ebiten/v2"
5 : )
6 :
7 : // TextAlign は一覧セル内のテキスト揃え方向を表す
8 : type TextAlign int
9 :
10 : // テキスト揃え方向の定数
11 : const (
12 : AlignLeft TextAlign = iota
13 : AlignRight
14 : )
15 :
16 : // Cell は一覧の1セル。Icon が非 nil ならアイコンセル、nil なら文字列セル。
17 : // アイコンは任意の列に置けるので、行はアイコンと文字列が混ざった一様な []Cell になる。
18 : // 将来アイコンと文字列を1セルへ併記したくなったら両方を持たせて拡張できる
19 : type Cell struct {
20 : Text string
21 : Icon *ebiten.Image
22 : }
23 :
24 : // TextCell は文字列を表すセルを返す
25 1 : func TextCell(s string) Cell { return Cell{Text: s} }
26 :
27 : // IconCell はアイコンを表すセルを返す。img が nil のときは透明セルになり、桁だけ合う
28 1 : func IconCell(img *ebiten.Image) Cell { return Cell{Icon: img} }
29 :
30 : // TextCells は文字列だけの行を手早く組む
31 : func TextCells(ss ...string) []Cell {
32 1 : cells := make([]Cell, len(ss))
33 1 : for i, s := range ss {
34 1 : cells[i] = TextCell(s)
35 1 : }
36 1 : return cells
37 : }
|