Line data Source code
1 : package menuframe
2 :
3 : import (
4 : "image"
5 :
6 : "github.com/kijimaD/ruins/internal/resources"
7 : "github.com/kijimaD/ruins/internal/widgets/theme"
8 : "github.com/kijimaD/ruins/internal/widgets/uicore"
9 : )
10 :
11 : // inputBox は1行入力欄の箱。テクスチャ枠を全面に敷き、中身は左右に余白を取って同じ矩形へ載せる。
12 : // 中身の縦位置は Text の VCenter で枠の中央へ合わせる。
13 : type inputBox struct {
14 : rect image.Rectangle
15 : frame uicore.Widget
16 : body uicore.Widget
17 : }
18 :
19 : // InputBox は1行入力欄の箱を組む。名前入力のように、テクスチャ枠の上へ入力中の文字列を
20 : // 載せる画面で使う。枠と余白の意匠は部品が持ち、置き場所は呼び出し側が Layout で決める。
21 : func InputBox(res resources.UIResources, body uicore.Widget) uicore.Widget {
22 1 : return &inputBox{
23 1 : frame: uicore.NewNineSlice(res.InputBG.Image, res.InputBG.BX, res.InputBG.BY),
24 1 : body: body,
25 1 : }
26 : }
27 :
28 : // Layout は Widget を実装する。枠を全面に、中身を左右余白の内側に置く。
29 : func (b *inputBox) Layout(r image.Rectangle) {
30 1 : b.rect = r
31 1 : b.frame.Layout(r)
32 1 : b.body.Layout(image.Rect(r.Min.X+theme.Space4, r.Min.Y, r.Max.X-theme.Space4, r.Max.Y))
33 1 : }
34 :
35 : // Draw は Widget を実装する。枠を敷いてから中身を描く。
36 : func (b *inputBox) Draw(cv uicore.Canvas) {
37 1 : b.frame.Draw(cv)
38 1 : b.body.Draw(cv)
39 1 : }
40 :
41 : // Children は Widget を実装する。
42 1 : func (b *inputBox) Children() []uicore.Widget { return []uicore.Widget{b.frame, b.body} }
43 :
44 : // Bounds は Widget を実装する。
45 1 : func (b *inputBox) Bounds() image.Rectangle { return b.rect }
|