summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main.c64
1 files changed, 64 insertions, 0 deletions
diff --git a/src/main.c b/src/main.c
new file mode 100644
index 0000000..88039ed
--- /dev/null
+++ b/src/main.c
@@ -0,0 +1,64 @@
+#define NK_IMPLEMENTATION
+#define NK_INCLUDE_DEFAULT_FONT
+#define NK_INCLUDE_DEFAULT_ALLOCATOR
+#define NK_INCLUDE_FONT_BAKING
+#include "nuklear.h"
+#include <stdio.h>
+
+static float font_width_calc(nk_handle handle, float height, const char *text, int len) {
+ (void)handle;
+ (void)height;
+ return (float)len * 8.0f;
+}
+
+int main(void) {
+ enum { EASY, HARD };
+ static int op = EASY;
+ static float value = 0.6f;
+ static int i = 20;
+ struct nk_context ctx;
+ struct nk_user_font font;
+ struct nk_font_atlas atlas;
+
+ font.userdata = (nk_handle)0;
+ font.height = 13.0f;
+ font.width = font_width_calc;
+
+ nk_init_default(&ctx, &font);
+ nk_font_atlas_init_default(&atlas);
+ nk_font_atlas_begin(&atlas);
+ nk_font_atlas_add_default(&atlas, 13.0f, 0);
+ int w, h;
+ const void *img = nk_font_atlas_bake(&atlas, &w, &h, NK_FONT_ATLAS_RGBA32);
+ (void)img;
+ nk_font_atlas_end(&atlas, nk_handle_id(0), NULL);
+
+ ctx.style.font = &font;
+
+ if (nk_begin(&ctx, "Show", nk_rect(50, 50, 220, 220),
+ NK_WINDOW_BORDER | NK_WINDOW_MOVABLE | NK_WINDOW_CLOSABLE)) {
+ nk_layout_row_static(&ctx, 30, 80, 1);
+ if (nk_button_label(&ctx, "button")) {
+ }
+
+ nk_layout_row_dynamic(&ctx, 30, 2);
+ if (nk_option_label(&ctx, "easy", op == EASY))
+ op = EASY;
+ if (nk_option_label(&ctx, "hard", op == HARD))
+ op = HARD;
+
+ nk_layout_row_begin(&ctx, NK_STATIC, 30, 2);
+ {
+ nk_layout_row_push(&ctx, 50);
+ nk_label(&ctx, "Volume:", NK_TEXT_LEFT);
+ nk_layout_row_push(&ctx, 110);
+ nk_slider_float(&ctx, 0, &value, 1.0f, 0.1f);
+ }
+ nk_layout_row_end(&ctx);
+ }
+ nk_end(&ctx);
+
+ nk_font_atlas_cleanup(&atlas);
+ nk_free(&ctx);
+ return 0;
+}