# Nuklear
![](https://cloud.githubusercontent.com/assets/8057201/11761525/ae06f0ca-a0c6-11e5-819d-5610b25f6ef4.gif)
## Contents
1. About section
2. Highlights section
3. Features section
4. Usage section
1. Flags section
2. Constants section
3. Dependencies section
5. Example section
6. API section
1. Context section
2. Input section
3. Drawing section
4. Window section
5. Layouting section
6. Groups section
7. Tree section
8. Properties section
7. License section
8. Changelog section
9. Gallery section
10. Credits section
## About
This is a minimal state immediate mode graphical user interface toolkit
written in ANSI C and licensed under public domain. It was designed as a simple
embeddable user interface for application and does not have any dependencies,
a default renderbackend or OS window and input handling but instead provides a very modular
library approach by using simple input state for input and draw
commands describing primitive shapes as output. So instead of providing a
layered library that tries to abstract over a number of platform and
render backends it only focuses on the actual UI.
## Highlights
- Graphical user interface toolkit
- Single header library
- Written in C89 (a.k.a. ANSI C or ISO C90)
- Small codebase (~18kLOC)
- Focus on portability, efficiency and simplicity
- No dependencies (not even the standard library if not wanted)
- Fully skinnable and customizable
- Low memory footprint with total memory control if needed or wanted
- UTF-8 support
- No global or hidden state
- Customizable library modules (you can compile and use only what you need)
- Optional font baker and vertex buffer output
## Features
- Absolutely no platform dependent code
- Memory management control ranging from/to
- Ease of use by allocating everything from standard library
- Control every byte of memory inside the library
- Font handling control ranging from/to
- Use your own font implementation for everything
- Use this libraries internal font baking and handling API
- Drawing output control ranging from/to
- Simple shapes for more high level APIs which already have drawing capabilities
- Hardware accessible anti-aliased vertex buffer output
- Customizable colors and properties ranging from/to
- Simple changes to color by filling a simple color table
- Complete control with ability to use skinning to decorate widgets
- Bendable UI library with widget ranging from/to
- Basic widgets like buttons, checkboxes, slider, ...
- Advanced widget like abstract comboboxes, contextual menus,...
- Compile time configuration to only compile what you need
- Subset which can be used if you do not want to link or use the standard library
- Can be easily modified to only update on user input instead of frame updates
## Usage
This library is self contained in one single header file and can be used either
in header only mode or in implementation mode. The header only mode is used
by default when included and allows including this header in other headers
and does not contain the actual implementation.
The implementation mode requires to define the preprocessor macro
NK_IMPLEMENTATION in *one* .c/.cpp file before #including this file, e.g.:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~C
#define NK_IMPLEMENTATION
#include "nuklear.h"
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Also optionally define the symbols listed in the section "OPTIONAL DEFINES"
below in header and implementation mode if you want to use additional functionality
or need more control over the library.
!!! WARNING
Every time nuklear is included define the same compiler flags. This very important not doing so could lead to compiler errors or even worse stack corruptions.
### Flags
Flag | Description
--------------------------------|------------------------------------------
NK_PRIVATE | If defined declares all functions as static, so they can only be accessed inside the file that contains the implementation
NK_INCLUDE_FIXED_TYPES | If defined it will include header `
Each window holds frame persistent state like position, size, flags, state tables,
and some garbage collected internal persistent widget state. Each window
is linked into a window stack list which determines the drawing and overlapping
order. The topmost window thereby is the currently active window.
To change window position inside the stack occurs either automatically by
user input by being clicked on or programmatically by calling `nk_window_focus`.
Windows by default are visible unless explicitly being defined with flag
`NK_WINDOW_HIDDEN`, the user clicked the close button on windows with flag
`NK_WINDOW_CLOSABLE` or if a window was explicitly hidden by calling
`nk_window_show`. To explicitly close and destroy a window call `nk_window_close`.
#### Usage
To create and keep a window you have to call one of the two `nk_begin_xxx`
functions to start window declarations and `nk_end` at the end. Furthermore it
is recommended to check the return value of `nk_begin_xxx` and only process
widgets inside the window if the value is not 0. Either way you have to call
`nk_end` at the end of window declarations. Furthermore, do not attempt to
nest `nk_begin_xxx` calls which will hopefully result in an assert or if not
in a segmentation fault.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
if (nk_begin_xxx(...) {
// [... widgets ...]
}
nk_end(ctx);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In the grand concept window and widget declarations need to occur after input
handling and before drawing to screen. Not doing so can result in higher
latency or at worst invalid behavior. Furthermore make sure that `nk_clear`
is called at the end of the frame. While nuklear's default platform backends
already call `nk_clear` for you if you write your own backend not calling
`nk_clear` can cause asserts or even worse undefined behavior.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~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_xxx(...);
}
}
nk_input_end(&ctx);
if (nk_begin_xxx(...) {
//[...]
}
nk_end(ctx);
const struct nk_command *cmd = 0;
nk_foreach(cmd, &ctx) {
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);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#### Reference
Function | Description
------------------------------------|----------------------------------------
nk_begin | Starts a new window; needs to be called every frame for every window (unless hidden) or otherwise the window gets removed
nk_begin_titled | Extended window start with separated title and identifier to allow multiple windows with same name but not title
nk_end | Needs to be called at the end of the window building process to process scaling, scrollbars and general cleanup
nk_window_find | Finds and returns the window with give name
nk_window_get_bounds | Returns a rectangle with screen position and size of the currently processed window.
nk_window_get_position | Returns the position of the currently processed window
nk_window_get_size | Returns the size with width and height of the currently processed window
nk_window_get_width | Returns the width of the currently processed window
nk_window_get_height | Returns the height of the currently processed window
nk_window_get_panel | Returns the underlying panel which contains all processing state of the current window
nk_window_get_content_region | Returns the position and size of the currently visible and non-clipped space inside the currently processed window
nk_window_get_content_region_min | Returns the upper rectangle position of the currently visible and non-clipped space inside the currently processed window
nk_window_get_content_region_max | Returns the upper rectangle position of the currently visible and non-clipped space inside the currently processed window
nk_window_get_content_region_size | Returns the size of the currently visible and non-clipped space inside the currently processed window
nk_window_get_canvas | Returns the draw command buffer. Can be used to draw custom widgets
nk_window_get_scroll | Gets the scroll offset of the current window
nk_window_has_focus | Returns if the currently processed window is currently active
nk_window_is_collapsed | Returns if the window with given name is currently minimized/collapsed
nk_window_is_closed | Returns if the currently processed window was closed
nk_window_is_hidden | Returns if the currently processed window was hidden
nk_window_is_active | Same as nk_window_has_focus for some reason
nk_window_is_hovered | Returns if the currently processed window is currently being hovered by mouse
nk_window_is_any_hovered | Return if any window currently hovered
nk_item_is_any_active | Returns if any window or widgets is currently hovered or active
nk_window_set_bounds | Updates position and size of the currently processed window
nk_window_set_position | Updates position of the currently process window
nk_window_set_size | Updates the size of the currently processed window
nk_window_set_focus | Set the currently processed window as active window
nk_window_set_scroll | Sets the scroll offset of the current window
nk_window_close | Closes the window with given window name which deletes the window at the end of the frame
nk_window_collapse | Collapses the window with given window name
nk_window_collapse_if | Collapses the window with given window name if the given condition was met
nk_window_show | Hides a visible or reshows a hidden window
nk_window_show_if | Hides/shows a window depending on condition
#### nk_panel_flags
Flag | Description
----------------------------|----------------------------------------
NK_WINDOW_BORDER | Draws a border around the window to visually separate window from the background
NK_WINDOW_MOVABLE | The movable flag indicates that a window can be moved by user input or by dragging the window header
NK_WINDOW_SCALABLE | The scalable flag indicates that a window can be scaled by user input by dragging a scaler icon at the button of the window
NK_WINDOW_CLOSABLE | Adds a closable icon into the header
NK_WINDOW_MINIMIZABLE | Adds a minimize icon into the header
NK_WINDOW_NO_SCROLLBAR | Removes the scrollbar from the window
NK_WINDOW_TITLE | Forces a header at the top at the window showing the title
NK_WINDOW_SCROLL_AUTO_HIDE | Automatically hides the window scrollbar if no user interaction: also requires delta time in `nk_context` to be set each frame
NK_WINDOW_BACKGROUND | Always keep window in the background
NK_WINDOW_SCALE_LEFT | Puts window scaler in the left-bottom corner instead right-bottom
NK_WINDOW_NO_INPUT | Prevents window of scaling, moving or getting focus
#### nk_collapse_states
State | Description
----------------|-----------------------------------------------------------
__NK_MINIMIZED__| UI section is collased and not visible until maximized
__NK_MAXIMIZED__| UI section is extended and visible until minimized
#### nk_begin
Starts a new window; needs to be called every frame for every
window (unless hidden) or otherwise the window gets removed
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
nk_bool nk_begin(struct nk_context *ctx, const char *title, struct nk_rect bounds, nk_flags flags);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Parameter | Description
------------|-----------------------------------------------------------
__ctx__ | Must point to an previously initialized `nk_context` struct
__title__ | Window title and identifier. Needs to be persistent over frames to identify the window
__bounds__ | Initial position and window size. However if you do not define `NK_WINDOW_SCALABLE` or `NK_WINDOW_MOVABLE` you can set window position and size every frame
__flags__ | Window flags defined in the nk_panel_flags section with a number of different window behaviors
Returns `true(1)` if the window can be filled up with widgets from this point
until `nk_end` or `false(0)` otherwise for example if minimized
#### nk_begin_titled
Extended window start with separated title and identifier to allow multiple
windows with same title but not name
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
nk_bool nk_begin_titled(struct nk_context *ctx, const char *name, const char *title, struct nk_rect bounds, nk_flags flags);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Parameter | Description
------------|-----------------------------------------------------------
__ctx__ | Must point to an previously initialized `nk_context` struct
__name__ | Window identifier. Needs to be persistent over frames to identify the window
__title__ | Window title displayed inside header if flag `NK_WINDOW_TITLE` or either `NK_WINDOW_CLOSABLE` or `NK_WINDOW_MINIMIZED` was set
__bounds__ | Initial position and window size. However if you do not define `NK_WINDOW_SCALABLE` or `NK_WINDOW_MOVABLE` you can set window position and size every frame
__flags__ | Window flags defined in the nk_panel_flags section with a number of different window behaviors
Returns `true(1)` if the window can be filled up with widgets from this point
until `nk_end` or `false(0)` otherwise for example if minimized
#### nk_end
Needs to be called at the end of the window building process to process scaling, scrollbars and general cleanup.
All widget calls after this functions will result in asserts or no state changes
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
void nk_end(struct nk_context *ctx);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Parameter | Description
------------|-----------------------------------------------------------
__ctx__ | Must point to an previously initialized `nk_context` struct
#### nk_window_find
Finds and returns a window from passed name
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
struct nk_window *nk_window_find(struct nk_context *ctx, const char *name);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Parameter | Description
------------|-----------------------------------------------------------
__ctx__ | Must point to an previously initialized `nk_context` struct
__name__ | Window identifier
Returns a `nk_window` struct pointing to the identified window or NULL if
no window with the given name was found
#### nk_window_get_bounds
Returns a rectangle with screen position and size of the currently processed window
!!! WARNING
Only call this function between calls `nk_begin_xxx` and `nk_end`
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
struct nk_rect nk_window_get_bounds(const struct nk_context *ctx);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Parameter | Description
------------|-----------------------------------------------------------
__ctx__ | Must point to an previously initialized `nk_context` struct
Returns a `nk_rect` struct with window upper left window position and size
#### nk_window_get_position
Returns the position of the currently processed window.
!!! WARNING
Only call this function between calls `nk_begin_xxx` and `nk_end`
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
struct nk_vec2 nk_window_get_position(const struct nk_context *ctx);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Parameter | Description
------------|-----------------------------------------------------------
__ctx__ | Must point to an previously initialized `nk_context` struct
Returns a `nk_vec2` struct with window upper left position
#### nk_window_get_size
Returns the size with width and height of the currently processed window.
!!! WARNING
Only call this function between calls `nk_begin_xxx` and `nk_end`
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
struct nk_vec2 nk_window_get_size(const struct nk_context *ctx);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Parameter | Description
------------|-----------------------------------------------------------
__ctx__ | Must point to an previously initialized `nk_context` struct
Returns a `nk_vec2` struct with window width and height
#### nk_window_get_width
Returns the width of the currently processed window.
!!! WARNING
Only call this function between calls `nk_begin_xxx` and `nk_end`
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
float nk_window_get_width(const struct nk_context *ctx);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Parameter | Description
------------|-----------------------------------------------------------
__ctx__ | Must point to an previously initialized `nk_context` struct
Returns the current window width
#### nk_window_get_height
Returns the height of the currently processed window.
!!! WARNING
Only call this function between calls `nk_begin_xxx` and `nk_end`
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
float nk_window_get_height(const struct nk_context *ctx);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Parameter | Description
------------|-----------------------------------------------------------
__ctx__ | Must point to an previously initialized `nk_context` struct
Returns the current window height
#### nk_window_get_panel
Returns the underlying panel which contains all processing state of the current window.
!!! WARNING
Only call this function between calls `nk_begin_xxx` and `nk_end`
!!! WARNING
Do not keep the returned panel pointer around, it is only valid until `nk_end`
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
struct nk_panel* nk_window_get_panel(struct nk_context *ctx);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Parameter | Description
------------|-----------------------------------------------------------
__ctx__ | Must point to an previously initialized `nk_context` struct
Returns a pointer to window internal `nk_panel` state.
#### nk_window_get_content_region
Returns the position and size of the currently visible and non-clipped space
inside the currently processed window.
!!! WARNING
Only call this function between calls `nk_begin_xxx` and `nk_end`
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
struct nk_rect nk_window_get_content_region(struct nk_context *ctx);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Parameter | Description
------------|-----------------------------------------------------------
__ctx__ | Must point to an previously initialized `nk_context` struct
Returns `nk_rect` struct with screen position and size (no scrollbar offset)
of the visible space inside the current window
#### nk_window_get_content_region_min
Returns the upper left position of the currently visible and non-clipped
space inside the currently processed window.
!!! WARNING
Only call this function between calls `nk_begin_xxx` and `nk_end`
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
struct nk_vec2 nk_window_get_content_region_min(struct nk_context *ctx);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Parameter | Description
------------|-----------------------------------------------------------
__ctx__ | Must point to an previously initialized `nk_context` struct
returns `nk_vec2` struct with upper left screen position (no scrollbar offset)
of the visible space inside the current window
#### nk_window_get_content_region_max
Returns the lower right screen position of the currently visible and
non-clipped space inside the currently processed window.
!!! WARNING
Only call this function between calls `nk_begin_xxx` and `nk_end`
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
struct nk_vec2 nk_window_get_content_region_max(struct nk_context *ctx);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Parameter | Description
------------|-----------------------------------------------------------
__ctx__ | Must point to an previously initialized `nk_context` struct
Returns `nk_vec2` struct with lower right screen position (no scrollbar offset)
of the visible space inside the current window
#### nk_window_get_content_region_size
Returns the size of the currently visible and non-clipped space inside the
currently processed window
!!! WARNING
Only call this function between calls `nk_begin_xxx` and `nk_end`
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
struct nk_vec2 nk_window_get_content_region_size(struct nk_context *ctx);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Parameter | Description
------------|-----------------------------------------------------------
__ctx__ | Must point to an previously initialized `nk_context` struct
Returns `nk_vec2` struct with size the visible space inside the current window
#### nk_window_get_canvas
Returns the draw command buffer. Can be used to draw custom widgets
!!! WARNING
Only call this function between calls `nk_begin_xxx` and `nk_end`
!!! WARNING
Do not keep the returned command buffer pointer around it is only valid until `nk_end`
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
struct nk_command_buffer* nk_window_get_canvas(struct nk_context *ctx);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Parameter | Description
------------|-----------------------------------------------------------
__ctx__ | Must point to an previously initialized `nk_context` struct
Returns a pointer to window internal `nk_command_buffer` struct used as
drawing canvas. Can be used to do custom drawing.
#### nk_window_get_scroll
Gets the scroll offset for the current window
!!! WARNING
Only call this function between calls `nk_begin_xxx` and `nk_end`
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
void nk_window_get_scroll(struct nk_context *ctx, nk_uint *offset_x, nk_uint *offset_y);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Parameter | Description
-------------|-----------------------------------------------------------
__ctx__ | Must point to an previously initialized `nk_context` struct
__offset_x__ | A pointer to the x offset output (or NULL to ignore)
__offset_y__ | A pointer to the y offset output (or NULL to ignore)
#### nk_window_has_focus
Returns if the currently processed window is currently active
!!! WARNING
Only call this function between calls `nk_begin_xxx` and `nk_end`
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
nk_bool nk_window_has_focus(const struct nk_context *ctx);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Parameter | Description
------------|-----------------------------------------------------------
__ctx__ | Must point to an previously initialized `nk_context` struct
Returns `false(0)` if current window is not active or `true(1)` if it is
#### nk_window_is_hovered
Return if the current window is being hovered
!!! WARNING
Only call this function between calls `nk_begin_xxx` and `nk_end`
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
nk_bool nk_window_is_hovered(struct nk_context *ctx);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Parameter | Description
------------|-----------------------------------------------------------
__ctx__ | Must point to an previously initialized `nk_context` struct
Returns `true(1)` if current window is hovered or `false(0)` otherwise
#### nk_window_is_collapsed
Returns if the window with given name is currently minimized/collapsed
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
nk_bool nk_window_is_collapsed(struct nk_context *ctx, const char *name);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Parameter | Description
------------|-----------------------------------------------------------
__ctx__ | Must point to an previously initialized `nk_context` struct
__name__ | Identifier of window you want to check if it is collapsed
Returns `true(1)` if current window is minimized and `false(0)` if window not
found or is not minimized
#### nk_window_is_closed
Returns if the window with given name was closed by calling `nk_close`
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
nk_bool nk_window_is_closed(struct nk_context *ctx, const char *name);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Parameter | Description
------------|-----------------------------------------------------------
__ctx__ | Must point to an previously initialized `nk_context` struct
__name__ | Identifier of window you want to check if it is closed
Returns `true(1)` if current window was closed or `false(0)` window not found or not closed
#### nk_window_is_hidden
Returns if the window with given name is hidden
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
nk_bool nk_window_is_hidden(struct nk_context *ctx, const char *name);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Parameter | Description
------------|-----------------------------------------------------------
__ctx__ | Must point to an previously initialized `nk_context` struct
__name__ | Identifier of window you want to check if it is hidden
Returns `true(1)` if current window is hidden or `false(0)` window not found or visible
#### nk_window_is_active
Same as nk_window_has_focus for some reason
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
nk_bool nk_window_is_active(struct nk_context *ctx, const char *name);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Parameter | Description
------------|-----------------------------------------------------------
__ctx__ | Must point to an previously initialized `nk_context` struct
__name__ | Identifier of window you want to check if it is active
Returns `true(1)` if current window is active or `false(0)` window not found or not active
#### nk_window_is_any_hovered
Returns if the any window is being hovered
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
nk_bool nk_window_is_any_hovered(struct nk_context*);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Parameter | Description
------------|-----------------------------------------------------------
__ctx__ | Must point to an previously initialized `nk_context` struct
Returns `true(1)` if any window is hovered or `false(0)` otherwise
#### nk_item_is_any_active
Returns if the any window is being hovered or any widget is currently active.
Can be used to decide if input should be processed by UI or your specific input handling.
Example could be UI and 3D camera to move inside a 3D space.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
nk_bool nk_item_is_any_active(struct nk_context*);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Parameter | Description
------------|-----------------------------------------------------------
__ctx__ | Must point to an previously initialized `nk_context` struct
Returns `true(1)` if any window is hovered or any item is active or `false(0)` otherwise
#### nk_window_set_bounds
Updates position and size of window with passed in name
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
void nk_window_set_bounds(struct nk_context*, const char *name, struct nk_rect bounds);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Parameter | Description
------------|-----------------------------------------------------------
__ctx__ | Must point to an previously initialized `nk_context` struct
__name__ | Identifier of the window to modify both position and size
__bounds__ | Must point to a `nk_rect` struct with the new position and size
#### nk_window_set_position
Updates position of window with passed name
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
void nk_window_set_position(struct nk_context*, const char *name, struct nk_vec2 pos);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Parameter | Description
------------|-----------------------------------------------------------
__ctx__ | Must point to an previously initialized `nk_context` struct
__name__ | Identifier of the window to modify both position
__pos__ | Must point to a `nk_vec2` struct with the new position
#### nk_window_set_size
Updates size of window with passed in name
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
void nk_window_set_size(struct nk_context*, const char *name, struct nk_vec2);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Parameter | Description
------------|-----------------------------------------------------------
__ctx__ | Must point to an previously initialized `nk_context` struct
__name__ | Identifier of the window to modify both window size
__size__ | Must point to a `nk_vec2` struct with new window size
#### nk_window_set_focus
Sets the window with given name as active
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
void nk_window_set_focus(struct nk_context*, const char *name);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Parameter | Description
------------|-----------------------------------------------------------
__ctx__ | Must point to an previously initialized `nk_context` struct
__name__ | Identifier of the window to set focus on
#### nk_window_set_scroll
Sets the scroll offset for the current window
!!! WARNING
Only call this function between calls `nk_begin_xxx` and `nk_end`
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
void nk_window_set_scroll(struct nk_context *ctx, nk_uint offset_x, nk_uint offset_y);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Parameter | Description
-------------|-----------------------------------------------------------
__ctx__ | Must point to an previously initialized `nk_context` struct
__offset_x__ | The x offset to scroll to
__offset_y__ | The y offset to scroll to
#### nk_window_close
Closes a window and marks it for being freed at the end of the frame
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
void nk_window_close(struct nk_context *ctx, const char *name);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Parameter | Description
------------|-----------------------------------------------------------
__ctx__ | Must point to an previously initialized `nk_context` struct
__name__ | Identifier of the window to close
#### nk_window_collapse
Updates collapse state of a window with given name
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
void nk_window_collapse(struct nk_context*, const char *name, enum nk_collapse_states state);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Parameter | Description
------------|-----------------------------------------------------------
__ctx__ | Must point to an previously initialized `nk_context` struct
__name__ | Identifier of the window to close
__state__ | value out of nk_collapse_states section
#### nk_window_collapse_if
Updates collapse state of a window with given name if given condition is met
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
void nk_window_collapse_if(struct nk_context*, const char *name, enum nk_collapse_states, int cond);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Parameter | Description
------------|-----------------------------------------------------------
__ctx__ | Must point to an previously initialized `nk_context` struct
__name__ | Identifier of the window to either collapse or maximize
__state__ | value out of nk_collapse_states section the window should be put into
__cond__ | condition that has to be met to actually commit the collapse state change
#### nk_window_show
updates visibility state of a window with given name
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
void nk_window_show(struct nk_context*, const char *name, enum nk_show_states);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Parameter | Description
------------|-----------------------------------------------------------
__ctx__ | Must point to an previously initialized `nk_context` struct
__name__ | Identifier of the window to either collapse or maximize
__state__ | state with either visible or hidden to modify the window with
#### nk_window_show_if
Updates visibility state of a window with given name if a given condition is met
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
void nk_window_show_if(struct nk_context*, const char *name, enum nk_show_states, int cond);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Parameter | Description
------------|-----------------------------------------------------------
__ctx__ | Must point to an previously initialized `nk_context` struct
__name__ | Identifier of the window to either hide or show
__state__ | state with either visible or hidden to modify the window with
__cond__ | condition that has to be met to actually commit the visbility state change
### Layouting
Layouting in general describes placing widget inside a window with position and size.
While in this particular implementation there are five different APIs for layouting
each with different trade offs between control and ease of use.
All layouting methods in this library are based around the concept of a row.
A row has a height the window content grows by and a number of columns and each
layouting method specifies how each widget is placed inside the row.
After a row has been allocated by calling a layouting functions and then
filled with widgets will advance an internal pointer over the allocated row.
To actually define a layout you just call the appropriate layouting function
and each subsequent widget call will place the widget as specified. Important
here is that if you define more widgets then columns defined inside the layout
functions it will allocate the next row without you having to make another layouting
call.
Biggest limitation with using all these APIs outside the `nk_layout_space_xxx` API
is that you have to define the row height for each. However the row height
often depends on the height of the font.
To fix that internally nuklear uses a minimum row height that is set to the
height plus padding of currently active font and overwrites the row height
value if zero.
If you manually want to change the minimum row height then
use nk_layout_set_min_row_height, and use nk_layout_reset_min_row_height to
reset it back to be derived from font height.
Also if you change the font in nuklear it will automatically change the minimum
row height for you and. This means if you change the font but still want
a minimum row height smaller than the font you have to repush your value.
For actually more advanced UI I would even recommend using the `nk_layout_space_xxx`
layouting method in combination with a cassowary constraint solver (there are
some versions on github with permissive license model) to take over all control over widget
layouting yourself. However for quick and dirty layouting using all the other layouting
functions should be fine.
#### Usage
1. __nk_layout_row_dynamic__
The easiest layouting function is `nk_layout_row_dynamic`. It provides each
widgets with same horizontal space inside the row and dynamically grows
if the owning window grows in width. So the number of columns dictates
the size of each widget dynamically by formula:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
widget_width = (window_width - padding - spacing) * (1/colum_count)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Just like all other layouting APIs if you define more widget than columns this
library will allocate a new row and keep all layouting parameters previously
defined.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
if (nk_begin_xxx(...) {
// first row with height: 30 composed of two widgets
nk_layout_row_dynamic(&ctx, 30, 2);
nk_widget(...);
nk_widget(...);
//
// second row with same parameter as defined above
nk_widget(...);
nk_widget(...);
//
// third row uses 0 for height which will use auto layouting
nk_layout_row_dynamic(&ctx, 0, 2);
nk_widget(...);
nk_widget(...);
}
nk_end(...);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2. __nk_layout_row_static__
Another easy layouting function is `nk_layout_row_static`. It provides each
widget with same horizontal pixel width inside the row and does not grow
if the owning window scales smaller or bigger.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
if (nk_begin_xxx(...) {
// first row with height: 30 composed of two widgets with width: 80
nk_layout_row_static(&ctx, 30, 80, 2);
nk_widget(...);
nk_widget(...);
//
// second row with same parameter as defined above
nk_widget(...);
nk_widget(...);
//
// third row uses 0 for height which will use auto layouting
nk_layout_row_static(&ctx, 0, 80, 2);
nk_widget(...);
nk_widget(...);
}
nk_end(...);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3. __nk_layout_row_xxx__
A little bit more advanced layouting API are functions `nk_layout_row_begin`,
`nk_layout_row_push` and `nk_layout_row_end`. They allow to directly
specify each column pixel or window ratio in a row. It supports either
directly setting per column pixel width or widget window ratio but not
both. Furthermore it is a immediate mode API so each value is directly
pushed before calling a widget. Therefore the layout is not automatically
repeating like the last two layouting functions.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
if (nk_begin_xxx(...) {
// first row with height: 25 composed of two widgets with width 60 and 40
nk_layout_row_begin(ctx, NK_STATIC, 25, 2);
nk_layout_row_push(ctx, 60);
nk_widget(...);
nk_layout_row_push(ctx, 40);
nk_widget(...);
nk_layout_row_end(ctx);
//
// second row with height: 25 composed of two widgets with window ratio 0.25 and 0.75
nk_layout_row_begin(ctx, NK_DYNAMIC, 25, 2);
nk_layout_row_push(ctx, 0.25f);
nk_widget(...);
nk_layout_row_push(ctx, 0.75f);
nk_widget(...);
nk_layout_row_end(ctx);
//
// third row with auto generated height: composed of two widgets with window ratio 0.25 and 0.75
nk_layout_row_begin(ctx, NK_DYNAMIC, 0, 2);
nk_layout_row_push(ctx, 0.25f);
nk_widget(...);
nk_layout_row_push(ctx, 0.75f);
nk_widget(...);
nk_layout_row_end(ctx);
}
nk_end(...);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4. __nk_layout_row__
The array counterpart to API nk_layout_row_xxx is the single nk_layout_row
functions. Instead of pushing either pixel or window ratio for every widget
it allows to define it by array. The trade of for less control is that
`nk_layout_row` is automatically repeating. Otherwise the behavior is the
same.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
if (nk_begin_xxx(...) {
// two rows with height: 30 composed of two widgets with width 60 and 40
const float size[] = {60,40};
nk_layout_row(ctx, NK_STATIC, 30, 2, ratio);
nk_widget(...);
nk_widget(...);
nk_widget(...);
nk_widget(...);
//
// two rows with height: 30 composed of two widgets with window ratio 0.25 and 0.75
const float ratio[] = {0.25, 0.75};
nk_layout_row(ctx, NK_DYNAMIC, 30, 2, ratio);
nk_widget(...);
nk_widget(...);
nk_widget(...);
nk_widget(...);
//
// two rows with auto generated height composed of two widgets with window ratio 0.25 and 0.75
const float ratio[] = {0.25, 0.75};
nk_layout_row(ctx, NK_DYNAMIC, 30, 2, ratio);
nk_widget(...);
nk_widget(...);
nk_widget(...);
nk_widget(...);
}
nk_end(...);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5. __nk_layout_row_template_xxx__
The most complex and second most flexible API is a simplified flexbox version without
line wrapping and weights for dynamic widgets. It is an immediate mode API but
unlike `nk_layout_row_xxx` it has auto repeat behavior and needs to be called
before calling the templated widgets.
The row template layout has three different per widget size specifier. The first
one is the `nk_layout_row_template_push_static` with fixed widget pixel width.
They do not grow if the row grows and will always stay the same.
The second size specifier is `nk_layout_row_template_push_variable`
which defines a minimum widget size but it also can grow if more space is available
not taken by other widgets.
Finally there are dynamic widgets with `nk_layout_row_template_push_dynamic`
which are completely flexible and unlike variable widgets can even shrink
to zero if not enough space is provided.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
if (nk_begin_xxx(...) {
// two rows with height: 30 composed of three widgets
nk_layout_row_template_begin(ctx, 30);
nk_layout_row_template_push_dynamic(ctx);
nk_layout_row_template_push_variable(ctx, 80);
nk_layout_row_template_push_static(ctx, 80);
nk_layout_row_template_end(ctx);
//
// first row
nk_widget(...); // dynamic widget can go to zero if not enough space
nk_widget(...); // variable widget with min 80 pixel but can grow bigger if enough space
nk_widget(...); // static widget with fixed 80 pixel width
//
// second row same layout
nk_widget(...);
nk_widget(...);
nk_widget(...);
}
nk_end(...);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
6. __nk_layout_space_xxx__
Finally the most flexible API directly allows you to place widgets inside the
window. The space layout API is an immediate mode API which does not support
row auto repeat and directly sets position and size of a widget. Position
and size hereby can be either specified as ratio of allocated space or
allocated space local position and pixel size. Since this API is quite
powerful there are a number of utility functions to get the available space
and convert between local allocated space and screen space.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
if (nk_begin_xxx(...) {
// static row with height: 500 (you can set column count to INT_MAX if you don't want to be bothered)
nk_layout_space_begin(ctx, NK_STATIC, 500, INT_MAX);
nk_layout_space_push(ctx, nk_rect(0,0,150,200));
nk_widget(...);
nk_layout_space_push(ctx, nk_rect(200,200,100,200));
nk_widget(...);
nk_layout_space_end(ctx);
//
// dynamic row with height: 500 (you can set column count to INT_MAX if you don't want to be bothered)
nk_layout_space_begin(ctx, NK_DYNAMIC, 500, INT_MAX);
nk_layout_space_push(ctx, nk_rect(0.5,0.5,0.1,0.1));
nk_widget(...);
nk_layout_space_push(ctx, nk_rect(0.7,0.6,0.1,0.1));
nk_widget(...);
}
nk_end(...);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#### Reference
Function | Description
----------------------------------------|------------------------------------
nk_layout_set_min_row_height | Set the currently used minimum row height to a specified value
nk_layout_reset_min_row_height | Resets the currently used minimum row height to font height
nk_layout_widget_bounds | Calculates current width a static layout row can fit inside a window
nk_layout_ratio_from_pixel | Utility functions to calculate window ratio from pixel size
nk_layout_row_dynamic | Current layout is divided into n same sized growing columns
nk_layout_row_static | Current layout is divided into n same fixed sized columns
nk_layout_row_begin | Starts a new row with given height and number of columns
nk_layout_row_push | Pushes another column with given size or window ratio
nk_layout_row_end | Finished previously started row
nk_layout_row | Specifies row columns in array as either window ratio or size
nk_layout_row_template_begin | Begins the row template declaration
nk_layout_row_template_push_dynamic | Adds a dynamic column that dynamically grows and can go to zero if not enough space
nk_layout_row_template_push_variable | Adds a variable column that dynamically grows but does not shrink below specified pixel width
nk_layout_row_template_push_static | Adds a static column that does not grow and will always have the same size
nk_layout_row_template_end | Marks the end of the row template
nk_layout_space_begin | Begins a new layouting space that allows to specify each widgets position and size
nk_layout_space_push | Pushes position and size of the next widget in own coordinate space either as pixel or ratio
nk_layout_space_end | Marks the end of the layouting space
nk_layout_space_bounds | Callable after nk_layout_space_begin and returns total space allocated
nk_layout_space_to_screen | Converts vector from nk_layout_space coordinate space into screen space
nk_layout_space_to_local | Converts vector from screen space into nk_layout_space coordinates
nk_layout_space_rect_to_screen | Converts rectangle from nk_layout_space coordinate space into screen space
nk_layout_space_rect_to_local | Converts rectangle from screen space into nk_layout_space coordinates
#### nk_layout_set_min_row_height
Sets the currently used minimum row height.
!!! WARNING
The passed height needs to include both your preferred row height
as well as padding. No internal padding is added.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
void nk_layout_set_min_row_height(struct nk_context*, float height);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Parameter | Description
------------|-----------------------------------------------------------
__ctx__ | Must point to an previously initialized `nk_context` struct after call `nk_begin_xxx`
__height__ | New minimum row height to be used for auto generating the row height
#### nk_layout_reset_min_row_height
Reset the currently used minimum row height back to `font_height + text_padding + padding`
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
void nk_layout_reset_min_row_height(struct nk_context*);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Parameter | Description
------------|-----------------------------------------------------------
__ctx__ | Must point to an previously initialized `nk_context` struct after call `nk_begin_xxx`
#### nk_layout_widget_bounds
Returns the width of the next row allocate by one of the layouting functions
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
struct nk_rect nk_layout_widget_bounds(struct nk_context*);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Parameter | Description
------------|-----------------------------------------------------------
__ctx__ | Must point to an previously initialized `nk_context` struct after call `nk_begin_xxx`
Return `nk_rect` with both position and size of the next row
#### nk_layout_ratio_from_pixel
Utility functions to calculate window ratio from pixel size
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
float nk_layout_ratio_from_pixel(struct nk_context*, float pixel_width);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Parameter | Description
------------|-----------------------------------------------------------
__ctx__ | Must point to an previously initialized `nk_context` struct after call `nk_begin_xxx`
__pixel__ | Pixel_width to convert to window ratio
Returns `nk_rect` with both position and size of the next row
#### nk_layout_row_dynamic
Sets current row layout to share horizontal space
between @cols number of widgets evenly. Once called all subsequent widget
calls greater than @cols will allocate a new row with same layout.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
void nk_layout_row_dynamic(struct nk_context *ctx, float height, int cols);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Parameter | Description
------------|-----------------------------------------------------------
__ctx__ | Must point to an previously initialized `nk_context` struct after call `nk_begin_xxx`
__height__ | Holds height of each widget in row or zero for auto layouting
__columns__ | Number of widget inside row
#### nk_layout_row_static
Sets current row layout to fill @cols number of widgets
in row with same @item_width horizontal size. Once called all subsequent widget
calls greater than @cols will allocate a new row with same layout.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
void nk_layout_row_static(struct nk_context *ctx, float height, int item_width, int cols);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Parameter | Description
------------|-----------------------------------------------------------
__ctx__ | Must point to an previously initialized `nk_context` struct after call `nk_begin_xxx`
__height__ | Holds height of each widget in row or zero for auto layouting
__width__ | Holds pixel width of each widget in the row
__columns__ | Number of widget inside row
#### nk_layout_row_begin
Starts a new dynamic or fixed row with given height and columns.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
void nk_layout_row_begin(struct nk_context *ctx, enum nk_layout_format fmt, float row_height, int cols);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Parameter | Description
------------|-----------------------------------------------------------
__ctx__ | Must point to an previously initialized `nk_context` struct after call `nk_begin_xxx`
__fmt__ | either `NK_DYNAMIC` for window ratio or `NK_STATIC` for fixed size columns
__height__ | holds height of each widget in row or zero for auto layouting
__columns__ | Number of widget inside row
#### nk_layout_row_push
Specifies either window ratio or width of a single column
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
void nk_layout_row_push(struct nk_context*, float value);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Parameter | Description
------------|-----------------------------------------------------------
__ctx__ | Must point to an previously initialized `nk_context` struct after call `nk_begin_xxx`
__value__ | either a window ratio or fixed width depending on @fmt in previous `nk_layout_row_begin` call
#### nk_layout_row_end
Finished previously started row
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
void nk_layout_row_end(struct nk_context*);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Parameter | Description
------------|-----------------------------------------------------------
__ctx__ | Must point to an previously initialized `nk_context` struct after call `nk_begin_xxx`
#### nk_layout_row
Specifies row columns in array as either window ratio or size
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
void nk_layout_row(struct nk_context*, enum nk_layout_format, float height, int cols, const float *ratio);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Parameter | Description
------------|-----------------------------------------------------------
__ctx__ | Must point to an previously initialized `nk_context` struct after call `nk_begin_xxx`
__fmt__ | Either `NK_DYNAMIC` for window ratio or `NK_STATIC` for fixed size columns
__height__ | Holds height of each widget in row or zero for auto layouting
__columns__ | Number of widget inside row
#### nk_layout_row_template_begin
Begins the row template declaration
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
void nk_layout_row_template_begin(struct nk_context*, float row_height);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Parameter | Description
------------|-----------------------------------------------------------
__ctx__ | Must point to an previously initialized `nk_context` struct after call `nk_begin_xxx`
__height__ | Holds height of each widget in row or zero for auto layouting
#### nk_layout_row_template_push_dynamic
Adds a dynamic column that dynamically grows and can go to zero if not enough space
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
void nk_layout_row_template_push_dynamic(struct nk_context*);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Parameter | Description
------------|-----------------------------------------------------------
__ctx__ | Must point to an previously initialized `nk_context` struct after call `nk_begin_xxx`
__height__ | Holds height of each widget in row or zero for auto layouting
#### nk_layout_row_template_push_variable
Adds a variable column that dynamically grows but does not shrink below specified pixel width
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
void nk_layout_row_template_push_variable(struct nk_context*, float min_width);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Parameter | Description
------------|-----------------------------------------------------------
__ctx__ | Must point to an previously initialized `nk_context` struct after call `nk_begin_xxx`
__width__ | Holds the minimum pixel width the next column must always be
#### nk_layout_row_template_push_static
Adds a static column that does not grow and will always have the same size
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
void nk_layout_row_template_push_static(struct nk_context*, float width);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Parameter | Description
------------|-----------------------------------------------------------
__ctx__ | Must point to an previously initialized `nk_context` struct after call `nk_begin_xxx`
__width__ | Holds the absolute pixel width value the next column must be
#### nk_layout_row_template_end
Marks the end of the row template
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
void nk_layout_row_template_end(struct nk_context*);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Parameter | Description
------------|-----------------------------------------------------------
__ctx__ | Must point to an previously initialized `nk_context` struct after call `nk_begin_xxx`
#### nk_layout_space_begin
Begins a new layouting space that allows to specify each widgets position and size.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
void nk_layout_space_begin(struct nk_context*, enum nk_layout_format, float height, int widget_count);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Parameter | Description
------------|-----------------------------------------------------------
__ctx__ | Must point to an previously initialized `nk_context` struct after call `nk_begin_xxx`
__fmt__ | Either `NK_DYNAMIC` for window ratio or `NK_STATIC` for fixed size columns
__height__ | Holds height of each widget in row or zero for auto layouting
__columns__ | Number of widgets inside row
#### nk_layout_space_push
Pushes position and size of the next widget in own coordinate space either as pixel or ratio
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
void nk_layout_space_push(struct nk_context *ctx, struct nk_rect bounds);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Parameter | Description
------------|-----------------------------------------------------------
__ctx__ | Must point to an previously initialized `nk_context` struct after call `nk_layout_space_begin`
__bounds__ | Position and size in laoyut space local coordinates
#### nk_layout_space_end
Marks the end of the layout space
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
void nk_layout_space_end(struct nk_context*);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Parameter | Description
------------|-----------------------------------------------------------
__ctx__ | Must point to an previously initialized `nk_context` struct after call `nk_layout_space_begin`
#### nk_layout_space_bounds
Utility function to calculate total space allocated for `nk_layout_space`
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
struct nk_rect nk_layout_space_bounds(struct nk_context*);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Parameter | Description
------------|-----------------------------------------------------------
__ctx__ | Must point to an previously initialized `nk_context` struct after call `nk_layout_space_begin`
Returns `nk_rect` holding the total space allocated
#### nk_layout_space_to_screen
Converts vector from nk_layout_space coordinate space into screen space
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
struct nk_vec2 nk_layout_space_to_screen(struct nk_context*, struct nk_vec2);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Parameter | Description
------------|-----------------------------------------------------------
__ctx__ | Must point to an previously initialized `nk_context` struct after call `nk_layout_space_begin`
__vec__ | Position to convert from layout space into screen coordinate space
Returns transformed `nk_vec2` in screen space coordinates
#### nk_layout_space_to_local
Converts vector from layout space into screen space
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
struct nk_vec2 nk_layout_space_to_local(struct nk_context*, struct nk_vec2);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Parameter | Description
------------|-----------------------------------------------------------
__ctx__ | Must point to an previously initialized `nk_context` struct after call `nk_layout_space_begin`
__vec__ | Position to convert from screen space into layout coordinate space
Returns transformed `nk_vec2` in layout space coordinates
#### nk_layout_space_rect_to_screen
Converts rectangle from screen space into layout space
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
struct nk_rect nk_layout_space_rect_to_screen(struct nk_context*, struct nk_rect);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Parameter | Description
------------|-----------------------------------------------------------
__ctx__ | Must point to an previously initialized `nk_context` struct after call `nk_layout_space_begin`
__bounds__ | Rectangle to convert from layout space into screen space
Returns transformed `nk_rect` in screen space coordinates
#### nk_layout_space_rect_to_local
Converts rectangle from layout space into screen space
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
struct nk_rect nk_layout_space_rect_to_local(struct nk_context*, struct nk_rect);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Parameter | Description
------------|-----------------------------------------------------------
__ctx__ | Must point to an previously initialized `nk_context` struct after call `nk_layout_space_begin`
__bounds__ | Rectangle to convert from layout space into screen space
Returns transformed `nk_rect` in layout space coordinates
#### nk_spacer
Spacer is a dummy widget that consumes space as usual but doesn't draw anything
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
void nk_spacer(struct nk_context* );
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Parameter | Description
------------|-----------------------------------------------------------
__ctx__ | Must point to an previously initialized `nk_context` struct after call `nk_layout_space_begin`
### 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
fuctionality. 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:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
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`:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
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);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#### 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
#### nk_group_begin
Starts a new widget group. Requires a previous layouting function to specify a pos/size.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
nk_bool nk_group_begin(struct nk_context*, const char *title, nk_flags);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Parameter | Description
------------|-----------------------------------------------------------
__ctx__ | Must point to an previously initialized `nk_context` struct
__title__ | Must be an unique identifier for this group that is also used for the group header
__flags__ | Window flags defined in the nk_panel_flags section with a number of different group behaviors
Returns `true(1)` if visible and fillable with widgets or `false(0)` otherwise
#### nk_group_begin_titled
Starts a new widget group. Requires a previous layouting function to specify a pos/size.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
nk_bool nk_group_begin_titled(struct nk_context*, const char *name, const char *title, nk_flags);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Parameter | Description
------------|-----------------------------------------------------------
__ctx__ | Must point to an previously initialized `nk_context` struct
__id__ | Must be an unique identifier for this group
__title__ | Group header title
__flags__ | Window flags defined in the nk_panel_flags section with a number of different group behaviors
Returns `true(1)` if visible and fillable with widgets or `false(0)` otherwise
#### nk_group_end
Ends a widget group
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
void nk_group_end(struct nk_context*);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Parameter | Description
------------|-----------------------------------------------------------
__ctx__ | Must point to an previously initialized `nk_context` struct
#### nk_group_scrolled_offset_begin
starts a new widget group. requires a previous layouting function to specify
a size. Does not keep track of scrollbar.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
nk_bool nk_group_scrolled_offset_begin(struct nk_context*, nk_uint *x_offset, nk_uint *y_offset, const char *title, nk_flags flags);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Parameter | Description
------------|-----------------------------------------------------------
__ctx__ | Must point to an previously initialized `nk_context` struct
__x_offset__| Scrollbar x-offset to offset all widgets inside the group horizontally.
__y_offset__| Scrollbar y-offset to offset all widgets inside the group vertically
__title__ | Window unique group title used to both identify and display in the group header
__flags__ | Window flags from the nk_panel_flags section
Returns `true(1)` if visible and fillable with widgets or `false(0)` otherwise
#### nk_group_scrolled_begin
Starts a new widget group. requires a previous
layouting function to specify a size. Does not keep track of scrollbar.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
nk_bool nk_group_scrolled_begin(struct nk_context*, struct nk_scroll *off, const char *title, nk_flags);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Parameter | Description
------------|-----------------------------------------------------------
__ctx__ | Must point to an previously initialized `nk_context` struct
__off__ | Both x- and y- scroll offset. Allows for manual scrollbar control
__title__ | Window unique group title used to both identify and display in the group header
__flags__ | Window flags from nk_panel_flags section
Returns `true(1)` if visible and fillable with widgets or `false(0)` otherwise
#### nk_group_scrolled_end
Ends a widget group after calling nk_group_scrolled_offset_begin or nk_group_scrolled_begin.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
void nk_group_scrolled_end(struct nk_context*);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Parameter | Description
------------|-----------------------------------------------------------
__ctx__ | Must point to an previously initialized `nk_context` struct
#### nk_group_get_scroll
Gets the scroll position of the given group.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
void nk_group_get_scroll(struct nk_context*, const char *id, nk_uint *x_offset, nk_uint *y_offset);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Parameter | Description
-------------|-----------------------------------------------------------
__ctx__ | Must point to an previously initialized `nk_context` struct
__id__ | The id of the group to get the scroll position of
__x_offset__ | A pointer to the x offset output (or NULL to ignore)
__y_offset__ | A pointer to the y offset output (or NULL to ignore)
#### nk_group_set_scroll
Sets the scroll position of the given group.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
void nk_group_set_scroll(struct nk_context*, const char *id, nk_uint x_offset, nk_uint y_offset);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Parameter | Description
-------------|-----------------------------------------------------------
__ctx__ | Must point to an previously initialized `nk_context` struct
__id__ | The id of the group to scroll
__x_offset__ | The x offset to scroll to
__y_offset__ | The y offset to scroll to
### Tree
Trees represent two different concept. First the concept of a collapsible
UI section that can be either in a hidden or visible state. They allow the UI
user to selectively minimize the current set of visible UI to comprehend.
The second concept are tree widgets for visual UI representation of trees.
Trees thereby can be nested for tree representations and multiple nested
collapsible UI sections. All trees are started by calling of the
`nk_tree_xxx_push_tree` functions and ended by calling one of the
`nk_tree_xxx_pop_xxx()` functions. Each starting functions takes a title label
and optionally an image to be displayed and the initial collapse state from
the nk_collapse_states section.
The runtime state of the tree is either stored outside the library by the caller
or inside which requires a unique ID. The unique ID can either be generated
automatically from `__FILE__` and `__LINE__` with function `nk_tree_push`,
by `__FILE__` and a user provided ID generated for example by loop index with
function `nk_tree_push_id` or completely provided from outside by user with
function `nk_tree_push_hashed`.
#### Usage
To create a tree you have to call one of the seven `nk_tree_xxx_push_xxx`
functions to start a collapsible UI section and `nk_tree_xxx_pop` to mark the
end.
Each starting function will either return `false(0)` if the tree is collapsed
or hidden and therefore does not need to be filled with content or `true(1)`
if visible and required to be filled.
!!! Note
The tree header does not require and layouting function and instead
calculates a auto height based on the currently used font size
The tree ending functions only need to be called if the tree content is
actually visible. So make sure the tree push function is guarded by `if`
and the pop call is only taken if the tree is visible.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
if (nk_tree_push(ctx, NK_TREE_TAB, "Tree", NK_MINIMIZED)) {
nk_layout_row_dynamic(...);
nk_widget(...);
nk_tree_pop(ctx);
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#### Reference
Function | Description
----------------------------|-------------------------------------------
nk_tree_push | Start a collapsible UI section with internal state management
nk_tree_push_id | Start a collapsible UI section with internal state management callable in a look
nk_tree_push_hashed | Start a collapsible UI section with internal state management with full control over internal unique ID use to store state
nk_tree_image_push | Start a collapsible UI section with image and label header
nk_tree_image_push_id | Start a collapsible UI section with image and label header and internal state management callable in a look
nk_tree_image_push_hashed | Start a collapsible UI section with image and label header and internal state management with full control over internal unique ID use to store state
nk_tree_pop | Ends a collapsible UI section
nk_tree_state_push | Start a collapsible UI section with external state management
nk_tree_state_image_push | Start a collapsible UI section with image and label header and external state management
nk_tree_state_pop | Ends a collapsabale UI section
#### nk_tree_type
Flag | Description
----------------|----------------------------------------
NK_TREE_NODE | Highlighted tree header to mark a collapsible UI section
NK_TREE_TAB | Non-highlighted tree header closer to tree representations
#### nk_tree_push
Starts a collapsible UI section with internal state management
!!! WARNING
To keep track of the runtime tree collapsible state this function uses
defines `__FILE__` and `__LINE__` to generate a unique ID. If you want
to call this function in a loop please use `nk_tree_push_id` or
`nk_tree_push_hashed` instead.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
#define nk_tree_push(ctx, type, title, state)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Parameter | Description
------------|-----------------------------------------------------------
__ctx__ | Must point to an previously initialized `nk_context` struct
__type__ | Value from the nk_tree_type section to visually mark a tree node header as either a collapseable UI section or tree node
__title__ | Label printed in the tree header
__state__ | Initial tree state value out of nk_collapse_states
Returns `true(1)` if visible and fillable with widgets or `false(0)` otherwise
#### nk_tree_push_id
Starts a collapsible UI section with internal state management callable in a look
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
#define nk_tree_push_id(ctx, type, title, state, id)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Parameter | Description
------------|-----------------------------------------------------------
__ctx__ | Must point to an previously initialized `nk_context` struct
__type__ | Value from the nk_tree_type section to visually mark a tree node header as either a collapseable UI section or tree node
__title__ | Label printed in the tree header
__state__ | Initial tree state value out of nk_collapse_states
__id__ | Loop counter index if this function is called in a loop
Returns `true(1)` if visible and fillable with widgets or `false(0)` otherwise
#### nk_tree_push_hashed
Start a collapsible UI section with internal state management with full
control over internal unique ID used to store state
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
nk_bool nk_tree_push_hashed(struct nk_context*, enum nk_tree_type, const char *title, enum nk_collapse_states initial_state, const char *hash, int len,int seed);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Parameter | Description
------------|-----------------------------------------------------------
__ctx__ | Must point to an previously initialized `nk_context` struct
__type__ | Value from the nk_tree_type section to visually mark a tree node header as either a collapseable UI section or tree node
__title__ | Label printed in the tree header
__state__ | Initial tree state value out of nk_collapse_states
__hash__ | Memory block or string to generate the ID from
__len__ | Size of passed memory block or string in __hash__
__seed__ | Seeding value if this function is called in a loop or default to `0`
Returns `true(1)` if visible and fillable with widgets or `false(0)` otherwise
#### nk_tree_image_push
Start a collapsible UI section with image and label header
!!! WARNING
To keep track of the runtime tree collapsible state this function uses
defines `__FILE__` and `__LINE__` to generate a unique ID. If you want
to call this function in a loop please use `nk_tree_image_push_id` or
`nk_tree_image_push_hashed` instead.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
#define nk_tree_image_push(ctx, type, img, title, state)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Parameter | Description
------------|-----------------------------------------------------------
__ctx__ | Must point to an previously initialized `nk_context` struct
__type__ | Value from the nk_tree_type section to visually mark a tree node header as either a collapseable UI section or tree node
__img__ | Image to display inside the header on the left of the label
__title__ | Label printed in the tree header
__state__ | Initial tree state value out of nk_collapse_states
Returns `true(1)` if visible and fillable with widgets or `false(0)` otherwise
#### nk_tree_image_push_id
Start a collapsible UI section with image and label header and internal state
management callable in a look
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
#define nk_tree_image_push_id(ctx, type, img, title, state, id)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Parameter | Description
------------|-----------------------------------------------------------
__ctx__ | Must point to an previously initialized `nk_context` struct
__type__ | Value from the nk_tree_type section to visually mark a tree node header as either a collapseable UI section or tree node
__img__ | Image to display inside the header on the left of the label
__title__ | Label printed in the tree header
__state__ | Initial tree state value out of nk_collapse_states
__id__ | Loop counter index if this function is called in a loop
Returns `true(1)` if visible and fillable with widgets or `false(0)` otherwise
#### nk_tree_image_push_hashed
Start a collapsible UI section with internal state management with full
control over internal unique ID used to store state
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
nk_bool nk_tree_image_push_hashed(struct nk_context*, enum nk_tree_type, struct nk_image, const char *title, enum nk_collapse_states initial_state, const char *hash, int len,int seed);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Parameter | Description
------------|-----------------------------------------------------------
__ctx__ | Must point to an previously initialized `nk_context` struct
__type__ | Value from the nk_tree_type section to visually mark a tree node header as either a collapseable UI section or tree node
__img__ | Image to display inside the header on the left of the label
__title__ | Label printed in the tree header
__state__ | Initial tree state value out of nk_collapse_states
__hash__ | Memory block or string to generate the ID from
__len__ | Size of passed memory block or string in __hash__
__seed__ | Seeding value if this function is called in a loop or default to `0`
Returns `true(1)` if visible and fillable with widgets or `false(0)` otherwise
#### nk_tree_pop
Ends a collapsabale UI section
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
void nk_tree_pop(struct nk_context*);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Parameter | Description
------------|-----------------------------------------------------------
__ctx__ | Must point to an previously initialized `nk_context` struct after calling `nk_tree_xxx_push_xxx`
#### nk_tree_state_push
Start a collapsible UI section with external state management
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
nk_bool nk_tree_state_push(struct nk_context*, enum nk_tree_type, const char *title, enum nk_collapse_states *state);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Parameter | Description
------------|-----------------------------------------------------------
__ctx__ | Must point to an previously initialized `nk_context` struct after calling `nk_tree_xxx_push_xxx`
__type__ | Value from the nk_tree_type section to visually mark a tree node header as either a collapseable UI section or tree node
__title__ | Label printed in the tree header
__state__ | Persistent state to update
Returns `true(1)` if visible and fillable with widgets or `false(0)` otherwise
#### nk_tree_state_image_push
Start a collapsible UI section with image and label header and external state management
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
nk_bool nk_tree_state_image_push(struct nk_context*, enum nk_tree_type, struct nk_image, const char *title, enum nk_collapse_states *state);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Parameter | Description
------------|-----------------------------------------------------------
__ctx__ | Must point to an previously initialized `nk_context` struct after calling `nk_tree_xxx_push_xxx`
__img__ | Image to display inside the header on the left of the label
__type__ | Value from the nk_tree_type section to visually mark a tree node header as either a collapseable UI section or tree node
__title__ | Label printed in the tree header
__state__ | Persistent state to update
Returns `true(1)` if visible and fillable with widgets or `false(0)` otherwise
#### nk_tree_state_pop
Ends a collapsabale UI section
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
void nk_tree_state_pop(struct nk_context*);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Parameter | Description
------------|-----------------------------------------------------------
__ctx__ | Must point to an previously initialized `nk_context` struct after calling `nk_tree_xxx_push_xxx`
### 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.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
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);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#### 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.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
void nk_property_int(struct nk_context *ctx, const char *name, int min, int *val, int max, int step, float inc_per_pixel);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Parameter | Description
--------------------|-----------------------------------------------------------
__ctx__ | Must point to an previously initialized `nk_context` struct after calling a layouting function
__name__ | String used both as a label as well as a unique identifier
__min__ | Minimum value not allowed to be underflown
__val__ | Integer pointer to be modified
__max__ | Maximum value not allowed to be overflown
__step__ | Increment added and subtracted on increment and decrement button
__inc_per_pixel__ | Value per pixel added or subtracted on dragging
#### nk_property_float
Float 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.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
void nk_property_float(struct nk_context *ctx, const char *name, float min, float *val, float max, float step, float inc_per_pixel);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Parameter | Description
--------------------|-----------------------------------------------------------
__ctx__ | Must point to an previously initialized `nk_context` struct after calling a layouting function
__name__ | String used both as a label as well as a unique identifier
__min__ | Minimum value not allowed to be underflown
__val__ | Float pointer to be modified
__max__ | Maximum value not allowed to be overflown
__step__ | Increment added and subtracted on increment and decrement button
__inc_per_pixel__ | Value per pixel added or subtracted on dragging
#### nk_property_double
Double 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.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
void nk_property_double(struct nk_context *ctx, const char *name, double min, double *val, double max, double step, double inc_per_pixel);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Parameter | Description
--------------------|-----------------------------------------------------------
__ctx__ | Must point to an previously initialized `nk_context` struct after calling a layouting function
__name__ | String used both as a label as well as a unique identifier
__min__ | Minimum value not allowed to be underflown
__val__ | Double pointer to be modified
__max__ | Maximum value not allowed to be overflown
__step__ | Increment added and subtracted on increment and decrement button
__inc_per_pixel__ | Value per pixel added or subtracted on dragging
#### nk_propertyi
Integer property modifying a passed in value and returning the new 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.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
int nk_propertyi(struct nk_context *ctx, const char *name, int min, int val, int max, int step, float inc_per_pixel);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Parameter | Description
--------------------|-----------------------------------------------------------
__ctx__ | Must point to an previously initialized `nk_context` struct after calling a layouting function
__name__ | String used both as a label as well as a unique identifier
__min__ | Minimum value not allowed to be underflown
__val__ | Current integer value to be modified and returned
__max__ | Maximum value not allowed to be overflown
__step__ | Increment added and subtracted on increment and decrement button
__inc_per_pixel__ | Value per pixel added or subtracted on dragging
Returns the new modified integer value
#### nk_propertyf
Float property modifying a passed in value and returning the new 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.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
float nk_propertyf(struct nk_context *ctx, const char *name, float min, float val, float max, float step, float inc_per_pixel);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Parameter | Description
--------------------|-----------------------------------------------------------
__ctx__ | Must point to an previously initialized `nk_context` struct after calling a layouting function
__name__ | String used both as a label as well as a unique identifier
__min__ | Minimum value not allowed to be underflown
__val__ | Current float value to be modified and returned
__max__ | Maximum value not allowed to be overflown
__step__ | Increment added and subtracted on increment and decrement button
__inc_per_pixel__ | Value per pixel added or subtracted on dragging
Returns the new modified float value
#### nk_propertyd
Float property modifying a passed in value and returning the new 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.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
float nk_propertyd(struct nk_context *ctx, const char *name, double min, double val, double max, double step, double inc_per_pixel);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Parameter | Description
--------------------|-----------------------------------------------------------
__ctx__ | Must point to an previously initialized `nk_context` struct after calling a layouting function
__name__ | String used both as a label as well as a unique identifier
__min__ | Minimum value not allowed to be underflown
__val__ | Current double value to be modified and returned
__max__ | Maximum value not allowed to be overflown
__step__ | Increment added and subtracted on increment and decrement button
__inc_per_pixel__ | Value per pixel added or subtracted on dragging
Returns the new modified double value
-XXX.XXX- X...X - X...X -X....X - X....X"
X...XXXXXXXXXXXXX...X - "
## License
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~none
------------------------------------------------------------------------------
This software is available under 2 licenses -- choose whichever you prefer.
------------------------------------------------------------------------------
ALTERNATIVE A - MIT License
Copyright (c) 2016-2018 Micha Mettke
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
------------------------------------------------------------------------------
ALTERNATIVE B - Public Domain (www.unlicense.org)
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or distribute this
software, either in source code form or as a compiled binary, for any purpose,
commercial or non-commercial, and by any means.
In jurisdictions that recognize copyright laws, the author or authors of this
software dedicate any and all copyright interest in the software to the public
domain. We make this dedication for the benefit of the public at large and to
the detriment of our heirs and successors. We intend this dedication to be an
overt act of relinquishment in perpetuity of all present and future rights to
this software under copyright law.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
------------------------------------------------------------------------------
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
## Changelog
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~none
[date] ([x.y.z]) - [description]
- [date]: date on which the change has been pushed
- [x.y.z]: Version string, represented in Semantic Versioning format
- [x]: Major version with API and library breaking changes
- [y]: Minor version with non-breaking API and library changes
- [z]: Patch version with no direct changes to the API
- 2022/05/27 (4.10.0) - Add nk_input_has_mouse_click_in_button_rect() to fix window move bug
- 2022/04/18 (4.9.7) - Change button behavior when NK_BUTTON_TRIGGER_ON_RELEASE is defined to
only trigger when the mouse position was inside the same button on down
- 2022/02/03 (4.9.6) - Allow overriding the NK_INV_SQRT function, similar to NK_SIN and NK_COS
- 2021/12/22 (4.9.5) - Revert layout bounds not accounting for padding due to regressions
- 2021/12/22 (4.9.4) - Fix checking hovering when window is minimized
- 2021/12/22 (4.09.3) - Fix layout bounds not accounting for padding
- 2021/12/19 (4.09.2) - Update to stb_rect_pack.h v1.01 and stb_truetype.h v1.26
- 2021/12/16 (4.09.1) - Fix the majority of GCC warnings
- 2021/10/16 (4.09.0) - Added nk_spacer() widget
- 2021/09/22 (4.08.6) - Fix "may be used uninitialized" warnings in nk_widget
- 2021/09/22 (4.08.5) - GCC __builtin_offsetof only exists in version 4 and later
- 2021/09/15 (4.08.4) - Fix "'num_len' may be used uninitialized" in nk_do_property
- 2021/09/15 (4.08.3) - Fix "Templates cannot be declared to have 'C' Linkage"
- 2021/09/08 (4.08.2) - Fix warnings in C89 builds
- 2021/09/08 (4.08.1) - Use compiler builtins for NK_OFFSETOF when possible
- 2021/08/17 (4.08.0) - Implemented 9-slice scaling support for widget styles
- 2021/08/16 (4.07.5) - Replace usage of memset in nk_font_atlas_bake with NK_MEMSET
- 2021/08/15 (4.07.4) - Fix conversion and sign conversion warnings
- 2021/08/08 (4.07.3) - Fix crash when baking merged fonts
- 2021/08/08 (4.07.2) - Fix Multiline Edit wrong offset
- 2021/03/17 (4.07.1) - Fix warning about unused parameter
- 2021/03/17 (4.07.0) - Fix nk_property hover bug
- 2021/03/15 (4.06.4) - Change nk_propertyi back to int
- 2021/03/15 (4.06.3) - Update documentation for functions that now return nk_bool
- 2020/12/19 (4.06.2) - Fix additional C++ style comments which are not allowed in ISO C90.
- 2020/10/11 (4.06.1) - Fix C++ style comments which are not allowed in ISO C90.
- 2020/10/07 (4.06.0) - Fix nk_combo return type wrongly changed to nk_bool
- 2020/09/05 (4.05.0) - Use the nk_font_atlas allocator for stb_truetype memory management.
- 2020/09/04 (4.04.1) - Replace every boolean int by nk_bool
- 2020/09/04 (4.04.0) - Add nk_bool with NK_INCLUDE_STANDARD_BOOL
- 2020/06/13 (4.03.1) - Fix nk_pool allocation sizes.
- 2020/06/04 (4.03.0) - Made nk_combo header symbols optional.
- 2020/05/27 (4.02.5) - Fix nk_do_edit: Keep scroll position when re-activating edit widget.
- 2020/05/09 (4.02.4) - Fix nk_menubar height calculation bug
- 2020/05/08 (4.02.3) - Fix missing stdarg.h with NK_INCLUDE_STANDARD_VARARGS
- 2020/04/30 (4.02.2) - Fix nk_edit border drawing bug
- 2020/04/09 (4.02.1) - Removed unused nk_sqrt function to fix compiler warnings
- Fixed compiler warnings if you bring your own methods for
nk_cos/nk_sin/nk_strtod/nk_memset/nk_memcopy/nk_dtoa
- 2020/04/06 (4.01.10) - Fix bug: Do not use pool before checking for NULL
- 2020/03/22 (4.01.9) - Fix bug where layout state wasn't restored correctly after
popping a tree.
- 2020/03/11 (4.01.8) - Fix bug where padding is subtracted from widget
- 2020/03/06 (4.01.7) - Fix bug where width padding was applied twice
- 2020/02/06 (4.01.6) - Update stb_truetype.h and stb_rect_pack.h and separate them
- 2019/12/10 (4.01.5) - Fix off-by-one error in NK_INTERSECT
- 2019/10/09 (4.01.4) - Fix bug for autoscrolling in nk_do_edit
- 2019/09/20 (4.01.3) - Fixed a bug wherein combobox cannot be closed by clicking the header
when NK_BUTTON_TRIGGER_ON_RELEASE is defined.
- 2019/09/10 (4.01.2) - Fixed the nk_cos function, which deviated significantly.
- 2019/09/08 (4.01.1) - Fixed a bug wherein re-baking of fonts caused a segmentation
fault due to dst_font->glyph_count not being zeroed on subsequent
bakes of the same set of fonts.
- 2019/06/23 (4.01.0) - Added nk_***_get_scroll and nk_***_set_scroll for groups, windows, and popups.
- 2019/06/12 (4.00.3) - Fix panel background drawing bug.
- 2018/10/31 (4.00.2) - Added NK_KEYSTATE_BASED_INPUT to "fix" state based backends
like GLFW without breaking key repeat behavior on event based.
- 2018/04/01 (4.00.1) - Fixed calling `nk_convert` multiple time per single frame.
- 2018/04/01 (4.00.0) - BREAKING CHANGE: nk_draw_list_clear no longer tries to
clear provided buffers. So make sure to either free
or clear each passed buffer after calling nk_convert.
- 2018/02/23 (3.00.6) - Fixed slider dragging behavior.
- 2018/01/31 (3.00.5) - Fixed overcalculation of cursor data in font baking process.
- 2018/01/31 (3.00.4) - Removed name collision with stb_truetype.
- 2018/01/28 (3.00.3) - Fixed panel window border drawing bug.
- 2018/01/12 (3.00.2) - Added `nk_group_begin_titled` for separated group identifier and title.
- 2018/01/07 (3.00.1) - Started to change documentation style.
- 2018/01/05 (3.00.0) - BREAKING CHANGE: The previous color picker API was broken
because of conversions between float and byte color representation.
Color pickers now use floating point values to represent
HSV values. To get back the old behavior I added some additional
color conversion functions to cast between nk_color and
nk_colorf.
- 2017/12/23 (2.00.7) - Fixed small warning.
- 2017/12/23 (2.00.7) - Fixed `nk_edit_buffer` behavior if activated to allow input.
- 2017/12/23 (2.00.7) - Fixed modifyable progressbar dragging visuals and input behavior.
- 2017/12/04 (2.00.6) - Added formatted string tooltip widget.
- 2017/11/18 (2.00.5) - Fixed window becoming hidden with flag `NK_WINDOW_NO_INPUT`.
- 2017/11/15 (2.00.4) - Fixed font merging.
- 2017/11/07 (2.00.3) - Fixed window size and position modifier functions.
- 2017/09/14 (2.00.2) - Fixed `nk_edit_buffer` and `nk_edit_focus` behavior.
- 2017/09/14 (2.00.1) - Fixed window closing behavior.
- 2017/09/14 (2.00.0) - BREAKING CHANGE: Modifying window position and size functions now
require the name of the window and must happen outside the window
building process (between function call nk_begin and nk_end).
- 2017/09/11 (1.40.9) - Fixed window background flag if background window is declared last.
- 2017/08/27 (1.40.8) - Fixed `nk_item_is_any_active` for hidden windows.
- 2017/08/27 (1.40.7) - Fixed window background flag.
- 2017/07/07 (1.40.6) - Fixed missing clipping rect check for hovering/clicked
query for widgets.
- 2017/07/07 (1.40.5) - Fixed drawing bug for vertex output for lines and stroked
and filled rectangles.
- 2017/07/07 (1.40.4) - Fixed bug in nk_convert trying to add windows that are in
process of being destroyed.
- 2017/07/07 (1.40.3) - Fixed table internal bug caused by storing table size in
window instead of directly in table.
- 2017/06/30 (1.40.2) - Removed unneeded semicolon in C++ NK_ALIGNOF macro.
- 2017/06/30 (1.40.1) - Fixed drawing lines smaller or equal zero.
- 2017/06/08 (1.40.0) - Removed the breaking part of last commit. Auto layout now only
comes in effect if you pass in zero was row height argument.
- 2017/06/08 (1.40.0) - BREAKING CHANGE: while not directly API breaking it will change
how layouting works. From now there will be an internal minimum
row height derived from font height. If you need a row smaller than
that you can directly set it by `nk_layout_set_min_row_height` and
reset the value back by calling `nk_layout_reset_min_row_height.
- 2017/06/08 (1.39.1) - Fixed property text edit handling bug caused by past `nk_widget` fix.
- 2017/06/08 (1.39.0) - Added function to retrieve window space without calling a `nk_layout_xxx` function.
- 2017/06/06 (1.38.5) - Fixed `nk_convert` return flag for command buffer.
- 2017/05/23 (1.38.4) - Fixed activation behavior for widgets partially clipped.
- 2017/05/10 (1.38.3) - Fixed wrong min window size mouse scaling over boundaries.
- 2017/05/09 (1.38.2) - Fixed vertical scrollbar drawing with not enough space.
- 2017/05/09 (1.38.1) - Fixed scaler dragging behavior if window size hits minimum size.
- 2017/05/06 (1.38.0) - Added platform double-click support.
- 2017/04/20 (1.37.1) - Fixed key repeat found inside glfw demo backends.
- 2017/04/20 (1.37.0) - Extended properties with selection and clipboard support.
- 2017/04/20 (1.36.2) - Fixed #405 overlapping rows with zero padding and spacing.
- 2017/04/09 (1.36.1) - Fixed #403 with another widget float error.
- 2017/04/09 (1.36.0) - Added window `NK_WINDOW_NO_INPUT` and `NK_WINDOW_NOT_INTERACTIVE` flags.
- 2017/04/09 (1.35.3) - Fixed buffer heap corruption.
- 2017/03/25 (1.35.2) - Fixed popup overlapping for `NK_WINDOW_BACKGROUND` windows.
- 2017/03/25 (1.35.1) - Fixed windows closing behavior.
- 2017/03/18 (1.35.0) - Added horizontal scroll requested in #377.
- 2017/03/18 (1.34.3) - Fixed long window header titles.
- 2017/03/04 (1.34.2) - Fixed text edit filtering.
- 2017/03/04 (1.34.1) - Fixed group closable flag.
- 2017/02/25 (1.34.0) - Added custom draw command for better language binding support.
- 2017/01/24 (1.33.0) - Added programmatic way to remove edit focus.
- 2017/01/24 (1.32.3) - Fixed wrong define for basic type definitions for windows.
- 2017/01/21 (1.32.2) - Fixed input capture from hidden or closed windows.
- 2017/01/21 (1.32.1) - Fixed slider behavior and drawing.
- 2017/01/13 (1.32.0) - Added flag to put scaler into the bottom left corner.
- 2017/01/13 (1.31.0) - Added additional row layouting method to combine both
dynamic and static widgets.
- 2016/12/31 (1.30.0) - Extended scrollbar offset from 16-bit to 32-bit.
- 2016/12/31 (1.29.2) - Fixed closing window bug of minimized windows.
- 2016/12/03 (1.29.1) - Fixed wrapped text with no seperator and C89 error.
- 2016/12/03 (1.29.0) - Changed text wrapping to process words not characters.
- 2016/11/22 (1.28.6) - Fixed window minimized closing bug.
- 2016/11/19 (1.28.5) - Fixed abstract combo box closing behavior.
- 2016/11/19 (1.28.4) - Fixed tooltip flickering.
- 2016/11/19 (1.28.3) - Fixed memory leak caused by popup repeated closing.
- 2016/11/18 (1.28.2) - Fixed memory leak caused by popup panel allocation.
- 2016/11/10 (1.28.1) - Fixed some warnings and C++ error.
- 2016/11/10 (1.28.0) - Added additional `nk_button` versions which allows to directly
pass in a style struct to change buttons visual.
- 2016/11/10 (1.27.0) - Added additional `nk_tree` versions to support external state
storage. Just like last the `nk_group` commit the main
advantage is that you optionally can minimize nuklears runtime
memory consumption or handle hash collisions.
- 2016/11/09 (1.26.0) - Added additional `nk_group` version to support external scrollbar
offset storage. Main advantage is that you can externalize
the memory management for the offset. It could also be helpful
if you have a hash collision in `nk_group_begin` but really
want the name. In addition I added `nk_list_view` which allows
to draw big lists inside a group without actually having to
commit the whole list to nuklear (issue #269).
- 2016/10/30 (1.25.1) - Fixed clipping rectangle bug inside `nk_draw_list`.
- 2016/10/29 (1.25.0) - Pulled `nk_panel` memory management into nuklear and out of
the hands of the user. From now on users don't have to care
about panels unless they care about some information. If you
still need the panel just call `nk_window_get_panel`.
- 2016/10/21 (1.24.0) - Changed widget border drawing to stroked rectangle from filled
rectangle for less overdraw and widget background transparency.
- 2016/10/18 (1.23.0) - Added `nk_edit_focus` for manually edit widget focus control.
- 2016/09/29 (1.22.7) - Fixed deduction of basic type in non `
Embeds [stb_texedit](https://github.com/nothings/stb/blob/master/stb_textedit.h), [stb_truetype](https://github.com/nothings/stb/blob/master/stb_truetype.h) and [stb_rectpack](https://github.com/nothings/stb/blob/master/stb_rect_pack.h) by Sean Barret (public domain)
Uses [stddoc.c](https://github.com/r-lyeh/stddoc.c) from r-lyeh@github.com for documentation generation
Embeds ProggyClean.ttf font by Tristan Grimmer (MIT license).
Big thank you to Omar Cornut (ocornut@github) for his [imgui library](https://github.com/ocornut/imgui) and
giving me the inspiration for this library, Casey Muratori for handmade hero
and his original immediate mode graphical user interface idea and Sean
Barret for his amazing single header libraries which restored my faith
in libraries and brought me to create some of my own. Finally Apoorva Joshi
for his single header file packer.