mirror of
https://github.com/ocornut/imgui.git
synced 2024-11-28 01:20:55 +01:00
Combo: simplified Combo() API uses a list clipper.
Wasn't as trivial before supporting IncludeItemByIndex().
This commit is contained in:
parent
51823d117d
commit
109a8632d7
@ -47,6 +47,8 @@ Other changes:
|
|||||||
responsible for honoring io.ConfigWindowsMoveFromTitleBarOnly. (#7576, #899)
|
responsible for honoring io.ConfigWindowsMoveFromTitleBarOnly. (#7576, #899)
|
||||||
- Scrollbar: made scrolling logic more standard: clicking above or below the
|
- Scrollbar: made scrolling logic more standard: clicking above or below the
|
||||||
grab scrolls by one page, holding mouse button repeats scrolling. (#7328, #150)
|
grab scrolls by one page, holding mouse button repeats scrolling. (#7328, #150)
|
||||||
|
- Combo: simplified Combo() API uses a list clipper (due to its api it wasn't
|
||||||
|
previously trivial before we added clipper.IncludeItemByIndex() function).
|
||||||
- Misc: made ImGuiDir and ImGuiSortDirection stronger-typed enums.
|
- Misc: made ImGuiDir and ImGuiSortDirection stronger-typed enums.
|
||||||
|
|
||||||
|
|
||||||
|
@ -151,7 +151,6 @@ It's mostly a bunch of personal notes, probably incomplete. Feel free to query i
|
|||||||
- drag float: added leeway on edge (e.g. a few invisible steps past the clamp limits)
|
- drag float: added leeway on edge (e.g. a few invisible steps past the clamp limits)
|
||||||
|
|
||||||
- combo: a way/helper to customize the combo preview (#1658) -> experimental BeginComboPreview()
|
- combo: a way/helper to customize the combo preview (#1658) -> experimental BeginComboPreview()
|
||||||
- combo: Combo() helper could use clipper.
|
|
||||||
- combo/listbox: keyboard control. need InputText-like non-active focus + key handling. considering keyboard for custom listbox (pr #203)
|
- combo/listbox: keyboard control. need InputText-like non-active focus + key handling. considering keyboard for custom listbox (pr #203)
|
||||||
- listbox: multiple selection (WIP range-select branch)
|
- listbox: multiple selection (WIP range-select branch)
|
||||||
- listbox: unselect option (#1208)
|
- listbox: unselect option (#1208)
|
||||||
|
@ -1952,28 +1952,30 @@ bool ImGui::Combo(const char* label, int* current_item, const char* (*getter)(vo
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Display items
|
// Display items
|
||||||
// FIXME-OPT: Use clipper (but we need to disable it on the appearing frame to make sure our call to SetItemDefaultFocus() is processed)
|
|
||||||
bool value_changed = false;
|
bool value_changed = false;
|
||||||
for (int i = 0; i < items_count; i++)
|
ImGuiListClipper clipper;
|
||||||
{
|
clipper.Begin(items_count);
|
||||||
const char* item_text = getter(user_data, i);
|
clipper.IncludeItemByIndex(*current_item);
|
||||||
if (item_text == NULL)
|
while (clipper.Step())
|
||||||
item_text = "*Unknown item*";
|
for (int i = clipper.DisplayStart; i < clipper.DisplayEnd; i++)
|
||||||
|
|
||||||
PushID(i);
|
|
||||||
const bool item_selected = (i == *current_item);
|
|
||||||
if (Selectable(item_text, item_selected) && *current_item != i)
|
|
||||||
{
|
{
|
||||||
value_changed = true;
|
const char* item_text = getter(user_data, i);
|
||||||
*current_item = i;
|
if (item_text == NULL)
|
||||||
|
item_text = "*Unknown item*";
|
||||||
|
|
||||||
|
PushID(i);
|
||||||
|
const bool item_selected = (i == *current_item);
|
||||||
|
if (Selectable(item_text, item_selected) && *current_item != i)
|
||||||
|
{
|
||||||
|
value_changed = true;
|
||||||
|
*current_item = i;
|
||||||
|
}
|
||||||
|
if (item_selected)
|
||||||
|
SetItemDefaultFocus();
|
||||||
|
PopID();
|
||||||
}
|
}
|
||||||
if (item_selected)
|
|
||||||
SetItemDefaultFocus();
|
|
||||||
PopID();
|
|
||||||
}
|
|
||||||
|
|
||||||
EndCombo();
|
EndCombo();
|
||||||
|
|
||||||
if (value_changed)
|
if (value_changed)
|
||||||
MarkItemEdited(g.LastItemData.ID);
|
MarkItemEdited(g.LastItemData.ID);
|
||||||
|
|
||||||
@ -7011,6 +7013,7 @@ bool ImGui::ListBox(const char* label, int* current_item, const char* (*getter)(
|
|||||||
bool value_changed = false;
|
bool value_changed = false;
|
||||||
ImGuiListClipper clipper;
|
ImGuiListClipper clipper;
|
||||||
clipper.Begin(items_count, GetTextLineHeightWithSpacing()); // We know exactly our line height here so we pass it as a minor optimization, but generally you don't need to.
|
clipper.Begin(items_count, GetTextLineHeightWithSpacing()); // We know exactly our line height here so we pass it as a minor optimization, but generally you don't need to.
|
||||||
|
clipper.IncludeItemByIndex(*current_item);
|
||||||
while (clipper.Step())
|
while (clipper.Step())
|
||||||
for (int i = clipper.DisplayStart; i < clipper.DisplayEnd; i++)
|
for (int i = clipper.DisplayStart; i < clipper.DisplayEnd; i++)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user