2
0
Эх сурвалжийг харах

Refactor: Style sheet type names

Michael Ragazzon 2 жил өмнө
parent
commit
b6f70fffcd

+ 3 - 3
Include/RmlUi/Core/StyleSheet.h

@@ -67,8 +67,8 @@ public:
 	/// Builds the node index for a combined style sheet.
 	/// Builds the node index for a combined style sheet.
 	void BuildNodeIndex();
 	void BuildNodeIndex();
 
 
-	/// Returns the DecoratorSpecification of the given name, or null if it does not exist.
-	const DecoratorSpecification* GetDecoratorSpecification(const String& name) const;
+	/// Returns the named @decorator, or null if it does not exist.
+	const NamedDecorator* GetNamedDecorator(const String& name) const;
 
 
 	/// Returns the Keyframes of the given name, or null if it does not exist.
 	/// Returns the Keyframes of the given name, or null if it does not exist.
 	/// @lifetime The returned pointer becomes invalidated whenever the style sheet is re-generated. Do not store this pointer or references to
 	/// @lifetime The returned pointer becomes invalidated whenever the style sheet is re-generated. Do not store this pointer or references to
@@ -103,7 +103,7 @@ private:
 	KeyframesMap keyframes;
 	KeyframesMap keyframes;
 
 
 	// Name of every @decorator mapped to their specification
 	// Name of every @decorator mapped to their specification
-	DecoratorSpecificationMap decorator_map;
+	NamedDecoratorMap decorator_map;
 
 
 	// Name of every @spritesheet and underlying sprites mapped to their values
 	// Name of every @spritesheet and underlying sprites mapped to their values
 	SpritesheetList spritesheet_list;
 	SpritesheetList spritesheet_list;

+ 3 - 18
Include/RmlUi/Core/StyleSheetTypes.h

@@ -52,33 +52,18 @@ struct Keyframes {
 };
 };
 using KeyframesMap = UnorderedMap<String, Keyframes>;
 using KeyframesMap = UnorderedMap<String, Keyframes>;
 
 
-struct DecoratorSpecification {
-	String decorator_type;
+struct NamedDecorator {
+	String type;
 	PropertyDictionary properties;
 	PropertyDictionary properties;
 	SharedPtr<Decorator> decorator;
 	SharedPtr<Decorator> decorator;
 };
 };
-using DecoratorSpecificationMap = UnorderedMap<String, DecoratorSpecification>;
+using NamedDecoratorMap = UnorderedMap<String, NamedDecorator>;
 
 
 struct DecoratorDeclaration {
 struct DecoratorDeclaration {
 	String type;
 	String type;
 	DecoratorInstancer* instancer;
 	DecoratorInstancer* instancer;
 	PropertyDictionary properties;
 	PropertyDictionary properties;
 };
 };
