-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest.c
More file actions
112 lines (91 loc) · 3.62 KB
/
test.c
File metadata and controls
112 lines (91 loc) · 3.62 KB
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#include "../lean_ui.h"
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
//-----------------------------------------------------------------------------------------------------------------------------
void draw_box(float x, float y, float width, float height, float radius, uint32_t srgb_color, void* user)
{
(void) user;
fprintf(stdout, "draw_box(%f, %f, %f, %f, %f, %x)\n", x, y, width, height, radius, srgb_color);
}
//-----------------------------------------------------------------------------------------------------------------------------
void draw_text(float x, float y, const char* text, uint32_t srgb_color, void* user)
{
(void) user;
fprintf(stdout, "draw_text(%f, %f, %s, %x)\n", x, y, text, srgb_color);
}
//-----------------------------------------------------------------------------------------------------------------------------
void draw_line(float x0, float y0, float x1, float y1, float width, uint32_t srgb_color, void* user)
{
(void) user;
fprintf(stdout, "draw_line(%f, %f, %f, %f, %f, %x)\n", x0, y0, x1, y1, width, srgb_color);
}
//-----------------------------------------------------------------------------------------------------------------------------
void set_clip_rect(uint16_t min_x, uint16_t min_y, uint16_t max_x, uint16_t max_y, void* user)
{
(void) user;
fprintf(stdout, "set_clip_rect(%u, %u, %u, %u)\n", min_x, min_y, max_x, max_y);
}
//-----------------------------------------------------------------------------------------------------------------------------
float text_width(const char* text, void* user)
{
(void) user;
return 16.f * strlen(text);
}
int main(void)
{
ui_def def =
{
.preallocated_buffer = malloc(ui_min_memory_size()),
.font_height = 32.f,
.renderer_callbacks =
{
.draw_box = draw_box,
.draw_text = draw_text,
.draw_line = draw_line,
.set_clip_rect = set_clip_rect,
.text_width = text_width
}
};
ui_context* ctx = ui_init(&def);
ui_update_mouse_button(ctx, button_pressed);
ui_update_mouse_pos(ctx, 187.f, 847.f);
ui_begin_frame(ctx, 1.f/60.f);
ui_begin_window(ctx, "Alright let's play!", 800, 100, 600, 1600, window_resizable);
ui_text(ctx, align_left, "On the left");
ui_text(ctx, align_right, "On the right");
ui_newline(ctx);
ui_value(ctx, "app time", "%2.2f sec", 45.f);
ui_value(ctx, "delta time", "%2.2f ms", 16.f);
ui_text(ctx, align_center, "In the middle");
ui_newline(ctx);
static bool test_bool, en_dessous;
ui_toggle(ctx, "This is a toggle", &test_bool);
ui_toggle(ctx, "and another one", &en_dessous);
ui_separator(ctx);
ui_text(ctx, align_center, "Choose your destiny");
ui_newline(ctx);
const char* list[] = {"Novice", "Warrior", "Master", "Champion"};
static uint32_t selected = 2;
ui_segmented(ctx, list, 4, &selected);
ui_text(ctx, align_left, "Your choice");
ui_text(ctx, align_center, list[selected]);
ui_newline(ctx);
ui_separator(ctx);
static float quantity = 5.f;
ui_slider(ctx, "Distance", 0.f, 100.f, 1.f, &quantity, "%3.2fkm");
ui_separator(ctx);
ui_button(ctx, "Left Button", align_left);
ui_button(ctx, "Center Button", align_center);
ui_button(ctx, "Right Button", align_right);
ui_newline(ctx);
float drive, pan, volume;
ui_knob(ctx, "drive", 1.f, 10.f, 2.f, &drive);
ui_knob(ctx, "pan", -1.f, 1.f, 0.f, &pan);
ui_knob(ctx, "volume", 0.f, 1.f, .7f, &volume);
ui_newline(ctx);
ui_end_window(ctx);
ui_end_frame(ctx);
free(def.preallocated_buffer);
return 0;
}