FullscreenUI: Use system scroll rate and layout scale

Makes scrolling feel much more responsive, and doesn't vary
depending on the size of the window.
This commit is contained in:
Stenzek 2025-06-08 16:49:26 +10:00
parent 38aebd0a3e
commit 29e55a2e5b
No known key found for this signature in database
8 changed files with 18 additions and 14 deletions

View File

@ -345,7 +345,11 @@ bool DisplayWidget::event(QEvent* event)
case QEvent::Wheel:
{
const QWheelEvent* wheel_event = static_cast<QWheelEvent*>(event);
emit windowMouseWheelEvent(wheel_event->angleDelta());
const QPoint angle_delta = wheel_event->angleDelta();
const float dx = static_cast<float>(angle_delta.x()) / static_cast<float>(QWheelEvent::DefaultDeltasPerStep);
const float dy = (static_cast<float>(angle_delta.y()) / static_cast<float>(QWheelEvent::DefaultDeltasPerStep)) *
static_cast<float>(QApplication::wheelScrollLines());
emit windowMouseWheelEvent(dx, dy);
return true;
}

View File

@ -44,7 +44,7 @@ Q_SIGNALS:
void windowKeyEvent(int key_code, bool pressed);
void windowTextEntered(const QString& text);
void windowMouseButtonEvent(int button, bool pressed);
void windowMouseWheelEvent(const QPoint& angle_delta);
void windowMouseWheelEvent(float dx, float dy);
protected:
bool event(QEvent* event) override;

View File

@ -97,7 +97,8 @@ bool InputBindingDialog::eventFilter(QObject* watched, QEvent* event)
else if (event_type == QEvent::Wheel)
{
const QPoint delta_angle(static_cast<QWheelEvent*>(event)->angleDelta());
const float dx = std::clamp(static_cast<float>(delta_angle.x()) / QtUtils::MOUSE_WHEEL_DELTA, -1.0f, 1.0f);
const float dx = std::clamp(
static_cast<float>(delta_angle.x()) / static_cast<float>(QWheelEvent::DefaultDeltasPerStep), -1.0f, 1.0f);
if (dx != 0.0f)
{
InputBindingKey key(InputManager::MakePointerAxisKey(0, InputPointerAxis::WheelX));
@ -105,7 +106,8 @@ bool InputBindingDialog::eventFilter(QObject* watched, QEvent* event)
m_new_bindings.push_back(key);
}
const float dy = std::clamp(static_cast<float>(delta_angle.y()) / QtUtils::MOUSE_WHEEL_DELTA, -1.0f, 1.0f);
const float dy = std::clamp(
static_cast<float>(delta_angle.y()) / static_cast<float>(QWheelEvent::DefaultDeltasPerStep), -1.0f, 1.0f);
if (dy != 0.0f)
{
InputBindingKey key(InputManager::MakePointerAxisKey(0, InputPointerAxis::WheelY));

View File

@ -124,7 +124,8 @@ bool InputBindingWidget::eventFilter(QObject* watched, QEvent* event)
else if (event_type == QEvent::Wheel)
{
const QPoint delta_angle(static_cast<QWheelEvent*>(event)->angleDelta());
const float dx = std::clamp(static_cast<float>(delta_angle.x()) / QtUtils::MOUSE_WHEEL_DELTA, -1.0f, 1.0f);
const float dx = std::clamp(
static_cast<float>(delta_angle.x()) / static_cast<float>(QWheelEvent::DefaultDeltasPerStep), -1.0f, 1.0f);
if (dx != 0.0f)
{
InputBindingKey key(InputManager::MakePointerAxisKey(0, InputPointerAxis::WheelX));
@ -132,7 +133,8 @@ bool InputBindingWidget::eventFilter(QObject* watched, QEvent* event)
m_new_bindings.push_back(key);
}
const float dy = std::clamp(static_cast<float>(delta_angle.y()) / QtUtils::MOUSE_WHEEL_DELTA, -1.0f, 1.0f);
const float dy = std::clamp(
static_cast<float>(delta_angle.y()) / static_cast<float>(QWheelEvent::DefaultDeltasPerStep), -1.0f, 1.0f);
if (dy != 0.0f)
{
InputBindingKey key(InputManager::MakePointerAxisKey(0, InputPointerAxis::WheelY));

View File

@ -903,15 +903,13 @@ void EmuThread::onDisplayWindowMouseButtonEvent(int button, bool pressed)
GenericInputBinding::Unknown);
}
void EmuThread::onDisplayWindowMouseWheelEvent(const QPoint& delta_angle)
void EmuThread::onDisplayWindowMouseWheelEvent(float dx, float dy)
{
DebugAssert(isCurrentThread());
const float dx = std::clamp(static_cast<float>(delta_angle.x()) / QtUtils::MOUSE_WHEEL_DELTA, -1.0f, 1.0f);
if (dx != 0.0f)
InputManager::UpdatePointerRelativeDelta(0, InputPointerAxis::WheelX, dx);
const float dy = std::clamp(static_cast<float>(delta_angle.y()) / QtUtils::MOUSE_WHEEL_DELTA, -1.0f, 1.0f);
if (dy != 0.0f)
InputManager::UpdatePointerRelativeDelta(0, InputPointerAxis::WheelY, dy);
}

View File

@ -223,7 +223,7 @@ public Q_SLOTS:
private Q_SLOTS:
void stopInThread();
void onDisplayWindowMouseButtonEvent(int button, bool pressed);
void onDisplayWindowMouseWheelEvent(const QPoint& delta_angle);
void onDisplayWindowMouseWheelEvent(float dx, float dy);
void onDisplayWindowResized(int width, int height, float scale);
void onDisplayWindowKeyEvent(int key, bool pressed);
void onDisplayWindowTextEntered(const QString& text);

View File

@ -45,9 +45,6 @@ enum class EntryType : u8;
namespace QtUtils {
/// Wheel delta is 120 as in winapi.
static constexpr float MOUSE_WHEEL_DELTA = 120.0f;
/// Creates a horizontal line widget.
QFrame* CreateHorizontalLine(QWidget* parent);

View File

@ -808,6 +808,7 @@ void ImGuiFullscreen::PushResetLayout()
ImGui::PushStyleVar(ImGuiStyleVar_GrabMinSize, LayoutScale(10.0f));
ImGui::PushStyleVar(ImGuiStyleVar_TabRounding, LayoutScale(4.0f));
ImGui::PushStyleVar(ImGuiStyleVar_ScrollSmooth, UIStyle.SmoothScrolling ? SMOOTH_SCROLLING_SPEED : 1.0f);
ImGui::PushStyleVar(ImGuiStyleVar_ScrollStepSize, LayoutScale(LAYOUT_LARGE_FONT_SIZE, LAYOUT_MENU_BUTTON_HEIGHT));
ImGui::PushStyleColor(ImGuiCol_Text, UIStyle.SecondaryTextColor);
ImGui::PushStyleColor(ImGuiCol_TextDisabled, UIStyle.DisabledColor);
ImGui::PushStyleColor(ImGuiCol_Button, UIStyle.SecondaryColor);
@ -825,7 +826,7 @@ void ImGuiFullscreen::PushResetLayout()
void ImGuiFullscreen::PopResetLayout()
{
ImGui::PopStyleColor(12);
ImGui::PopStyleVar(13);
ImGui::PopStyleVar(14);
}
void ImGuiFullscreen::QueueResetFocus(FocusResetType type)