[studio,nostalgia/gfx/studio] Cleanup
All checks were successful
Build / build (push) Successful in 1m14s

This commit is contained in:
Gary Talent 2025-05-06 01:00:04 -05:00
parent 8c6b2234ec
commit 0003454311
12 changed files with 55 additions and 43 deletions

View File

@ -129,7 +129,7 @@ void TileSheetEditorImGui::keyStateChanged(turbine::Key const key, bool const do
if (!down) { if (!down) {
return; return;
} }
if (key == turbine::Key::Escape) { if (ig::mainWinHasFocus() && key == turbine::Key::Escape) {
m_subsheetEditor.close(); m_subsheetEditor.close();
m_exportMenu.close(); m_exportMenu.close();
m_palPicker.close(); m_palPicker.close();

View File

@ -30,6 +30,10 @@ bool AboutPopup::isOpen() const noexcept {
} }
void AboutPopup::draw(StudioContext &sctx) noexcept { void AboutPopup::draw(StudioContext &sctx) noexcept {
if (ImGui::IsKeyPressed(ImGuiKey_Escape)) {
close();
return;
}
switch (m_stage) { switch (m_stage) {
case Stage::Closed: case Stage::Closed:
break; break;

View File

@ -32,6 +32,10 @@ bool DeleteConfirmation::isOpen() const noexcept {
} }
void DeleteConfirmation::draw(StudioContext &ctx) noexcept { void DeleteConfirmation::draw(StudioContext &ctx) noexcept {
if (ImGui::IsKeyPressed(ImGuiKey_Escape)) {
close();
return;
}
switch (m_stage) { switch (m_stage) {
case Stage::Closed: case Stage::Closed:
break; break;

View File

@ -33,6 +33,10 @@ bool NewDir::isOpen() const noexcept {
} }
void NewDir::draw(StudioContext &ctx) noexcept { void NewDir::draw(StudioContext &ctx) noexcept {
if (ImGui::IsKeyPressed(ImGuiKey_Escape)) {
close();
return;
}
switch (m_stage) { switch (m_stage) {
case Stage::Closed: case Stage::Closed:
break; break;

View File

@ -45,6 +45,10 @@ bool NewMenu::isOpen() const noexcept {
} }
void NewMenu::draw(StudioContext &sctx) noexcept { void NewMenu::draw(StudioContext &sctx) noexcept {
if (ImGui::IsKeyPressed(ImGuiKey_Escape)) {
close();
return;
}
switch (m_stage) { switch (m_stage) {
case Stage::Opening: case Stage::Opening:
ImGui::OpenPopup(title().c_str()); ImGui::OpenPopup(title().c_str());

View File

@ -12,7 +12,8 @@
namespace studio { namespace studio {
NewProject::NewProject(ox::StringParam projectDatadir) noexcept: m_projectDataDir(std::move(projectDatadir)) { NewProject::NewProject(ox::StringParam projectDatadir) noexcept:
m_projectDataDir{std::move(projectDatadir)} {
setTitle("New Project"); setTitle("New Project");
setSize({230, 140}); setSize({230, 140});
} }
@ -32,7 +33,11 @@ bool NewProject::isOpen() const noexcept {
return m_open; return m_open;
} }
void NewProject::draw(studio::StudioContext &ctx) noexcept { void NewProject::draw(StudioContext &ctx) noexcept {
if (ImGui::IsKeyPressed(ImGuiKey_Escape)) {
close();
return;
}
switch (m_stage) { switch (m_stage) {
case Stage::Opening: case Stage::Opening:
ImGui::OpenPopup(title().c_str()); ImGui::OpenPopup(title().c_str());
@ -48,39 +53,25 @@ void NewProject::draw(studio::StudioContext &ctx) noexcept {
} }
} }
void NewProject::drawNewProjectName(studio::StudioContext &sctx) noexcept { void NewProject::drawNewProjectName(StudioContext &sctx) noexcept {
drawWindow(sctx.tctx, m_open, [this, &sctx] { drawWindow(sctx.tctx, m_open, [this, &sctx] {
ig::InputText("Name", m_projectName); ig::InputText("Name", m_projectName);
ImGui::Text("Path: %s", m_projectPath.c_str()); ImGui::Text("Path: %s", m_projectPath.c_str());
if (ImGui::Button("Browse")) { if (ig::PushButton("Browse")) {
oxLogError(studio::chooseDirectory().moveTo(m_projectPath)); oxLogError(studio::chooseDirectory().moveTo(m_projectPath));
} }
drawLastPageButtons(sctx); drawLastPageButtons(sctx);
}); });
} }
void NewProject::drawFirstPageButtons() noexcept { void NewProject::drawLastPageButtons(StudioContext&) noexcept {
ImGui::SetCursorPosX(ImGui::GetCursorPosX() + ImGui::GetContentRegionAvail().x - 130); ImGui::SetCursorPosX(ImGui::GetCursorPosX() + ImGui::GetContentRegionAvail().x - 110);
ImGui::SetCursorPosY(ImGui::GetCursorPosY() + ImGui::GetContentRegionAvail().y - 20); ImGui::SetCursorPosY(ImGui::GetCursorPosY() + ImGui::GetContentRegionAvail().y - 22);
auto const btnSz = ImVec2(60, 20); if (ig::PushButton("Finish")) {
if (ImGui::Button("Next", btnSz)) {
m_stage = Stage::NewItemName;
}
ImGui::SameLine();
if (ImGui::Button("Cancel", btnSz)) {
ImGui::CloseCurrentPopup();
m_stage = Stage::Closed;
}
}
void NewProject::drawLastPageButtons(studio::StudioContext&) noexcept {
ImGui::SetCursorPosX(ImGui::GetCursorPosX() + ImGui::GetContentRegionAvail().x - 95);
ImGui::SetCursorPosY(ImGui::GetCursorPosY() + ImGui::GetContentRegionAvail().y - 20);
if (ImGui::Button("Finish")) {
finish(); finish();
} }
ImGui::SameLine(); ImGui::SameLine();
if (ImGui::Button("Quit")) { if (ig::PushButton("Quit")) {
ImGui::CloseCurrentPopup(); ImGui::CloseCurrentPopup();
m_stage = Stage::Closed; m_stage = Stage::Closed;
} }

View File

@ -47,8 +47,6 @@ class NewProject: public studio::Popup {
private: private:
void drawNewProjectName(studio::StudioContext &ctx) noexcept; void drawNewProjectName(studio::StudioContext &ctx) noexcept;
void drawFirstPageButtons() noexcept;
void drawLastPageButtons(studio::StudioContext &ctx) noexcept; void drawLastPageButtons(studio::StudioContext &ctx) noexcept;
void finish() noexcept; void finish() noexcept;

View File

@ -35,6 +35,10 @@ bool RenameFile::isOpen() const noexcept {
} }
void RenameFile::draw(StudioContext &ctx) noexcept { void RenameFile::draw(StudioContext &ctx) noexcept {
if (ImGui::IsKeyPressed(ImGuiKey_Escape)) {
close();
return;
}
switch (m_stage) { switch (m_stage) {
case Stage::Closed: case Stage::Closed:
break; break;

View File

@ -119,14 +119,6 @@ StudioUI::StudioUI(turbine::Context &ctx, ox::StringParam projectDataDir) noexce
} }
void StudioUI::handleKeyEvent(turbine::Key const key, bool const down) noexcept { void StudioUI::handleKeyEvent(turbine::Key const key, bool const down) noexcept {
for (auto const p : m_popups) {
if (p->isOpen()) {
if (key == turbine::Key::Escape) {
p->close();
}
return;
}
}
if (m_activeEditor && !ImGui::IsKeyDown(ImGuiKey_ModCtrl)) { if (m_activeEditor && !ImGui::IsKeyDown(ImGuiKey_ModCtrl)) {
m_activeEditor->keyStateChanged(key, down); m_activeEditor->keyStateChanged(key, down);
} }

View File

@ -67,14 +67,6 @@ class StudioUI: public ox::SignalHandler {
&m_newDirDialog, &m_newDirDialog,
&m_renameFile, &m_renameFile,
}; };
ox::Array<Popup*, 6> const m_popups = {
&m_newMenu,
&m_newProject,
&m_aboutPopup,
&m_deleteConfirmation,
&m_newDirDialog,
&m_renameFile,
};
bool m_showProjectExplorer = true; bool m_showProjectExplorer = true;
struct NavAction { struct NavAction {
ox::String path; ox::String path;

View File

@ -25,7 +25,7 @@ class Popup: public Widget {
// emits path parameter // emits path parameter
ox::Signal<ox::Error(ox::String const&)> finished; ox::Signal<ox::Error(ox::String const&)> finished;
virtual ~Popup() noexcept = default; ~Popup() noexcept override = default;
virtual void open() noexcept = 0; virtual void open() noexcept = 0;

View File

@ -82,6 +82,25 @@ PopupResponse PopupControlsOkCancel(
return PopupControlsOkCancel(ImGui::GetContentRegionAvail().x + 17, popupOpen, ok, cancel); return PopupControlsOkCancel(ImGui::GetContentRegionAvail().x + 17, popupOpen, ok, cancel);
} }
PopupResponse PopupControlsOk(
bool &popupOpen,
ox::CStringViewCR ok) {
auto out = PopupResponse::None;
constexpr auto btnSz = ImVec2{50, BtnSz.y};
ImGui::Separator();
ImGui::SetCursorPosX(ImGui::GetContentRegionAvail().x - 101);
if (ImGui::Button(ok.c_str(), btnSz)) {
popupOpen = false;
out = PopupResponse::OK;
}
ImGui::SameLine();
if (ImGui::IsKeyDown(ImGuiKey_Escape)) {
popupOpen = false;
out = PopupResponse::Cancel;
}
return out;
}
bool BeginPopup(turbine::Context &ctx, ox::CStringViewCR popupName, bool &show, ImVec2 const&sz) { bool BeginPopup(turbine::Context &ctx, ox::CStringViewCR popupName, bool &show, ImVec2 const&sz) {
constexpr auto modalFlags = ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize; constexpr auto modalFlags = ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize;
centerNextWindow(ctx); centerNextWindow(ctx);