GUI: fix piano allowing you to scroll on mobile

This commit is contained in:
tildearrow 2022-12-01 19:05:54 -05:00
parent 3b0ef7c096
commit 8eecdd4b93
4 changed files with 20 additions and 15 deletions

View file

@ -3449,13 +3449,10 @@ void ImGui::SetActiveID(ImGuiID id, ImGuiWindow* window)
g.ActiveIdSource = (g.NavActivateId == id || g.NavActivateInputId == id || g.NavJustMovedToId == id) ? (ImGuiInputSource)ImGuiInputSource_Nav : ImGuiInputSource_Mouse; g.ActiveIdSource = (g.NavActivateId == id || g.NavActivateInputId == id || g.NavJustMovedToId == id) ? (ImGuiInputSource)ImGuiInputSource_Nav : ImGuiInputSource_Mouse;
// TODO: check whether this works // TODO: check whether this works
if (g.LastItemData.InFlags & ImGuiItemFlags_NoInertialScroll) { if (g.LastItemData.InFlags & ImGuiItemFlags_NoInertialScroll) {
if (window) { g.InertialScrollInhibited=true;
window->InertialScrollInhibited=true;
printf("inhibiting scroll\n");
}
} }
} else { } else {
if (window) window->InertialScrollInhibited=false; g.InertialScrollInhibited=false;
} }
// Clear declaration of inputs claimed by the widget // Clear declaration of inputs claimed by the widget
@ -5104,6 +5101,11 @@ void ImGui::EndFrame()
g.DragDropWithinSource = false; g.DragDropWithinSource = false;
} }
// Check for inertial scroll inhibit status
if (g.IO.MouseReleased[ImGuiMouseButton_Left]) {
g.InertialScrollInhibited=false;
}
// End frame // End frame
g.WithinFrameScope = false; g.WithinFrameScope = false;
g.FrameCountEnded = g.FrameCount; g.FrameCountEnded = g.FrameCount;
@ -6934,7 +6936,7 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags)
if ((g.IO.MouseDown[ImGuiMouseButton_Left] || g.IO.MouseReleased[ImGuiMouseButton_Left]) && if ((g.IO.MouseDown[ImGuiMouseButton_Left] || g.IO.MouseReleased[ImGuiMouseButton_Left]) &&
g.ActiveId!=GetWindowScrollbarID(window,ImGuiAxis_X) && g.ActiveId!=GetWindowScrollbarID(window,ImGuiAxis_X) &&
g.ActiveId!=GetWindowScrollbarID(window,ImGuiAxis_Y) && g.ActiveId!=GetWindowScrollbarID(window,ImGuiAxis_Y) &&
!window->InertialScrollInhibited) { !g.InertialScrollInhibited) {
// launch inertial scroll // launch inertial scroll
if (g.IO.MouseClicked[ImGuiMouseButton_Left]) { if (g.IO.MouseClicked[ImGuiMouseButton_Left]) {
window->InertialScrollSpeed=ImVec2(0.0f,0.0f); window->InertialScrollSpeed=ImVec2(0.0f,0.0f);
@ -6955,6 +6957,9 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags)
window->InertialScroll=false; window->InertialScroll=false;
} }
} }
} else if (g.InertialScrollInhibited) {
window->InertialScrollSpeed=ImVec2(0.0f,0.0f);
window->InertialScroll=false;
} }
} }
@ -6983,9 +6988,6 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags)
window->InertialScrollSpeed.x=0.0f; window->InertialScrollSpeed.x=0.0f;
window->InertialScrollSpeed.y=0.0f; window->InertialScrollSpeed.y=0.0f;
} }
if (g.IO.MouseReleased[ImGuiMouseButton_Left]) {
window->InertialScrollInhibited=false;
}
} }
// Apply scrolling // Apply scrolling
@ -7554,10 +7556,8 @@ void ImGui::EndDisabled()
void ImGui::InhibitInertialScroll() void ImGui::InhibitInertialScroll()
{ {
ImGuiWindow* window = GetCurrentWindow(); ImGuiContext& g = *GImGui;
if (window!=NULL) { g.InertialScrollInhibited=true;
window->InertialScrollInhibited=true;
}
} }
// FIXME: Look into renaming this once we have settled the new Focus/Activation/TabStop system. // FIXME: Look into renaming this once we have settled the new Focus/Activation/TabStop system.

