[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) {
return;
}
if (key == turbine::Key::Escape) {
if (ig::mainWinHasFocus() && key == turbine::Key::Escape) {
m_subsheetEditor.close();
m_exportMenu.close();
m_palPicker.close();

View File

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

View File

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

View File

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

View File

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

View File

@ -12,7 +12,8 @@
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");
setSize({230, 140});
}
@ -32,7 +33,11 @@ bool NewProject::isOpen() const noexcept {
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) {
case Stage::Opening:
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] {
ig::InputText("Name", m_projectName);
ImGui::Text("Path: %s", m_projectPath.c_str());
if (ImGui::Button("Browse")) {
if (ig::PushButton("Browse")) {
oxLogError(studio::chooseDirectory().moveTo(m_projectPath));
}
drawLastPageButtons(sctx);
});
}
void NewProject::drawFirstPageButtons() noexcept {
ImGui::SetCursorPosX(ImGui::GetCursorPosX() + ImGui::GetContentRegionAvail().x - 130);
ImGui::SetCursorPosY(ImGui::GetCursorPosY() + ImGui::GetContentRegionAvail().y - 20);
auto const btnSz = ImVec2(60, 20);
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")) {
void NewProject::drawLastPageButtons(StudioContext&) noexcept {
ImGui::SetCursorPosX(ImGui::GetCursorPosX() + ImGui::GetContentRegionAvail().x - 110);
ImGui::SetCursorPosY(ImGui::GetCursorPosY() + ImGui::GetContentRegionAvail().y - 22);
if (ig::PushButton("Finish")) {
finish();
}
ImGui::SameLine();
if (ImGui::Button("Quit")) {
if (ig::PushButton("Quit")) {
ImGui::CloseCurrentPopup();
m_stage = Stage::Closed;
}

View File

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

View File

@ -35,6 +35,10 @@ bool RenameFile::isOpen() const noexcept {
}
void RenameFile::draw(StudioContext &ctx) noexcept {
if (ImGui::IsKeyPressed(ImGuiKey_Escape)) {
close();
return;
}
switch (m_stage) {
case Stage::Closed:
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 {
for (auto const p : m_popups) {
if (p->isOpen()) {
if (key == turbine::Key::Escape) {
p->close();
}
return;
}
}
if (m_activeEditor && !ImGui::IsKeyDown(ImGuiKey_ModCtrl)) {
m_activeEditor->keyStateChanged(key, down);
}

View File

@ -67,14 +67,6 @@ class StudioUI: public ox::SignalHandler {
&m_newDirDialog,
&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;
struct NavAction {
ox::String path;

View File

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

View File

@ -82,6 +82,25 @@ PopupResponse PopupControlsOkCancel(
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) {
constexpr auto modalFlags = ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize;
centerNextWindow(ctx);