-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.cpp
More file actions
73 lines (58 loc) · 1.93 KB
/
Main.cpp
File metadata and controls
73 lines (58 loc) · 1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include <Siv3D.hpp>
#include <FlexLayout.hpp>
// <数値>_px や <数値>_ch などのリテラルを使えるようにする
using namespace FlexLayout::Literals;
void Main()
{
Window::SetStyle(WindowStyle::Sizable);
Scene::SetBackground(Palette::White);
// レイアウト本体
FlexLayout::Layout layout{ U"Layout.xml", FlexLayout::EnableHotReload::Yes };
FlexLayout::Layout templateLayout{ U"Template.xml", FlexLayout::EnableHotReload::Yes };
// ボックスの描画関数
std::function<void(const FlexLayout::Box&)> drawBox;
drawBox = [&](const FlexLayout::Box& box) {
auto borderAreaRect = box.borderAreaRect();
auto contentAreaRect = box.contentAreaRect();
// 描画
box.drawFrame(Palette::Gray);
if (auto label = box.asLabel())
{
label->draw(Palette::Black);
}
// 子ボックスを再帰的に描画
for (const auto& child : box.children())
{
drawBox(child);
}
};
int cloneId = 0;
auto document = layout.document();
auto button = *document->getElementById(U"button")->as<FlexLayout::SimpleGUI::Button>();
auto slider = *document->getElementById(U"slider")->as<FlexLayout::SimpleGUI::Slider>();
auto cloneTarget = *document->getElementById(U"clone-target");
auto cloneButton = *document->getElementById(U"clone-button")->as<FlexLayout::SimpleGUI::Button>();
auto resetButton = *document->getElementById(U"reset-button")->as<FlexLayout::SimpleGUI::Button>();
while (System::Update())
{
layout.updateAll(Scene::Rect());
layout.drawUI();
if (auto document = layout.document())
{
drawBox(*document);
if (cloneButton->clicked())
{
auto clone = templateLayout.document()->cloneNode(true);
// IDのラベルを更新
clone.getElementById(U"label")->setTextContent(Format(cloneId++));
cloneTarget.appendChild(clone);
}
if (resetButton->clicked())
{
cloneId = 0;
cloneTarget.removeChildren();
}
FlexLayout::Debugger::DrawHoveredBoxLayout(*document);
}
}
}