Files
yoga/src/Layout.h

121 lines
2.6 KiB
C
Raw Normal View History

2014-04-18 16:00:53 -07:00
#ifndef __LAYOUT_H
#define __LAYOUT_H
2014-04-28 12:34:04 -07:00
#include <math.h>
2014-09-11 09:23:30 -07:00
#include <stdbool.h>
2014-04-26 12:16:27 -07:00
#define CSS_UNDEFINED NAN
2014-04-18 16:00:53 -07:00
typedef enum {
CSS_FLEX_DIRECTION_COLUMN = 0,
CSS_FLEX_DIRECTION_ROW
} css_flex_direction_t;
typedef enum {
CSS_JUSTIFY_FLEX_START = 0,
CSS_JUSTIFY_CENTER,
CSS_JUSTIFY_FLEX_END,
CSS_JUSTIFY_SPACE_BETWEEN,
CSS_JUSTIFY_SPACE_AROUND
} css_justify_t;
// Note: auto is only a valid value for alignSelf. It is NOT a valid value for
// alignItems.
typedef enum {
CSS_ALIGN_AUTO = 0,
CSS_ALIGN_FLEX_START,
CSS_ALIGN_CENTER,
CSS_ALIGN_FLEX_END,
CSS_ALIGN_STRETCH
} css_align_t;
2014-04-22 13:18:05 -07:00
typedef enum {
CSS_POSITION_RELATIVE = 0,
CSS_POSITION_ABSOLUTE
} css_position_type_t;
2014-04-18 16:00:53 -07:00
// Note: left and top are shared between position[2] and position[4], so
// they have to be before right and bottom.
typedef enum {
CSS_LEFT = 0,
CSS_TOP,
CSS_RIGHT,
CSS_BOTTOM
} css_position_t;
typedef enum {
CSS_WIDTH = 0,
CSS_HEIGHT
} css_dimension_t;
typedef struct {
float position[2];
float dimensions[2];
2014-09-11 09:23:30 -07:00
// Instead of recomputing the entire layout every single time, we
// cache some information to break early when nothing changed
bool should_update;
float last_requested_dimensions[2];
float last_parent_max_width;
float last_dimensions[2];
float last_position[2];
2014-04-18 16:00:53 -07:00
} css_layout_t;
2014-04-28 12:34:04 -07:00
typedef struct {
float dimensions[2];
} css_dim_t;
2014-04-18 16:00:53 -07:00
typedef struct {
css_flex_direction_t flex_direction;
css_justify_t justify_content;
css_align_t align_items;
css_align_t align_self;
2014-04-22 13:18:05 -07:00
css_position_type_t position_type;
2014-09-11 09:23:30 -07:00
float flex;
2014-04-18 16:00:53 -07:00
float margin[4];
2014-04-22 14:59:59 -07:00
float position[4];
/**
* You should skip all the rules that contain negative values for the
* following attributes. For example:
* {padding: 10, paddingLeft: -5}
* should output:
* {left: 10 ...}
* the following two are incorrect:
* {left: -5 ...}
* {left: 0 ...}
*/
2014-04-18 16:00:53 -07:00
float padding[4];
2014-04-22 13:18:05 -07:00
float border[4];
2014-04-18 16:00:53 -07:00
float dimensions[2];
} css_style_t;
typedef struct css_node {
css_style_t style;
css_layout_t layout;
int children_count;
2014-06-11 21:00:57 -07:00
css_dim_t (*measure)(void *context, float width);
void (*print)(void *context);
2014-09-11 09:23:30 -07:00
struct css_node* (*get_child)(void *context, int i);
bool (*is_dirty)(void *context);
2014-06-11 21:00:57 -07:00
void *context;
2014-04-18 16:00:53 -07:00
} css_node_t;
// Lifecycle of nodes and children
2014-05-16 18:04:24 -07:00
css_node_t *new_css_node(void);
2014-09-11 09:23:30 -07:00
void init_css_node(css_node_t *node);
2014-04-18 16:00:53 -07:00
void free_css_node(css_node_t *node);
// Print utilities
typedef enum {
CSS_PRINT_LAYOUT = 1,
2014-09-11 09:23:30 -07:00
CSS_PRINT_STYLE = 2,
CSS_PRINT_CHILDREN = 4,
} css_print_options_t;
void print_css_node(css_node_t *node, css_print_options_t options);
2014-04-18 16:00:53 -07:00
// Function that computes the layout!
void layoutNode(css_node_t *node, float maxWidth);
2014-04-18 16:00:53 -07:00
#endif