Skip to content

Commit cad8f4d

Browse files
committed
key(凡例)の位置と囲いを追加
1 parent 9a66450 commit cad8f4d

File tree

3 files changed

+178
-0
lines changed

3 files changed

+178
-0
lines changed

pltGUI/plt_create.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@ void CreatePltFile(WholeSettingUI& whole, Array<GraphSettingUI>& graphs) {
3030
if (ws.logscale_x.b) writer << U"set logscale x";
3131
if (ws.logscale_y.b) writer << U"set logscale y";
3232
if (ws.sample.b) writer << U"set sample " << ws.sample.v.text;
33+
if (ws.key.b) {
34+
writer << U"set key " << ws.key.v.pos.getItem() << (ws.key.v.box ? U" box" : U"");
35+
}
36+
else {
37+
writer << U"unset key";
38+
}
39+
3340

3441

3542
// 全体設定の最後

pltGUI/plt_setting.h

Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
template <class T>
77
class WithBool {
88
public:
9+
WithBool(bool _b=false) :b(_b) {};
910
bool b = false;
1011
T v;
1112
};
@@ -17,6 +18,160 @@ class WithBool <void> {
1718
bool b = false;
1819
};
1920

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+
};
20175

21176
/// @brief タイトルなどグラフ全体の設定
22177
class WholeSetting {
@@ -31,6 +186,7 @@ class WholeSetting {
31186
WithBool<void> logscale_x;
32187
WithBool<void> logscale_y;
33188
WithBool<TextEditState> sample;
189+
WithBool<PltKey> key{ true };
34190
WithBool<FilePath> loadfile;
35191
};
36192

pltGUI/ui_plt_setting.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,28 @@ class WholeSettingUI : public ScrollableUI {
5050
MyGUI::Text(U"sample", dpos.x(180));
5151
MyGUI::TextBox(s.sample, dpos.y(55));
5252

53+
MyGUI::CheckBoxArea(s.key.b, dpos.x(20), s.key.v.pos.isOpen() ? Vec2(600, 250) : Vec2(600, 50));
54+
MyGUI::Text(U"key", dpos.x(180));
55+
s.key.v.pos.setPos((dpos.x(250) - Vec2(0, 15)).asPoint());
56+
s.key.v.pos.update();
57+
s.key.v.pos.draw();
58+
MyGUI::CheckBox(s.key.v.box, dpos.x(20));
59+
MyGUI::Text(U"box", dpos.y(55));
60+
if (s.key.v.pos.isOpen()) {
61+
dpos.y(200);
62+
}
63+
5364
MyGUI::CheckBoxArea(s.loadfile.b, dpos.x(20), Vec2(600, 50));
5465
MyGUI::Text(U"load", dpos.x(180));
5566
MyGUI::Text(FileSystem::FileName(s.loadfile.v), dpos.x(380));
5667
if (MyGUI::FolderIconButton(dpos.y(55))) {
5768
Optional<String> file = Dialog::OpenFile(Array{ FileFilter{U"gnuplot",{U"plt"}},FileFilter::AllFiles() });
5869
if (file) s.loadfile.v = *file;
5970
}
71+
72+
73+
74+
dpos.y(200);
6075
}
6176
};
6277

0 commit comments

Comments
 (0)