From c6c8e3598bfb481f2437b7c788483da74a463648 Mon Sep 17 00:00:00 2001 From: shweet Date: Sat, 3 Oct 2026 18:00:15 -0400 Subject: [PATCH] Fix card lists: zero window padding for the list child, tooltips keep the window style Co-Authored-By: Claude Opus 5.5 --- src/imgui/window/animations.cpp | 2 +- src/imgui/window/panel.cpp | 41 ++++++++++++++++++++++--------- src/imgui/window/panel.hpp | 6 ++++- src/imgui/window/regions.cpp | 24 +++++++++--------- src/imgui/window/shaders.cpp | 5 ++-- src/imgui/window/sounds.cpp | 5 ++-- src/imgui/window/spritesheets.cpp | 6 ++--- 7 files changed, 56 insertions(+), 33 deletions(-) diff --git a/src/imgui/window/animations.cpp b/src/imgui/window/animations.cpp index 2ebe5d5..1c7316a 100644 --- a/src/imgui/window/animations.cpp +++ b/src/imgui/window/animations.cpp @@ -783,7 +783,7 @@ namespace anm2ed::imgui list_select_end(panel, selection, focus, rows, arrowKey); animations_selection_set(document, selection, groupSelection); }, - &footerActions); + false, &footerActions); } ImGui::End(); diff --git a/src/imgui/window/panel.cpp b/src/imgui/window/panel.cpp index e22fca7..6119ed6 100644 --- a/src/imgui/window/panel.cpp +++ b/src/imgui/window/panel.cpp @@ -42,14 +42,27 @@ namespace anm2ed::imgui if (state.scrollId == key) state.scrollId = -1; } - void row_tooltip_update(const ListRows& rows, int key) + // Tooltips keep the window's padding and spacing, which card lists zero out for themselves. + bool tooltip_begin(const PanelState& state, bool isItem) { - if (!rows.tooltip_draw) return; - if (ImGui::BeginItemTooltip()) - { - rows.tooltip_draw(key); - ImGui::EndTooltip(); - } + ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, state.tooltipPadding); + ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, state.tooltipSpacing); + if (isItem ? ImGui::BeginItemTooltip() : ImGui::BeginTooltip()) return true; + ImGui::PopStyleVar(2); + return false; + } + + void tooltip_end() + { + ImGui::EndTooltip(); + ImGui::PopStyleVar(2); + } + + void row_tooltip_update(const PanelState& state, const ListRows& rows, int key) + { + if (!rows.tooltip_draw || !tooltip_begin(state)) return; + rows.tooltip_draw(key); + tooltip_end(); } // Arrow keys move a single selection through the keys. @@ -152,7 +165,7 @@ namespace anm2ed::imgui rows.activate(key); auto isBreak = rows.drag_drop_update && rows.drag_drop_update(key, index); - row_tooltip_update(rows, key); + row_tooltip_update(panel.state, rows, key); ImGui::PopID(); return isBreak; } @@ -194,11 +207,11 @@ namespace anm2ed::imgui if (rows.tooltip_draw && ImGui::IsItemHovered(ImGuiHoveredFlags_ForTooltip) && !ImGui::IsMouseDragging(ImGuiMouseButton_Left)) { - ImGui::SetNextWindowSize(ImVec2(ImGui::CalcTextSize(label.c_str()).x + style.ItemSpacing.x + - style.WindowPadding.x * TOOLTIP_PADDING_MULTIPLIER, + ImGui::SetNextWindowSize(ImVec2(ImGui::CalcTextSize(label.c_str()).x + panel.state.tooltipSpacing.x + + panel.state.tooltipPadding.x * TOOLTIP_PADDING_MULTIPLIER, 0), ImGuiCond_Appearing); - row_tooltip_update(rows, key); + row_tooltip_update(panel.state, rows, key); } isBreak = rows.drag_drop_update && rows.drag_drop_update(key, index); @@ -258,15 +271,19 @@ namespace anm2ed::imgui // The list in a bordered child with its context menu and shortcuts, then the footer buttons. void list_panel_draw(Panel& panel, Actions& actions, const Footer& footer, const std::function& list, - Actions* footerActions) + bool isCards, Actions* footerActions) { auto& [manager, settings, resources, dialog, clipboard, document, state] = panel; + state.tooltipPadding = ImGui::GetStyle().WindowPadding; + state.tooltipSpacing = ImGui::GetStyle().ItemSpacing; + if (isCards) ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2()); if (ImGui::BeginChild("##List Child", size_without_footer_get((int)footer.size()), ImGuiChildFlags_Borders)) { list(); actions_shortcuts_update(actions, manager); } ImGui::EndChild(); + if (isCards) ImGui::PopStyleVar(); if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenOverlappedByWindow) && ImGui::IsMouseReleased(ImGuiMouseButton_Right)) diff --git a/src/imgui/window/panel.hpp b/src/imgui/window/panel.hpp index 82ca660..b1a1fa5 100644 --- a/src/imgui/window/panel.hpp +++ b/src/imgui/window/panel.hpp @@ -47,6 +47,8 @@ namespace anm2ed::imgui std::vector keys{}; std::vector dragIds{}; MultiSelectStorage selection{}; + ImVec2 tooltipPadding{}; + ImVec2 tooltipSpacing{}; }; // Everything a panel draws with, for one frame. Commands get the document again when they run. @@ -91,7 +93,9 @@ namespace anm2ed::imgui void content_list_draw(Panel&, SelectionKind, const std::vector&, const ListRows&); int list_select_begin(Panel&, std::set&, int&, const ListRows&, const std::vector&); void list_select_end(Panel&, std::set&, int&, const ListRows&, int); - void list_panel_draw(Panel&, Actions&, const Footer&, const std::function&, Actions* = nullptr); + void list_panel_draw(Panel&, Actions&, const Footer&, const std::function&, bool = false, Actions* = nullptr); + bool tooltip_begin(const PanelState&, bool = true); + void tooltip_end(); void tooltip_name_draw(Resources&, const std::string&); void tooltip_image_draw(const CardImage&, const std::function&); void directory_open(Dialog&, Document&, const std::filesystem::path&); diff --git a/src/imgui/window/regions.cpp b/src/imgui/window/regions.cpp index 66d9022..aae161f 100644 --- a/src/imgui/window/regions.cpp +++ b/src/imgui/window/regions.cpp @@ -252,12 +252,10 @@ namespace anm2ed::imgui auto mousePos = ImGui::GetIO().MousePos; ImGui::SetNextWindowPos(ImVec2(mousePos.x + DRAG_TOOLTIP_OFFSET.x, mousePos.y + DRAG_TOOLTIP_OFFSET.y)); - if (ImGui::BeginTooltip()) - { - for (auto regionId : state.dragIds) - if (auto region = model::item_get(spritesheet->regions, regionId)) ImGui::TextUnformatted(region->name.c_str()); - ImGui::EndTooltip(); - } + if (!tooltip_begin(state, false)) return; + for (auto regionId : state.dragIds) + if (auto region = model::item_get(spritesheet->regions, regionId)) ImGui::TextUnformatted(region->name.c_str()); + tooltip_end(); } void region_properties_open(RegionsPanel& regions, Document& document, int id) @@ -536,12 +534,14 @@ namespace anm2ed::imgui .activate = [&](int id) { region_properties_open(regions, document, id); }, .drag_drop_update = [&](int id, int index) { return region_drag_drop_update(panel, id, index); }, .cardLines = REGION_CARD_LINES}; - list_panel_draw(panel, actions, {{ACTION_ADD, ACTION_EXPORT, ACTION_REMOVE_UNUSED}}, - [&]() - { - content_list_draw(panel, SelectionKind::REGIONS, item_ids_get(spritesheet->regions), rows); - region_drag_tooltip_update(panel); - }); + list_panel_draw( + panel, actions, {{ACTION_ADD, ACTION_EXPORT, ACTION_REMOVE_UNUSED}}, + [&]() + { + content_list_draw(panel, SelectionKind::REGIONS, item_ids_get(spritesheet->regions), rows); + region_drag_tooltip_update(panel); + }, + true); } } ImGui::End(); diff --git a/src/imgui/window/shaders.cpp b/src/imgui/window/shaders.cpp index 08f3ba1..f0b237d 100644 --- a/src/imgui/window/shaders.cpp +++ b/src/imgui/window/shaders.cpp @@ -378,8 +378,9 @@ namespace anm2ed::imgui .image_get = image_get, .activate = properties_open, .cardLines = SHADER_CARD_LINES}; - list_panel_draw(panel, actions, {{ACTION_ADD, ACTION_REMOVE_UNUSED, ACTION_RELOAD}}, - [&]() { content_list_draw(panel, SelectionKind::SHADERS, item_ids_get(items), rows); }); + list_panel_draw( + panel, actions, {{ACTION_ADD, ACTION_REMOVE_UNUSED, ACTION_RELOAD}}, + [&]() { content_list_draw(panel, SelectionKind::SHADERS, item_ids_get(items), rows); }, true); propertiesPopup.trigger(); if (ImGui::BeginPopupModal(propertiesPopup.label(), &propertiesPopup.isOpen, ImGuiWindowFlags_NoResize)) diff --git a/src/imgui/window/sounds.cpp b/src/imgui/window/sounds.cpp index 8848f5d..713737f 100644 --- a/src/imgui/window/sounds.cpp +++ b/src/imgui/window/sounds.cpp @@ -131,8 +131,9 @@ namespace anm2ed::imgui }, .activate = open, .cardLines = SOUND_CARD_LINES}; - list_panel_draw(panel, actions, {{ACTION_ADD, ACTION_REMOVE_UNUSED, ACTION_RELOAD, ACTION_REPLACE}}, - [&]() { content_list_draw(panel, SelectionKind::SOUNDS, item_ids_get(sounds), rows); }); + list_panel_draw( + panel, actions, {{ACTION_ADD, ACTION_REMOVE_UNUSED, ACTION_RELOAD, ACTION_REPLACE}}, + [&]() { content_list_draw(panel, SelectionKind::SOUNDS, item_ids_get(sounds), rows); }, true); } ImGui::End(); } diff --git a/src/imgui/window/spritesheets.cpp b/src/imgui/window/spritesheets.cpp index ceb3f2c..a043b8e 100644 --- a/src/imgui/window/spritesheets.cpp +++ b/src/imgui/window/spritesheets.cpp @@ -363,9 +363,9 @@ namespace anm2ed::imgui }, .activate = open, .cardLines = SPRITESHEET_CARD_LINES}; - list_panel_draw(panel, actions, - {{ACTION_ADD, ACTION_RELOAD, ACTION_REPLACE}, {ACTION_REMOVE_UNUSED, ACTION_SAVE}}, - [&]() { content_list_draw(panel, SelectionKind::SPRITESHEETS, item_ids_get(items), rows); }); + list_panel_draw( + panel, actions, {{ACTION_ADD, ACTION_RELOAD, ACTION_REPLACE}, {ACTION_REMOVE_UNUSED, ACTION_SAVE}}, + [&]() { content_list_draw(panel, SelectionKind::SPRITESHEETS, item_ids_get(items), rows); }, true); } ImGui::End();