Nuklear
Minimal-state, immediate-mode graphical user interface toolkit written in ANSI C.
Loading...
Searching...
No Matches
Properties

Properties are the main value modification widgets in Nuklear.

Changing a value can be achieved by dragging, adding/removing incremental steps on button click or by directly typing a number.

Usage

Each property requires a unique name for identification that is also used for displaying a label. If you want to use the same name multiple times make sure add a '#' before your name. The '#' will not be shown but will generate a unique ID. Each property also takes in a minimum and maximum value. If you want to make use of the complete number range of a type just use the provided type limits from limits.h. For example INT_MIN and INT_MAX for nk_property_int and nk_propertyi. In additional each property takes in a increment value that will be added or subtracted if either the increment decrement button is clicked. Finally there is a value for increment per pixel dragged that is added or subtracted from the value.

int value = 0;
struct nk_context ctx;
nk_init_xxx(&ctx, ...);
while (1) {
// Input
Event evt;
nk_input_begin(&ctx);
while (GetEvent(&evt)) {
if (evt.type == MOUSE_MOVE)
nk_input_motion(&ctx, evt.motion.x, evt.motion.y);
else if (evt.type == [...]) {
nk_input_xxx(...);
}
}
nk_input_end(&ctx);
//
// Window
if (nk_begin_xxx(...) {
// Property
nk_layout_row_dynamic(...);
nk_property_int(ctx, "ID", INT_MIN, &value, INT_MAX, 1, 1);
}
nk_end(ctx);
//
// Draw
const struct nk_command *cmd = 0;
nk_foreach(cmd, &ctx) {
switch (cmd->type) {
case NK_COMMAND_LINE:
your_draw_line_function(...)
break;
case NK_COMMAND_RECT
your_draw_rect_function(...)
break;
case ...:
// [...]
}
nk_clear(&ctx);
}
nk_free(&ctx);
command base and header of every command inside the buffer
Definition nuklear.h:4577

Reference

Function Description
nk_property_int Integer property directly modifying a passed in value
nk_property_float Float property directly modifying a passed in value
nk_property_double Double property directly modifying a passed in value
nk_propertyi Integer property returning the modified int value
nk_propertyf Float property returning the modified float value
nk_propertyd Double property returning the modified double value

# nk_property_int

Integer property directly modifying a passed in value

Warning
To generate a unique property ID using the same label make sure to insert a # at the beginning. It will not be shown but guarantees correct behavior.
nk_bool nk_property_int(struct nk_context *ctx, const char *name, int min, int *val, int max, int step, float inc_per_pixel);
Parameter Description
Parameters
[in]ctx
Must point to an previously initialized nk_context struct after calling a layouting function
Parameters
[in]name
String used both as a label as well as a unique identifier
Parameters
[in]min
Minimum value not allowed to be underflown
Parameters
[in]val
Integer pointer to be modified
Parameters
[in]max
Maximum value not allowed to be overflown
Parameters
[in]step
Increment added and subtracted on increment and decrement button
Parameters
[in]inc_per_pixel
Value per pixel added or subtracted on dragging
Returns
true(1) if the value changed