aboutsummaryrefslogtreecommitdiff
path: root/core/src/UI
diff options
context:
space:
mode:
Diffstat (limited to 'core/src/UI')
-rw-r--r--core/src/UI/UI_Templates.cpp34
-rw-r--r--core/src/UI/UI_Workflows.cpp14
2 files changed, 33 insertions, 15 deletions
diff --git a/core/src/UI/UI_Templates.cpp b/core/src/UI/UI_Templates.cpp
index 309ff21..ebf5f62 100644
--- a/core/src/UI/UI_Templates.cpp
+++ b/core/src/UI/UI_Templates.cpp
@@ -22,11 +22,12 @@ namespace {
class TemplateUI
{
public:
- static std::unique_ptr<TemplateUI> CreateByKind(Template::Kind kind, std::unique_ptr<Template> tmpl);
+ static std::unique_ptr<TemplateUI> CreateByKind(std::unique_ptr<Template> tmpl);
static std::unique_ptr<TemplateUI> CreateByKind(Template::Kind kind);
virtual ~TemplateUI() = default;
virtual void Display() = 0;
+ virtual void Close() = 0;
};
// Table template styles
@@ -133,7 +134,7 @@ public:
Resize(6, 5);
}
- virtual ~TableTemplateUI() override
+ ~TableTemplateUI() override
{
// We can't move this to be a destructor of the union
// because that way it would run after the destruction of mTable
@@ -163,7 +164,7 @@ public:
}
}
- virtual void Display() override
+ void Display() override
{
ImGui::Columns(2);
if (mFirstDraw) {
@@ -182,6 +183,11 @@ public:
ImGui::Columns(1);
}
+ void Close() override
+ {
+ // TODO
+ }
+
void Resize(int width, int height)
{
mTable->Resize(width, height);
@@ -896,16 +902,18 @@ private:
}
};
-std::unique_ptr<TemplateUI> TemplateUI::CreateByKind(Template::Kind kind, std::unique_ptr<Template> tmpl)
+template <class TTarget>
+static auto CastTemplateAs(std::unique_ptr<Template>& input) requires std::is_base_of_v<Template, TTarget>
{
-#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));
+ return std::unique_ptr<TTarget>(static_cast<TTarget*>(input.release()));
+}
+
+std::unique_ptr<TemplateUI> TemplateUI::CreateByKind(std::unique_ptr<Template> tmpl)
+{
+ switch (tmpl->GetKind()) {
+ case Template::KD_Table: return std::make_unique<TableTemplateUI>(CastTemplateAs<TableTemplate>(tmpl));
case Template::InvalidKind: break;
}
-#pragma pop_macro("UNIQUE_CAST")
return nullptr;
}
@@ -929,6 +937,7 @@ void UI::TemplatesTab()
// Toolbar item: close
if (ImGui::Button(ICON_FA_TIMES " " I18N_TEXT("Close", L10N_CLOSE), openTemplate == nullptr)) {
+ openTemplate->Close();
openTemplate = nullptr;
}
@@ -940,8 +949,9 @@ void UI::TemplatesTab()
if (ImGui::BeginPopupModal(I18N_TEXT("Open asset", L10N_ASSET_OPEN_DIALOG_TITLE), &openedDummy, ImGuiWindowFlags_AlwaysAutoResize)) {
if (ImGui::Button(ICON_FA_FOLDER_OPEN " " I18N_TEXT("Open", L10N_OPEN), state.SelectedAsset == nullptr)) {
ImGui::CloseCurrentPopup();
- auto kind = static_cast<Template::Kind>(state.SelectedAsset->Payload);
- openTemplate = TemplateUI::CreateByKind(kind);
+
+ auto tmpl = project.Templates.Load(*state.SelectedAsset);
+ openTemplate = TemplateUI::CreateByKind(std::move(tmpl));
}
ImGui::SameLine();
project.Templates.DisplayControls(state);
diff --git a/core/src/UI/UI_Workflows.cpp b/core/src/UI/UI_Workflows.cpp
index e61e934..036e532 100644
--- a/core/src/UI/UI_Workflows.cpp
+++ b/core/src/UI/UI_Workflows.cpp
@@ -44,7 +44,7 @@ public:
ImNodes::DestroyEditor(mContext);
}
- void Draw()
+ void Display()
{
ImNodes::SetCurrentEditor(mContext);
ImNodes::Begin("");
@@ -235,6 +235,11 @@ public:
ImNodes::End();
}
+
+ void Close()
+ {
+ // TODO
+ }
};
} // namespace
@@ -248,6 +253,7 @@ void UI::WorkflowsTab()
// Toolbar item: close
if (ImGui::Button(ICON_FA_TIMES " " I18N_TEXT("Close", L10N_CLOSE), openWorkflow == nullptr)) {
+ openWorkflow->Close();
openWorkflow = nullptr;
}
@@ -257,7 +263,9 @@ void UI::WorkflowsTab()
ImGui::OpenPopup(I18N_TEXT("Open asset", L10N_ASSET_OPEN_DIALOG_TITLE));
}
if (ImGui::BeginPopupModal(I18N_TEXT("Open asset", L10N_ASSET_OPEN_DIALOG_TITLE), &openedDummy, ImGuiWindowFlags_AlwaysAutoResize)) {
- if (ImGui::Button(I18N_TEXT("Open", L10N_OPEN), state.SelectedAsset == nullptr)) {
+ if (ImGui::Button(ICON_FA_FOLDER_OPEN " " I18N_TEXT("Open", L10N_OPEN), state.SelectedAsset == nullptr)) {
+ ImGui::CloseCurrentPopup();
+
auto workflow = project.Workflows.Load(*state.SelectedAsset);
openWorkflow = std::make_unique<WorkflowUI>(std::move(workflow));
}
@@ -280,6 +288,6 @@ void UI::WorkflowsTab()
}
if (openWorkflow) {
- openWorkflow->Draw();
+ openWorkflow->Display();
}
}