[nostalgia/core/studio/paletteeditor] Fix adding page if there is no existing page
All checks were successful
Build / build (push) Successful in 3m19s
All checks were successful
Build / build (push) Successful in 3m19s
This commit is contained in:
parent
95950441d1
commit
ba1bf950a8
@ -1,6 +1,7 @@
|
|||||||
target_sources(
|
target_sources(
|
||||||
NostalgiaCore-Studio PRIVATE
|
NostalgiaCore-Studio PRIVATE
|
||||||
commands/addcolorcommand.cpp
|
commands/addcolorcommand.cpp
|
||||||
|
commands/addpagecommand.cpp
|
||||||
commands/applycolorallpagescommand.cpp
|
commands/applycolorallpagescommand.cpp
|
||||||
commands/duplicatepagecommand.cpp
|
commands/duplicatepagecommand.cpp
|
||||||
commands/movecolorcommand.cpp
|
commands/movecolorcommand.cpp
|
||||||
|
@ -0,0 +1,28 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2016 - 2025 Gary Talent (gary@drinkingtea.net). All rights reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "commands.hpp"
|
||||||
|
|
||||||
|
#include "addpagecommand.hpp"
|
||||||
|
|
||||||
|
namespace nostalgia::core {
|
||||||
|
|
||||||
|
AddPageCommand::AddPageCommand(Palette &pal) noexcept:
|
||||||
|
m_pal(pal) {}
|
||||||
|
|
||||||
|
int AddPageCommand::commandId() const noexcept {
|
||||||
|
return static_cast<int>(PaletteEditorCommandId::AddPage);
|
||||||
|
}
|
||||||
|
|
||||||
|
ox::Error AddPageCommand::redo() noexcept {
|
||||||
|
m_pal.pages.emplace_back(ox::sfmt("Page {}", m_pal.pages.size() + 1), ox::Vector<PaletteColor>{});
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
ox::Error AddPageCommand::undo() noexcept {
|
||||||
|
m_pal.pages.pop_back();
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,31 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2016 - 2025 Gary Talent (gary@drinkingtea.net). All rights reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <studio/studio.hpp>
|
||||||
|
|
||||||
|
#include <nostalgia/core/palette.hpp>
|
||||||
|
|
||||||
|
namespace nostalgia::core {
|
||||||
|
|
||||||
|
class AddPageCommand: public studio::UndoCommand {
|
||||||
|
private:
|
||||||
|
Palette &m_pal;
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit AddPageCommand(Palette &pal) noexcept;
|
||||||
|
|
||||||
|
~AddPageCommand() noexcept override = default;
|
||||||
|
|
||||||
|
[[nodiscard]]
|
||||||
|
int commandId() const noexcept final;
|
||||||
|
|
||||||
|
ox::Error redo() noexcept final;
|
||||||
|
|
||||||
|
ox::Error undo() noexcept final;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
@ -9,6 +9,7 @@ namespace nostalgia::core {
|
|||||||
enum class PaletteEditorCommandId {
|
enum class PaletteEditorCommandId {
|
||||||
ApplyColorAllPages,
|
ApplyColorAllPages,
|
||||||
RenamePage,
|
RenamePage,
|
||||||
|
AddPage,
|
||||||
DuplicatePage,
|
DuplicatePage,
|
||||||
RemovePage,
|
RemovePage,
|
||||||
AddColor,
|
AddColor,
|
||||||
|
@ -23,7 +23,7 @@ int DuplicatePageCommand::commandId() const noexcept {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ox::Error DuplicatePageCommand::redo() noexcept {
|
ox::Error DuplicatePageCommand::redo() noexcept {
|
||||||
m_pal.pages.emplace(m_dstIdx, "", std::move(m_page));
|
m_pal.pages.emplace(m_dstIdx, ox::sfmt("Page {}", m_pal.pages.size() + 1), std::move(m_page));
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
#include <keel/media.hpp>
|
#include <keel/media.hpp>
|
||||||
|
|
||||||
#include "commands/addcolorcommand.hpp"
|
#include "commands/addcolorcommand.hpp"
|
||||||
|
#include "commands/addpagecommand.hpp"
|
||||||
#include "commands/applycolorallpagescommand.hpp"
|
#include "commands/applycolorallpagescommand.hpp"
|
||||||
#include "commands/duplicatepagecommand.hpp"
|
#include "commands/duplicatepagecommand.hpp"
|
||||||
#include "commands/movecolorcommand.hpp"
|
#include "commands/movecolorcommand.hpp"
|
||||||
@ -196,7 +197,11 @@ void PaletteEditorImGui::drawPagesEditor() noexcept {
|
|||||||
constexpr auto toolbarHeight = 40;
|
constexpr auto toolbarHeight = 40;
|
||||||
auto const btnSz = ImVec2{paneSz.x / 4 - 5.5f, 24};
|
auto const btnSz = ImVec2{paneSz.x / 4 - 5.5f, 24};
|
||||||
if (ImGui::Button("Add", btnSz)) {
|
if (ImGui::Button("Add", btnSz)) {
|
||||||
|
if (m_pal.pages.empty()) {
|
||||||
|
std::ignore = pushCommand<AddPageCommand>(m_pal);
|
||||||
|
} else {
|
||||||
std::ignore = pushCommand<DuplicatePageCommand>(m_pal, 0u, m_pal.pages.size());
|
std::ignore = pushCommand<DuplicatePageCommand>(m_pal, 0u, m_pal.pages.size());
|
||||||
|
}
|
||||||
m_page = m_pal.pages.size() - 1;
|
m_page = m_pal.pages.size() - 1;
|
||||||
}
|
}
|
||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
|
Loading…
Reference in New Issue
Block a user