forked from haasn/libplacebo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
nuklear.c
81 lines (66 loc) · 2.13 KB
/
nuklear.c
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/* Trivial UI demo, very unfinished. Currently just lets you change the
* background color of the window and nothing else.
*
* License: CC0 / Public Domain
*/
#include "common.h"
#include "window.h"
#include "ui.h"
static struct pl_context *ctx;
static struct window *win;
static struct ui *ui;
static bool render(const struct pl_swapchain_frame *frame)
{
ui_update_input(ui, win);
enum nk_panel_flags win_flags = NK_WINDOW_BORDER | NK_WINDOW_MOVABLE |
NK_WINDOW_SCALABLE | NK_WINDOW_MINIMIZABLE | NK_WINDOW_TITLE;
static struct nk_colorf background = { 0.0f, 0.0f, 0.0f, 1.0f };
struct nk_context *nk = ui_get_context(ui);
if (nk_begin(nk, "Settings", nk_rect(100, 100, 500, 200), win_flags)) {
nk_layout_row_dynamic(nk, 20, 1);
nk_label(nk, "Window background:", NK_TEXT_LEFT);
nk_layout_row_dynamic(nk, 25, 1);
if (nk_combo_begin_color(nk, nk_rgb_cf(background), nk_vec2(nk_widget_width(nk), 400))) {
nk_layout_row_dynamic(nk, 120, 1);
nk_color_pick(nk, &background, NK_RGB);
nk_combo_end(nk);
}
}
nk_end(nk);
assert(frame->fbo->params.blit_dst);
pl_tex_clear(win->gpu, frame->fbo, (const float *) &background.r);
return ui_draw(ui, frame);
}
static void uninit(int ret)
{
ui_destroy(&ui);
window_destroy(&win);
pl_context_destroy(&ctx);
exit(ret);
}
int main(int argc, char **argv)
{
ctx = demo_context();
win = window_create(ctx, "nuklear demo", 640, 480, 0);
ui = win ? ui_create(win->gpu) : NULL;
if (!win || !ui)
uninit(1);
while (!win->window_lost) {
struct pl_swapchain_frame frame;
bool ok = pl_swapchain_start_frame(win->swapchain, &frame);
if (!ok) {
window_poll(win, true);
continue;
}
if (!render(&frame))
uninit(1);
ok = pl_swapchain_submit_frame(win->swapchain);
if (!ok) {
fprintf(stderr, "libplacebo: failed submitting frame!\n");
uninit(3);
}
pl_swapchain_swap_buffers(win->swapchain);
window_poll(win, false);
}
uninit(0);
}