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

Groups are basically windows inside windows.

They allow to subdivide space in a window to layout widgets as a group. Almost all more complex widget layouting requirements can be solved using groups and basic layouting functionality. Groups just like windows are identified by an unique name and internally keep track of scrollbar offsets by default. However additional versions are provided to directly manage the scrollbar.

Usage

To create a group you have to call one of the three nk_group_begin_xxx functions to start group declarations and nk_group_end at the end. Furthermore it is required to check the return value of nk_group_begin_xxx and only process widgets inside the window if the value is not 0. Nesting groups is possible and even encouraged since many layouting schemes can only be achieved by nesting. Groups, unlike windows, need nk_group_end to be only called if the corresponding nk_group_begin_xxx call does not return 0:

if (nk_group_begin_xxx(ctx, ...) {
// [... widgets ...]
nk_group_end(ctx);
}

In the grand concept groups can be called after starting a window with nk_begin_xxx and before calling nk_end:

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(...) {
// [...widgets...]
nk_layout_row_dynamic(...);
if (nk_group_begin_xxx(ctx, ...) {
//[... widgets ...]
nk_group_end(ctx);
}
}
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_group_begin Start a new group with internal scrollbar handling
nk_group_begin_titled Start a new group with separated name and title and internal scrollbar handling
nk_group_end Ends a group. Should only be called if nk_group_begin returned non-zero
nk_group_scrolled_offset_begin Start a new group with manual separated handling of scrollbar x- and y-offset
nk_group_scrolled_begin Start a new group with manual scrollbar handling
nk_group_scrolled_end Ends a group with manual scrollbar handling. Should only be called if nk_group_begin returned non-zero
nk_group_get_scroll Gets the scroll offset for the given group
nk_group_set_scroll Sets the scroll offset for the given group