diff --git a/release-notes.md b/release-notes.md index e235a86e..0312e2f6 100644 --- a/release-notes.md +++ b/release-notes.md @@ -1,3 +1,7 @@ +# d2025.06.0 + +* PaletteEditor: Add RGB key shortcuts for focusing color channels + # d2025.05.0 * Add app icon for both window and file diff --git a/src/nostalgia/modules/gfx/src/studio/paletteeditor/paletteeditor-imgui.cpp b/src/nostalgia/modules/gfx/src/studio/paletteeditor/paletteeditor-imgui.cpp index 756c747a..8b2847f3 100644 --- a/src/nostalgia/modules/gfx/src/studio/paletteeditor/paletteeditor-imgui.cpp +++ b/src/nostalgia/modules/gfx/src/studio/paletteeditor/paletteeditor-imgui.cpp @@ -118,12 +118,12 @@ void PaletteEditorImGui::navigateTo(ox::StringViewCR arg) noexcept { } } -void PaletteEditorImGui::drawColumnLeftAlign(ox::CStringView txt) noexcept { +void PaletteEditorImGui::drawColumnLeftAlign(ox::CStringViewCR txt) noexcept { ImGui::TableNextColumn(); ImGui::Text("%s", txt.c_str()); } -void PaletteEditorImGui::drawColumn(ox::CStringView txt) noexcept { +void PaletteEditorImGui::drawColumn(ox::CStringViewCR txt) noexcept { ImGui::TableNextColumn(); ImGui::SetCursorPosX( ImGui::GetCursorPosX() + ImGui::GetColumnWidth() - ImGui::CalcTextSize(txt.data()).x); @@ -143,7 +143,15 @@ void PaletteEditorImGui::numShortcuts(size_t &val, size_t const sizeRange) noexc } } -void PaletteEditorImGui::colorInput(ox::CStringView label, int &v, bool &inputFocused) noexcept { +void PaletteEditorImGui::colorInput( + ox::CStringViewCR label, + int &v, + bool &inputFocused, + FocusCmd const colorChannel) noexcept { + if (colorChannel == m_focusCmd) [[unlikely]] { + ImGui::SetKeyboardFocusHere(); + m_focusCmd = FocusCmd::None; + } ImGui::InputInt(label.c_str(), &v, 1, 5); inputFocused = inputFocused || ImGui::IsItemFocused(); v = ox::max(v, 0); @@ -296,9 +304,9 @@ void PaletteEditorImGui::drawColorEditor() noexcept { "Name", m_pal.colorNames[m_selectedColorRow]); bool inputFocused = ImGui::IsItemFocused(); ImGui::Separator(); - colorInput("Red", r, inputFocused); - colorInput("Green", g, inputFocused); - colorInput("Blue", b, inputFocused); + colorInput("Red", r, inputFocused, FocusCmd::Red); + colorInput("Green", g, inputFocused, FocusCmd::Green); + colorInput("Blue", b, inputFocused, FocusCmd::Blue); if (ig::PushButton("Apply to all pages", {-1, ig::BtnSz.y})) { std::ignore = pushCommand( m_pal, m_page, m_selectedColorRow); @@ -309,6 +317,15 @@ void PaletteEditorImGui::drawColorEditor() noexcept { } else { numShortcuts(m_page, m_pal.pages.size()); } + if (ImGui::IsKeyDown(ImGuiKey_R)) { + m_focusCmd = FocusCmd::Red; + } + if (ImGui::IsKeyDown(ImGuiKey_G)) { + m_focusCmd = FocusCmd::Green; + } + if (ImGui::IsKeyDown(ImGuiKey_B)) { + m_focusCmd = FocusCmd::Blue; + } } auto const newColor = color16(r, g, b, a); if (c != newColor) { @@ -320,7 +337,7 @@ void PaletteEditorImGui::drawColorEditor() noexcept { } } -ox::Error PaletteEditorImGui::renamePage(ox::StringView name) noexcept { +ox::Error PaletteEditorImGui::renamePage(ox::StringViewCR name) noexcept { return pushCommand(m_pal, m_page, name); } diff --git a/src/nostalgia/modules/gfx/src/studio/paletteeditor/paletteeditor-imgui.hpp b/src/nostalgia/modules/gfx/src/studio/paletteeditor/paletteeditor-imgui.hpp index 5fed246d..cba95ffd 100644 --- a/src/nostalgia/modules/gfx/src/studio/paletteeditor/paletteeditor-imgui.hpp +++ b/src/nostalgia/modules/gfx/src/studio/paletteeditor/paletteeditor-imgui.hpp @@ -36,6 +36,13 @@ class PaletteEditorImGui: public studio::Editor { Palette m_pal; size_t m_selectedColorRow = 0; size_t m_page = 0; + enum class FocusCmd { + None, + Red, + Green, + Blue, + }; + FocusCmd m_focusCmd; public: PaletteEditorImGui(studio::Context &sctx, ox::StringParam path); @@ -48,9 +55,9 @@ class PaletteEditorImGui: public studio::Editor { void navigateTo(ox::StringViewCR arg) noexcept override; private: - static void drawColumnLeftAlign(ox::CStringView txt) noexcept; + static void drawColumnLeftAlign(ox::CStringViewCR txt) noexcept; - static void drawColumn(ox::CStringView txt) noexcept; + static void drawColumn(ox::CStringViewCR txt) noexcept; static void drawColumn(ox::Integer_c auto i) noexcept { drawColumn(ox::intToStr(i)); @@ -58,7 +65,7 @@ class PaletteEditorImGui: public studio::Editor { static void numShortcuts(size_t &val, size_t sizeRange) noexcept; - static void colorInput(ox::CStringView label, int &v, bool &inputFocused) noexcept; + void colorInput(ox::CStringViewCR label, int &v, bool &inputFocused, FocusCmd colorChannel) noexcept; void drawColorsEditor() noexcept; @@ -66,7 +73,7 @@ class PaletteEditorImGui: public studio::Editor { void drawColorEditor() noexcept; - ox::Error renamePage(ox::StringView name) noexcept; + ox::Error renamePage(ox::StringViewCR name) noexcept; ox::Error handleCommand(studio::UndoCommand const*) noexcept; };