Tip: To have a list filling the entire window width, use size.x = -FLT_MIN and pass an non-visible label e.g. "##empty" Tip: If your vertical size is calculated from an item count (e.g. 10 * item_height) consider adding a fractional part to facilitate seeing scrolling boundaries (e.g. 10.25 * item_height).
| 6347 | // Tip: To have a list filling the entire window width, use size.x = -FLT_MIN and pass an non-visible label e.g. "##empty" |
| 6348 | // Tip: If your vertical size is calculated from an item count (e.g. 10 * item_height) consider adding a fractional part to facilitate seeing scrolling boundaries (e.g. 10.25 * item_height). |
| 6349 | bool ImGui::BeginListBox(const char* label, const ImVec2& size_arg) |
| 6350 | { |
| 6351 | ImGuiContext& g = *GImGui; |
| 6352 | ImGuiWindow* window = GetCurrentWindow(); |
| 6353 | if (window->SkipItems) |
| 6354 | return false; |
| 6355 | |
| 6356 | const ImGuiStyle& style = g.Style; |
| 6357 | const ImGuiID id = GetID(label); |
| 6358 | const ImVec2 label_size = CalcTextSize(label, NULL, true); |
| 6359 | |
| 6360 | // Size default to hold ~7.25 items. |
| 6361 | // Fractional number of items helps seeing that we can scroll down/up without looking at scrollbar. |
| 6362 | ImVec2 size = ImFloor(CalcItemSize(size_arg, CalcItemWidth(), GetTextLineHeightWithSpacing() * 7.25f + style.FramePadding.y * 2.0f)); |
| 6363 | ImVec2 frame_size = ImVec2(size.x, ImMax(size.y, label_size.y)); |
| 6364 | ImRect frame_bb(window->DC.CursorPos, window->DC.CursorPos + frame_size); |
| 6365 | ImRect bb(frame_bb.Min, frame_bb.Max + ImVec2(label_size.x > 0.0f ? style.ItemInnerSpacing.x + label_size.x : 0.0f, 0.0f)); |
| 6366 | g.NextItemData.ClearFlags(); |
| 6367 | |
| 6368 | if (!IsRectVisible(bb.Min, bb.Max)) |
| 6369 | { |
| 6370 | ItemSize(bb.GetSize(), style.FramePadding.y); |
| 6371 | ItemAdd(bb, 0, &frame_bb); |
| 6372 | return false; |
| 6373 | } |
| 6374 | |
| 6375 | // FIXME-OPT: We could omit the BeginGroup() if label_size.x but would need to omit the EndGroup() as well. |
| 6376 | BeginGroup(); |
| 6377 | if (label_size.x > 0.0f) |
| 6378 | { |
| 6379 | ImVec2 label_pos = ImVec2(frame_bb.Max.x + style.ItemInnerSpacing.x, frame_bb.Min.y + style.FramePadding.y); |
| 6380 | RenderText(label_pos, label); |
| 6381 | window->DC.CursorMaxPos = ImMax(window->DC.CursorMaxPos, label_pos + label_size); |
| 6382 | } |
| 6383 | |
| 6384 | BeginChildFrame(id, frame_bb.GetSize()); |
| 6385 | return true; |
| 6386 | } |
| 6387 | |
| 6388 | #ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS |
| 6389 | // OBSOLETED in 1.81 (from February 2021) |
nothing calls this directly
no test coverage detected