Skip to content

Commit

Permalink
Scroll controller: Only scroll in scrollable directions
Browse files Browse the repository at this point in the history
  • Loading branch information
mikke89 committed Jul 7, 2024
1 parent 5b3ece4 commit 5d37025
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions Source/Core/ScrollController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,15 @@
*/

#include "ScrollController.h"
#include "../../Include/RmlUi/Core/ComputedValues.h"
#include "../../Include/RmlUi/Core/Core.h"
#include "../../Include/RmlUi/Core/Element.h"
#include "../../Include/RmlUi/Core/SystemInterface.h"

namespace Rml {

static constexpr float AUTOSCROLL_SPEED_FACTOR = 0.09f;
static constexpr float AUTOSCROLL_DEADZONE = 10.0f; // [dp]
static constexpr float AUTOSCROLL_DEADZONE = 10.0f; // [dp]

static constexpr float SMOOTHSCROLL_WINDOW_SIZE = 50.f; // The window where smoothing is applied, as a distance from scroll start and end. [dp]
static constexpr float SMOOTHSCROLL_MAX_VELOCITY = 10'000.f; // [dp/s]
Expand Down Expand Up @@ -198,9 +199,12 @@ bool ScrollController::HasSmoothscrollReachedTarget() const
void ScrollController::PerformScrollOnTarget(Vector2f delta_distance)
{
RMLUI_ASSERT(target);
if (delta_distance.x != 0.f)
auto overflow_is_scrollable = [](Style::Overflow overflow) { return overflow == Style::Overflow::Auto || overflow == Style::Overflow::Scroll; };
auto& computed_values = target->GetComputedValues();

if (delta_distance.x != 0.f && overflow_is_scrollable(computed_values.overflow_x()))
target->SetScrollLeft(target->GetScrollLeft() + delta_distance.x);
if (delta_distance.y != 0.f)
if (delta_distance.y != 0.f && overflow_is_scrollable(computed_values.overflow_y()))
target->SetScrollTop(target->GetScrollTop() + delta_distance.y);
}

Expand Down

0 comments on commit 5d37025

Please sign in to comment.