From ce685968b2d3d841739f2443a4e4a37af2066399 Mon Sep 17 00:00:00 2001 From: hippoz <10706925-hippoz@users.noreply.gitlab.com> Date: Wed, 24 May 2023 23:02:58 +0300 Subject: [PATCH] add small example program --- example/build.sh | 5 +++++ example/main.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 example/build.sh create mode 100644 example/main.c diff --git a/example/build.sh b/example/build.sh new file mode 100644 index 0000000..43f77cb --- /dev/null +++ b/example/build.sh @@ -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 diff --git a/example/main.c b/example/main.c new file mode 100644 index 0000000..65c688b --- /dev/null +++ b/example/main.c @@ -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; +}