ComputedValues.h 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441
  1. /*
  2. * This source file is part of RmlUi, the HTML/CSS Interface Middleware
  3. *
  4. * For the latest information, see http://github.com/mikke89/RmlUi
  5. *
  6. * Copyright (c) 2019-2023 The RmlUi Team, and contributors
  7. *
  8. * Permission is hereby granted, free of charge, to any person obtaining a copy
  9. * of this software and associated documentation files (the "Software"), to deal
  10. * in the Software without restriction, including without limitation the rights
  11. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  12. * copies of the Software, and to permit persons to whom the Software is
  13. * furnished to do so, subject to the following conditions:
  14. *
  15. * The above copyright notice and this permission notice shall be included in
  16. * all copies or substantial portions of the Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  19. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  20. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  21. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  22. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  23. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  24. * THE SOFTWARE.
  25. *
  26. */
  27. #ifndef RMLUI_CORE_COMPUTEDVALUES_H
  28. #define RMLUI_CORE_COMPUTEDVALUES_H
  29. #include "Animation.h"
  30. #include "Element.h"
  31. #include "StyleTypes.h"
  32. #include "Types.h"
  33. #include <cfloat>
  34. namespace Rml {
  35. namespace Style {
  36. /*
  37. A computed value is a value resolved as far as possible :before: introducing layouting. See CSS specs for details of each property.
  38. Note: Enums and default values must correspond to the keywords and defaults in `StyleSheetSpecification.cpp`.
  39. */
  40. struct CommonValues {
  41. CommonValues() :
  42. display(Display::Inline), position(Position::Static), float_(Float::None), clear(Clear::None), overflow_x(Overflow::Visible),
  43. overflow_y(Overflow::Visible), visibility(Visibility::Visible),
  44. has_decorator(false), box_sizing(BoxSizing::ContentBox),
  45. width_type(LengthPercentageAuto::Auto), height_type(LengthPercentageAuto::Auto),
  46. margin_top_type(LengthPercentageAuto::Length), margin_right_type(LengthPercentageAuto::Length),
  47. margin_bottom_type(LengthPercentageAuto::Length), margin_left_type(LengthPercentageAuto::Length),
  48. padding_top_type(LengthPercentage::Length), padding_right_type(LengthPercentage::Length), padding_bottom_type(LengthPercentage::Length),
  49. padding_left_type(LengthPercentage::Length),
  50. top_type(LengthPercentageAuto::Auto), right_type(LengthPercentageAuto::Auto), bottom_type(LengthPercentageAuto::Auto),
  51. left_type(LengthPercentageAuto::Auto), z_index_type(NumberAuto::Auto)
  52. {}
  53. Display display : 4;
  54. Position position : 2;
  55. Float float_ : 2;
  56. Clear clear : 2;
  57. Overflow overflow_x : 2, overflow_y : 2;
  58. Visibility visibility : 1;
  59. bool has_decorator : 1;
  60. BoxSizing box_sizing : 1;
  61. LengthPercentageAuto::Type width_type : 2, height_type : 2;
  62. LengthPercentageAuto::Type margin_top_type : 2, margin_right_type : 2, margin_bottom_type : 2, margin_left_type : 2;
  63. LengthPercentage::Type padding_top_type : 1, padding_right_type : 1, padding_bottom_type : 1, padding_left_type : 1;
  64. LengthPercentageAuto::Type top_type : 2, right_type : 2, bottom_type : 2, left_type : 2;
  65. NumberAuto::Type z_index_type : 1;
  66. float width_value = 0;
  67. float height_value = 0;
  68. float margin_top_value = 0;
  69. float margin_right_value = 0;
  70. float margin_bottom_value = 0;
  71. float margin_left_value = 0;
  72. float padding_top_value = 0;
  73. float padding_right_value = 0;
  74. float padding_bottom_value = 0;
  75. float padding_left_value = 0;
  76. float top_value = 0;
  77. float right_value = 0;
  78. float bottom_value = 0;
  79. float left_value = 0;
  80. float z_index_value = 0;
  81. uint16_t border_top_width = 0, border_right_width = 0, border_bottom_width = 0, border_left_width = 0;
  82. Colourb border_top_color{255, 255, 255}, border_right_color{255, 255, 255}, border_bottom_color{255, 255, 255},
  83. border_left_color{255, 255, 255};
  84. Colourb background_color = Colourb(0, 0, 0, 0);
  85. };
  86. struct InheritedValues {
  87. InheritedValues() :
  88. font_weight(FontWeight::Normal), has_letter_spacing(0), font_style(FontStyle::Normal), has_font_effect(false),
  89. pointer_events(PointerEvents::Auto), focus(Focus::Auto), text_align(TextAlign::Left), text_decoration(TextDecoration::None),
  90. text_transform(TextTransform::None), white_space(WhiteSpace::Normal), word_break(WordBreak::Normal),
  91. direction(Direction::Auto), line_height_inherit_type(LineHeight::Number)
  92. {}
  93. // Font face used to render text and resolve ex properties. Does not represent a true property
  94. // like most computed values, but placed here as it is used and inherited in a similar manner.
  95. FontFaceHandle font_face_handle = 0;
  96. float font_size = 12.f;
  97. float opacity = 1;
  98. Colourb color = Colourb(255, 255, 255);
  99. FontWeight font_weight : 10;
  100. uint16_t has_letter_spacing : 1;
  101. FontStyle font_style : 1;
  102. bool has_font_effect : 1;
  103. PointerEvents pointer_events : 1;
  104. Focus focus : 1;
  105. TextAlign text_align : 2;
  106. TextDecoration text_decoration : 2;
  107. TextTransform text_transform : 2;
  108. WhiteSpace white_space : 3;
  109. WordBreak word_break : 2;
  110. Direction direction : 2;
  111. LineHeight::InheritType line_height_inherit_type : 1;
  112. float line_height = 12.f * 1.2f;
  113. float line_height_inherit = 1.2f;
  114. String language = "";
  115. };
  116. struct RareValues {
  117. RareValues() :
  118. min_width_type(LengthPercentage::Length), max_width_type(LengthPercentage::Length), min_height_type(LengthPercentage::Length),
  119. max_height_type(LengthPercentage::Length),
  120. perspective_origin_x_type(LengthPercentage::Percentage), perspective_origin_y_type(LengthPercentage::Percentage),
  121. transform_origin_x_type(LengthPercentage::Percentage), transform_origin_y_type(LengthPercentage::Percentage), has_local_transform(false),
  122. has_local_perspective(false),
  123. flex_basis_type(LengthPercentageAuto::Auto), row_gap_type(LengthPercentage::Length), column_gap_type(LengthPercentage::Length),
  124. vertical_align_type(VerticalAlign::Baseline), drag(Drag::None), tab_index(TabIndex::None), overscroll_behavior(OverscrollBehavior::Auto)
  125. {}
  126. LengthPercentage::Type min_width_type : 1, max_width_type : 1;
  127. LengthPercentage::Type min_height_type : 1, max_height_type : 1;
  128. LengthPercentage::Type perspective_origin_x_type : 1, perspective_origin_y_type : 1;
  129. LengthPercentage::Type transform_origin_x_type : 1, transform_origin_y_type : 1;
  130. bool has_local_transform : 1, has_local_perspective : 1;
  131. LengthPercentageAuto::Type flex_basis_type : 2;
  132. LengthPercentage::Type row_gap_type : 1, column_gap_type : 1;
  133. VerticalAlign::Type vertical_align_type : 4;
  134. Drag drag : 3;
  135. TabIndex tab_index : 1;
  136. OverscrollBehavior overscroll_behavior : 1;
  137. Clip clip;
  138. float min_width = 0, max_width = FLT_MAX;
  139. float min_height = 0, max_height = FLT_MAX;
  140. float vertical_align_length = 0;
  141. float perspective = 0;
  142. float perspective_origin_x = 50.f;
  143. float perspective_origin_y = 50.f;
  144. float transform_origin_x = 50.f;
  145. float transform_origin_y = 50.f;
  146. float transform_origin_z = 0.0f;
  147. float flex_basis = 0;
  148. float row_gap = 0, column_gap = 0;
  149. int16_t border_top_left_radius = 0, border_top_right_radius = 0, border_bottom_right_radius = 0, border_bottom_left_radius = 0;
  150. Colourb image_color = Colourb(255, 255, 255);
  151. float scrollbar_margin = 0.f;
  152. };
  153. class ComputedValues : NonCopyMoveable {
  154. public:
  155. explicit ComputedValues(Element* element) : element(element) {}
  156. // clang-format off
  157. // -- Common --
  158. LengthPercentageAuto width() const { return LengthPercentageAuto(common.width_type, common.width_value); }
  159. LengthPercentageAuto height() const { return LengthPercentageAuto(common.height_type, common.height_value); }
  160. LengthPercentageAuto margin_top() const { return LengthPercentageAuto(common.margin_top_type, common.margin_top_value); }
  161. LengthPercentageAuto margin_right() const { return LengthPercentageAuto(common.margin_right_type, common.margin_right_value); }
  162. LengthPercentageAuto margin_bottom() const { return LengthPercentageAuto(common.margin_bottom_type, common.margin_bottom_value); }
  163. LengthPercentageAuto margin_left() const { return LengthPercentageAuto(common.margin_left_type, common.margin_left_value); }
  164. LengthPercentage padding_top() const { return LengthPercentage(common.padding_top_type, common.padding_top_value); }
  165. LengthPercentage padding_right() const { return LengthPercentage(common.padding_right_type, common.padding_right_value); }
  166. LengthPercentage padding_bottom() const { return LengthPercentage(common.padding_bottom_type, common.padding_bottom_value); }
  167. LengthPercentage padding_left() const { return LengthPercentage(common.padding_left_type, common.padding_left_value); }
  168. LengthPercentageAuto top() const { return LengthPercentageAuto(common.top_type, common.top_value); }
  169. LengthPercentageAuto right() const { return LengthPercentageAuto(common.right_type, common.right_value); }
  170. LengthPercentageAuto bottom() const { return LengthPercentageAuto(common.bottom_type, common.bottom_value); }
  171. LengthPercentageAuto left() const { return LengthPercentageAuto(common.left_type, common.left_value); }
  172. NumberAuto z_index() const { return NumberAuto(common.z_index_type, common.z_index_value); }
  173. float border_top_width() const { return (float)common.border_top_width; }
  174. float border_right_width() const { return (float)common.border_right_width; }
  175. float border_bottom_width() const { return (float)common.border_bottom_width; }
  176. float border_left_width() const { return (float)common.border_left_width; }
  177. BoxSizing box_sizing() const { return common.box_sizing; }
  178. Display display() const { return common.display; }
  179. Position position() const { return common.position; }
  180. Float float_() const { return common.float_; }
  181. Clear clear() const { return common.clear; }
  182. Overflow overflow_x() const { return common.overflow_x; }
  183. Overflow overflow_y() const { return common.overflow_y; }
  184. Visibility visibility() const { return common.visibility; }
  185. Colourb background_color() const { return common.background_color; }
  186. Colourb border_top_color() const { return common.border_top_color; }
  187. Colourb border_right_color() const { return common.border_right_color; }
  188. Colourb border_bottom_color() const { return common.border_bottom_color; }
  189. Colourb border_left_color() const { return common.border_left_color; }
  190. bool has_decorator() const { return common.has_decorator; }
  191. // -- Inherited --
  192. String font_family() const;
  193. String cursor() const;
  194. FontFaceHandle font_face_handle() const { return inherited.font_face_handle; }
  195. float font_size() const { return inherited.font_size; }
  196. float letter_spacing() const;
  197. bool has_font_effect() const { return inherited.has_font_effect; }
  198. FontStyle font_style() const { return inherited.font_style; }
  199. FontWeight font_weight() const { return inherited.font_weight; }
  200. PointerEvents pointer_events() const { return inherited.pointer_events; }
  201. Focus focus() const { return inherited.focus; }
  202. TextAlign text_align() const { return inherited.text_align; }
  203. TextDecoration text_decoration() const { return inherited.text_decoration; }
  204. TextTransform text_transform() const { return inherited.text_transform; }
  205. WhiteSpace white_space() const { return inherited.white_space; }
  206. WordBreak word_break() const { return inherited.word_break; }
  207. Colourb color() const { return inherited.color; }
  208. float opacity() const { return inherited.opacity; }
  209. LineHeight line_height() const { return LineHeight(inherited.line_height, inherited.line_height_inherit_type, inherited.line_height_inherit); }
  210. const String& language() const { return inherited.language; }
  211. Direction direction() const { return inherited.direction; }
  212. // -- Rare --
  213. MinWidth min_width() const { return LengthPercentage(rare.min_width_type, rare.min_width); }
  214. MaxWidth max_width() const { return LengthPercentage(rare.max_width_type, rare.max_width); }
  215. MinHeight min_height() const { return LengthPercentage(rare.min_height_type, rare.min_height); }
  216. MinHeight max_height() const { return LengthPercentage(rare.max_height_type, rare.max_height); }
  217. VerticalAlign vertical_align() const { return VerticalAlign(rare.vertical_align_type, rare.vertical_align_length); }
  218. const AnimationList* animation() const;
  219. const TransitionList* transition() const;
  220. float perspective() const { return rare.perspective; }
  221. PerspectiveOrigin perspective_origin_x() const { return LengthPercentage(rare.perspective_origin_x_type, rare.perspective_origin_x); }
  222. PerspectiveOrigin perspective_origin_y() const { return LengthPercentage(rare.perspective_origin_y_type, rare.perspective_origin_y); }
  223. TransformPtr transform() const { return GetLocalProperty(PropertyId::Transform, TransformPtr()); }
  224. TransformOrigin transform_origin_x() const { return LengthPercentage(rare.transform_origin_x_type, rare.transform_origin_x); }
  225. TransformOrigin transform_origin_y() const { return LengthPercentage(rare.transform_origin_y_type, rare.transform_origin_y); }
  226. float transform_origin_z() const { return rare.transform_origin_z; }
  227. bool has_local_transform() const { return rare.has_local_transform; }
  228. bool has_local_perspective() const { return rare.has_local_perspective; }
  229. AlignContent align_content() const { return GetLocalPropertyKeyword(PropertyId::AlignContent, AlignContent::Stretch); }
  230. AlignItems align_items() const { return GetLocalPropertyKeyword(PropertyId::AlignItems, AlignItems::Stretch); }
  231. AlignSelf align_self() const { return GetLocalPropertyKeyword(PropertyId::AlignSelf, AlignSelf::Auto); }
  232. FlexDirection flex_direction() const { return GetLocalPropertyKeyword(PropertyId::FlexDirection, FlexDirection::Row); }
  233. FlexWrap flex_wrap() const { return GetLocalPropertyKeyword(PropertyId::FlexWrap, FlexWrap::Nowrap); }
  234. JustifyContent justify_content() const { return GetLocalPropertyKeyword(PropertyId::JustifyContent, JustifyContent::FlexStart); }
  235. float flex_grow() const { return GetLocalProperty(PropertyId::FlexGrow, 0.f); }
  236. float flex_shrink() const { return GetLocalProperty(PropertyId::FlexShrink, 1.f); }
  237. FlexBasis flex_basis() const { return LengthPercentageAuto(rare.flex_basis_type, rare.flex_basis); }
  238. float border_top_left_radius() const { return (float)rare.border_top_left_radius; }
  239. float border_top_right_radius() const { return (float)rare.border_top_right_radius; }
  240. float border_bottom_right_radius() const { return (float)rare.border_bottom_right_radius; }
  241. float border_bottom_left_radius() const { return (float)rare.border_bottom_left_radius; }
  242. Clip clip() const { return rare.clip; }
  243. Drag drag() const { return rare.drag; }
  244. TabIndex tab_index() const { return rare.tab_index; }
  245. Colourb image_color() const { return rare.image_color; }
  246. LengthPercentage row_gap() const { return LengthPercentage(rare.row_gap_type, rare.row_gap); }
  247. LengthPercentage column_gap() const { return LengthPercentage(rare.column_gap_type, rare.column_gap); }
  248. OverscrollBehavior overscroll_behavior() const { return rare.overscroll_behavior; }
  249. float scrollbar_margin() const { return rare.scrollbar_margin; }
  250. // -- Assignment --
  251. // Common
  252. void width (LengthPercentageAuto value) { common.width_type = value.type; common.width_value = value.value; }
  253. void height (LengthPercentageAuto value) { common.height_type = value.type; common.height_value = value.value; }
  254. void margin_top (LengthPercentageAuto value) { common.margin_top_type = value.type; common.margin_top_value = value.value; }
  255. void margin_right (LengthPercentageAuto value) { common.margin_right_type = value.type; common.margin_right_value = value.value; }
  256. void margin_bottom (LengthPercentageAuto value) { common.margin_bottom_type = value.type; common.margin_bottom_value = value.value; }
  257. void margin_left (LengthPercentageAuto value) { common.margin_left_type = value.type; common.margin_left_value = value.value; }
  258. void padding_top (LengthPercentage value) { common.padding_top_type = value.type; common.padding_top_value = value.value; }
  259. void padding_right (LengthPercentage value) { common.padding_right_type = value.type; common.padding_right_value = value.value; }
  260. void padding_bottom (LengthPercentage value) { common.padding_bottom_type = value.type; common.padding_bottom_value = value.value; }
  261. void padding_left (LengthPercentage value) { common.padding_left_type = value.type; common.padding_left_value = value.value; }
  262. void top (LengthPercentageAuto value) { common.top_type = value.type; common.top_value = value.value; }
  263. void right (LengthPercentageAuto value) { common.right_type = value.type; common.right_value = value.value; }
  264. void bottom (LengthPercentageAuto value) { common.bottom_type = value.type; common.bottom_value = value.value; }
  265. void left (LengthPercentageAuto value) { common.left_type = value.type; common.left_value = value.value; }
  266. void z_index (NumberAuto value) { common.z_index_type = value.type; common.z_index_value = value.value; }
  267. void border_top_width (int16_t value) { common.border_top_width = value; }
  268. void border_right_width (int16_t value) { common.border_right_width = value; }
  269. void border_bottom_width(int16_t value) { common.border_bottom_width = value; }
  270. void border_left_width (int16_t value) { common.border_left_width = value; }
  271. void box_sizing (BoxSizing value) { common.box_sizing = value; }
  272. void display (Display value) { common.display = value; }
  273. void position (Position value) { common.position = value; }
  274. void float_ (Float value) { common.float_ = value; }
  275. void clear (Clear value) { common.clear = value; }
  276. void overflow_x (Overflow value) { common.overflow_x = value; }
  277. void overflow_y (Overflow value) { common.overflow_y = value; }
  278. void visibility (Visibility value) { common.visibility = value; }
  279. void background_color (Colourb value) { common.background_color = value; }
  280. void border_top_color (Colourb value) { common.border_top_color = value; }
  281. void border_right_color (Colourb value) { common.border_right_color = value; }
  282. void border_bottom_color(Colourb value) { common.border_bottom_color = value; }
  283. void border_left_color (Colourb value) { common.border_left_color = value; }
  284. void has_decorator (bool value) { common.has_decorator = value; }
  285. // Inherited
  286. void font_face_handle (FontFaceHandle value) { inherited.font_face_handle = value; }
  287. void font_size (float value) { inherited.font_size = value; }
  288. void has_letter_spacing(bool value) { inherited.has_letter_spacing = value; }
  289. void has_font_effect (bool value) { inherited.has_font_effect = value; }
  290. void font_style (FontStyle value) { inherited.font_style = value; }
  291. void font_weight (FontWeight value) { inherited.font_weight = value; }
  292. void pointer_events (PointerEvents value) { inherited.pointer_events = value; }
  293. void focus (Focus value) { inherited.focus = value; }
  294. void text_align (TextAlign value) { inherited.text_align = value; }
  295. void text_decoration (TextDecoration value) { inherited.text_decoration = value; }
  296. void text_transform (TextTransform value) { inherited.text_transform = value; }
  297. void white_space (WhiteSpace value) { inherited.white_space = value; }
  298. void word_break (WordBreak value) { inherited.word_break = value; }
  299. void color (Colourb value) { inherited.color = value; }
  300. void opacity (float value) { inherited.opacity = value; }
  301. void line_height (LineHeight value) { inherited.line_height = value.value; inherited.line_height_inherit_type = value.inherit_type; inherited.line_height_inherit = value.inherit_value; }
  302. void language (const String& value) { inherited.language = value; }
  303. void direction (Direction value) { inherited.direction = value; }
  304. // Rare
  305. void min_width (MinWidth value) { rare.min_width_type = value.type; rare.min_width = value.value; }
  306. void max_width (MaxWidth value) { rare.max_width_type = value.type; rare.max_width = value.value; }
  307. void min_height (MinHeight value) { rare.min_height_type = value.type; rare.min_height = value.value; }
  308. void max_height (MaxHeight value) { rare.max_height_type = value.type; rare.max_height = value.value; }
  309. void vertical_align (VerticalAlign value) { rare.vertical_align_type = value.type; rare.vertical_align_length = value.value; }
  310. void perspective_origin_x (PerspectiveOrigin value) { rare.perspective_origin_x_type = value.type; rare.perspective_origin_x = value.value; }
  311. void perspective_origin_y (PerspectiveOrigin value) { rare.perspective_origin_y_type = value.type; rare.perspective_origin_y = value.value; }
  312. void transform_origin_x (TransformOrigin value) { rare.transform_origin_x_type = value.type; rare.transform_origin_x = value.value; }
  313. void transform_origin_y (TransformOrigin value) { rare.transform_origin_y_type = value.type; rare.transform_origin_y = value.value; }
  314. void row_gap (LengthPercentage value) { rare.row_gap_type = value.type; rare.row_gap = value.value; }
  315. void column_gap (LengthPercentage value) { rare.column_gap_type = value.type; rare.column_gap = value.value; }
  316. void flex_basis (FlexBasis value) { rare.flex_basis_type = value.type; rare.flex_basis = value.value; }
  317. void transform_origin_z (float value) { rare.transform_origin_z = value; }
  318. void perspective (float value) { rare.perspective = value; }
  319. void has_local_perspective (bool value) { rare.has_local_perspective = value; }
  320. void has_local_transform (bool value) { rare.has_local_transform = value; }
  321. void border_top_left_radius (float value) { rare.border_top_left_radius = (int16_t)value; }
  322. void border_top_right_radius (float value) { rare.border_top_right_radius = (int16_t)value; }
  323. void border_bottom_right_radius(float value) { rare.border_bottom_right_radius = (int16_t)value; }
  324. void border_bottom_left_radius (float value) { rare.border_bottom_left_radius = (int16_t)value; }
  325. void clip (Clip value) { rare.clip = value; }
  326. void drag (Drag value) { rare.drag = value; }
  327. void tab_index (TabIndex value) { rare.tab_index = value; }
  328. void image_color (Colourb value) { rare.image_color = value; }
  329. void overscroll_behavior (OverscrollBehavior value){ rare.overscroll_behavior = value; }
  330. void scrollbar_margin (float value) { rare.scrollbar_margin = value; }
  331. // clang-format on
  332. // -- Management --
  333. void CopyNonInherited(const ComputedValues& other)
  334. {
  335. common = other.common;
  336. rare = other.rare;
  337. }
  338. void CopyInherited(const ComputedValues& parent) { inherited = parent.inherited; }
  339. private:
  340. template <typename T>
  341. inline T GetLocalPropertyKeyword(PropertyId id, T default_value) const
  342. {
  343. if (auto p = element->GetLocalProperty(id))
  344. return static_cast<T>(p->Get<int>());
  345. return default_value;
  346. }
  347. template <typename T>
  348. inline T GetLocalProperty(PropertyId id, T default_value) const
  349. {
  350. if (auto p = element->GetLocalProperty(id))
  351. return p->Get<T>();
  352. return default_value;
  353. }
  354. Element* element = nullptr;
  355. CommonValues common;
  356. InheritedValues inherited;
  357. RareValues rare;
  358. };
  359. } // namespace Style
  360. // Resolves a computed LengthPercentage(Auto) value to the base unit 'px'.
  361. // Percentages are scaled by the base value, if definite (>= 0), otherwise return the default value.
  362. // Auto lengths always return the default value.
  363. RMLUICORE_API float ResolveValueOr(Style::LengthPercentageAuto length, float base_value, float default_value);
  364. RMLUICORE_API float ResolveValueOr(Style::LengthPercentage length, float base_value, float default_value);
  365. RMLUICORE_API_INLINE float ResolveValue(Style::LengthPercentageAuto length, float base_value)
  366. {
  367. return ResolveValueOr(length, base_value, 0.f);
  368. }
  369. RMLUICORE_API_INLINE float ResolveValue(Style::LengthPercentage length, float base_value)
  370. {
  371. return ResolveValueOr(length, base_value, 0.f);
  372. }
  373. using ComputedValues = Style::ComputedValues;
  374. } // namespace Rml
  375. #endif