Browse Source

Computed values spec

Michael Ragazzon 6 years ago
parent
commit
d59adecf25
2 changed files with 123 additions and 0 deletions
  1. 2 0
      Samples/basic/benchmark/src/main.cpp
  2. 121 0
      Source/Core/StyleSheetSpecification.cpp

+ 2 - 0
Samples/basic/benchmark/src/main.cpp

@@ -38,6 +38,8 @@
 //  - Memory pools for common elements. Also, a lot of temporary objects are created and destroyed.
 //  - Memory pools for common elements. Also, a lot of temporary objects are created and destroyed.
 //  - Try replacing ElementAttributes with vector.
 //  - Try replacing ElementAttributes with vector.
 //  - Can we optimize the layouting? E.g. why is ElementTextDefault::GenerateLine being called even when neither text nor size have seemingly been changed.
 //  - Can we optimize the layouting? E.g. why is ElementTextDefault::GenerateLine being called even when neither text nor size have seemingly been changed.
+//  - During first update after construction: Create computed values of all properties, and use these instead of GetProperty. 
+//       Instead, GetComputedValue which gives either absolute length, percentage, keywords (enum), color, etc. Inherited values then only need to check their nearest parent.
 //  - [bug] Input.range appears only after one additional frame.
 //  - [bug] Input.range appears only after one additional frame.
 
 
 class DemoWindow
 class DemoWindow

+ 121 - 0
Source/Core/StyleSheetSpecification.cpp

@@ -154,6 +154,127 @@ void StyleSheetSpecification::RegisterDefaultParsers()
 	RegisterParser(TRANSFORM, new PropertyParserTransform());
 	RegisterParser(TRANSFORM, new PropertyParserTransform());
 }
 }
 
 
+
+namespace RCSS 
+{
+	struct LengthPercentageAuto {
+		enum Type { Length, Percentage, Auto } type = Length;
+		float value = 0;
+		LengthPercentageAuto() {}
+		LengthPercentageAuto(Type type, float value = 0) : type(type), value(value) {}
+	};
+	struct LengthPercentage {
+		enum Type { Length, Percentage } type = Length;
+		float value = 0;
+	};
+
+	struct NumberAuto {
+		enum Type { Number, Auto } type = Number;
+		float value = 0;
+		NumberAuto() {}
+		NumberAuto(Type type, float value = 0) : type(type), value(value) {}
+	};
+
+	enum class Display { None, Block, Inline, InlineBlock };
+	enum class Position { Static, Relative, Absolute, Fixed };
+
+	enum class Float { None, Left, Right };
+	enum class Clear { None, Left, Right, Both };
+
+	struct VerticalAlign {
+		enum Type { Baseline, Middle, Sub, Super, TextTop, TextBottom, Top, Bottom, Length } type = Baseline;
+		float value = 0; // For length type
+	};
+
+
+	enum class Overflow { Visible, Hidden, Auto, Scroll };
+
+	struct Clip {
+		enum Type { Auto, Number, None } type = Auto;
+		float value;
+	};
+
+	enum class Visibility { Visible, Hidden };
+
+	enum class FontStyle { Normal, Italic };
+	enum class FontWeight { Normal, Bold };
+
+	enum class TextAlign { Left, Right, Center, Justify };
+	enum class TextDecoration { None, Underline };
+	enum class TextTransform { None, Capitalize, Uppercase, Lowercase };
+	enum class WhiteSpace { Normal, Pre, Nowrap, Prewrap, Preline };
+
+	enum class Drag { None, Drag, DragDrop, Block, Clone };
+	enum class TabIndex { None, Auto };
+	enum class Focus { None, Auto };
+	enum class PointerEvents { None, Auto };
+
+
+	struct ComputedValues 
+	{
+		LengthPercentageAuto margin_top, margin_right, margin_bottom, margin_left;
+		LengthPercentage padding_top, padding_right, padding_bottom, padding_left;
+		float border_top_width = 0, border_right_width = 0, border_bottom_width = 0, border_left_width = 0;
+		Colourb border_top_color{ 255, 255, 255 }, border_right_color{ 255, 255, 255 }, border_bottom_color{ 255, 255, 255 }, border_left_color{ 255, 255, 255 };
+
+		Display display = Display::Inline;
+		Position position = Position::Static;
+
+		LengthPercentageAuto top{ LengthPercentageAuto::Auto }, right{ LengthPercentageAuto::Auto }, bottom{ LengthPercentageAuto::Auto }, left{ LengthPercentageAuto::Auto };
+
+		Float _float = Float::None;
+		Clear clear = Clear::None;
+
+		NumberAuto z_index = { NumberAuto::Auto };
+
+		LengthPercentageAuto width = { LengthPercentageAuto::Auto };
+		LengthPercentage min_width, max_width;
+		LengthPercentageAuto height = { LengthPercentageAuto::Auto };
+		LengthPercentage min_height, max_height;
+	
+		float line_height = 1.2f;
+		VerticalAlign vertical_align;
+	
+		Overflow overflow_x = Overflow::Visible, overflow_y = Overflow::Visible;
+		Clip clip;
+
+		Visibility visibility = Visibility::Visible;
+
+		Colourb background_color = Colourb(255, 255, 255, 0);
+		Colourb color = Colourb(255, 255, 255);
+		Colourb image_color = Colourb(255, 255, 255);
+		float opacity = 1;
+
+		String font_family;
+		String font_charset; // empty is same as "U+0020-007E"
+		FontStyle font_style = FontStyle::Normal;
+		FontWeight font_weight = FontWeight::Normal;
+		LengthPercentage font_size;
+
+		TextAlign text_align = TextAlign::Left;
+		TextDecoration text_decoration = TextDecoration::None;
+		TextTransform text_transform = TextTransform::None;
+		WhiteSpace white_space = WhiteSpace::Normal;
+
+		String cursor;
+
+		Drag drag = Drag::None;
+		TabIndex tab_index = TabIndex::None;
+		Focus focus = Focus::Auto;
+		float scrollbar_margin = 0;
+		PointerEvents pointer_events = PointerEvents::Auto;
+
+		float perspective = 0;
+		float perspective_origin_x = 0.5f, perspective_origin_y = 0.5f; // Relative
+
+		String transform;
+		float transform_origin_x = 0.5f, transform_origin_y = 0.5f, transform_origin_z = 0.f;
+
+		String transition; // empty is same as "none"
+		String animation;  // empty is same as "none"
+	};
+}
+
 // Registers Rocket's default style properties.
 // Registers Rocket's default style properties.
 void StyleSheetSpecification::RegisterDefaultProperties()
 void StyleSheetSpecification::RegisterDefaultProperties()
 {
 {