dep/imgui: Add overridable scroll rate

This commit is contained in:
Stenzek 2025-06-08 16:40:46 +10:00
parent bd9e206165
commit 38aebd0a3e
No known key found for this signature in database
3 changed files with 9 additions and 3 deletions

View File

@ -1726,6 +1726,7 @@ enum ImGuiStyleVar_
ImGuiStyleVar_SeparatorTextBorderSize, // float SeparatorTextBorderSize ImGuiStyleVar_SeparatorTextBorderSize, // float SeparatorTextBorderSize
ImGuiStyleVar_SeparatorTextAlign, // ImVec2 SeparatorTextAlign ImGuiStyleVar_SeparatorTextAlign, // ImVec2 SeparatorTextAlign
ImGuiStyleVar_SeparatorTextPadding, // ImVec2 SeparatorTextPadding ImGuiStyleVar_SeparatorTextPadding, // ImVec2 SeparatorTextPadding
ImGuiStyleVar_ScrollStepSize, // ImVec2 ScrollStepSize
ImGuiStyleVar_ScrollSmooth, // float ScrollSmooth ImGuiStyleVar_ScrollSmooth, // float ScrollSmooth
ImGuiStyleVar_COUNT ImGuiStyleVar_COUNT
}; };
@ -2207,6 +2208,7 @@ struct ImGuiStyle
ImGuiHoveredFlags HoverFlagsForTooltipMouse;// Default flags when using IsItemHovered(ImGuiHoveredFlags_ForTooltip) or BeginItemTooltip()/SetItemTooltip() while using mouse. ImGuiHoveredFlags HoverFlagsForTooltipMouse;// Default flags when using IsItemHovered(ImGuiHoveredFlags_ForTooltip) or BeginItemTooltip()/SetItemTooltip() while using mouse.
ImGuiHoveredFlags HoverFlagsForTooltipNav; // Default flags when using IsItemHovered(ImGuiHoveredFlags_ForTooltip) or BeginItemTooltip()/SetItemTooltip() while using keyboard/gamepad. ImGuiHoveredFlags HoverFlagsForTooltipNav; // Default flags when using IsItemHovered(ImGuiHoveredFlags_ForTooltip) or BeginItemTooltip()/SetItemTooltip() while using keyboard/gamepad.
ImVec2 ScrollStepSize; // Step size for scrolling, 0.0f uses default ImGui behaviour.
float ScrollSmooth; // Smooth scrolling amount: 1.0f no smoothing. Anything above 1.0f will make the scroll delta more smooth. float ScrollSmooth; // Smooth scrolling amount: 1.0f no smoothing. Anything above 1.0f will make the scroll delta more smooth.
IMGUI_API ImGuiStyle(); IMGUI_API ImGuiStyle();

View File

@ -2512,6 +2512,7 @@ struct IMGUI_API ImGuiWindow
ImVec2 Scroll; // Current Visible Scroll position ImVec2 Scroll; // Current Visible Scroll position
ImVec2 ScrollExpected; // Current Expected Scroll position ImVec2 ScrollExpected; // Current Expected Scroll position
ImVec2 ScrollMax; ImVec2 ScrollMax;
ImVec2 ScrollStepSize;
ImVec2 ScrollTarget; // target scroll position. stored as cursor position with scrolling canceled out, so the highest point is always 0.0f. (FLT_MAX for no change) ImVec2 ScrollTarget; // target scroll position. stored as cursor position with scrolling canceled out, so the highest point is always 0.0f. (FLT_MAX for no change)
ImVec2 ScrollTargetCenterRatio; // 0.0f = scroll so that target position is at top, 0.5f = scroll so that target position is centered ImVec2 ScrollTargetCenterRatio; // 0.0f = scroll so that target position is at top, 0.5f = scroll so that target position is centered
ImVec2 ScrollTargetEdgeSnapDist; // 0.0f = no snapping, >0.0f snapping threshold ImVec2 ScrollTargetEdgeSnapDist; // 0.0f = no snapping, >0.0f snapping threshold

View File

