From 8d9e73f1a11e1f34d3e0f797df577029f56e1d7e Mon Sep 17 00:00:00 2001 From: Pascal Thomet Date: Thu, 8 Oct 2026 14:47:02 +0200 Subject: [PATCH] Widgets: Sliders & Drags display the value in a tooltip on touchscreens. On a touchscreen, the finger often hides the value inside a slider or a drag. We now display the value in a tooltip, if and only if using a touchscreen, and while the finger holds the widget. Thanks to fixes following #8036, the tooltip is correctly displayed above the finger. --- imgui_widgets.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index 287d94062..fdf8ae18e 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -2743,6 +2743,18 @@ static bool TempInputIsClampEnabled(ImGuiSliderFlags flags, ImGuiDataType data_t return false; } +// On a touch screen, the finger may hide the value of the drag or slider (just below the finger): we display it in a tooltip above the finger. +static void DisplayValueTooltipForTouchScreen(ImGuiID id, const char* value_buf, const char* value_buf_end) +{ + ImGuiContext& g = *GImGui; + if (g.ActiveId != id || g.ActiveIdSource != ImGuiInputSource_Mouse || g.IO.MouseSource != ImGuiMouseSource_TouchScreen) + return; + if (!ImGui::BeginTooltip()) + return; + ImGui::TextUnformatted(value_buf, value_buf_end); + ImGui::EndTooltip(); +} + // Note: p_data, p_min and p_max are _pointers_ to a memory address holding the data. For a Drag widget, p_min and p_max are optional. // Read code of e.g. DragFloat(), DragInt() etc. or examples in 'Demo->Widgets->Data Types' to understand how to use this function directly. bool ImGui::DragScalar(const char* label, ImGuiDataType data_type, void* p_data, float v_speed, const void* p_min, const void* p_max, const char* format, ImGuiSliderFlags flags) @@ -2837,6 +2849,7 @@ bool ImGui::DragScalar(const char* label, ImGuiDataType data_type, void* p_data, RenderTextClipped(frame_bb.Min, frame_bb.Max, value_buf, value_buf_end, NULL, ImVec2(0.5f, 0.5f)); if (is_mixed) PopStyleColor(); + DisplayValueTooltipForTouchScreen(id, value_buf, value_buf_end); if (label_size.x > 0.0f) RenderText(ImVec2(frame_bb.Max.x + style.ItemInnerSpacing.x, frame_bb.Min.y + style.FramePadding.y), label, label_end, false); @@ -3449,6 +3462,7 @@ bool ImGui::SliderScalar(const char* label, ImGuiDataType data_type, void* p_dat RenderTextClipped(frame_bb.Min, frame_bb.Max, value_buf, value_buf_end, NULL, ImVec2(0.5f, 0.5f)); if (is_mixed) PopStyleColor(); + DisplayValueTooltipForTouchScreen(id, value_buf, value_buf_end); if (label_size.x > 0.0f) RenderText(ImVec2(frame_bb.Max.x + style.ItemInnerSpacing.x, frame_bb.Min.y + style.FramePadding.y), label, label_end, false); @@ -3606,6 +3620,7 @@ bool ImGui::VSliderScalar(const char* label, const ImVec2& size, ImGuiDataType d RenderTextClipped(ImVec2(frame_bb.Min.x, frame_bb.Min.y + style.FramePadding.y), frame_bb.Max, value_buf, value_buf_end, NULL, ImVec2(0.5f, 0.0f)); if (is_mixed) PopStyleColor(); + DisplayValueTooltipForTouchScreen(id, value_buf, value_buf_end); if (label_size.x > 0.0f) RenderText(ImVec2(frame_bb.Max.x + style.ItemInnerSpacing.x, frame_bb.Min.y + style.FramePadding.y), label, label_end, false);