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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
|
#include "UI.hpp"
#include "Model/GlobalStates.hpp"
#include "Model/Project.hpp"
#include "Model/Template/TableTemplate.hpp"
#include "Model/Template/Template.hpp"
#include "UI/Localization.hpp"
#include <imgui.h>
#include <imgui_extra_math.h>
#include <imgui_stdlib.h>
#include <fstream>
#include <iostream>
#include <utility>
namespace {
class TemplateUI
{
public:
static std::unique_ptr<TemplateUI> CreateByKind(Template::Kind kind, std::unique_ptr<Template> tmpl);
static std::unique_ptr<TemplateUI> CreateByKind(Template::Kind kind);
virtual ~TemplateUI() = default;
virtual void Draw() = 0;
};
class TableTemplateUI : public TemplateUI
{
private:
std::unique_ptr<TableTemplate> mTable;
TableCell* mSelectedCell = nullptr;
public:
TableTemplateUI(std::unique_ptr<TableTemplate> table)
: mTable{ std::move(table) }
{
}
virtual void Draw() override
{
ImGui::Columns(2);
DrawInspector();
ImGui::NextColumn();
DrawTable();
ImGui::NextColumn();
ImGui::Columns(1);
}
private:
void DrawInspector()
{
if (ImGui::BeginTabBar("Inspector")) {
if (ImGui::BeginTabItem("Table")) {
DrawTableInspector();
ImGui::EndTabItem();
}
if (ImGui::BeginTabItem("Cell")) {
DrawCellInspector();
ImGui::EndTabItem();
}
ImGui::EndTabBar();
}
}
void DrawTableInspector()
{
// TODO
}
void DrawCellInspector()
{
if (mSelectedCell) {
} else {
ImGui::Text("Select a cell to edit");
}
}
void DrawTable()
{
constexpr int kCellSpacing = 20;
int colCount = mTable->GetTableWidth();
int rowCount = mTable->GetTableHeight();
float x = 0.0f;
float y = 0.0f;
for (int rowIdx = 0; rowIdx < rowCount; ++rowIdx) {
int rowHeight = mTable->GetRowHeight(rowIdx);
for (int colIdx = 0; colIdx < colCount; ++colIdx) {
int colWidth = mTable->GetColumnWidth(colIdx);
ImRect rect{
ImVec2(x, y),
ImVec2(colWidth, rowHeight),
};
// TODO
x += colWidth;
x += kCellSpacing;
}
y += rowHeight;
y += kCellSpacing;
}
}
};
std::unique_ptr<TemplateUI> TemplateUI::CreateByKind(Template::Kind kind, std::unique_ptr<Template> tmpl)
{
#pragma push_macro("UNIQUE_CAST")
#undef UNIQUE_CAST
#define UNIQUE_CAST(TargetType, input) std::unique_ptr<TargetType>(static_cast<TargetType*>(input.release()))
switch (kind) {
case Template::KD_Table: return std::make_unique<TableTemplateUI>(UNIQUE_CAST(TableTemplate, tmpl));
case Template::InvalidKind: return nullptr;
}
#pragma pop_macro("UNIQUE_CAST")
}
std::unique_ptr<TemplateUI> TemplateUI::CreateByKind(Template::Kind kind)
{
switch (kind) {
case Template::KD_Table: return std::make_unique<TableTemplateUI>(std::make_unique<TableTemplate>());
case Template::InvalidKind: return nullptr;
}
}
} // namespace
void UI::TemplatesTab()
{
auto ls = LocaleStrings::Instance.get();
auto& project = *GlobalStates::GetInstance().GetCurrentProject();
static std::unique_ptr<TemplateUI> openTemplate;
static AssetList::ListState state;
bool openedDummy = true;
// Toolbar item: close
if (ImGui::Button(ls->Close.Get(), openTemplate == nullptr)) {
openTemplate = nullptr;
}
// Toolbar item: open...
ImGui::SameLine();
if (ImGui::Button(ls->OpenAsset.Get())) {
ImGui::OpenPopup(ls->OpenAssetDialogTitle.Get());
}
if (ImGui::BeginPopupModal(ls->OpenAssetDialogTitle.Get(), &openedDummy, ImGuiWindowFlags_AlwaysAutoResize)) {
if (ImGui::Button(ls->Open.Get(), state.SelectedAsset == nullptr)) {
auto kind = static_cast<Template::Kind>(state.SelectedAsset->Payload);
openTemplate = TemplateUI::CreateByKind(kind);
}
ImGui::SameLine();
project.Templates.DisplayControls(state);
project.Templates.DisplayDetailsList(state);
ImGui::EndPopup();
}
// Toolbar item: manage...
ImGui::SameLine();
if (ImGui::Button(ls->ManageAssets.Get())) {
ImGui::OpenPopup(ls->ManageAssetsDialogTitle.Get());
}
if (ImGui::BeginPopupModal(ls->ManageAssetsDialogTitle.Get(), &openedDummy, ImGuiWindowFlags_AlwaysAutoResize)) {
project.Templates.DisplayControls(state);
project.Templates.DisplayDetailsList(state);
ImGui::EndPopup();
}
if (openTemplate) {
openTemplate->Draw();
}
}
|