Browse Source

Minor scroll widget cleanup

Fix always true condition, and non-functional change to box sizing.
Michael Ragazzon 1 year ago
parent
commit
85ffeea7f6
2 changed files with 11 additions and 15 deletions
  1. 1 1
      Include/RmlUi/Core/Box.h
  2. 10 14
      Source/Core/WidgetScroll.cpp

+ 1 - 1
Include/RmlUi/Core/Box.h

@@ -89,10 +89,10 @@ public:
 	float GetCumulativeEdge(BoxArea area, BoxEdge edge) const;
 
 	/// Returns the size along a single direction of the given 'area', including all inner areas up-to and including 'area_end'.
-	/// @example GetSizeAcross(Horizontal, Border, Padding) returns the total width of the horizontal borders and paddings.
 	/// @param direction The desired direction.
 	/// @param area The widest area to include.
 	/// @param area_end The last area to include, anything inside this is excluded.
+	/// @example GetSizeAcross(Horizontal, Border, Padding) returns the total width of the horizontal borders and paddings.
 	float GetSizeAcross(BoxDirection direction, BoxArea area, BoxArea area_end = BoxArea::Content) const;
 
 	/// Returns the size of the frame defined by the given area, not including inner areas.

+ 10 - 14
Source/Core/WidgetScroll.cpp

@@ -36,6 +36,7 @@
 #include "../../Include/RmlUi/Core/Property.h"
 #include "Clock.h"
 #include "Layout/LayoutDetails.h"
+#include <algorithm>
 
 namespace Rml {
 
@@ -144,20 +145,17 @@ bool WidgetScroll::Initialise(Orientation _orientation)
 
 void WidgetScroll::Update()
 {
+	if (!std::any_of(std::begin(arrow_timers), std::end(arrow_timers), [](float timer) { return timer > 0; }))
+		return;
+
+	double current_time = Clock::GetElapsedTime();
+	const float delta_time = float(current_time - last_update_time);
+	last_update_time = current_time;
+
 	for (int i = 0; i < 2; i++)
 	{
-		bool updated_time = false;
-		float delta_time = 0;
-
 		if (arrow_timers[i] > 0)
 		{
-			if (!updated_time)
-			{
-				double current_time = Clock::GetElapsedTime();
-				delta_time = float(current_time - last_update_time);
-				last_update_time = current_time;
-			}
-
 			arrow_timers[i] -= delta_time;
 			while (arrow_timers[i] <= 0)
 			{
@@ -315,8 +313,7 @@ void WidgetScroll::FormatBar(float bar_length)
 
 		if (orientation == VERTICAL)
 		{
-			float track_length = track_size.y -
-				(bar_box.GetCumulativeEdge(BoxArea::Content, BoxEdge::Top) + bar_box.GetCumulativeEdge(BoxArea::Content, BoxEdge::Bottom));
+			float track_length = track_size.y - bar_box.GetSizeAcross(BoxDirection::Vertical, BoxArea::Margin, BoxArea::Padding);
 
 			if (height.type == height.Auto)
 			{
@@ -336,8 +333,7 @@ void WidgetScroll::FormatBar(float bar_length)
 		}
 		else
 		{
-			float track_length = track_size.x -
-				(bar_box.GetCumulativeEdge(BoxArea::Content, BoxEdge::Left) + bar_box.GetCumulativeEdge(BoxArea::Content, BoxEdge::Right));
+			float track_length = track_size.x - bar_box.GetSizeAcross(BoxDirection::Horizontal, BoxArea::Margin, BoxArea::Padding);
 
 			if (width.type == width.Auto)
 			{