2 * Copyright (c) 2014, Facebook, Inc.
5 * This source code is licensed under the BSD-style license found in the
6 * LICENSE file in the root directory of this source tree. An additional grant
7 * of patent rights can be found in the PATENTS file in the same directory.
18 // Not defined in MSVC++
20 static const unsigned long __nan[2] = {0xffffffff, 0x7fffffff};
21 #define NAN (*(const float *)__nan)
24 #define CSS_UNDEFINED NAN
27 CSS_DIRECTION_INHERIT = 0,
33 CSS_FLEX_DIRECTION_COLUMN = 0,
34 CSS_FLEX_DIRECTION_COLUMN_REVERSE,
35 CSS_FLEX_DIRECTION_ROW,
36 CSS_FLEX_DIRECTION_ROW_REVERSE
37 } css_flex_direction_t;
40 CSS_JUSTIFY_FLEX_START = 0,
43 CSS_JUSTIFY_SPACE_BETWEEN,
44 CSS_JUSTIFY_SPACE_AROUND
47 // Note: auto is only a valid value for alignSelf. It is NOT a valid value for
58 CSS_POSITION_RELATIVE = 0,
60 } css_position_type_t;
67 // Note: left and top are shared between position[2] and position[4], so
68 // they have to be before right and bottom.
80 CSS_MEASURE_MODE_UNDEFINED = 0,
81 CSS_MEASURE_MODE_EXACTLY,
82 CSS_MEASURE_MODE_AT_MOST
93 css_direction_t direction;
95 // Instead of recomputing the entire layout every single time, we
96 // cache some information to break early when nothing changed
98 float last_requested_dimensions[2];
99 float last_parent_max_width;
100 float last_parent_max_height;
101 float last_dimensions[2];
102 float last_position[2];
103 css_direction_t last_direction;
111 css_direction_t direction;
112 css_flex_direction_t flex_direction;
113 css_justify_t justify_content;
114 css_align_t align_content;
115 css_align_t align_items;
116 css_align_t align_self;
117 css_position_type_t position_type;
118 css_wrap_type_t flex_wrap;
123 * You should skip all the rules that contain negative values for the
124 * following attributes. For example:
125 * {padding: 10, paddingLeft: -5}
128 * the following two are incorrect:
135 float minDimensions[2];
136 float maxDimensions[2];
139 typedef struct css_node css_node_t;
146 css_node_t *next_absolute_child;
147 css_node_t *next_flex_child;
149 css_dim_t (*measure)(void *context, float width, css_measure_mode_t widthMode, float height, css_measure_mode_t heightMode);
150 void (*print)(void *context);
151 struct css_node* (*get_child)(void *context, int i);
152 bool (*is_dirty)(void *context);
156 // Lifecycle of nodes and children
157 css_node_t *new_css_node(void);
158 void init_css_node(css_node_t *node);
159 void free_css_node(css_node_t *node);
163 CSS_PRINT_LAYOUT = 1,
165 CSS_PRINT_CHILDREN = 4,
166 } css_print_options_t;
167 void print_css_node(css_node_t *node, css_print_options_t options);
169 bool isUndefined(float value);
171 // Function that computes the layout!
172 void layoutNode(css_node_t *node, float maxWidth, float maxHeight, css_direction_t parentDirection);
174 // Reset the calculated layout values for a given node. You should call this before `layoutNode`.
175 void resetNodeLayout(css_node_t *node);