[nostalgia/core/studio] Add Palette page names to editor
This commit is contained in:
@@ -4,8 +4,6 @@
|
||||
|
||||
#include <imgui.h>
|
||||
|
||||
#include <ox/std/memory.hpp>
|
||||
|
||||
#include <keel/media.hpp>
|
||||
|
||||
#include <nostalgia/core/gfx.hpp>
|
||||
@@ -17,6 +15,27 @@ namespace nostalgia::core {
|
||||
|
||||
namespace ig = studio::ig;
|
||||
|
||||
|
||||
void PaletteEditorImGui::PageRename::draw(turbine::Context &tctx) noexcept {
|
||||
if (!m_show) {
|
||||
return;
|
||||
}
|
||||
if (ig::BeginPopup(tctx, "Rename Page", m_show)) {
|
||||
ig::InputText("Name", m_name);
|
||||
switch (ig::PopupControlsOkCancel(m_show)) {
|
||||
case ig::PopupResponse::OK:
|
||||
inputSubmitted.emit(m_name);
|
||||
[[fallthrough]];
|
||||
case ig::PopupResponse::Cancel:
|
||||
close();
|
||||
default:
|
||||
break;
|
||||
}
|
||||
ImGui::EndPopup();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
PaletteEditorImGui::PaletteEditorImGui(studio::StudioContext &sctx, ox::StringParam path):
|
||||
Editor(std::move(path)),
|
||||
m_sctx(sctx),
|
||||
@@ -26,6 +45,7 @@ PaletteEditorImGui::PaletteEditorImGui(studio::StudioContext &sctx, ox::StringPa
|
||||
throw OxException(1, "PaletteEditorImGui: invalid Palette object");
|
||||
}
|
||||
undoStack()->changeTriggered.connect(this, &PaletteEditorImGui::handleCommand);
|
||||
m_pageRename.inputSubmitted.connect(this, &PaletteEditorImGui::renamePage);
|
||||
}
|
||||
|
||||
void PaletteEditorImGui::keyStateChanged(turbine::Key key, bool down) {
|
||||
@@ -49,7 +69,7 @@ void PaletteEditorImGui::keyStateChanged(turbine::Key key, bool down) {
|
||||
void PaletteEditorImGui::draw(studio::StudioContext&) noexcept {
|
||||
auto const paneSize = ImGui::GetContentRegionAvail();
|
||||
{
|
||||
ImGui::BeginChild("Pages", {250, paneSize.y}, true);
|
||||
ImGui::BeginChild("Pages", {280, paneSize.y}, true);
|
||||
drawPagesEditor();
|
||||
ImGui::EndChild();
|
||||
}
|
||||
@@ -59,6 +79,7 @@ void PaletteEditorImGui::draw(studio::StudioContext&) noexcept {
|
||||
drawColorsEditor();
|
||||
ImGui::EndChild();
|
||||
}
|
||||
m_pageRename.draw(m_tctx);
|
||||
}
|
||||
|
||||
ox::Error PaletteEditorImGui::saveItem() noexcept {
|
||||
@@ -166,7 +187,7 @@ void PaletteEditorImGui::drawPagesEditor() noexcept {
|
||||
constexpr auto tableFlags = ImGuiTableFlags_RowBg;
|
||||
auto const paneSz = ImGui::GetContentRegionAvail();
|
||||
constexpr auto toolbarHeight = 40;
|
||||
auto const btnSz = ImVec2{paneSz.x / 3 - 5.5f, 24};
|
||||
auto const btnSz = ImVec2{paneSz.x / 4 - 5.5f, 24};
|
||||
if (ImGui::Button("Add", btnSz)) {
|
||||
std::ignore = pushCommand<DuplicatePageCommand>(m_pal, 0u, m_pal.pages.size());
|
||||
m_page = m_pal.pages.size() - 1;
|
||||
@@ -177,9 +198,13 @@ void PaletteEditorImGui::drawPagesEditor() noexcept {
|
||||
m_page = std::min(m_page, m_pal.pages.size() - 1);
|
||||
}
|
||||
ImGui::SameLine();
|
||||
if (ImGui::Button("Duplicate", btnSz)) {
|
||||
if (ImGui::Button("Clone", btnSz)) {
|
||||
std::ignore = pushCommand<DuplicatePageCommand>(m_pal, m_page, m_pal.pages.size());
|
||||
}
|
||||
ImGui::SameLine();
|
||||
if (ImGui::Button("Rename", btnSz)) {
|
||||
m_pageRename.show(m_pal.pages[m_page].name);
|
||||
}
|
||||
ImGui::BeginTable(
|
||||
"PageSelect",
|
||||
2,
|
||||
@@ -187,11 +212,13 @@ void PaletteEditorImGui::drawPagesEditor() noexcept {
|
||||
{paneSz.x, paneSz.y - (toolbarHeight + 5)});
|
||||
{
|
||||
ImGui::TableSetupColumn("Page", ImGuiTableColumnFlags_WidthFixed, 60);
|
||||
ImGui::TableSetupColumn("Name", ImGuiTableColumnFlags_WidthFixed, 200);
|
||||
ImGui::TableHeadersRow();
|
||||
for (auto i = 0u; i < m_pal.pages.size(); ++i) {
|
||||
ig::IDStackItem const idStackItem(static_cast<int>(i));
|
||||
ImGui::TableNextRow();
|
||||
drawColumn(i + 1);
|
||||
drawColumnLeftAlign(m_pal.pages[i].name);
|
||||
ImGui::SameLine();
|
||||
if (ImGui::Selectable("##PageRow", i == m_page, ImGuiSelectableFlags_SpanAllColumns)) {
|
||||
m_page = i;
|
||||
@@ -232,6 +259,10 @@ void PaletteEditorImGui::drawColorEditor() noexcept {
|
||||
}
|
||||
}
|
||||
|
||||
ox::Error PaletteEditorImGui::renamePage(ox::StringView name) noexcept {
|
||||
return pushCommand<RenamePageCommand>(m_pal, m_page, name);
|
||||
}
|
||||
|
||||
ox::Error PaletteEditorImGui::handleCommand(studio::UndoCommand const*cmd) noexcept {
|
||||
if (dynamic_cast<RemovePageCommand const*>(cmd)) {
|
||||
m_page = ox::min(m_page, m_pal.pages.size() - 1);
|
||||
|
||||
@@ -14,6 +14,23 @@ namespace nostalgia::core {
|
||||
class PaletteEditorImGui: public studio::Editor {
|
||||
|
||||
private:
|
||||
class PageRename {
|
||||
private:
|
||||
ox::IString<50> m_name;
|
||||
bool m_show = false;
|
||||
public:
|
||||
ox::Signal<ox::Error(ox::StringView name)> inputSubmitted;
|
||||
constexpr void show(ox::StringView const&name) noexcept {
|
||||
m_show = true;
|
||||
m_name = name;
|
||||
}
|
||||
constexpr void close() noexcept {
|
||||
m_show = false;
|
||||
}
|
||||
[[nodiscard]]
|
||||
constexpr bool isOpen() const noexcept { return m_show; }
|
||||
void draw(turbine::Context &tctx) noexcept;
|
||||
} m_pageRename;
|
||||
studio::StudioContext &m_sctx;
|
||||
turbine::Context &m_tctx;
|
||||
Palette m_pal;
|
||||
@@ -45,6 +62,8 @@ class PaletteEditorImGui: public studio::Editor {
|
||||
|
||||
void drawColorEditor() noexcept;
|
||||
|
||||
ox::Error renamePage(ox::StringView name) noexcept;
|
||||
|
||||
ox::Error handleCommand(studio::UndoCommand const*) noexcept;
|
||||
};
|
||||
|
||||
|
||||
@@ -47,6 +47,26 @@ ox::Error ApplyColorAllPagesCommand::undo() noexcept {
|
||||
}
|
||||
|
||||
|
||||
RenamePageCommand::RenamePageCommand(Palette &pal, size_t const page, ox::StringParam name) noexcept:
|
||||
m_pal(pal),
|
||||
m_page(page),
|
||||
m_name{std::move(name)} {}
|
||||
|
||||
int RenamePageCommand::commandId() const noexcept {
|
||||
return static_cast<int>(PaletteEditorCommandId::RenamePage);
|
||||
}
|
||||
|
||||
ox::Error RenamePageCommand::redo() noexcept {
|
||||
std::swap(m_pal.pages[m_page].name, m_name);
|
||||
return {};
|
||||
}
|
||||
|
||||
ox::Error RenamePageCommand::undo() noexcept {
|
||||
std::swap(m_pal.pages[m_page].name, m_name);
|
||||
return {};
|
||||
}
|
||||
|
||||
|
||||
DuplicatePageCommand::DuplicatePageCommand(Palette &pal, size_t srcIdx, size_t dstIdx) noexcept:
|
||||
m_pal(pal),
|
||||
m_dstIdx(dstIdx) {
|
||||
|
||||
@@ -13,6 +13,7 @@ namespace nostalgia::core {
|
||||
|
||||
enum class PaletteEditorCommandId {
|
||||
ApplyColorAllPages,
|
||||
RenamePage,
|
||||
DuplicatePage,
|
||||
RemovePage,
|
||||
AddColor,
|
||||
@@ -43,6 +44,26 @@ class ApplyColorAllPagesCommand: public studio::UndoCommand {
|
||||
ox::Error undo() noexcept final;
|
||||
};
|
||||
|
||||
class RenamePageCommand: public studio::UndoCommand {
|
||||
private:
|
||||
Palette &m_pal;
|
||||
size_t m_page = 0;
|
||||
ox::String m_name;
|
||||
|
||||
public:
|
||||
RenamePageCommand(Palette &pal, size_t page, ox::StringParam name) noexcept;
|
||||
|
||||
~RenamePageCommand() noexcept override = default;
|
||||
|
||||
[[nodiscard]]
|
||||
int commandId() const noexcept final;
|
||||
|
||||
ox::Error redo() noexcept final;
|
||||
|
||||
ox::Error undo() noexcept final;
|
||||
|
||||
};
|
||||
|
||||
class DuplicatePageCommand: public studio::UndoCommand {
|
||||
private:
|
||||
Palette &m_pal;
|
||||
|
||||
Reference in New Issue
Block a user