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).
| 6604 | // Tip: To have a list filling the entire window width, use size.x = -FLT_MIN and pass an non-visible label e.g. "##empty" |
| 6605 | // 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). |
| 6606 | bool ImGui::BeginListBox(const char* label, const ImVec2& size_arg) |
| 6607 | { |
| 6608 | ImGuiContext& g = *GImGui; |
| 6609 | ImGuiWindow* window = GetCurrentWindow(); |
| 6610 | if (window->SkipItems) |
| 6611 | return false; |
| 6612 | |
| 6613 | const ImGuiStyle& style = g.Style; |
| 6614 | const ImGuiID id = GetID(label); |
| 6615 | const ImVec2 label_size = CalcTextSize(label, NULL, true); |
| 6616 | |
| 6617 | // Size default to hold ~7.25 items. |
| 6618 | // Fractional number of items helps seeing that we can scroll down/up without looking at scrollbar. |
| 6619 | ImVec2 size = ImFloor(CalcItemSize(size_arg, CalcItemWidth(), GetTextLineHeightWithSpacing() * 7.25f + style.FramePadding.y * 2.0f)); |
| 6620 | ImVec2 frame_size = ImVec2(size.x, ImMax(size.y, label_size.y)); |
| 6621 | ImRect frame_bb(window->DC.CursorPos, window->DC.CursorPos + frame_size); |
| 6622 | ImRect bb(frame_bb.Min, frame_bb.Max + ImVec2(label_size.x > 0.0f ? style.ItemInnerSpacing.x + label_size.x : 0.0f, 0.0f)); |
| 6623 | g.NextItemData.ClearFlags(); |
| 6624 | |
| 6625 | if (!IsRectVisible(bb.Min, bb.Max)) |
| 6626 | { |
| 6627 | ItemSize(bb.GetSize(), style.FramePadding.y); |
| 6628 | ItemAdd(bb, 0, &frame_bb); |
| 6629 | return false; |
| 6630 | } |
| 6631 | |
| 6632 | // FIXME-OPT: We could omit the BeginGroup() if label_size.x but would need to omit the EndGroup() as well. |
| 6633 | BeginGroup(); |
| 6634 | if (label_size.x > 0.0f) |
| 6635 | { |
| 6636 | ImVec2 label_pos = ImVec2(frame_bb.Max.x + style.ItemInnerSpacing.x, frame_bb.Min.y + style.FramePadding.y); |
| 6637 | RenderText(label_pos, label); |
| 6638 | window->DC.CursorMaxPos = ImMax(window->DC.CursorMaxPos, label_pos + label_size); |
| 6639 | } |
| 6640 | |
| 6641 | BeginChildFrame(id, frame_bb.GetSize()); |
| 6642 | return true; |
| 6643 | } |
| 6644 | |
| 6645 | void ImGui::EndListBox() |
| 6646 | { |
nothing calls this directly
no test coverage detected