Răsfoiți Sursa

Add inset property

Equivalent to its CSS counter-part.
Michael Ragazzon 2 luni în urmă
părinte
comite
ef0d58bb54

+ 1 - 0
Include/RmlUi/Core/ID.h

@@ -51,6 +51,7 @@ enum class ShorthandId : uint8_t {
 	BorderLeft,
 	BorderLeft,
 	Border,
 	Border,
 	BorderRadius,
 	BorderRadius,
+	Inset,
 	Overflow,
 	Overflow,
 	Background,
 	Background,
 	Font,
 	Font,

+ 1 - 4
Samples/basic/demo/data/demo.rml

@@ -38,10 +38,7 @@
 
 
 body.window
 body.window
 {
 {
-	left: 80dp;
-	right: 80dp;
-	top: 50dp;
-	bottom: 50dp;
+	inset: 50dp 80dp;
 	min-width: 1040dp;
 	min-width: 1040dp;
 	min-height: 300dp;
 	min-height: 300dp;
 	max-width: none;
 	max-width: none;

+ 1 - 0
Source/Core/StyleSheetSpecification.cpp

@@ -338,6 +338,7 @@ void StyleSheetSpecification::RegisterDefaultProperties()
 	RegisterProperty(PropertyId::Right, "right", "auto", false, false).AddParser("keyword", "auto").AddParser("length_percent").SetRelativeTarget(RelativeTarget::ContainingBlockWidth);
 	RegisterProperty(PropertyId::Right, "right", "auto", false, false).AddParser("keyword", "auto").AddParser("length_percent").SetRelativeTarget(RelativeTarget::ContainingBlockWidth);
 	RegisterProperty(PropertyId::Bottom, "bottom", "auto", false, false).AddParser("keyword", "auto").AddParser("length_percent").SetRelativeTarget(RelativeTarget::ContainingBlockHeight);
 	RegisterProperty(PropertyId::Bottom, "bottom", "auto", false, false).AddParser("keyword", "auto").AddParser("length_percent").SetRelativeTarget(RelativeTarget::ContainingBlockHeight);
 	RegisterProperty(PropertyId::Left, "left", "auto", false, false).AddParser("keyword", "auto").AddParser("length_percent").SetRelativeTarget(RelativeTarget::ContainingBlockWidth);
 	RegisterProperty(PropertyId::Left, "left", "auto", false, false).AddParser("keyword", "auto").AddParser("length_percent").SetRelativeTarget(RelativeTarget::ContainingBlockWidth);
+	RegisterShorthand(ShorthandId::Inset, "inset", "top, right, bottom, left", ShorthandType::Box);
 
 
 	RegisterProperty(PropertyId::Float, "float", "none", false, true).AddParser("keyword", "none, left, right");
 	RegisterProperty(PropertyId::Float, "float", "none", false, true).AddParser("keyword", "none, left, right");
 	RegisterProperty(PropertyId::Clear, "clear", "none", false, true).AddParser("keyword", "none, left, right, both");
 	RegisterProperty(PropertyId::Clear, "clear", "none", false, true).AddParser("keyword", "none, left, right, both");

+ 35 - 0
Tests/Source/UnitTests/Properties.cpp

@@ -54,6 +54,41 @@ TEST_CASE("Properties")
 	Context* context = Rml::CreateContext("main", window_size);
 	Context* context = Rml::CreateContext("main", window_size);
 	ElementDocument* document = context->CreateDocument();
 	ElementDocument* document = context->CreateDocument();
 
 
+	SUBCASE("inset")
+	{
+		struct InsetTestCase {
+			String inset_value;
+
+			struct ExpectedValues {
+				String top;
+				String right;
+				String bottom;
+				String left;
+			} expected;
+		};
+
+		InsetTestCase tests[] = {
+			{"auto", {"auto", "auto", "auto", "auto"}},
+			{"0", {"0px", "0px", "0px", "0px"}},
+			{"1px", {"1px", "1px", "1px", "1px"}},
+			{"1dp", {"1dp", "1dp", "1dp", "1dp"}},
+			{"1%", {"1%", "1%", "1%", "1%"}},
+			{"10px 20px", {"10px", "20px", "10px", "20px"}},
+			{"10px 20px 30px", {"10px", "20px", "30px", "20px"}},
+			{"10px 20px 30px 40px", {"10px", "20px", "30px", "40px"}},
+		};
+
+		for (const InsetTestCase& test : tests)
+		{
+			CHECK(document->SetProperty("inset", test.inset_value));
+
+			CHECK(document->GetProperty("top")->ToString() == test.expected.top);
+			CHECK(document->GetProperty("right")->ToString() == test.expected.right);
+			CHECK(document->GetProperty("bottom")->ToString() == test.expected.bottom);
+			CHECK(document->GetProperty("left")->ToString() == test.expected.left);
+		}
+	}
+
 	SUBCASE("flex")
 	SUBCASE("flex")
 	{
 	{
 		struct FlexTestCase {
 		struct FlexTestCase {