6
6
template <class T >
7
7
class WithBool {
8
8
public:
9
+ WithBool (bool _b=false ) :b(_b) {};
9
10
bool b = false ;
10
11
T v;
11
12
};
@@ -17,6 +18,160 @@ class WithBool <void> {
17
18
bool b = false ;
18
19
};
19
20
21
+ class Pulldown
22
+ {
23
+ public:
24
+
25
+ Pulldown () = default ;
26
+
27
+ Pulldown (const Array<String>& items,const size_t & index = 0 , const Point& pos = { 0 ,0 })
28
+ : m_items{ items }
29
+ , m_rect{ pos, 0 , (FontAsset (U" main" ).height () + m_padding.y * 2 ) }
30
+ {
31
+ for (const auto & item : m_items)
32
+ {
33
+ m_rect.w = Max (m_rect.w , static_cast <int32>(FontAsset (U" main" )(item).region ().w ));
34
+ }
35
+ m_rect.w += (m_padding.x * 2 + m_downButtonSize);
36
+ m_index = Clamp (index, size_t (0 ), items.size ());
37
+ }
38
+
39
+ bool isEmpty () const
40
+ {
41
+ return m_items.empty ();
42
+ }
43
+
44
+ void update ()
45
+ {
46
+ if (isEmpty ())
47
+ {
48
+ return ;
49
+ }
50
+
51
+ if (m_rect.leftClicked ())
52
+ {
53
+ m_isOpen = (not m_isOpen);
54
+ }
55
+
56
+ Point pos = m_rect.pos .movedBy (0 , m_rect.h );
57
+
58
+ if (m_isOpen)
59
+ {
60
+ for (auto i : step (m_items.size ()))
61
+ {
62
+ if (const Rect rect{ pos, m_rect.w , m_rect.h };
63
+ rect.leftClicked ())
64
+ {
65
+ m_index = i;
66
+ m_isOpen = false ;
67
+ break ;
68
+ }
69
+
70
+ pos.y += m_rect.h ;
71
+ }
72
+ }
73
+ }
74
+
75
+ void draw () const
76
+ {
77
+ m_rect.draw ();
78
+
79
+ if (isEmpty ())
80
+ {
81
+ return ;
82
+ }
83
+
84
+ m_rect.drawFrame (1 , 0 , m_isOpen ? UIColor::Accent : UIColor::frame ());
85
+
86
+ Point pos = m_rect.pos ;
87
+
88
+ FontAsset (U" main" )(m_items[m_index]).draw (pos + m_padding, UIColor::text ());
89
+
90
+ Triangle{ (m_rect.x + m_rect.w - m_downButtonSize / 2.0 - m_padding.x ), (m_rect.y + m_rect.h / 2.0 ),
91
+ (m_downButtonSize * 0.5 ), 180_deg }.draw (UIColor::text ());
92
+
93
+ pos.y += m_rect.h ;
94
+
95
+ if (m_isOpen)
96
+ {
97
+ const Rect backRect{ pos, m_rect.w , (m_rect.h * m_items.size ()) };
98
+
99
+ backRect.drawShadow ({ 1 , 1 }, 4 , 1 ).draw ();
100
+
101
+ for (const auto & item : m_items)
102
+ {
103
+ if (const Rect rect{ pos, m_rect.size };
104
+ rect.mouseOver ())
105
+ {
106
+ rect.draw (UIColor::Accent.lerp (UIColor::Base,0.5 ));
107
+ }
108
+
109
+ FontAsset (U" main" )(item).draw ((pos + m_padding), Palette::Black);
110
+
111
+ pos.y += m_rect.h ;
112
+ }
113
+
114
+ backRect.drawFrame (1 , 0 , Palette::Gray);
115
+ }
116
+ }
117
+
118
+ void setPos (const Point& pos)
119
+ {
120
+ m_rect.setPos (pos);
121
+ }
122
+
123
+ const Rect& getRect () const
124
+ {
125
+ return m_rect;
126
+ }
127
+
128
+ size_t getIndex () const
129
+ {
130
+ return m_index;
131
+ }
132
+
133
+ String getItem () const
134
+ {
135
+ if (isEmpty ())
136
+ {
137
+ return {};
138
+ }
139
+
140
+ return m_items[m_index];
141
+ }
142
+
143
+ void setIndex (const size_t & index) {
144
+ if (InRange (index, size_t (0 ), m_items.size ())) {
145
+ m_index = index;
146
+ }
147
+ }
148
+
149
+ bool isOpen () {
150
+ return m_isOpen;
151
+ }
152
+
153
+ private:
154
+
155
+ Array<String> m_items;
156
+
157
+ size_t m_index = 0 ;
158
+
159
+ Size m_padding{ 6 , 2 };
160
+
161
+ Rect m_rect;
162
+
163
+ int32 m_downButtonSize = 16 ;
164
+
165
+ bool m_isOpen = false ;
166
+ };
167
+
168
+
169
+ class PltKey {
170
+ public:
171
+ Array<String> poslist{ U" top left" ,U" top right" ,U" bottom left" , U" bottom right" , U" top outside" , U" bottom outside" };
172
+ Pulldown pos{ poslist, 1 };
173
+ bool box;
174
+ };
20
175
21
176
// / @brief タイトルなどグラフ全体の設定
22
177
class WholeSetting {
@@ -31,6 +186,7 @@ class WholeSetting {
31
186
WithBool<void > logscale_x;
32
187
WithBool<void > logscale_y;
33
188
WithBool<TextEditState> sample;
189
+ WithBool<PltKey> key{ true };
34
190
WithBool<FilePath> loadfile;
35
191
};
36
192
0 commit comments