Skip to content

Commit ed7551c

Browse files
committed
Selectable: Fixed horizontal label alignment when combined with using ImGuiSelectableFlags_SpanAllColumns. (ocornut#8338)
1 parent bbf9578 commit ed7551c

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

docs/CHANGELOG.txt

+2
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,8 @@ Other changes:
139139
the label (not only the highlight/frame) also spans all columns. This is
140140
useful for table rows where you know nothing else is submitted. (#8318, #3565)
141141
Obviously best used with ImGuiTableFlags_NoBordersInBodyUntilResize.
142+
- Selectable: Fixed horizontal label alignment when combined with using
143+
ImGuiSelectableFlags_SpanAllColumns. (#8338)
142144
- Drags: Added ImGuiSliderFlags_NoSpeedTweaks flag to disable keyboard
143145
modifiers altering the tweak speed. Useful if you want to alter tweak speed
144146
yourself based on your own logic. (#8223)

imgui_widgets.cpp

+3-6
Original file line numberDiff line numberDiff line change
@@ -6943,13 +6943,9 @@ bool ImGui::Selectable(const char* label, bool selected, ImGuiSelectableFlags fl
69436943
if (size_arg.x == 0.0f || (flags & ImGuiSelectableFlags_SpanAvailWidth))
69446944
size.x = ImMax(label_size.x, max_x - min_x);
69456945

6946-
// Text stays at the submission position, but bounding box may be extended on both sides
6947-
const ImVec2 text_min = pos;
6948-
const ImVec2 text_max(min_x + size.x, pos.y + size.y);
6949-
69506946
// Selectables are meant to be tightly packed together with no click-gap, so we extend their box to cover spacing between selectable.
69516947
// FIXME: Not part of layout so not included in clipper calculation, but ItemSize currently doesn't allow offsetting CursorPos.
6952-
ImRect bb(min_x, pos.y, text_max.x, text_max.y);
6948+
ImRect bb(min_x, pos.y, min_x + size.x, pos.y + size.y);
69536949
if ((flags & ImGuiSelectableFlags_NoPadWithHalfSpacing) == 0)
69546950
{
69556951
const float spacing_x = span_all_columns ? 0.0f : style.ItemSpacing.x;
@@ -7085,8 +7081,9 @@ bool ImGui::Selectable(const char* label, bool selected, ImGuiSelectableFlags fl
70857081
PopColumnsBackground();
70867082
}
70877083

7084+
// Text stays at the submission position. Alignment/clipping extents ignore SpanAllColumns.
70887085
if (is_visible)
7089-
RenderTextClipped(text_min, text_max, label, NULL, &label_size, style.SelectableTextAlign, &bb);
7086+
RenderTextClipped(pos, ImVec2(window->WorkRect.Max.x, pos.y + size.y), label, NULL, &label_size, style.SelectableTextAlign, &bb);
70907087

70917088
// Automatically close popups
70927089
if (pressed && (window->Flags & ImGuiWindowFlags_Popup) && !(flags & ImGuiSelectableFlags_NoAutoClosePopups) && (g.LastItemData.ItemFlags & ImGuiItemFlags_AutoClosePopups))

0 commit comments

Comments
 (0)