-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathnuklear_console_knob.h
More file actions
101 lines (82 loc) · 2.84 KB
/
nuklear_console_knob.h
File metadata and controls
101 lines (82 loc) · 2.84 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
#ifndef NK_CONSOLE_KNOB_H__
#define NK_CONSOLE_KNOB_H__
#include "nuklear_console_property.h"
/**
* Data for Property and Slider widgets.
*/
typedef struct nk_console_knob_data {
nk_console_property_data property; /* Inherited from property */
enum nk_heading zero_direction;
float dead_zone_degrees;
} nk_console_knob_data;
#if defined(__cplusplus)
extern "C" {
#endif
/**
* Creates a Knob widget using an integer value.
*/
NK_API nk_console* nk_console_knob_int(nk_console* parent, const char* label, int min, int* val, int max, int step, float inc_per_pixel);
/**
* Creates a Knob widget using a float value.
*/
NK_API nk_console* nk_console_knob_float(nk_console* parent, const char* label, float min, float* val, float max, float step, float inc_per_pixel);
#if defined(__cplusplus)
}
#endif
#endif // NK_CONSOLE_KNOB_H__
#if defined(NK_CONSOLE_IMPLEMENTATION) && !defined(NK_CONSOLE_HEADER_ONLY)
#ifndef NK_CONSOLE_KNOB_IMPLEMENTATION_ONCE
#define NK_CONSOLE_KNOB_IMPLEMENTATION_ONCE
#if defined(__cplusplus)
extern "C" {
#endif
NK_API nk_console* nk_console_knob_int(nk_console* parent, const char* label, int min, int* val, int max, int step, float inc_per_pixel) {
// Create the property data.
nk_console_knob_data* data = (nk_console_knob_data*)NK_CONSOLE_MALLOC(nk_handle_id(0), NULL, sizeof(nk_console_knob_data));
nk_zero(data, sizeof(nk_console_knob_data));
data->property.min_int = min;
data->property.val_int = val;
data->property.max_int = max;
data->property.step_int = step;
data->property.inc_per_pixel = inc_per_pixel;
data->zero_direction = NK_DOWN;
data->dead_zone_degrees = 60.0f;
nk_console* widget = nk_console_label(parent, label);
widget->render = &nk_console_property_render;
widget->type = NK_CONSOLE_KNOB_INT;
widget->selectable = nk_true;
widget->data = (void*)data;
widget->columns = label != NULL ? 2 : 1;
if (val != NULL) {
if (*val < min) {
*val = min;
}
else if (*val > max) {
*val = max;
}
}
return widget;
}
NK_API nk_console* nk_console_knob_float(nk_console* parent, const char* label, float min, float* val, float max, float step, float inc_per_pixel) {
nk_console* widget = nk_console_knob_int(parent, label, 0, NULL, 0, 0, inc_per_pixel);
nk_console_knob_data* data = (nk_console_knob_data*)widget->data;
widget->type = NK_CONSOLE_KNOB_FLOAT;
data->property.min_float = min;
data->property.val_float = val;
data->property.max_float = max;
data->property.step_float = step;
if (val != NULL) {
if (*val < min) {
*val = min;
}
else if (*val > max) {
*val = max;
}
}
return widget;
}
#if defined(__cplusplus)
}
#endif
#endif // NK_CONSOLE_KNOB_IMPLEMENTATION_ONCE
#endif // NK_CONSOLE_IMPLEMENTATION