GUI: better inertial scroll inhibit logic

also better pattern editor mute in mobile
This commit is contained in:
tildearrow 2022-12-02 22:59:52 -05:00
parent e7cfde9a2b
commit f84469e4fd
5 changed files with 51 additions and 12 deletions

View file

@ -3451,8 +3451,6 @@ void ImGui::SetActiveID(ImGuiID id, ImGuiWindow* window)
if (g.LastItemData.InFlags & ImGuiItemFlags_NoInertialScroll) {
g.InertialScrollInhibited=true;
}
} else {
g.InertialScrollInhibited=false;
}
// Clear declaration of inputs claimed by the widget
@ -5102,7 +5100,7 @@ void ImGui::EndFrame()
}
// Check for inertial scroll inhibit status
if (g.IO.MouseReleased[ImGuiMouseButton_Left]) {
if (!g.IO.MouseDown[ImGuiMouseButton_Left]) {
g.InertialScrollInhibited=false;
}
@ -6941,25 +6939,32 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags)
if (g.IO.MouseClicked[ImGuiMouseButton_Left]) {
window->InertialScrollSpeed=ImVec2(0.0f,0.0f);
window->InertialScroll=false;
g.InertialScroll=false;
g.WasInertialScroll=false;
} else {
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);
window->InertialScroll=false;
g.InertialScroll=false;
} else {
window->InertialScrollSpeed=ImVec2(window->ScrollbarX?-g.IO.MouseDelta.x:0.0f,window->ScrollbarY?-g.IO.MouseDelta.y:0.0f);
if (window->ScrollbarX || window->ScrollbarY) {
window->InertialScroll=true;
g.InertialScroll=true;
g.WasInertialScroll=true;
}
}
} else {
window->InertialScrollSpeed=ImVec2(0.0f,0.0f);
window->InertialScroll=false;
g.InertialScroll=false;
}
}
} else if (g.InertialScrollInhibited) {
window->InertialScrollSpeed=ImVec2(0.0f,0.0f);
window->InertialScroll=false;
g.InertialScroll=false;
}
}
@ -6982,6 +6987,7 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags)
window->InertialScrollSpeed.x=0.0f;
window->InertialScrollSpeed.y=0.0f;
window->InertialScroll=false;
g.InertialScroll=false;
}
if (g.IO.MouseDown[ImGuiMouseButton_Left]) {
@ -7556,11 +7562,22 @@ void ImGui::EndDisabled()
bool ImGui::IsInertialScroll()
{
/*
ImGuiWindow* window = GetCurrentWindow();
if (window==NULL) return false;
return window->InertialScroll;
*/
ImGuiContext& g = *GImGui;
return g.InertialScroll;
}
// WasInertialScroll()
bool ImGui::WasInertialScroll()
{
ImGuiContext& g = *GImGui;
return g.WasInertialScroll;
}
// InhibitInertialScroll()

View file

@ -840,6 +840,7 @@ namespace ImGui
// Inertial scroll
IMGUI_API bool IsInertialScroll();
IMGUI_API bool WasInertialScroll();
IMGUI_API void InhibitInertialScroll();
// Clipping

View file

@ -1938,6 +1938,8 @@ struct ImGuiContext
// Inertial scroll
bool InertialScrollInhibited; // Is inertial scroll inhibited? (e.g. by ImGuiItemFlags_NoInertialScroll)
bool InertialScroll; // Is any window being scrolled?
bool WasInertialScroll; // Was ^?
// Render
float DimBgRatio; // 0.0..1.0 animation when fading in a dimming background (for modal window and CTRL+TAB list)

View file

@ -61,6 +61,8 @@
if (SDL_HapticRumblePlay(vibrator,0.5f,20)!=0) { \
logV("could not vibrate: %s!",SDL_GetError()); \
} \
} else { \
fputc(7,stderr); /* bell */ \
}
#define BIND_FOR(x) getKeyName(actionKeys[x],true).c_str()

View file

@ -734,19 +734,36 @@ void FurnaceGUI::drawPattern() {
ImGui::SetTooltip("%s",e->getChannelName(i));
}
if (settings.channelFont==0) ImGui::PopFont();
if (ImGui::IsItemClicked(ImGuiMouseButton_Left)) {
if (settings.soloAction!=1 && soloTimeout>0 && soloChan==i) {
e->toggleSolo(i);
soloTimeout=0;
} else {
e->toggleMute(i);
soloTimeout=20;
soloChan=i;
if (mobileUI) {
if (ImGui::IsItemHovered()) {
if (CHECK_LONG_HOLD) {
NOTIFY_LONG_HOLD;
e->toggleSolo(i);
soloChan=i;
}
if (ImGui::IsMouseReleased(ImGuiMouseButton_Left) && !ImGui::WasInertialScroll()) {
if (soloChan!=i) {
e->toggleMute(i);
} else {
soloChan=-1;
}
}
}
} else {
if (ImGui::IsItemClicked(ImGuiMouseButton_Left)) {
if (settings.soloAction!=1 && soloTimeout>0 && soloChan==i) {
e->toggleSolo(i);
soloTimeout=0;
} else {
e->toggleMute(i);
soloTimeout=20;
soloChan=i;
}
}
}
if (muted) ImGui::PopStyleColor();
ImGui::PopStyleColor(4);
if (settings.soloAction!=2) if (ImGui::IsItemClicked(ImGuiMouseButton_Right)) {
if (settings.soloAction!=2 && !mobileUI) if (ImGui::IsItemClicked(ImGuiMouseButton_Right)) {
inhibitMenu=true;
e->toggleSolo(i);
}