Merge "Updated NanoSVG to latest version (9 July 2017)" into devel/master
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / third-party / facebook-flexbox / layout.h
1 /**
2  * Copyright (c) 2014, Facebook, Inc.
3  * All rights reserved.
4  *
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.
8  */
9
10 #ifndef __LAYOUT_H
11 #define __LAYOUT_H
12
13 #include <math.h>
14 #ifndef __cplusplus
15 #include <stdbool.h>
16 #endif
17
18 // Not defined in MSVC++
19 #ifndef NAN
20 static const unsigned long __nan[2] = {0xffffffff, 0x7fffffff};
21 #define NAN (*(const float *)__nan)
22 #endif
23
24 #define CSS_UNDEFINED NAN
25
26 typedef enum {
27   CSS_DIRECTION_INHERIT = 0,
28   CSS_DIRECTION_LTR,
29   CSS_DIRECTION_RTL
30 } css_direction_t;
31
32 typedef enum {
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;
38
39 typedef enum {
40   CSS_JUSTIFY_FLEX_START = 0,
41   CSS_JUSTIFY_CENTER,
42   CSS_JUSTIFY_FLEX_END,
43   CSS_JUSTIFY_SPACE_BETWEEN,
44   CSS_JUSTIFY_SPACE_AROUND
45 } css_justify_t;
46
47 // Note: auto is only a valid value for alignSelf. It is NOT a valid value for
48 // alignItems.
49 typedef enum {
50   CSS_ALIGN_AUTO = 0,
51   CSS_ALIGN_FLEX_START,
52   CSS_ALIGN_CENTER,
53   CSS_ALIGN_FLEX_END,
54   CSS_ALIGN_STRETCH
55 } css_align_t;
56
57 typedef enum {
58   CSS_POSITION_RELATIVE = 0,
59   CSS_POSITION_ABSOLUTE
60 } css_position_type_t;
61
62 typedef enum {
63   CSS_NOWRAP = 0,
64   CSS_WRAP
65 } css_wrap_type_t;
66
67 // Note: left and top are shared between position[2] and position[4], so
68 // they have to be before right and bottom.
69 typedef enum {
70   CSS_LEFT = 0,
71   CSS_TOP,
72   CSS_RIGHT,
73   CSS_BOTTOM,
74   CSS_START,
75   CSS_END,
76   CSS_POSITION_COUNT
77 } css_position_t;
78
79 typedef enum {
80   CSS_MEASURE_MODE_UNDEFINED = 0,
81   CSS_MEASURE_MODE_EXACTLY,
82   CSS_MEASURE_MODE_AT_MOST
83 } css_measure_mode_t;
84
85 typedef enum {
86   CSS_WIDTH = 0,
87   CSS_HEIGHT
88 } css_dimension_t;
89
90 typedef struct {
91   float position[4];
92   float dimensions[2];
93   css_direction_t direction;
94
95   // Instead of recomputing the entire layout every single time, we
96   // cache some information to break early when nothing changed
97   bool should_update;
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;
104 } css_layout_t;
105
106 typedef struct {
107   float dimensions[2];
108 } css_dim_t;
109
110 typedef struct {
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;
119   float flex;
120   float margin[6];
121   float position[4];
122   /**
123    * You should skip all the rules that contain negative values for the
124    * following attributes. For example:
125    *   {padding: 10, paddingLeft: -5}
126    * should output:
127    *   {left: 10 ...}
128    * the following two are incorrect:
129    *   {left: -5 ...}
130    *   {left: 0 ...}
131    */
132   float padding[6];
133   float border[6];
134   float dimensions[2];
135   float minDimensions[2];
136   float maxDimensions[2];
137 } css_style_t;
138
139 typedef struct css_node css_node_t;
140 struct css_node {
141   css_style_t style;
142   css_layout_t layout;
143   int children_count;
144   int line_index;
145
146   css_node_t *next_absolute_child;
147   css_node_t *next_flex_child;
148
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);
153   void *context;
154 };
155
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);
160
161 // Print utilities
162 typedef enum {
163   CSS_PRINT_LAYOUT = 1,
164   CSS_PRINT_STYLE = 2,
165   CSS_PRINT_CHILDREN = 4,
166 } css_print_options_t;
167 void print_css_node(css_node_t *node, css_print_options_t options);
168
169 bool isUndefined(float value);
170
171 // Function that computes the layout!
172 void layoutNode(css_node_t *node, float maxWidth, float maxHeight, css_direction_t parentDirection);
173
174 // Reset the calculated layout values for a given node. You should call this before `layoutNode`.
175 void resetNodeLayout(css_node_t *node);
176
177 #endif // __LAYOUT_H