SliderRange2: Add ImGuiSliderFlags_Range for SliderFloat2/Int2

Alternative API: SliderFloat2(label, v, min, max, fmt, ImGuiSliderFlags_Range)
renders as a range slider instead of two separate sliders.

This minimizes API surface by reusing existing SliderScalarN functions.
This commit is contained in:
Entrpi 2026-01-13 01:21:12 +11:00
parent 94d0184527
commit 5487b0872e
3 changed files with 14 additions and 1 deletions

View file

@ -1932,6 +1932,7 @@ enum ImGuiSliderFlags_
ImGuiSliderFlags_ClampZeroRange = 1 << 10, // Clamp even if min==max==0.0f. Otherwise due to legacy reason DragXXX functions don't clamp with those values. When your clamping limits are dynamic you almost always want to use it.
ImGuiSliderFlags_NoSpeedTweaks = 1 << 11, // Disable keyboard modifiers altering tweak speed. Useful if you want to alter tweak speed yourself based on your own logic.
ImGuiSliderFlags_ColorMarkers = 1 << 12, // DragScalarN(), SliderScalarN(): Draw R/G/B/A color markers on each component.
ImGuiSliderFlags_Range = 1 << 13, // SliderScalarN() with 2 components: Render as a range slider instead of two separate sliders. v[0] is min, v[1] is max.
ImGuiSliderFlags_AlwaysClamp = ImGuiSliderFlags_ClampOnInput | ImGuiSliderFlags_ClampZeroRange,
ImGuiSliderFlags_InvalidMask_ = 0x7000000F, // [Internal] We treat using those bits as being potentially a 'float power' argument from legacy API (obsoleted 2020-08) that has got miscast to this enum, and will trigger an assert if needed.
};

View file

@ -981,7 +981,10 @@ static void DemoWindowWidgetsBasic()
ImGui::SliderFloatRange2("range float", &fmin, &fmax, 0.0f, 1.0f);
ImGui::SliderFloatRange2("range (size)", &fmin, &fmax, 0.0f, 1.0f, "%.2f...%.2f (%.2f)");
ImGui::SliderIntRange2("range int", &imin, &imax, 0, 100);
ImGui::SameLine(); HelpMarker("Click and drag handles individually, or drag the bar between them to move both.\nCtrl+Click to input values. Use \"...\" or \" - \" as separator to set both.");
// Alternative: use SliderFloat2 with ImGuiSliderFlags_Range
static float range_arr[2] = { 0.25f, 0.75f };
ImGui::SliderFloat2("range (flag)", range_arr, 0.0f, 1.0f, "%.3f", ImGuiSliderFlags_Range);
ImGui::SameLine(); HelpMarker("Click and drag handles individually, or drag the bar between them to move both.\nCtrl+Click to input values. Use \"...\" or \" - \" as separator to set both.\n\nRange sliders can also be created with SliderFloat2(..., ImGuiSliderFlags_Range).");
}
ImGui::SeparatorText("Selectors/Pickers");

View file

@ -3390,6 +3390,15 @@ bool ImGui::SliderScalarN(const char* label, ImGuiDataType data_type, void* v, i
if (window->SkipItems)
return false;
// Range slider mode: render 2 components as a single range slider
if (components == 2 && (flags & ImGuiSliderFlags_Range))
{
size_t type_size = GDataTypeInfo[data_type].Size;
void* v0 = v;
void* v1 = (void*)((char*)v + type_size);
return SliderScalarRange2(label, data_type, v0, v1, v_min, v_max, format, flags & ~ImGuiSliderFlags_Range);
}
ImGuiContext& g = *GImGui;
bool value_changed = false;
BeginGroup();