add small example program

This commit is contained in:
hippoz 2023-05-24 23:02:58 +03:00
parent 98288a60cd
commit ce685968b2
Signed by: hippoz
GPG key ID: 56C4E02A85F2FBED
2 changed files with 63 additions and 0 deletions

5
example/build.sh Normal file
View file

@ -0,0 +1,5 @@
#!/bin/sh
set -xe
gcc -Wall -Wextra -std=gnu99 $(pkg-config --cflags --libs xcb xcb-xkb cairo pangocairo xkbcommon xkbcommon-x11) -lm main.c -o main

58
example/main.c Normal file
View file

@ -0,0 +1,58 @@
#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;
}