Squashed 'deps/nostalgia/' changes from 66cd5c4a..3c7652ef

3c7652ef [nostalgia/core/studio] Fix PaletteEditor to handle Palettes with 0 pages
941bc713 [studio] Fix NewMenu name input
e4ae23e1 [olympic/developer-handbook] Remove Ox submodules from project structure
67187d5e [olympic/developer-handbook] Elaborate more on exception usage
3271a371 [ox] Add Project Structure section to docs
ea9f50de [olympic] Add error handling back to developer-handbook.md
ea3c5e03 [olympic] Remove Ox from developer-handbook.md
c8c4177d [ox] Add ox-docs.md
76b540e3 [nostalgia/core] Cleanup, add missing FileAddress wrapper function
20627486 [keel] Cleanup
135f0e4c [nostalgia/core/studio/paletteeditor] Fix Alt shortcuts to respect keyboard focus
cb166876 [studio] Add variant of InputText that returns an IString
cb3ef0e7 [keel] Cleanup
0a62d900 [studio] Remove Editor::setRequiresConstantRefresh
ba7e3929 [nostalgia/core/studio] Make TileSheetEditor palette keys behave like PaletteEditor
36c4022b [nostalgia/core/studio] Fix PaletteEditor shortcuts to differentiate based on Alt key
e22b25e5 [studio] Remove Editor::requiresConstantRefresh
c6efabaa [studio,nostalgia] Fix PaletteEditor color update command merging, add setObsolete
1f6fefdb [nostalgia/core/studio] Disable PaletteEditor num key shorts when page rename is open
1e34f91e Merge commit '34b7779397bd4712603b4c5a39ffc57b74da0abd'
35cb2ece [nostalgia/core/studio] Fix PaletteEditor color name edit

git-subtree-dir: deps/nostalgia
git-subtree-split: 3c7652efc205cb3acdb993d7eeb1e2c2d894c2cb
This commit is contained in:
2024-11-01 22:21:09 -05:00
parent 34b7779397
commit 9e11019b87
21 changed files with 679 additions and 640 deletions

View File

@@ -23,7 +23,6 @@ class BaseEditor: public Widget {
bool m_cutEnabled = false;
bool m_copyEnabled = false;
bool m_pasteEnabled = false;
bool m_requiresConstantRefresh = false;
public:
~BaseEditor() override = default;
@@ -52,9 +51,6 @@ class BaseEditor: public Widget {
virtual void onActivated() noexcept;
[[nodiscard]]
bool requiresConstantRefresh() const noexcept;
void close() const;
/**
@@ -71,10 +67,10 @@ class BaseEditor: public Widget {
[[nodiscard]]
bool unsavedChanges() const noexcept;
void setExportable(bool);
void setExportable(bool) noexcept;
[[nodiscard]]
bool exportable() const;
bool exportable() const noexcept;
void setCutEnabled(bool);

View File

@@ -128,9 +128,35 @@ void centerNextWindow(turbine::Context &ctx) noexcept;
bool PushButton(ox::CStringView lbl, ImVec2 const&btnSz = BtnSz) noexcept;
template<typename Str>
struct TextInput {
bool changed{};
Str text;
explicit constexpr operator ox::String() const noexcept { return ox::String{text}; }
constexpr operator ox::CStringView() const noexcept { return text; }
constexpr operator ox::StringView() const noexcept { return text; }
constexpr operator bool() const noexcept { return changed; }
};
template<size_t MaxChars = 50>
TextInput<ox::IString<MaxChars>> InputText(
ox::CStringViewCR label,
ox::StringViewCR currentText,
ImGuiInputTextFlags const flags = 0,
ImGuiInputTextCallback const callback = nullptr,
void *user_data = nullptr) noexcept {
TextInput<ox::IString<MaxChars>> out = {.text = currentText};
out.changed = ImGui::InputText(
label.c_str(), out.text.data(), MaxChars + 1, flags, callback, user_data);
if (out.changed) {
std::ignore = out.text.unsafeResize(ox::strlen(out.text.c_str()));
}
return out;
}
template<size_t StrCap>
bool InputText(
ox::CStringView label,
ox::CStringViewCR label,
ox::IString<StrCap> &text,
ImGuiInputTextFlags const flags = 0,
ImGuiInputTextCallback const callback = nullptr,

View File

@@ -17,13 +17,22 @@ class NoChangesException: public ox::Exception {
};
class UndoCommand {
private:
bool m_obsolete{};
public:
virtual ~UndoCommand() noexcept = default;
virtual ox::Error redo() noexcept = 0;
virtual ox::Error undo() noexcept = 0;
[[nodiscard]]
virtual int commandId() const noexcept = 0;
virtual bool mergeWith(UndoCommand const&cmd) noexcept;
virtual bool mergeWith(UndoCommand &cmd) noexcept;
constexpr void setObsolete(bool obsolete) noexcept {
m_obsolete = obsolete;
}
[[nodiscard]]
constexpr bool isObsolete() const noexcept {
return m_obsolete;
}
};
}

View File

@@ -36,10 +36,6 @@ void BaseEditor::keyStateChanged(turbine::Key, bool) {
void BaseEditor::onActivated() noexcept {
}
bool BaseEditor::requiresConstantRefresh() const noexcept {
return m_requiresConstantRefresh;
}
void BaseEditor::close() const {
this->closed.emit(itemPath());
}
@@ -66,12 +62,12 @@ bool BaseEditor::unsavedChanges() const noexcept {
return m_unsavedChanges;
}
void BaseEditor::setExportable(bool exportable) {
void BaseEditor::setExportable(bool exportable) noexcept {
m_exportable = exportable;
exportableChanged.emit(exportable);
}
bool BaseEditor::exportable() const {
bool BaseEditor::exportable() const noexcept {
return m_exportable;
}
@@ -110,10 +106,6 @@ UndoStack *BaseEditor::undoStack() noexcept {
return nullptr;
}
void BaseEditor::setRequiresConstantRefresh(bool value) noexcept {
m_requiresConstantRefresh = value;
}
Editor::Editor(ox::StringParam itemPath) noexcept:
m_itemPath(std::move(itemPath)),

View File

@@ -3,7 +3,7 @@
namespace studio {
bool UndoCommand::mergeWith(UndoCommand const&) noexcept {
bool UndoCommand::mergeWith(UndoCommand&) noexcept {
return false;
}

View File

@@ -17,6 +17,10 @@ ox::Error UndoStack::push(ox::UPtr<UndoCommand> &&cmd) noexcept {
m_stack.emplace_back(std::move(cmd));
++m_stackIdx;
}
if ((*m_stack.back().unwrap())->isObsolete()) {
m_stack.pop_back();
--m_stackIdx;
}
return {};
}