diff options
author | rtk0c <[email protected]> | 2021-08-15 09:17:02 -0700 |
---|---|---|
committer | rtk0c <[email protected]> | 2021-08-15 09:17:02 -0700 |
commit | 64a6dbcfdb89a5f57d93d47a2be0c741dda4662d (patch) | |
tree | 241eaba2351f3a7e6343ce93532e19a4b93757d3 /core | |
parent | f0326e5c5deca0fb719d8522b45c59364b566300 (diff) |
Fix issues and cleanup
- Fix compile error on MSVC where <vector> is not included properly
- Fix creating a workflow actually saves to the templates/ directory
- Fix renaming assets are not saved to disk
- TODO ser/deser still not working
- Cleanup AssetList::* pure virtual setup (fewer splits)
Diffstat (limited to 'core')
-rw-r--r-- | core/src/Model/Assets.cpp | 25 | ||||
-rw-r--r-- | core/src/Model/Assets.hpp | 26 | ||||
-rw-r--r-- | core/src/Model/Template/TableTemplate.hpp | 11 | ||||
-rw-r--r-- | core/src/Model/Template/Template.hpp | 25 | ||||
-rw-r--r-- | core/src/Model/Template/Template_Main.cpp | 90 | ||||
-rw-r--r-- | core/src/Model/Workflow/Value.hpp | 3 | ||||
-rw-r--r-- | core/src/Model/Workflow/Workflow.hpp | 31 | ||||
-rw-r--r-- | core/src/Model/Workflow/Workflow_Main.cpp | 84 | ||||
-rw-r--r-- | core/src/UI/UI_Templates.cpp | 34 | ||||
-rw-r--r-- | core/src/UI/UI_Workflows.cpp | 14 |
10 files changed, 211 insertions, 132 deletions
diff --git a/core/src/Model/Assets.cpp b/core/src/Model/Assets.cpp index 374995d..dc1ebbd 100644 --- a/core/src/Model/Assets.cpp +++ b/core/src/Model/Assets.cpp @@ -3,10 +3,10 @@ #include "UI/UI.hpp" #include "Utils/I18n.hpp" +#include <IconsFontAwesome.h> #include <imgui.h> #include <imgui_stdlib.h> #include <tsl/array_map.h> -#include <IconsFontAwesome.h> #include <fstream> #include <string> #include <utility> @@ -94,6 +94,11 @@ int AssetList::GetCount() const return mPrivate->Assets.size(); } +const tsl::array_map<char, SavedAsset>& AssetList::GetAssets() const +{ + return mPrivate->Assets; +} + const SavedAsset* AssetList::FindByName(std::string_view name) const { auto iter = mPrivate->Assets.find(name); @@ -114,7 +119,7 @@ const SavedAsset& AssetList::Create(SavedAsset asset) savedAsset.Uuid = uuids::uuid_random_generator{}(); } - SaveEmptyInstance(savedAsset); + SaveInstance(savedAsset, nullptr); return savedAsset; } @@ -122,7 +127,7 @@ const SavedAsset& AssetList::Create(SavedAsset asset) std::unique_ptr<Asset> AssetList::CreateAndLoad(SavedAsset assetIn) { auto& savedAsset = Create(std::move(assetIn)); - auto asset = std::unique_ptr<Asset>(CreateEmptyInstance(savedAsset)); + auto asset = std::unique_ptr<Asset>(CreateInstance(savedAsset)); return asset; } @@ -138,7 +143,7 @@ std::unique_ptr<Asset> AssetList::Load(std::string_view name) const std::unique_ptr<Asset> AssetList::Load(const SavedAsset& asset) const { - return std::unique_ptr<Asset>(LoadImpl(asset)); + return std::unique_ptr<Asset>(LoadInstance(asset)); } const SavedAsset* AssetList::Rename(std::string_view oldName, std::string_view newName) @@ -149,8 +154,10 @@ const SavedAsset* AssetList::Rename(std::string_view oldName, std::string_view n auto info = std::move(iter.value()); info.Name = newName; - auto [newIter, DISCARD] = mPrivate->Assets.insert(newName, std::move(info)); + RenameInstanceOnDisk(info, oldName); + mPrivate->Assets.erase(iter); + auto [newIter, DISCARD] = mPrivate->Assets.insert(newName, std::move(info)); return &newIter.value(); } @@ -186,12 +193,8 @@ void AssetList::DisplayIconsList(ListState& state) void AssetList::DisplayDetailsList(ListState& state) { - SetupDetailsTable("AssetDetailsTable"); - for (auto& asset : mPrivate->Assets) { - ImGui::TableNextRow(); - DrawDetailsTableRow(state, asset); - } - ImGui::EndTable(); + // Note: stub function remained here in case any state processing needs to be done before issuing to implementers + DisplayDetailsTable(state); } void AssetList::DisplayControls(ListState& state) diff --git a/core/src/Model/Assets.hpp b/core/src/Model/Assets.hpp index 9fd781f..0a050d6 100644 --- a/core/src/Model/Assets.hpp +++ b/core/src/Model/Assets.hpp @@ -3,6 +3,7 @@ #include "Utils/UUID.hpp" #include "cplt_fwd.hpp" +#include <tsl/array_map.h> #include <filesystem> #include <iosfwd> #include <memory> @@ -50,6 +51,9 @@ public: void Reload(); int GetCount() const; + // TODO convert to custom iterable + const tsl::array_map<char, SavedAsset>& GetAssets() const; + const SavedAsset* FindByName(std::string_view name) const; const SavedAsset& Create(SavedAsset asset); std::unique_ptr<Asset> CreateAndLoad(SavedAsset asset); @@ -79,21 +83,22 @@ protected: void DiscoverFilesByExtension(const std::function<void(SavedAsset)>& callback, const std::filesystem::path& containerDir, std::string_view extension) const; void DiscoverFilesByHeader(const std::function<void(SavedAsset)>& callback, const std::filesystem::path& containerDir, const std::function<bool(std::istream&)>& validater) const; - virtual void SaveEmptyInstance(const SavedAsset& asset) const = 0; - virtual Asset* CreateEmptyInstance(const SavedAsset& asset) const = 0; - - virtual Asset* LoadImpl(const SavedAsset& asset) const = 0; + /// Create an empty/default instance of this asset type on disk, potentially qualified by SavedAsset::Payload. + /// Return `true` on success and `false` on failure. + virtual bool SaveInstance(const SavedAsset& assetInfo, const Asset* asset) const = 0; + /// The returned pointer indicate ownership to the object. + virtual Asset* LoadInstance(const SavedAsset& assetInfo) const = 0; + /// Create an empty/default instance of this asset type, potentially qualified by SavedAsset::Payload. + /// The returned pointer indicate ownership to the object. + virtual Asset* CreateInstance(const SavedAsset& assetInfo) const = 0; + virtual bool RenameInstanceOnDisk(const SavedAsset& assetInfo, std::string_view oldName) const = 0; virtual std::string RetrieveNameFromFile(const std::filesystem::path& file) const = 0; virtual uuids::uuid RetrieveUuidFromFile(const std::filesystem::path& file) const = 0; virtual std::filesystem::path RetrievePathFromAsset(const SavedAsset& asset) const = 0; virtual void DisplayAssetCreator(ListState& state) = 0; - - /// This should call ImGui::BeginTable() along with other accessories such as setting up the header row. - virtual void SetupDetailsTable(const char* tableId) const = 0; - virtual void DrawBigIcon(ListState& state, const SavedAsset& asset) const = 0; - virtual void DrawDetailsTableRow(ListState& state, const SavedAsset& asset) const = 0; + virtual void DisplayDetailsTable(ListState& state) const = 0; }; template <class T> @@ -102,6 +107,8 @@ class AssetListTyped : public AssetList public: using AssetList::AssetList; +#pragma clang diagnostic push +#pragma ide diagnostic ignored "HidingNonVirtualFunction" std::unique_ptr<T> CreateAndLoad(SavedAsset asset) { return std::unique_ptr<T>(static_cast<T*>(AssetList::CreateAndLoad(asset).release())); @@ -116,4 +123,5 @@ public: { return std::unique_ptr<T>(static_cast<T*>(AssetList::Load(asset).release())); } +#pragma clang diagnostic pop }; diff --git a/core/src/Model/Template/TableTemplate.hpp b/core/src/Model/Template/TableTemplate.hpp index 141e952..c651ce1 100644 --- a/core/src/Model/Template/TableTemplate.hpp +++ b/core/src/Model/Template/TableTemplate.hpp @@ -43,7 +43,7 @@ public: TextAlignment HorizontalAlignment = AlignCenter; TextAlignment VerticalAlignment = AlignCenter; CellType Type = ConstantCell; - /// The id of the group description object, if this cell isn't a constant or singluar parameter cell. Otherwise, this value is -1. + /// The id of the group description object, if this cell isn't a constant or singular parameter cell. Otherwise, this value is -1. int DataId = -1; public: @@ -57,11 +57,12 @@ public: // TODO support reverse (bottom to top) filling order // TODO support horizontal filling order -/// Parameter group information for a grouped array of cells. When instanciated, an array of 0 or more + +/// Parameter group information for a grouped array of cells. When instantiated, an array of 0 or more /// elements shall be provided by the user, which will replace the group of templated cells with a list /// of rows, each instantiated with the n-th element in the provided array. /// \code -/// [["foo", "bar", "foobar"], +/// [["foo", "bar", "foobar"], /// ["a", "b", c"], /// ["1", "2", "3"], /// ["x", "y", "z"]] @@ -210,6 +211,6 @@ public: lxw_workbook* InstantiateToExcelWorkbook(const TableInstantiationParameters& params) const; lxw_worksheet* InstantiateToExcelWorksheet(lxw_workbook* workbook, const TableInstantiationParameters& params) const; - virtual ReadResult ReadFrom(std::istream& stream) override; - virtual void WriteTo(std::ostream& stream) const override; + ReadResult ReadFrom(std::istream& stream) override; + void WriteTo(std::ostream& stream) const override; }; diff --git a/core/src/Model/Template/Template.hpp b/core/src/Model/Template/Template.hpp index 7d43130..30fdc75 100644 --- a/core/src/Model/Template/Template.hpp +++ b/core/src/Model/Template/Template.hpp @@ -31,7 +31,7 @@ public: static bool IsInstance(const Template* tmpl); Template(Kind kind); - virtual ~Template() = default; + ~Template() override = default; Kind GetKind() const; @@ -57,20 +57,17 @@ public: using AssetListTyped::AssetListTyped; protected: - virtual void DiscoverFiles(const std::function<void(SavedAsset)>& callback) const override; + void DiscoverFiles(const std::function<void(SavedAsset)>& callback) const override; - virtual std::string RetrieveNameFromFile(const std::filesystem::path& file) const override; - virtual uuids::uuid RetrieveUuidFromFile(const std::filesystem::path& file) const override; - virtual std::filesystem::path RetrievePathFromAsset(const SavedAsset& asset) const override; + std::string RetrieveNameFromFile(const std::filesystem::path& file) const override; + uuids::uuid RetrieveUuidFromFile(const std::filesystem::path& file) const override; + std::filesystem::path RetrievePathFromAsset(const SavedAsset& asset) const override; - virtual void SaveEmptyInstance(const SavedAsset& asset) const override; - virtual Template* CreateEmptyInstance(const SavedAsset& diskForm) const override; + bool SaveInstance(const SavedAsset& assetInfo, const Asset* asset) const override; + Template* LoadInstance(const SavedAsset& assetInfo) const override; + Template* CreateInstance(const SavedAsset& assetInfo) const override; + bool RenameInstanceOnDisk(const SavedAsset& assetInfo, std::string_view oldName) const override; - virtual Template* LoadImpl(const SavedAsset& diskForm) const override; - - virtual void DisplayAssetCreator(ListState& state) override; - - virtual void SetupDetailsTable(const char* tableId) const override; - virtual void DrawBigIcon(ListState& state, const SavedAsset& asset) const override; - virtual void DrawDetailsTableRow(ListState& state, const SavedAsset& asset) const override; + void DisplayAssetCreator(ListState& state) override; + void DisplayDetailsTable(ListState& state) const override; }; diff --git a/core/src/Model/Template/Template_Main.cpp b/core/src/Model/Template/Template_Main.cpp index a681c4a..19803aa 100644 --- a/core/src/Model/Template/Template_Main.cpp +++ b/core/src/Model/Template/Template_Main.cpp @@ -2,8 +2,8 @@ #include "Model/GlobalStates.hpp" #include "Model/Project.hpp" -#include "Utils/I18n.hpp" #include "UI/UI.hpp" +#include "Utils/I18n.hpp" #include "Utils/UUID.hpp" #include <imgui.h> @@ -57,28 +57,33 @@ fs::path TemplateAssetList::RetrievePathFromAsset(const SavedAsset& asset) const return GetConnectedProject().GetTemplatePath(fileName); } -void TemplateAssetList::SaveEmptyInstance(const SavedAsset& asset) const +bool TemplateAssetList::SaveInstance(const SavedAsset& assetInfo, const Asset* asset) const { - auto path = RetrievePathFromAsset(asset); + auto path = RetrievePathFromAsset(assetInfo); - std::ofstream ofs(path); - if (!ofs) return; - ofs << (uint64_t)asset.Name.size(); - ofs << asset.Name; - ofs << static_cast<Template::Kind>(asset.Payload); -} + std::ofstream ofs(path, std::ios::binary); + if (!ofs) return false; + ofs << (uint64_t)assetInfo.Name.size(); + ofs << assetInfo.Name; + ofs << static_cast<Template::Kind>(assetInfo.Payload); -Template* TemplateAssetList::CreateEmptyInstance(const SavedAsset& asset) const -{ - auto kind = static_cast<Template::Kind>(asset.Payload); - return Template::CreateByKind(kind).release(); + if (auto tmpl = static_cast<const Template*>(asset)) { + tmpl->WriteTo(ofs); + } + + return true; } -Template* TemplateAssetList::LoadImpl(const SavedAsset& asset) const +static std::unique_ptr<Template> LoadTemplateFromFile(const fs::path& path) { - std::ifstream ifs(RetrievePathFromAsset(asset)); + std::ifstream ifs(path, std::ios::binary); if (!ifs) return nullptr; + // TODO fix serialization + uint64_t nameSize; + ifs >> nameSize; + ifs.seekg(nameSize, std::ios::end); + uint32_t iKind; ifs >> iKind; @@ -90,7 +95,32 @@ Template* TemplateAssetList::LoadImpl(const SavedAsset& asset) const return nullptr; } - return tmpl.release(); + return tmpl; +} + +Template* TemplateAssetList::LoadInstance(const SavedAsset& assetInfo) const +{ + return ::LoadTemplateFromFile(RetrievePathFromAsset(assetInfo)).release(); +} + +Template* TemplateAssetList::CreateInstance(const SavedAsset& assetInfo) const +{ + auto kind = static_cast<Template::Kind>(assetInfo.Payload); + return Template::CreateByKind(kind).release(); +} + +bool TemplateAssetList::RenameInstanceOnDisk(const SavedAsset& assetInfo, std::string_view oldName) const +{ + // Get asset path, which is only dependent on UUID + auto path = RetrievePathFromAsset(assetInfo); + + auto tmpl = ::LoadTemplateFromFile(path); + if (!tmpl) return false; + + // Rewrite the asset with the updated name (note the given assetInfo already has the update name) + SaveInstance(assetInfo, tmpl.get()); + + return true; } void TemplateAssetList::DisplayAssetCreator(ListState& state) @@ -170,28 +200,26 @@ void TemplateAssetList::DisplayAssetCreator(ListState& state) } } -void TemplateAssetList::SetupDetailsTable(const char* tableId) const +void TemplateAssetList::DisplayDetailsTable(ListState& state) const { - ImGui::BeginTable(tableId, 2, ImGuiTableFlags_Borders); + ImGui::BeginTable("AssetDetailsTable", 2, ImGuiTableFlags_Borders); ImGui::TableSetupColumn(I18N_TEXT("Name", L10N_NAME)); ImGui::TableSetupColumn(I18N_TEXT("Type", L10N_TYPE)); ImGui::TableHeadersRow(); -} -void TemplateAssetList::DrawBigIcon(ListState& state, const SavedAsset& asset) const -{ - // TODO -} + for (auto& asset : this->GetAssets()) { + ImGui::TableNextRow(); -void TemplateAssetList::DrawDetailsTableRow(ListState& state, const SavedAsset& asset) const -{ - ImGui::TableNextColumn(); - if (ImGui::Selectable(asset.Name.c_str(), state.SelectedAsset == &asset, ImGuiSelectableFlags_SpanAllColumns | ImGuiSelectableFlags_DontClosePopups)) { - state.SelectedAsset = &asset; + ImGui::TableNextColumn(); + if (ImGui::Selectable(asset.Name.c_str(), state.SelectedAsset == &asset, ImGuiSelectableFlags_SpanAllColumns | ImGuiSelectableFlags_DontClosePopups)) { + state.SelectedAsset = &asset; + } + + ImGui::TableNextColumn(); + auto kind = static_cast<Template::Kind>(asset.Payload); + ImGui::TextUnformatted(Template::FormatKind(kind)); } - ImGui::TableNextColumn(); - auto kind = static_cast<Template::Kind>(asset.Payload); - ImGui::TextUnformatted(Template::FormatKind(kind)); + ImGui::EndTable(); } diff --git a/core/src/Model/Workflow/Value.hpp b/core/src/Model/Workflow/Value.hpp index ed35349..2198674 100644 --- a/core/src/Model/Workflow/Value.hpp +++ b/core/src/Model/Workflow/Value.hpp @@ -1,11 +1,12 @@ #pragma once -#include "cplt_fwd.hpp" #include "Utils/Color.hpp" +#include "cplt_fwd.hpp" #include <iosfwd> #include <memory> #include <string> +#include <vector> class BaseValue { diff --git a/core/src/Model/Workflow/Workflow.hpp b/core/src/Model/Workflow/Workflow.hpp index cba0d72..c156582 100644 --- a/core/src/Model/Workflow/Workflow.hpp +++ b/core/src/Model/Workflow/Workflow.hpp @@ -7,13 +7,13 @@ #include <imgui_node_editor.h> #include <cstddef> -#include <span> #include <cstdint> #include <filesystem> #include <functional> #include <iosfwd> #include <limits> #include <memory> +#include <span> #include <string> #include <variant> #include <vector> @@ -41,7 +41,7 @@ public: void DrawDebugInfo() const; void ReadFrom(std::istream& stream); - void WriteTo(std::ostream& stream); + void WriteTo(std::ostream& stream) const; }; class WorkflowNode @@ -285,7 +285,7 @@ public: RR_InvalidVersion, }; ReadResult ReadFrom(std::istream& stream); - void WriteTo(std::ostream& stream); + void WriteTo(std::ostream& stream) const; private: std::pair<WorkflowConnection&, uint32_t> AllocWorkflowConnection(); @@ -303,21 +303,18 @@ public: // Inherit constructors using AssetListTyped::AssetListTyped; -public: - virtual void DiscoverFiles(const std::function<void(SavedAsset)>& callback) const override; - - virtual std::string RetrieveNameFromFile(const std::filesystem::path& file) const override; - virtual uuids::uuid RetrieveUuidFromFile(const std::filesystem::path& file) const override; - virtual std::filesystem::path RetrievePathFromAsset(const SavedAsset& asset) const override; - - virtual void SaveEmptyInstance(const SavedAsset& asset) const override; - virtual Workflow* CreateEmptyInstance(const SavedAsset& diskForm) const override; +protected: + void DiscoverFiles(const std::function<void(SavedAsset)>& callback) const override; - virtual Workflow* LoadImpl(const SavedAsset& diskForm) const override; + std::string RetrieveNameFromFile(const std::filesystem::path& file) const override; + uuids::uuid RetrieveUuidFromFile(const std::filesystem::path& file) const override; + std::filesystem::path RetrievePathFromAsset(const SavedAsset& asset) const override; - virtual void DisplayAssetCreator(ListState& state) override; + bool SaveInstance(const SavedAsset& assetInfo, const Asset* asset) const override; + Workflow* LoadInstance(const SavedAsset& assetInfo) const override; + Workflow* CreateInstance(const SavedAsset& assetInfo) const override; + bool RenameInstanceOnDisk(const SavedAsset& assetInfo, std::string_view oldName) const override; - virtual void SetupDetailsTable(const char* tableId) const override; - virtual void DrawBigIcon(ListState& state, const SavedAsset& asset) const override; - virtual void DrawDetailsTableRow(ListState& state, const SavedAsset& asset) const override; + void DisplayAssetCreator(ListState& state) override; + void DisplayDetailsTable(ListState& state) const override; }; diff --git a/core/src/Model/Workflow/Workflow_Main.cpp b/core/src/Model/Workflow/Workflow_Main.cpp index 2dbed58..d502413 100644 --- a/core/src/Model/Workflow/Workflow_Main.cpp +++ b/core/src/Model/Workflow/Workflow_Main.cpp @@ -3,8 +3,8 @@ #include "Model/GlobalStates.hpp" #include "Model/Project.hpp" #include "UI/UI.hpp" -#include "Utils/UUID.hpp" #include "Utils/I18n.hpp" +#include "Utils/UUID.hpp" #include <imgui.h> #include <imgui_node_editor.h> @@ -57,7 +57,7 @@ void WorkflowConnection::ReadFrom(std::istream& stream) stream >> DestinationNode >> DestinationPin; } -void WorkflowConnection::WriteTo(std::ostream& stream) +void WorkflowConnection::WriteTo(std::ostream& stream) const { stream << SourceNode << SourcePin; stream << DestinationNode << DestinationPin; @@ -393,7 +393,7 @@ Workflow::GlobalPinId Workflow::DisassembleGlobalPinId(ImNodes::PinId pinId) // Therefore we encode one ourselves // Global pin id format - // nnnnnnnn nnnnnnnn nnnnnnnn nnnnnnnn Tppppppp pppppppp pppppppp pppppppp + // nnnnnnnn nnnnnnnn nnnnnnnn nnnnnnnn Tppppppp ppppppppp pppppppp pppppppp // <------- (32 bits) node id -------> ^<------ (31 bits) pin id --------> // | (1 bit) input (false) vs output (true) @@ -676,7 +676,7 @@ Workflow::ReadResult Workflow::ReadFrom(std::istream& stream) return RR_Success; } -void Workflow::WriteTo(std::ostream& stream) +void Workflow::WriteTo(std::ostream& stream) const { // Version stream << (uint64_t)0; @@ -775,35 +775,63 @@ uuids::uuid WorkflowAssetList::RetrieveUuidFromFile(const fs::path& file) const fs::path WorkflowAssetList::RetrievePathFromAsset(const SavedAsset& asset) const { auto fileName = uuids::to_string(asset.Uuid); - return GetConnectedProject().GetTemplatePath(fileName); + return GetConnectedProject().GetWorkflowPath(fileName); } -void WorkflowAssetList::SaveEmptyInstance(const SavedAsset& asset) const +bool WorkflowAssetList::SaveInstance(const SavedAsset& assetInfo, const Asset* asset) const { - auto path = RetrievePathFromAsset(asset); + auto path = RetrievePathFromAsset(assetInfo); std::ofstream ofs(path); - if (!ofs) return; - ofs << (uint64_t)asset.Name.size(); - ofs << asset.Name; -} + if (!ofs) return false; + ofs << (uint64_t)assetInfo.Name.size(); + ofs << assetInfo.Name; -Workflow* WorkflowAssetList::CreateEmptyInstance(const SavedAsset& asset) const -{ - return new Workflow(); + if (auto workflow = static_cast<const Workflow*>(asset)) { + workflow->WriteTo(ofs); + } + + return true; } -Workflow* WorkflowAssetList::LoadImpl(const SavedAsset& asset) const +static std::unique_ptr<Workflow> LoadWorkflowFromFile(const fs::path& path) { - std::ifstream ifs(RetrievePathFromAsset(asset)); + std::ifstream ifs(path); if (!ifs) return nullptr; + // TODO fix serialization + uint64_t nameSize; + ifs >> nameSize; + ifs.seekg(nameSize, std::ios::end); + auto workflow = std::make_unique<Workflow>(); if (workflow->ReadFrom(ifs) != Workflow::RR_Success) { return nullptr; } - return workflow.release(); + return workflow; +} + +Workflow* WorkflowAssetList::LoadInstance(const SavedAsset& assetInfo) const +{ + return ::LoadWorkflowFromFile(RetrievePathFromAsset(assetInfo)).release(); +} + +Workflow* WorkflowAssetList::CreateInstance(const SavedAsset& assetInfo) const +{ + return new Workflow(); +} + +bool WorkflowAssetList::RenameInstanceOnDisk(const SavedAsset& assetInfo, std::string_view oldName) const +{ + auto path = RetrievePathFromAsset(assetInfo); + + auto workflow = ::LoadWorkflowFromFile(path); + if (!workflow) return false; + + SaveInstance(assetInfo, workflow.get()); + + return true; } void WorkflowAssetList::DisplayAssetCreator(ListState& state) @@ -863,23 +891,21 @@ void WorkflowAssetList::DisplayAssetCreator(ListState& state) } } -void WorkflowAssetList::SetupDetailsTable(const char* tableId) const +void WorkflowAssetList::DisplayDetailsTable(ListState& state) const { - ImGui::BeginTable(tableId, 1, ImGuiTableFlags_Borders); + ImGui::BeginTable("AssetDetailsTable", 1, ImGuiTableFlags_Borders); ImGui::TableSetupColumn(I18N_TEXT("Name", L10N_NAME)); ImGui::TableHeadersRow(); -} -void WorkflowAssetList::DrawBigIcon(ListState& state, const SavedAsset& asset) const -{ - // TODO -} + for (auto& asset : this->GetAssets()) { + ImGui::TableNextRow(); -void WorkflowAssetList::DrawDetailsTableRow(ListState& state, const SavedAsset& asset) const -{ - ImGui::TableNextColumn(); - if (ImGui::Selectable(asset.Name.c_str(), state.SelectedAsset == &asset, ImGuiSelectableFlags_SpanAllColumns | ImGuiSelectableFlags_DontClosePopups)) { - state.SelectedAsset = &asset; + ImGui::TableNextColumn(); + if (ImGui::Selectable(asset.Name.c_str(), state.SelectedAsset == &asset, ImGuiSelectableFlags_SpanAllColumns | ImGuiSelectableFlags_DontClosePopups)) { + state.SelectedAsset = &asset; + } } + + ImGui::EndTable(); } 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(); } } |