Bläddra i källkod

Add Box::GetFrameSize function

Michael Ragazzon 3 år sedan
förälder
incheckning
4152393051
2 ändrade filer med 25 tillägg och 10 borttagningar
  1. 8 4
      Include/RmlUi/Core/Box.h
  2. 17 6
      Source/Core/Box.cpp

+ 8 - 4
Include/RmlUi/Core/Box.h

@@ -106,12 +106,16 @@ public:
 	/// @return The cumulative size of the edge.
 	float GetCumulativeEdge(Area area, Edge edge) const;
 
-	/// Returns the size along a single direction of the given 'area', including all inner areas up-to and including 'area_end'.
+	/// Returns the size along a single direction starting at 'area_outer', up-to and including 'area_inner'.
 	/// @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.
-	float GetSizeAcross(Direction direction, Area area, Area area_end = Area::CONTENT) const;
+	/// @param area_outer The widest area to include.
+	/// @param area_inner The last area to include, anything inside this is excluded.
+	float GetSizeAcross(Direction direction, Area area_outer, Area area_inner = Area::CONTENT) const;
+
+	/// Returns the size of the frame defined by the given area, not including inner areas.
+	/// @param area The area to use.
+	Vector2f GetFrameSize(Area area) const;
 
 	/// Compares the size of the content area and the other area edges.
 	/// @return True if the boxes represent the same area.

+ 17 - 6
Source/Core/Box.cpp

@@ -15,7 +15,7 @@
  *
  * The above copyright notice and this permission notice shall be included in
  * all copies or substantial portions of the Software.
- * 
+ *
  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
@@ -95,22 +95,33 @@ float Box::GetCumulativeEdge(Area area, Edge edge) const
 	return size;
 }
 
-float Box::GetSizeAcross(Direction direction, Area area, Area area_end) const
+float Box::GetSizeAcross(Direction direction, Area area_outer, Area area_inner) const
 {
 	static_assert(HORIZONTAL == 1 && VERTICAL == 0, "");
-	RMLUI_ASSERT(area <= area_end && direction <= 1);
+	RMLUI_ASSERT(area_outer <= area_inner && direction <= 1);
 
 	float size = 0.0f;
 
-	if (area_end == CONTENT)
+	if (area_inner == CONTENT)
 		size = (direction == HORIZONTAL ? content.x : content.y);
-	
-	for (int i = area; i <= area_end && i < CONTENT; i++)
+
+	for (int i = area_outer; i <= area_inner && i < CONTENT; i++)
 		size += (area_edges[i][TOP + (int)direction] + area_edges[i][BOTTOM + (int)direction]);
 
 	return size;
 }
 
+Vector2f Box::GetFrameSize(Area area) const
+{
+	if (area == CONTENT)
+		return content;
+
+	return {
+		area_edges[area][RIGHT] + area_edges[area][LEFT],
+		area_edges[area][TOP] + area_edges[area][BOTTOM],
+	};
+}
+
 // Compares the size of the content area and the other area edges.
 bool Box::operator==(const Box& rhs) const
 {