瀏覽代碼

Scroll controller: Only scroll in scrollable directions

Michael Ragazzon 1 年之前
父節點
當前提交
5d3702504f
共有 1 個文件被更改,包括 7 次插入3 次删除
  1. 7 3
      Source/Core/ScrollController.cpp

+ 7 - 3
Source/Core/ScrollController.cpp

@@ -27,6 +27,7 @@
  */
 
 #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"
@@ -34,7 +35,7 @@
 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]
@@ -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);
 }