MCPcopy Create free account
hub / github.com/KebsCS/KBotExt / Selectable

Method Selectable

KBotExt/imgui/imgui_widgets.cpp:6444–6584  ·  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

6442// With this scheme, ImGuiSelectableFlags_SpanAllColumns and ImGuiSelectableFlags_AllowOverlap are also frequently used flags.
6443// FIXME: Selectable() with (size.x == 0.0f) and (SelectableTextAlign.x > 0.0f) followed by SameLine() is currently not supported.
6444bool ImGui::Selectable(const char* label, bool selected, ImGuiSelectableFlags flags, const ImVec2& size_arg)
6445{
6446 ImGuiWindow* window = GetCurrentWindow();
6447 if (window->SkipItems)
6448 return false;
6449
6450 ImGuiContext& g = *GImGui;
6451 const ImGuiStyle& style = g.Style;
6452
6453 // Submit label or explicit size to ItemSize(), whereas ItemAdd() will submit a larger/spanning rectangle.
6454 ImGuiID id = window->GetID(label);
6455 ImVec2 label_size = CalcTextSize(label, NULL, true);
6456 ImVec2 size(size_arg.x != 0.0f ? size_arg.x : label_size.x, size_arg.y != 0.0f ? size_arg.y : label_size.y);
6457 ImVec2 pos = window->DC.CursorPos;
6458 pos.y += window->DC.CurrLineTextBaseOffset;
6459 ItemSize(size, 0.0f);
6460
6461 // Fill horizontal space
6462 // We don't support (size < 0.0f) in Selectable() because the ItemSpacing extension would make explicitly right-aligned sizes not visibly match other widgets.
6463 const bool span_all_columns = (flags & ImGuiSelectableFlags_SpanAllColumns) != 0;
6464 const float min_x = span_all_columns ? window->ParentWorkRect.Min.x : pos.x;
6465 const float max_x = span_all_columns ? window->ParentWorkRect.Max.x : window->WorkRect.Max.x;
6466 if (size_arg.x == 0.0f || (flags & ImGuiSelectableFlags_SpanAvailWidth))
6467 size.x = ImMax(label_size.x, max_x - min_x);
6468
6469 // Text stays at the submission position, but bounding box may be extended on both sides
6470 const ImVec2 text_min = pos;
6471 const ImVec2 text_max(min_x + size.x, pos.y + size.y);
6472
6473 // Selectables are meant to be tightly packed together with no click-gap, so we extend their box to cover spacing between selectable.
6474 ImRect bb(min_x, pos.y, text_max.x, text_max.y);
6475 if ((flags & ImGuiSelectableFlags_NoPadWithHalfSpacing) == 0)
6476 {
6477 const float spacing_x = span_all_columns ? 0.0f : style.ItemSpacing.x;
6478 const float spacing_y = style.ItemSpacing.y;
6479 const float spacing_L = IM_FLOOR(spacing_x * 0.50f);
6480 const float spacing_U = IM_FLOOR(spacing_y * 0.50f);
6481 bb.Min.x -= spacing_L;
6482 bb.Min.y -= spacing_U;
6483 bb.Max.x += (spacing_x - spacing_L);
6484 bb.Max.y += (spacing_y - spacing_U);
6485 }
6486 //if (g.IO.KeyCtrl) { GetForegroundDrawList()->AddRect(bb.Min, bb.Max, IM_COL32(0, 255, 0, 255)); }
6487
6488 // Modify ClipRect for the ItemAdd(), faster than doing a PushColumnsBackground/PushTableBackground for every Selectable..
6489 const float backup_clip_rect_min_x = window->ClipRect.Min.x;
6490 const float backup_clip_rect_max_x = window->ClipRect.Max.x;
6491 if (span_all_columns)
6492 {
6493 window->ClipRect.Min.x = window->ParentWorkRect.Min.x;
6494 window->ClipRect.Max.x = window->ParentWorkRect.Max.x;
6495 }
6496
6497 const bool disabled_item = (flags & ImGuiSelectableFlags_Disabled) != 0;
6498 const bool item_add = ItemAdd(bb, id, NULL, disabled_item ? ImGuiItemFlags_Disabled : ImGuiItemFlags_None);
6499 if (span_all_columns)
6500 {
6501 window->ClipRect.Min.x = backup_clip_rect_min_x;

Callers

nothing calls this directly

Calls 5

GetCurrentWindowFunction · 0.85
ItemSizeFunction · 0.85
ImMaxFunction · 0.85
WindowRectAbsToRelFunction · 0.85
GetIDMethod · 0.80

Tested by

no test coverage detected