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.
This commit is contained in:
Pascal Thomet 2026-10-08 14:47:02 +02:00
parent 2859f6723c
commit 8d9e73f1a1
No known key found for this signature in database
GPG Key ID: 421F2328314F192D

View File

@ -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);