MCPcopy Create free account
hub / github.com/crossuo/crossuo / ListBox

Function ListBox

tools/xuoi/widgets.cpp:84–132  ·  view source on GitHub ↗

copied from imgui_widgets

Source from the content-addressed store, hash-verified

82
83// copied from imgui_widgets
84bool ListBox(
85 const char *label,
86 int *current_item,
87 bool (*items_getter)(void *, int, const char **),
88 void *data,
89 int items_count,
90 int height_in_items,
91 ListBoxItemCallback callback)
92{
93 if (!ImGui::ListBoxHeader(label, items_count, height_in_items))
94 return false;
95
96 ImGuiSelectableFlags flags = 0;
97 if (callback)
98 {
99 flags = ImGuiSelectableFlags_AllowDoubleClick;
100 }
101
102 // Assume all items have even height (= 1 line of text). If you need items of different or variable sizes you can create a custom version of ListBox() in your code without using the clipper.
103 bool value_changed = false;
104 ImGuiListClipper clipper(
105 items_count,
106 ImGui::
107 GetTextLineHeightWithSpacing()); // We know exactly our line height here so we pass it as a minor optimization, but generally you don't need to.
108 while (clipper.Step())
109 for (int i = clipper.DisplayStart; i < clipper.DisplayEnd; i++)
110 {
111 const bool item_selected = (i == *current_item);
112 const char *item_text;
113 if (!items_getter(data, i, &item_text))
114 item_text = "*Unknown item*";
115
116 ImGui::PushID(i);
117 if (ImGui::Selectable(item_text, item_selected, flags))
118 {
119 *current_item = i;
120 value_changed = true;
121 if (callback && ImGui::IsMouseDoubleClicked(0))
122 {
123 callback(i);
124 }
125 }
126 if (item_selected)
127 ImGui::SetItemDefaultFocus();
128 ImGui::PopID();
129 }
130 ImGui::ListBoxFooter();
131 return value_changed;
132}
133
134bool DialogYesNo(const char *title, const char *msg, bool &open)
135{

Callers 5

ui_accountsFunction · 0.85
ui_backupsFunction · 0.85
ListBoxMethod · 0.85
ShowDemoWindowWidgetsFunction · 0.85
ShowDemoWindowLayoutFunction · 0.85

Calls 2

callbackClass · 0.50
StepMethod · 0.45

Tested by

no test coverage detected