From 9511cb57196b657912e3e7b55eeee95c9d673fbc Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Wed, 22 Jan 2025 23:37:44 -0600 Subject: [PATCH] [studio] Fix prev tracking --- src/olympic/studio/applib/src/newmenu.cpp | 18 +++++++++++++----- src/olympic/studio/applib/src/newmenu.hpp | 3 ++- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/olympic/studio/applib/src/newmenu.cpp b/src/olympic/studio/applib/src/newmenu.cpp index 91296383..a348a2c7 100644 --- a/src/olympic/studio/applib/src/newmenu.cpp +++ b/src/olympic/studio/applib/src/newmenu.cpp @@ -91,7 +91,7 @@ void NewMenu::drawNewItemType(StudioContext const&sctx) noexcept { auto const&im = *m_types[m_selectedType]; drawFirstPageButtons(im.itemTemplates().size() == 1 ? Stage::NewItemPath : Stage::NewItemTemplate); - if (m_stage == Stage::NewItemPath) { + if (m_stage == Stage::NewItemPath || m_stage == Stage::NewItemTemplate) { if (m_path.len() == 0) { m_path = im.defaultPath(); } @@ -108,7 +108,7 @@ void NewMenu::drawNewItemTemplate(StudioContext const&sctx) noexcept { ig::ListBox("Template", [&](size_t const i) -> ox::CStringView { return templates[i]->name(); }, templates.size(), m_selectedTemplate, {200, 100}); - drawButtons(Stage::NewItemType, Stage::NewItemPath); + drawButtons(Stage::NewItemPath); }); } @@ -126,15 +126,19 @@ void NewMenu::drawNewItemPath(StudioContext &sctx) noexcept { }); } -void NewMenu::drawButtons(Stage const prev, Stage const next) noexcept { +void NewMenu::drawButtons(Stage const next) noexcept { ImGui::SetCursorPosX(ImGui::GetCursorPosX() + ImGui::GetContentRegionAvail().x - 198); ImGui::SetCursorPosY(ImGui::GetCursorPosY() + ImGui::GetContentRegionAvail().y - 20); constexpr ImVec2 btnSz{60, 20}; if (ImGui::Button("Back", btnSz)) { - m_stage = prev; + if (auto const p = m_prev.back(); p.ok()) { + m_stage = *p.value; + } + m_prev.pop_back(); } ImGui::SameLine(); if (ImGui::Button("Next", btnSz)) { + m_prev.emplace_back(m_stage); m_stage = next; } ImGui::SameLine(); @@ -149,6 +153,7 @@ void NewMenu::drawFirstPageButtons(Stage const next) noexcept { ImGui::SetCursorPosY(ImGui::GetCursorPosY() + ImGui::GetContentRegionAvail().y - 20); constexpr ImVec2 btnSz{60, 20}; if (ImGui::Button("Next", btnSz)) { + m_prev.emplace_back(m_stage); m_stage = next; } ImGui::SameLine(); @@ -163,7 +168,10 @@ void NewMenu::drawLastPageButtons(StudioContext &sctx) noexcept { ImGui::SetCursorPosY(ImGui::GetCursorPosY() + ImGui::GetContentRegionAvail().y - 20); constexpr ImVec2 btnSz{60, 20}; if (ImGui::Button("Back", btnSz)) { - m_stage = Stage::NewItemType; + if (auto const p = m_prev.back(); p.ok()) { + m_stage = *p.value; + } + m_prev.pop_back(); } ImGui::SameLine(); if (ImGui::Button("Finish", btnSz)) { diff --git a/src/olympic/studio/applib/src/newmenu.hpp b/src/olympic/studio/applib/src/newmenu.hpp index 3059c405..f2db5f00 100644 --- a/src/olympic/studio/applib/src/newmenu.hpp +++ b/src/olympic/studio/applib/src/newmenu.hpp @@ -29,6 +29,7 @@ class NewMenu final: public Popup { private: Stage m_stage = Stage::Closed; + ox::Vector m_prev; keel::Context &m_kctx; ox::String m_typeName; ox::IString<255> m_itemName; @@ -79,7 +80,7 @@ class NewMenu final: public Popup { void drawNewItemTemplate(StudioContext const &sctx) noexcept; - void drawButtons(Stage prev, Stage next) noexcept; + void drawButtons(Stage next) noexcept; void drawFirstPageButtons(Stage next) noexcept;