d89ef83551
Properties can now have values of different types, and they are registered with their name, either to a layout class or globally. Layout classes are also registered with their name.
144 lines
5.1 KiB
C
144 lines
5.1 KiB
C
#include "clay.h"
|
|
#include "layout.h"
|
|
#include "context.h"
|
|
|
|
static struct clay_layout_class_s layout_class_flex = {};
|
|
|
|
|
|
enum flex_direction {
|
|
FLEX_DIRECTION_ROW,
|
|
FLEX_DIRECTION_ROW_REVERSE,
|
|
FLEX_DIRECTION_COLUMN,
|
|
FLEX_DIRECTION_COLUMN_REVERSE,
|
|
};
|
|
|
|
static clay_prop_definition_in prop_direction = {
|
|
.keywords = CLAY_PROP_DEF_KEYWORDS(
|
|
CLAY_PROP_DEF_KEYWORD("row", FLEX_DIRECTION_ROW),
|
|
CLAY_PROP_DEF_KEYWORD("row-reverse", FLEX_DIRECTION_ROW_REVERSE),
|
|
CLAY_PROP_DEF_KEYWORD("column", FLEX_DIRECTION_COLUMN),
|
|
CLAY_PROP_DEF_KEYWORD("column-reverse", FLEX_DIRECTION_COLUMN_REVERSE),
|
|
),
|
|
};
|
|
|
|
enum flex_wrap {
|
|
FLEX_WRAP_NOWRAP,
|
|
FLEX_WRAP_WRAP,
|
|
FLEX_WRAP_WRAP_REVERSE,
|
|
};
|
|
|
|
static clay_prop_definition_in prop_wrap = {
|
|
.keywords = CLAY_PROP_DEF_KEYWORDS(
|
|
CLAY_PROP_DEF_KEYWORD("nowrap", FLEX_WRAP_NOWRAP),
|
|
CLAY_PROP_DEF_KEYWORD("wrap", FLEX_WRAP_WRAP),
|
|
CLAY_PROP_DEF_KEYWORD("wrap-reverse", FLEX_WRAP_WRAP_REVERSE),
|
|
),
|
|
};
|
|
|
|
enum justify_content {
|
|
JUSTIFY_CONTENT_START,
|
|
JUSTIFY_CONTENT_END,
|
|
JUSTIFY_CONTENT_CENTER,
|
|
JUSTIFY_CONTENT_SPACE_BETWEEN,
|
|
JUSTIFY_CONTENT_SPACE_AROUND,
|
|
JUSTIFY_CONTENT_SPACE_EVENLY,
|
|
};
|
|
|
|
static clay_prop_definition_in prop_justify_content = {
|
|
.keywords = CLAY_PROP_DEF_KEYWORDS(
|
|
CLAY_PROP_DEF_KEYWORD("start", JUSTIFY_CONTENT_START),
|
|
CLAY_PROP_DEF_KEYWORD("end", JUSTIFY_CONTENT_END),
|
|
CLAY_PROP_DEF_KEYWORD("center", JUSTIFY_CONTENT_CENTER),
|
|
CLAY_PROP_DEF_KEYWORD("space-between", JUSTIFY_CONTENT_SPACE_BETWEEN),
|
|
CLAY_PROP_DEF_KEYWORD("space-around", JUSTIFY_CONTENT_SPACE_AROUND),
|
|
CLAY_PROP_DEF_KEYWORD("space-evenly", JUSTIFY_CONTENT_SPACE_EVENLY),
|
|
),
|
|
};
|
|
|
|
enum align_items {
|
|
ALIGN_ITEMS_START,
|
|
ALIGN_ITEMS_END,
|
|
ALIGN_ITEMS_CENTER,
|
|
ALIGN_ITEMS_STRETCH,
|
|
};
|
|
|
|
static clay_prop_definition_in prop_align_items = {
|
|
.keywords = CLAY_PROP_DEF_KEYWORDS(
|
|
CLAY_PROP_DEF_KEYWORD("start", ALIGN_ITEMS_START),
|
|
CLAY_PROP_DEF_KEYWORD("end", ALIGN_ITEMS_END),
|
|
CLAY_PROP_DEF_KEYWORD("center", ALIGN_ITEMS_CENTER),
|
|
CLAY_PROP_DEF_KEYWORD("stretch", ALIGN_ITEMS_STRETCH),
|
|
),
|
|
};
|
|
|
|
enum align_content {
|
|
ALIGN_CONTENT_START,
|
|
ALIGN_CONTENT_END,
|
|
ALIGN_CONTENT_CENTER,
|
|
ALIGN_CONTENT_STRETCH,
|
|
ALIGN_CONTENT_SPACE_BETWEEN,
|
|
ALIGN_CONTENT_SPACE_AROUND,
|
|
ALIGN_CONTENT_SPACE_EVENLY,
|
|
};
|
|
|
|
static clay_prop_definition_in prop_align_content = {
|
|
.keywords = CLAY_PROP_DEF_KEYWORDS(
|
|
CLAY_PROP_DEF_KEYWORD("start", ALIGN_CONTENT_START),
|
|
CLAY_PROP_DEF_KEYWORD("end", ALIGN_CONTENT_END),
|
|
CLAY_PROP_DEF_KEYWORD("center", ALIGN_CONTENT_CENTER),
|
|
CLAY_PROP_DEF_KEYWORD("stretch", ALIGN_CONTENT_STRETCH),
|
|
CLAY_PROP_DEF_KEYWORD("space-between", ALIGN_CONTENT_SPACE_BETWEEN),
|
|
CLAY_PROP_DEF_KEYWORD("space-around", ALIGN_CONTENT_SPACE_AROUND),
|
|
CLAY_PROP_DEF_KEYWORD("space-evenly", ALIGN_CONTENT_SPACE_EVENLY),
|
|
),
|
|
};
|
|
|
|
static clay_prop_definition_in prop_gap = {
|
|
.allow_float = true,
|
|
.allow_int = true,
|
|
.allow_units = CLAY_PROP_UNIT_ABSOLUTE | CLAY_PROP_UNIT_PX,
|
|
.max_values = 2,
|
|
};
|
|
|
|
static clay_prop_definition_in prop_gap_single = {
|
|
.allow_float = true,
|
|
.allow_int = true,
|
|
.allow_units = CLAY_PROP_UNIT_ABSOLUTE | CLAY_PROP_UNIT_PX,
|
|
};
|
|
|
|
static clay_prop_definition_in prop_flex_order = {
|
|
.allow_int = true,
|
|
.allow_units = CLAY_PROP_UNIT_NONE,
|
|
};
|
|
|
|
static clay_prop_definition_in prop_flex_grow_shrink = {
|
|
.allow_int = true,
|
|
.allow_float = true,
|
|
.allow_units = CLAY_PROP_UNIT_NONE,
|
|
};
|
|
|
|
static clay_prop_definition_in prop_flex_basis = {
|
|
.allow_int = true,
|
|
.allow_float = true,
|
|
.allow_units = CLAY_PROP_UNIT_ANY_UNIT,
|
|
};
|
|
|
|
|
|
void clay_flex_register(clay_ctx ctx) {
|
|
clay_ctx_register_layout_class(ctx, "flex", &layout_class_flex);
|
|
|
|
clay_ctx_register_class_property(ctx, "flex", "direction", &prop_direction);
|
|
clay_ctx_register_class_property(ctx, "flex", "wrap", &prop_wrap);
|
|
clay_ctx_register_class_property(ctx, "flex", "justify-content", &prop_justify_content);
|
|
clay_ctx_register_class_property(ctx, "flex", "align-items", &prop_align_items);
|
|
clay_ctx_register_class_property(ctx, "flex", "align-content", &prop_align_content);
|
|
clay_ctx_register_class_property(ctx, "flex", "gap", &prop_gap);
|
|
clay_ctx_register_class_property(ctx, "flex", "column-gap", &prop_gap_single);
|
|
clay_ctx_register_class_property(ctx, "flex", "row-gap", &prop_gap_single);
|
|
|
|
clay_ctx_register_global_property(ctx, "order", &prop_flex_order);
|
|
clay_ctx_register_global_property(ctx, "flex-grow", &prop_flex_grow_shrink);
|
|
clay_ctx_register_global_property(ctx, "flex-shrink", &prop_flex_grow_shrink);
|
|
clay_ctx_register_global_property(ctx, "flex-basis", &prop_flex_basis);
|
|
clay_ctx_register_global_property(ctx, "align-self", &prop_align_items);
|
|
} |