View file

@ -1936,6 +1936,9 @@ struct ImGuiContext
float NavWindowingHighlightAlpha; float NavWindowingHighlightAlpha;
bool NavWindowingToggleLayer; bool NavWindowingToggleLayer;
// Inertial scroll
bool InertialScrollInhibited; // Is inertial scroll inhibited? (e.g. by ImGuiItemFlags_NoInertialScroll)
// Render // Render
float DimBgRatio; // 0.0..1.0 animation when fading in a dimming background (for modal window and CTRL+TAB list) float DimBgRatio; // 0.0..1.0 animation when fading in a dimming background (for modal window and CTRL+TAB list)
ImGuiMouseCursor MouseCursor; ImGuiMouseCursor MouseCursor;
@ -2145,6 +2148,8 @@ struct ImGuiContext
NavWindowingTimer = NavWindowingHighlightAlpha = 0.0f; NavWindowingTimer = NavWindowingHighlightAlpha = 0.0f;
NavWindowingToggleLayer = false; NavWindowingToggleLayer = false;
InertialScrollInhibited = false;
DimBgRatio = 0.0f; DimBgRatio = 0.0f;
MouseCursor = ImGuiMouseCursor_Arrow; MouseCursor = ImGuiMouseCursor_Arrow;
@ -2295,7 +2300,6 @@ struct IMGUI_API ImGuiWindow
ImVec2 ScrollTargetEdgeSnapDist; // 0.0f = no snapping, >0.0f snapping threshold 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 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") ImVec2 InertialScrollSpeed; // current speed of inertial scroll (AKA "swipe")
bool InertialScrollInhibited; // Is inertial scroll inhibited? (e.g. by ImGuiItemFlags_NoInertialScroll)
bool ScrollbarX, ScrollbarY; // Are scrollbars visible? bool ScrollbarX, ScrollbarY; // Are scrollbars visible?
bool ViewportOwned; bool ViewportOwned;
bool Active; // Set to true on Begin(), unless Collapsed bool Active; // Set to true on Begin(), unless Collapsed

View file

@ -3113,7 +3113,7 @@ bool ImGui::VSliderScalar(const char* label, const ImVec2& size, ImGuiDataType d
const ImRect bb(frame_bb.Min, frame_bb.Max + ImVec2(label_size.x > 0.0f ? style.ItemInnerSpacing.x + label_size.x : 0.0f, 0.0f)); const ImRect bb(frame_bb.Min, frame_bb.Max + ImVec2(label_size.x > 0.0f ? style.ItemInnerSpacing.x + label_size.x : 0.0f, 0.0f));
ItemSize(bb, style.FramePadding.y); ItemSize(bb, style.FramePadding.y);
if (!ItemAdd(frame_bb, id)) if (!ItemAdd(frame_bb, id, NULL, ImGuiItemFlags_NoInertialScroll))
return false; return false;
// Default format string when passing NULL // Default format string when passing NULL

View file

@ -222,6 +222,7 @@ void FurnaceGUI::drawPiano() {
bool canInput=false; bool canInput=false;
if (ImGui::ItemHoverable(rect,ImGui::GetID("pianoDisplay"))) { if (ImGui::ItemHoverable(rect,ImGui::GetID("pianoDisplay"))) {
canInput=true; canInput=true;
ImGui::InhibitInertialScroll();
} }
if (view) { if (view) {
int notes=oct*12; int notes=oct*12;