GUI: more inertial scrolling work
This commit is contained in:
parent
2a349e2daa
commit
a04d6b8e0b
|
@ -1178,6 +1178,9 @@ ImGuiIO::ImGuiIO()
|
|||
ConfigViewportsNoDecoration = true;
|
||||
ConfigViewportsNoDefaultParent = false;
|
||||
|
||||
// Inertial scrolling options (when ImGuiConfigFlags_InertialScrollEnable is set)
|
||||
ConfigInertialScrollToleranceSqr = 36.0f;
|
||||
|
||||
// Miscellaneous options
|
||||
MouseDrawCursor = false;
|
||||
#ifdef __APPLE__
|
||||
|
@ -4156,6 +4159,8 @@ static void ImGui::UpdateMouseInputs()
|
|||
// Round mouse position to avoid spreading non-rounded position (e.g. UpdateManualResize doesn't support them well)
|
||||
if (IsMousePosValid(&io.MousePos))
|
||||
io.MousePos = g.MouseLastValidPos = ImFloorSigned(io.MousePos);
|
||||
|
||||
io.MouseDeltaPrev=io.MouseDelta;
|
||||
|
||||
// If mouse just appeared or disappeared (usually denoted by -FLT_MAX components) we cancel out movement in MouseDelta
|
||||
if (IsMousePosValid(&io.MousePos) && IsMousePosValid(&io.MousePosPrev))
|
||||
|
@ -4167,6 +4172,18 @@ static void ImGui::UpdateMouseInputs()
|
|||
if (io.MouseDelta.x != 0.0f || io.MouseDelta.y != 0.0f)
|
||||
g.NavDisableMouseHover = false;
|
||||
|
||||
// Update mouse speed
|
||||
if (ImFabs(io.MouseDelta.x)>ImFabs(io.MouseDeltaPrev.x)) {
|
||||
io.MouseSpeed.x=io.MouseDelta.x;
|
||||
} else {
|
||||
io.MouseSpeed.x=io.MouseDeltaPrev.x;
|
||||
}
|
||||
if (ImFabs(io.MouseDelta.y)>ImFabs(io.MouseDeltaPrev.y)) {
|
||||
io.MouseSpeed.y=io.MouseDelta.y;
|
||||
} else {
|
||||
io.MouseSpeed.y=io.MouseDeltaPrev.y;
|
||||
}
|
||||
|
||||
io.MousePosPrev = io.MousePos;
|
||||
for (int i = 0; i < IM_ARRAYSIZE(io.MouseDown); i++)
|
||||
{
|
||||
|
@ -6896,17 +6913,21 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags)
|
|||
|
||||
// Inertial scroll
|
||||
if (g.IO.ConfigFlags & ImGuiConfigFlags_InertialScrollEnable) {
|
||||
if (g.IO.MouseClicked[ImGuiMouseButton_Left] && (g.NavWindowingTarget ? g.NavWindowingTarget : g.NavWindow) == window) {
|
||||
g.InertialScrollId = window->ID;
|
||||
printf("changing the ID to %d\n",window->ID);
|
||||
}
|
||||
if ((g.NavWindowingTarget ? g.NavWindowingTarget : g.NavWindow) == window) {
|
||||
if (g.IO.MouseDown[ImGuiMouseButton_Left] || g.IO.MouseReleased[ImGuiMouseButton_Left]) {
|
||||
// launch inertial scroll
|
||||
if (g.IO.MouseClicked[ImGuiMouseButton_Left]) {
|
||||
window->InertialScrollSpeed=ImVec2(0.0f,0.0f);
|
||||
} else {
|
||||
window->InertialScrollSpeed=ImVec2(window->ScrollbarX?-g.IO.MouseDelta.x:0.0f,window->ScrollbarY?-g.IO.MouseDelta.y:0.0f);
|
||||
if (g.IO.MouseDragMaxDistanceSqr[ImGuiMouseButton_Left]>g.IO.ConfigInertialScrollToleranceSqr) {
|
||||
if (g.IO.MouseReleased[ImGuiMouseButton_Left]) {
|
||||
window->InertialScrollSpeed=ImVec2(window->ScrollbarX?-g.IO.MouseSpeed.x:0.0f,window->ScrollbarY?-g.IO.MouseSpeed.y:0.0f);
|
||||
} else {
|
||||
window->InertialScrollSpeed=ImVec2(window->ScrollbarX?-g.IO.MouseDelta.x:0.0f,window->ScrollbarY?-g.IO.MouseDelta.y:0.0f);
|
||||
}
|
||||
} else {
|
||||
window->InertialScrollSpeed=ImVec2(0.0f,0.0f);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2022,6 +2022,9 @@ struct ImGuiIO
|
|||
bool ConfigViewportsNoDecoration; // = true // Disable default OS window decoration flag for secondary viewports. When a viewport doesn't want window decorations, ImGuiViewportFlags_NoDecoration will be set on it. Enabling decoration can create subsequent issues at OS levels (e.g. minimum window size).
|
||||
bool ConfigViewportsNoDefaultParent; // = false // Disable default OS parenting to main viewport for secondary viewports. By default, viewports are marked with ParentViewportId = <main_viewport>, expecting the platform backend to setup a parent/child relationship between the OS windows (some backend may ignore this). Set to true if you want the default to be 0, then all viewports will be top-level OS windows.
|
||||
|
||||
// Inertial scrolling options (when ImGuiConfigFlags_InertialScrollEnable is set)
|
||||
float ConfigInertialScrollToleranceSqr;// = 36.0f // After a point moves past this distance, inertial scroll begins
|
||||
|
||||
// Miscellaneous options
|
||||
bool MouseDrawCursor; // = false // Request ImGui to draw a mouse cursor for you (if you are on a platform without a mouse cursor). Cannot be easily renamed to 'io.ConfigXXX' because this is frequently used by backend implementations.
|
||||
bool ConfigMacOSXBehaviors; // = defined(__APPLE__) // OS X style: Text editing cursor movement using Alt instead of Ctrl, Shortcuts using Cmd/Super instead of Ctrl, Line/Text Start and End using Cmd+Arrows instead of Home/End, Double click selects by word instead of selecting whole text, Multi-selection in lists uses Cmd/Super instead of Ctrl.
|
||||
|
@ -2099,6 +2102,8 @@ struct ImGuiIO
|
|||
int MetricsActiveWindows; // Number of active windows
|
||||
int MetricsActiveAllocations; // Number of active allocations, updated by MemAlloc/MemFree based on current context. May be off if you have multiple imgui contexts.
|
||||
ImVec2 MouseDelta; // Mouse delta. Note that this is zero if either current or previous position are invalid (-FLT_MAX,-FLT_MAX), so a disappearing/reappearing mouse won't have a huge delta.
|
||||
ImVec2 MouseDeltaPrev; // Previous mouse delta.
|
||||
ImVec2 MouseSpeed; // Average mouse speed in a short timeframe. Used for inertial scroll.
|
||||
|
||||
// Legacy: before 1.87, we required backend to fill io.KeyMap[] (imgui->native map) during initialization and io.KeysDown[] (native indices) every frame.
|
||||
// This is still temporarily supported as a legacy feature. However the new preferred scheme is for backend to call io.AddKeyEvent().
|
||||
|
|
|
@ -1817,7 +1817,6 @@ struct ImGuiContext
|
|||
ImGuiWindow* WheelingWindow; // Track the window we started mouse-wheeling on. Until a timer elapse or mouse has moved, generally keep scrolling the same window even if during the course of scrolling the mouse ends up hovering a child window.
|
||||
ImVec2 WheelingWindowRefMousePos;
|
||||
float WheelingWindowTimer;
|
||||
ImGuiID InertialScrollId; // The last window in where to apply inertial scroll
|
||||
|
||||
// Item/widgets state and tracking information
|
||||
ImGuiID DebugHookIdInfo; // Will call core hooks: DebugHookIdInfo() from GetID functions, used by Stack Tool [next HoveredId/ActiveId to not pull in an extra cache-line]
|
||||
|
|
|
@ -42,7 +42,7 @@ void FurnaceGUI::drawDebug() {
|
|||
nextWindow=GUI_WINDOW_NOTHING;
|
||||
}
|
||||
if (!debugOpen) return;
|
||||
ImGui::SetNextWindowSizeConstraints(ImVec2(400.0f*dpiScale,200.0f*dpiScale),ImVec2(canvasW,canvasH));
|
||||
ImGui::SetNextWindowSizeConstraints(ImVec2(100.0f*dpiScale,100.0f*dpiScale),ImVec2(canvasW,canvasH));
|
||||
if (ImGui::Begin("Debug",&debugOpen,globalWinFlags|ImGuiWindowFlags_NoDocking)) {
|
||||
ImGui::Text("NOTE: use with caution.");
|
||||
if (ImGui::TreeNode("Debug Controls")) {
|
||||
|
|
Loading…
Reference in New Issue