[studio] Fix prev tracking
All checks were successful
Build / build (push) Successful in 3m16s

This commit is contained in:
Gary Talent 2025-01-22 23:37:44 -06:00
parent 1cc1d561e2
commit 9511cb5719
2 changed files with 15 additions and 6 deletions

View File

@ -91,7 +91,7 @@ void NewMenu::drawNewItemType(StudioContext const&sctx) noexcept {
auto const&im = *m_types[m_selectedType]; auto const&im = *m_types[m_selectedType];
drawFirstPageButtons(im.itemTemplates().size() == 1 ? drawFirstPageButtons(im.itemTemplates().size() == 1 ?
Stage::NewItemPath : Stage::NewItemTemplate); Stage::NewItemPath : Stage::NewItemTemplate);
if (m_stage == Stage::NewItemPath) { if (m_stage == Stage::NewItemPath || m_stage == Stage::NewItemTemplate) {
if (m_path.len() == 0) { if (m_path.len() == 0) {
m_path = im.defaultPath(); m_path = im.defaultPath();
} }
@ -108,7 +108,7 @@ void NewMenu::drawNewItemTemplate(StudioContext const&sctx) noexcept {
ig::ListBox("Template", [&](size_t const i) -> ox::CStringView { ig::ListBox("Template", [&](size_t const i) -> ox::CStringView {
return templates[i]->name(); return templates[i]->name();
}, templates.size(), m_selectedTemplate, {200, 100}); }, 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::SetCursorPosX(ImGui::GetCursorPosX() + ImGui::GetContentRegionAvail().x - 198);
ImGui::SetCursorPosY(ImGui::GetCursorPosY() + ImGui::GetContentRegionAvail().y - 20); ImGui::SetCursorPosY(ImGui::GetCursorPosY() + ImGui::GetContentRegionAvail().y - 20);
constexpr ImVec2 btnSz{60, 20}; constexpr ImVec2 btnSz{60, 20};
if (ImGui::Button("Back", btnSz)) { 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(); ImGui::SameLine();
if (ImGui::Button("Next", btnSz)) { if (ImGui::Button("Next", btnSz)) {
m_prev.emplace_back(m_stage);
m_stage = next; m_stage = next;
} }
ImGui::SameLine(); ImGui::SameLine();
@ -149,6 +153,7 @@ void NewMenu::drawFirstPageButtons(Stage const next) noexcept {
ImGui::SetCursorPosY(ImGui::GetCursorPosY() + ImGui::GetContentRegionAvail().y - 20); ImGui::SetCursorPosY(ImGui::GetCursorPosY() + ImGui::GetContentRegionAvail().y - 20);
constexpr ImVec2 btnSz{60, 20}; constexpr ImVec2 btnSz{60, 20};
if (ImGui::Button("Next", btnSz)) { if (ImGui::Button("Next", btnSz)) {
m_prev.emplace_back(m_stage);
m_stage = next; m_stage = next;
} }
ImGui::SameLine(); ImGui::SameLine();
@ -163,7 +168,10 @@ void NewMenu::drawLastPageButtons(StudioContext &sctx) noexcept {
ImGui::SetCursorPosY(ImGui::GetCursorPosY() + ImGui::GetContentRegionAvail().y - 20); ImGui::SetCursorPosY(ImGui::GetCursorPosY() + ImGui::GetContentRegionAvail().y - 20);
constexpr ImVec2 btnSz{60, 20}; constexpr ImVec2 btnSz{60, 20};
if (ImGui::Button("Back", btnSz)) { 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(); ImGui::SameLine();
if (ImGui::Button("Finish", btnSz)) { if (ImGui::Button("Finish", btnSz)) {

View File

@ -29,6 +29,7 @@ class NewMenu final: public Popup {
private: private:
Stage m_stage = Stage::Closed; Stage m_stage = Stage::Closed;
ox::Vector<Stage, 2> m_prev;
keel::Context &m_kctx; keel::Context &m_kctx;
ox::String m_typeName; ox::String m_typeName;
ox::IString<255> m_itemName; ox::IString<255> m_itemName;
@ -79,7 +80,7 @@ class NewMenu final: public Popup {
void drawNewItemTemplate(StudioContext const &sctx) noexcept; void drawNewItemTemplate(StudioContext const &sctx) noexcept;
void drawButtons(Stage prev, Stage next) noexcept; void drawButtons(Stage next) noexcept;
void drawFirstPageButtons(Stage next) noexcept; void drawFirstPageButtons(Stage next) noexcept;