-
-struct DecoratorDeclarationView {
-	DecoratorDeclarationView(const DecoratorDeclaration& declaration) :
-		type(declaration.type), instancer(declaration.instancer), properties(declaration.properties)
-	{}
-	DecoratorDeclarationView(const DecoratorSpecification* specification) :
-		type(specification->decorator_type), instancer(Factory::GetDecoratorInstancer(specification->decorator_type)),
-		properties(specification->properties)
-	{}
-
-	const String& type;
-	DecoratorInstancer* instancer;
-	const PropertyDictionary& properties;
-};
-
 struct DecoratorDeclarationList {
 struct DecoratorDeclarationList {
 	Vector<DecoratorDeclaration> list;
 	Vector<DecoratorDeclaration> list;
 	String value;
 	String value;

+ 17 - 9
Source/Core/ElementAnimation.cpp

@@ -169,31 +169,39 @@ static Property InterpolateProperties(const Property& p0, const Property& p1, fl
 		return Property{TransformPtr(std::move(t)), Unit::TRANSFORM};
 		return Property{TransformPtr(std::move(t)), Unit::TRANSFORM};
 	}
 	}
 
 
+	struct DecoratorDeclarationView {
+		DecoratorDeclarationView(const DecoratorDeclaration& declaration) :
+			type(declaration.type), instancer(declaration.instancer), properties(declaration.properties)
+		{}
+		DecoratorDeclarationView(const NamedDecorator* specification) :
+			type(specification->type), instancer(Factory::GetDecoratorInstancer(specification->type)), properties(specification->properties)
+		{}
+		const String& type;
+		DecoratorInstancer* instancer;
+		const PropertyDictionary& properties;
+	};
+
 	if (p0.unit == Unit::DECORATOR && p1.unit == Unit::DECORATOR)
 	if (p0.unit == Unit::DECORATOR && p1.unit == Unit::DECORATOR)
 	{
 	{
 		auto DiscreteInterpolation = [&]() { return alpha < 0.5f ? p0 : p1; };
 		auto DiscreteInterpolation = [&]() { return alpha < 0.5f ? p0 : p1; };
 
 
-		// We construct DecoratorDeclarationView from declaration if it has instancer, otherwise we look for DecoratorSpecification and return
-		// DecoratorDeclarationView from it
+		// If we have an instancer we pass that directly to the declaration view, otherwise look for a named @decorator.
 		auto GetDecoratorDeclarationView = [&](const DecoratorDeclaration& declaration) -> DecoratorDeclarationView {
 		auto GetDecoratorDeclarationView = [&](const DecoratorDeclaration& declaration) -> DecoratorDeclarationView {
 			if (declaration.instancer)
 			if (declaration.instancer)
 				return DecoratorDeclarationView{declaration};
 				return DecoratorDeclarationView{declaration};
 
 
 			const StyleSheet* style_sheet = element.GetStyleSheet();
 			const StyleSheet* style_sheet = element.GetStyleSheet();
 			if (!style_sheet)
 			if (!style_sheet)
-			{
-				Log::Message(Log::LT_WARNING, "Failed to get element stylesheet for '%s' decorator rule.", declaration.type.c_str());
 				return DecoratorDeclarationView{declaration};
 				return DecoratorDeclarationView{declaration};
-			}
 
 
-			const DecoratorSpecification* specification = style_sheet->GetDecoratorSpecification(declaration.type);
-			if (!specification)
+			const NamedDecorator* named_decorator = style_sheet->GetNamedDecorator(declaration.type);
+			if (!named_decorator)
 			{
 			{
-				Log::Message(Log::LT_WARNING, "Could not find DecoratorSpecification for '%s' decorator rule.", declaration.type.c_str());
+				Log::Message(Log::LT_WARNING, "Could not find a named @decorator '%s'.", declaration.type.c_str());
 				return DecoratorDeclarationView{declaration};
 				return DecoratorDeclarationView{declaration};
 			}
 			}
 
 
-			return DecoratorDeclarationView{specification};
+			return DecoratorDeclarationView{named_decorator};
 		};
 		};
 
 
 		auto& ptr0 = p0.value.GetReference<DecoratorsPtr>();
 		auto& ptr0 = p0.value.GetReference<DecoratorsPtr>();

+ 1 - 1
Source/Core/StyleSheet.cpp

@@ -97,7 +97,7 @@ void StyleSheet::BuildNodeIndex()
 	root->BuildIndex(styled_node_index);
 	root->BuildIndex(styled_node_index);
 }
 }
 
 
-const DecoratorSpecification* StyleSheet::GetDecoratorSpecification(const String& name) const
+const NamedDecorator* StyleSheet::GetNamedDecorator(const String& name) const
 {
 {
 	auto it = decorator_map.find(name);
 	auto it = decorator_map.find(name);
 	if (it != decorator_map.end())
 	if (it != decorator_map.end())

+ 4 - 4
Source/Core/StyleSheetParser.cpp

@@ -325,7 +325,7 @@ bool StyleSheetParser::ParseKeyframeBlock(KeyframesMap& keyframes_map, const Str
 	return true;
 	return true;
 }
 }
 
 
-bool StyleSheetParser::ParseDecoratorBlock(const String& at_name, DecoratorSpecificationMap& decorator_map, const StyleSheet& style_sheet,
+bool StyleSheetParser::ParseDecoratorBlock(const String& at_name, NamedDecoratorMap& decorator_map, const StyleSheet& style_sheet,
 	const SharedPtr<const PropertySource>& source)
 	const SharedPtr<const PropertySource>& source)
 {
 {
 	StringList name_type;
 	StringList name_type;
@@ -360,9 +360,9 @@ bool StyleSheetParser::ParseDecoratorBlock(const String& at_name, DecoratorSpeci
 		if (it != decorator_map.end())
 		if (it != decorator_map.end())
 		{
 		{
 			// Yes, try to retrieve the instancer from the parent type, and add its property values.
 			// Yes, try to retrieve the instancer from the parent type, and add its property values.
-			decorator_instancer = Factory::GetDecoratorInstancer(it->second.decorator_type);
+			decorator_instancer = Factory::GetDecoratorInstancer(it->second.type);
 			properties = it->second.properties;
 			properties = it->second.properties;
-			decorator_type = it->second.decorator_type;
+			decorator_type = it->second.type;
 		}
 		}
 
 
 		// If we still don't have an instancer, we cannot continue.
 		// If we still don't have an instancer, we cannot continue.
@@ -393,7 +393,7 @@ bool StyleSheetParser::ParseDecoratorBlock(const String& at_name, DecoratorSpeci
 		return false;
 		return false;
 	}
 	}
 
 
-	decorator_map.emplace(name, DecoratorSpecification{std::move(decorator_type), std::move(properties), std::move(decorator)});
+	decorator_map.emplace(name, NamedDecorator{std::move(decorator_type), std::move(properties), std::move(decorator)});
 
 
 	return true;
 	return true;
 }
 }

+ 1 - 1
Source/Core/StyleSheetParser.h

@@ -105,7 +105,7 @@ private:
 	bool ParseKeyframeBlock(KeyframesMap& keyframes_map, const String& identifier, const String& rules, const PropertyDictionary& properties);
 	bool ParseKeyframeBlock(KeyframesMap& keyframes_map, const String& identifier, const String& rules, const PropertyDictionary& properties);
 
 
 	// Attempts to parse a @decorator block
 	// Attempts to parse a @decorator block
-	bool ParseDecoratorBlock(const String& at_name, DecoratorSpecificationMap& decorator_map, const StyleSheet& style_sheet,
+	bool ParseDecoratorBlock(const String& at_name, NamedDecoratorMap& decorator_map, const StyleSheet& style_sheet,
 		const SharedPtr<const PropertySource>& source);
 		const SharedPtr<const PropertySource>& source);
 
 
 	// Attempts to parse the properties of a @media query
 	// Attempts to parse the properties of a @media query