Fix card lists: zero window padding for the list child, tooltips keep the window style

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
shweetandClaude Opus 5.5 committed 2026-10-03 18:00:15 -04:00
1 parent dc32483c45
commit c6c8e3598b
7 files changed
+56 -33

No files matched your search

+1 -1
View File
@@ -783,7 +783,7 @@ namespace anm2ed::imgui
list_select_end(panel, selection, focus, rows, arrowKey); list_select_end(panel, selection, focus, rows, arrowKey);
animations_selection_set(document, selection, groupSelection); animations_selection_set(document, selection, groupSelection);
}, },
&footerActions); false, &footerActions);
} }
ImGui::End(); ImGui::End();
+29 -12
View File
@@ -42,14 +42,27 @@ namespace anm2ed::imgui
if (state.scrollId == key) state.scrollId = -1; 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; ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, state.tooltipPadding);
if (ImGui::BeginItemTooltip()) ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, state.tooltipSpacing);
{ if (isItem ? ImGui::BeginItemTooltip() : ImGui::BeginTooltip()) return true;
rows.tooltip_draw(key); ImGui::PopStyleVar(2);
ImGui::EndTooltip(); 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. // Arrow keys move a single selection through the keys.
@@ -152,7 +165,7 @@ namespace anm2ed::imgui
rows.activate(key); rows.activate(key);
auto isBreak = rows.drag_drop_update && rows.drag_drop_update(key, index); 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(); ImGui::PopID();
return isBreak; return isBreak;
} }
@@ -194,11 +207,11 @@ namespace anm2ed::imgui
if (rows.tooltip_draw && ImGui::IsItemHovered(ImGuiHoveredFlags_ForTooltip) && if (rows.tooltip_draw && ImGui::IsItemHovered(ImGuiHoveredFlags_ForTooltip) &&
!ImGui::IsMouseDragging(ImGuiMouseButton_Left)) !ImGui::IsMouseDragging(ImGuiMouseButton_Left))
{ {
ImGui::SetNextWindowSize(ImVec2(ImGui::CalcTextSize(label.c_str()).x + style.ItemSpacing.x + ImGui::SetNextWindowSize(ImVec2(ImGui::CalcTextSize(label.c_str()).x + panel.state.tooltipSpacing.x +
style.WindowPadding.x * TOOLTIP_PADDING_MULTIPLIER, panel.state.tooltipPadding.x * TOOLTIP_PADDING_MULTIPLIER,
0), 0),
ImGuiCond_Appearing); 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); 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. // 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<void()>& list, void list_panel_draw(Panel& panel, Actions& actions, const Footer& footer, const std::function<void()>& list,
Actions* footerActions) bool isCards, Actions* footerActions)
{ {
auto& [manager, settings, resources, dialog, clipboard, document, state] = panel; 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)) if (ImGui::BeginChild("##List Child", size_without_footer_get((int)footer.size()), ImGuiChildFlags_Borders))
{ {
list(); list();
actions_shortcuts_update(actions, manager); actions_shortcuts_update(actions, manager);
} }
ImGui::EndChild(); ImGui::EndChild();
if (isCards) ImGui::PopStyleVar();
if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenOverlappedByWindow) && if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenOverlappedByWindow) &&
ImGui::IsMouseReleased(ImGuiMouseButton_Right)) ImGui::IsMouseReleased(ImGuiMouseButton_Right))
+5 -1
View File
@@ -47,6 +47,8 @@ namespace anm2ed::imgui
std::vector<int> keys{}; std::vector<int> keys{};
std::vector<int> dragIds{}; std::vector<int> dragIds{};
MultiSelectStorage selection{}; MultiSelectStorage selection{};
ImVec2 tooltipPadding{};
ImVec2 tooltipSpacing{};
}; };
// Everything a panel draws with, for one frame. Commands get the document again when they run. // 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<int>&, const ListRows&); void content_list_draw(Panel&, SelectionKind, const std::vector<int>&, const ListRows&);
int list_select_begin(Panel&, std::set<int>&, int&, const ListRows&, const std::vector<int>&); int list_select_begin(Panel&, std::set<int>&, int&, const ListRows&, const std::vector<int>&);
void list_select_end(Panel&, std::set<int>&, int&, const ListRows&, int); void list_select_end(Panel&, std::set<int>&, int&, const ListRows&, int);
void list_panel_draw(Panel&, Actions&, const Footer&, const std::function<void()>&, Actions* = nullptr); void list_panel_draw(Panel&, Actions&, const Footer&, const std::function<void()>&, bool = false, Actions* = nullptr);
bool tooltip_begin(const PanelState&, bool = true);
void tooltip_end();
void tooltip_name_draw(Resources&, const std::string&); void tooltip_name_draw(Resources&, const std::string&);
void tooltip_image_draw(const CardImage&, const std::function<void()>&); void tooltip_image_draw(const CardImage&, const std::function<void()>&);
void directory_open(Dialog&, Document&, const std::filesystem::path&); void directory_open(Dialog&, Document&, const std::filesystem::path&);
+12 -12
View File
@@ -252,12 +252,10 @@ namespace anm2ed::imgui
auto mousePos = ImGui::GetIO().MousePos; auto mousePos = ImGui::GetIO().MousePos;
ImGui::SetNextWindowPos(ImVec2(mousePos.x + DRAG_TOOLTIP_OFFSET.x, mousePos.y + DRAG_TOOLTIP_OFFSET.y)); ImGui::SetNextWindowPos(ImVec2(mousePos.x + DRAG_TOOLTIP_OFFSET.x, mousePos.y + DRAG_TOOLTIP_OFFSET.y));
if (ImGui::BeginTooltip()) if (!tooltip_begin(state, false)) return;
{ for (auto regionId : state.dragIds)
for (auto regionId : state.dragIds) if (auto region = model::item_get(spritesheet->regions, regionId)) ImGui::TextUnformatted(region->name.c_str());
if (auto region = model::item_get(spritesheet->regions, regionId)) ImGui::TextUnformatted(region->name.c_str()); tooltip_end();
ImGui::EndTooltip();
}
} }
void region_properties_open(RegionsPanel& regions, Document& document, int id) 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); }, .activate = [&](int id) { region_properties_open(regions, document, id); },
.drag_drop_update = [&](int id, int index) { return region_drag_drop_update(panel, id, index); }, .drag_drop_update = [&](int id, int index) { return region_drag_drop_update(panel, id, index); },
.cardLines = REGION_CARD_LINES}; .cardLines = REGION_CARD_LINES};
list_panel_draw(panel, actions, {{ACTION_ADD, ACTION_EXPORT, ACTION_REMOVE_UNUSED}}, 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); content_list_draw(panel, SelectionKind::REGIONS, item_ids_get(spritesheet->regions), rows);
}); region_drag_tooltip_update(panel);
},
true);
} }
} }
ImGui::End(); ImGui::End();
+3 -2
View File
@@ -378,8 +378,9 @@ namespace anm2ed::imgui
.image_get = image_get, .image_get = image_get,
.activate = properties_open, .activate = properties_open,
.cardLines = SHADER_CARD_LINES}; .cardLines = SHADER_CARD_LINES};
list_panel_draw(panel, actions, {{ACTION_ADD, ACTION_REMOVE_UNUSED, ACTION_RELOAD}}, list_panel_draw(
[&]() { content_list_draw(panel, SelectionKind::SHADERS, item_ids_get(items), rows); }); panel, actions, {{ACTION_ADD, ACTION_REMOVE_UNUSED, ACTION_RELOAD}},
[&]() { content_list_draw(panel, SelectionKind::SHADERS, item_ids_get(items), rows); }, true);
propertiesPopup.trigger(); propertiesPopup.trigger();
if (ImGui::BeginPopupModal(propertiesPopup.label(), &propertiesPopup.isOpen, ImGuiWindowFlags_NoResize)) if (ImGui::BeginPopupModal(propertiesPopup.label(), &propertiesPopup.isOpen, ImGuiWindowFlags_NoResize))
+3 -2
View File
@@ -131,8 +131,9 @@ namespace anm2ed::imgui
}, },
.activate = open, .activate = open,
.cardLines = SOUND_CARD_LINES}; .cardLines = SOUND_CARD_LINES};
list_panel_draw(panel, actions, {{ACTION_ADD, ACTION_REMOVE_UNUSED, ACTION_RELOAD, ACTION_REPLACE}}, list_panel_draw(
[&]() { content_list_draw(panel, SelectionKind::SOUNDS, item_ids_get(sounds), rows); }); 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(); ImGui::End();
} }
+3 -3
View File
@@ -363,9 +363,9 @@ namespace anm2ed::imgui
}, },
.activate = open, .activate = open,
.cardLines = SPRITESHEET_CARD_LINES}; .cardLines = SPRITESHEET_CARD_LINES};
list_panel_draw(panel, actions, list_panel_draw(
{{ACTION_ADD, ACTION_RELOAD, ACTION_REPLACE}, {ACTION_REMOVE_UNUSED, ACTION_SAVE}}, panel, actions, {{ACTION_ADD, ACTION_RELOAD, ACTION_REPLACE}, {ACTION_REMOVE_UNUSED, ACTION_SAVE}},
[&]() { content_list_draw(panel, SelectionKind::SPRITESHEETS, item_ids_get(items), rows); }); [&]() { content_list_draw(panel, SelectionKind::SPRITESHEETS, item_ids_get(items), rows); }, true);
} }
ImGui::End(); ImGui::End();