diff --git a/src/nostalgia/modules/core/src/studio/paletteeditor/paletteeditor-imgui.cpp b/src/nostalgia/modules/core/src/studio/paletteeditor/paletteeditor-imgui.cpp index fd8f9217..4f4adcf7 100644 --- a/src/nostalgia/modules/core/src/studio/paletteeditor/paletteeditor-imgui.cpp +++ b/src/nostalgia/modules/core/src/studio/paletteeditor/paletteeditor-imgui.cpp @@ -98,6 +98,12 @@ void PaletteEditorImGui::drawColumn(ox::CStringView txt) noexcept { ImGui::Text("%s", txt.c_str()); } +void PaletteEditorImGui::colorInput(ox::CStringView label, int &v, bool &inputFocused) noexcept { + ImGui::InputInt(label.c_str(), &v, 1, 5); + inputFocused = inputFocused || ImGui::IsItemFocused(); + v = ox::max(v, 0); +} + void PaletteEditorImGui::drawColorsEditor() noexcept { constexpr auto tableFlags = ImGuiTableFlags_RowBg; auto const colorsSz = ImGui::GetContentRegionAvail(); @@ -240,19 +246,13 @@ void PaletteEditorImGui::drawColorEditor() noexcept { ImGui::InputText("Name", name.data(), name.cap() + 1); ImGui::Separator(); bool inputFocused = false; - ImGui::InputInt("Red", &r, 1, 5); - inputFocused |= ImGui::IsItemFocused(); - ImGui::InputInt("Green", &g, 1, 5); - inputFocused |= ImGui::IsItemFocused(); - ImGui::InputInt("Blue", &b, 1, 5); - inputFocused |= ImGui::IsItemFocused(); + colorInput("Red", r, inputFocused); + colorInput("Green", g, inputFocused); + colorInput("Blue", b, inputFocused); if (ig::PushButton("Apply to all pages", {-1, ig::BtnSz.y})) { std::ignore = pushCommand( m_pal, m_page, m_selectedColorRow); } - r = ox::max(r, 0); - g = ox::max(g, 0); - b = ox::max(b, 0); if (!inputFocused) { for (auto i = 0u; i < ox::min(10, largestPage(m_pal)); ++i) { auto const key = static_cast(ImGuiKey_1 + i); diff --git a/src/nostalgia/modules/core/src/studio/paletteeditor/paletteeditor-imgui.hpp b/src/nostalgia/modules/core/src/studio/paletteeditor/paletteeditor-imgui.hpp index feefa082..d11d614f 100644 --- a/src/nostalgia/modules/core/src/studio/paletteeditor/paletteeditor-imgui.hpp +++ b/src/nostalgia/modules/core/src/studio/paletteeditor/paletteeditor-imgui.hpp @@ -56,6 +56,8 @@ class PaletteEditorImGui: public studio::Editor { drawColumn(ox::itoa(i)); } + static void colorInput(ox::CStringView label, int &v, bool &inputFocused) noexcept; + void drawColorsEditor() noexcept; void drawPagesEditor() noexcept;