|
@@ -609,24 +609,58 @@ void ImGui::ShowDemoWindow(bool* p_open)
|
|
|
|
|
|
if (ImGui::TreeNode("Selectables"))
|
|
if (ImGui::TreeNode("Selectables"))
|
|
{
|
|
{
|
|
|
|
+ // Selectable() has 2 overloads:
|
|
|
|
+ // - The one taking "bool selected" as a read-only selection information. When Selectable() has been clicked is returns true and you can alter selection state accordingly.
|
|
|
|
+ // - The one taking "bool* p_selected" as a read-write selection information (convenient in some cases)
|
|
|
|
+ // The earlier is more flexible, as in real application your selection may be stored in a different manner (in flags within objects, as an external list, etc).
|
|
if (ImGui::TreeNode("Basic"))
|
|
if (ImGui::TreeNode("Basic"))
|
|
{
|
|
{
|
|
- static bool selected[4] = { false, true, false, false };
|
|
|
|
- ImGui::Selectable("1. I am selectable", &selected[0]);
|
|
|
|
- ImGui::Selectable("2. I am selectable", &selected[1]);
|
|
|
|
|
|
+ static bool selection[5] = { false, true, false, false, false };
|
|
|
|
+ ImGui::Selectable("1. I am selectable", &selection[0]);
|
|
|
|
+ ImGui::Selectable("2. I am selectable", &selection[1]);
|
|
ImGui::Text("3. I am not selectable");
|
|
ImGui::Text("3. I am not selectable");
|
|
- ImGui::Selectable("4. I am selectable", &selected[2]);
|
|
|
|
- if (ImGui::Selectable("5. I am double clickable", selected[3], ImGuiSelectableFlags_AllowDoubleClick))
|
|
|
|
|
|
+ ImGui::Selectable("4. I am selectable", &selection[3]);
|
|
|
|
+ if (ImGui::Selectable("5. I am double clickable", selection[4], ImGuiSelectableFlags_AllowDoubleClick))
|
|
if (ImGui::IsMouseDoubleClicked(0))
|
|
if (ImGui::IsMouseDoubleClicked(0))
|
|
- selected[3] = !selected[3];
|
|
|
|
|
|
+ selection[4] = !selection[4];
|
|
ImGui::TreePop();
|
|
ImGui::TreePop();
|
|
}
|
|
}
|
|
- if (ImGui::TreeNode("Rendering more text into the same block"))
|
|
|
|
|
|
+ if (ImGui::TreeNode("Selection State: Single Selection"))
|
|
{
|
|
{
|
|
|
|
+ static int selected = -1;
|
|
|
|
+ for (int n = 0; n < 5; n++)
|
|
|
|
+ {
|
|
|
|
+ char buf[32];
|
|
|
|
+ sprintf(buf, "Object %d", n);
|
|
|
|
+ if (ImGui::Selectable(buf, selected == n))
|
|
|
|
+ selected = n;
|
|
|
|
+ }
|
|
|
|
+ ImGui::TreePop();
|
|
|
|
+ }
|
|
|
|
+ if (ImGui::TreeNode("Selection State: Multiple Selection"))
|
|
|
|
+ {
|
|
|
|
+ ShowHelpMarker("Hold CTRL and click to select multiple items.");
|
|
|
|
+ static bool selection[5] = { false, false, false, false, false };
|
|
|
|
+ for (int n = 0; n < 5; n++)
|
|
|
|
+ {
|
|
|
|
+ char buf[32];
|
|
|
|
+ sprintf(buf, "Object %d", n);
|
|
|
|
+ if (ImGui::Selectable(buf, selection[n]))
|
|
|
|
+ {
|
|
|
|
+ if (!ImGui::GetIO().KeyCtrl) // Clear selection when CTRL is not held
|
|
|
|
+ memset(selection, 0, sizeof(selection));
|
|
|
|
+ selection[n] ^= 1;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ ImGui::TreePop();
|
|
|
|
+ }
|
|
|
|
+ if (ImGui::TreeNode("Rendering more text into the same line"))
|
|
|
|
+ {
|
|
|
|
+ // Using the Selectable() override that takes "bool* p_selected" parameter and toggle your booleans automatically.
|
|
static bool selected[3] = { false, false, false };
|
|
static bool selected[3] = { false, false, false };
|
|
- ImGui::Selectable("main.c", &selected[0]); ImGui::SameLine(300); ImGui::Text(" 2,345 bytes");
|
|
|
|
|
|
+ ImGui::Selectable("main.c", &selected[0]); ImGui::SameLine(300); ImGui::Text(" 2,345 bytes");
|
|
ImGui::Selectable("Hello.cpp", &selected[1]); ImGui::SameLine(300); ImGui::Text("12,345 bytes");
|
|
ImGui::Selectable("Hello.cpp", &selected[1]); ImGui::SameLine(300); ImGui::Text("12,345 bytes");
|
|
- ImGui::Selectable("Hello.h", &selected[2]); ImGui::SameLine(300); ImGui::Text(" 2,345 bytes");
|
|
|
|
|
|
+ ImGui::Selectable("Hello.h", &selected[2]); ImGui::SameLine(300); ImGui::Text(" 2,345 bytes");
|
|
ImGui::TreePop();
|
|
ImGui::TreePop();
|
|
}
|
|
}
|
|
if (ImGui::TreeNode("In columns"))
|
|
if (ImGui::TreeNode("In columns"))
|