@ -1381,6 +1381,7 @@ ImGuiStyle::ImGuiStyle()
HoverDelayNormal = 0.40f; // Delay for IsItemHovered(ImGuiHoveredFlags_DelayNormal). " HoverDelayNormal = 0.40f; // Delay for IsItemHovered(ImGuiHoveredFlags_DelayNormal). "
HoverFlagsForTooltipMouse = ImGuiHoveredFlags_Stationary | ImGuiHoveredFlags_DelayShort | ImGuiHoveredFlags_AllowWhenDisabled; // Default flags when using IsItemHovered(ImGuiHoveredFlags_ForTooltip) or BeginItemTooltip()/SetItemTooltip() while using mouse. HoverFlagsForTooltipMouse = ImGuiHoveredFlags_Stationary | ImGuiHoveredFlags_DelayShort | ImGuiHoveredFlags_AllowWhenDisabled; // Default flags when using IsItemHovered(ImGuiHoveredFlags_ForTooltip) or BeginItemTooltip()/SetItemTooltip() while using mouse.
HoverFlagsForTooltipNav = ImGuiHoveredFlags_NoSharedDelay | ImGuiHoveredFlags_DelayNormal | ImGuiHoveredFlags_AllowWhenDisabled; // Default flags when using IsItemHovered(ImGuiHoveredFlags_ForTooltip) or BeginItemTooltip()/SetItemTooltip() while using keyboard/gamepad. HoverFlagsForTooltipNav = ImGuiHoveredFlags_NoSharedDelay | ImGuiHoveredFlags_DelayNormal | ImGuiHoveredFlags_AllowWhenDisabled; // Default flags when using IsItemHovered(ImGuiHoveredFlags_ForTooltip) or BeginItemTooltip()/SetItemTooltip() while using keyboard/gamepad.
ScrollStepSize = ImVec2(0.0f, 0.0f);// Disabled by default.
ScrollSmooth = 1.0f; // Disabled by default. It's just immediate jump from ScrollExpected to the visual Scroll. ScrollSmooth = 1.0f; // Disabled by default. It's just immediate jump from ScrollExpected to the visual Scroll.
// Default theme // Default theme
@ -3422,6 +3423,7 @@ static const ImGuiStyleVarInfo GStyleVarsInfo[] =
{ 1, ImGuiDataType_Float, (ImU32)offsetof(ImGuiStyle, SeparatorTextBorderSize)}, // ImGuiStyleVar_SeparatorTextBorderSize { 1, ImGuiDataType_Float, (ImU32)offsetof(ImGuiStyle, SeparatorTextBorderSize)}, // ImGuiStyleVar_SeparatorTextBorderSize
{ 2, ImGuiDataType_Float, (ImU32)offsetof(ImGuiStyle, SeparatorTextAlign) }, // ImGuiStyleVar_SeparatorTextAlign { 2, ImGuiDataType_Float, (ImU32)offsetof(ImGuiStyle, SeparatorTextAlign) }, // ImGuiStyleVar_SeparatorTextAlign
{ 2, ImGuiDataType_Float, (ImU32)offsetof(ImGuiStyle, SeparatorTextPadding) }, // ImGuiStyleVar_SeparatorTextPadding { 2, ImGuiDataType_Float, (ImU32)offsetof(ImGuiStyle, SeparatorTextPadding) }, // ImGuiStyleVar_SeparatorTextPadding
{ 2, ImGuiDataType_Float, (ImU32)offsetof(ImGuiStyle, ScrollStepSize) }, // ImGuiStyleVar_ScrollStepSize
{ 1, ImGuiDataType_Float, (ImU32)offsetof(ImGuiStyle, ScrollSmooth) }, // ImGuiStyleVar_ScrollSmooth { 1, ImGuiDataType_Float, (ImU32)offsetof(ImGuiStyle, ScrollSmooth) }, // ImGuiStyleVar_ScrollSmooth
}; };
@ -7276,6 +7278,7 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags)
window->TitleBarHeight = (flags & ImGuiWindowFlags_NoTitleBar) ? 0.0f : g.FontSize + g.Style.FramePadding.y * 2.0f; window->TitleBarHeight = (flags & ImGuiWindowFlags_NoTitleBar) ? 0.0f : g.FontSize + g.Style.FramePadding.y * 2.0f;
window->MenuBarHeight = (flags & ImGuiWindowFlags_MenuBar) ? window->DC.MenuBarOffset.y + g.FontSize + g.Style.FramePadding.y * 2.0f : 0.0f; window->MenuBarHeight = (flags & ImGuiWindowFlags_MenuBar) ? window->DC.MenuBarOffset.y + g.FontSize + g.Style.FramePadding.y * 2.0f : 0.0f;
window->FontRefSize = g.FontSize; // Lock this to discourage calling window->CalcFontSize() outside of current window. window->FontRefSize = g.FontSize; // Lock this to discourage calling window->CalcFontSize() outside of current window.
window->ScrollStepSize = style.ScrollStepSize;
// Depending on condition we use previous or current window size to compare against contents size to decide if a scrollbar should be visible. // Depending on condition we use previous or current window size to compare against contents size to decide if a scrollbar should be visible.
// Those flags will be altered further down in the function depending on more conditions. // Those flags will be altered further down in the function depending on more conditions.
@ -9748,7 +9751,7 @@ void ImGui::UpdateMouseWheel()
{ {
LockWheelingWindow(window, wheel.x); LockWheelingWindow(window, wheel.x);
float max_step = window->InnerRect.GetWidth() * 0.67f; float max_step = window->InnerRect.GetWidth() * 0.67f;
float scroll_step = ImTrunc(ImMin(2 * window->FontRefSize, max_step)); float scroll_step = (window->ScrollStepSize.x != 0.0f) ? window->ScrollStepSize.x : ImTrunc(ImMin(2 * window->FontRefSize, max_step));
SetScrollX(window, window->ScrollExpected.x - wheel.x * scroll_step); SetScrollX(window, window->ScrollExpected.x - wheel.x * scroll_step);
g.WheelingWindowScrolledFrame = g.FrameCount; g.WheelingWindowScrolledFrame = g.FrameCount;
} }
@ -9756,7 +9759,7 @@ void ImGui::UpdateMouseWheel()
{ {
LockWheelingWindow(window, wheel.y); LockWheelingWindow(window, wheel.y);
float max_step = window->InnerRect.GetHeight() * 0.67f; float max_step = window->InnerRect.GetHeight() * 0.67f;
float scroll_step = ImTrunc(ImMin(5 * window->FontRefSize, max_step)); float scroll_step = (window->ScrollStepSize.y != 0.0f) ? window->ScrollStepSize.y : ImTrunc(ImMin(5 * window->FontRefSize, max_step));
SetScrollY(window, window->ScrollExpected.y - wheel.y * scroll_step); SetScrollY(window, window->ScrollExpected.y - wheel.y * scroll_step);
g.WheelingWindowScrolledFrame = g.FrameCount; g.WheelingWindowScrolledFrame = g.FrameCount;
} }