Skip to content

Commit d2ddb97

Browse files
committed
Widgets: Added SliderFloatRange2(), SliderIntRange2() for range selection. (#76)
- Two-handle slider for selecting a min/max range - Middle bar dragging to move both handles together while maintaining range - Hover highlighting to show which handle will be selected on click - Ctrl+Click text input with "XXX...YYYY" parsing to set both values - Per-handle format strings for different precision on each handle - Optional step parameter for snapping
1 parent f538454 commit d2ddb97

File tree

4 files changed

+551
-0
lines changed

4 files changed

+551
-0
lines changed

imgui.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -704,6 +704,9 @@ namespace ImGui
704704
IMGUI_API bool SliderInt4(const char* label, int v[4], int v_min, int v_max, const char* format = "%d", ImGuiSliderFlags flags = 0);
705705
IMGUI_API bool SliderScalar(const char* label, ImGuiDataType data_type, void* p_data, const void* p_min, const void* p_max, const char* format = NULL, ImGuiSliderFlags flags = 0);
706706
IMGUI_API bool SliderScalarN(const char* label, ImGuiDataType data_type, void* p_data, int components, const void* p_min, const void* p_max, const char* format = NULL, ImGuiSliderFlags flags = 0);
707+
IMGUI_API bool SliderScalarRange2(const char* label, ImGuiDataType data_type, void* p_v_min, void* p_v_max, const void* p_min, const void* p_max, const char* format = NULL, const char* format_max = NULL, ImGuiSliderFlags flags = 0, const void* p_step = NULL);
708+
IMGUI_API bool SliderFloatRange2(const char* label, float* v_current_min, float* v_current_max, float v_min = 0.0f, float v_max = 1.0f, const char* format = "%.3f", const char* format_max = NULL, ImGuiSliderFlags flags = 0, float step = 0.0f);
709+
IMGUI_API bool SliderIntRange2(const char* label, int* v_current_min, int* v_current_max, int v_min = 0, int v_max = 100, const char* format = "%d", const char* format_max = NULL, ImGuiSliderFlags flags = 0, int step = 0);
707710
IMGUI_API bool VSliderFloat(const char* label, const ImVec2& size, float* v, float v_min, float v_max, const char* format = "%.3f", ImGuiSliderFlags flags = 0);
708711
IMGUI_API bool VSliderInt(const char* label, const ImVec2& size, int* v, int v_min, int v_max, const char* format = "%d", ImGuiSliderFlags flags = 0);
709712
IMGUI_API bool VSliderScalar(const char* label, const ImVec2& size, ImGuiDataType data_type, void* p_data, const void* p_min, const void* p_max, const char* format = NULL, ImGuiSliderFlags flags = 0);

imgui_demo.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -974,6 +974,13 @@ static void DemoWindowWidgetsBasic()
974974
const char* elem_name = (elem >= 0 && elem < Element_COUNT) ? elems_names[elem] : "Unknown";
975975
ImGui::SliderInt("slider enum", &elem, 0, Element_COUNT - 1, elem_name); // Use ImGuiSliderFlags_NoInput flag to disable Ctrl+Click here.
976976
ImGui::SameLine(); HelpMarker("Using the format string parameter to display a name instead of the underlying integer.");
977+
978+
IMGUI_DEMO_MARKER("Widgets/Basic/SliderFloatRange2, SliderIntRange2");
979+
static float fmin = 0.25f, fmax = 0.75f;
980+
static int imin = 25, imax = 75;
981+
ImGui::SliderFloatRange2("range float", &fmin, &fmax, 0.0f, 1.0f);
982+
ImGui::SliderIntRange2("range int", &imin, &imax, 0, 100);
983+
ImGui::SameLine(); HelpMarker("Click and drag handles individually, or drag the bar between them to move both.");
977984
}
978985

979986
ImGui::SeparatorText("Selectors/Pickers");

imgui_internal.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2469,6 +2469,7 @@ struct ImGuiContext
24692469
float SliderGrabClickOffset;
24702470
float SliderCurrentAccum; // Accumulated slider delta when using navigation controls.
24712471
bool SliderCurrentAccumDirty; // Has the accumulated slider delta changed since last time we tried to apply it?
2472+
ImS8 SliderRangeActiveHandle; // For SliderScalarRange2: which handle is active (0=min, 1=max, -1=bar)
24722473
bool DragCurrentAccumDirty;
24732474
float DragCurrentAccum; // Accumulator for dragging modification. Always high-precision, not rounded by end-user precision settings
24742475
float DragSpeedDefaultRatio; // If speed == 0.0f, uses (max-min) * DragSpeedDefaultRatio

0 commit comments

Comments
 (0)