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;
// TODO: check whether this works
if (g.LastItemData.InFlags & ImGuiItemFlags_NoInertialScroll) {
if (window) {
window->InertialScrollInhibited=true;
printf("inhibiting scroll\n");
}
g.InertialScrollInhibited=true;
}
} else {
if (window) window->InertialScrollInhibited=false;
g.InertialScrollInhibited=false;
}
// Clear declaration of inputs claimed by the widget
@ -5104,6 +5101,11 @@ void ImGui::EndFrame()
g.DragDropWithinSource = false;
}
// Check for inertial scroll inhibit status
if (g.IO.MouseReleased[ImGuiMouseButton_Left]) {
g.InertialScrollInhibited=false;
}
// End frame
g.WithinFrameScope = false;
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]) &&
g.ActiveId!=GetWindowScrollbarID(window,ImGuiAxis_X) &&
g.ActiveId!=GetWindowScrollbarID(window,ImGuiAxis_Y) &&
!window->InertialScrollInhibited) {
!g.InertialScrollInhibited) {
// launch inertial scroll
if (g.IO.MouseClicked[ImGuiMouseButton_Left]) {
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;
}
}
} 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.y=0.0f;
}
if (g.IO.MouseReleased[ImGuiMouseButton_Left]) {
window->InertialScrollInhibited=false;
}
}
// Apply scrolling
@ -7554,10 +7556,8 @@ void ImGui::EndDisabled()
void ImGui::InhibitInertialScroll()
{
ImGuiWindow* window = GetCurrentWindow();
if (window!=NULL) {
window->InertialScrollInhibited=true;
}
ImGuiContext& g = *GImGui;
g.InertialScrollInhibited=true;
}
// 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;
bool NavWindowingToggleLayer;
// Inertial scroll
bool InertialScrollInhibited; // Is inertial scroll inhibited? (e.g. by ImGuiItemFlags_NoInertialScroll)
// Render
float DimBgRatio; // 0.0..1.0 animation when fading in a dimming background (for modal window and CTRL+TAB list)
ImGuiMouseCursor MouseCursor;
@ -2145,6 +2148,8 @@ struct ImGuiContext
NavWindowingTimer = NavWindowingHighlightAlpha = 0.0f;
NavWindowingToggleLayer = false;
InertialScrollInhibited = false;
DimBgRatio = 0.0f;
MouseCursor = ImGuiMouseCursor_Arrow;
@ -2295,7 +2300,6 @@ struct IMGUI_API ImGuiWindow
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 InertialScrollInhibited; // Is inertial scroll inhibited? (e.g. by ImGuiItemFlags_NoInertialScroll)
bool ScrollbarX, ScrollbarY; // Are scrollbars visible?
bool ViewportOwned;
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));
ItemSize(bb, style.FramePadding.y);
if (!ItemAdd(frame_bb, id))
if (!ItemAdd(frame_bb, id, NULL, ImGuiItemFlags_NoInertialScroll))
return false;
// Default format string when passing NULL

View File

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