Demo: better showcase use of SetNextItemAllowOverlap(). (#6574, #6512, #3909, #517)

+ Merge some shallow changes from range-select branch.
This commit is contained in:
ocornut 2023-07-05 14:19:01 +02:00
parent 3fe4319314
commit 9a15730c2a
2 changed files with 48 additions and 14 deletions

View File

@ -38,6 +38,8 @@ Breaking changes:
Other changes: Other changes:
- Demo: Better showcase use of SetNextItemAllowOverlap(). (#6574, #6512, #3909, #517)
----------------------------------------------------------------------- -----------------------------------------------------------------------
VERSION 1.89.7 (Released 2023-07-04) VERSION 1.89.7 (Released 2023-07-04)

View File

@ -1262,16 +1262,16 @@ static void ShowDemoWindowWidgets()
IMGUI_DEMO_MARKER("Widgets/Selectables/Basic"); IMGUI_DEMO_MARKER("Widgets/Selectables/Basic");
if (ImGui::TreeNode("Basic")) if (ImGui::TreeNode("Basic"))
{ {
static bool selection[5] = { false, true, false, false, false }; static bool selection[5] = { false, true, false, false };
ImGui::Selectable("1. I am selectable", &selection[0]); ImGui::Selectable("1. I am selectable", &selection[0]);
ImGui::Selectable("2. I am selectable", &selection[1]); ImGui::Selectable("2. I am selectable", &selection[1]);
ImGui::Text("(I am not selectable)"); ImGui::Selectable("3. I am selectable", &selection[2]);
ImGui::Selectable("4. I am selectable", &selection[3]); if (ImGui::Selectable("4. I am double clickable", selection[3], ImGuiSelectableFlags_AllowDoubleClick))
if (ImGui::Selectable("5. I am double clickable", selection[4], ImGuiSelectableFlags_AllowDoubleClick))
if (ImGui::IsMouseDoubleClicked(0)) if (ImGui::IsMouseDoubleClicked(0))
selection[4] = !selection[4]; selection[3] = !selection[3];
ImGui::TreePop(); ImGui::TreePop();
} }
IMGUI_DEMO_MARKER("Widgets/Selectables/Single Selection"); IMGUI_DEMO_MARKER("Widgets/Selectables/Single Selection");
if (ImGui::TreeNode("Selection State: Single Selection")) if (ImGui::TreeNode("Selection State: Single Selection"))
{ {
@ -1303,17 +1303,18 @@ static void ShowDemoWindowWidgets()
} }
ImGui::TreePop(); ImGui::TreePop();
} }
IMGUI_DEMO_MARKER("Widgets/Selectables/Rendering more text into the same line"); IMGUI_DEMO_MARKER("Widgets/Selectables/Rendering more items on the same line");
if (ImGui::TreeNode("Rendering more text into the same line")) if (ImGui::TreeNode("Rendering more items on the same line"))
{ {
// Using the Selectable() override that takes "bool* p_selected" parameter, // (1) Using SetNextItemAllowOverlap()
// this function toggle your bool value automatically. // (2) Using the Selectable() override that takes "bool* p_selected" parameter, the bool value is toggled 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::SetNextItemAllowOverlap(); ImGui::Selectable("main.c", &selected[0]); ImGui::SameLine(); ImGui::SmallButton("Link 1");
ImGui::Selectable("Hello.cpp", &selected[1]); ImGui::SameLine(300); ImGui::Text("12,345 bytes"); ImGui::SetNextItemAllowOverlap(); ImGui::Selectable("Hello.cpp", &selected[1]); ImGui::SameLine(); ImGui::SmallButton("Link 2");
ImGui::Selectable("Hello.h", &selected[2]); ImGui::SameLine(300); ImGui::Text(" 2,345 bytes"); ImGui::SetNextItemAllowOverlap(); ImGui::Selectable("Hello.h", &selected[2]); ImGui::SameLine(); ImGui::SmallButton("Link 3");
ImGui::TreePop(); ImGui::TreePop();
} }
IMGUI_DEMO_MARKER("Widgets/Selectables/In columns"); IMGUI_DEMO_MARKER("Widgets/Selectables/In columns");
if (ImGui::TreeNode("In columns")) if (ImGui::TreeNode("In columns"))
{ {
@ -1349,6 +1350,7 @@ static void ShowDemoWindowWidgets()
} }
ImGui::TreePop(); ImGui::TreePop();
} }
IMGUI_DEMO_MARKER("Widgets/Selectables/Grid"); IMGUI_DEMO_MARKER("Widgets/Selectables/Grid");
if (ImGui::TreeNode("Grid")) if (ImGui::TreeNode("Grid"))
{ {
@ -2795,11 +2797,11 @@ static void ShowDemoWindowLayout()
// Text // Text
IMGUI_DEMO_MARKER("Layout/Basic Horizontal Layout/SameLine"); IMGUI_DEMO_MARKER("Layout/Basic Horizontal Layout/SameLine");
ImGui::Text("Two items: Hello"); ImGui::SameLine(); ImGui::Text("Two items: Hello"); ImGui::SameLine();
ImGui::TextColored(ImVec4(1,1,0,1), "Sailor"); ImGui::TextColored(ImVec4(1, 1, 0, 1), "Sailor");
// Adjust spacing // Adjust spacing
ImGui::Text("More spacing: Hello"); ImGui::SameLine(0, 20); ImGui::Text("More spacing: Hello"); ImGui::SameLine(0, 20);
ImGui::TextColored(ImVec4(1,1,0,1), "Sailor"); ImGui::TextColored(ImVec4(1, 1, 0, 1), "Sailor");
// Button // Button
ImGui::AlignTextToFramePadding(); ImGui::AlignTextToFramePadding();
@ -3397,6 +3399,36 @@ static void ShowDemoWindowLayout()
ImGui::TreePop(); ImGui::TreePop();
} }
IMGUI_DEMO_MARKER("Layout/Overlap Mode");
if (ImGui::TreeNode("Overlap Mode"))
{
static bool enable_allow_overlap = true;
HelpMarker(
"Hit-testing is by default performed in item submission order, which generally is perceived as 'back-to-front'.\n\n"
"By using SetNextItemAllowOverlap() you can notify that an item may be overlapped by another. Doing so alters the hovering logic: items using AllowOverlap mode requires an extra frame to accept hovered state.");
ImGui::Checkbox("Enable AllowOverlap", &enable_allow_overlap);
ImVec2 button1_pos = ImGui::GetCursorScreenPos();
ImVec2 button2_pos = ImVec2(button1_pos.x + 50.0f, button1_pos.y + 50.0f);
if (enable_allow_overlap)
ImGui::SetNextItemAllowOverlap();
ImGui::Button("Button 1", ImVec2(80, 80));
ImGui::SetCursorScreenPos(button2_pos);
ImGui::Button("Button 2", ImVec2(80, 80));
// This is typically used with width-spanning items.
// (note that Selectable() has a dedicated flag ImGuiSelectableFlags_AllowOverlap, which is a shortcut
// for using SetNextItemAllowOverlap(). For demo purpose we use SetNextItemAllowOverlap() here.)
if (enable_allow_overlap)
ImGui::SetNextItemAllowOverlap();
ImGui::Selectable("Some Selectable", false);
ImGui::SameLine();
ImGui::SmallButton("++");
ImGui::TreePop();
}
} }
static void ShowDemoWindowPopups() static void ShowDemoWindowPopups()