1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
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;
}
|