Line data Source code
1 : package messagewindow
2 :
3 : import (
4 : "image/color"
5 :
6 : "github.com/hajimehoshi/ebiten/v2"
7 : "github.com/kijimaD/ruins/internal/widgets/theme"
8 : )
9 :
10 : // 最小サイズの定数
11 : const (
12 : MinWidth = 600 // 最小幅
13 : MinHeight = 300 // 最小高さ
14 : )
15 :
16 : // 窓の高さと選択肢のページ件数の上下限
17 : const (
18 : maxHeightRatio = 0.8 // 窓の高さの上限。画面高に対する比
19 : minItemsPerPage = 3 // 1ページの選択肢の下限。窓が低くてもこれだけは出す
20 : maxItemsPerPage = 15 // 1ページの選択肢の上限。多すぎる一覧を切る
21 : )
22 :
23 : // windowSize はウィンドウサイズの設定
24 : type windowSize struct {
25 : Width int
26 : Height int
27 : }
28 :
29 : // windowPadding は内側余白の設定
30 : type windowPadding struct {
31 : Top int
32 : Bottom int
33 : Left int
34 : Right int
35 : }
36 :
37 : // windowStyle はウィンドウの外観設定
38 : type windowStyle struct {
39 : BackgroundColor color.Color
40 : BorderColor color.Color
41 : BorderWidth int
42 : windowPadding windowPadding
43 : }
44 :
45 : // textStyle はテキストの外観設定
46 : type textStyle struct {
47 : Color color.RGBA
48 : }
49 :
50 : // actionStyle はアクション表示の外観設定
51 : type actionStyle struct {
52 : ShowCloseButton bool
53 : CloseButtonText string
54 : ActionAreaColor color.Color
55 : ActionTextColor color.RGBA
56 : }
57 :
58 : // windowConfig はメッセージウィンドウの設定
59 : type windowConfig struct {
60 : // レイアウト設定
61 : Size windowSize
62 : Center bool // 画面中央に配置するか
63 :
64 : // 外観設定
65 : windowStyle windowStyle
66 : textStyle textStyle
67 : actionStyle actionStyle
68 :
69 : // 動作設定
70 : SkippableKeys []ebiten.Key
71 : CloseOnClick bool // ウィンドウ外クリックで閉じる
72 : ShowBackground bool // 背景オーバーレイを表示
73 : }
74 :
75 : // defaultWindowConfig はデフォルト設定を返す
76 : func defaultWindowConfig() windowConfig {
77 1 : return windowConfig{
78 1 : Size: windowSize{
79 1 : Width: MinWidth,
80 1 : Height: MinHeight,
81 1 : },
82 1 : Center: true,
83 1 :
84 1 : windowStyle: windowStyle{
85 1 : BackgroundColor: theme.WindowBackground,
86 1 : BorderColor: theme.WindowBorder,
87 1 : BorderWidth: 2,
88 1 : windowPadding: windowPadding{
89 1 : Top: 20,
90 1 : Bottom: 20,
91 1 : Left: 20,
92 1 : Right: 20,
93 1 : },
94 1 : },
95 1 :
96 1 : textStyle: textStyle{
97 1 : Color: theme.TextPrimary,
98 1 : },
99 1 :
100 1 : actionStyle: actionStyle{
101 1 : ShowCloseButton: true,
102 1 : CloseButtonText: "Close [Enter/Escape]",
103 1 : ActionAreaColor: theme.WindowActionBg,
104 1 : ActionTextColor: theme.WindowActionText,
105 1 : },
106 1 :
107 1 : SkippableKeys: []ebiten.Key{
108 1 : ebiten.KeyEnter,
109 1 : ebiten.KeyEscape,
110 1 : ebiten.KeySpace,
111 1 : },
112 1 : CloseOnClick: false,
113 1 : ShowBackground: true,
114 1 : }
115 : }
|