#include "clay.h" #include "clay-layout.h" #include "clay-context.h" #include "clay-color.h" static void cleanup_document(clay layout); static void init_document(clay layout); static void debug_document(clay layout); static struct layout_class layout_class_document = { .init = &init_document, .cleanup = &cleanup_document, .debug = &debug_document, }; static void init_document(clay layout) { // todo: anything? } static void cleanup_document(clay layout) { // todo: anything? } static void debug_document(clay layout) { printf("document:\n"); clay_property_value width_prop = clay_get_prop(layout, "width"); clay_property_value height_prop = clay_get_prop(layout, "height"); clay_property_value content_prop = clay_get_prop(layout, "content"); clay_property_value bgcolor_prop = clay_get_prop(layout, "bg-color"); if (width_prop->type == CLAY_PROPERTY_INT) { printf(" width: %d\n", width_prop->int_val); } if (height_prop->type == CLAY_PROPERTY_INT) { printf(" height: %d\n", height_prop->int_val); } if (bgcolor_prop->type == CLAY_PROPERTY_POINTER) { clay_color *color = (clay_color*)bgcolor_prop->pointer_val; printf(" bg-color: (%d, %d, %d, %d)\n", color->r, color->g, color->b, color->a); } printf("\n"); if (content_prop->type == CLAY_PROPERTY_POINTER && content_prop->pointer_val != NULL) { clay content = (clay) content_prop->pointer_val; content->class.debug(content); } } clay clay_create_document(clay_ctx ctx) { return clay_create_layout(ctx, layout_class_document); } void clay_render_to_png(clay doc, const char *path) { // todo } void clay_debug_layout(clay doc) { doc->class.debug(doc); } void clay_document_register_props(clay_ctx ctx) { clay_ctx_register_property(ctx, "width", CLAY_PROPERTY_INT); clay_ctx_register_property(ctx, "height", CLAY_PROPERTY_INT); clay_ctx_register_property(ctx, "content", CLAY_PROPERTY_POINTER); clay_ctx_register_property(ctx, "bg-color", CLAY_PROPERTY_POINTER); }