raven/example/main.c

59 lines
1.6 KiB
C
Raw Normal View History

2023-05-24 23:02:58 +03:00
#include "pango/pango-font.h"
#define RAVEN_IMPLEMENTATION
#include "libraven.h"
typedef struct AppState {
PangoFontDescription *desc;
} AppState;
UINode *main_view_scaffold(UINode *root, AppState *state)
{
{
background_node_new(root, UISlate50, 0);
UIBoxLayoutNode *layout = box_layout_new(root, UI_DIRECTION_VERTICAL);
box_layout_set_margins(layout, 36);
layout->gap = 12;
layout->justify_secondary_dimension = UI_BOX_LAYOUT_JUSTIFY_CENTER;
}
{
UINode *input = (UINode*)text_input_new(root);
background_node_new(input, UISlate200, 10);
input->width_policy = UI_SIZE_POLICY_STATIC;
input->height_policy = UI_SIZE_POLICY_GROW;
input->rect.w = 38;
UIBoxLayoutNode *layout = box_layout_new(input, UI_DIRECTION_HORIZONTAL);
layout->justify_secondary_dimension = UI_BOX_LAYOUT_JUSTIFY_CENTER;
layout->margin_left = 0;
UINode *input_text_container = node_new(input, "input_text_container");
UITextNode *input_text = text_node_new(input_text_container, state->desc, UINeutral950, NULL);
((UITextInputNode*)input)->text_node = input_text;
}
return root;
}
int main(void)
{
UIWindow *window = window_new(800, 600);
if (!window) {
fprintf(stderr, "err: failed to create window\n");
return EXIT_FAILURE;
}
AppState state ={
.desc = pango_font_description_from_string("Roboto:size=16")
};
UINode *root = node_new(NULL, "[root]");
window_attach_root(window, root);
main_view_scaffold(root, &state);
window_turn(window);
window_free(window);
return 0;
}