MCPcopy Create free account
hub / github.com/Wemino/MarkerPatch / Selectable

Method Selectable

include/imgui/imgui_widgets.cpp:7353–7538  ·  view source on GitHub ↗

Tip: pass a non-visible label (e.g. "##hello") then you can use the space to draw other text or image. But you need to make sure the ID is unique, e.g. enclose calls in PushID/PopID or use ##unique_id. With this scheme, ImGuiSelectableFlags_SpanAllColumns and ImGuiSelectableFlags_AllowOverlap are also frequently used flags. FIXME: Selectable() with (size.x == 0.0f) and (SelectableTextAlign.x > 0.0

Source from the content-addressed store, hash-verified

7351// With this scheme, ImGuiSelectableFlags_SpanAllColumns and ImGuiSelectableFlags_AllowOverlap are also frequently used flags.
7352// FIXME: Selectable() with (size.x == 0.0f) and (SelectableTextAlign.x > 0.0f) followed by SameLine() is currently not supported.
7353bool ImGui::Selectable(const char* label, bool selected, ImGuiSelectableFlags flags, const ImVec2& size_arg)
7354{
7355 ImGuiWindow* window = GetCurrentWindow();
7356 if (window->SkipItems)
7357 return false;
7358
7359 ImGuiContext& g = *GImGui;
7360 const ImGuiStyle& style = g.Style;
7361
7362 // Submit label or explicit size to ItemSize(), whereas ItemAdd() will submit a larger/spanning rectangle.
7363 ImGuiID id = window->GetID(label);
7364 const char* label_end = FindRenderedTextEnd(label);
7365 ImVec2 label_size = CalcTextSize(label, label_end, false);
7366 ImVec2 size(size_arg.x != 0.0f ? size_arg.x : label_size.x, size_arg.y != 0.0f ? size_arg.y : label_size.y);
7367 ImVec2 pos = window->DC.CursorPos;
7368 pos.y += window->DC.CurrLineTextBaseOffset;
7369 ItemSize(size, 0.0f);
7370
7371 // Fill horizontal space
7372 // We don't support (size < 0.0f) in Selectable() because the ItemSpacing extension would make explicitly right-aligned sizes not visibly match other widgets.
7373 const bool span_all_columns = (flags & ImGuiSelectableFlags_SpanAllColumns) != 0;
7374 const float min_x = span_all_columns ? window->ParentWorkRect.Min.x : pos.x;
7375 const float max_x = span_all_columns ? window->ParentWorkRect.Max.x : window->WorkRect.Max.x;
7376 if (size_arg.x == 0.0f || (flags & ImGuiSelectableFlags_SpanAvailWidth))
7377 size.x = ImMax(label_size.x, max_x - min_x);
7378
7379 // Selectables are meant to be tightly packed together with no click-gap, so we extend their box to cover spacing between selectable.
7380 // FIXME: Not part of layout so not included in clipper calculation, but ItemSize currently doesn't allow offsetting CursorPos.
7381 ImRect bb(min_x, pos.y, min_x + size.x, pos.y + size.y);
7382 if ((flags & ImGuiSelectableFlags_NoPadWithHalfSpacing) == 0)
7383 {
7384 const float spacing_x = span_all_columns ? 0.0f : style.ItemSpacing.x;
7385 const float spacing_y = style.ItemSpacing.y;
7386 const float spacing_L = IM_TRUNC(spacing_x * 0.50f);
7387 const float spacing_U = IM_TRUNC(spacing_y * 0.50f);
7388 bb.Min.x -= spacing_L;
7389 bb.Min.y -= spacing_U;
7390 bb.Max.x += (spacing_x - spacing_L);
7391 bb.Max.y += (spacing_y - spacing_U);
7392 }
7393 //if (g.IO.KeyCtrl) { GetForegroundDrawList()->AddRect(bb.Min, bb.Max, IM_COL32(0, 255, 0, 255)); }
7394
7395 const bool disabled_item = (flags & ImGuiSelectableFlags_Disabled) != 0;
7396 const ImGuiItemFlags extra_item_flags = disabled_item ? (ImGuiItemFlags)ImGuiItemFlags_Disabled : ImGuiItemFlags_None;
7397 bool is_visible;
7398 if (span_all_columns)
7399 {
7400 // Modify ClipRect for the ItemAdd(), faster than doing a PushColumnsBackground/PushTableBackgroundChannel for every Selectable..
7401 const float backup_clip_rect_min_x = window->ClipRect.Min.x;
7402 const float backup_clip_rect_max_x = window->ClipRect.Max.x;
7403 window->ClipRect.Min.x = window->ParentWorkRect.Min.x;
7404 window->ClipRect.Max.x = window->ParentWorkRect.Max.x;
7405 is_visible = ItemAdd(bb, id, NULL, extra_item_flags);
7406 window->ClipRect.Min.x = backup_clip_rect_min_x;
7407 window->ClipRect.Max.x = backup_clip_rect_max_x;
7408 }
7409 else
7410 {

Callers

nothing calls this directly

Calls 9

GetCurrentWindowFunction · 0.85
ItemSizeFunction · 0.85
ImMaxFunction · 0.85
WindowRectAbsToRelFunction · 0.85
ImVec2Function · 0.85
ImMinFunction · 0.85
GetForegroundDrawListFunction · 0.85
GetIDMethod · 0.80
AddTextMethod · 0.80

Tested by

no test coverage detected