### nk_popup_begin Source: https://immediate-mode-ui.github.io/Nuklear/nuklear__popup_8c_source.html Starts a new popup window. This function is used to initiate the creation and display of a popup. It handles the setup of the popup window, its properties, and prepares the context for drawing its content. It returns true if the popup is successfully started and can be drawn, and false otherwise. ```APIDOC ## nk_popup_begin ### Description Starts a new popup window with a given title, flags, and rectangular bounds. This function prepares the Nuklear context to draw a popup. It returns `nk_true` if the popup was successfully started and can be drawn, and `nk_false` if the popup is invalid or already closed. ### Function Signature ```c NK_API nk_bool nk_popup_begin(struct nk_context *ctx, enum nk_popup_type type, const char *title, nk_flags flags, struct nk_rect rect) ``` ### Parameters - **ctx** (`struct nk_context *`) - Pointer to the Nuklear context. - **type** (`enum nk_popup_type`) - The type of popup (e.g., `NK_POPUP_DYNAMIC`). - **title** (`const char *`) - The title of the popup window. - **flags** (`nk_flags`) - Flags to customize the popup window's behavior and appearance. - **rect** (`struct nk_rect`) - The rectangular area defining the popup's position and size relative to its parent window. ### Returns - `nk_bool` - `nk_true` if the popup was successfully started, `nk_false` otherwise. ``` -------------------------------- ### nk_contextual_begin Source: https://immediate-mode-ui.github.io/Nuklear/nuklear__contextual_8c_source.html Starts a new contextual menu. This function should be called when a right-click or similar event occurs to initiate the display of a contextual menu. It handles the positioning and setup of the menu window. ```APIDOC ## nk_contextual_begin ### Description Starts a new contextual menu. This function should be called when a right-click or similar event occurs to initiate the display of a contextual menu. It handles the positioning and setup of the menu window. ### Method `nk_bool nk_contextual_begin(struct nk_context *ctx, nk_flags flags, struct nk_vec2 size, struct nk_rect trigger_bounds)` ### Parameters #### Path Parameters - **ctx** (`struct nk_context *`) - Required - Pointer to the Nuklear context. - **flags** (`nk_flags`) - Required - Flags to control the behavior and appearance of the menu window. - **size** (`struct nk_vec2`) - Required - The desired size of the contextual menu. - **trigger_bounds** (`struct nk_rect`) - Required - The bounding box of the element that triggered the contextual menu. ### Response #### Success Response (1) - Returns `nk_true` if the contextual menu was successfully started. #### Error Response (0) - Returns `nk_false` if the contextual menu could not be started (e.g., if the context is invalid or not the active window). ``` -------------------------------- ### nk_start Source: https://immediate-mode-ui.github.io/Nuklear/nuklear__context_8c_source.html Starts the drawing process for a specific window by initializing its command buffer. ```APIDOC ## nk_start ### Description Starts the drawing process for a specific window by initializing its command buffer. ### Parameters #### Path Parameters - **ctx** (*struct nk_context* *) - Description not available - **win** (*struct nk_window* *) - Description not available ### Method void ### Endpoint N/A (Function Call) ### Request Example ```c struct nk_context ctx; struct nk_window win; // ... initialization ... nk_start(&ctx, &win); ``` ### Response #### Success Response void #### Response Example N/A ``` -------------------------------- ### Start Window Drawing Source: https://immediate-mode-ui.github.io/Nuklear/nuklear__context_8c_source.html Starts the drawing process for a specific window by initializing its command buffer. ```c NK_LIB void nk_start(struct nk_context *ctx, struct nk_window *win) { NK_ASSERT(ctx); NK_ASSERT(win); nk_start_buffer(ctx, &win->buffer); } ``` -------------------------------- ### Draw List Initialization and Setup Source: https://immediate-mode-ui.github.io/Nuklear/nuklear_8h_source.html Functions to initialize and set up a draw list for rendering. ```APIDOC ## nk_draw_list_init ### Description Initializes a draw list structure. ### Method void ### Parameters - **draw_list** (struct nk_draw_list*) - Pointer to the draw list to initialize. ## nk_draw_list_setup ### Description Sets up the draw list with configuration for command, vertex, and element buffers, along with anti-aliasing settings. ### Method void ### Parameters - **draw_list** (struct nk_draw_list*) - Pointer to the draw list to set up. - **config** (const struct nk_convert_config*) - Pointer to the conversion configuration. - **cmds** (struct nk_buffer*) - Pointer to the command buffer. - **vertices** (struct nk_buffer*) - Pointer to the vertex buffer. - **elements** (struct nk_buffer*) - Pointer to the element buffer. - **line_aa** (enum nk_anti_aliasing) - Anti-aliasing setting for lines. - **shape_aa** (enum nk_anti_aliasing) - Anti-aliasing setting for shapes. ``` -------------------------------- ### Start Command Buffer Source: https://immediate-mode-ui.github.io/Nuklear/nuklear__context_8c_source.html Initializes a command buffer for a window. This should be called at the beginning of drawing a window. ```c NK_LIB void nk_start_buffer(struct nk_context *ctx, struct nk_command_buffer *buffer) { NK_ASSERT(ctx); NK_ASSERT(buffer); if (!ctx || !buffer) return; buffer->begin = ctx->memory.allocated; buffer->end = buffer->begin; buffer->last = buffer->begin; buffer->clip = nk_null_rect; } ``` -------------------------------- ### Begin Group Source: https://immediate-mode-ui.github.io/Nuklear/nuklear_8h_source.html Starts a new group with a title and flags. Groups help organize widgets and can be used for clipping or scrolling. ```c NK_API nk_bool nk_group_begin(struct nk_context*, const char *title, nk_flags); ``` -------------------------------- ### Begin a Group Source: https://immediate-mode-ui.github.io/Nuklear/nuklear__group_8c_source.html Starts a new group with a given title and flags. This function is a wrapper around `nk_group_begin_titled`. ```c NK_API nk_bool nk_group_begin(struct nk_context *ctx, const char *title, nk_flags flags) { return nk_group_begin_titled(ctx, title, title, flags); } ``` -------------------------------- ### nk_begin Source: https://immediate-mode-ui.github.io/Nuklear/nuklear__window_8c_source.html Starts a new window in the Nuklear UI. This is a convenience function that calls `nk_begin_titled` with the same string for both name and title. ```APIDOC ## nk_begin ### Description Starts a new window in the Nuklear UI. This is a convenience function that calls `nk_begin_titled` with the same string for both name and title. ### Function Signature ```c nk_bool nk_begin(struct nk_context *ctx, const char *title, struct nk_rect bounds, nk_flags flags) ``` ### Parameters * **ctx** (struct nk_context *) - Pointer to the Nuklear context. * **title** (const char *) - The title of the window. * **bounds** (struct nk_rect) - The initial bounding rectangle of the window. * **flags** (nk_flags) - Flags to control the window's behavior (e.g., NK_WINDOW_BACKGROUND). ### Returns * (nk_bool) - Returns true if the window was successfully started, false otherwise. ``` -------------------------------- ### Begin Nuklear Window (Simple) Source: https://immediate-mode-ui.github.io/Nuklear/nuklear__window_8c_source.html Starts a new Nuklear window with a given title and bounds. This is a convenience function that calls `nk_begin_titled`. ```c #include "nuklear.h" NK_API nk_bool nk_begin(struct nk_context *ctx, const char *title, struct nk_rect bounds, nk_flags flags) { return nk_begin_titled(ctx, title, title, bounds, flags); } ``` -------------------------------- ### nk_layout_row_begin Source: https://immediate-mode-ui.github.io/Nuklear/Layouting.html Starts a new layout row with a specified height and number of columns. This function must be paired with `nk_layout_row_end`. ```APIDOC ## nk_layout_row_begin ### Description Starts a new row with given height and number of columns. ### Function Signature ```c void nk_layout_row_begin(struct nk_context *ctx, enum nk_layout_format fmt, float height, int columns); ``` ### Parameters * **ctx** (*struct nk_context* *) - Required - Pointer to the Nuklear context. * **fmt** (*enum nk_layout_format* *) - Required - The layout format (e.g., `NK_STATIC`, `NK_DYNAMIC`, `NK_HORIZONTAL`, `NK_VERTICAL`). * **height** (*float*) - Required - The height of the row. * **columns** (*int*) - Required - The number of columns in the row. ``` -------------------------------- ### nk_draw_list_setup Source: https://immediate-mode-ui.github.io/Nuklear/nuklear__vertex_8c_source.html Sets up the draw list with configuration, buffers, and anti-aliasing settings. This prepares the draw list for subsequent drawing operations. ```APIDOC ## nk_draw_list_setup ### Description Configures the draw list with conversion settings, command, vertex, and element buffers, along with anti-aliasing options for lines and shapes. ### Function Signature ```c void nk_draw_list_setup(struct nk_draw_list *canvas, const struct nk_convert_config *config, struct nk_buffer *cmds, struct nk_buffer *vertices, struct nk_buffer *elements, enum nk_anti_aliasing line_aa, enum nk_anti_aliasing shape_aa) ``` ### Parameters - **canvas** (*struct nk_draw_list* *) - The draw list to set up. - **config** (*const struct nk_convert_config* *) - Pointer to the conversion configuration. - **cmds** (*struct nk_buffer* *) - Pointer to the buffer for drawing commands. - **vertices** (*struct nk_buffer* *) - Pointer to the buffer for vertex data. - **elements** (*struct nk_buffer* *) - Pointer to the buffer for element data. - **line_aa** (*enum nk_anti_aliasing*) - Anti-aliasing setting for lines. - **shape_aa** (*enum nk_anti_aliasing*) - Anti-aliasing setting for shapes. ``` -------------------------------- ### Initialize Font Atlas with Default Allocator Source: https://immediate-mode-ui.github.io/Nuklear/nuklear_8h_source.html Initializes a font atlas using the default memory allocator. This is a convenient way to get started. ```c NK_API void nk_font_atlas_init_default(struct nk_font_atlas*); ``` -------------------------------- ### Begin Popup Window Source: https://immediate-mode-ui.github.io/Nuklear/nuklear__popup_8c_source.html Initiates the creation and display of a popup window. It handles window creation, setup, and ensures correct popup behavior. Returns true if the popup is active and ready for content, false otherwise. ```c #include "nuklear.h" #include "nuklear_internal.h" /* =============================================================== * * POPUP * * ===============================================================*/ NK_API nk_bool nk_popup_begin(struct nk_context *ctx, enum nk_popup_type type, const char *title, nk_flags flags, struct nk_rect rect) { struct nk_window *popup; struct nk_window *win; struct nk_panel *panel; int title_len; nk_hash title_hash; nk_size allocated; NK_ASSERT(ctx); NK_ASSERT(title); NK_ASSERT(ctx->current); NK_ASSERT(ctx->current->layout); if (!ctx || !ctx->current || !ctx->current->layout) return 0; win = ctx->current; panel = win->layout; NK_ASSERT(!((int)panel->type & (int)NK_PANEL_SET_POPUP) && "popups are not allowed to have popups"); (void)panel; title_len = (int)nk_strlen(title); title_hash = nk_murmur_hash(title, (int)title_len, NK_PANEL_POPUP); popup = win->popup.win; if (!popup) { popup = (struct nk_window*)nk_create_window(ctx); popup->parent = win; win->popup.win = popup; win->popup.active = 0; win->popup.type = NK_PANEL_POPUP; } /* make sure we have correct popup */ if (win->popup.name != title_hash) { if (!win->popup.active) { nk_zero(popup, sizeof(*popup)); win->popup.name = title_hash; win->popup.active = 1; win->popup.type = NK_PANEL_POPUP; } else return 0; } /* popup position is local to window */ ctx->current = popup; rect.x += win->layout->clip.x; rect.y += win->layout->clip.y; /* setup popup data */ popup->parent = win; popup->bounds = rect; popup->seq = ctx->seq; popup->layout = (struct nk_panel*)nk_create_panel(ctx); popup->flags = flags; popup->flags |= NK_WINDOW_BORDER; if (type == NK_POPUP_DYNAMIC) popup->flags |= NK_WINDOW_DYNAMIC; popup->buffer = win->buffer; nk_start_popup(ctx, win); allocated = ctx->memory.allocated; nk_push_scissor(&popup->buffer, nk_null_rect); if (nk_panel_begin(ctx, title, NK_PANEL_POPUP)) { /* popup is running therefore invalidate parent panels */ struct nk_panel *root; root = win->layout; while (root) { root->flags |= NK_WINDOW_ROM; root->flags &= ~(nk_flags)NK_WINDOW_REMOVE_ROM; root = root->parent; } win->popup.active = 1; popup->layout->offset_x = &popup->scrollbar.x; popup->layout->offset_y = &popup->scrollbar.y; popup->layout->parent = win->layout; return 1; } else { /* popup was closed/is invalid so cleanup */ struct nk_panel *root; root = win->layout; while (root) { root->flags |= NK_WINDOW_REMOVE_ROM; root = root->parent; } win->popup.buf.active = 0; win->popup.active = 0; ctx->memory.allocated = allocated; ctx->current = win; nk_free_panel(ctx, popup->layout); popup->layout = 0; return 0; } } ``` -------------------------------- ### Initialize Nuklear String with Default Allocator Source: https://immediate-mode-ui.github.io/Nuklear/nuklear__string_8c_source.html Initializes a Nuklear string structure using the default memory allocator. This is a convenient way to get started with string handling. ```c #include "nuklear.h" #include "nuklear_internal.h" NK_API void nk_str_init_default(struct nk_str *str) { struct nk_allocator alloc; alloc.userdata.ptr = 0; alloc.alloc = nk_malloc; alloc.free = nk_mfree; nk_buffer_init(&str->buffer, &alloc, 32); str->len = 0; } ``` -------------------------------- ### Full Input and Rendering Loop Source: https://immediate-mode-ui.github.io/Nuklear/Input.html This example illustrates a complete application loop that includes initializing Nuklear, handling all input events, clearing the context, rendering the UI, and freeing resources. It shows the typical flow for a Nuklear application. ```c struct nk_context ctx; nk_init_xxx(&ctx, ...); while (1) { 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_end(&ctx); // [...] nk_clear(&ctx); } nk_free(&ctx); ``` -------------------------------- ### Initialize Nuklear Context with Default Allocator Source: https://immediate-mode-ui.github.io/Nuklear/nuklear__context_8c_source.html Initializes the Nuklear context using the default memory allocator (malloc/mfree). This is a convenient way to get started if custom memory management is not required. ```c #include "nuklear.h" struct nk_context ctx; // Initialize with default allocator and a font (optional) if (nk_init_default(&ctx, 0)) { // Context initialized successfully } else { // Initialization failed } ``` -------------------------------- ### Begin Menu with Image Button Source: https://immediate-mode-ui.github.io/Nuklear/nuklear__menu_8c_source.html Initiates a menu window using an image button as the header. Requires a valid context, window, and input state. The menu is displayed if the image button is clicked. ```c NK_API nk_bool nk_menu_begin_image(struct nk_context *ctx, const char *id, struct nk_image img, struct nk_vec2 size) { struct nk_window *win; const struct nk_input *in; struct nk_rect header; int is_clicked = nk_false; nk_flags state; NK_ASSERT(ctx->current->layout); if (!ctx || !ctx->current || !ctx->current->layout) return 0; win = ctx->current; state = nk_widget(&header, ctx); if (!state) return 0; in = (state == NK_WIDGET_ROM || state == NK_WIDGET_DISABLED || win->layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; if (nk_do_button_image(&ctx->last_widget_state, &win->buffer, header, img, NK_BUTTON_DEFAULT, &ctx->style.menu_button, in)) is_clicked = nk_true; return nk_menu_begin(ctx, win, id, is_clicked, header, size); } ``` -------------------------------- ### Get Start of Nuklear Draw Commands Source: https://immediate-mode-ui.github.io/Nuklear/nuklear__vertex_8c_source.html Retrieves a pointer to the first draw command in a Nuklear draw list's command buffer. Ensures the buffer is valid and contains commands before returning. ```c #include "nuklear.h" #include "nuklear_internal.h" const struct nk_draw_command* nk__draw_list_begin(const struct nk_draw_list *canvas, const struct nk_buffer *buffer) { nk_byte *memory; nk_size offset; const struct nk_draw_command *cmd; NK_ASSERT(buffer); if (!buffer || !buffer->size || !canvas->cmd_count) return 0; memory = (nk_byte*)buffer->memory.ptr; offset = buffer->memory.size - canvas->cmd_offset; cmd = nk_ptr_add(const struct nk_draw_command, memory, offset); return cmd; } ``` -------------------------------- ### Begin Nuklear Window (Titled) Source: https://immediate-mode-ui.github.io/Nuklear/nuklear__window_8c_source.html Initiates a Nuklear window, creating it if it doesn't exist. It sets up the window's properties, including name, title, bounds, and flags. Requires a font to be loaded. ```c #include "nuklear.h" NK_API nk_bool nk_begin_titled(struct nk_context *ctx, const char *name, const char *title, struct nk_rect bounds, nk_flags flags) { struct nk_window *win; struct nk_style *style; nk_hash name_hash; int name_len; int ret = 0; NK_ASSERT(ctx); NK_ASSERT(name); NK_ASSERT(title); NK_ASSERT(ctx->style.font && ctx->style.font->width && "if this triggers you forgot to add a font"); NK_ASSERT(!ctx->current && "if this triggers you missed a `nk_end` call"); if (!ctx || ctx->current || !title || !name) return 0; /* find or create window */ style = &ctx->style; name_len = (int)nk_strlen(name); name_hash = nk_murmur_hash(name, (int)name_len, NK_WINDOW_TITLE); win = nk_find_window(ctx, name_hash, name); if (!win) { /* create new window */ nk_size name_length = (nk_size)name_len; win = (struct nk_window*)nk_create_window(ctx); NK_ASSERT(win); if (!win) return 0; if (flags & NK_WINDOW_BACKGROUND) nk_insert_window(ctx, win, NK_INSERT_FRONT); else nk_insert_window(ctx, win, NK_INSERT_BACK); nk_command_buffer_init(&win->buffer, &ctx->memory, NK_CLIPPING_ON); win->flags = flags; win->bounds = bounds; win->name = name_hash; name_length = NK_MIN(name_length, NK_WINDOW_MAX_NAME-1); /* ... rest of the function */ } ``` -------------------------------- ### Get Rune at Position Source: https://immediate-mode-ui.github.io/Nuklear/nuklear__string_8c_source.html A convenience function to get only the UTF-8 rune at a specific character position in a string. It internally calls `nk_str_at_const`. ```c NK_API nk_rune nk_str_rune_at(const struct nk_str *str, int pos) { int len; nk_rune unicode = 0; nk_str_at_const(str, pos, &unicode, &len); return unicode; } ``` -------------------------------- ### nk_menubar_begin Source: https://immediate-mode-ui.github.io/Nuklear/nuklear__menu_8c_source.html Starts a menubar at the top of the current window. This function should be called after `nk_begin` and before any other widgets within the menubar. It sets up the layout for menu items. ```APIDOC ## nk_menubar_begin ### Description Starts a menubar at the top of the current window. This function should be called after `nk_begin` and before any other widgets within the menubar. It sets up the layout for menu items. ### Function Signature ```c void nk_menubar_begin(struct nk_context *ctx) ``` ### Parameters * **ctx** (*struct nk_context* *) - Pointer to the Nuklear context. ``` -------------------------------- ### C++ Class Definitions for Doxygen Graph Example Source: https://immediate-mode-ui.github.io/Nuklear/graph_legend.html These C++ class definitions are used to generate an example Doxygen graph, illustrating various inheritance and usage scenarios. ```cpp /*! Invisible class because of truncation */ class Invisible { }; /*! Truncated class, inheritance relation is hidden */ class Truncated : public Invisible { }; /* Class not documented with doxygen comments */ class Undocumented { }; /*! Class that is inherited using public inheritance */ class PublicBase : public Truncated { }; /*! A template class */ template class Templ { }; /*! Class that is inherited using protected inheritance */ class ProtectedBase { }; /*! Class that is inherited using private inheritance */ class PrivateBase { }; /*! Class that is used by the Inherited class */ class Used { }; /*! Super class that inherits a number of other classes */ class Inherited : public PublicBase, protected ProtectedBase, private PrivateBase, public Undocumented, public Templ { private: Used *m_usedClass; }; ``` -------------------------------- ### End Row Layout Source: https://immediate-mode-ui.github.io/Nuklear/nuklear_8h_source.html Finishes the definition of a row started with `nk_layout_row_begin`. ```c NK_API void nk_layout_row_end(struct nk_context*); ``` -------------------------------- ### Begin Image Menu Source: https://immediate-mode-ui.github.io/Nuklear/nuklear__menu_8c_source.html Starts a menu that is triggered by an image button. This function sets up the header rectangle and checks for input, then calls the internal menu begin function. ```c NK_API nk_bool nk_menu_begin_image(struct nk_context *ctx, const char *id, struct nk_image img, struct nk_vec2 size) { struct nk_window *win; struct nk_rect header; const struct nk_input *in; int is_clicked = nk_false; nk_flags state; NK_ASSERT(ctx); NK_ASSERT(ctx->current); ``` -------------------------------- ### Begin Layout Space Source: https://immediate-mode-ui.github.io/Nuklear/nuklear_8h_source.html Starts defining a layout space with a specific format, height, and expected widget count. Use `nk_layout_space_push` to define areas within this space. ```c NK_API void nk_layout_space_begin(struct nk_context*, enum nk_layout_format, float height, int widget_count); ``` -------------------------------- ### End Layout Space Source: https://immediate-mode-ui.github.io/Nuklear/nuklear_8h_source.html Finishes the definition of a layout space started with `nk_layout_space_begin`. ```c NK_API void nk_layout_space_end(struct nk_context*); ``` -------------------------------- ### Begin Tooltip Source: https://immediate-mode-ui.github.io/Nuklear/nuklear__tooltip_8c_source.html Initiates a tooltip with a specified width. It uses default positioning and offset from the window style. ```c #include "nuklear.h" #include "nuklear_internal.h" NK_API nk_bool nk_tooltip_begin(struct nk_context *ctx, float width) { return nk_tooltip_begin_offset(ctx, width, ctx->style.window.tooltip_origin, ctx->style.window.tooltip_offset); } ``` -------------------------------- ### Get position from nk_rect Source: https://immediate-mode-ui.github.io/Nuklear/nuklear__math_8c_source.html Extracts the position (x, y) from a rectangle and returns it as a nk_vec2. ```c NK_API struct nk_vec2 nk_rect_pos(struct nk_rect r) { struct nk_vec2 ret; ret.x = r.x; ret.y = r.y; return ret; } ``` -------------------------------- ### End Row Template Source: https://immediate-mode-ui.github.io/Nuklear/nuklear_8h_source.html Finishes the definition of a row using a template started with `nk_layout_row_template_begin`. ```c NK_API void nk_layout_row_template_end(struct nk_context*); ``` -------------------------------- ### Setup Panel Layout Source: https://immediate-mode-ui.github.io/Nuklear/nuklear__panel_8c_source.html Initializes the panel layout structure based on window properties and style settings. Adjusts bounds for borders and scrollbars, and sets initial positioning for content. ```c /* setup panel */ layout->type = panel_type; layout->flags = win->flags; layout->bounds = win->bounds; layout->bounds.x += panel_padding.x; layout->bounds.w -= 2*panel_padding.x; if (win->flags & NK_WINDOW_BORDER) { layout->border = nk_panel_get_border(style, win->flags, panel_type); layout->bounds = nk_shrink_rect(layout->bounds, layout->border); } else layout->border = 0; layout->at_y = layout->bounds.y; layout->at_x = layout->bounds.x; layout->max_x = 0; layout->header_height = 0; layout->footer_height = 0; nk_layout_reset_min_row_height(ctx); layout->row.index = 0; layout->row.columns = 0; layout->row.ratio = 0; layout->row.item_width = 0; layout->row.tree_depth = 0; layout->row.height = panel_padding.y; layout->has_scrolling = nk_true; if (!(win->flags & NK_WINDOW_NO_SCROLLBAR)) layout->bounds.w -= scrollbar_size.x; if (!nk_panel_is_nonblock(panel_type)) { layout->footer_height = 0; if (!(win->flags & NK_WINDOW_NO_SCROLLBAR) || win->flags & NK_WINDOW_SCALABLE) layout->footer_height = scrollbar_size.y; layout->bounds.h -= layout->footer_height; } ``` -------------------------------- ### Get Window Size Source: https://immediate-mode-ui.github.io/Nuklear/nuklear_8h_source.html Retrieves the current size (width and height) of the active window. ```c NK_API struct nk_vec2 nk_window_get_size(const struct nk_context *ctx); ``` -------------------------------- ### Get size from nk_rect Source: https://immediate-mode-ui.github.io/Nuklear/nuklear__math_8c_source.html Extracts the size (width, height) from a rectangle and returns it as a nk_vec2. ```c NK_API struct nk_vec2 nk_rect_size(struct nk_rect r) { struct nk_vec2 ret; ret.x = r.w; ret.y = r.h; return ret; } ``` -------------------------------- ### Begin Menu with Image and Text Button Source: https://immediate-mode-ui.github.io/Nuklear/nuklear__menu_8c_source.html Creates a menu window header using a button that displays both an image and text. Handles input and styling for the button. The menu is initiated if the button is pressed. ```c NK_API nk_bool nk_menu_begin_image_text(struct nk_context *ctx, const char *title, int len, nk_flags align, struct nk_image img, struct nk_vec2 size) { struct nk_window *win; struct nk_rect header; const struct nk_input *in; int is_clicked = nk_false; nk_flags state; NK_ASSERT(ctx); NK_ASSERT(ctx->current); NK_ASSERT(ctx->current->layout); if (!ctx || !ctx->current || !ctx->current->layout) return 0; win = ctx->current; state = nk_widget(&header, ctx); if (!state) return 0; in = (state == NK_WIDGET_ROM || state == NK_WIDGET_DISABLED || win->layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; if (nk_do_button_text_image(&ctx->last_widget_state, &win->buffer, header, img, title, len, align, NK_BUTTON_DEFAULT, &ctx->style.menu_button, ctx->style.font, in)) is_clicked = nk_true; return nk_menu_begin(ctx, win, title, is_clicked, header, size); } ``` -------------------------------- ### Begin Free-Form Layout Space Source: https://immediate-mode-ui.github.io/Nuklear/nuklear__layout_8c_source.html Initiates a free-form layout space within the current window. Use NK_STATIC for fixed-size widgets or NK_DYNAMIC for widgets that adapt to available space. ```c NK_API void nk_layout_space_begin(struct nk_context *ctx, enum nk_layout_format fmt, float height, int widget_count) { struct nk_window *win; struct nk_panel *layout; NK_ASSERT(ctx); NK_ASSERT(ctx->current); NK_ASSERT(ctx->current->layout); if (!ctx || !ctx->current || !ctx->current->layout) return; win = ctx->current; layout = win->layout; nk_panel_layout(ctx, win, height, widget_count); if (fmt == NK_STATIC) layout->row.type = NK_LAYOUT_STATIC_FREE; else layout->row.type = NK_LAYOUT_DYNAMIC_FREE; layout->row.ratio = 0; layout->row.filled = 0; layout->row.item_width = 0; layout->row.item_offset = 0; } ``` -------------------------------- ### Begin Combo Box with Symbol Source: https://immediate-mode-ui.github.io/Nuklear/nuklear__combo_8c_source.html Initiates a combo box that displays a symbol. This function sets up the combo box header, including drawing the background, border, and the symbol button. ```c NK_API nk_bool nk_combo_begin_symbol(struct nk_context *ctx, enum nk_symbol_type symbol, struct nk_vec2 size) { struct nk_window *win; struct nk_style *style; const struct nk_input *in; struct nk_rect header; int is_clicked = nk_false; enum nk_widget_layout_states s; const struct nk_style_item *background; struct nk_color sym_background; struct nk_color symbol_color; NK_ASSERT(ctx); NK_ASSERT(ctx->current); NK_ASSERT(ctx->current->layout); if (!ctx || !ctx->current || !ctx->current->layout) return 0; win = ctx->current; style = &ctx->style; s = nk_widget(&header, ctx); ``` -------------------------------- ### Begin Combo Box with Color Source: https://immediate-mode-ui.github.io/Nuklear/nuklear__combo_8c_source.html Initiates a combo box that displays a color swatch. It handles drawing the combo box header, background, border, color swatch, and the open/close button. ```c NK_API nk_bool nk_combo_begin_color(struct nk_context *ctx, struct nk_color color, struct nk_vec2 size) { struct nk_window *win; struct nk_style *style; const struct nk_input *in; struct nk_rect header; int is_clicked = nk_false; enum nk_widget_layout_states s; const struct nk_style_item *background; NK_ASSERT(ctx); NK_ASSERT(ctx->current); NK_ASSERT(ctx->current->layout); if (!ctx || !ctx->current || !ctx->current->layout) return 0; win = ctx->current; style = &ctx->style; s = nk_widget(&header, ctx); if (s == NK_WIDGET_INVALID) return 0; in = (win->layout->flags & NK_WINDOW_ROM || s == NK_WIDGET_DISABLED || s == NK_WIDGET_ROM)? 0: &ctx->input; if (nk_button_behavior(&ctx->last_widget_state, header, in, NK_BUTTON_DEFAULT)) is_clicked = nk_true; /* draw combo box header background and border */ if (ctx->last_widget_state & NK_WIDGET_STATE_ACTIVED) background = &style->combo.active; else if (ctx->last_widget_state & NK_WIDGET_STATE_HOVER) background = &style->combo.hover; else background = &style->combo.normal; switch(background->type) { case NK_STYLE_ITEM_IMAGE: nk_draw_image(&win->buffer, header, &background->data.image, nk_rgb_factor(nk_white, style->combo.color_factor)); break; case NK_STYLE_ITEM_NINE_SLICE: nk_draw_nine_slice(&win->buffer, header, &background->data.slice, nk_rgb_factor(nk_white, style->combo.color_factor)); break; case NK_STYLE_ITEM_COLOR: nk_fill_rect(&win->buffer, header, style->combo.rounding, nk_rgb_factor(background->data.color, style->combo.color_factor)); nk_stroke_rect(&win->buffer, header, style->combo.rounding, style->combo.border, nk_rgb_factor(style->combo.border_color, style->combo.color_factor)); break; } { struct nk_rect content; struct nk_rect button; struct nk_rect bounds; int draw_button_symbol; enum nk_symbol_type sym; if (ctx->last_widget_state & NK_WIDGET_STATE_HOVER) sym = style->combo.sym_hover; else if (is_clicked) sym = style->combo.sym_active; else sym = style->combo.sym_normal; /* represents whether or not the combo's button symbol should be drawn */ draw_button_symbol = sym != NK_SYMBOL_NONE; /* calculate button */ button.w = header.h - 2 * style->combo.button_padding.y; button.x = (header.x + header.w - header.h) - style->combo.button_padding.x; button.y = header.y + style->combo.button_padding.y; button.h = button.w; content.x = button.x + style->combo.button.padding.x; content.y = button.y + style->combo.button.padding.y; content.w = button.w - 2 * style->combo.button.padding.x; content.h = button.h - 2 * style->combo.button.padding.y; /* draw color */ bounds.h = header.h - 4 * style->combo.content_padding.y; bounds.y = header.y + 2 * style->combo.content_padding.y; bounds.x = header.x + 2 * style->combo.content_padding.x; if (draw_button_symbol) bounds.w = (button.x - (style->combo.content_padding.x + style->combo.spacing.x)) - bounds.x; else bounds.w = header.w - 4 * style->combo.content_padding.x; nk_fill_rect(&win->buffer, bounds, 0, nk_rgb_factor(color, style->combo.color_factor)); /* draw open/close button */ if (draw_button_symbol) nk_draw_button_symbol(&win->buffer, &button, &content, ctx->last_widget_state, &ctx->style.combo.button, sym, style->font); } return nk_combo_begin(ctx, win, size, is_clicked, header); } ``` -------------------------------- ### Popup Functions Source: https://immediate-mode-ui.github.io/Nuklear/nuklear_8h_source.html Functions for managing popup windows, including getting and setting scroll offsets. ```APIDOC ## nk_popup_get_scroll ### Description Retrieves the current scroll offset of a popup window. ### Signature ```c NK_API void nk_popup_get_scroll(const struct nk_context* ctx, nk_uint *offset_x, nk_uint *offset_y); ``` ## nk_popup_set_scroll ### Description Sets the scroll offset for a popup window. ### Signature ```c NK_API void nk_popup_set_scroll(struct nk_context* ctx, nk_uint offset_x, nk_uint offset_y); ``` ``` -------------------------------- ### Get Window Scroll Offset Source: https://immediate-mode-ui.github.io/Nuklear/nuklear_8h_source.html Retrieves the current scroll offsets (X and Y) of the active window. ```c NK_API void nk_window_get_scroll(const struct nk_context *ctx, nk_uint *offset_x, nk_uint *offset_y); ``` -------------------------------- ### Begin Combo Box with Image and Label Source: https://immediate-mode-ui.github.io/Nuklear/nuklear__combo_8c_source.html Initiates a combo box with an image and a selected label. Ideal for combo boxes where each item has a corresponding image. ```c NK_API nk_bool nk_combo_begin_image_label(struct nk_context *ctx, const char *selected, struct nk_image img, struct nk_vec2 size) { return nk_combo_begin_image_text(ctx, selected, nk_strlen(selected), img, size); } ``` -------------------------------- ### Widget Bounds and Geometry Source: https://immediate-mode-ui.github.io/Nuklear/nuklear__widget_8c_source.html Functions to get the bounding rectangle, position, and size of the current widget. ```APIDOC ## nk_widget_bounds ### Description Returns the bounding rectangle of the current widget. ### Function Signature `struct nk_rect nk_widget_bounds(const struct nk_context *ctx);` ### Parameters - `ctx` (struct nk_context*): Pointer to the Nuklear context. ### Returns A `struct nk_rect` representing the widget's bounds. ## nk_widget_position ### Description Returns the top-left position of the current widget. ### Function Signature `struct nk_vec2 nk_widget_position(const struct nk_context *ctx);` ### Parameters - `ctx` (struct nk_context*): Pointer to the Nuklear context. ### Returns A `struct nk_vec2` representing the widget's position. ## nk_widget_size ### Description Returns the size (width and height) of the current widget. ### Function Signature `struct nk_vec2 nk_widget_size(const struct nk_context *ctx);` ### Parameters - `ctx` (struct nk_context*): Pointer to the Nuklear context. ### Returns A `struct nk_vec2` representing the widget's size. ## nk_widget_width ### Description Returns the width of the current widget. ### Function Signature `float nk_widget_width(const struct nk_context *ctx);` ### Parameters - `ctx` (struct nk_context*): Pointer to the Nuklear context. ### Returns A float representing the widget's width. ## nk_widget_height ### Description Returns the height of the current widget. ### Function Signature `float nk_widget_height(const struct nk_context *ctx);` ### Parameters - `ctx` (struct nk_context*): Pointer to the Nuklear context. ### Returns A float representing the widget's height. ``` -------------------------------- ### Initialize Text Editor with Allocator Source: https://immediate-mode-ui.github.io/Nuklear/nuklear__text__editor_8c_source.html Initializes the text editor using a provided allocator for dynamic memory allocation. Sets up the state and string buffer. ```c NK_API void nk_textedit_init(struct nk_text_edit *state, const struct nk_allocator *alloc, nk_size size) { NK_ASSERT(state); NK_ASSERT(alloc); if (!state || !alloc) return; NK_MEMSET(state, 0, sizeof(struct nk_text_edit)); nk_textedit_clear_state(state, NK_TEXT_EDIT_SINGLE_LINE, 0); nk_str_init(&state->string, alloc, size); } ``` -------------------------------- ### Begin Text Menu Source: https://immediate-mode-ui.github.io/Nuklear/nuklear__menu_8c_source.html Starts a menu that is triggered by a text button. It handles the button interaction and then calls the internal menu begin function. ```c NK_API nk_bool nk_menu_begin_text(struct nk_context *ctx, const char *title, int len, nk_flags align, struct nk_vec2 size) { struct nk_window *win; const struct nk_input *in; struct nk_rect header; int is_clicked = nk_false; nk_flags state; NK_ASSERT(ctx); NK_ASSERT(ctx->current); NK_ASSERT(ctx->current->layout); if (!ctx || !ctx->current || !ctx->current->layout) return 0; win = ctx->current; state = nk_widget(&header, ctx); if (!state) return 0; in = (state == NK_WIDGET_ROM || state == NK_WIDGET_DISABLED || win->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; if (nk_do_button_text(&ctx->last_widget_state, &win->buffer, header, title, len, align, NK_BUTTON_DEFAULT, &ctx->style.menu_button, in, ctx->style.font)) is_clicked = nk_true; return nk_menu_begin(ctx, win, title, is_clicked, header, size); } ``` -------------------------------- ### nk_combo_begin_image_label Source: https://immediate-mode-ui.github.io/Nuklear/nuklear__combo_8c_source.html Starts a new combo box with an image and a label for the selected item. It internally calls `nk_combo_begin_image_text`. ```APIDOC ## nk_combo_begin_image_label ### Description Starts a new combo box that displays an image and a label representing the currently selected item. This function is a convenience wrapper that calls `nk_combo_begin_image_text`. ### Prototype ```c bool nk_combo_begin_image_label(struct nk_context *ctx, const char *selected, struct nk_image img, struct nk_vec2 size) ``` ### Parameters * **ctx** (struct nk_context *) - Pointer to the Nuklear context. * **selected** (const char *) - The label of the currently selected item. * **img** (struct nk_image) - The image to display. * **size** (struct nk_vec2) - The desired size of the combo box. ### Returns * (bool) - Returns true if the combo box was opened, false otherwise. ``` -------------------------------- ### nk_combo_begin_symbol_label Source: https://immediate-mode-ui.github.io/Nuklear/nuklear__combo_8c_source.html Starts a new combo box with a symbol and a label for the selected item. It internally calls `nk_combo_begin_symbol_text`. ```APIDOC ## nk_combo_begin_symbol_label ### Description Starts a new combo box that displays a symbol and a label representing the currently selected item. This function is a convenience wrapper that calls `nk_combo_begin_symbol_text`. ### Prototype ```c bool nk_combo_begin_symbol_label(struct nk_context *ctx, const char *selected, enum nk_symbol_type type, struct nk_vec2 size) ``` ### Parameters * **ctx** (struct nk_context *) - Pointer to the Nuklear context. * **selected** (const char *) - The label of the currently selected item. * **type** (enum nk_symbol_type) - The type of symbol to display. * **size** (struct nk_vec2) - The desired size of the combo box. ### Returns * (bool) - Returns true if the combo box was opened, false otherwise. ``` -------------------------------- ### nk_start_buffer Source: https://immediate-mode-ui.github.io/Nuklear/nuklear__context_8c_source.html Initializes a command buffer for a window. This function sets up the buffer's start and end pointers, preparing it to receive drawing commands. ```APIDOC ## nk_start_buffer ### Description Initializes a command buffer for a window. This function sets up the buffer's start and end pointers, preparing it to receive drawing commands. ### Parameters #### Path Parameters - **ctx** (*struct nk_context* *) - Description not available - **buffer** (*struct nk_command_buffer* *) - Description not available ### Method void ### Endpoint N/A (Function Call) ### Request Example ```c struct nk_context ctx; struct nk_command_buffer buffer; // ... initialization ... nk_start_buffer(&ctx, &buffer); ``` ### Response #### Success Response void #### Response Example N/A ``` -------------------------------- ### Get Group Scroll Offset Source: https://immediate-mode-ui.github.io/Nuklear/nuklear_8h_source.html Retrieves the current scroll offsets (X and Y) for a group identified by its ID. ```c NK_API void nk_group_get_scroll(struct nk_context*, const char *id, nk_uint *x_offset, nk_uint *y_offset); ``` -------------------------------- ### nk_begin_titled Source: https://immediate-mode-ui.github.io/Nuklear/nuklear__window_8c_source.html Starts a new window in the Nuklear UI with a specified name and title. It handles finding or creating the window and setting up its initial state. ```APIDOC ## nk_begin_titled ### Description Starts a new window in the Nuklear UI with a specified name and title. It handles finding or creating the window and setting up its initial state. ### Function Signature ```c nk_bool nk_begin_titled(struct nk_context *ctx, const char *name, const char *title, struct nk_rect bounds, nk_flags flags) ``` ### Parameters * **ctx** (struct nk_context *) - Pointer to the Nuklear context. * **name** (const char *) - The unique name of the window. * **title** (const char *) - The title displayed for the window. * **bounds** (struct nk_rect) - The initial bounding rectangle of the window. * **flags** (nk_flags) - Flags to control the window's behavior. ### Returns * (nk_bool) - Returns true if the window was successfully started, false otherwise. ``` -------------------------------- ### Get Window Height Source: https://immediate-mode-ui.github.io/Nuklear/nuklear__window_8c_source.html Retrieves the height of the current window. Asserts that the context and current window are valid. ```c NK_API float nk_window_get_height(const struct nk_context *ctx) { NK_ASSERT(ctx); NK_ASSERT(ctx->current); if (!ctx || !ctx->current) return 0; return ctx->current->bounds.h; } ``` -------------------------------- ### Get Window Width Source: https://immediate-mode-ui.github.io/Nuklear/nuklear__window_8c_source.html Retrieves the width of the current window. Asserts that the context and current window are valid. ```c NK_API float nk_window_get_width(const struct nk_context *ctx) { NK_ASSERT(ctx); NK_ASSERT(ctx->current); if (!ctx || !ctx->current) return 0; return ctx->current->bounds.w; } ``` -------------------------------- ### Open a Popup Window Source: https://immediate-mode-ui.github.io/Nuklear/nuklear__popup_8c_source.html Initiates the opening of a popup window. It sets up the popup's internal state and begins its layout process. Ensure the context and window are valid before calling. ```c NK_API int nk_popup_open( struct nk_context *ctx, enum nk_panel_type panel_type, struct nk_rect const r, struct nk_window *parent) { struct nk_window *popup; int is_active; NK_ASSERT(ctx); NK_ASSERT(ctx->current); NK_ASSERT(ctx->current->layout); if (!ctx || !ctx->current || !ctx->current->layout) return 0; popup = ctx->current; is_active = nk_find_popup(ctx, popup->parent); if (is_active) return 1; popup->flags |= NK_WINDOW_DYNAMIC; popup->seq = ctx->seq; win->popup.active = 1; NK_ASSERT(popup->layout); nk_start_popup(ctx, win); popup->buffer = win->buffer; nk_push_scissor(&popup->buffer, nk_null_rect); ctx->current = popup; nk_panel_begin(ctx, 0, panel_type); win->buffer = popup->buffer; popup->layout->parent = win->layout; popup->layout->offset_x = &popup->scrollbar.x; popup->layout->offset_y = &popup->scrollbar.y; /* set read only mode to all parent panels */ { struct nk_panel *root; root = win->layout; while (root) { root->flags |= NK_WINDOW_ROM; root = root->parent; } } return is_active; } ``` -------------------------------- ### Get Widget Height Source: https://immediate-mode-ui.github.io/Nuklear/nuklear__widget_8c_source.html Retrieves the height of the current widget. Returns 0 if the context or layout is invalid. ```c #include "nuklear.h" #include "nuklear_internal.h" float nk_widget_height(const struct nk_context *ctx) { struct nk_rect bounds; NK_ASSERT(ctx); NK_ASSERT(ctx->current); if (!ctx || !ctx->current) return 0; nk_layout_peek(&bounds, ctx); return bounds.h; } ``` -------------------------------- ### Begin Nuklear Window Source: https://immediate-mode-ui.github.io/Nuklear/nuklear_8h_source.html Starts a new Nuklear window. This function must be called before adding any widgets to the window. It returns true if the window is visible and interactive. ```c NK_API nk_bool nk_begin(struct nk_context *ctx, const char *title, struct nk_rect bounds, nk_flags flags); ``` -------------------------------- ### nk_context::begin Field Source: https://immediate-mode-ui.github.io/Nuklear/structnk__context.html Pointer to the beginning of the window list. ```APIDOC ## ◆ begin struct nk_window* nk_context::begin --- Definition at line 5793 of file nuklear.h. ``` -------------------------------- ### Get Widget Width Source: https://immediate-mode-ui.github.io/Nuklear/nuklear__widget_8c_source.html Retrieves the width of the current widget. Returns 0 if the context or layout is invalid. ```c #include "nuklear.h" #include "nuklear_internal.h" float nk_widget_width(const struct nk_context *ctx) { struct nk_rect bounds; NK_ASSERT(ctx); NK_ASSERT(ctx->current); if (!ctx || !ctx->current) return 0; nk_layout_peek(&bounds, ctx); return bounds.w; } ```