mirror of
https://github.com/ocornut/imgui.git
synced 2026-09-10 07:55:55 +00:00
Added ImGuiItemFlags_MixedValue support for Drags, Sliders, InputScalar, InputText, RadioButton, Combo. (#5518, #5677, #6865)
This commit is contained in:
@@ -87,6 +87,7 @@ Index of this file:
|
||||
// [SECTION] DemoWindowWidgetsImages()
|
||||
// [SECTION] DemoWindowWidgetsListBoxes()
|
||||
// [SECTION] DemoWindowWidgetsLiveEdit()
|
||||
// [SECTION] DemoWindowWidgetsMixedValues()
|
||||
// [SECTION] DemoWindowWidgetsMultiComponents()
|
||||
// [SECTION] DemoWindowWidgetsPlotting()
|
||||
// [SECTION] DemoWindowWidgetsProgressBars()
|
||||
@@ -2020,7 +2021,7 @@ static void DemoWindowWidgetsLiveEdit(ImGuiDemoWindowData* demo_data)
|
||||
{
|
||||
if (ImGui::TreeNode("Live Edit Flags"))
|
||||
{
|
||||
IMGUI_DEMO_MARKER("Widgets/Live Edit Flgs");
|
||||
IMGUI_DEMO_MARKER("Widgets/Live Edit Flags");
|
||||
|
||||
ImGui::TextWrapped("Select whether to apply keyboard edits to backing variables _while_ typing.");
|
||||
|
||||
@@ -2050,6 +2051,59 @@ static void DemoWindowWidgetsLiveEdit(ImGuiDemoWindowData* demo_data)
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// [SECTION] DemoWindowWidgetsMixedValues()
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
static void DemoWindowWidgetsMixedValues()
|
||||
{
|
||||
if (ImGui::TreeNode("Mixed Values"))
|
||||
{
|
||||
// This is designed for advanced property editors which are generally reusable and data-driven.
|
||||
HelpMarker("Using ImGuiItemFlags_MixedValue.");
|
||||
|
||||
static float items[3] = { 12.0f, 0.0f, 0.0f };
|
||||
float* item_ref = &items[0];
|
||||
|
||||
ImGui::SeparatorText("Scalar/Text Widgets");
|
||||
const bool is_mixed = memcmp(&items[0], &items[1], sizeof(float)) != 0 || memcmp(&items[0], &items[2], sizeof(float)) != 0;
|
||||
|
||||
// Demonstrate Drags, Sliders, Inputs
|
||||
ImGui::PushItemFlag(ImGuiItemFlags_MixedValue, is_mixed);
|
||||
bool edited = false;
|
||||
edited |= ImGui::DragFloat("DragFloat", item_ref);
|
||||
edited |= ImGui::SliderFloat("SliderFloat", item_ref, 0.0f, 100.0f);
|
||||
edited |= ImGui::InputFloat("InputFloat", item_ref, 1.0f);
|
||||
if (edited)
|
||||
for (float& item : items)
|
||||
if (&item != item_ref)
|
||||
item = *item_ref;
|
||||
ImGui::PopItemFlag();
|
||||
|
||||
ImGui::Text("Underlying data:");
|
||||
ImGui::InputFloat("item 0 (ref)", &items[0]);
|
||||
ImGui::InputFloat("item 1", &items[1]);
|
||||
ImGui::InputFloat("item 2", &items[2]);
|
||||
|
||||
// Demonstrate Checkbox()
|
||||
// (this is automatically used by e.g. CheckboxFlags())
|
||||
ImGui::SeparatorText("Others Widgets");
|
||||
bool b_on = true, b_off = false;
|
||||
ImGui::Checkbox("Checkbox On", &b_on);
|
||||
ImGui::Checkbox("Checkbox Off", &b_off);
|
||||
ImGui::PushItemFlag(ImGuiItemFlags_MixedValue, true);
|
||||
ImGui::Checkbox("Checkbox Mixed", &b_off);
|
||||
ImGui::RadioButton("RadioButton Mixed", true);
|
||||
ImGui::SameLine();
|
||||
ImGui::RadioButton("RadioButton Mixed##2", true); // Showing 2 radio buttons makes the example more clear
|
||||
int combo_idx = 0;
|
||||
ImGui::Combo("Combo", &combo_idx, "One\0Two\0Three\0");
|
||||
ImGui::PopItemFlag();
|
||||
|
||||
ImGui::TreePop();
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// [SECTION] DemoWindowWidgetsMultiComponents()
|
||||
//-----------------------------------------------------------------------------
|
||||
@@ -2230,12 +2284,14 @@ static void DemoWindowWidgetsQueryingStatuses()
|
||||
};
|
||||
static int item_type = 4;
|
||||
static bool item_disabled = false;
|
||||
static bool item_mixedvalue = false;
|
||||
static bool liveedit_flags_override = false;
|
||||
static ImGuiItemFlags liveedit_flags = 0;
|
||||
ImGui::Combo("Item Type", &item_type, item_names, IM_COUNTOF(item_names), IM_COUNTOF(item_names));
|
||||
ImGui::SameLine();
|
||||
HelpMarker("Testing how various types of items are interacting with the IsItemXXX functions. Note that the bool return value of most ImGui function is generally equivalent to calling ImGui::IsItemHovered().");
|
||||
ImGui::Checkbox("Item Disabled", &item_disabled);
|
||||
ImGui::Checkbox("Item MixedValue", &item_mixedvalue);
|
||||
ImGui::Checkbox("Override LiveEdit:", &liveedit_flags_override);
|
||||
ImGui::SameLine();
|
||||
if (!liveedit_flags_override)
|
||||
@@ -2260,6 +2316,8 @@ static void DemoWindowWidgetsQueryingStatuses()
|
||||
static char str[16] = {};
|
||||
if (item_disabled)
|
||||
ImGui::BeginDisabled(true);
|
||||
if (item_mixedvalue)
|
||||
ImGui::PushItemFlag(ImGuiItemFlags_MixedValue, true);
|
||||
if (item_type == 0) { ImGui::Text("ITEM: Text"); } // Testing text items with no identifier/interaction
|
||||
if (item_type == 1) { ret = ImGui::Button("ITEM: Button"); } // Testing button
|
||||
if (item_type == 2) { ImGui::PushItemFlag(ImGuiItemFlags_ButtonRepeat, true); ret = ImGui::Button("ITEM: Button"); ImGui::PopItemFlag(); } // Testing button (with repeater)
|
||||
@@ -2343,6 +2401,8 @@ static void DemoWindowWidgetsQueryingStatuses()
|
||||
ImGui::PopItemFlag();
|
||||
ImGui::PopItemFlag();
|
||||
}
|
||||
if (item_mixedvalue)
|
||||
ImGui::PopItemFlag();
|
||||
if (item_disabled)
|
||||
ImGui::EndDisabled();
|
||||
|
||||
@@ -4505,6 +4565,7 @@ static void DemoWindowWidgets(ImGuiDemoWindowData* demo_data)
|
||||
DemoWindowWidgetsImages();
|
||||
DemoWindowWidgetsListBoxes();
|
||||
DemoWindowWidgetsLiveEdit(demo_data);
|
||||
DemoWindowWidgetsMixedValues();
|
||||
DemoWindowWidgetsMultiComponents();
|
||||
DemoWindowWidgetsPlotting();
|
||||
DemoWindowWidgetsProgressBars();
|
||||
|
||||
Reference in New Issue
Block a user