GUI: inertial scrolling experiments

This commit is contained in:
tildearrow 2022-11-30 19:42:51 -05:00
parent 704863533f
commit 285dae9239
4 changed files with 45 additions and 0 deletions

View File

@ -3313,6 +3313,7 @@ ImGuiWindow::ImGuiWindow(ImGuiContext* context, const char* name) : DrawListInst
TabId = GetID("#TAB");
ScrollTarget = ImVec2(FLT_MAX, FLT_MAX);
ScrollTargetCenterRatio = ImVec2(0.5f, 0.5f);
InertialScrollSpeed = ImVec2(0.0f, 0.0f);
AutoFitFramesX = AutoFitFramesY = -1;
AutoPosLastDirection = ImGuiDir_None;
SetWindowPosAllowFlags = SetWindowSizeAllowFlags = SetWindowCollapsedAllowFlags = SetWindowDockAllowFlags = ImGuiCond_Always | ImGuiCond_Once | ImGuiCond_FirstUseEver | ImGuiCond_Appearing;
@ -6893,6 +6894,43 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags)
window->ScrollMax.x = ImMax(0.0f, window->ContentSize.x + window->WindowPadding.x * 2.0f - window->InnerRect.GetWidth());
window->ScrollMax.y = ImMax(0.0f, window->ContentSize.y + window->WindowPadding.y * 2.0f - window->InnerRect.GetHeight());
// Inertial scroll
if (g.IO.ConfigFlags & ImGuiConfigFlags_InertialScrollEnable) {
if (g.HoveredWindow == window) {
if (g.IO.MouseDown[ImGuiMouseButton_Left] || g.IO.MouseReleased[ImGuiMouseButton_Left]) {
// launch inertial scroll
if (g.IO.MouseClicked[ImGuiMouseButton_Left]) {
g.HoveredWindow->InertialScrollSpeed=ImVec2(0.0f,0.0f);
} else {
g.HoveredWindow->InertialScrollSpeed=ImVec2(-g.IO.MouseDelta.x,-g.IO.MouseDelta.y);
}
}
}
if (window->ScrollTarget.x == FLT_MAX && window->ScrollTarget.y == FLT_MAX) {
if (fabs(window->InertialScrollSpeed.x)>0.1f) {
window->Scroll.x=window->Scroll.x+window->InertialScrollSpeed.x;
window->InertialScrollSpeed.x*=0.95f;
} else {
window->InertialScrollSpeed.x=0.0f;
}
if (fabs(window->InertialScrollSpeed.y)>0.1f) {
window->Scroll.y=window->Scroll.y+window->InertialScrollSpeed.y;
window->InertialScrollSpeed.y*=0.95f;
} else {
window->InertialScrollSpeed.y=0.0f;
}
} else {
window->InertialScrollSpeed.x=0.0f;
window->InertialScrollSpeed.y=0.0f;
}
if (g.IO.MouseDown[ImGuiMouseButton_Left]) {
window->InertialScrollSpeed.x=0.0f;
window->InertialScrollSpeed.y=0.0f;
}
}
// Apply scrolling
window->Scroll = CalcNextScrollFromScrollTargetAndClamp(window);
window->ScrollTarget = ImVec2(FLT_MAX, FLT_MAX);
@ -18612,6 +18650,7 @@ void ImGui::DebugNodeWindow(ImGuiWindow* window, const char* label)
(flags & ImGuiWindowFlags_NoMouseInputs)? "NoMouseInputs":"", (flags & ImGuiWindowFlags_NoNavInputs) ? "NoNavInputs" : "", (flags & ImGuiWindowFlags_AlwaysAutoResize) ? "AlwaysAutoResize" : "");
BulletText("WindowClassId: 0x%08X", window->WindowClass.ClassId);
BulletText("Scroll: (%.2f/%.2f,%.2f/%.2f) Scrollbar:%s%s", window->Scroll.x, window->ScrollMax.x, window->Scroll.y, window->ScrollMax.y, window->ScrollbarX ? "X" : "", window->ScrollbarY ? "Y" : "");
BulletText("InertialScrollSpeed: %.2f,%.2f",window->InertialScrollSpeed.x,window->InertialScrollSpeed.y);
BulletText("Active: %d/%d, WriteAccessed: %d, BeginOrderWithinContext: %d", window->Active, window->WasActive, window->WriteAccessed, (window->Active || window->WasActive) ? window->BeginOrderWithinContext : -1);
BulletText("Appearing: %d, Hidden: %d (CanSkip %d Cannot %d), SkipItems: %d", window->Appearing, window->Hidden, window->HiddenFramesCanSkipItems, window->HiddenFramesCannotSkipItems, window->SkipItems);
for (int layer = 0; layer < ImGuiNavLayer_COUNT; layer++)

View File

@ -1573,6 +1573,9 @@ enum ImGuiConfigFlags_
// [BETA] Docking
ImGuiConfigFlags_DockingEnable = 1 << 6, // Docking enable flags.
// [CUSTOM] Inertial scroll
ImGuiConfigFlags_InertialScrollEnable = 1 << 7, // Docking enable flags.
// [BETA] Viewports
// When using viewports it is recommended that your default value for ImGuiCol_WindowBg is opaque (Alpha=1.0) so transition to a viewport won't be noticeable.
ImGuiConfigFlags_ViewportsEnable = 1 << 10, // Viewport enable flags (require both ImGuiBackendFlags_PlatformHasViewports + ImGuiBackendFlags_RendererHasViewports set by the respective backends)

View File

@ -2293,6 +2293,7 @@ struct IMGUI_API ImGuiWindow
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 ScrollbarSizes; // Size taken by each scrollbars on their smaller axis. Pay attention! ScrollbarSizes.x == width of the vertical scrollbar, ScrollbarSizes.y = height of the horizontal scrollbar.
ImVec2 InertialScrollSpeed; // current speed of inertial scroll (AKA "swipe")
bool ScrollbarX, ScrollbarY; // Are scrollbars visible?
bool ViewportOwned;
bool Active; // Set to true on Begin(), unless Collapsed

View File

@ -2629,9 +2629,11 @@ void FurnaceGUI::toggleMobileUI(bool enable, bool force) {
mobileUI=enable;
if (mobileUI) {
ImGui::GetIO().IniFilename=NULL;
ImGui::GetIO().ConfigFlags|=ImGuiConfigFlags_InertialScrollEnable;
} else {
ImGui::GetIO().IniFilename=NULL;
ImGui::LoadIniSettingsFromDisk(finalLayoutPath);
ImGui::GetIO().ConfigFlags&=~ImGuiConfigFlags_InertialScrollEnable;
}
}
}