aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHanspeter Portner <dev@open-music-kontrollers.ch>2017-07-05 22:53:00 +0200
committerHanspeter Portner <dev@open-music-kontrollers.ch>2017-07-05 22:53:00 +0200
commitacef0e39c3a30753792641dc4cb3aebe05eb7b21 (patch)
tree2fd981adbedd0c8a474f2f798077efe472720a61
parent01eb4f88d8e82d9c3223aabc76d54570fc7bc7da (diff)
downloadnuk.lv2-acef0e39c3a30753792641dc4cb3aebe05eb7b21.tar.xz
Squashed 'nuklear/' changes from 01eb4f8..12257a4
12257a4 omk: don't clear draw_list. c9303e8 omk: fix group border. 928cd5f omk: fix lost scrollbar state in nk_edit_buffer. 3074c95 omk: fix lexer code to work with utf8. 08924f1 add support for syntax highlighting ca1c9b3 Fixed text wrapping without seperator ebe516c Text wrap now splits words not characters #292 a16877b Fixed minimized window closing bug #266 67ad444 Merge pull request #284 from nsawa/fix__windows_demos_down_flag_reversed 19fd622 Merge pull request #286 from nsawa/fix__missing_init_of_popup_border 6a374ea Fixed abstract comobox closing behavior #282 c490e80 Fixed tooltip flickering #278 e7c06e0 fixed memory leak caused by repeated popup closing e229856 Fixed memory leak caused by popup panmel alloc a7283af fix: popup border is not shown when using the default style settings 43b0574 fix for readability 2849cdf fix: In the windows demos, the key reaction is occured at the timing of the control keys are released. 8e60328 Merge pull request #277 from keharriso/edit_fixes 40ea365 Fix edit cursor movement and text overflow c61d4f0 Fixed edit multiline widget width calculation d26ff34 Fixed small edit widget box width calculation 4a4fdf1 Added missing X11 key up and down event handling 34b12bd Added missing up and down event key to SDL demo f2b9b9a Allow `NK_API` to be overwritten #281 7fa1aa2 Merge pull request #280 from nsawa/fix__nk_layout_widget_space 344f121 fix: using nk_layout_row_begin() with NK_STATIC makes incorrect layout 02fb019 Fixed warnings and C++ error #279 1acb7ba Added additional `nk_tree` version 42efd82 Added addition `nk_group` and new `nk_list_view` 9f9591c Removed SDL1.2 version to ease development a24f3f6 Merge pull request #254 from coderobe/patch-1 33077a1 Merge pull request #276 from nsawa/fix__nk_color_hex_rgba ebed2e6 fix: nk_value_color_hex() showed incorrect value. 18bacf0 Merge pull request #274 from nsawa/fix__nk_hsva_f ccc8fd6 Merge pull request #273 from nsawa/fix__nk_value_color_byte bb7ffc4 fix: nk_hsva_f() lacked processing for quadrant 3 329dacd fix: nk_value_color_byte() shows incorrect text dea4a71 Merge pull request #270 from nsawa/nk_combo_separator__bugfix fdecbc7 Merge pull request #271 from sillyousu/master 72491ba remove useless variable bb2cd9a bugfix: nk_combo_separator showed incorrect item length and broken item text. b280370 Fixed copy & paste error 69b13a0 Fixed C++ errors 7ed612e Merge branch 'master' of https://github.com/vurtun/gui d8688c6 Fixed clipping rectangle bug bd3fd83 Pulled panel memory managment into nuklear 534b14a Fixed X11 stroke rect drawing fe785e5 Fix segfault git-subtree-dir: nuklear git-subtree-split: 12257a487ecd6adbc2c43a58ff407bab10387807
-rw-r--r--CHANGELOG.md26
-rw-r--r--Readme.md3
-rw-r--r--demo/calculator.c6
-rw-r--r--demo/d3d11/main.c12
-rw-r--r--demo/d3d11/nuklear_d3d11.h4
-rw-r--r--demo/gdi/main.c7
-rw-r--r--demo/gdi/nuklear_gdi.h4
-rw-r--r--demo/gdip/main.c7
-rw-r--r--demo/gdip/nuklear_gdip.h4
-rw-r--r--demo/glfw_opengl2/main.c12
-rw-r--r--demo/glfw_opengl2/nuklear_glfw_gl2.h2
-rw-r--r--demo/glfw_opengl3/main.c12
-rw-r--r--demo/glfw_opengl3/nuklear_glfw_gl3.h2
-rw-r--r--demo/node_editor.c33
-rw-r--r--demo/overview.c74
-rw-r--r--demo/sdl1_2/Makefile20
-rw-r--r--demo/sdl1_2/main.c137
-rw-r--r--demo/sdl1_2/nuklear_sdl.h474
-rw-r--r--demo/sdl_opengl2/main.c12
-rw-r--r--demo/sdl_opengl2/nuklear_sdl_gl2.h6
-rw-r--r--demo/sdl_opengl3/main.c50
-rw-r--r--demo/sdl_opengl3/nuklear_sdl_gl3.h16
-rw-r--r--demo/x11/main.c15
-rw-r--r--demo/x11/nuklear_xlib.h16
-rw-r--r--demo/x11_opengl2/main.c12
-rw-r--r--demo/x11_opengl2/nuklear_xlib_gl2.h4
-rw-r--r--demo/x11_opengl3/main.c12
-rw-r--r--demo/x11_opengl3/nuklear_xlib_gl3.h4
-rw-r--r--example/canvas.c3
-rw-r--r--example/extended.c29
-rw-r--r--example/file_browser.c9
-rw-r--r--example/skinning.c4
-rw-r--r--nuklear.h1773
33 files changed, 1375 insertions, 1429 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 05741d3..17f1858 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,4 +1,30 @@
# Changelog
+- 2016/12/03 (1.191)- Fixed wrapped text with no seperator and C89 error
+- 2016/12/03 (1.19) - Changed text wrapping to process words not characters
+- 2016/11/22 (1.184)- Fixed window minimized closing bug
+- 2016/11/19 (1.184)- Fixed abstract combo box closing behavior
+- 2016/11/19 (1.184)- Fixed tooltip flickering
+- 2016/11/19 (1.183)- Fixed memory leak caused by popup repeated closing
+- 2016/11/18 (1.182)- Fixed memory leak caused by popup panel allocation
+- 2016/11/10 (1.181)- Fixed some warnings and C++ error
+- 2016/11/10 (1.180)- Added additional `nk_button` versions which allows to directly
+ pass in a style struct to change buttons visual.
+- 2016/11/10 (1.180)- 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.180)- 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.171)- Fixed clipping rectangle bug inside `nk_draw_list`
+- 2016/10/29 (1.170)- 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.160)- Changed widget border drawing to stroked rectangle from filled
rectangle for less overdraw and widget background transparency.
- 2016/10/18 (1.160)- Added `nk_edit_focus` for manually edit widget focus control
diff --git a/Readme.md b/Readme.md
index c2c1a60..29d56d3 100644
--- a/Readme.md
+++ b/Readme.md
@@ -58,8 +58,7 @@ int op = EASY;
float value = 0.6f;
int i = 20;
-struct nk_panel layout;
-if (nk_begin(&ctx, &layout, "Show", nk_rect(50, 50, 220, 220),
+if (nk_begin(&ctx, "Show", nk_rect(50, 50, 220, 220),
NK_WINDOW_BORDER|NK_WINDOW_MOVABLE|NK_WINDOW_CLOSABLE)) {
/* fixed widget pixel width */
nk_layout_row_static(&ctx, 30, 80, 1);
diff --git a/demo/calculator.c b/demo/calculator.c
index c45cc6a..b871301 100644
--- a/demo/calculator.c
+++ b/demo/calculator.c
@@ -2,8 +2,7 @@
static void
calculator(struct nk_context *ctx)
{
- struct nk_panel layout;
- if (nk_begin(ctx, &layout, "Calculator", nk_rect(10, 10, 180, 250),
+ if (nk_begin(ctx, "Calculator", nk_rect(10, 10, 180, 250),
NK_WINDOW_BORDER|NK_WINDOW_NO_SCROLLBAR|NK_WINDOW_MOVABLE))
{
static int set = 0, prev = 0, op = 0;
@@ -29,8 +28,7 @@ calculator(struct nk_context *ctx)
a = b = op = 0; current = &a; set = 0;
} if (nk_button_label(ctx, "0")) {
*current = *current*10.0f; set = 0;
- }
- if (nk_button_label(ctx, "=")) {
+ } if (nk_button_label(ctx, "=")) {
solve = 1; prev = op; op = 0;
}
} else if (((i+1) % 4)) {
diff --git a/demo/d3d11/main.c b/demo/d3d11/main.c
index 63c3c8a..bc0dc64 100644
--- a/demo/d3d11/main.c
+++ b/demo/d3d11/main.c
@@ -1,4 +1,4 @@
-/* nuklear - v1.09 - public domain */
+/* nuklear - v1.17 - public domain */
#define COBJMACROS
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
@@ -209,8 +209,7 @@ int main(void)
nk_input_end(ctx);
/* GUI */
- {struct nk_panel layout;
- if (nk_begin(ctx, &layout, "Demo", nk_rect(50, 50, 230, 250),
+ if (nk_begin(ctx, "Demo", nk_rect(50, 50, 230, 250),
NK_WINDOW_BORDER|NK_WINDOW_MOVABLE|NK_WINDOW_SCALABLE|
NK_WINDOW_MINIMIZABLE|NK_WINDOW_TITLE))
{
@@ -227,11 +226,10 @@ int main(void)
nk_layout_row_dynamic(ctx, 22, 1);
nk_property_int(ctx, "Compression:", 0, &property, 100, 10, 1);
- {struct nk_panel combo;
nk_layout_row_dynamic(ctx, 20, 1);
nk_label(ctx, "background:", NK_TEXT_LEFT);
nk_layout_row_dynamic(ctx, 25, 1);
- if (nk_combo_begin_color(ctx, &combo, background, nk_vec2(nk_widget_width(ctx),400))) {
+ if (nk_combo_begin_color(ctx, background, nk_vec2(nk_widget_width(ctx),400))) {
nk_layout_row_dynamic(ctx, 120, 1);
background = nk_color_picker(ctx, background, NK_RGBA);
nk_layout_row_dynamic(ctx, 25, 1);
@@ -240,9 +238,9 @@ int main(void)
background.b = (nk_byte)nk_propertyi(ctx, "#B:", 0, background.b, 255, 1,1);
background.a = (nk_byte)nk_propertyi(ctx, "#A:", 0, background.a, 255, 1,1);
nk_combo_end(ctx);
- }}
+ }
}
- nk_end(ctx);}
+ nk_end(ctx);
if (nk_window_is_closed(ctx, "Demo")) break;
/* -------------- EXAMPLES ---------------- */
diff --git a/demo/d3d11/nuklear_d3d11.h b/demo/d3d11/nuklear_d3d11.h
index 7de383e..efddf0d 100644
--- a/demo/d3d11/nuklear_d3d11.h
+++ b/demo/d3d11/nuklear_d3d11.h
@@ -1,5 +1,5 @@
/*
- * Nuklear - v1.00 - public domain
+ * Nuklear - v1.17 - public domain
* no warrenty implied; use at your own risk.
* authored from 2015-2016 by Micha Mettke
*/
@@ -205,7 +205,7 @@ nk_d3d11_handle_event(HWND wnd, UINT msg, WPARAM wparam, LPARAM lparam)
case WM_SYSKEYDOWN:
case WM_SYSKEYUP:
{
- int down = (lparam >> 31) & 1;
+ int down = !((lparam >> 31) & 1);
int ctrl = GetKeyState(VK_CONTROL) & (1 << 15);
switch (wparam)
diff --git a/demo/gdi/main.c b/demo/gdi/main.c
index d9a80ca..e82cd16 100644
--- a/demo/gdi/main.c
+++ b/demo/gdi/main.c
@@ -1,4 +1,4 @@
-/* nuklear - v1.09 - public domain */
+/* nuklear - v1.17 - public domain */
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <stdio.h>
@@ -123,8 +123,7 @@ int main(void)
nk_input_end(ctx);
/* GUI */
- {struct nk_panel layout;
- if (nk_begin(ctx, &layout, "Demo", nk_rect(50, 50, 200, 200),
+ if (nk_begin(ctx, "Demo", nk_rect(50, 50, 200, 200),
NK_WINDOW_BORDER|NK_WINDOW_MOVABLE|NK_WINDOW_SCALABLE|
NK_WINDOW_CLOSABLE|NK_WINDOW_MINIMIZABLE|NK_WINDOW_TITLE))
{
@@ -141,7 +140,7 @@ int main(void)
nk_layout_row_dynamic(ctx, 22, 1);
nk_property_int(ctx, "Compression:", 0, &property, 100, 10, 1);
}
- nk_end(ctx);}
+ nk_end(ctx);
if (nk_window_is_closed(ctx, "Demo")) break;
/* -------------- EXAMPLES ---------------- */
diff --git a/demo/gdi/nuklear_gdi.h b/demo/gdi/nuklear_gdi.h
index 72b8e5e..6d3a84a 100644
--- a/demo/gdi/nuklear_gdi.h
+++ b/demo/gdi/nuklear_gdi.h
@@ -1,5 +1,5 @@
/*
- * Nuklear - v1.00 - public domain
+ * Nuklear - v1.17 - public domain
* no warrenty implied; use at your own risk.
* authored from 2015-2016 by Micha Mettke
*/
@@ -516,7 +516,7 @@ nk_gdi_handle_event(HWND wnd, UINT msg, WPARAM wparam, LPARAM lparam)
case WM_SYSKEYDOWN:
case WM_SYSKEYUP:
{
- int down = (lparam >> 31) & 1;
+ int down = !((lparam >> 31) & 1);
int ctrl = GetKeyState(VK_CONTROL) & (1 << 15);
switch (wparam)
diff --git a/demo/gdip/main.c b/demo/gdip/main.c
index 85b07cd..7d623e7 100644
--- a/demo/gdip/main.c
+++ b/demo/gdip/main.c
@@ -1,4 +1,4 @@
-/* nuklear - v1.09 - public domain */
+/* nuklear - v1.17 - public domain */
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <stdio.h>
@@ -118,8 +118,7 @@ int main(void)
nk_input_end(ctx);
/* GUI */
- {struct nk_panel layout;
- if (nk_begin(ctx, &layout, "Demo", nk_rect(50, 50, 200, 200),
+ if (nk_begin(ctx, "Demo", nk_rect(50, 50, 200, 200),
NK_WINDOW_BORDER|NK_WINDOW_MOVABLE|NK_WINDOW_SCALABLE|
NK_WINDOW_CLOSABLE|NK_WINDOW_MINIMIZABLE|NK_WINDOW_TITLE))
{
@@ -136,7 +135,7 @@ int main(void)
nk_layout_row_dynamic(ctx, 22, 1);
nk_property_int(ctx, "Compression:", 0, &property, 100, 10, 1);
}
- nk_end(ctx);}
+ nk_end(ctx);
if (nk_window_is_closed(ctx, "Demo")) break;
/* -------------- EXAMPLES ---------------- */
diff --git a/demo/gdip/nuklear_gdip.h b/demo/gdip/nuklear_gdip.h
index 0b620ed..66ccc0d 100644
--- a/demo/gdip/nuklear_gdip.h
+++ b/demo/gdip/nuklear_gdip.h
@@ -1,5 +1,5 @@
/*
- * Nuklear - v1.00 - public domain
+ * Nuklear - v1.17 - public domain
* no warrenty implied; use at your own risk.
* authored from 2015-2016 by Micha Mettke
*/
@@ -754,7 +754,7 @@ nk_gdip_handle_event(HWND wnd, UINT msg, WPARAM wparam, LPARAM lparam)
case WM_SYSKEYDOWN:
case WM_SYSKEYUP:
{
- int down = (lparam >> 31) & 1;
+ int down = !((lparam >> 31) & 1);
int ctrl = GetKeyState(VK_CONTROL) & (1 << 15);
switch (wparam)
diff --git a/demo/glfw_opengl2/main.c b/demo/glfw_opengl2/main.c
index f5ea3b0..1c0f284 100644
--- a/demo/glfw_opengl2/main.c
+++ b/demo/glfw_opengl2/main.c
@@ -1,4 +1,4 @@
-/* nuklear - v1.09 - public domain */
+/* nuklear - v1.17 - public domain */
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
@@ -104,8 +104,7 @@ int main(void)
nk_glfw3_new_frame();
/* GUI */
- {struct nk_panel layout;
- if (nk_begin(ctx, &layout, "Demo", nk_rect(50, 50, 230, 250),
+ if (nk_begin(ctx, "Demo", nk_rect(50, 50, 230, 250),
NK_WINDOW_BORDER|NK_WINDOW_MOVABLE|NK_WINDOW_SCALABLE|
NK_WINDOW_MINIMIZABLE|NK_WINDOW_TITLE))
{
@@ -123,11 +122,10 @@ int main(void)
nk_layout_row_dynamic(ctx, 25, 1);
nk_property_int(ctx, "Compression:", 0, &property, 100, 10, 1);
- {struct nk_panel combo;
nk_layout_row_dynamic(ctx, 20, 1);
nk_label(ctx, "background:", NK_TEXT_LEFT);
nk_layout_row_dynamic(ctx, 25, 1);
- if (nk_combo_begin_color(ctx, &combo, background, nk_vec2(nk_widget_width(ctx),400))) {
+ if (nk_combo_begin_color(ctx, background, nk_vec2(nk_widget_width(ctx),400))) {
nk_layout_row_dynamic(ctx, 120, 1);
background = nk_color_picker(ctx, background, NK_RGBA);
nk_layout_row_dynamic(ctx, 25, 1);
@@ -136,9 +134,9 @@ int main(void)
background.b = (nk_byte)nk_propertyi(ctx, "#B:", 0, background.b, 255, 1,1);
background.a = (nk_byte)nk_propertyi(ctx, "#A:", 0, background.a, 255, 1,1);
nk_combo_end(ctx);
- }}
+ }
}
- nk_end(ctx);}
+ nk_end(ctx);
/* -------------- EXAMPLES ---------------- */
/*calculator(ctx);*/
diff --git a/demo/glfw_opengl2/nuklear_glfw_gl2.h b/demo/glfw_opengl2/nuklear_glfw_gl2.h
index 798a3a2..93af773 100644
--- a/demo/glfw_opengl2/nuklear_glfw_gl2.h
+++ b/demo/glfw_opengl2/nuklear_glfw_gl2.h
@@ -1,5 +1,5 @@
/*
- * Nuklear - v1.00 - public domain
+ * Nuklear - v1.17 - public domain
* no warrenty implied; use at your own risk.
* authored from 2015-2016 by Micha Mettke
*/
diff --git a/demo/glfw_opengl3/main.c b/demo/glfw_opengl3/main.c
index 2ebe15d..d74ee56 100644
--- a/demo/glfw_opengl3/main.c
+++ b/demo/glfw_opengl3/main.c
@@ -1,4 +1,4 @@
-/* nuklear - v1.09 - public domain */
+/* nuklear - v1.17 - public domain */
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
@@ -118,8 +118,7 @@ int main(void)
nk_glfw3_new_frame();
/* GUI */
- {struct nk_panel layout;
- if (nk_begin(ctx, &layout, "Demo", nk_rect(50, 50, 230, 250),
+ if (nk_begin(ctx, "Demo", nk_rect(50, 50, 230, 250),
NK_WINDOW_BORDER|NK_WINDOW_MOVABLE|NK_WINDOW_SCALABLE|
NK_WINDOW_MINIMIZABLE|NK_WINDOW_TITLE))
{
@@ -137,11 +136,10 @@ int main(void)
nk_layout_row_dynamic(ctx, 25, 1);
nk_property_int(ctx, "Compression:", 0, &property, 100, 10, 1);
- {struct nk_panel combo;
nk_layout_row_dynamic(ctx, 20, 1);
nk_label(ctx, "background:", NK_TEXT_LEFT);
nk_layout_row_dynamic(ctx, 25, 1);
- if (nk_combo_begin_color(ctx, &combo, background, nk_vec2(nk_widget_width(ctx),400))) {
+ if (nk_combo_begin_color(ctx, background, nk_vec2(nk_widget_width(ctx),400))) {
nk_layout_row_dynamic(ctx, 120, 1);
background = nk_color_picker(ctx, background, NK_RGBA);
nk_layout_row_dynamic(ctx, 25, 1);
@@ -150,9 +148,9 @@ int main(void)
background.b = (nk_byte)nk_propertyi(ctx, "#B:", 0, background.b, 255, 1,1);
background.a = (nk_byte)nk_propertyi(ctx, "#A:", 0, background.a, 255, 1,1);
nk_combo_end(ctx);
- }}
+ }
}
- nk_end(ctx);}
+ nk_end(ctx);
/* -------------- EXAMPLES ---------------- */
/*calculator(ctx);*/
diff --git a/demo/glfw_opengl3/nuklear_glfw_gl3.h b/demo/glfw_opengl3/nuklear_glfw_gl3.h
index 6b8d982..aabb365 100644
--- a/demo/glfw_opengl3/nuklear_glfw_gl3.h
+++ b/demo/glfw_opengl3/nuklear_glfw_gl3.h
@@ -1,5 +1,5 @@
/*
- * Nuklear - v1.00 - public domain
+ * Nuklear - v1.17 - public domain
* no warrenty implied; use at your own risk.
* authored from 2015-2016 by Micha Mettke
*/
diff --git a/demo/node_editor.c b/demo/node_editor.c
index 8a3e72b..6949f59 100644
--- a/demo/node_editor.c
+++ b/demo/node_editor.c
@@ -152,7 +152,6 @@ node_editor(struct nk_context *ctx)
const struct nk_input *in = &ctx->input;
struct nk_command_buffer *canvas;
struct node *updated = 0;
- struct nk_panel layout;
struct node_editor *nodedit = &nodeEditor;
if (!nodeEditor.initialized) {
@@ -160,7 +159,7 @@ node_editor(struct nk_context *ctx)
nodeEditor.initialized = 1;
}
- if (nk_begin(ctx, &layout, "NodeEdit", nk_rect(0, 0, 800, 600),
+ if (nk_begin(ctx, "NodeEdit", nk_rect(0, 0, 800, 600),
NK_WINDOW_BORDER|NK_WINDOW_NO_SCROLLBAR|NK_WINDOW_MOVABLE|NK_WINDOW_CLOSABLE))
{
/* allocate complete window space */
@@ -168,7 +167,6 @@ node_editor(struct nk_context *ctx)
total_space = nk_window_get_content_region(ctx);
nk_layout_space_begin(ctx, NK_STATIC, total_space.h, nodedit->node_count);
{
- struct nk_panel node, menu;
struct node *it = nodedit->begin;
struct nk_rect size = nk_layout_space_bounds(ctx);
@@ -184,18 +182,21 @@ node_editor(struct nk_context *ctx)
}
/* execute each node as a movable group */
+ struct nk_panel *node;
while (it) {
/* calculate scrolled node window position and size */
nk_layout_space_push(ctx, nk_rect(it->bounds.x - nodedit->scrolling.x,
it->bounds.y - nodedit->scrolling.y, it->bounds.w, it->bounds.h));
/* execute node window */
- if (nk_group_begin(ctx, &node, it->name, NK_WINDOW_MOVABLE|NK_WINDOW_NO_SCROLLBAR|NK_WINDOW_BORDER|NK_WINDOW_TITLE))
+ if (nk_group_begin(ctx, it->name, NK_WINDOW_MOVABLE|NK_WINDOW_NO_SCROLLBAR|NK_WINDOW_BORDER|NK_WINDOW_TITLE))
{
/* always have last selected node on top */
- if (nk_input_mouse_clicked(in, NK_BUTTON_LEFT, node.bounds) &&
+
+ node = nk_window_get_panel(ctx);
+ if (nk_input_mouse_clicked(in, NK_BUTTON_LEFT, node->bounds) &&
(!(it->prev && nk_input_mouse_clicked(in, NK_BUTTON_LEFT,
- nk_layout_space_rect_to_screen(ctx, node.bounds)))) &&
+ nk_layout_space_rect_to_screen(ctx, node->bounds)))) &&
nodedit->end != it)
{
updated = it;
@@ -215,17 +216,17 @@ node_editor(struct nk_context *ctx)
/* node connector and linking */
float space;
struct nk_rect bounds;
- bounds = nk_layout_space_rect_to_local(ctx, node.bounds);
+ bounds = nk_layout_space_rect_to_local(ctx, node->bounds);
bounds.x += nodedit->scrolling.x;
bounds.y += nodedit->scrolling.y;
it->bounds = bounds;
/* output connector */
- space = node.bounds.h / (float)((it->output_count) + 1);
+ space = node->bounds.h / (float)((it->output_count) + 1);
for (n = 0; n < it->output_count; ++n) {
struct nk_rect circle;
- circle.x = node.bounds.x + node.bounds.w-4;
- circle.y = node.bounds.y + space * (float)(n+1);
+ circle.x = node->bounds.x + node->bounds.w-4;
+ circle.y = node->bounds.y + space * (float)(n+1);
circle.w = 8; circle.h = 8;
nk_fill_circle(canvas, circle, nk_rgb(100, 100, 100));
@@ -248,11 +249,11 @@ node_editor(struct nk_context *ctx)
}
/* input connector */
- space = node.bounds.h / (float)((it->input_count) + 1);
+ space = node->bounds.h / (float)((it->input_count) + 1);
for (n = 0; n < it->input_count; ++n) {
struct nk_rect circle;
- circle.x = node.bounds.x-4;
- circle.y = node.bounds.y + space * (float)(n+1);
+ circle.x = node->bounds.x-4;
+ circle.y = node->bounds.y + space * (float)(n+1);
circle.w = 8; circle.h = 8;
nk_fill_circle(canvas, circle, nk_rgb(100, 100, 100));
if (nk_input_is_mouse_released(in, NK_BUTTON_LEFT) &&
@@ -279,8 +280,8 @@ node_editor(struct nk_context *ctx)
struct node_link *link = &nodedit->links[n];
struct node *ni = node_editor_find(nodedit, link->input_id);
struct node *no = node_editor_find(nodedit, link->output_id);
- float spacei = node.bounds.h / (float)((ni->output_count) + 1);
- float spaceo = node.bounds.h / (float)((no->input_count) + 1);
+ float spacei = node->bounds.h / (float)((ni->output_count) + 1);
+ float spaceo = node->bounds.h / (float)((no->input_count) + 1);
struct nk_vec2 l0 = nk_layout_space_to_screen(ctx,
nk_vec2(ni->bounds.x + ni->bounds.w, 3.0f + ni->bounds.y + spacei * (float)(link->input_slot+1)));
struct nk_vec2 l1 = nk_layout_space_to_screen(ctx,
@@ -316,7 +317,7 @@ node_editor(struct nk_context *ctx)
}
/* contextual menu */
- if (nk_contextual_begin(ctx, &menu, 0, nk_vec2(100, 220), nk_window_get_bounds(ctx))) {
+ if (nk_contextual_begin(ctx, 0, nk_vec2(100, 220), nk_window_get_bounds(ctx))) {
const char *grid_option[] = {"Show Grid", "Hide Grid"};
nk_layout_row_dynamic(ctx, 25, 1);
if (nk_contextual_item_label(ctx, "New", NK_TEXT_CENTERED))
diff --git a/demo/overview.c b/demo/overview.c
index 3b26117..e271318 100644
--- a/demo/overview.c
+++ b/demo/overview.c
@@ -2,8 +2,6 @@
static int
overview(struct nk_context *ctx)
{
- struct nk_panel menu;
-
/* window flags */
static int show_menu = nk_true;
static int titlebar = nk_true;
@@ -17,7 +15,6 @@ overview(struct nk_context *ctx)
/* popups */
static enum nk_style_header_align header_align = NK_HEADER_RIGHT;
static int show_app_about = nk_false;
- struct nk_panel layout;
/* window flags */
window_flags = 0;
@@ -28,7 +25,7 @@ overview(struct nk_context *ctx)
if (no_scrollbar) window_flags |= NK_WINDOW_NO_SCROLLBAR;
if (minimizable) window_flags |= NK_WINDOW_MINIMIZABLE;
- if (nk_begin(ctx, &layout, "Overview", nk_rect(10, 10, 400, 600), window_flags))
+ if (nk_begin(ctx, "Overview", nk_rect(10, 10, 400, 600), window_flags))
{
if (show_menu)
{
@@ -39,9 +36,9 @@ overview(struct nk_context *ctx)
static int mcheck = nk_true;
nk_menubar_begin(ctx);
- nk_layout_row_begin(ctx, NK_STATIC, 25, 2);
+ nk_layout_row_begin(ctx, NK_STATIC, 25, 4);
nk_layout_row_push(ctx, 45);
- if (nk_menu_begin_label(ctx, &menu, "MENU", NK_TEXT_LEFT, nk_vec2(120, 200)))
+ if (nk_menu_begin_label(ctx, "MENU", NK_TEXT_LEFT, nk_vec2(120, 200)))
{
static size_t prog = 40;
static int slider = 10;
@@ -66,9 +63,8 @@ overview(struct nk_context *ctx)
if (show_app_about)
{
/* about popup */
- struct nk_panel popup;
static struct nk_rect s = {20, 100, 300, 190};
- if (nk_popup_begin(ctx, &popup, NK_POPUP_STATIC, "About", NK_WINDOW_CLOSABLE, s))
+ if (nk_popup_begin(ctx, NK_POPUP_STATIC, "About", NK_WINDOW_CLOSABLE, s))
{
nk_layout_row_dynamic(ctx, 20, 1);
nk_label(ctx, "Nuklear", NK_TEXT_LEFT);
@@ -272,14 +268,13 @@ overview(struct nk_context *ctx)
char buffer[64];
size_t sum = 0;
- struct nk_panel combo;
/* default combobox */
nk_layout_row_static(ctx, 25, 200, 1);
current_weapon = nk_combo(ctx, weapons, LEN(weapons), current_weapon, 25, nk_vec2(200,200));
/* slider color combobox */
- if (nk_combo_begin_color(ctx, &combo, combo_color, nk_vec2(200,200))) {
+ if (nk_combo_begin_color(ctx, combo_color, nk_vec2(200,200))) {
float ratios[] = {0.15f, 0.85f};
nk_layout_row(ctx, NK_DYNAMIC, 30, 2, ratios);
nk_label(ctx, "R:", NK_TEXT_LEFT);
@@ -294,7 +289,7 @@ overview(struct nk_context *ctx)
}
/* complex color combobox */
- if (nk_combo_begin_color(ctx, &combo, combo_color2, nk_vec2(200,400))) {
+ if (nk_combo_begin_color(ctx, combo_color2, nk_vec2(200,400))) {
enum color_mode {COL_RGB, COL_HSV};
static int col_mode = COL_RGB;
#ifndef DEMO_DO_NOT_USE_COLOR_PICKER
@@ -327,7 +322,7 @@ overview(struct nk_context *ctx)
/* progressbar combobox */
sum = prog_a + prog_b + prog_c + prog_d;
sprintf(buffer, "%lu", sum);
- if (nk_combo_begin_label(ctx, &combo, buffer, nk_vec2(200,200))) {
+ if (nk_combo_begin_label(ctx, buffer, nk_vec2(200,200))) {
nk_layout_row_dynamic(ctx, 30, 1);
nk_progress(ctx, &prog_a, 100, NK_MODIFIABLE);
nk_progress(ctx, &prog_b, 100, NK_MODIFIABLE);
@@ -339,7 +334,7 @@ overview(struct nk_context *ctx)
/* checkbox combobox */
sum = (size_t)(check_values[0] + check_values[1] + check_values[2] + check_values[3] + check_values[4]);
sprintf(buffer, "%lu", sum);
- if (nk_combo_begin_label(ctx, &combo, buffer, nk_vec2(200,200))) {
+ if (nk_combo_begin_label(ctx, buffer, nk_vec2(200,200))) {
nk_layout_row_dynamic(ctx, 30, 1);
nk_checkbox_label(ctx, weapons[0], &check_values[0]);
nk_checkbox_label(ctx, weapons[1], &check_values[1]);
@@ -350,7 +345,7 @@ overview(struct nk_context *ctx)
/* complex text combobox */
sprintf(buffer, "%.2f, %.2f, %.2f", position[0], position[1],position[2]);
- if (nk_combo_begin_label(ctx, &combo, buffer, nk_vec2(200,200))) {
+ if (nk_combo_begin_label(ctx, buffer, nk_vec2(200,200))) {
nk_layout_row_dynamic(ctx, 25, 1);
nk_property_float(ctx, "#X:", -1024.0f, &position[0], 1024.0f, 1,0.5f);
nk_property_float(ctx, "#Y:", -1024.0f, &position[1], 1024.0f, 1,0.5f);
@@ -360,7 +355,7 @@ overview(struct nk_context *ctx)
/* chart combobox */
sprintf(buffer, "%.1f", chart_selection);
- if (nk_combo_begin_label(ctx, &combo, buffer, nk_vec2(200,250))) {
+ if (nk_combo_begin_label(ctx, buffer, nk_vec2(200,250))) {
size_t i = 0;
static const float values[]={26.0f,13.0f,30.0f,15.0f,25.0f,10.0f,20.0f,40.0f, 12.0f, 8.0f, 22.0f, 28.0f, 5.0f};
nk_layout_row_dynamic(ctx, 150, 1);
@@ -393,7 +388,7 @@ overview(struct nk_context *ctx)
/* time combobox */
sprintf(buffer, "%02d:%02d:%02d", sel_time.tm_hour, sel_time.tm_min, sel_time.tm_sec);
- if (nk_combo_begin_label(ctx, &combo, buffer, nk_vec2(200,250))) {
+ if (nk_combo_begin_label(ctx, buffer, nk_vec2(200,250))) {
time_selected = 1;
nk_layout_row_dynamic(ctx, 25, 1);
sel_time.tm_sec = nk_propertyi(ctx, "#S:", 0, sel_time.tm_sec, 60, 1, 1);
@@ -404,7 +399,7 @@ overview(struct nk_context *ctx)
/* date combobox */
sprintf(buffer, "%02d-%02d-%02d", sel_date.tm_mday, sel_date.tm_mon+1, sel_date.tm_year+1900);
- if (nk_combo_begin_label(ctx, &combo, buffer, nk_vec2(350,400)))
+ if (nk_combo_begin_label(ctx, buffer, nk_vec2(350,400)))
{
int i = 0;
const char *month[] = {"January", "February", "March", "Apil", "May", "June", "July", "August", "September", "Ocotober", "November", "December"};
@@ -647,7 +642,7 @@ overview(struct nk_context *ctx)
bounds = nk_widget_bounds(ctx);
nk_label(ctx, "Right click me for menu", NK_TEXT_LEFT);
- if (nk_contextual_begin(ctx, &menu, 0, nk_vec2(100, 300), bounds)) {
+ if (nk_contextual_begin(ctx, 0, nk_vec2(100, 300), bounds)) {
static size_t prog = 40;
static int slider = 10;
@@ -673,7 +668,7 @@ overview(struct nk_context *ctx)
nk_button_color(ctx, color);
nk_layout_row_end(ctx);
- if (nk_contextual_begin(ctx, &menu, 0, nk_vec2(350, 60), bounds)) {
+ if (nk_contextual_begin(ctx, 0, nk_vec2(350, 60), bounds)) {
nk_layout_row_dynamic(ctx, 30, 4);
color.r = (nk_byte)nk_propertyi(ctx, "#r", 0, color.r, 255, 1, 1);
color.g = (nk_byte)nk_propertyi(ctx, "#g", 0, color.g, 255, 1, 1);
@@ -694,7 +689,7 @@ overview(struct nk_context *ctx)
if (popup_active)
{
static struct nk_rect s = {20, 100, 220, 90};
- if (nk_popup_begin(ctx, &menu, NK_POPUP_STATIC, "Error", 0, s))
+ if (nk_popup_begin(ctx, NK_POPUP_STATIC, "Error", 0, s))
{
nk_layout_row_dynamic(ctx, 25, 1);
nk_label(ctx, "A terrible error as occured", NK_TEXT_LEFT);
@@ -800,7 +795,6 @@ overview(struct nk_context *ctx)
static int group_no_scrollbar = nk_false;
static int group_width = 320;
static int group_height = 200;
- struct nk_panel tab;
nk_flags group_flags = 0;
if (group_border) group_flags |= NK_WINDOW_BORDER;
@@ -822,7 +816,7 @@ overview(struct nk_context *ctx)
nk_layout_row_end(ctx);
nk_layout_row_static(ctx, (float)group_height, group_width, 2);
- if (nk_group_begin(ctx, &tab, "Group", group_flags)) {
+ if (nk_group_begin(ctx, "Group", group_flags)) {
int i = 0;
static int selected[16];
nk_layout_row_static(ctx, 18, 100, 1);
@@ -836,13 +830,11 @@ overview(struct nk_context *ctx)
if (nk_tree_push(ctx, NK_TREE_NODE, "Notebook", NK_MINIMIZED))
{
static int current_tab = 0;
- struct nk_panel group;
struct nk_vec2 item_padding;
struct nk_rect bounds;
float step = (2*3.141592654f) / 32;
enum chart_type {CHART_LINE, CHART_HISTO, CHART_MIXED};
const char *names[] = {"Lines", "Columns", "Mixed"};
- float rounding;
float id = 0;
int i;
@@ -868,7 +860,7 @@ overview(struct nk_context *ctx)
/* Body */
nk_layout_row_dynamic(ctx, 140, 1);
- if (nk_group_begin(ctx, &group, "Notebook", NK_WINDOW_BORDER))
+ if (nk_group_begin(ctx, "Notebook", NK_WINDOW_BORDER))
{
nk_style_pop_vec2(ctx);
switch (current_tab) {
@@ -919,9 +911,8 @@ overview(struct nk_context *ctx)
if (nk_tree_push(ctx, NK_TREE_NODE, "Simple", NK_MINIMIZED))
{
- struct nk_panel tab;
nk_layout_row_dynamic(ctx, 300, 2);
- if (nk_group_begin(ctx, &tab, "Group_Without_Border", 0)) {
+ if (nk_group_begin(ctx, "Group_Without_Border", 0)) {
int i = 0;
char buffer[64];
nk_layout_row_static(ctx, 18, 150, 1);
@@ -931,7 +922,7 @@ overview(struct nk_context *ctx)
}
nk_group_end(ctx);
}
- if (nk_group_begin(ctx, &tab, "Group_With_Border", NK_WINDOW_BORDER)) {
+ if (nk_group_begin(ctx, "Group_With_Border", NK_WINDOW_BORDER)) {
int i = 0;
char buffer[64];
nk_layout_row_dynamic(ctx, 25, 2);
@@ -947,10 +938,9 @@ overview(struct nk_context *ctx)
if (nk_tree_push(ctx, NK_TREE_NODE, "Complex", NK_MINIMIZED))
{
int i;
- struct nk_panel tab;
nk_layout_space_begin(ctx, NK_STATIC, 500, 64);
nk_layout_space_push(ctx, nk_rect(0,0,150,500));
- if (nk_group_begin(ctx, &tab, "Group_left", NK_WINDOW_BORDER)) {
+ if (nk_group_begin(ctx, "Group_left", NK_WINDOW_BORDER)) {
static int selected[32];
nk_layout_row_static(ctx, 18, 100, 1);
for (i = 0; i < 32; ++i)
@@ -959,7 +949,7 @@ overview(struct nk_context *ctx)
}
nk_layout_space_push(ctx, nk_rect(160,0,150,240));
- if (nk_group_begin(ctx, &tab, "Group_top", NK_WINDOW_BORDER)) {
+ if (nk_group_begin(ctx, "Group_top", NK_WINDOW_BORDER)) {
nk_layout_row_dynamic(ctx, 25, 1);
nk_button_label(ctx, "#FFAA");
nk_button_label(ctx, "#FFBB");
@@ -971,7 +961,7 @@ overview(struct nk_context *ctx)
}
nk_layout_space_push(ctx, nk_rect(160,250,150,250));
- if (nk_group_begin(ctx, &tab, "Group_buttom", NK_WINDOW_BORDER)) {
+ if (nk_group_begin(ctx, "Group_buttom", NK_WINDOW_BORDER)) {
nk_layout_row_dynamic(ctx, 25, 1);
nk_button_label(ctx, "#FFAA");
nk_button_label(ctx, "#FFBB");
@@ -983,7 +973,7 @@ overview(struct nk_context *ctx)
}
nk_layout_space_push(ctx, nk_rect(320,0,150,150));
- if (nk_group_begin(ctx, &tab, "Group_right_top", NK_WINDOW_BORDER)) {
+ if (nk_group_begin(ctx, "Group_right_top", NK_WINDOW_BORDER)) {
static int selected[4];
nk_layout_row_static(ctx, 18, 100, 1);
for (i = 0; i < 4; ++i)
@@ -992,7 +982,7 @@ overview(struct nk_context *ctx)
}
nk_layout_space_push(ctx, nk_rect(320,160,150,150));
- if (nk_group_begin(ctx, &tab, "Group_right_center", NK_WINDOW_BORDER)) {
+ if (nk_group_begin(ctx, "Group_right_center", NK_WINDOW_BORDER)) {
static int selected[4];
nk_layout_row_static(ctx, 18, 100, 1);
for (i = 0; i < 4; ++i)
@@ -1001,7 +991,7 @@ overview(struct nk_context *ctx)
}
nk_layout_space_push(ctx, nk_rect(320,320,150,150));
- if (nk_group_begin(ctx, &tab, "Group_right_bottom", NK_WINDOW_BORDER)) {
+ if (nk_group_begin(ctx, "Group_right_bottom", NK_WINDOW_BORDER)) {
static int selected[4];
nk_layout_row_static(ctx, 18, 100, 1);
for (i = 0; i < 4; ++i)
@@ -1023,7 +1013,6 @@ overview(struct nk_context *ctx)
{
static float a = 100, b = 100, c = 100;
struct nk_rect bounds;
- struct nk_panel sub;
float row_layout[5];
row_layout[0] = a;
@@ -1047,7 +1036,7 @@ overview(struct nk_context *ctx)
nk_layout_row(ctx, NK_STATIC, 200, 5, row_layout);
/* left space */
- if (nk_group_begin(ctx, &sub, "left", NK_WINDOW_NO_SCROLLBAR|NK_WINDOW_BORDER|NK_WINDOW_NO_SCROLLBAR)) {
+ if (nk_group_begin(ctx, "left", NK_WINDOW_NO_SCROLLBAR|NK_WINDOW_BORDER|NK_WINDOW_NO_SCROLLBAR)) {
nk_layout_row_dynamic(ctx, 25, 1);
nk_button_label(ctx, "#FFAA");
nk_button_label(ctx, "#FFBB");
@@ -1070,7 +1059,7 @@ overview(struct nk_context *ctx)
}
/* middle space */
- if (nk_group_begin(ctx, &sub, "center", NK_WINDOW_BORDER|NK_WINDOW_NO_SCROLLBAR)) {
+ if (nk_group_begin(ctx, "center", NK_WINDOW_BORDER|NK_WINDOW_NO_SCROLLBAR)) {
nk_layout_row_dynamic(ctx, 25, 1);
nk_button_label(ctx, "#FFAA");
nk_button_label(ctx, "#FFBB");
@@ -1093,7 +1082,7 @@ overview(struct nk_context *ctx)
}
/* right space */
- if (nk_group_begin(ctx, &sub, "right", NK_WINDOW_BORDER|NK_WINDOW_NO_SCROLLBAR)) {
+ if (nk_group_begin(ctx, "right", NK_WINDOW_BORDER|NK_WINDOW_NO_SCROLLBAR)) {
nk_layout_row_dynamic(ctx, 25, 1);
nk_button_label(ctx, "#FFAA");
nk_button_label(ctx, "#FFBB");
@@ -1110,7 +1099,6 @@ overview(struct nk_context *ctx)
if (nk_tree_push(ctx, NK_TREE_NODE, "Horizontal", NK_MINIMIZED))
{
static float a = 100, b = 100, c = 100;
- struct nk_panel sub;
struct nk_rect bounds;
/* header */
@@ -1126,7 +1114,7 @@ overview(struct nk_context *ctx)
/* top space */
nk_layout_row_dynamic(ctx, a, 1);
- if (nk_group_begin(ctx, &sub, "top", NK_WINDOW_NO_SCROLLBAR|NK_WINDOW_BORDER)) {
+ if (nk_group_begin(ctx, "top", NK_WINDOW_NO_SCROLLBAR|NK_WINDOW_BORDER)) {
nk_layout_row_dynamic(ctx, 25, 3);
nk_button_label(ctx, "#FFAA");
nk_button_label(ctx, "#FFBB");
@@ -1151,7 +1139,7 @@ overview(struct nk_context *ctx)
/* middle space */
nk_layout_row_dynamic(ctx, b, 1);
- if (nk_group_begin(ctx, &sub, "middle", NK_WINDOW_NO_SCROLLBAR|NK_WINDOW_BORDER)) {
+ if (nk_group_begin(ctx, "middle", NK_WINDOW_NO_SCROLLBAR|NK_WINDOW_BORDER)) {
nk_layout_row_dynamic(ctx, 25, 3);
nk_button_label(ctx, "#FFAA");
nk_button_label(ctx, "#FFBB");
@@ -1177,7 +1165,7 @@ overview(struct nk_context *ctx)
/* bottom space */
nk_layout_row_dynamic(ctx, c, 1);
- if (nk_group_begin(ctx, &sub, "bottom", NK_WINDOW_NO_SCROLLBAR|NK_WINDOW_BORDER)) {
+ if (nk_group_begin(ctx, "bottom", NK_WINDOW_NO_SCROLLBAR|NK_WINDOW_BORDER)) {
nk_layout_row_dynamic(ctx, 25, 3);
nk_button_label(ctx, "#FFAA");
nk_button_label(ctx, "#FFBB");
diff --git a/demo/sdl1_2/Makefile b/demo/sdl1_2/Makefile
deleted file mode 100644
index 36283bf..0000000
--- a/demo/sdl1_2/Makefile
+++ /dev/null
@@ -1,20 +0,0 @@
-# Install
-BIN = demo
-
-# Flags
-CFLAGS = -std=c89 -pedantic -O2
-
-SRC = main.c
-OBJ = $(SRC:.c=.o)
-
-ifeq ($(OS),Windows_NT)
-BIN := $(BIN).exe
-LIBS = -lmingw32 -lSDLmain -lSDL -lm
-else
-LIBS = -lSDL -lSDL_gfx -lm
-endif
-
-$(BIN):
- @mkdir -p bin
- rm -f bin/$(BIN) $(OBJS)
- $(CC) $(SRC) $(CFLAGS) -o bin/$(BIN) $(LIBS)
diff --git a/demo/sdl1_2/main.c b/demo/sdl1_2/main.c
deleted file mode 100644
index 352f6d1..0000000
--- a/demo/sdl1_2/main.c
+++ /dev/null
@@ -1,137 +0,0 @@
-/* nuklear - v1.09 - public domain */
-#include <stdio.h>
-#include <stdlib.h>
-#include <stdint.h>
-#include <stdarg.h>
-#include <string.h>
-#include <math.h>
-#include <assert.h>
-#include <math.h>
-
-#include <SDL/SDL.h>
-
-#define NK_INCLUDE_FIXED_TYPES
-#define NK_INCLUDE_STANDARD_IO
-#define NK_INCLUDE_STANDARD_VARARGS
-#define NK_INCLUDE_DEFAULT_ALLOCATOR
-#define NK_IMPLEMENTATION
-#define NK_SDL_IMPLEMENTATION
-#include "../../nuklear.h"
-#include "nuklear_sdl.h"
-
-#define WINDOW_WIDTH 800
-#define WINDOW_HEIGHT 600
-
-/* ===============================================================
- *
- * EXAMPLE
- *
- * ===============================================================*/
-/* This are some code examples to provide a small overview of what can be
- * done with this library. To try out an example uncomment the include
- * and the corresponding function. */
-/*#include "../style.c"*/
-/*#include "../calculator.c"*/
-/*#include "../overview.c"*/
-/*#include "../node_editor.c"*/
-
-/* ===============================================================
- *
- * DEMO
- *
- * ===============================================================*/
-int main(int argc, char **argv)
-{
- static SDL_Surface *screen_surface;
- struct nk_color background;
- int running = 1;
- struct nk_context *ctx;
- float bg[4];
-
- /* SDL setup */
- if( SDL_Init(SDL_INIT_VIDEO) == -1) {
- printf( "Can't init SDL: %s\n", SDL_GetError( ) );
- return 1;
- }
- screen_surface = SDL_SetVideoMode(WINDOW_WIDTH, WINDOW_HEIGHT, 32, SDL_SWSURFACE);
- if(screen_surface == NULL) {
- printf( "Can't set video mode: %s\n", SDL_GetError( ) );
- return 1;
- }
-
- ctx = nk_sdl_init(screen_surface);
- background = nk_rgb(28,48,62);
-
- /* style.c */
- /*set_style(ctx, THEME_WHITE);*/
- /*set_style(ctx, THEME_RED);*/
- /*set_style(ctx, THEME_BLUE);*/
- /*set_style(ctx, THEME_DARK);*/
-
- while (running)
- {
- /* Input */
- SDL_Event evt;
- nk_input_begin(ctx);
- while (SDL_PollEvent(&evt)) {
- if (evt.type == SDL_QUIT) goto cleanup;
- nk_sdl_handle_event(&evt);
- }
- nk_input_end(ctx);
-
- /* GUI */
- {struct nk_panel layout;
- if (nk_begin(ctx, &layout, "Demo", nk_rect(50, 50, 210, 250),
- NK_WINDOW_BORDER|NK_WINDOW_MOVABLE|NK_WINDOW_SCALABLE|
- NK_WINDOW_MINIMIZABLE|NK_WINDOW_TITLE))
- {
- enum {EASY, HARD};
- static int op = EASY;
- static int property = 20;
- static char buffer[64];
- static int len;
-
- nk_layout_row_static(ctx, 30, 80, 1);
- if (nk_button_label(ctx, "button"))
- fprintf(stdout, "button pressed\n");
- nk_layout_row_dynamic(ctx, 30, 2);
- if (nk_option_label(ctx, "easy", op == EASY)) op = EASY;
- if (nk_option_label(ctx, "hard", op == HARD)) op = HARD;
- nk_layout_row_dynamic(ctx, 25, 1);
- nk_property_int(ctx, "Compression:", 0, &property, 100, 10, 1);
- nk_edit_string(ctx, NK_EDIT_SIMPLE, buffer, &len, 64, 0);
-
- {struct nk_panel combo;
- nk_layout_row_dynamic(ctx, 30, 1);
- nk_label(ctx, "background:", NK_TEXT_LEFT);
- nk_layout_row_dynamic(ctx, 25, 1);
- if (nk_combo_begin_color(ctx, &combo, background, 400)) {
- nk_layout_row_dynamic(ctx, 120, 1);
- background = nk_color_picker(ctx, background, NK_RGBA);
- nk_layout_row_dynamic(ctx, 25, 1);
- background.r = (nk_byte)nk_propertyi(ctx, "#R:", 0, background.r, 255, 1,1);
- background.g = (nk_byte)nk_propertyi(ctx, "#G:", 0, background.g, 255, 1,1);
- background.b = (nk_byte)nk_propertyi(ctx, "#B:", 0, background.b, 255, 1,1);
- background.a = (nk_byte)nk_propertyi(ctx, "#A:", 0, background.a, 255, 1,1);
- nk_combo_end(ctx);
- }}
- }
- nk_end(ctx);}
-
- /* -------------- EXAMPLES ---------------- */
- /*calculator(ctx);*/
- /*overview(ctx);*/
- /*node_editor(ctx);*/
- /* ----------------------------------------- */
-
- /* Draw */
- nk_color_fv(bg, background);
- nk_sdl_render(nk_rgb(30,30,30));
- }
-
-cleanup:
- nk_sdl_shutdown();
- SDL_Quit();
- return 0;
-}
-
diff --git a/demo/sdl1_2/nuklear_sdl.h b/demo/sdl1_2/nuklear_sdl.h
deleted file mode 100644
index 8b6e785..0000000
--- a/demo/sdl1_2/nuklear_sdl.h
+++ /dev/null
@@ -1,474 +0,0 @@
-/*
- * Nuklear - v1.00 - public domain
- * no warrenty implied; use at your own risk.
- * authored from 2015-2016 by Micha Mettke
- */
-/*
- * ==============================================================
- *
- * API
- *
- * ===============================================================
- */
-#ifndef NK_SDL_H_
-#define NK_SDL_H_
-
-#include <SDL/SDL.h>
-typedef struct nk_sdl_Font nk_sdl_Font;
-NK_API struct nk_context* nk_sdl_init(SDL_Surface *screen_surface);
-NK_API void nk_sdl_handle_event(SDL_Event *evt);
-NK_API void nk_sdl_render(struct nk_color clear);
-NK_API void nk_sdl_shutdown(void);
-
-#endif
-/*
- * ==============================================================
- *
- * IMPLEMENTATION
- *
- * ===============================================================
- */
-#ifdef NK_SDL_IMPLEMENTATION
-
-#include <string.h>
-#include <SDL/SDL.h>
-#include <SDL/SDL_gfxPrimitives.h>
-
-#ifndef MAX
-#define MAX(a,b) ((a) < (b) ? (b) : (a))
-#endif
-
-#ifndef NK_SDL_MAX_POINTS
-#define NK_SDL_MAX_POINTS 128
-#endif
-
-struct nk_sdl_Font {
- int width;
- int height;
- int handle;
-};
-
-static struct nk_sdl {
- SDL_Surface *screen_surface;
- struct nk_context ctx;
-} sdl;
-
-static nk_sdl_Font *sdl_font;
-static SDL_Rect sdl_clip_rect;
-
-static void
-nk_sdl_scissor(SDL_Surface *surface, float x, float y, float w, float h)
-{
- sdl_clip_rect.x = x;
- sdl_clip_rect.y = y;
- sdl_clip_rect.w = w + 1;
- sdl_clip_rect.h = h;
- SDL_SetClipRect(surface, &sdl_clip_rect);
-}
-
-static void
-nk_sdl_stroke_line(SDL_Surface *surface, short x0, short y0, short x1,
- short y1, unsigned int line_thickness, struct nk_color col)
-{
- thickLineRGBA(surface, x0, y0, x1, y1, line_thickness, col.r, col.g, col.b, col.a);
-}
-
-static void
-nk_sdl_stroke_rect(SDL_Surface *surface, short x, short y, unsigned short w,
- unsigned short h, unsigned short r, unsigned short line_thickness, struct nk_color col)
-{
- /* Note: thickness is not used by default */
- if (r == 0) {
- rectangleRGBA(surface, x, y, x + w, y + h, col.r, col.g, col.b, col.a);
- } else {
- roundedRectangleRGBA(surface, x, y, x + w, y + h, r, col.r, col.g, col.b, col.a);
- }
-}
-
-static void
-nk_sdl_fill_rect(SDL_Surface *surface, short x, short y, unsigned short w,
- unsigned short h, unsigned short r, struct nk_color col)
-{
- if (r == 0) {
- boxRGBA(surface, x, y, x + w, y + h, col.r, col.g, col.b, col.a);
- } else {
- roundedBoxRGBA(surface, x, y, x + w, y + h, r, col.r, col.g, col.b, col.a);
- }
-}
-
-static void
-nk_sdl_fill_triangle(SDL_Surface *surface, short x0, short y0, short x1, short y1, short x2, short y2, struct nk_color col)
-{
- filledTrigonRGBA(surface, x0, y0, x1, y1, x2, y2, col.r, col.g, col.b, col.a);
-}
-
-static void
-nk_sdl_stroke_triangle(SDL_Surface *surface, short x0, short y0, short x1,
- short y1, short x2, short y2, unsigned short line_thickness, struct nk_color col)
-{
- /* Note: thickness is not used by default */
- aatrigonRGBA(surface, x0, y0, x1, y1, x2, y2, col.r, col.g, col.b, col.a);
-}
-
-static void
-nk_sdl_fill_polygon(SDL_Surface *surface, const struct nk_vec2i *pnts, int count, struct nk_color col)
-{
- Sint16 p_x[NK_SDL_MAX_POINTS];
- Sint16 p_y[NK_SDL_MAX_POINTS];
- int i;
- for (i = 0; (i < count) && (i < NK_SDL_MAX_POINTS); ++i) {
- p_x[i] = pnts[i].x;
- p_y[i] = pnts[i].y;
- }
- filledPolygonRGBA (surface, (Sint16 *)p_x, (Sint16 *)p_y, count, col.r, col.g, col.b, col.a);
-}
-
-static void
-nk_sdl_stroke_polygon(SDL_Surface *surface, const struct nk_vec2i *pnts, int count,
- unsigned short line_thickness, struct nk_color col)
-{
- /* Note: thickness is not used by default */
- Sint16 p_x[NK_SDL_MAX_POINTS];
- Sint16 p_y[NK_SDL_MAX_POINTS];
- int i;
- for (i = 0; (i < count) && (i < NK_SDL_MAX_POINTS); ++i) {
- p_x[i] = pnts[i].x;
- p_y[i] = pnts[i].y;
- }
- aapolygonRGBA(surface, (Sint16 *)p_x, (Sint16 *)p_y, count, col.r, col.g, col.b, col.a);
-}
-
-static void
-nk_sdl_stroke_polyline(SDL_Surface *surface, const struct nk_vec2i *pnts,
- int count, unsigned short line_thickness, struct nk_color col)
-{
- int x0, y0, x1, y1;
- if (count == 1) {
- x0 = pnts[0].x;
- y0 = pnts[0].y;
- x1 = x0;
- y1 = y0;
- thickLineRGBA(surface, x0, y0, x1, y1, line_thickness, col.r, col.g, col.b, col.a);
- } else if (count >= 2) {
- int i;
- for (i = 0; i < (count - 1); i++) {
- x0 = pnts[i].x;
- y0 = pnts[i].y;
- x1 = pnts[i + 1].x;
- y1 = pnts[i + 1].y;
- thickLineRGBA(surface, x0, y0, x1, y1, line_thickness, col.r, col.g, col.b, col.a);
- }
- }
-}
-
-static void
-nk_sdl_fill_circle(SDL_Surface *surface, short x, short y, unsigned short w,
- unsigned short h, struct nk_color col)
-{
- filledEllipseRGBA(surface, x + w /2, y + h /2, w / 2, h / 2, col.r, col.g, col.b, col.a);
-}
-
-static void
-nk_sdl_stroke_circle(SDL_Surface *surface, short x, short y, unsigned short w,
- unsigned short h, unsigned short line_thickness, struct nk_color col)
-{
- /* Note: thickness is not used by default */
- aaellipseRGBA (surface, x + w /2, y + h /2, w / 2, h / 2, col.r, col.g, col.b, col.a);
-}
-
-static void
-nk_sdl_stroke_curve(SDL_Surface *surface, struct nk_vec2i p1,
- struct nk_vec2i p2, struct nk_vec2i p3, struct nk_vec2i p4, unsigned int num_segments,
- unsigned short line_thickness, struct nk_color col)
-{
- unsigned int i_step;
- float t_step;
- struct nk_vec2i last = p1;
-
- num_segments = MAX(num_segments, 1);
- t_step = 1.0f/(float)num_segments;
- for (i_step = 1; i_step <= num_segments; ++i_step) {
- float t = t_step * (float)i_step;
- float u = 1.0f - t;
- float w1 = u*u*u;
- float w2 = 3*u*u*t;
- float w3 = 3*u*t*t;
- float w4 = t * t *t;
- float x = w1 * p1.x + w2 * p2.x + w3 * p3.x + w4 * p4.x;
- float y = w1 * p1.y + w2 * p2.y + w3 * p3.y + w4 * p4.y;
- nk_sdl_stroke_line(surface, last.x, last.y, (short)x, (short)y, line_thickness, col);
- last.x = (short)x; last.y = (short)y;
- }
-}
-
-static void
-nk_sdl_draw_text(SDL_Surface *surface, short x, short y, unsigned short w, unsigned short h,
- const char *text, int len, nk_sdl_Font *font, struct nk_color cbg, struct nk_color cfg)
-{
- int i;
- nk_sdl_fill_rect(surface, x, y, len * font->width, font->height, 0, cbg);
- for (i = 0; i < len; i++) {
- characterRGBA(surface, x, y, text[i], cfg.r, cfg.g, cfg.b, cfg.a);
- x += font->width;
- }
-}
-
-static void
-interpolate_color(struct nk_color c1, struct nk_color c2, struct nk_color *result, float fraction)
-{
- float r = c1.r + (c2.r - c1.r) * fraction;
- float g = c1.g + (c2.g - c1.g) * fraction;
- float b = c1.b + (c2.b - c1.b) * fraction;
- float a = c1.a + (c2.a - c1.a) * fraction;
-
- result->r = (nk_byte)NK_CLAMP(0, r, 255);
- result->g = (nk_byte)NK_CLAMP(0, g, 255);
- result->b = (nk_byte)NK_CLAMP(0, b, 255);
- result->a = (nk_byte)NK_CLAMP(0, a, 255);
-}
-
-static void
-nk_sdl_fill_rect_multi_color(SDL_Surface *surface, short x, short y, unsigned short w, unsigned short h,
- struct nk_color left, struct nk_color top, struct nk_color right, struct nk_color bottom)
-{
- struct nk_color X1, X2, Y;
- float fraction_x, fraction_y;
- int i,j;
-
- for (j = 0; j < h; j++) {
- fraction_y = ((float)j) / h;
- for (i = 0; i < w; i++) {
- fraction_x = ((float)i) / w;
- interpolate_color(left, top, &X1, fraction_x);
- interpolate_color(right, bottom, &X2, fraction_x);
- interpolate_color(X1, X2, &Y, fraction_y);
- pixelRGBA(surface, x + i, y + j, Y.r, Y.g, Y.b, Y.a);
- }
- }
-}
-
-static void
-nk_sdl_clear(SDL_Surface *surface, struct nk_color col)
-{
- nk_sdl_fill_rect(surface, 0, 0, surface->w, surface->h, 0, col);
-}
-
-static void
-nk_sdl_blit(SDL_Surface *surface)
-{
- SDL_UpdateRect(surface, 0, 0, 0, 0);
-}
-
-NK_API void
-nk_sdl_render(struct nk_color clear)
-{
- const struct nk_command *cmd;
-
- SDL_Surface *screen_surface = sdl.screen_surface;
- nk_sdl_clear(screen_surface, clear);
-
- nk_foreach(cmd, &sdl.ctx)
- {
- switch (cmd->type) {
- case NK_COMMAND_NOP: break;
- case NK_COMMAND_SCISSOR: {
- const struct nk_command_scissor *s =(const struct nk_command_scissor*)cmd;
- nk_sdl_scissor(screen_surface, s->x, s->y, s->w, s->h);
- } break;
- case NK_COMMAND_LINE: {
- const struct nk_command_line *l = (const struct nk_command_line *)cmd;
- nk_sdl_stroke_line(screen_surface, l->begin.x, l->begin.y, l->end.x,
- l->end.y, l->line_thickness, l->color);
- } break;
- case NK_COMMAND_RECT: {
- const struct nk_command_rect *r = (const struct nk_command_rect *)cmd;
- nk_sdl_stroke_rect(screen_surface, r->x, r->y, r->w, r->h,
- (unsigned short)r->rounding, r->line_thickness, r->color);
- } break;
- case NK_COMMAND_RECT_FILLED: {
- const struct nk_command_rect_filled *r = (const struct nk_command_rect_filled *)cmd;
- nk_sdl_fill_rect(screen_surface, r->x, r->y, r->w, r->h,
- (unsigned short)r->rounding, r->color);
- } break;
- case NK_COMMAND_CIRCLE: {
- const struct nk_command_circle *c = (const struct nk_command_circle *)cmd;
- nk_sdl_stroke_circle(screen_surface, c->x, c->y, c->w, c->h, c->line_thickness, c->color);
- } break;
- case NK_COMMAND_CIRCLE_FILLED: {
- const struct nk_command_circle_filled *c = (const struct nk_command_circle_filled *)cmd;
- nk_sdl_fill_circle(screen_surface, c->x, c->y, c->w, c->h, c->color);
- } break;
- case NK_COMMAND_TRIANGLE: {
- const struct nk_command_triangle*t = (const struct nk_command_triangle*)cmd;
- nk_sdl_stroke_triangle(screen_surface, t->a.x, t->a.y, t->b.x, t->b.y,
- t->c.x, t->c.y, t->line_thickness, t->color);
- } break;
- case NK_COMMAND_TRIANGLE_FILLED: {
- const struct nk_command_triangle_filled *t = (const struct nk_command_triangle_filled *)cmd;
- nk_sdl_fill_triangle(screen_surface, t->a.x, t->a.y, t->b.x, t->b.y, t->c.x, t->c.y, t->color);
- } break;
- case NK_COMMAND_POLYGON: {
- const struct nk_command_polygon *p =(const struct nk_command_polygon*)cmd;
- nk_sdl_stroke_polygon(screen_surface, p->points, p->point_count, p->line_thickness,p->color);
- } break;
- case NK_COMMAND_POLYGON_FILLED: {
- const struct nk_command_polygon_filled *p = (const struct nk_command_polygon_filled *)cmd;
- nk_sdl_fill_polygon(screen_surface, p->points, p->point_count, p->color);
- } break;
- case NK_COMMAND_POLYLINE: {
- const struct nk_command_polyline *p = (const struct nk_command_polyline *)cmd;
- nk_sdl_stroke_polyline(screen_surface, p->points, p->point_count, p->line_thickness, p->color);
- } break;
- case NK_COMMAND_TEXT: {
- const struct nk_command_text *t = (const struct nk_command_text*)cmd;
- nk_sdl_draw_text(screen_surface, t->x, t->y, t->w, t->h,
- (const char*)t->string, t->length,
- (nk_sdl_Font*)t->font->userdata.ptr,
- t->background, t->foreground);
- } break;
- case NK_COMMAND_CURVE: {
- const struct nk_command_curve *q = (const struct nk_command_curve *)cmd;
- nk_sdl_stroke_curve(screen_surface, q->begin, q->ctrl[0], q->ctrl[1],
- q->end, 22, q->line_thickness, q->color);
- } break;
- case NK_COMMAND_RECT_MULTI_COLOR: {
- const struct nk_command_rect_multi_color *r = (const struct nk_command_rect_multi_color *)cmd;
- nk_sdl_fill_rect_multi_color(screen_surface, r->x, r->y, r->w, r->h, r->left, r->top, r->right, r->bottom);
- } break;
- case NK_COMMAND_IMAGE:
- case NK_COMMAND_ARC:
- case NK_COMMAND_ARC_FILLED:
- default: break;
- }
- }
- nk_sdl_blit(sdl.screen_surface);
- nk_clear(&sdl.ctx);
-
-}
-
-static void
-nk_sdl_clipbard_paste(nk_handle usr, struct nk_text_edit *edit)
-{
- /* Not supported in SDL 1.2. Use platform specific code. */
-}
-
-static void
-nk_sdl_clipbard_copy(nk_handle usr, const char *text, int len)
-{
- /* Not supported in SDL 1.2. Use platform specific code. */
-}
-
-static float
-nk_sdl_get_text_width(nk_handle handle, float height, const char *text, int len)
-{
- return len * sdl_font->width;
-}
-
-NK_API struct nk_context*
-nk_sdl_init(SDL_Surface *screen_surface)
-{
- struct nk_user_font font;
- sdl_font = (nk_sdl_Font*)calloc(1, sizeof(nk_sdl_Font));
- sdl_font->width = 8; /* Default in the SDL_gfx library */
- sdl_font->height = 8; /* Default in the SDL_gfx library */
- if (!sdl_font)
- return NULL;
-
- font.userdata = nk_handle_ptr(sdl_font);
- font.height = (float)sdl_font->height;
- font.width = nk_sdl_get_text_width;
-
- sdl.screen_surface = screen_surface;
- nk_init_default(&sdl.ctx, &font);
- sdl.ctx.clip.copy = nk_sdl_clipbard_copy;
- sdl.ctx.clip.paste = nk_sdl_clipbard_paste;
- sdl.ctx.clip.userdata = nk_handle_ptr(0);
- return &sdl.ctx;
-}
-
-NK_API void
-nk_sdl_handle_event(SDL_Event *evt)
-{
-
- struct nk_context *ctx = &sdl.ctx;
- if (evt->type == SDL_VIDEORESIZE) {
- /* Do nothing */
- } else if (evt->type == SDL_KEYUP || evt->type == SDL_KEYDOWN) {
- /* key events */
- int down = evt->type == SDL_KEYDOWN;
- SDLMod state = SDL_GetModState();
- SDLKey sym = evt->key.keysym.sym;
-
- if (sym == SDLK_RSHIFT || sym == SDLK_LSHIFT) nk_input_key(ctx, NK_KEY_SHIFT, down);
- else if (sym == SDLK_DELETE) nk_input_key(ctx, NK_KEY_DEL, down);
- else if (sym == SDLK_RETURN) nk_input_key(ctx, NK_KEY_ENTER, down);
- else if (sym == SDLK_TAB) nk_input_key(ctx, NK_KEY_TAB, down);
- else if (sym == SDLK_LEFT) nk_input_key(ctx, NK_KEY_LEFT, down);
- else if (sym == SDLK_RIGHT) nk_input_key(ctx, NK_KEY_RIGHT, down);
- else if (sym == SDLK_BACKSPACE) nk_input_key(ctx, NK_KEY_BACKSPACE, down);
- else if (sym == SDLK_HOME) nk_input_key(ctx, NK_KEY_TEXT_START, down);
- else if (sym == SDLK_END) nk_input_key(ctx, NK_KEY_TEXT_END, down);
- else if (sym == SDLK_SPACE && !down) nk_input_char(ctx, ' ');
- else {
- if (sym == SDLK_c && state == SDLK_LCTRL)
- nk_input_key(ctx, NK_KEY_COPY, down);
- else if (sym == SDLK_v && state == SDLK_LCTRL)
- nk_input_key(ctx, NK_KEY_PASTE, down);
- else if (sym == SDLK_x && state == SDLK_LCTRL)
- nk_input_key(ctx, NK_KEY_CUT, down);
- else if (sym == SDLK_z && state == SDLK_LCTRL)
- nk_input_key(ctx, NK_KEY_TEXT_UNDO, down);
- else if (sym == SDLK_r && state == SDLK_LCTRL)
- nk_input_key(ctx, NK_KEY_TEXT_REDO, down);
- else if (sym == SDLK_LEFT && state == SDLK_LCTRL)
- nk_input_key(ctx, NK_KEY_TEXT_WORD_LEFT, down);
- else if (sym == SDLK_RIGHT && state == SDLK_LCTRL)
- nk_input_key(ctx, NK_KEY_TEXT_WORD_RIGHT, down);
- else if (sym == SDLK_b && state == SDLK_LCTRL)
- nk_input_key(ctx, NK_KEY_TEXT_LINE_START, down);
- else if (sym == SDLK_e && state == SDLK_LCTRL)
- nk_input_key(ctx, NK_KEY_TEXT_LINE_END, down);
- else if (!down) {
- /* This demo does not provide full unicode support since the default
- * sdl1.2 font only allows runes in range 0-255. But this demo
- * already is quite limited and not really meant for full blown Apps
- * anyway. So I think ASCII support for Debugging Tools should be enough */
- if (sym >= SDLK_0 && sym <= SDLK_9) {
- nk_rune rune = '0' + sym - SDLK_0;
- nk_input_unicode(ctx, rune);
- } else if (sym >= SDLK_a && sym <= SDLK_z) {
- nk_rune rune = 'a' + sym - SDLK_a;
- rune = ((state == KMOD_LSHIFT) ? (nk_rune)nk_to_upper((int)rune):rune);
- nk_input_unicode(ctx, rune);
- }
- }
- }
- } else if (evt->type == SDL_MOUSEBUTTONDOWN || evt->type == SDL_MOUSEBUTTONUP) {
- /* mouse button */
- int down = evt->type == SDL_MOUSEBUTTONDOWN;
- const int x = evt->button.x, y = evt->button.y;
- if (evt->button.button == SDL_BUTTON_LEFT)
- nk_input_button(ctx, NK_BUTTON_LEFT, x, y, down);
- if (evt->button.button == SDL_BUTTON_MIDDLE)
- nk_input_button(ctx, NK_BUTTON_MIDDLE, x, y, down);
- if (evt->button.button == SDL_BUTTON_RIGHT)
- nk_input_button(ctx, NK_BUTTON_RIGHT, x, y, down);
- if (evt->button.button == SDL_BUTTON_WHEELUP)
- nk_input_scroll(ctx, 1.0f);
- if (evt->button.button == SDL_BUTTON_WHEELDOWN)
- nk_input_scroll(ctx, -1.0f);
- } else if (evt->type == SDL_MOUSEMOTION) {
- nk_input_motion(ctx, evt->motion.x, evt->motion.y);
- }
-}
-
-NK_API void
-nk_sdl_shutdown(void)
-{
- free(sdl_font);
- nk_free(&sdl.ctx);
-}
-
-
-#endif
-
diff --git a/demo/sdl_opengl2/main.c b/demo/sdl_opengl2/main.c
index dfdfe87..0d96551 100644
--- a/demo/sdl_opengl2/main.c
+++ b/demo/sdl_opengl2/main.c
@@ -1,4 +1,4 @@
-/* nuklear - v1.09 - public domain */
+/* nuklear - v1.17 - public domain */
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
@@ -116,8 +116,7 @@ main(int argc, char* argv[])
nk_input_end(ctx);
/* GUI */
- {struct nk_panel layout;
- if (nk_begin(ctx, &layout, "Demo", nk_rect(50, 50, 210, 250),
+ if (nk_begin(ctx, "Demo", nk_rect(50, 50, 210, 250),
NK_WINDOW_BORDER|NK_WINDOW_MOVABLE|NK_WINDOW_SCALABLE|
NK_WINDOW_MINIMIZABLE|NK_WINDOW_TITLE))
{
@@ -134,11 +133,10 @@ main(int argc, char* argv[])
nk_layout_row_dynamic(ctx, 25, 1);
nk_property_int(ctx, "Compression:", 0, &property, 100, 10, 1);
- {struct nk_panel combo;
nk_layout_row_dynamic(ctx, 20, 1);
nk_label(ctx, "background:", NK_TEXT_LEFT);
nk_layout_row_dynamic(ctx, 25, 1);
- if (nk_combo_begin_color(ctx, &combo, background, nk_vec2(nk_widget_width(ctx),400))) {
+ if (nk_combo_begin_color(ctx, background, nk_vec2(nk_widget_width(ctx),400))) {
nk_layout_row_dynamic(ctx, 120, 1);
background = nk_color_picker(ctx, background, NK_RGBA);
nk_layout_row_dynamic(ctx, 25, 1);
@@ -147,9 +145,9 @@ main(int argc, char* argv[])
background.b = (nk_byte)nk_propertyi(ctx, "#B:", 0, background.b, 255, 1,1);
background.a = (nk_byte)nk_propertyi(ctx, "#A:", 0, background.a, 255, 1,1);
nk_combo_end(ctx);
- }}
+ }
}
- nk_end(ctx);}
+ nk_end(ctx);
/* -------------- EXAMPLES ---------------- */
/*calculator(ctx);*/
diff --git a/demo/sdl_opengl2/nuklear_sdl_gl2.h b/demo/sdl_opengl2/nuklear_sdl_gl2.h
index 0068c12..45c5970 100644
--- a/demo/sdl_opengl2/nuklear_sdl_gl2.h
+++ b/demo/sdl_opengl2/nuklear_sdl_gl2.h
@@ -1,5 +1,5 @@
/*
- * Nuklear - v1.00 - public domain
+ * Nuklear - v1.17 - public domain
* no warrenty implied; use at your own risk.
* authored from 2015-2016 by Micha Mettke
*/
@@ -284,6 +284,10 @@ nk_sdl_handle_event(SDL_Event *evt)
nk_input_key(ctx, NK_KEY_TEXT_LINE_START, down && state[SDL_SCANCODE_LCTRL]);
else if (sym == SDLK_e)
nk_input_key(ctx, NK_KEY_TEXT_LINE_END, down && state[SDL_SCANCODE_LCTRL]);
+ else if (sym == SDLK_UP)
+ nk_input_key(ctx, NK_KEY_UP, down);
+ else if (sym == SDLK_DOWN)
+ nk_input_key(ctx, NK_KEY_DOWN, down);
else if (sym == SDLK_LEFT) {
if (state[SDL_SCANCODE_LCTRL])
nk_input_key(ctx, NK_KEY_TEXT_WORD_LEFT, down);
diff --git a/demo/sdl_opengl3/main.c b/demo/sdl_opengl3/main.c
index b686c9a..aee4f82 100644
--- a/demo/sdl_opengl3/main.c
+++ b/demo/sdl_opengl3/main.c
@@ -1,4 +1,4 @@
-/* nuklear - v1.09 - public domain */
+/* nuklear - v1.17 - public domain */
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
@@ -26,8 +26,8 @@
#include "../../nuklear.h"
#include "nuklear_sdl_gl3.h"
-#define WINDOW_WIDTH 1200
-#define WINDOW_HEIGHT 800
+#define WINDOW_WIDTH 800
+#define WINDOW_HEIGHT 600
#define MAX_VERTEX_MEMORY 512 * 1024
#define MAX_ELEMENT_MEMORY 128 * 1024
@@ -123,16 +123,35 @@ main(int argc, char* argv[])
}
nk_input_end(ctx);
+
/* GUI */
- {struct nk_panel layout;
- if (nk_begin(ctx, &layout, "Demo", nk_rect(200, 200, 210, 250),
+ if (nk_begin(ctx, "Demo", nk_rect(50, 50, 200, 200),
NK_WINDOW_BORDER|NK_WINDOW_MOVABLE|NK_WINDOW_SCALABLE|
- NK_WINDOW_MINIMIZABLE|NK_WINDOW_TITLE))
+ NK_WINDOW_CLOSABLE|NK_WINDOW_MINIMIZABLE|NK_WINDOW_TITLE))
{
+ nk_menubar_begin(ctx);
+ nk_layout_row_begin(ctx, NK_STATIC, 25, 2);
+ nk_layout_row_push(ctx, 45);
+ if (nk_menu_begin_label(ctx, "FILE", NK_TEXT_LEFT, nk_vec2(120, 200))) {
+ nk_layout_row_dynamic(ctx, 30, 1);
+ nk_menu_item_label(ctx, "OPEN", NK_TEXT_LEFT);
+ nk_menu_item_label(ctx, "CLOSE", NK_TEXT_LEFT);
+ nk_menu_end(ctx);
+ }
+ nk_layout_row_push(ctx, 45);
+ if (nk_menu_begin_label(ctx, "EDIT", NK_TEXT_LEFT, nk_vec2(120, 200))) {
+ nk_layout_row_dynamic(ctx, 30, 1);
+ nk_menu_item_label(ctx, "COPY", NK_TEXT_LEFT);
+ nk_menu_item_label(ctx, "CUT", NK_TEXT_LEFT);
+ nk_menu_item_label(ctx, "PASTE", NK_TEXT_LEFT);
+ nk_menu_end(ctx);
+ }
+ nk_layout_row_end(ctx);
+ nk_menubar_end(ctx);
+
enum {EASY, HARD};
static int op = EASY;
static int property = 20;
-
nk_layout_row_static(ctx, 30, 80, 1);
if (nk_button_label(ctx, "button"))
fprintf(stdout, "button pressed\n");
@@ -141,23 +160,8 @@ main(int argc, char* argv[])
if (nk_option_label(ctx, "hard", op == HARD)) op = HARD;
nk_layout_row_dynamic(ctx, 25, 1);
nk_property_int(ctx, "Compression:", 0, &property, 100, 10, 1);
-
- {struct nk_panel combo;
- nk_layout_row_dynamic(ctx, 20, 1);
- nk_label(ctx, "background:", NK_TEXT_LEFT);
- nk_layout_row_dynamic(ctx, 25, 1);
- if (nk_combo_begin_color(ctx, &combo, background, nk_vec2(nk_widget_width(ctx),400))) {
- nk_layout_row_dynamic(ctx, 120, 1);
- background = nk_color_picker(ctx, background, NK_RGBA);
- nk_layout_row_dynamic(ctx, 25, 1);
- background.r = (nk_byte)nk_propertyi(ctx, "#R:", 0, background.r, 255, 1,1);
- background.g = (nk_byte)nk_propertyi(ctx, "#G:", 0, background.g, 255, 1,1);
- background.b = (nk_byte)nk_propertyi(ctx, "#B:", 0, background.b, 255, 1,1);
- background.a = (nk_byte)nk_propertyi(ctx, "#A:", 0, background.a, 255, 1,1);
- nk_combo_end(ctx);
- }}
}
- nk_end(ctx);}
+ nk_end(ctx);
/* -------------- EXAMPLES ---------------- */
/*calculator(ctx);*/
diff --git a/demo/sdl_opengl3/nuklear_sdl_gl3.h b/demo/sdl_opengl3/nuklear_sdl_gl3.h
index 4dc7ec9..17c0899 100644
--- a/demo/sdl_opengl3/nuklear_sdl_gl3.h
+++ b/demo/sdl_opengl3/nuklear_sdl_gl3.h
@@ -1,5 +1,5 @@
/*
- * Nuklear - v1.00 - public domain
+ * Nuklear - v1.17 - public domain
* no warrenty implied; use at your own risk.
* authored from 2015-2016 by Micha Mettke
*/
@@ -230,7 +230,7 @@ nk_sdl_render(enum nk_anti_aliasing AA, int max_vertex_buffer, int max_element_b
glBufferData(GL_ARRAY_BUFFER, max_vertex_buffer, NULL, GL_STREAM_DRAW);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, max_element_buffer, NULL, GL_STREAM_DRAW);
- /* load draw vertices & elements directly into vertex + element buffer */
+ /* load vertices/elements directly into vertex/element buffer */
vertices = glMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY);
elements = glMapBuffer(GL_ELEMENT_ARRAY_BUFFER, GL_WRITE_ONLY);
{
@@ -256,8 +256,8 @@ nk_sdl_render(enum nk_anti_aliasing AA, int max_vertex_buffer, int max_element_b
/* setup buffers to load vertices and elements */
{struct nk_buffer vbuf, ebuf;
- nk_buffer_init_fixed(&vbuf, vertices, (size_t)max_vertex_buffer);
- nk_buffer_init_fixed(&ebuf, elements, (size_t)max_element_buffer);
+ nk_buffer_init_fixed(&vbuf, vertices, (nk_size)max_vertex_buffer);
+ nk_buffer_init_fixed(&ebuf, elements, (nk_size)max_element_buffer);
nk_convert(&sdl.ctx, &dev->cmds, &vbuf, &ebuf, &config);}
}
glUnmapBuffer(GL_ARRAY_BUFFER);
@@ -267,12 +267,10 @@ nk_sdl_render(enum nk_anti_aliasing AA, int max_vertex_buffer, int max_element_b
nk_draw_foreach(cmd, &sdl.ctx, &dev->cmds) {
if (!cmd->elem_count) continue;
glBindTexture(GL_TEXTURE_2D, (GLuint)cmd->texture.id);
- glScissor(
- (GLint)(cmd->clip_rect.x * scale.x),
+ glScissor((GLint)(cmd->clip_rect.x * scale.x),
(GLint)((height - (GLint)(cmd->clip_rect.y + cmd->clip_rect.h)) * scale.y),
(GLint)(cmd->clip_rect.w * scale.x),
(GLint)(cmd->clip_rect.h * scale.y));
-
glDrawElements(GL_TRIANGLES, (GLsizei)cmd->elem_count, GL_UNSIGNED_SHORT, offset);
offset += cmd->elem_count;
}
@@ -384,6 +382,10 @@ nk_sdl_handle_event(SDL_Event *evt)
nk_input_key(ctx, NK_KEY_TEXT_LINE_START, down && state[SDL_SCANCODE_LCTRL]);
else if (sym == SDLK_e)
nk_input_key(ctx, NK_KEY_TEXT_LINE_END, down && state[SDL_SCANCODE_LCTRL]);
+ else if (sym == SDLK_UP)
+ nk_input_key(ctx, NK_KEY_UP, down);
+ else if (sym == SDLK_DOWN)
+ nk_input_key(ctx, NK_KEY_DOWN, down);
else if (sym == SDLK_LEFT) {
if (state[SDL_SCANCODE_LCTRL])
nk_input_key(ctx, NK_KEY_TEXT_WORD_LEFT, down);
diff --git a/demo/x11/main.c b/demo/x11/main.c
index 724b05f..8f4b12c 100644
--- a/demo/x11/main.c
+++ b/demo/x11/main.c
@@ -1,4 +1,4 @@
-/* nuklear - v1.09 - public domain */
+/* nuklear - v1.17 - public domain */
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
@@ -91,8 +91,8 @@ sleep_for(long t)
* and the corresponding function. */
/*#include "../style.c"*/
/*#include "../calculator.c"*/
-/*#include "../overview.c"*/
-/*#include "../node_editor.c"*/
+#include "../overview.c"
+#include "../node_editor.c"
/* ===============================================================
*
@@ -155,8 +155,7 @@ main(void)
nk_input_end(ctx);
/* GUI */
- {struct nk_panel layout;
- if (nk_begin(ctx, &layout, "Demo", nk_rect(50, 50, 200, 200),
+ if (nk_begin(ctx, "Demo", nk_rect(50, 50, 200, 200),
NK_WINDOW_BORDER|NK_WINDOW_MOVABLE|NK_WINDOW_SCALABLE|
NK_WINDOW_CLOSABLE|NK_WINDOW_MINIMIZABLE|NK_WINDOW_TITLE))
{
@@ -173,13 +172,13 @@ main(void)
nk_layout_row_dynamic(ctx, 25, 1);
nk_property_int(ctx, "Compression:", 0, &property, 100, 10, 1);
}
- nk_end(ctx);}
+ nk_end(ctx);
if (nk_window_is_closed(ctx, "Demo")) break;
/* -------------- EXAMPLES ---------------- */
/*calculator(ctx);*/
- /*overview(ctx);*/
- /*node_editor(ctx);*/
+ overview(ctx);
+ node_editor(ctx);
/* ----------------------------------------- */
/* Draw */
diff --git a/demo/x11/nuklear_xlib.h b/demo/x11/nuklear_xlib.h
index 67c5344..df66d78 100644
--- a/demo/x11/nuklear_xlib.h
+++ b/demo/x11/nuklear_xlib.h
@@ -1,5 +1,5 @@
/*
- * Nuklear - v1.00 - public domain
+ * Nuklear - v1.17 - public domain
* no warrenty implied; use at your own risk.
* authored from 2015-2016 by Micha Mettke
*/
@@ -138,7 +138,7 @@ nk_xsurf_stroke_rect(XSurface* surf, short x, short y, unsigned short w,
XSetForeground(surf->dpy, surf->gc, c);
XSetLineAttributes(surf->dpy, surf->gc, line_thickness, LineSolid, CapButt, JoinMiter);
if (r == 0) {
- XFillRectangle(surf->dpy, surf->drawable, surf->gc, x, y, w, h);
+ XDrawRectangle(surf->dpy, surf->drawable, surf->gc, x, y, w, h);
} else {
short xc = x + r;
short yc = y + r;
@@ -146,17 +146,17 @@ nk_xsurf_stroke_rect(XSurface* surf, short x, short y, unsigned short w,
short hc = (short)(h - 2 * r);
XDrawLine(surf->dpy, surf->drawable, surf->gc, xc, y, xc+wc, y);
- XDrawLine(surf->dpy, surf->drawable, surf->gc, x+w, yc, x+w, yc+wc);
+ XDrawLine(surf->dpy, surf->drawable, surf->gc, x+w, yc, x+w, yc+hc);
XDrawLine(surf->dpy, surf->drawable, surf->gc, xc, y+h, xc+wc, y+h);
- XDrawLine(surf->dpy, surf->drawable, surf->gc, x, yc, yc+hc, x);
+ XDrawLine(surf->dpy, surf->drawable, surf->gc, x, yc, x, yc+hc);
- XFillArc(surf->dpy, surf->drawable, surf->gc, xc + wc - r, y,
+ XDrawArc(surf->dpy, surf->drawable, surf->gc, xc + wc - r, y,
(unsigned)r*2, (unsigned)r*2, 0 * 64, 90 * 64);
- XFillArc(surf->dpy, surf->drawable, surf->gc, x, y,
+ XDrawArc(surf->dpy, surf->drawable, surf->gc, x, y,
(unsigned)r*2, (unsigned)r*2, 90 * 64, 90 * 64);
- XFillArc(surf->dpy, surf->drawable, surf->gc, x, yc + hc - r,
+ XDrawArc(surf->dpy, surf->drawable, surf->gc, x, yc + hc - r,
(unsigned)r*2, (unsigned)2*r, 180 * 64, 90 * 64);
- XFillArc(surf->dpy, surf->drawable, surf->gc, xc + wc - r, yc + hc - r,
+ XDrawArc(surf->dpy, surf->drawable, surf->gc, xc + wc - r, yc + hc - r,
(unsigned)r*2, (unsigned)2*r, -90 * 64, 90 * 64);
}
XSetLineAttributes(surf->dpy, surf->gc, 1, LineSolid, CapButt, JoinMiter);
diff --git a/demo/x11_opengl2/main.c b/demo/x11_opengl2/main.c
index 2a19d0c..cfe5604 100644
--- a/demo/x11_opengl2/main.c
+++ b/demo/x11_opengl2/main.c
@@ -1,4 +1,4 @@
-/* nuklear - v1.09 - public domain */
+/* nuklear - v1.17 - public domain */
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
@@ -252,8 +252,7 @@ int main(int argc, char **argv)
nk_input_end(ctx);
/* GUI */
- {struct nk_panel layout;
- if (nk_begin(ctx, &layout, "Demo", nk_rect(50, 50, 200, 200),
+ if (nk_begin(ctx, "Demo", nk_rect(50, 50, 200, 200),
NK_WINDOW_BORDER|NK_WINDOW_MOVABLE|NK_WINDOW_SCALABLE|
NK_WINDOW_CLOSABLE|NK_WINDOW_MINIMIZABLE|NK_WINDOW_TITLE))
{
@@ -270,11 +269,10 @@ int main(int argc, char **argv)
nk_layout_row_dynamic(ctx, 25, 1);
nk_property_int(ctx, "Compression:", 0, &property, 100, 10, 1);
- {struct nk_panel combo;
nk_layout_row_dynamic(ctx, 20, 1);
nk_label(ctx, "background:", NK_TEXT_LEFT);
nk_layout_row_dynamic(ctx, 25, 1);
- if (nk_combo_begin_color(ctx, &combo, background, nk_vec2(nk_widget_width(ctx),400))) {
+ if (nk_combo_begin_color(ctx, background, nk_vec2(nk_widget_width(ctx),400))) {
nk_layout_row_dynamic(ctx, 120, 1);
background = nk_color_picker(ctx, background, NK_RGBA);
nk_layout_row_dynamic(ctx, 25, 1);
@@ -283,9 +281,9 @@ int main(int argc, char **argv)
background.b = (nk_byte)nk_propertyi(ctx, "#B:", 0, background.b, 255, 1,1);
background.a = (nk_byte)nk_propertyi(ctx, "#A:", 0, background.a, 255, 1,1);
nk_combo_end(ctx);
- }}
+ }
}
- nk_end(ctx);}
+ nk_end(ctx);
if (nk_window_is_closed(ctx, "Demo")) break;
/* -------------- EXAMPLES ---------------- */
diff --git a/demo/x11_opengl2/nuklear_xlib_gl2.h b/demo/x11_opengl2/nuklear_xlib_gl2.h
index cfa12b7..a814455 100644
--- a/demo/x11_opengl2/nuklear_xlib_gl2.h
+++ b/demo/x11_opengl2/nuklear_xlib_gl2.h
@@ -1,5 +1,5 @@
/*
- * Nuklear - v1.00 - public domain
+ * Nuklear - v1.17 - public domain
* no warrenty implied; use at your own risk.
* authored from 2015-2016 by Micha Mettke
*/
@@ -241,6 +241,8 @@ nk_x11_handle_event(XEvent *evt)
else if (*code == XK_Tab) nk_input_key(ctx, NK_KEY_TAB, down);
else if (*code == XK_Left) nk_input_key(ctx, NK_KEY_LEFT, down);
else if (*code == XK_Right) nk_input_key(ctx, NK_KEY_RIGHT, down);
+ else if (*code == XK_Up) nk_input_key(ctx, NK_KEY_UP, down);
+ else if (*code == XK_Down) nk_input_key(ctx, NK_KEY_DOWN, down);
else if (*code == XK_BackSpace) nk_input_key(ctx, NK_KEY_BACKSPACE, down);
else if (*code == XK_space && !down) nk_input_char(ctx, ' ');
else if (*code == XK_Page_Up) nk_input_key(ctx, NK_KEY_SCROLL_UP, down);
diff --git a/demo/x11_opengl3/main.c b/demo/x11_opengl3/main.c
index 7297b3a..cd026f9 100644
--- a/demo/x11_opengl3/main.c
+++ b/demo/x11_opengl3/main.c
@@ -1,4 +1,4 @@
-/* nuklear - v1.09 - public domain */
+/* nuklear - v1.17 - public domain */
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
@@ -249,8 +249,7 @@ int main(int argc, char **argv)
nk_input_end(ctx);
/* GUI */
- {struct nk_panel layout;
- if (nk_begin(ctx, &layout, "Demo", nk_rect(50, 50, 200, 200),
+ if (nk_begin(ctx, "Demo", nk_rect(50, 50, 200, 200),
NK_WINDOW_BORDER|NK_WINDOW_MOVABLE|NK_WINDOW_SCALABLE|
NK_WINDOW_CLOSABLE|NK_WINDOW_MINIMIZABLE|NK_WINDOW_TITLE))
{
@@ -267,11 +266,10 @@ int main(int argc, char **argv)
nk_layout_row_dynamic(ctx, 25, 1);
nk_property_int(ctx, "Compression:", 0, &property, 100, 10, 1);
- {struct nk_panel combo;
nk_layout_row_dynamic(ctx, 20, 1);
nk_label(ctx, "background:", NK_TEXT_LEFT);
nk_layout_row_dynamic(ctx, 25, 1);
- if (nk_combo_begin_color(ctx, &combo, background, nk_vec2(nk_widget_width(ctx),400))) {
+ if (nk_combo_begin_color(ctx, background, nk_vec2(nk_widget_width(ctx),400))) {
nk_layout_row_dynamic(ctx, 120, 1);
background = nk_color_picker(ctx, background, NK_RGBA);
nk_layout_row_dynamic(ctx, 25, 1);
@@ -280,9 +278,9 @@ int main(int argc, char **argv)
background.b = (nk_byte)nk_propertyi(ctx, "#B:", 0, background.b, 255, 1,1);
background.a = (nk_byte)nk_propertyi(ctx, "#A:", 0, background.a, 255, 1,1);
nk_combo_end(ctx);
- }}
+ }
}
- nk_end(ctx);}
+ nk_end(ctx);
if (nk_window_is_closed(ctx, "Demo")) break;
/* -------------- EXAMPLES ---------------- */
diff --git a/demo/x11_opengl3/nuklear_xlib_gl3.h b/demo/x11_opengl3/nuklear_xlib_gl3.h
index b5bbeef..b0f56b9 100644
--- a/demo/x11_opengl3/nuklear_xlib_gl3.h
+++ b/demo/x11_opengl3/nuklear_xlib_gl3.h
@@ -1,5 +1,5 @@
/*
- * Nuklear - v1.00 - public domain
+ * Nuklear - v1.17 - public domain
* no warrenty implied; use at your own risk.
* authored from 2015-2016 by Micha Mettke
*/
@@ -611,6 +611,8 @@ nk_x11_handle_event(XEvent *evt)
else if (*code == XK_Tab) nk_input_key(ctx, NK_KEY_TAB, down);
else if (*code == XK_Left) nk_input_key(ctx, NK_KEY_LEFT, down);
else if (*code == XK_Right) nk_input_key(ctx, NK_KEY_RIGHT, down);
+ else if (*code == XK_Up) nk_input_key(ctx, NK_KEY_UP, down);
+ else if (*code == XK_Down) nk_input_key(ctx, NK_KEY_DOWN, down);
else if (*code == XK_BackSpace) nk_input_key(ctx, NK_KEY_BACKSPACE, down);
else if (*code == XK_space && !down) nk_input_char(ctx, ' ');
else if (*code == XK_Page_Up) nk_input_key(ctx, NK_KEY_SCROLL_UP, down);
diff --git a/example/canvas.c b/example/canvas.c
index 9957b12..c5f5634 100644
--- a/example/canvas.c
+++ b/example/canvas.c
@@ -348,7 +348,6 @@ pump_input(struct nk_context *ctx, GLFWwindow *win)
}
struct nk_canvas {
- struct nk_panel layout;
struct nk_command_buffer *painter;
struct nk_vec2 item_spacing;
struct nk_vec2 panel_padding;
@@ -371,7 +370,7 @@ canvas_begin(struct nk_context *ctx, struct nk_canvas *canvas, nk_flags flags,
/* create/update window and set position + size */
flags = flags & ~NK_WINDOW_DYNAMIC;
- nk_begin(ctx, &canvas->layout, "Window", nk_rect(x, y, width, height), NK_WINDOW_NO_SCROLLBAR|flags);
+ nk_begin(ctx, "Window", nk_rect(x, y, width, height), NK_WINDOW_NO_SCROLLBAR|flags);
nk_window_set_bounds(ctx, nk_rect(x, y, width, height));
/* allocate the complete window space for drawing */
diff --git a/example/extended.c b/example/extended.c
index 41263e6..e555d65 100644
--- a/example/extended.c
+++ b/example/extended.c
@@ -80,7 +80,6 @@ ui_piemenu(struct nk_context *ctx, struct nk_vec2 pos, float radius,
{
int ret = -1;
struct nk_rect total_space;
- struct nk_panel popup;
struct nk_rect bounds;
int active_item = 0;
@@ -94,7 +93,7 @@ ui_piemenu(struct nk_context *ctx, struct nk_vec2 pos, float radius,
ctx->style.window.spacing = nk_vec2(0,0);
ctx->style.window.padding = nk_vec2(0,0);
- if (nk_popup_begin(ctx, &popup, NK_POPUP_STATIC, "piemenu", NK_WINDOW_NO_SCROLLBAR,
+ if (nk_popup_begin(ctx, NK_POPUP_STATIC, "piemenu", NK_WINDOW_NO_SCROLLBAR,
nk_rect(pos.x - total_space.x - radius, pos.y - radius - total_space.y,
2*radius,2*radius)))
{
@@ -187,12 +186,10 @@ grid_demo(struct nk_context *ctx, struct media *media)
static const char *items[] = {"Item 0","item 1","item 2"};
static int selected_item = 0;
static int check = 1;
- struct nk_panel layout;
int i;
- struct nk_panel combo;
nk_style_set_font(ctx, &media->font_20->handle);
- if (nk_begin(ctx, &layout, "Grid Demo", nk_rect(600, 350, 275, 250),
+ if (nk_begin(ctx, "Grid Demo", nk_rect(600, 350, 275, 250),
NK_WINDOW_TITLE|NK_WINDOW_BORDER|NK_WINDOW_MOVABLE|
NK_WINDOW_NO_SCROLLBAR))
{
@@ -207,7 +204,7 @@ grid_demo(struct nk_context *ctx, struct media *media)
nk_label(ctx, "Checkbox:", NK_TEXT_RIGHT);
nk_checkbox_label(ctx, "Check me", &check);
nk_label(ctx, "Combobox:", NK_TEXT_RIGHT);
- if (nk_combo_begin_label(ctx, &combo, items[selected_item], nk_vec2(nk_widget_width(ctx), 200))) {
+ if (nk_combo_begin_label(ctx, items[selected_item], nk_vec2(nk_widget_width(ctx), 200))) {
nk_layout_row_dynamic(ctx, 25, 1);
for (i = 0; i < 3; ++i)
if (nk_combo_item_label(ctx, items[i], NK_TEXT_LEFT))
@@ -253,15 +250,13 @@ ui_widget_centered(struct nk_context *ctx, struct media *media, float height)
static void
button_demo(struct nk_context *ctx, struct media *media)
{
- struct nk_panel layout;
- struct nk_panel menu;
static int option = 1;
static int toggle0 = 1;
static int toggle1 = 0;
static int toggle2 = 1;
nk_style_set_font(ctx, &media->font_20->handle);
- nk_begin(ctx, &layout, "Button Demo", nk_rect(50,50,255,610),
+ nk_begin(ctx, "Button Demo", nk_rect(50,50,255,610),
NK_WINDOW_BORDER|NK_WINDOW_MOVABLE|NK_WINDOW_TITLE);
/*------------------------------------------------
@@ -271,7 +266,7 @@ button_demo(struct nk_context *ctx, struct media *media)
{
/* toolbar */
nk_layout_row_static(ctx, 40, 40, 4);
- if (nk_menu_begin_image(ctx, &menu, "Music", media->play, nk_vec2(110,120)))
+ if (nk_menu_begin_image(ctx, "Music", media->play, nk_vec2(110,120)))
{
/* settings */
nk_layout_row_dynamic(ctx, 25, 1);
@@ -341,7 +336,7 @@ button_demo(struct nk_context *ctx, struct media *media)
* CONTEXTUAL
*------------------------------------------------*/
nk_style_set_font(ctx, &media->font_18->handle);
- if (nk_contextual_begin(ctx, &menu, NK_WINDOW_NO_SCROLLBAR, nk_vec2(150, 300), nk_window_get_bounds(ctx))) {
+ if (nk_contextual_begin(ctx, NK_WINDOW_NO_SCROLLBAR, nk_vec2(150, 300), nk_window_get_bounds(ctx))) {
nk_layout_row_dynamic(ctx, 30, 1);
if (nk_contextual_item_image_label(ctx, media->copy, "Clone", NK_TEXT_RIGHT))
fprintf(stdout, "pressed clone!\n");
@@ -377,10 +372,8 @@ basic_demo(struct nk_context *ctx, struct media *media)
static struct nk_vec2 piemenu_pos;
int i = 0;
- struct nk_panel layout;
- struct nk_panel combo;
nk_style_set_font(ctx, &media->font_20->handle);
- nk_begin(ctx, &layout, "Basic Demo", nk_rect(320, 50, 275, 610),
+ nk_begin(ctx, "Basic Demo", nk_rect(320, 50, 275, 610),
NK_WINDOW_BORDER|NK_WINDOW_MOVABLE|NK_WINDOW_TITLE);
/*------------------------------------------------
@@ -403,7 +396,7 @@ basic_demo(struct nk_context *ctx, struct media *media)
*------------------------------------------------*/
if (image_active) {
struct nk_panel popup;
- if (nk_popup_begin(ctx, &popup, NK_POPUP_STATIC, "Image Popup", 0, nk_rect(265, 0, 320, 220))) {
+ if (nk_popup_begin(ctx, NK_POPUP_STATIC, "Image Popup", 0, nk_rect(265, 0, 320, 220))) {
nk_layout_row_static(ctx, 82, 82, 3);
for (i = 0; i < 9; ++i) {
if (nk_button_image(ctx, media->images[i])) {
@@ -420,7 +413,7 @@ basic_demo(struct nk_context *ctx, struct media *media)
*------------------------------------------------*/
ui_header(ctx, media, "Combo box");
ui_widget(ctx, media, 40);
- if (nk_combo_begin_label(ctx, &combo, items[selected_item], nk_vec2(nk_widget_width(ctx), 200))) {
+ if (nk_combo_begin_label(ctx, items[selected_item], nk_vec2(nk_widget_width(ctx), 200))) {
nk_layout_row_dynamic(ctx, 35, 1);
for (i = 0; i < 3; ++i)
if (nk_combo_item_label(ctx, items[i], NK_TEXT_LEFT))
@@ -429,7 +422,7 @@ basic_demo(struct nk_context *ctx, struct media *media)
}
ui_widget(ctx, media, 40);
- if (nk_combo_begin_image_label(ctx, &combo, items[selected_icon], media->images[selected_icon], nk_vec2(nk_widget_width(ctx), 200))) {
+ if (nk_combo_begin_image_label(ctx, items[selected_icon], media->images[selected_icon], nk_vec2(nk_widget_width(ctx), 200))) {
nk_layout_row_dynamic(ctx, 35, 1);
for (i = 0; i < 3; ++i)
if (nk_combo_item_image_label(ctx, media->images[i], items[i], NK_TEXT_RIGHT))
@@ -457,7 +450,7 @@ basic_demo(struct nk_context *ctx, struct media *media)
* PIEMENU
*------------------------------------------------*/
if (nk_input_is_mouse_click_down_in_rect(&ctx->input, NK_BUTTON_RIGHT,
- layout.bounds,nk_true)){
+ nk_window_get_bounds(ctx),nk_true)){
piemenu_pos = ctx->input.mouse.pos;
piemenu_active = 1;
}
diff --git a/example/file_browser.c b/example/file_browser.c
index 67ef7f7..ece4cb8 100644
--- a/example/file_browser.c
+++ b/example/file_browser.c
@@ -397,14 +397,12 @@ static int
file_browser_run(struct file_browser *browser, struct nk_context *ctx)
{
int ret = 0;
- struct nk_panel layout;
struct media *media = browser->media;
struct nk_rect total_space;
- if (nk_begin(ctx, &layout, "File Browser", nk_rect(50, 50, 800, 600),
+ if (nk_begin(ctx, "File Browser", nk_rect(50, 50, 800, 600),
NK_WINDOW_BORDER|NK_WINDOW_NO_SCROLLBAR|NK_WINDOW_MOVABLE))
{
- struct nk_panel sub;
static float ratio[] = {0.25f, NK_UNDEFINED};
float spacing_x = ctx->style.window.spacing.x;
@@ -434,7 +432,7 @@ file_browser_run(struct file_browser *browser, struct nk_context *ctx)
/* window layout */
total_space = nk_window_get_content_region(ctx);
nk_layout_row(ctx, NK_DYNAMIC, total_space.h, 2, ratio);
- nk_group_begin(ctx, &sub, "Special", NK_WINDOW_NO_SCROLLBAR);
+ nk_group_begin(ctx, "Special", NK_WINDOW_NO_SCROLLBAR);
{
struct nk_image home = media->icons.home;
struct nk_image desktop = media->icons.desktop;
@@ -451,7 +449,7 @@ file_browser_run(struct file_browser *browser, struct nk_context *ctx)
}
/* output directory content window */
- nk_group_begin(ctx, &sub, "Content", 0);
+ nk_group_begin(ctx, "Content", 0);
{
int index = -1;
size_t i = 0, j = 0, k = 0;
@@ -504,7 +502,6 @@ file_browser_run(struct file_browser *browser, struct nk_context *ctx)
browser->directory[n+1] = '\0';
}
file_browser_reload_directory_content(browser, browser->directory);
- sub.offset->y = 0;
}
nk_group_end(ctx);
}
diff --git a/example/skinning.c b/example/skinning.c
index a1547c5..4634b09 100644
--- a/example/skinning.c
+++ b/example/skinning.c
@@ -735,7 +735,7 @@ int main(int argc, char *argv[])
/* GUI */
{struct nk_panel layout, tab;
- if (nk_begin(&ctx, &layout, "Demo", nk_rect(50, 50, 300, 400),
+ if (nk_begin(&ctx, "Demo", nk_rect(50, 50, 300, 400),
NK_WINDOW_BORDER|NK_WINDOW_MOVABLE|NK_WINDOW_TITLE))
{
int i;
@@ -785,7 +785,7 @@ int main(int argc, char *argv[])
nk_chart_end(&ctx);
nk_layout_row_dynamic(&ctx, 250, 1);
- if (nk_group_begin(&ctx, &tab, "Standard", NK_WINDOW_BORDER|NK_WINDOW_BORDER))
+ if (nk_group_begin(&ctx, "Standard", NK_WINDOW_BORDER|NK_WINDOW_BORDER))
{
if (nk_tree_push(&ctx, NK_TREE_NODE, "Window", NK_MAXIMIZED)) {
static int selected[8];
diff --git a/nuklear.h b/nuklear.h
index 66ac17f..b1f229e 100644
--- a/nuklear.h
+++ b/nuklear.h
@@ -1,5 +1,5 @@
/*
- Nuklear - v1.156 - public domain
+ Nuklear - v1.18 - public domain
no warrenty implied; use at your own risk.
authored from 2015-2016 by Micha Mettke
@@ -70,7 +70,7 @@ FEATURES:
OPTIONAL DEFINES:
NK_PRIVATE
If defined declares all functions as static, so they can only be accessed
- for the file that creates the implementation
+ inside the file that contains the implementation
NK_INCLUDE_FIXED_TYPES
If defined it will include header <stdint.h> for fixed sized types
@@ -186,7 +186,6 @@ OPTIONAL DEFINES:
NK_COS
You can define this to 'cosf' or your own cosine implementation
replacement. If not nuklear will use its own approximation implementation.
- <!> If used it only needs to be define for the implementation not header <!>
<!> If used it is only required to be defined for the implementation part <!>
NK_STRTOD
@@ -271,11 +270,13 @@ extern "C" {
*
* ===============================================================
*/
+#ifndef NK_API
#ifdef NK_PRIVATE
#define NK_API static
#else
#define NK_API extern
#endif
+#endif
#define NK_INTERN static
#define NK_STORAGE static
@@ -306,6 +307,10 @@ extern "C" {
#endif
#endif
+#define NK_MIN(a,b) ((a) < (b) ? (a) : (b))
+#define NK_MAX(a,b) ((a) < (b) ? (b) : (a))
+#define NK_CLAMP(i,v,x) (NK_MAX(NK_MIN(v,x), i))
+
/*
* ===============================================================
*
@@ -426,6 +431,19 @@ struct nk_user_font;
struct nk_panel;
struct nk_context;
struct nk_draw_vertex_layout_element;
+struct nk_style_button;
+struct nk_style_toggle;
+struct nk_style_selectable;
+struct nk_style_slide;
+struct nk_style_progress;
+struct nk_style_scrollbar;
+struct nk_style_edit;
+struct nk_style_property;
+struct nk_style_chart;
+struct nk_style_combo;
+struct nk_style_tab;
+struct nk_style_window_header;
+struct nk_style_window;
enum {nk_false, nk_true};
struct nk_color {nk_byte r,g,b,a;};
@@ -439,8 +457,8 @@ typedef union {void *ptr; int id;} nk_handle;
struct nk_image {nk_handle handle;unsigned short w,h;unsigned short region[4];};
struct nk_cursor {struct nk_image img; struct nk_vec2 size, offset;};
struct nk_scroll {unsigned short x, y;};
-enum nk_heading {NK_UP, NK_RIGHT, NK_DOWN, NK_LEFT};
+enum nk_heading {NK_UP, NK_RIGHT, NK_DOWN, NK_LEFT};
enum nk_button_behavior {NK_BUTTON_DEFAULT, NK_BUTTON_REPEATER};
enum nk_modify {NK_FIXED = nk_false, NK_MODIFIABLE = nk_true};
enum nk_orientation {NK_VERTICAL, NK_HORIZONTAL};
@@ -483,6 +501,16 @@ struct nk_convert_config {
nk_size vertex_alignment; /* vertex alignment: Can be optained by NK_ALIGNOF */
};
+struct nk_list_view {
+/* public: */
+ int begin, end, count;
+/* private: */
+ int total_height;
+ struct nk_context *ctx;
+ nk_ushort *scroll_pointer;
+ nk_ushort scroll_value;
+};
+
enum nk_symbol_type {
NK_SYMBOL_NONE,
NK_SYMBOL_X,
@@ -650,16 +678,15 @@ enum nk_edit_events {
NK_EDIT_DEACTIVATED = NK_FLAG(3), /* edit widget went from state active to state inactive */
NK_EDIT_COMMITED = NK_FLAG(4) /* edit widget has received an enter and lost focus */
};
-
enum nk_panel_flags {
- NK_WINDOW_BORDER = NK_FLAG(0), /* Draws a border around the window to visually separate the window * from the background */
- NK_WINDOW_MOVABLE = NK_FLAG(1), /* The movable flag indicates that a window can be moved by user input or * by dragging the window header */
- NK_WINDOW_SCALABLE = NK_FLAG(2), /* 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_BORDER = NK_FLAG(0), /* Draws a border around the window to visually separate the window from the background */
+ NK_WINDOW_MOVABLE = NK_FLAG(1), /* The movable flag indicates that a window can be moved by user input or by dragging the window header */
+ NK_WINDOW_SCALABLE = NK_FLAG(2), /* 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 = NK_FLAG(3), /* adds a closable icon into the header */
NK_WINDOW_MINIMIZABLE = NK_FLAG(4), /* adds a minimize icon into the header */
NK_WINDOW_NO_SCROLLBAR = NK_FLAG(5), /* Removes the scrollbar from the window */
NK_WINDOW_TITLE = NK_FLAG(6), /* Forces a header at the top at the window showing the title */
- NK_WINDOW_SCROLL_AUTO_HIDE = NK_FLAG(7), /* Automatically hides the window scrollbar if no user interaction */
+ NK_WINDOW_SCROLL_AUTO_HIDE = NK_FLAG(7), /* Automatically hides the window scrollbar if no user interaction: also requires delta time in `nk_context` to be set each frame */
NK_WINDOW_BACKGROUND = NK_FLAG(8) /* Always keep window in the background */
};
@@ -668,8 +695,8 @@ enum nk_panel_flags {
NK_API int nk_init_default(struct nk_context*, const struct nk_user_font*);
#endif
NK_API int nk_init_fixed(struct nk_context*, void *memory, nk_size size, const struct nk_user_font*);
-NK_API int nk_init_custom(struct nk_context*, struct nk_buffer *cmds, struct nk_buffer *pool, const struct nk_user_font*);
NK_API int nk_init(struct nk_context*, struct nk_allocator*, const struct nk_user_font*);
+NK_API int nk_init_custom(struct nk_context*, struct nk_buffer *cmds, struct nk_buffer *pool, const struct nk_user_font*);
NK_API void nk_clear(struct nk_context*);
NK_API void nk_free(struct nk_context*);
#ifdef NK_INCLUDE_COMMAND_USERDATA
@@ -677,8 +704,8 @@ NK_API void nk_set_user_data(struct nk_context*, nk_handle h
#endif
/* window */
-NK_API int nk_begin(struct nk_context*, struct nk_panel*, const char *title, struct nk_rect bounds, nk_flags flags);
-NK_API int nk_begin_titled(struct nk_context*, struct nk_panel*, const char *name, const char *title, struct nk_rect bounds, nk_flags flags);
+NK_API int nk_begin(struct nk_context*, const char *title, struct nk_rect bounds, nk_flags flags);
+NK_API int nk_begin_titled(struct nk_context*, const char *name, const char *title, struct nk_rect bounds, nk_flags flags);
NK_API void nk_end(struct nk_context*);
NK_API struct nk_window* nk_window_find(struct nk_context *ctx, const char *name);
@@ -735,9 +762,15 @@ NK_API struct nk_rect nk_layout_space_rect_to_local(struct nk_context*
NK_API float nk_layout_ratio_from_pixel(struct nk_context*, float pixel_width);
/* Layout: Group */
-NK_API int nk_group_begin(struct nk_context*, struct nk_panel*, const char *title, nk_flags);
+NK_API int nk_group_begin(struct nk_context*, const char *title, nk_flags);
NK_API void nk_group_end(struct nk_context*);
+NK_API int nk_group_scrolled_begin(struct nk_context*, struct nk_scroll*, const char *title, nk_flags);
+NK_API void nk_group_scrolled_end(struct nk_context*);
+
+NK_API int nk_list_view_begin(struct nk_context*, struct nk_list_view *out, const char *id, nk_flags, int row_height, int row_count);
+NK_API void nk_list_view_end(struct nk_list_view*);
+
/* Layout: Tree */
#define nk_tree_push(ctx, type, title, state) nk_tree_push_hashed(ctx, type, title, state, NK_FILE_LINE,nk_strlen(NK_FILE_LINE),__LINE__)
#define nk_tree_push_id(ctx, type, title, state, id) nk_tree_push_hashed(ctx, type, title, state, NK_FILE_LINE,nk_strlen(NK_FILE_LINE),id)
@@ -747,6 +780,10 @@ NK_API int nk_tree_push_hashed(struct nk_context*, enum nk_
NK_API int 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);
NK_API void nk_tree_pop(struct nk_context*);
+NK_API int nk_tree_state_push(struct nk_context*, enum nk_tree_type, const char *title, enum nk_collapse_states *state);
+NK_API int nk_tree_state_image_push(struct nk_context*, enum nk_tree_type, struct nk_image, const char *title, enum nk_collapse_states *state);
+NK_API void nk_tree_state_pop(struct nk_context*);
+
/* Widgets */
NK_API void nk_text(struct nk_context*, const char*, int, nk_flags);
NK_API void nk_text_colored(struct nk_context*, const char*, int, nk_flags, struct nk_color);
@@ -774,6 +811,10 @@ NK_API void nk_value_color_hex(struct nk_context*, const cha
#endif
/* Widgets: Buttons */
+NK_API void nk_button_set_behavior(struct nk_context*, enum nk_button_behavior);
+NK_API int nk_button_push_behavior(struct nk_context*, enum nk_button_behavior);
+NK_API int nk_button_pop_behavior(struct nk_context*);
+
NK_API int nk_button_text(struct nk_context*, const char *title, int len);
NK_API int nk_button_label(struct nk_context*, const char *title);
NK_API int nk_button_color(struct nk_context*, struct nk_color);
@@ -784,9 +825,14 @@ NK_API int nk_button_symbol_text(struct nk_context*, enum n
NK_API int nk_button_image_label(struct nk_context*, struct nk_image img, const char*, nk_flags text_alignment);
NK_API int nk_button_image_text(struct nk_context*, struct nk_image img, const char*, int, nk_flags alignment);
-NK_API void nk_button_set_behavior(struct nk_context*, enum nk_button_behavior);
-NK_API int nk_button_push_behavior(struct nk_context*, enum nk_button_behavior);
-NK_API int nk_button_pop_behavior(struct nk_context*);
+NK_API int nk_button_text_styled(struct nk_context*, const struct nk_style_button*, const char *title, int len);
+NK_API int nk_button_label_styled(struct nk_context*, const struct nk_style_button*, const char *title);
+NK_API int nk_button_symbol_styled(struct nk_context*, const struct nk_style_button*, enum nk_symbol_type);
+NK_API int nk_button_image_styled(struct nk_context*, const struct nk_style_button*, struct nk_image img);
+NK_API int nk_button_symbol_label_styled(struct nk_context*,const struct nk_style_button*, enum nk_symbol_type, const char*, nk_flags text_alignment);
+NK_API int nk_button_symbol_text_styled(struct nk_context*,const struct nk_style_button*, enum nk_symbol_type, const char*, int, nk_flags alignment);
+NK_API int nk_button_image_label_styled(struct nk_context*,const struct nk_style_button*, struct nk_image img, const char*, nk_flags text_alignment);
+NK_API int nk_button_image_text_styled(struct nk_context*,const struct nk_style_button*, struct nk_image img, const char*, int, nk_flags alignment);
/* Widgets: Checkbox */
NK_API int nk_check_label(struct nk_context*, const char*, int active);
@@ -855,7 +901,7 @@ NK_API void nk_plot(struct nk_context*, enum nk_chart_type,
NK_API void nk_plot_function(struct nk_context*, enum nk_chart_type, void *userdata, float(*value_getter)(void* user, int index), int count, int offset);
/* Popups */
-NK_API int nk_popup_begin(struct nk_context*, struct nk_panel*, enum nk_popup_type, const char*, nk_flags, struct nk_rect bounds);
+NK_API int nk_popup_begin(struct nk_context*, enum nk_popup_type, const char*, nk_flags, struct nk_rect bounds);
NK_API void nk_popup_close(struct nk_context*);
NK_API void nk_popup_end(struct nk_context*);
@@ -870,15 +916,15 @@ NK_API void nk_combobox_separator(struct nk_context*, const
NK_API void nk_combobox_callback(struct nk_context*, void(*item_getter)(void*, int, const char**), void*, int *selected, int count, int item_height, struct nk_vec2 size);
/* Combobox: abstract */
-NK_API int nk_combo_begin_text(struct nk_context*, struct nk_panel*, const char *selected, int, struct nk_vec2 size);
-NK_API int nk_combo_begin_label(struct nk_context*, struct nk_panel*, const char *selected, struct nk_vec2 size);
-NK_API int nk_combo_begin_color(struct nk_context*, struct nk_panel*, struct nk_color color, struct nk_vec2 size);
-NK_API int nk_combo_begin_symbol(struct nk_context*, struct nk_panel*, enum nk_symbol_type, struct nk_vec2 size);
-NK_API int nk_combo_begin_symbol_label(struct nk_context*, struct nk_panel*, const char *selected, enum nk_symbol_type, struct nk_vec2 size);
-NK_API int nk_combo_begin_symbol_text(struct nk_context*, struct nk_panel*, const char *selected, int, enum nk_symbol_type, struct nk_vec2 size);
-NK_API int nk_combo_begin_image(struct nk_context*, struct nk_panel*, struct nk_image img, struct nk_vec2 size);
-NK_API int nk_combo_begin_image_label(struct nk_context*, struct nk_panel*, const char *selected, struct nk_image, struct nk_vec2 size);
-NK_API int nk_combo_begin_image_text(struct nk_context*, struct nk_panel*, const char *selected, int, struct nk_image, struct nk_vec2 size);
+NK_API int nk_combo_begin_text(struct nk_context*, const char *selected, int, struct nk_vec2 size);
+NK_API int nk_combo_begin_label(struct nk_context*, const char *selected, struct nk_vec2 size);
+NK_API int nk_combo_begin_color(struct nk_context*, struct nk_color color, struct nk_vec2 size);
+NK_API int nk_combo_begin_symbol(struct nk_context*, enum nk_symbol_type, struct nk_vec2 size);
+NK_API int nk_combo_begin_symbol_label(struct nk_context*, const char *selected, enum nk_symbol_type, struct nk_vec2 size);
+NK_API int nk_combo_begin_symbol_text(struct nk_context*, const char *selected, int, enum nk_symbol_type, struct nk_vec2 size);
+NK_API int nk_combo_begin_image(struct nk_context*, struct nk_image img, struct nk_vec2 size);
+NK_API int nk_combo_begin_image_label(struct nk_context*, const char *selected, struct nk_image, struct nk_vec2 size);
+NK_API int nk_combo_begin_image_text(struct nk_context*, const char *selected, int, struct nk_image, struct nk_vec2 size);
NK_API int nk_combo_item_label(struct nk_context*, const char*, nk_flags alignment);
NK_API int nk_combo_item_text(struct nk_context*, const char*,int, nk_flags alignment);
NK_API int nk_combo_item_image_label(struct nk_context*, struct nk_image, const char*, nk_flags alignment);
@@ -889,7 +935,7 @@ NK_API void nk_combo_close(struct nk_context*);
NK_API void nk_combo_end(struct nk_context*);
/* Contextual */
-NK_API int nk_contextual_begin(struct nk_context*, struct nk_panel*, nk_flags, struct nk_vec2, struct nk_rect trigger_bounds);
+NK_API int nk_contextual_begin(struct nk_context*, nk_flags, struct nk_vec2, struct nk_rect trigger_bounds);
NK_API int nk_contextual_item_text(struct nk_context*, const char*, int,nk_flags align);
NK_API int nk_contextual_item_label(struct nk_context*, const char*, nk_flags align);
NK_API int nk_contextual_item_image_label(struct nk_context*, struct nk_image, const char*, nk_flags alignment);
@@ -901,21 +947,21 @@ NK_API void nk_contextual_end(struct nk_context*);
/* Tooltip */
NK_API void nk_tooltip(struct nk_context*, const char*);
-NK_API int nk_tooltip_begin(struct nk_context*, struct nk_panel*, float width);
+NK_API int nk_tooltip_begin(struct nk_context*, float width);
NK_API void nk_tooltip_end(struct nk_context*);
/* Menu */
NK_API void nk_menubar_begin(struct nk_context*);
NK_API void nk_menubar_end(struct nk_context*);
-NK_API int nk_menu_begin_text(struct nk_context*, struct nk_panel*, const char* title, int title_len, nk_flags align, struct nk_vec2 size);
-NK_API int nk_menu_begin_label(struct nk_context*, struct nk_panel*, const char*, nk_flags align, struct nk_vec2 size);
-NK_API int nk_menu_begin_image(struct nk_context*, struct nk_panel*, const char*, struct nk_image, struct nk_vec2 size);
-NK_API int nk_menu_begin_image_text(struct nk_context*, struct nk_panel*, const char*, int,nk_flags align,struct nk_image, struct nk_vec2 size);
-NK_API int nk_menu_begin_image_label(struct nk_context*, struct nk_panel*, const char*, nk_flags align,struct nk_image, struct nk_vec2 size);
-NK_API int nk_menu_begin_symbol(struct nk_context*, struct nk_panel*, const char*, enum nk_symbol_type, struct nk_vec2 size);
-NK_API int nk_menu_begin_symbol_text(struct nk_context*, struct nk_panel*, const char*, int,nk_flags align,enum nk_symbol_type, struct nk_vec2 size);
-NK_API int nk_menu_begin_symbol_label(struct nk_context*, struct nk_panel*, const char*, nk_flags align,enum nk_symbol_type, struct nk_vec2 size);
+NK_API int nk_menu_begin_text(struct nk_context*, const char* title, int title_len, nk_flags align, struct nk_vec2 size);
+NK_API int nk_menu_begin_label(struct nk_context*, const char*, nk_flags align, struct nk_vec2 size);
+NK_API int nk_menu_begin_image(struct nk_context*, const char*, struct nk_image, struct nk_vec2 size);
+NK_API int nk_menu_begin_image_text(struct nk_context*, const char*, int,nk_flags align,struct nk_image, struct nk_vec2 size);
+NK_API int nk_menu_begin_image_label(struct nk_context*, const char*, nk_flags align,struct nk_image, struct nk_vec2 size);
+NK_API int nk_menu_begin_symbol(struct nk_context*, const char*, enum nk_symbol_type, struct nk_vec2 size);
+NK_API int nk_menu_begin_symbol_text(struct nk_context*, const char*, int,nk_flags align,enum nk_symbol_type, struct nk_vec2 size);
+NK_API int nk_menu_begin_symbol_label(struct nk_context*, const char*, nk_flags align,enum nk_symbol_type, struct nk_vec2 size);
NK_API int nk_menu_item_text(struct nk_context*, const char*, int,nk_flags align);
NK_API int nk_menu_item_label(struct nk_context*, const char*, nk_flags alignment);
NK_API int nk_menu_item_image_label(struct nk_context*, struct nk_image, const char*, nk_flags alignment);
@@ -1086,6 +1132,316 @@ NK_API int nk_utf_encode(nk_rune, char*, int);
NK_API int nk_utf_len(const char*, int byte_len);
NK_API const char* nk_utf_at(const char *buffer, int length, int index, nk_rune *unicode, int *len);
+/* ===============================================================
+ *
+ * FONT
+ *
+ * ===============================================================*/
+/* Font handling in this library was designed to be quite customizable and lets
+ you decide what you want to use and what you want to provide. There are three
+ different ways to use the font atlas. The first two will use your font
+ handling scheme and only requires essential data to run nuklear. The next
+ slightly more advanced features is font handling with vertex buffer output.
+ Finally the most complex API wise is using nuklears font baking API.
+
+ 1.) Using your own implementation without vertex buffer output
+ --------------------------------------------------------------
+ So first up the easiest way to do font handling is by just providing a
+ `nk_user_font` struct which only requires the height in pixel of the used
+ font and a callback to calculate the width of a string. This way of handling
+ fonts is best fitted for using the normal draw shape command API where you
+ do all the text drawing yourself and the library does not require any kind
+ of deeper knowledge about which font handling mechanism you use.
+ IMPORTANT: the `nk_user_font` pointer provided to nuklear has to persist
+ over the complete life time! I know this sucks but it is currently the only
+ way to switch between fonts.
+
+ float your_text_width_calculation(nk_handle handle, float height, const char *text, int len)
+ {
+ your_font_type *type = handle.ptr;
+ float text_width = ...;
+ return text_width;
+ }
+
+ struct nk_user_font font;
+ font.userdata.ptr = &your_font_class_or_struct;
+ font.height = your_font_height;
+ font.width = your_text_width_calculation;
+
+ struct nk_context ctx;
+ nk_init_default(&ctx, &font);
+
+ 2.) Using your own implementation with vertex buffer output
+ --------------------------------------------------------------
+ While the first approach works fine if you don't want to use the optional
+ vertex buffer output it is not enough if you do. To get font handling working
+ for these cases you have to provide two additional parameters inside the
+ `nk_user_font`. First a texture atlas handle used to draw text as subimages
+ of a bigger font atlas texture and a callback to query a character's glyph
+ information (offset, size, ...). So it is still possible to provide your own
+ font and use the vertex buffer output.
+
+ float your_text_width_calculation(nk_handle handle, float height, const char *text, int len)
+ {
+ your_font_type *type = handle.ptr;
+ float text_width = ...;
+ return text_width;
+ }
+ void query_your_font_glyph(nk_handle handle, float font_height, struct nk_user_font_glyph *glyph, nk_rune codepoint, nk_rune next_codepoint)
+ {
+ your_font_type *type = handle.ptr;
+ glyph.width = ...;
+ glyph.height = ...;
+ glyph.xadvance = ...;
+ glyph.uv[0].x = ...;
+ glyph.uv[0].y = ...;
+ glyph.uv[1].x = ...;
+ glyph.uv[1].y = ...;
+ glyph.offset.x = ...;
+ glyph.offset.y = ...;
+ }
+
+ struct nk_user_font font;
+ font.userdata.ptr = &your_font_class_or_struct;
+ font.height = your_font_height;
+ font.width = your_text_width_calculation;
+ font.query = query_your_font_glyph;
+ font.texture.id = your_font_texture;
+
+ struct nk_context ctx;
+ nk_init_default(&ctx, &font);
+
+ 3.) Nuklear font baker
+ ------------------------------------
+ The final approach if you do not have a font handling functionality or don't
+ want to use it in this library is by using the optional font baker.
+ The font baker API's can be used to create a font plus font atlas texture
+ and can be used with or without the vertex buffer output.
+
+ It still uses the `nk_user_font` struct and the two different approaches
+ previously stated still work. The font baker is not located inside
+ `nk_context` like all other systems since it can be understood as more of
+ an extension to nuklear and does not really depend on any `nk_context` state.
+
+ Font baker need to be initialized first by one of the nk_font_atlas_init_xxx
+ functions. If you don't care about memory just call the default version
+ `nk_font_atlas_init_default` which will allocate all memory from the standard library.
+ If you want to control memory allocation but you don't care if the allocated
+ memory is temporary and therefore can be freed directly after the baking process
+ is over or permanent you can call `nk_font_atlas_init`.
+
+ After successfull intializing the font baker you can add Truetype(.ttf) fonts from
+ different sources like memory or from file by calling one of the `nk_font_atlas_add_xxx`.
+ functions. Adding font will permanently store each font, font config and ttf memory block(!)
+ inside the font atlas and allows to reuse the font atlas. If you don't want to reuse
+ the font baker by for example adding additional fonts you can call
+ `nk_font_atlas_cleanup` after the baking process is over (after calling nk_font_atlas_end).
+
+ As soon as you added all fonts you wanted you can now start the baking process
+ for every selected glyphes to image by calling `nk_font_atlas_bake`.
+ The baking process returns image memory, width and height which can be used to
+ either create your own image object or upload it to any graphics library.
+ No matter which case you finally have to call `nk_font_atlas_end` which
+ will free all temporary memory including the font atlas image so make sure
+ you created our texture beforehand. `nk_font_atlas_end` requires a handle
+ to your font texture or object and optionally fills a `struct nk_draw_null_texture`
+ which can be used for the optional vertex output. If you don't want it just
+ set the argument to `NULL`.
+
+ At this point you are done and if you don't want to reuse the font atlas you
+ can call `nk_font_atlas_cleanup` to free all truetype blobs and configuration
+ memory. Finally if you don't use the font atlas and any of it's fonts anymore
+ you need to call `nk_font_atlas_clear` to free all memory still being used.
+
+ struct nk_font_atlas atlas;
+ nk_font_atlas_init_default(&atlas);
+ nk_font_atlas_begin(&atlas);
+ nk_font *font = nk_font_atlas_add_from_file(&atlas, "Path/To/Your/TTF_Font.ttf", 13, 0);
+ nk_font *font2 = nk_font_atlas_add_from_file(&atlas, "Path/To/Your/TTF_Font2.ttf", 16, 0);
+ void* img = nk_font_atlas_bake(&atlas, &img_width, &img_height, NK_FONT_ATLAS_RGBA32, 0);
+ nk_font_atlas_end(&atlas, nk_handle_id(texture), 0);
+
+ struct nk_context ctx;
+ nk_init_default(&ctx, &font->handle);
+ while (1) {
+
+ }
+ nk_font_atlas_clear(&atlas);
+
+ The font baker API is probably the most complex API inside this library and
+ I would suggest reading some of my examples `example/` to get a grip on how
+ to use the font atlas. There are a number of details I left out. For example
+ how to merge fonts, configure a font with `nk_font_config` to use other languages,
+ use another texture coodinate format and a lot more:
+
+ struct nk_font_config cfg = nk_font_config(font_pixel_height);
+ cfg.merge_mode = nk_false or nk_true;
+ cfg.range = nk_font_korean_glyph_ranges();
+ cfg.coord_type = NK_COORD_PIXEL;
+ nk_font *font = nk_font_atlas_add_from_file(&atlas, "Path/To/Your/TTF_Font.ttf", 13, &cfg);
+
+*/
+struct nk_user_font_glyph;
+typedef float(*nk_text_width_f)(nk_handle, float h, const char*, int len);
+typedef void(*nk_query_font_glyph_f)(nk_handle handle, float font_height,
+ struct nk_user_font_glyph *glyph,
+ nk_rune codepoint, nk_rune next_codepoint);
+
+#ifdef NK_INCLUDE_VERTEX_BUFFER_OUTPUT
+struct nk_user_font_glyph {
+ struct nk_vec2 uv[2];
+ /* texture coordinates */
+ struct nk_vec2 offset;
+ /* offset between top left and glyph */
+ float width, height;
+ /* size of the glyph */
+ float xadvance;
+ /* offset to the next glyph */
+};
+#endif
+
+struct nk_user_font {
+ nk_handle userdata;
+ /* user provided font handle */
+ float height;
+ /* max height of the font */
+ nk_text_width_f width;
+ /* font string width in pixel callback */
+#ifdef NK_INCLUDE_VERTEX_BUFFER_OUTPUT
+ nk_query_font_glyph_f query;
+ /* font glyph callback to query drawing info */
+ nk_handle texture;
+ /* texture handle to the used font atlas or texture */
+#endif
+};
+
+#ifdef NK_INCLUDE_FONT_BAKING
+enum nk_font_coord_type {
+ NK_COORD_UV, /* texture coordinates inside font glyphs are clamped between 0-1 */
+ NK_COORD_PIXEL /* texture coordinates inside font glyphs are in absolute pixel */
+};
+
+struct nk_baked_font {
+ float height;
+ /* height of the font */
+ float ascent, descent;
+ /* font glyphs ascent and descent */
+ nk_rune glyph_offset;
+ /* glyph array offset inside the font glyph baking output array */
+ nk_rune glyph_count;
+ /* number of glyphs of this font inside the glyph baking array output */
+ const nk_rune *ranges;
+ /* font codepoint ranges as pairs of (from/to) and 0 as last element */
+};
+
+struct nk_font_config {
+ struct nk_font_config *next;
+ /* NOTE: only used internally */
+ void *ttf_blob;
+ /* pointer to loaded TTF file memory block.
+ * NOTE: not needed for nk_font_atlas_add_from_memory and nk_font_atlas_add_from_file. */
+ nk_size ttf_size;
+ /* size of the loaded TTF file memory block
+ * NOTE: not needed for nk_font_atlas_add_from_memory and nk_font_atlas_add_from_file. */
+
+ unsigned char ttf_data_owned_by_atlas;
+ /* used inside font atlas: default to: 0*/
+ unsigned char merge_mode;
+ /* merges this font into the last font */
+ unsigned char pixel_snap;
+ /* align every character to pixel boundary (if true set oversample (1,1)) */
+ unsigned char oversample_v, oversample_h;
+ /* rasterize at hight quality for sub-pixel position */
+ unsigned char padding[3];
+
+ float size;
+ /* baked pixel height of the font */
+ enum nk_font_coord_type coord_type;
+ /* texture coordinate format with either pixel or UV coordinates */
+ struct nk_vec2 spacing;
+ /* extra pixel spacing between glyphs */
+ const nk_rune *range;
+ /* list of unicode ranges (2 values per range, zero terminated) */
+ struct nk_baked_font *font;
+ /* font to setup in the baking process: NOTE: not needed for font atlas */
+ nk_rune fallback_glyph;
+ /* fallback glyph to use if a given rune is not found */
+};
+
+struct nk_font_glyph {
+ nk_rune codepoint;
+ float xadvance;
+ float x0, y0, x1, y1, w, h;
+ float u0, v0, u1, v1;
+};
+
+struct nk_font {
+ struct nk_font *next;
+ struct nk_user_font handle;
+ struct nk_baked_font info;
+ float scale;
+ struct nk_font_glyph *glyphs;
+ const struct nk_font_glyph *fallback;
+ nk_rune fallback_codepoint;
+ nk_handle texture;
+ struct nk_font_config *config;
+};
+
+enum nk_font_atlas_format {
+ NK_FONT_ATLAS_ALPHA8,
+ NK_FONT_ATLAS_RGBA32
+};
+
+struct nk_font_atlas {
+ void *pixel;
+ int tex_width;
+ int tex_height;
+
+ struct nk_allocator permanent;
+ struct nk_allocator temporary;
+
+ struct nk_recti custom;
+ struct nk_cursor cursors[NK_CURSOR_COUNT];
+
+ int glyph_count;
+ struct nk_font_glyph *glyphs;
+ struct nk_font *default_font;
+ struct nk_font *fonts;
+ struct nk_font_config *config;
+ int font_num;
+};
+
+/* some language glyph codepoint ranges */
+NK_API const nk_rune *nk_font_default_glyph_ranges(void);
+NK_API const nk_rune *nk_font_chinese_glyph_ranges(void);
+NK_API const nk_rune *nk_font_cyrillic_glyph_ranges(void);
+NK_API const nk_rune *nk_font_korean_glyph_ranges(void);
+
+#ifdef NK_INCLUDE_DEFAULT_ALLOCATOR
+NK_API void nk_font_atlas_init_default(struct nk_font_atlas*);
+#endif
+NK_API void nk_font_atlas_init(struct nk_font_atlas*, struct nk_allocator*);
+NK_API void nk_font_atlas_init_custom(struct nk_font_atlas*, struct nk_allocator *persistent, struct nk_allocator *transient);
+NK_API void nk_font_atlas_begin(struct nk_font_atlas*);
+NK_API struct nk_font_config nk_font_config(float pixel_height);
+NK_API struct nk_font *nk_font_atlas_add(struct nk_font_atlas*, const struct nk_font_config*);
+#ifdef NK_INCLUDE_DEFAULT_FONT
+NK_API struct nk_font* nk_font_atlas_add_default(struct nk_font_atlas*, float height, const struct nk_font_config*);
+#endif
+NK_API struct nk_font* nk_font_atlas_add_from_memory(struct nk_font_atlas *atlas, void *memory, nk_size size, float height, const struct nk_font_config *config);
+#ifdef NK_INCLUDE_STANDARD_IO
+NK_API struct nk_font* nk_font_atlas_add_from_file(struct nk_font_atlas *atlas, const char *file_path, float height, const struct nk_font_config*);
+#endif
+NK_API struct nk_font *nk_font_atlas_add_compressed(struct nk_font_atlas*, void *memory, nk_size size, float height, const struct nk_font_config*);
+NK_API struct nk_font* nk_font_atlas_add_compressed_base85(struct nk_font_atlas*, const char *data, float height, const struct nk_font_config *config);
+NK_API const void* nk_font_atlas_bake(struct nk_font_atlas*, int *width, int *height, enum nk_font_atlas_format);
+NK_API void nk_font_atlas_end(struct nk_font_atlas*, nk_handle tex, struct nk_draw_null_texture*);
+NK_API const struct nk_font_glyph* nk_font_find_glyph(struct nk_font*, nk_rune unicode);
+NK_API void nk_font_atlas_cleanup(struct nk_font_atlas *atlas);
+NK_API void nk_font_atlas_clear(struct nk_font_atlas*);
+
+#endif
+
/* ==============================================================
*
* MEMORY BUFFER
@@ -1188,7 +1544,9 @@ NK_API nk_size nk_buffer_total(struct nk_buffer*);
* ===============================================================*/
/* Basic string buffer which is only used in context with the text editor
* to manage and manipulate dynamic or fixed size string content. This is _NOT_
- * the default string handling method.*/
+ * the default string handling method. The only instance you should have any contact
+ * with this API is if you interact with an `nk_text_edit` object inside one of the
+ * copy and paste functions and even there only for more advanced cases. */
struct nk_str {
struct nk_buffer buffer;
int len; /* in codepoints/runes/glyphs */
@@ -1305,6 +1663,18 @@ enum nk_text_edit_mode {
NK_TEXT_EDIT_MODE_REPLACE
};
+struct nk_token {
+ struct nk_color color;
+ int offset;
+};
+
+struct nk_lexer {
+ struct nk_token *tokens;
+ struct nk_token *(*lex)(void *data, const char *buf, int size);
+ void *data;
+ int needs_refresh;
+};
+
struct nk_text_edit {
struct nk_clipboard clip;
struct nk_str string;
@@ -1323,6 +1693,7 @@ struct nk_text_edit {
unsigned char padding1;
float preferred_x;
struct nk_text_undo_state undo;
+ struct nk_lexer lexer;
};
/* filter function */
@@ -1352,207 +1723,6 @@ NK_API void nk_textedit_redo(struct nk_text_edit*);
/* ===============================================================
*
- * FONT
- *
- * ===============================================================*/
-/* Font handling in this library was designed to be quite customizable and lets
- you decide what you want to use and what you want to provide. In this sense
- there are four different degrees between control and ease of use and two
- different drawing APIs to provide for.
-
- So first of the easiest way to do font handling is by just providing a
- `nk_user_font` struct which only requires the height in pixel of the used
- font and a callback to calculate the width of a string. This way of handling
- fonts is best fitted for using the normal draw shape command API were you
- do all the text drawing yourself and the library does not require any kind
- of deeper knowledge about which font handling mechanism you use.
-
- While the first approach works fine if you don't want to use the optional
- vertex buffer output it is not enough if you do. To get font handling working
- for these cases you have to provide two additional parameters inside the
- `nk_user_font`. First a texture atlas handle used to draw text as subimages
- of a bigger font atlas texture and a callback to query a character's glyph
- information (offset, size, ...). So it is still possible to provide your own
- font and use the vertex buffer output.
-
- The final approach if you do not have a font handling functionality or don't
- want to use it in this library is by using the optional font baker. This API
- is divided into a high- and low-level API with different priorities between
- ease of use and control. Both API's can be used to create a font and
- font atlas texture and can even be used with or without the vertex buffer
- output. So it still uses the `nk_user_font` struct and the two different
- approaches previously stated still work.
- Now to the difference between the low level API and the high level API. The low
- level API provides a lot of control over the baking process of the font and
- provides total control over memory. It consists of a number of functions that
- need to be called from begin to end and each step requires some additional
- configuration, so it is a lot more complex than the high-level API.
- If you don't want to do all the work required for using the low-level API
- you can use the font atlas API. It provides the same functionality as the
- low-level API but takes away some configuration and all of memory control and
- in term provides a easier to use API.
-*/
-struct nk_user_font_glyph;
-typedef float(*nk_text_width_f)(nk_handle, float h, const char*, int len);
-typedef void(*nk_query_font_glyph_f)(nk_handle handle, float font_height,
- struct nk_user_font_glyph *glyph,
- nk_rune codepoint, nk_rune next_codepoint);
-
-#ifdef NK_INCLUDE_VERTEX_BUFFER_OUTPUT
-struct nk_user_font_glyph {
- struct nk_vec2 uv[2];
- /* texture coordinates */
- struct nk_vec2 offset;
- /* offset between top left and glyph */
- float width, height;
- /* size of the glyph */
- float xadvance;
- /* offset to the next glyph */
-};
-#endif
-
-struct nk_user_font {
- nk_handle userdata;
- /* user provided font handle */
- float height;
- /* max height of the font */
- nk_text_width_f width;
- /* font string width in pixel callback */
-#ifdef NK_INCLUDE_VERTEX_BUFFER_OUTPUT
- nk_query_font_glyph_f query;
- /* font glyph callback to query drawing info */
- nk_handle texture;
- /* texture handle to the used font atlas or texture */
-#endif
-};
-
-#ifdef NK_INCLUDE_FONT_BAKING
-enum nk_font_coord_type {
- NK_COORD_UV, /* texture coordinates inside font glyphs are clamped between 0-1 */
- NK_COORD_PIXEL /* texture coordinates inside font glyphs are in absolute pixel */
-};
-
-struct nk_baked_font {
- float height;
- /* height of the font */
- float ascent, descent;
- /* font glyphs ascent and descent */
- nk_rune glyph_offset;
- /* glyph array offset inside the font glyph baking output array */
- nk_rune glyph_count;
- /* number of glyphs of this font inside the glyph baking array output */
- const nk_rune *ranges;
- /* font codepoint ranges as pairs of (from/to) and 0 as last element */
-};
-
-struct nk_font_config {
- struct nk_font_config *next;
- /* NOTE: only used internally */
- void *ttf_blob;
- /* pointer to loaded TTF file memory block.
- * NOTE: not needed for nk_font_atlas_add_from_memory and nk_font_atlas_add_from_file. */
- nk_size ttf_size;
- /* size of the loaded TTF file memory block
- * NOTE: not needed for nk_font_atlas_add_from_memory and nk_font_atlas_add_from_file. */
-
- unsigned char ttf_data_owned_by_atlas;
- /* used inside font atlas: default to: 0*/
- unsigned char merge_mode;
- /* merges this font into the last font */
- unsigned char pixel_snap;
- /* align every character to pixel boundary (if true set oversample (1,1)) */
- unsigned char oversample_v, oversample_h;
- /* rasterize at hight quality for sub-pixel position */
- unsigned char padding[3];
-
- float size;
- /* baked pixel height of the font */
- enum nk_font_coord_type coord_type;
- /* texture coordinate format with either pixel or UV coordinates */
- struct nk_vec2 spacing;
- /* extra pixel spacing between glyphs */
- const nk_rune *range;
- /* list of unicode ranges (2 values per range, zero terminated) */
- struct nk_baked_font *font;
- /* font to setup in the baking process: NOTE: not needed for font atlas */
- nk_rune fallback_glyph;
- /* fallback glyph to use if a given rune is not found */
-};
-
-struct nk_font_glyph {
- nk_rune codepoint;
- float xadvance;
- float x0, y0, x1, y1, w, h;
- float u0, v0, u1, v1;
-};
-
-struct nk_font {
- struct nk_font *next;
- struct nk_user_font handle;
- struct nk_baked_font info;
- float scale;
- struct nk_font_glyph *glyphs;
- const struct nk_font_glyph *fallback;
- nk_rune fallback_codepoint;
- nk_handle texture;
- struct nk_font_config *config;
-};
-
-enum nk_font_atlas_format {
- NK_FONT_ATLAS_ALPHA8,
- NK_FONT_ATLAS_RGBA32
-};
-
-struct nk_font_atlas {
- void *pixel;
- int tex_width;
- int tex_height;
-
- struct nk_allocator permanent;
- struct nk_allocator temporary;
- struct nk_recti custom;
- struct nk_cursor cursors[NK_CURSOR_COUNT];
-
- int glyph_count;
- struct nk_font_glyph *glyphs;
- struct nk_font *default_font;
- struct nk_font *fonts;
- struct nk_font_config *config;
- int font_num;
-};
-
-/* some language glyph codepoint ranges */
-NK_API const nk_rune *nk_font_default_glyph_ranges(void);
-NK_API const nk_rune *nk_font_chinese_glyph_ranges(void);
-NK_API const nk_rune *nk_font_cyrillic_glyph_ranges(void);
-NK_API const nk_rune *nk_font_korean_glyph_ranges(void);
-
-#ifdef NK_INCLUDE_DEFAULT_ALLOCATOR
-NK_API void nk_font_atlas_init_default(struct nk_font_atlas*);
-#endif
-NK_API void nk_font_atlas_init(struct nk_font_atlas*, struct nk_allocator*);
-NK_API void nk_font_atlas_init_custom(struct nk_font_atlas*, struct nk_allocator *persistent, struct nk_allocator *transient);
-NK_API void nk_font_atlas_begin(struct nk_font_atlas*);
-NK_API struct nk_font_config nk_font_config(float pixel_height);
-NK_API struct nk_font *nk_font_atlas_add(struct nk_font_atlas*, const struct nk_font_config*);
-#ifdef NK_INCLUDE_DEFAULT_FONT
-NK_API struct nk_font* nk_font_atlas_add_default(struct nk_font_atlas*, float height, const struct nk_font_config*);
-#endif
-NK_API struct nk_font* nk_font_atlas_add_from_memory(struct nk_font_atlas *atlas, void *memory, nk_size size, float height, const struct nk_font_config *config);
-#ifdef NK_INCLUDE_STANDARD_IO
-NK_API struct nk_font* nk_font_atlas_add_from_file(struct nk_font_atlas *atlas, const char *file_path, float height, const struct nk_font_config*);
-#endif
-NK_API struct nk_font *nk_font_atlas_add_compressed(struct nk_font_atlas*, void *memory, nk_size size, float height, const struct nk_font_config*);
-NK_API struct nk_font* nk_font_atlas_add_compressed_base85(struct nk_font_atlas*, const char *data, float height, const struct nk_font_config *config);
-NK_API const void* nk_font_atlas_bake(struct nk_font_atlas*, int *width, int *height, enum nk_font_atlas_format);
-NK_API void nk_font_atlas_end(struct nk_font_atlas*, nk_handle tex, struct nk_draw_null_texture*);
-NK_API void nk_font_atlas_clear(struct nk_font_atlas*);
-NK_API const struct nk_font_glyph* nk_font_find_glyph(struct nk_font*, nk_rune unicode);
-
-#endif
-
-/* ===============================================================
- *
* DRAWING
*
* ===============================================================*/
@@ -1566,11 +1736,39 @@ NK_API const struct nk_font_glyph* nk_font_find_glyph(struct nk_font*, nk_rune u
drawing API and the optional vertex buffer API only takes this format and
converts it into a hardware accessible format.
- Draw commands are divided into filled shapes and shape outlines but only
- filled shapes as well as line, curves and scissor are required to be provided.
- All other shape drawing commands can be used but are not required. This was
- done to allow the maximum number of render backends to be able to use this
- library without you having to do additional work.
+ To use the command queue to draw your own widgets you can access the
+ command buffer of each window by calling `nk_window_get_canvas` after
+ previously having called `nk_begin`:
+
+ void draw_red_rectangle_widget(struct nk_context *ctx)
+ {
+ struct nk_command_buffer *canvas;
+ struct nk_input *input = &ctx->input;
+ canvas = nk_window_get_canvas(ctx);
+
+ struct nk_rect space;
+ enum nk_widget_layout_states state;
+ state = nk_widget(&space, ctx);
+ if (!state) return;
+
+ if (state != NK_WIDGET_ROM)
+ update_your_widget_by_user_input(...);
+ nk_fill_rect(canvas, space, 0, nk_rgb(255,0,0));
+ }
+
+ if (nk_begin(...)) {
+ nk_layout_row_dynamic(ctx, 25, 1);
+ draw_red_rectangle_widget(ctx);
+ }
+ nk_end(..)
+
+ Important to know if you want to create your own widgets is the `nk_widget`
+ call. It allocates space on the panel reserved for this widget to be used,
+ but also returns the state of the widget space. If your widget is not seen and does
+ not have to be updated it is '0' and you can just return. If it only has
+ to be drawn the state will be `NK_WIDGET_ROM` otherwise you can do both
+ update and draw your widget. The reason for seperating is to only draw and
+ update what is actually neccessary which is crucial for performance.
*/
enum nk_command_type {
NK_COMMAND_NOP,
@@ -1792,7 +1990,6 @@ struct nk_mouse_button {
unsigned int clicked;
struct nk_vec2 clicked_pos;
};
-
struct nk_mouse {
struct nk_mouse_button buttons[NK_BUTTON_MAX];
struct nk_vec2 pos;
@@ -1808,7 +2005,6 @@ struct nk_key {
int down;
unsigned int clicked;
};
-
struct nk_keyboard {
struct nk_key keys[NK_KEY_MAX];
char text[NK_INPUT_MAX];
@@ -1836,7 +2032,6 @@ NK_API int nk_input_is_key_pressed(const struct nk_input*, enum nk_keys);
NK_API int nk_input_is_key_released(const struct nk_input*, enum nk_keys);
NK_API int nk_input_is_key_down(const struct nk_input*, enum nk_keys);
-
/* ===============================================================
*
* DRAW LIST
@@ -1918,18 +2113,22 @@ struct nk_draw_command {
};
struct nk_draw_list {
- struct nk_convert_config config;
struct nk_rect clip_rect;
+ struct nk_vec2 circle_vtx[12];
+ struct nk_convert_config config;
+
struct nk_buffer *buffer;
struct nk_buffer *vertices;
struct nk_buffer *elements;
+
unsigned int element_count;
unsigned int vertex_count;
- nk_size cmd_offset;
unsigned int cmd_count;
+ nk_size cmd_offset;
+
unsigned int path_count;
unsigned int path_offset;
- struct nk_vec2 circle_vtx[12];
+
#ifdef NK_INCLUDE_COMMAND_USERDATA
nk_handle userdata;
#endif
@@ -1937,7 +2136,7 @@ struct nk_draw_list {
/* draw list */
NK_API void nk_draw_list_init(struct nk_draw_list*);
-NK_API void nk_draw_list_setup(struct nk_draw_list *canvas, const struct nk_convert_config *config, struct nk_buffer *cmds, struct nk_buffer *vertices, struct nk_buffer *elements);
+NK_API void nk_draw_list_setup(struct nk_draw_list*, const struct nk_convert_config*, struct nk_buffer *cmds, struct nk_buffer *vertices, struct nk_buffer *elements);
NK_API void nk_draw_list_clear(struct nk_draw_list*);
/* drawing */
@@ -1949,7 +2148,7 @@ NK_API void nk_draw_list_clear(struct nk_draw_list *list);
/* path */
NK_API void nk_draw_list_path_clear(struct nk_draw_list*);
-NK_API void nk_draw_list_path_line_to(struct nk_draw_list *list, struct nk_vec2 pos);
+NK_API void nk_draw_list_path_line_to(struct nk_draw_list*, struct nk_vec2 pos);
NK_API void nk_draw_list_path_arc_to_fast(struct nk_draw_list*, struct nk_vec2 center, float radius, int a_min, int a_max);
NK_API void nk_draw_list_path_arc_to(struct nk_draw_list*, struct nk_vec2 center, float radius, float a_min, float a_max, unsigned int segments);
NK_API void nk_draw_list_path_rect_to(struct nk_draw_list*, struct nk_vec2 a, struct nk_vec2 b, float rounding);
@@ -1967,7 +2166,7 @@ NK_API void nk_draw_list_stroke_poly_line(struct nk_draw_list*, const struct nk_
/* fill */
NK_API void nk_draw_list_fill_rect(struct nk_draw_list*, struct nk_rect rect, struct nk_color, float rounding);
-NK_API void nk_draw_list_fill_rect_multi_color(struct nk_draw_list *list, struct nk_rect rect, struct nk_color left, struct nk_color top, struct nk_color right, struct nk_color bottom);
+NK_API void nk_draw_list_fill_rect_multi_color(struct nk_draw_list*, struct nk_rect rect, struct nk_color left, struct nk_color top, struct nk_color right, struct nk_color bottom);
NK_API void nk_draw_list_fill_triangle(struct nk_draw_list*, struct nk_vec2 a, struct nk_vec2 b, struct nk_vec2 c, struct nk_color);
NK_API void nk_draw_list_fill_circle(struct nk_draw_list*, struct nk_vec2 center, float radius, struct nk_color col, unsigned int segs);
NK_API void nk_draw_list_fill_poly_convex(struct nk_draw_list*, const struct nk_vec2 *points, const unsigned int count, struct nk_color, enum nk_anti_aliasing);
@@ -2331,7 +2530,6 @@ enum nk_style_header_align {
NK_HEADER_LEFT,
NK_HEADER_RIGHT
};
-
struct nk_style_window_header {
/* background */
struct nk_style_item normal;
@@ -2456,9 +2654,9 @@ struct nk_chart_slot {
};
struct nk_chart {
- struct nk_chart_slot slots[NK_CHART_MAX_SLOT];
int slot;
float x, y, w, h;
+ struct nk_chart_slot slots[NK_CHART_MAX_SLOT];
};
struct nk_row_layout {
@@ -2467,7 +2665,8 @@ struct nk_row_layout {
float height;
int columns;
const float *ratio;
- float item_width, item_height;
+ float item_width;
+ float item_height;
float item_offset;
float filled;
struct nk_rect item;
@@ -2570,6 +2769,7 @@ struct nk_window {
nk_hash name;
char name_string[NK_WINDOW_MAX_NAME];
nk_flags flags;
+
struct nk_rect bounds;
struct nk_scroll scrollbar;
struct nk_command_buffer buffer;
@@ -2595,6 +2795,28 @@ struct nk_window {
/*==============================================================
* STACK
* =============================================================*/
+/* The style modifier stack can be used to temporarily change a
+ * property inside `nk_style`. For example if you want a special
+ * red button you can temporarily push the old button color onto a stack
+ * draw the button with a red color and then you just pop the old color
+ * back from the stack:
+ *
+ * nk_style_push_style_item(ctx, &ctx->style.button.normal, nk_style_item_color(nk_rgb(255,0,0)));
+ * nk_style_push_style_item(ctx, &ctx->style.button.hover, nk_style_item_color(nk_rgb(255,0,0)));
+ * nk_style_push_style_item(ctx, &ctx->style.button.active, nk_style_item_color(nk_rgb(255,0,0)));
+ * nk_style_push_vec2(ctx, &cx->style.button.padding, nk_vec2(2,2));
+ *
+ * nk_button(...);
+ *
+ * nk_style_pop_style_item(ctx);
+ * nk_style_pop_style_item(ctx);
+ * nk_style_pop_style_item(ctx);
+ * nk_style_pop_vec2(ctx);
+ *
+ * Nuklear has a stack for style_items, float properties, vector properties,
+ * flags, colors, fonts and for button_behavior. Each has it's own fixed size stack
+ * which can be changed at compile time.
+ */
#ifndef NK_BUTTON_BEHAVIOR_STACK_SIZE
#define NK_BUTTON_BEHAVIOR_STACK_SIZE 8
#endif
@@ -2664,7 +2886,8 @@ struct nk_configuration_stacks {
/*==============================================================
* CONTEXT
* =============================================================*/
-#define NK_VALUE_PAGE_CAPACITY ((sizeof(struct nk_window) / sizeof(nk_uint)) / 2)
+#define NK_VALUE_PAGE_CAPACITY \
+ ((NK_MAX(sizeof(struct nk_window),sizeof(struct nk_panel)) / sizeof(nk_uint)) / 2)
struct nk_table {
unsigned int seq;
@@ -2675,6 +2898,7 @@ struct nk_table {
union nk_page_data {
struct nk_table tbl;
+ struct nk_panel pan;
struct nk_window win;
};
@@ -2685,7 +2909,7 @@ struct nk_page_element {
};
struct nk_page {
- unsigned size;
+ unsigned int size;
struct nk_page *next;
struct nk_page_element win[1];
};
@@ -2708,9 +2932,9 @@ struct nk_context {
struct nk_buffer memory;
struct nk_clipboard clip;
nk_flags last_widget_state;
- float delta_time_seconds;
enum nk_button_behavior button_behavior;
struct nk_configuration_stacks stacks;
+ float delta_time_seconds;
/* private:
should only be accessed if you
@@ -2722,7 +2946,7 @@ struct nk_context {
nk_handle userdata;
#endif
/* text editor objects are quite big because of an internal
- * undo/redo stack. Therefore does not make sense to have one for
+ * undo/redo stack. Therefore it does not make sense to have one for
* each window for temporary use cases, so I only provide *one* instance
* for all windows. This works because the content is cleared anyway */
struct nk_text_edit text_edit;
@@ -2745,10 +2969,6 @@ struct nk_context {
/* ==============================================================
* MATH
* =============================================================== */
-#define NK_MIN(a,b) ((a) < (b) ? (a) : (b))
-#define NK_MAX(a,b) ((a) < (b) ? (b) : (a))
-#define NK_CLAMP(i,v,x) (NK_MAX(NK_MIN(v,x), i))
-
#define NK_PI 3.141592654f
#define NK_UTF_INVALID 0xFFFD
#define NK_MAX_FLOAT_PRECISION 2
@@ -3035,8 +3255,8 @@ NK_API struct nk_rect
nk_rect(float x, float y, float w, float h)
{
struct nk_rect r;
- r.x = x, r.y = y;
- r.w = w, r.h = h;
+ r.x = x; r.y = y;
+ r.w = w; r.h = h;
return r;
}
@@ -3804,6 +4024,7 @@ nk_vsnprintf(char *buf, int buf_size, const char *fmt, va_list args)
NK_ARG_FLAG_NUM = 0x10,
NK_ARG_FLAG_ZERO = 0x20
};
+
char number_buffer[NK_MAX_NUMBER_BUFFER];
enum nk_arg_type arg_type = NK_ARG_TYPE_DEFAULT;
int precision = NK_DEFAULT;
@@ -4283,14 +4504,14 @@ NK_API void
nk_color_hex_rgba(char *output, struct nk_color col)
{
#define NK_TO_HEX(i) ((i) <= 9 ? '0' + (i): 'A' - 10 + (i))
- output[0] = (char)NK_TO_HEX((col.r & 0x0F));
- output[1] = (char)NK_TO_HEX((col.r & 0xF0) >> 4);
- output[2] = (char)NK_TO_HEX((col.g & 0x0F));
- output[3] = (char)NK_TO_HEX((col.g & 0xF0) >> 4);
- output[4] = (char)NK_TO_HEX((col.b & 0x0F));
- output[5] = (char)NK_TO_HEX((col.b & 0xF0) >> 4);
- output[6] = (char)NK_TO_HEX((col.a & 0x0F));
- output[7] = (char)NK_TO_HEX((col.a & 0xF0) >> 4);
+ output[0] = (char)NK_TO_HEX((col.r & 0xF0) >> 4);
+ output[1] = (char)NK_TO_HEX((col.r & 0x0F));
+ output[2] = (char)NK_TO_HEX((col.g & 0xF0) >> 4);
+ output[3] = (char)NK_TO_HEX((col.g & 0x0F));
+ output[4] = (char)NK_TO_HEX((col.b & 0xF0) >> 4);
+ output[5] = (char)NK_TO_HEX((col.b & 0x0F));
+ output[6] = (char)NK_TO_HEX((col.a & 0xF0) >> 4);
+ output[7] = (char)NK_TO_HEX((col.a & 0x0F));
output[8] = '\0';
#undef NK_TO_HEX
}
@@ -4299,12 +4520,12 @@ NK_API void
nk_color_hex_rgb(char *output, struct nk_color col)
{
#define NK_TO_HEX(i) ((i) <= 9 ? '0' + (i): 'A' - 10 + (i))
- output[0] = (char)NK_TO_HEX((col.r & 0x0F));
- output[1] = (char)NK_TO_HEX((col.r & 0xF0) >> 4);
- output[2] = (char)NK_TO_HEX((col.g & 0x0F));
- output[3] = (char)NK_TO_HEX((col.g & 0xF0) >> 4);
- output[4] = (char)NK_TO_HEX((col.b & 0x0F));
- output[5] = (char)NK_TO_HEX((col.b & 0xF0) >> 4);
+ output[0] = (char)NK_TO_HEX((col.r & 0xF0) >> 4);
+ output[1] = (char)NK_TO_HEX((col.r & 0x0F));
+ output[2] = (char)NK_TO_HEX((col.g & 0xF0) >> 4);
+ output[3] = (char)NK_TO_HEX((col.g & 0x0F));
+ output[4] = (char)NK_TO_HEX((col.b & 0xF0) >> 4);
+ output[5] = (char)NK_TO_HEX((col.b & 0x0F));
output[6] = '\0';
#undef NK_TO_HEX
}
@@ -4461,11 +4682,12 @@ nk_hsva_f(float h, float s, float v, float a)
t = v * (1.0f - s * (1.0f - f));
switch (i) {
- case 0: out.r = v; out.g = t; out.b = p; break;
+ case 0: default: out.r = v; out.g = t; out.b = p; break;
case 1: out.r = q; out.g = v; out.b = p; break;
case 2: out.r = p; out.g = v; out.b = t; break;
+ case 3: out.r = p; out.g = q; out.b = v; break;
case 4: out.r = t; out.g = p; out.b = v; break;
- case 5: default: out.r = v; out.g = p; out.b = q; break;
+ case 5: out.r = v; out.g = p; out.b = q; break;
}
return nk_rgba_f(out.r, out.g, out.b, a);
}
@@ -4804,30 +5026,51 @@ nk_triangle_from_direction(struct nk_vec2 *result, struct nk_rect r,
NK_INTERN int
nk_text_clamp(const struct nk_user_font *font, const char *text,
- int text_len, float space, int *glyphs, float *text_width)
+ int text_len, float space, int *glyphs, float *text_width,
+ nk_rune *sep_list, int sep_count)
{
+ int i = 0;
int glyph_len = 0;
float last_width = 0;
nk_rune unicode = 0;
float width = 0;
int len = 0;
int g = 0;
+ float s;
+
+ int sep_len = 0;
+ int sep_g = 0;
+ float sep_width = 0;
+ sep_count = NK_MAX(sep_count,0);
glyph_len = nk_utf_decode(text, &unicode, text_len);
while (glyph_len && (width < space) && (len < text_len)) {
- float s;
len += glyph_len;
s = font->width(font->userdata, font->height, text, len);
-
- last_width = width;
+ for (i = 0; i < sep_count; ++i) {
+ if (unicode != sep_list[i]) continue;
+ sep_width = last_width = width;
+ sep_g = g+1;
+ sep_len = len;
+ break;
+ }
+ if (i == NK_MAX(sep_count,0)){
+ last_width = sep_width = width;
+ sep_g = g+1;
+ }
width = s;
glyph_len = nk_utf_decode(&text[len], &unicode, text_len - len);
g++;
}
-
- *glyphs = g;
- *text_width = last_width;
- return len;
+ if (len >= text_len) {
+ *glyphs = g;
+ *text_width = last_width;
+ return len;
+ } else {
+ *glyphs = sep_g;
+ *text_width = sep_width;
+ return (!sep_len) ? len: sep_len;
+ }
}
enum {NK_DO_NOT_STOP_ON_NEW_LINE, NK_STOP_ON_NEW_LINE};
@@ -5845,7 +6088,6 @@ nk_command_buffer_push(struct nk_command_buffer* b,
NK_ASSERT(b);
NK_ASSERT(b->base);
if (!b) return 0;
-
cmd = (struct nk_command*)nk_buffer_alloc(b->base,NK_BUFFER_FRONT,size,align);
if (!cmd) return 0;
@@ -5854,7 +6096,6 @@ nk_command_buffer_push(struct nk_command_buffer* b,
unaligned = (nk_byte*)cmd + size;
memory = NK_ALIGN_PTR(unaligned, align);
alignment = (nk_size)((nk_byte*)memory - (nk_byte*)unaligned);
-
#ifdef NK_ZERO_COMMAND_MEMORY
NK_MEMSET(cmd, 0, size + alignment);
#endif
@@ -6256,7 +6497,7 @@ nk_draw_text(struct nk_command_buffer *b, struct nk_rect r,
if (text_width > r.w){
int glyphs = 0;
float txt_width = (float)text_width;
- length = nk_text_clamp(font, string, length, r.w, &glyphs, &txt_width);
+ length = nk_text_clamp(font, string, length, r.w, &glyphs, &txt_width, 0,0);
}
if (!length) return;
@@ -6286,6 +6527,8 @@ NK_API void
nk_draw_list_init(struct nk_draw_list *list)
{
nk_size i = 0;
+ NK_ASSERT(list);
+ if (!list) return;
nk_zero(list, sizeof(*list));
for (i = 0; i < NK_LEN(list->circle_vtx); ++i) {
const float a = ((float)i / (float)NK_LEN(list->circle_vtx)) * 2 * NK_PI;
@@ -6298,6 +6541,14 @@ NK_API void
nk_draw_list_setup(struct nk_draw_list *canvas, const struct nk_convert_config *config,
struct nk_buffer *cmds, struct nk_buffer *vertices, struct nk_buffer *elements)
{
+ NK_ASSERT(canvas);
+ NK_ASSERT(config);
+ NK_ASSERT(cmds);
+ NK_ASSERT(vertices);
+ NK_ASSERT(elements);
+ if (!canvas || !config || !cmds || !vertices || !elements)
+ return;
+
canvas->buffer = cmds;
canvas->config = *config;
canvas->elements = elements;
@@ -6466,9 +6717,9 @@ nk_draw_list_add_clip(struct nk_draw_list *list, struct nk_rect rect)
nk_draw_list_push_command(list, rect, list->config.null.texture);
} else {
struct nk_draw_command *prev = nk_draw_list_command_last(list);
- if (prev->elem_count == 0) {
+ if (prev->elem_count == 0)
prev->clip_rect = rect;
- } else nk_draw_list_push_command(list, rect, prev->texture);
+ nk_draw_list_push_command(list, rect, prev->texture);
}
}
@@ -8820,11 +9071,11 @@ nk_tt__fill_active_edges_new(float *scanline, float *scanline_fill, int len,
float t;
y0 = y_bottom - (y0 - y_top);
y1 = y_bottom - (y1 - y_top);
- t = y0, y0 = y1, y1 = t;
- t = x_bottom, x_bottom = x_top, x_top = t;
+ t = y0; y0 = y1; y1 = t;
+ t = x_bottom; x_bottom = x_top; x_top = t;
dx = -dx;
dy = -dy;
- t = x0, x0 = xb, xb = t;
+ t = x0; x0 = xb; xb = t;
}
x1 = (int) x_top;
@@ -9762,6 +10013,7 @@ nk_font_baker_memory(nk_size *temp, int *glyph_count,
int range_count = 0;
int total_range_count = 0;
struct nk_font_config *iter;
+
NK_ASSERT(config_list);
NK_ASSERT(glyph_count);
if (!config_list) {
@@ -10149,8 +10401,11 @@ nk_font_find_glyph(struct nk_font *font, nk_rune unicode)
int count;
int total_glyphs = 0;
const struct nk_font_glyph *glyph = 0;
+
NK_ASSERT(font);
NK_ASSERT(font->glyphs);
+ NK_ASSERT(font->info.ranges);
+ if (!font || !font->glyphs) return 0;
glyph = font->fallback;
count = nk_range_count(font->info.ranges);
@@ -10407,22 +10662,21 @@ nk_adler32(unsigned int adler32, unsigned char *buffer, unsigned int buflen)
blocklen = buflen % 5552;
while (buflen) {
for (i=0; i + 7 < blocklen; i += 8) {
- s1 += buffer[0], s2 += s1;
- s1 += buffer[1], s2 += s1;
- s1 += buffer[2], s2 += s1;
- s1 += buffer[3], s2 += s1;
- s1 += buffer[4], s2 += s1;
- s1 += buffer[5], s2 += s1;
- s1 += buffer[6], s2 += s1;
- s1 += buffer[7], s2 += s1;
-
+ s1 += buffer[0]; s2 += s1;
+ s1 += buffer[1]; s2 += s1;
+ s1 += buffer[2]; s2 += s1;
+ s1 += buffer[3]; s2 += s1;
+ s1 += buffer[4]; s2 += s1;
+ s1 += buffer[5]; s2 += s1;
+ s1 += buffer[6]; s2 += s1;
+ s1 += buffer[7]; s2 += s1;
buffer += 8;
}
+ for (; i < blocklen; ++i) {
+ s1 += *buffer++; s2 += s1;
+ }
- for (; i < blocklen; ++i)
- s1 += *buffer++, s2 += s1;
-
- s1 %= ADLER_MOD, s2 %= ADLER_MOD;
+ s1 %= ADLER_MOD; s2 %= ADLER_MOD;
buflen -= (unsigned int)blocklen;
blocklen = 5552;
}
@@ -10582,14 +10836,16 @@ nk_font_atlas_add(struct nk_font_atlas *atlas, const struct nk_font_config *conf
struct nk_font_config *cfg;
NK_ASSERT(atlas);
- NK_ASSERT(config);
NK_ASSERT(atlas->permanent.alloc);
NK_ASSERT(atlas->permanent.free);
NK_ASSERT(atlas->temporary.alloc);
NK_ASSERT(atlas->temporary.free);
+
+ NK_ASSERT(config);
NK_ASSERT(config->ttf_blob);
NK_ASSERT(config->ttf_size);
NK_ASSERT(config->size > 0.0f);
+
if (!atlas || !config || !config->ttf_blob || !config->ttf_size || config->size <= 0.0f||
!atlas->permanent.alloc || !atlas->permanent.free ||
!atlas->temporary.alloc || !atlas->temporary.free)
@@ -10654,6 +10910,7 @@ nk_font_atlas_add_from_memory(struct nk_font_atlas *atlas, void *memory,
struct nk_font_config cfg;
NK_ASSERT(memory);
NK_ASSERT(size);
+
NK_ASSERT(atlas);
NK_ASSERT(atlas->temporary.alloc);
NK_ASSERT(atlas->temporary.free);
@@ -10685,6 +10942,7 @@ nk_font_atlas_add_from_file(struct nk_font_atlas *atlas, const char *file_path,
NK_ASSERT(atlas->temporary.free);
NK_ASSERT(atlas->permanent.alloc);
NK_ASSERT(atlas->permanent.free);
+
if (!atlas || !file_path) return 0;
memory = nk_file_load(file_path, &size, &atlas->permanent);
if (!memory) return 0;
@@ -10707,13 +10965,14 @@ nk_font_atlas_add_compressed(struct nk_font_atlas *atlas,
void *decompressed_data;
struct nk_font_config cfg;
- NK_ASSERT(compressed_data);
- NK_ASSERT(compressed_size);
NK_ASSERT(atlas);
NK_ASSERT(atlas->temporary.alloc);
NK_ASSERT(atlas->temporary.free);
NK_ASSERT(atlas->permanent.alloc);
NK_ASSERT(atlas->permanent.free);
+
+ NK_ASSERT(compressed_data);
+ NK_ASSERT(compressed_size);
if (!atlas || !compressed_data || !atlas->temporary.alloc || !atlas->temporary.free ||
!atlas->permanent.alloc || !atlas->permanent.free)
return 0;
@@ -10741,12 +11000,13 @@ nk_font_atlas_add_compressed_base85(struct nk_font_atlas *atlas,
void *compressed_data;
struct nk_font *font;
- NK_ASSERT(data_base85);
NK_ASSERT(atlas);
NK_ASSERT(atlas->temporary.alloc);
NK_ASSERT(atlas->temporary.free);
NK_ASSERT(atlas->permanent.alloc);
NK_ASSERT(atlas->permanent.free);
+
+ NK_ASSERT(data_base85);
if (!atlas || !data_base85 || !atlas->temporary.alloc || !atlas->temporary.free ||
!atlas->permanent.alloc || !atlas->permanent.free)
return 0;
@@ -10787,13 +11047,14 @@ nk_font_atlas_bake(struct nk_font_atlas *atlas, int *width, int *height,
struct nk_font *font_iter;
struct nk_font_baker *baker;
- NK_ASSERT(width);
- NK_ASSERT(height);
NK_ASSERT(atlas);
NK_ASSERT(atlas->temporary.alloc);
NK_ASSERT(atlas->temporary.free);
NK_ASSERT(atlas->permanent.alloc);
NK_ASSERT(atlas->permanent.free);
+
+ NK_ASSERT(width);
+ NK_ASSERT(height);
if (!atlas || !width || !height ||
!atlas->temporary.alloc || !atlas->temporary.free ||
!atlas->permanent.alloc || !atlas->permanent.free)
@@ -10840,8 +11101,8 @@ nk_font_atlas_bake(struct nk_font_atlas *atlas, int *width, int *height,
nk_font_bake_custom_data(atlas->pixel, *width, *height, atlas->custom,
nk_custom_cursor_data, NK_CURSOR_DATA_W, NK_CURSOR_DATA_H, '.', 'X');
- /* convert alpha8 image into rgba32 image */
if (fmt == NK_FONT_ATLAS_RGBA32) {
+ /* convert alpha8 image into rgba32 image */
void *img_rgba = atlas->temporary.alloc(atlas->temporary.userdata,0,
(nk_size)(*width * *height * 4));
NK_ASSERT(img_rgba);
@@ -10883,7 +11144,6 @@ nk_font_atlas_bake(struct nk_font_atlas *atlas, int *width, int *height,
cursor->size = nk_cursor_data[i][1];
cursor->offset = nk_cursor_data[i][2];
}}
-
/* free temporary memory */
atlas->temporary.free(atlas->temporary.userdata, tmp);
return atlas->pixel;
@@ -10916,8 +11176,8 @@ nk_font_atlas_end(struct nk_font_atlas *atlas, nk_handle texture,
}
if (null) {
null->texture = texture;
- null->uv = nk_vec2((atlas->custom.x + 0.5f)/(float)atlas->tex_width,
- (atlas->custom.y + 0.5f)/(float)atlas->tex_height);
+ null->uv.x = (atlas->custom.x + 0.5f)/(float)atlas->tex_width;
+ null->uv.y = (atlas->custom.y + 0.5f)/(float)atlas->tex_height;
}
for (font_iter = atlas->fonts; font_iter; font_iter = font_iter->next) {
font_iter->texture = texture;
@@ -10939,6 +11199,26 @@ nk_font_atlas_end(struct nk_font_atlas *atlas, nk_handle texture,
}
NK_API void
+nk_font_atlas_cleanup(struct nk_font_atlas *atlas)
+{
+ NK_ASSERT(atlas);
+ NK_ASSERT(atlas->temporary.alloc);
+ NK_ASSERT(atlas->temporary.free);
+ NK_ASSERT(atlas->permanent.alloc);
+ NK_ASSERT(atlas->permanent.free);
+
+ if (!atlas || !atlas->permanent.alloc || !atlas->permanent.free) return;
+ if (atlas->config) {
+ struct nk_font_config *iter, *next;
+ for (iter = atlas->config; iter; iter = next) {
+ next = iter->next;
+ atlas->permanent.free(atlas->permanent.userdata, iter->ttf_blob);
+ atlas->permanent.free(atlas->permanent.userdata, iter);
+ }
+ }
+}
+
+NK_API void
nk_font_atlas_clear(struct nk_font_atlas *atlas)
{
NK_ASSERT(atlas);
@@ -10946,10 +11226,9 @@ nk_font_atlas_clear(struct nk_font_atlas *atlas)
NK_ASSERT(atlas->temporary.free);
NK_ASSERT(atlas->permanent.alloc);
NK_ASSERT(atlas->permanent.free);
- if (!atlas || !atlas->temporary.alloc || !atlas->temporary.free ||
- !atlas->permanent.alloc || !atlas->permanent.free)
- return;
+ if (!atlas || !atlas->permanent.alloc || !atlas->permanent.free) return;
+ nk_font_atlas_cleanup(atlas);
if (atlas->fonts) {
struct nk_font *iter, *next;
for (iter = atlas->fonts; iter; iter = next) {
@@ -10958,14 +11237,6 @@ nk_font_atlas_clear(struct nk_font_atlas *atlas)
}
atlas->fonts = 0;
}
- if (atlas->config) {
- struct nk_font_config *iter, *next;
- for (iter = atlas->config; iter; iter = next) {
- next = iter->next;
- atlas->permanent.free(atlas->permanent.userdata, iter->ttf_blob);
- atlas->permanent.free(atlas->permanent.userdata, iter);
- }
- }
if (atlas->glyphs)
atlas->permanent.free(atlas->permanent.userdata, atlas->glyphs);
nk_zero_struct(*atlas);
@@ -11401,31 +11672,28 @@ nk_textedit_find_charpos(struct nk_text_find *find, struct nk_text_edit *state,
int z = state->string.len;
int i=0, first;
+ nk_zero_struct(r);
if (n == z) {
/* if it's at the end, then find the last line -- simpler than trying to
explicitly handle this case in the regular code */
+ nk_textedit_layout_row(&r, state, 0, row_height, font);
if (single_line) {
- nk_textedit_layout_row(&r, state, 0, row_height, font);
- find->y = 0;
find->first_char = 0;
find->length = z;
- find->height = r.ymax - r.ymin;
- find->x = r.x1;
} else {
- find->y = 0;
- find->x = 0;
- find->height = 1;
-
while (i < z) {
- nk_textedit_layout_row(&r, state, i, row_height, font);
prev_start = i;
i += r.num_chars;
+ nk_textedit_layout_row(&r, state, i, row_height, font);
}
find->first_char = i;
- find->length = 0;
- find->prev_first = prev_start;
+ find->length = r.num_chars;
}
+ find->x = r.x1;
+ find->y = r.ymin;
+ find->height = r.ymax - r.ymin;
+ find->prev_first = prev_start;
return;
}
@@ -11599,9 +11867,11 @@ nk_textedit_paste(struct nk_text_edit *state, char const *ctext, int len)
int glyphs;
const char *text = (const char *) ctext;
if (state->mode == NK_TEXT_EDIT_MODE_VIEW) return 0;
+
/* if there's a selection, the paste should delete it */
nk_textedit_clamp(state);
nk_textedit_delete_selection(state);
+
/* try to insert the characters */
glyphs = nk_utf_len(ctext, len);
if (nk_str_insert_text_char(&state->string, state->cursor, text, len)) {
@@ -11672,6 +11942,8 @@ nk_textedit_text(struct nk_text_edit *state, const char *text, int total_len)
glyph_len = nk_utf_decode(text + text_len, &unicode, total_len-text_len);
text_len += glyph_len;
}
+
+ state->lexer.needs_refresh = 1;
}
NK_INTERN void
@@ -11816,7 +12088,7 @@ retry:
nk_textedit_layout_row(&row, state, state->cursor, row_height, font);
x = row.x0;
- for (i=0; i < row.num_chars; ++i) {
+ for (i=0; i < row.num_chars && x < row.x1; ++i) {
float dx = nk_textedit_get_width(state, start, i, font);
x += dx;
if (x > goal_x)
@@ -11863,7 +12135,7 @@ retry:
nk_textedit_layout_row(&row, state, state->cursor, row_height, font);
x = row.x0;
- for (i=0; i < row.num_chars; ++i) {
+ for (i=0; i < row.num_chars && x < row.x1; ++i) {
float dx = nk_textedit_get_width(state, find.prev_first, i, font);
x += dx;
if (x > goal_x)
@@ -11978,6 +12250,8 @@ retry:
--state->cursor;
}} break;
}
+
+ state->lexer.needs_refresh = 1;
}
NK_INTERN void
@@ -12337,7 +12611,7 @@ nk_widget_text(struct nk_command_buffer *o, struct nk_rect b,
b.h = NK_MAX(b.h, 2 * t->padding.y);
label.x = 0; label.w = 0;
label.y = b.y + t->padding.y;
- label.h = b.h - 2 * t->padding.y;
+ label.h = NK_MIN(f->height, b.h - 2 * t->padding.y);
text_width = f->width(f->userdata, f->height, (const char*)string, len);
text_width += (2.0f * t->padding.x);
@@ -12370,6 +12644,79 @@ nk_widget_text(struct nk_command_buffer *o, struct nk_rect b,
}
NK_INTERN void
+nk_widget_text_lexed(struct nk_command_buffer *o, struct nk_rect b,
+ const char *string, int len, const struct nk_text *t,
+ nk_flags a, const struct nk_user_font *f, struct nk_token *tokens,
+ int offset)
+{
+ struct nk_rect label;
+ float text_width;
+ struct nk_token *token = tokens;
+
+ NK_ASSERT(o);
+ NK_ASSERT(t);
+ if (!o || !t) return;
+
+ b.h = NK_MAX(b.h, 2 * t->padding.y);
+ label.x = 0; label.w = 0;
+ label.y = b.y + t->padding.y;
+ label.h = NK_MIN(f->height, b.h - 2 * t->padding.y);
+
+ text_width = f->width(f->userdata, f->height, (const char*)string, len);
+ text_width += (2.0f * t->padding.x);
+
+ /* align in x-axis */
+ if (a & NK_TEXT_ALIGN_LEFT) {
+ label.x = b.x + t->padding.x;
+ label.w = NK_MAX(0, b.w - 2 * t->padding.x);
+ } else if (a & NK_TEXT_ALIGN_CENTERED) {
+ label.w = NK_MAX(1, 2 * t->padding.x + (float)text_width);
+ label.x = (b.x + t->padding.x + ((b.w - 2 * t->padding.x) - label.w) / 2);
+ label.x = NK_MAX(b.x + t->padding.x, label.x);
+ label.w = NK_MIN(b.x + b.w, label.x + label.w);
+ if (label.w >= label.x) label.w -= label.x;
+ } else if (a & NK_TEXT_ALIGN_RIGHT) {
+ label.x = NK_MAX(b.x + t->padding.x, (b.x + b.w) - (2 * t->padding.x + (float)text_width));
+ label.w = (float)text_width + 2 * t->padding.x;
+ } else return;
+
+ /* align in y-axis */
+ if (a & NK_TEXT_ALIGN_MIDDLE) {
+ label.y = b.y + b.h/2.0f - (float)f->height/2.0f;
+ label.h = NK_MAX(b.h/2.0f, b.h - (b.h/2.0f + f->height/2.0f));
+ } else if (a & NK_TEXT_ALIGN_BOTTOM) {
+ label.y = b.y + b.h - f->height;
+ label.h = f->height;
+ }
+
+ //FIXME do this chunk-wise instead of character-wise
+ const int glyph_max = nk_utf_len(string, len);
+ const float dd = text_width/glyph_max;
+ for(int i = 0, u = 0; i < len; u++)
+ {
+ nk_rune unicode;
+ const int glyph_len = nk_utf_decode(string + i, &unicode, len - i);
+
+ const struct nk_rect dst = {
+ .x = label.x + u*dd,
+ .y = label.y,
+ .w = text_width,
+ .h = label.h
+ };
+
+ struct nk_color bg = t->background;
+ struct nk_color fg = t->text;
+
+ while(offset + i >= token->offset)
+ token++;
+
+ fg = token->color;
+ nk_draw_text(o, dst, string + i, glyph_len, f, bg, fg);
+ i += glyph_len;
+ }
+}
+
+NK_INTERN void
nk_widget_text_wrap(struct nk_command_buffer *o, struct nk_rect b,
const char *string, int len, const struct nk_text *t,
const struct nk_user_font *f)
@@ -12380,6 +12727,7 @@ nk_widget_text_wrap(struct nk_command_buffer *o, struct nk_rect b,
int done = 0;
struct nk_rect line;
struct nk_text text;
+ NK_INTERN nk_rune seperator[] = {' '};
NK_ASSERT(o);
NK_ASSERT(t);
@@ -12398,14 +12746,13 @@ nk_widget_text_wrap(struct nk_command_buffer *o, struct nk_rect b,
line.w = b.w - 2 * t->padding.x;
line.h = 2 * t->padding.y + f->height;
- fitting = nk_text_clamp(f, string, len, line.w, &glyphs, &width);
+ fitting = nk_text_clamp(f, string, len, line.w, &glyphs, &width, seperator,NK_LEN(seperator));
while (done < len) {
if (!fitting || line.y + line.h >= (b.y + b.h)) break;
nk_widget_text(o, line, &string[done], fitting, &text, NK_TEXT_LEFT, f);
done += fitting;
line.y += f->height + 2 * t->padding.y;
- fitting = nk_text_clamp(f, &string[done], len - done,
- line.w, &glyphs, &width);
+ fitting = nk_text_clamp(f, &string[done], len - done, line.w, &glyphs, &width, seperator,NK_LEN(seperator));
}
}
@@ -13786,7 +14133,8 @@ nk_edit_draw_text(struct nk_command_buffer *out,
const struct nk_style_edit *style, float pos_x, float pos_y,
float x_offset, const char *text, int byte_len, float row_height,
const struct nk_user_font *font, struct nk_color background,
- struct nk_color foreground, int is_selected)
+ struct nk_color foreground, int is_selected, struct nk_lexer *lexer,
+ int offset)
{
NK_ASSERT(out);
NK_ASSERT(font);
@@ -13823,8 +14171,16 @@ nk_edit_draw_text(struct nk_command_buffer *out,
if (is_selected) /* selection needs to draw different background color */
nk_fill_rect(out, label, 0, background);
- nk_widget_text(out, label, line, (int)((text + text_len) - line),
- &txt, NK_TEXT_CENTERED, font);
+ if(lexer->tokens && !is_selected)
+ {
+ nk_widget_text_lexed(out, label, line, (int)((text + text_len) - line),
+ &txt, NK_TEXT_CENTERED, font, lexer->tokens, line - text + offset);
+ }
+ else
+ {
+ nk_widget_text(out, label, line, (int)((text + text_len) - line),
+ &txt, NK_TEXT_CENTERED, font);
+ }
text_len++;
line_count++;
@@ -13857,11 +14213,34 @@ nk_edit_draw_text(struct nk_command_buffer *out,
if (is_selected)
nk_fill_rect(out, label, 0, background);
- nk_widget_text(out, label, line, (int)((text + text_len) - line),
- &txt, NK_TEXT_LEFT, font);
+ if(lexer->tokens && !is_selected)
+ {
+ nk_widget_text_lexed(out, label, line, (int)((text + text_len) - line),
+ &txt, NK_TEXT_LEFT, font, lexer->tokens, line - text + offset);
+ }
+ else
+ {
+ nk_widget_text(out, label, line, (int)((text + text_len) - line),
+ &txt, NK_TEXT_LEFT, font);
+ }
}}
}
+NK_INTERN void
+nk_edit_refresh_lex(struct nk_text_edit *edit)
+{
+ if(edit->lexer.needs_refresh || !edit->lexer.tokens)
+ {
+ if(edit->lexer.tokens)
+ free(edit->lexer.tokens);
+
+ edit->lexer.tokens = edit->lexer.lex(edit->lexer.data,
+ nk_str_get_const(&edit->string), nk_str_len_char(&edit->string));
+
+ edit->lexer.needs_refresh = 0;
+ }
+}
+
NK_INTERN nk_flags
nk_do_edit(nk_flags *state, struct nk_command_buffer *out,
struct nk_rect bounds, nk_flags flags, nk_plugin_filter filter,
@@ -13877,6 +14256,7 @@ nk_do_edit(nk_flags *state, struct nk_command_buffer *out,
char cursor_follow = 0;
struct nk_rect old_clip;
struct nk_rect clip;
+ int has_changes = 0;
NK_ASSERT(state);
NK_ASSERT(out);
@@ -13890,7 +14270,7 @@ nk_do_edit(nk_flags *state, struct nk_command_buffer *out,
area.w = bounds.w - (2.0f * style->padding.x + 2 * style->border);
area.h = bounds.h - (2.0f * style->padding.y + 2 * style->border);
if (flags & NK_EDIT_MULTILINE)
- area.w = area.h - style->scrollbar_size.y;
+ area.w = NK_MAX(0, area.w - style->scrollbar_size.x);
row_height = (flags & NK_EDIT_MULTILINE)? font->height + style->row_padding: area.h;
/* calculate clipping rectangle */
@@ -13909,7 +14289,11 @@ nk_do_edit(nk_flags *state, struct nk_command_buffer *out,
if (!prev_state && edit->active) {
const enum nk_text_edit_type type = (flags & NK_EDIT_MULTILINE) ?
NK_TEXT_EDIT_MULTI_LINE: NK_TEXT_EDIT_SINGLE_LINE;
+ const int cursor = edit->cursor;
+ const struct nk_vec2 scrollbar = edit->scrollbar;
nk_textedit_clear_state(edit, type, filter);
+ edit->cursor = cursor;
+ edit->scrollbar = scrollbar;
if (flags & NK_EDIT_ALWAYS_INSERT_MODE)
edit->mode = NK_TEXT_EDIT_MODE_INSERT;
if (flags & NK_EDIT_AUTO_SELECT)
@@ -14014,7 +14398,7 @@ nk_do_edit(nk_flags *state, struct nk_command_buffer *out,
/* tab handler */
{int tab = nk_input_is_key_pressed(in, NK_KEY_TAB);
if (tab && (flags & NK_EDIT_ALLOW_TAB)) {
- nk_textedit_text(edit, " ", 4);
+ nk_textedit_text(edit, " ", 2);
cursor_follow = nk_true;
}}
}
@@ -14045,7 +14429,7 @@ nk_do_edit(nk_flags *state, struct nk_command_buffer *out,
nk_fill_rect(out, bounds, style->rounding, background->data.color);
} else nk_draw_image(out, bounds, &background->data.image, nk_white);}
- area.w -= style->cursor_size + style->scrollbar_size.x;
+ area.w = NK_MAX(0, area.w - style->cursor_size);
if (edit->active)
{
int total_lines = 1;
@@ -14110,7 +14494,7 @@ nk_do_edit(nk_flags *state, struct nk_command_buffer *out,
const char *remaining;
/* calculate 2d position */
- selection_offset_start.y = (float)(total_lines-1) * row_height;
+ selection_offset_start.y = (float)(NK_MAX(total_lines-1,0)) * row_height;
row_size = nk_text_calculate_text_bounds(font, text+row_begin,
text_len-row_begin, row_height, &remaining,
&out_offset, &glyph_offset, NK_STOP_ON_NEW_LINE);
@@ -14143,6 +14527,7 @@ nk_do_edit(nk_flags *state, struct nk_command_buffer *out,
glyphs++;
row_begin = text_len;
glyph_len = nk_utf_decode(text + text_len, &unicode, len-text_len);
+ glyph_width = font->width(font->userdata, font->height, text+text_len, glyph_len);
continue;
}
@@ -14204,7 +14589,7 @@ nk_do_edit(nk_flags *state, struct nk_command_buffer *out,
scroll_step = scroll.h * 0.10f;
scroll_inc = scroll.h * 0.01f;
scroll_target = text_size.y;
- edit->scrollbar.y = nk_do_scrollbarv(&ws, out, scroll, 0,
+ edit->scrollbar.y = nk_do_scrollbarv(&ws, out, scroll, nk_true,
scroll_offset, scroll_target, scroll_step, scroll_inc,
&style->scrollbar, in, font);
}
@@ -14247,6 +14632,13 @@ nk_do_edit(nk_flags *state, struct nk_command_buffer *out,
background_color = nk_rgba(0,0,0,0);
else background_color = background->data.color;
+ if(edit->lexer.lex)
+ {
+ if(has_changes)
+ edit->lexer.needs_refresh = 1;
+
+ nk_edit_refresh_lex(edit);
+ }
if (edit->select_start == edit->select_end) {
/* no selection so just draw the complete text */
@@ -14254,7 +14646,7 @@ nk_do_edit(nk_flags *state, struct nk_command_buffer *out,
int l = nk_str_len_char(&edit->string);
nk_edit_draw_text(out, style, area.x - edit->scrollbar.x,
area.y - edit->scrollbar.y, 0, begin, l, row_height, font,
- background_color, text_color, nk_false);
+ background_color, text_color, nk_false, &edit->lexer, 0);
} else {
/* edit has selection so draw 1-3 text chunks */
if (edit->select_start != edit->select_end && selection_begin > 0){
@@ -14263,9 +14655,14 @@ nk_do_edit(nk_flags *state, struct nk_command_buffer *out,
NK_ASSERT(select_begin_ptr);
nk_edit_draw_text(out, style, area.x - edit->scrollbar.x,
area.y - edit->scrollbar.y, 0, begin, (int)(select_begin_ptr - begin),
- row_height, font, background_color, text_color, nk_false);
+ row_height, font, background_color, text_color, nk_false, &edit->lexer, 0);
}
if (edit->select_start != edit->select_end) {
+ const int offset = edit->select_start < edit->select_end ? edit->select_start : edit->select_end;
+ int glyph_offset;
+ nk_rune unicode;
+ const char *ptr = nk_str_at_const(&edit->string, offset, &unicode, &glyph_offset);
+ const int offset2 = ptr - nk_str_get_const(&edit->string);
/* draw selected text */
NK_ASSERT(select_begin_ptr);
if (!select_end_ptr) {
@@ -14277,7 +14674,8 @@ nk_do_edit(nk_flags *state, struct nk_command_buffer *out,
area.y + selection_offset_start.y - edit->scrollbar.y,
selection_offset_start.x,
select_begin_ptr, (int)(select_end_ptr - select_begin_ptr),
- row_height, font, sel_background_color, sel_text_color, nk_true);
+ row_height, font, sel_background_color, sel_text_color, nk_true,
+ &edit->lexer, offset2);
}
if ((edit->select_start != edit->select_end &&
selection_end < edit->string.len))
@@ -14286,13 +14684,19 @@ nk_do_edit(nk_flags *state, struct nk_command_buffer *out,
const char *begin = select_end_ptr;
const char *end = nk_str_get_const(&edit->string) +
nk_str_len_char(&edit->string);
+ const int offset = edit->select_start < edit->select_end ? edit->select_end : edit->select_start;
+ int glyph_offset;
+ nk_rune unicode;
+ const char *ptr = nk_str_at_const(&edit->string, offset, &unicode, &glyph_offset);
+ const int offset2 = ptr - nk_str_get_const(&edit->string);
NK_ASSERT(select_end_ptr);
nk_edit_draw_text(out, style,
area.x - edit->scrollbar.x,
area.y + selection_offset_end.y - edit->scrollbar.y,
selection_offset_end.x,
begin, (int)(end - begin), row_height, font,
- background_color, text_color, nk_true);
+ background_color, text_color, nk_false,
+ &edit->lexer, offset2);
}
}
@@ -14336,9 +14740,13 @@ nk_do_edit(nk_flags *state, struct nk_command_buffer *out,
int l = nk_str_len_char(&edit->string);
const char *begin = nk_str_get_const(&edit->string);
+ if(edit->lexer.lex)
+ nk_edit_refresh_lex(edit);
+
const struct nk_style_item *background;
struct nk_color background_color;
struct nk_color text_color;
+ nk_push_scissor(out, clip);
if (*state & NK_WIDGET_STATE_ACTIVED) {
background = &style->active;
text_color = style->text_active;
@@ -14354,7 +14762,7 @@ nk_do_edit(nk_flags *state, struct nk_command_buffer *out,
else background_color = background->data.color;
nk_edit_draw_text(out, style, area.x - edit->scrollbar.x,
area.y - edit->scrollbar.y, 0, begin, l, row_height, font,
- background_color, text_color, nk_false);
+ background_color, text_color, nk_false, &edit->lexer, 0);
}
nk_push_scissor(out, old_clip);}
return ret;
@@ -14921,7 +15329,7 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table)
/* default text */
text = &style->text;
text->color = table[NK_COLOR_TEXT];
- text->padding = nk_vec2(4,4);
+ text->padding = nk_vec2(0,0);
/* default button */
button = &style->button;
@@ -15121,8 +15529,8 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table)
scroll->dec_symbol = NK_SYMBOL_CIRCLE_SOLID;
scroll->inc_symbol = NK_SYMBOL_CIRCLE_SOLID;
scroll->userdata = nk_handle_ptr(0);
- scroll->border_color = table[NK_COLOR_BORDER];
- scroll->cursor_border_color = table[NK_COLOR_BORDER];
+ scroll->border_color = table[NK_COLOR_SCROLLBAR];
+ scroll->cursor_border_color = table[NK_COLOR_SCROLLBAR];
scroll->padding = nk_vec2(0,0);
scroll->show_buttons = nk_false;
scroll->border = 0;
@@ -15408,6 +15816,7 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table)
win->background = table[NK_COLOR_WINDOW];
win->fixed_background = nk_style_item_color(table[NK_COLOR_WINDOW]);
win->border_color = table[NK_COLOR_BORDER];
+ win->popup_border_color = table[NK_COLOR_BORDER];
win->combo_border_color = table[NK_COLOR_BORDER];
win->contextual_border_color = table[NK_COLOR_BORDER];
win->menu_border_color = table[NK_COLOR_BORDER];
@@ -15425,6 +15834,7 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table)
win->menu_border = 1.0f;
win->group_border = 1.0f;
win->tooltip_border = 1.0f;
+ win->popup_border = 1.0f;
win->border = 2.0f;
win->padding = nk_vec2(4,4);
@@ -15660,6 +16070,8 @@ NK_INTERN void nk_remove_window(struct nk_context*, struct nk_window*);
NK_INTERN void nk_free_window(struct nk_context *ctx, struct nk_window *win);
NK_INTERN void nk_free_table(struct nk_context *ctx, struct nk_table *tbl);
NK_INTERN void nk_remove_table(struct nk_window *win, struct nk_table *tbl);
+NK_INTERN void* nk_create_panel(struct nk_context *ctx);
+NK_INTERN void nk_free_panel(struct nk_context*, struct nk_panel *pan);
NK_INTERN void
nk_setup(struct nk_context *ctx, const struct nk_user_font *font)
@@ -15786,7 +16198,7 @@ nk_clear(struct nk_context *ctx)
ctx->style.cursor_active = ctx->style.cursors[NK_CURSOR_ARROW];
NK_MEMSET(&ctx->overlay, 0, sizeof(ctx->overlay));
#ifdef NK_INCLUDE_VERTEX_BUFFER_OUTPUT
- nk_draw_list_clear(&ctx->draw_list);
+ //nk_draw_list_clear(&ctx->draw_list);
#endif
/* garbage collector */
@@ -16257,6 +16669,7 @@ nk_panel_begin(struct nk_context *ctx, const char *title, enum nk_panel_type pan
{
layout->flags |= NK_WINDOW_HIDDEN;
layout->flags |= NK_WINDOW_CLOSED;
+ layout->flags &= (nk_flags)~NK_WINDOW_MINIMIZED;
}
}
@@ -16501,24 +16914,9 @@ nk_panel_end(struct nk_context *ctx)
layout->bounds.y + layout->bounds.h + layout->footer_height:
window->bounds.y + window->bounds.h;
- /* draw border top */
- nk_stroke_line(out,window->bounds.x,window->bounds.y,
- window->bounds.x + window->bounds.w, window->bounds.y,
- layout->border, border_color);
-
- /* draw bottom border */
- nk_stroke_line(out, window->bounds.x, padding_y,
- window->bounds.x + window->bounds.w, padding_y, layout->border, border_color);
-
- /* draw left border */
- nk_stroke_line(out, window->bounds.x + layout->border*0.5f,
- window->bounds.y, window->bounds.x + layout->border*0.5f,
- padding_y, layout->border, border_color);
-
- /* draw right border */
- nk_stroke_line(out, window->bounds.x + window->bounds.w - layout->border*0.5f,
- window->bounds.y, window->bounds.x + window->bounds.w - layout->border*0.5f,
- padding_y, layout->border, border_color);
+ /* draw border rectangle */
+ nk_stroke_rect(out, nk_rect(window->bounds.x, window->bounds.y,
+ window->bounds.w - 2.f, padding_y - window->bounds.y), 0.f, layout->border, border_color);
}
/* scaler */
@@ -16610,7 +17008,6 @@ nk_panel_end(struct nk_context *ctx)
NK_ASSERT(!layout->row.tree_depth);
}
-
/* ----------------------------------------------------------------
*
* PAGE ELEMENT
@@ -16644,7 +17041,8 @@ nk_create_page_element(struct nk_context *ctx)
}
NK_INTERN void
-nk_free_page_element(struct nk_context *ctx, struct nk_page_element *elem)
+nk_link_page_element_into_freelist(struct nk_context *ctx,
+ struct nk_page_element *elem)
{
/* link table into freelist */
if (!ctx->freelist) {
@@ -16655,6 +17053,46 @@ nk_free_page_element(struct nk_context *ctx, struct nk_page_element *elem)
}
}
+NK_INTERN void
+nk_free_page_element(struct nk_context *ctx, struct nk_page_element *elem)
+{
+ /* we have a pool so just add to free list */
+ if (ctx->use_pool) {
+ nk_link_page_element_into_freelist(ctx, elem);
+ return;
+ }
+
+ /* if possible remove last element from back of fixed memory buffer */
+ {void *elem_end = (void*)(elem + 1);
+ void *buffer_end = (nk_byte*)ctx->memory.memory.ptr + ctx->memory.size;
+ if (elem_end == buffer_end)
+ ctx->memory.size -= sizeof(struct nk_page_element);
+ else nk_link_page_element_into_freelist(ctx, elem);}
+}
+
+/* ----------------------------------------------------------------
+ *
+ * PANEL
+ *
+ * ---------------------------------------------------------------*/
+NK_INTERN void*
+nk_create_panel(struct nk_context *ctx)
+{
+ struct nk_page_element *elem;
+ elem = nk_create_page_element(ctx);
+ if (!elem) return 0;
+ nk_zero_struct(*elem);
+ return &elem->data.pan;
+}
+
+NK_INTERN void
+nk_free_panel(struct nk_context *ctx, struct nk_panel *pan)
+{
+ union nk_page_data *pd = NK_CONTAINER_OF(pan, union nk_page_data, pan);
+ struct nk_page_element *pe = NK_CONTAINER_OF(pd, struct nk_page_element, data);
+ nk_free_page_element(ctx, pe);
+}
+
/* ----------------------------------------------------------------
*
* TABLES
@@ -16663,7 +17101,8 @@ nk_free_page_element(struct nk_context *ctx, struct nk_page_element *elem)
NK_INTERN struct nk_table*
nk_create_table(struct nk_context *ctx)
{
- struct nk_page_element *elem = nk_create_page_element(ctx);
+ struct nk_page_element *elem;
+ elem = nk_create_page_element(ctx);
if (!elem) return 0;
nk_zero_struct(*elem);
return &elem->data.tbl;
@@ -16731,10 +17170,10 @@ nk_add_value(struct nk_context *ctx, struct nk_window *win,
NK_INTERN nk_uint*
nk_find_value(struct nk_window *win, nk_hash name)
{
- unsigned short size = win->table_size;
+ nk_ushort size = win->table_size;
struct nk_table *iter = win->tables;
while (iter) {
- unsigned short i = 0;
+ nk_ushort i = 0;
for (i = 0; i < size; ++i) {
if (iter->keys[i] == name) {
iter->seq = win->seq;
@@ -16755,7 +17194,8 @@ nk_find_value(struct nk_window *win, nk_hash name)
NK_INTERN void*
nk_create_window(struct nk_context *ctx)
{
- struct nk_page_element *elem = nk_create_page_element(ctx);
+ struct nk_page_element *elem;
+ elem = nk_create_page_element(ctx);
if (!elem) return 0;
elem->data.win.seq = ctx->seq;
return &elem->data.win;
@@ -16887,15 +17327,15 @@ nk_remove_window(struct nk_context *ctx, struct nk_window *win)
}
NK_API int
-nk_begin(struct nk_context *ctx, struct nk_panel *layout, const char *title,
+nk_begin(struct nk_context *ctx, const char *title,
struct nk_rect bounds, nk_flags flags)
{
- return nk_begin_titled(ctx, layout, title, title, bounds, flags);
+ return nk_begin_titled(ctx, title, title, bounds, flags);
}
NK_API int
-nk_begin_titled(struct nk_context *ctx, struct nk_panel *layout,
- const char *name, const char *title, struct nk_rect bounds, nk_flags flags)
+nk_begin_titled(struct nk_context *ctx, const char *name, const char *title,
+ struct nk_rect bounds, nk_flags flags)
{
struct nk_window *win;
struct nk_style *style;
@@ -17019,25 +17459,29 @@ nk_begin_titled(struct nk_context *ctx, struct nk_panel *layout,
win->flags |= NK_WINDOW_ROM;
}
- win->layout = layout;
+ win->layout = (struct nk_panel*)nk_create_panel(ctx);
ctx->current = win;
ret = nk_panel_begin(ctx, title, NK_PANEL_WINDOW);
- layout->offset = &win->scrollbar;
+ win->layout->offset = &win->scrollbar;
return ret;
}
NK_API void
nk_end(struct nk_context *ctx)
{
+ struct nk_panel *layout;
NK_ASSERT(ctx);
NK_ASSERT(ctx->current && "if this triggers you forgot to call `nk_begin`");
NK_ASSERT(ctx->current->layout);
+
+ layout = ctx->current->layout;
if (!ctx || !ctx->current) return;
- if (ctx->current->flags & NK_WINDOW_HIDDEN) {
+ if (layout->type == NK_PANEL_WINDOW && (ctx->current->flags & NK_WINDOW_HIDDEN)) {
ctx->current = 0;
return;
}
nk_panel_end(ctx);
+ nk_free_panel(ctx, ctx->current->layout);
ctx->current = 0;
}
@@ -17387,7 +17831,7 @@ nk_window_set_focus(struct nk_context *ctx, const char *name)
/*----------------------------------------------------------------
*
- * PANEL
+ * MENUBAR
*
* --------------------------------------------------------------*/
NK_API void
@@ -17583,7 +18027,6 @@ nk_layout_row_begin(struct nk_context *ctx, enum nk_layout_format fmt,
win = ctx->current;
layout = win->layout;
-
nk_panel_layout(ctx, win, row_height, cols);
if (fmt == NK_DYNAMIC)
layout->row.type = NK_LAYOUT_DYNAMIC_ROW;
@@ -17610,7 +18053,6 @@ nk_layout_row_push(struct nk_context *ctx, float ratio_or_width)
win = ctx->current;
layout = win->layout;
-
if (layout->row.type == NK_LAYOUT_DYNAMIC_ROW) {
float ratio = ratio_or_width;
if ((ratio + layout->row.filled) > 1.0f) return;
@@ -17933,10 +18375,7 @@ nk_layout_widget_space(struct nk_rect *bounds, const struct nk_context *ctx,
item_width = layout->row.item_width;
item_offset = layout->row.item_offset;
item_spacing = (float)layout->row.index * spacing.x;
- if (modify) {
- layout->row.item_offset += item_width;
- layout->row.index = 0;
- }
+ if (modify) layout->row.item_offset += item_width;
} break;
case NK_LAYOUT_STATIC_FREE: {
/* free widget placing */
@@ -18021,9 +18460,8 @@ nk_layout_peek(struct nk_rect *bounds, struct nk_context *ctx)
}
NK_INTERN int
-nk_tree_base(struct nk_context *ctx, enum nk_tree_type type,
- struct nk_image *img, const char *title, enum nk_collapse_states initial_state,
- const char *hash, int len, int line)
+nk_tree_state_base(struct nk_context *ctx, enum nk_tree_type type,
+ struct nk_image *img, const char *title, enum nk_collapse_states *state)
{
struct nk_window *win;
struct nk_panel *layout;
@@ -18039,9 +18477,6 @@ nk_tree_base(struct nk_context *ctx, enum nk_tree_type type,
struct nk_text text;
nk_flags ws = 0;
- int title_len = 0;
- nk_hash tree_hash = 0;
- nk_uint *state = 0;
enum nk_widget_layout_states widget_state;
NK_ASSERT(ctx);
@@ -18073,19 +18508,6 @@ nk_tree_base(struct nk_context *ctx, enum nk_tree_type type,
}
} else text.background = style->window.background;
- /* find, create or set tab persistent state (open/closed) */
- if (hash) {
- tree_hash = nk_murmur_hash(hash, len, (nk_hash)line);
- } else {
- title_len = (int)nk_strlen(title);
- tree_hash = nk_murmur_hash(title, (int)title_len, (nk_hash)line);
- }
- state = nk_find_value(win, tree_hash);
- if (!state) {
- state = nk_add_value(ctx, win, tree_hash, 0);
- *state = initial_state;
- }
-
/* update node state */
in = (!(layout->flags & NK_WINDOW_ROM)) ? &ctx->input: 0;
in = (in && widget_state == NK_WIDGET_VALID) ? &ctx->input : 0;
@@ -18141,20 +18563,41 @@ nk_tree_base(struct nk_context *ctx, enum nk_tree_type type,
} else return nk_false;
}
-NK_API int
-nk_tree_push_hashed(struct nk_context *ctx, enum nk_tree_type type,
- const char *title, enum nk_collapse_states initial_state,
+NK_INTERN int
+nk_tree_base(struct nk_context *ctx, enum nk_tree_type type,
+ struct nk_image *img, const char *title, enum nk_collapse_states initial_state,
const char *hash, int len, int line)
-{return nk_tree_base(ctx, type, 0, title, initial_state, hash, len, line);}
+{
+ struct nk_window *win = ctx->current;
+ int title_len = 0;
+ nk_hash tree_hash = 0;
+ nk_uint *state = 0;
+
+ /* retrieve tree state from internal widget state tables */
+ if (!hash) {
+ title_len = (int)nk_strlen(title);
+ tree_hash = nk_murmur_hash(title, (int)title_len, (nk_hash)line);
+ } else tree_hash = nk_murmur_hash(hash, len, (nk_hash)line);
+ state = nk_find_value(win, tree_hash);
+ if (!state) {
+ state = nk_add_value(ctx, win, tree_hash, 0);
+ *state = initial_state;
+ }
+ return nk_tree_state_base(ctx, type, img, title, (enum nk_collapse_states*)state);
+}
NK_API int
-nk_tree_image_push_hashed(struct nk_context *ctx, enum nk_tree_type type,
- struct nk_image img, const char *title, enum nk_collapse_states initial_state,
- const char *hash, int len,int seed)
-{return nk_tree_base(ctx, type, &img, title, initial_state, hash, len, seed);}
+nk_tree_state_push(struct nk_context *ctx, enum nk_tree_type type,
+ const char *title, enum nk_collapse_states *state)
+{return nk_tree_state_base(ctx, type, 0, title, state);}
+
+NK_API int
+nk_tree_state_image_push(struct nk_context *ctx, enum nk_tree_type type,
+ struct nk_image img, const char *title, enum nk_collapse_states *state)
+{return nk_tree_state_base(ctx, type, &img, title, state);}
NK_API void
-nk_tree_pop(struct nk_context *ctx)
+nk_tree_state_pop(struct nk_context *ctx)
{
struct nk_window *win = 0;
struct nk_panel *layout = 0;
@@ -18172,6 +18615,23 @@ nk_tree_pop(struct nk_context *ctx)
NK_ASSERT(layout->row.tree_depth);
layout->row.tree_depth--;
}
+
+NK_API int
+nk_tree_push_hashed(struct nk_context *ctx, enum nk_tree_type type,
+ const char *title, enum nk_collapse_states initial_state,
+ const char *hash, int len, int line)
+{return nk_tree_base(ctx, type, 0, title, initial_state, hash, len, line);}
+
+NK_API int
+nk_tree_image_push_hashed(struct nk_context *ctx, enum nk_tree_type type,
+ struct nk_image img, const char *title, enum nk_collapse_states initial_state,
+ const char *hash, int len,int seed)
+{return nk_tree_base(ctx, type, &img, title, initial_state, hash, len, seed);}
+
+NK_API void
+nk_tree_pop(struct nk_context *ctx)
+{nk_tree_state_pop(ctx);}
+
/*----------------------------------------------------------------
*
* WIDGETS
@@ -18532,7 +18992,7 @@ nk_value_float(struct nk_context *ctx, const char *prefix, float value)
NK_API void
nk_value_color_byte(struct nk_context *ctx, const char *p, struct nk_color c)
-{nk_labelf(ctx, NK_TEXT_LEFT, "%s: (%c, %c, %c, %c)", p, c.r, c.g, c.b, c.a);}
+{nk_labelf(ctx, NK_TEXT_LEFT, "%s: (%d, %d, %d, %d)", p, c.r, c.g, c.b, c.a);}
NK_API void
nk_value_color_float(struct nk_context *ctx, const char *p, struct nk_color color)
@@ -18654,33 +19114,45 @@ nk_button_pop_behavior(struct nk_context *ctx)
}
NK_API int
-nk_button_text(struct nk_context *ctx, const char *title, int len)
+nk_button_text_styled(struct nk_context *ctx,
+ const struct nk_style_button *style, const char *title, int len)
{
struct nk_window *win;
struct nk_panel *layout;
const struct nk_input *in;
- const struct nk_style *style;
struct nk_rect bounds;
enum nk_widget_layout_states state;
NK_ASSERT(ctx);
+ NK_ASSERT(style);
NK_ASSERT(ctx->current);
NK_ASSERT(ctx->current->layout);
- if (!ctx || !ctx->current || !ctx->current->layout) return 0;
+ if (!style || !ctx || !ctx->current || !ctx->current->layout) return 0;
win = ctx->current;
- style = &ctx->style;
layout = win->layout;
state = nk_widget(&bounds, ctx);
if (!state) return 0;
in = (state == NK_WIDGET_ROM || layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input;
return nk_do_button_text(&ctx->last_widget_state, &win->buffer, bounds,
- title, len, style->button.text_alignment, ctx->button_behavior,
- &style->button, in, style->font);
+ title, len, style->text_alignment, ctx->button_behavior,
+ style, in, ctx->style.font);
}
+NK_API int
+nk_button_text(struct nk_context *ctx, const char *title, int len)
+{
+ NK_ASSERT(ctx);
+ if (!ctx) return 0;
+ return nk_button_text_styled(ctx, &ctx->style.button, title, len);
+}
+
+NK_API int nk_button_label_styled(struct nk_context *ctx,
+ const struct nk_style_button *style, const char *title)
+{return nk_button_text_styled(ctx, style, title, nk_strlen(title));}
+
NK_API int nk_button_label(struct nk_context *ctx, const char *title)
{return nk_button_text(ctx, title, nk_strlen(title));}
@@ -18721,12 +19193,12 @@ nk_button_color(struct nk_context *ctx, struct nk_color color)
}
NK_API int
-nk_button_symbol(struct nk_context *ctx, enum nk_symbol_type symbol)
+nk_button_symbol_styled(struct nk_context *ctx,
+ const struct nk_style_button *style, enum nk_symbol_type symbol)
{
struct nk_window *win;
struct nk_panel *layout;
const struct nk_input *in;
- const struct nk_style *style;
struct nk_rect bounds;
enum nk_widget_layout_states state;
@@ -18738,23 +19210,29 @@ nk_button_symbol(struct nk_context *ctx, enum nk_symbol_type symbol)
return 0;
win = ctx->current;
- style = &ctx->style;
layout = win->layout;
-
state = nk_widget(&bounds, ctx);
if (!state) return 0;
in = (state == NK_WIDGET_ROM || layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input;
return nk_do_button_symbol(&ctx->last_widget_state, &win->buffer, bounds,
- symbol, ctx->button_behavior, &style->button, in, style->font);
+ symbol, ctx->button_behavior, style, in, ctx->style.font);
}
NK_API int
-nk_button_image(struct nk_context *ctx, struct nk_image img)
+nk_button_symbol(struct nk_context *ctx, enum nk_symbol_type symbol)
+{
+ NK_ASSERT(ctx);
+ if (!ctx) return 0;
+ return nk_button_symbol_styled(ctx, &ctx->style.button, symbol);
+}
+
+NK_API int
+nk_button_image_styled(struct nk_context *ctx, const struct nk_style_button *style,
+ struct nk_image img)
{
struct nk_window *win;
struct nk_panel *layout;
const struct nk_input *in;
- const struct nk_style *style;
struct nk_rect bounds;
enum nk_widget_layout_states state;
@@ -18766,24 +19244,31 @@ nk_button_image(struct nk_context *ctx, struct nk_image img)
return 0;
win = ctx->current;
- style = &ctx->style;
layout = win->layout;
state = nk_widget(&bounds, ctx);
if (!state) return 0;
in = (state == NK_WIDGET_ROM || layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input;
return nk_do_button_image(&ctx->last_widget_state, &win->buffer, bounds,
- img, ctx->button_behavior, &style->button, in);
+ img, ctx->button_behavior, style, in);
}
NK_API int
-nk_button_symbol_text(struct nk_context *ctx, enum nk_symbol_type symbol,
- const char* text, int len, nk_flags align)
+nk_button_image(struct nk_context *ctx, struct nk_image img)
+{
+ NK_ASSERT(ctx);
+ if (!ctx) return 0;
+ return nk_button_image_styled(ctx, &ctx->style.button, img);
+}
+
+NK_API int
+nk_button_symbol_text_styled(struct nk_context *ctx,
+ const struct nk_style_button *style, enum nk_symbol_type symbol,
+ const char *text, int len, nk_flags align)
{
struct nk_window *win;
struct nk_panel *layout;
const struct nk_input *in;
- const struct nk_style *style;
struct nk_rect bounds;
enum nk_widget_layout_states state;
@@ -18795,7 +19280,6 @@ nk_button_symbol_text(struct nk_context *ctx, enum nk_symbol_type symbol,
return 0;
win = ctx->current;
- style = &ctx->style;
layout = win->layout;
state = nk_widget(&bounds, ctx);
@@ -18803,21 +19287,35 @@ nk_button_symbol_text(struct nk_context *ctx, enum nk_symbol_type symbol,
in = (state == NK_WIDGET_ROM || layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input;
return nk_do_button_text_symbol(&ctx->last_widget_state, &win->buffer, bounds,
symbol, text, len, align, ctx->button_behavior,
- &style->button, style->font, in);
+ style, ctx->style.font, in);
+}
+
+NK_API int
+nk_button_symbol_text(struct nk_context *ctx, enum nk_symbol_type symbol,
+ const char* text, int len, nk_flags align)
+{
+ NK_ASSERT(ctx);
+ if (!ctx) return 0;
+ return nk_button_symbol_text_styled(ctx, &ctx->style.button, symbol, text, len, align);
}
NK_API int nk_button_symbol_label(struct nk_context *ctx, enum nk_symbol_type symbol,
const char *label, nk_flags align)
{return nk_button_symbol_text(ctx, symbol, label, nk_strlen(label), align);}
+NK_API int nk_button_symbol_label_styled(struct nk_context *ctx,
+ const struct nk_style_button *style, enum nk_symbol_type symbol,
+ const char *title, nk_flags align)
+{return nk_button_symbol_text_styled(ctx, style, symbol, title, nk_strlen(title), align);}
+
NK_API int
-nk_button_image_text(struct nk_context *ctx, struct nk_image img,
- const char *text, int len, nk_flags align)
+nk_button_image_text_styled(struct nk_context *ctx,
+ const struct nk_style_button *style, struct nk_image img, const char *text,
+ int len, nk_flags align)
{
struct nk_window *win;
struct nk_panel *layout;
const struct nk_input *in;
- const struct nk_style *style;
struct nk_rect bounds;
enum nk_widget_layout_states state;
@@ -18829,7 +19327,6 @@ nk_button_image_text(struct nk_context *ctx, struct nk_image img,
return 0;
win = ctx->current;
- style = &ctx->style;
layout = win->layout;
state = nk_widget(&bounds, ctx);
@@ -18837,13 +19334,24 @@ nk_button_image_text(struct nk_context *ctx, struct nk_image img,
in = (state == NK_WIDGET_ROM || layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input;
return nk_do_button_text_image(&ctx->last_widget_state, &win->buffer,
bounds, img, text, len, align, ctx->button_behavior,
- &style->button, style->font, in);
+ style, ctx->style.font, in);
}
+NK_API int
+nk_button_image_text(struct nk_context *ctx, struct nk_image img,
+ const char *text, int len, nk_flags align)
+{return nk_button_image_text_styled(ctx, &ctx->style.button,img, text, len, align);}
+
+
NK_API int nk_button_image_label(struct nk_context *ctx, struct nk_image img,
const char *label, nk_flags align)
{return nk_button_image_text(ctx, img, label, nk_strlen(label), align);}
+NK_API int nk_button_image_label_styled(struct nk_context *ctx,
+ const struct nk_style_button *style, struct nk_image img,
+ const char *label, nk_flags text_alignment)
+{return nk_button_image_text_styled(ctx, style, img, label, nk_strlen(label), text_alignment);}
+
/*----------------------------------------------------------------
*
* SELECTABLE
@@ -19002,6 +19510,7 @@ nk_checkbox_flags_text(struct nk_context *ctx, const char *text, int len,
NK_ASSERT(text);
NK_ASSERT(flags);
if (!ctx || !text || !flags) return 0;
+
active = (int)((*flags & value) & value);
if (nk_checkbox_text(ctx, text, len, &active)) {
if (active) *flags |= value;
@@ -19259,8 +19768,8 @@ nk_edit_string(struct nk_context *ctx, nk_flags flags,
win->edit.sel_start = edit->select_start;
win->edit.sel_end = edit->select_end;
win->edit.mode = edit->mode;
- win->edit.scrollbar.x = (unsigned short)edit->scrollbar.x;
- win->edit.scrollbar.y = (unsigned short)edit->scrollbar.y;
+ win->edit.scrollbar.x = (nk_ushort)edit->scrollbar.x;
+ win->edit.scrollbar.y = (nk_ushort)edit->scrollbar.y;
}
return state;
}
@@ -19474,6 +19983,7 @@ nk_property_int(struct nk_context *ctx, const char *name,
NK_ASSERT(ctx);
NK_ASSERT(name);
NK_ASSERT(val);
+
if (!ctx || !ctx->current || !name || !val) return;
variant = nk_property_variant_int(*val, min, max, step);
nk_property(ctx, name, &variant, inc_per_pixel, NK_FILTER_INT);
@@ -19488,6 +19998,7 @@ nk_property_float(struct nk_context *ctx, const char *name,
NK_ASSERT(ctx);
NK_ASSERT(name);
NK_ASSERT(val);
+
if (!ctx || !ctx->current || !name || !val) return;
variant = nk_property_variant_float(*val, min, max, step);
nk_property(ctx, name, &variant, inc_per_pixel, NK_FILTER_FLOAT);
@@ -19502,6 +20013,7 @@ nk_property_double(struct nk_context *ctx, const char *name,
NK_ASSERT(ctx);
NK_ASSERT(name);
NK_ASSERT(val);
+
if (!ctx || !ctx->current || !name || !val) return;
variant = nk_property_variant_double(*val, min, max, step);
nk_property(ctx, name, &variant, inc_per_pixel, NK_FILTER_FLOAT);
@@ -19515,6 +20027,7 @@ nk_propertyi(struct nk_context *ctx, const char *name, int min, int val,
struct nk_property_variant variant;
NK_ASSERT(ctx);
NK_ASSERT(name);
+
if (!ctx || !ctx->current || !name) return val;
variant = nk_property_variant_int(val, min, max, step);
nk_property(ctx, name, &variant, inc_per_pixel, NK_FILTER_INT);
@@ -19529,6 +20042,7 @@ nk_propertyf(struct nk_context *ctx, const char *name, float min,
struct nk_property_variant variant;
NK_ASSERT(ctx);
NK_ASSERT(name);
+
if (!ctx || !ctx->current || !name) return val;
variant = nk_property_variant_float(val, min, max, step);
nk_property(ctx, name, &variant, inc_per_pixel, NK_FILTER_FLOAT);
@@ -19543,6 +20057,7 @@ nk_propertyd(struct nk_context *ctx, const char *name, double min,
struct nk_property_variant variant;
NK_ASSERT(ctx);
NK_ASSERT(name);
+
if (!ctx || !ctx->current || !name) return val;
variant = nk_property_variant_double(val, min, max, step);
nk_property(ctx, name, &variant, inc_per_pixel, NK_FILTER_FLOAT);
@@ -19719,8 +20234,7 @@ nk_chart_push_line(struct nk_context *ctx, struct nk_window *win,
bounds.x = g->slots[slot].last.x - 2;
bounds.y = g->slots[slot].last.y - 2;
- bounds.w = 4;
- bounds.h = 4;
+ bounds.w = bounds.h = 4;
color = g->slots[slot].color;
if (!(layout->flags & NK_WINDOW_ROM) &&
@@ -19743,8 +20257,7 @@ nk_chart_push_line(struct nk_context *ctx, struct nk_window *win,
bounds.x = cur.x - 3;
bounds.y = cur.y - 3;
- bounds.w = 6;
- bounds.h = 6;
+ bounds.w = bounds.h = 6;
/* user selection of current data point */
if (!(layout->flags & NK_WINDOW_ROM)) {
@@ -19913,55 +20426,21 @@ nk_plot_function(struct nk_context *ctx, enum nk_chart_type type, void *userdata
*
* --------------------------------------------------------------*/
NK_API int
-nk_group_begin(struct nk_context *ctx, struct nk_panel *layout, const char *title,
- nk_flags flags)
+nk_group_scrolled_begin(struct nk_context *ctx,
+ struct nk_scroll *scroll, const char *title, nk_flags flags)
{
- struct nk_window *win;
- const struct nk_rect *c;
- union {struct nk_scroll *s; nk_uint *i;} value;
- struct nk_window panel;
struct nk_rect bounds;
- nk_hash title_hash;
- int title_len;
-
- NK_ASSERT(ctx);
- NK_ASSERT(title);
- NK_ASSERT(ctx->current);
- NK_ASSERT(ctx->current->layout);
- if (!ctx || !ctx->current || !ctx->current->layout || !title)
- return 0;
+ struct nk_window panel;
+ struct nk_window *win;
- /* allocate space for the group panel inside the panel */
win = ctx->current;
- c = &win->layout->clip;
nk_panel_alloc_space(&bounds, ctx);
- nk_zero(layout, sizeof(*layout));
- NK_ASSERT(win->layout != layout && "Parent and group are not allowed to use the same panel");
- /* This assert triggers either if you pass the same panel to a parent parent and child group
- * or forgot to add a `nk_group_end` to a `nk_group_begin`.
- * Correct example:
- * struct nk_panel panel;
- * if (nk_begin(...,&panel,...)) {
- * struct nk_panel tab;
- * if (nk_group_begin(...,&tab,...)) {
- * ....
- * nk_group_end(...);
- * }
- * }
- */
- /* find persistent group scrollbar value */
- title_len = (int)nk_strlen(title);
- title_hash = nk_murmur_hash(title, (int)title_len, NK_PANEL_GROUP);
- value.i = nk_find_value(win, title_hash);
- if (!value.i) {
- value.i = nk_add_value(ctx, win, title_hash, 0);
- *value.i = 0;
- }
+ {const struct nk_rect *c = &win->layout->clip;
if (!NK_INTERSECT(c->x, c->y, c->w, c->h, bounds.x, bounds.y, bounds.w, bounds.h) &&
!(flags & NK_WINDOW_MOVABLE)) {
return 0;
- }
+ }}
if (win->flags & NK_WINDOW_ROM)
flags |= NK_WINDOW_ROM;
@@ -19969,24 +20448,25 @@ nk_group_begin(struct nk_context *ctx, struct nk_panel *layout, const char *titl
nk_zero(&panel, sizeof(panel));
panel.bounds = bounds;
panel.flags = flags;
- panel.scrollbar.x = (unsigned short)value.s->x;
- panel.scrollbar.y = (unsigned short)value.s->y;
+ panel.scrollbar.x = scroll->x;
+ panel.scrollbar.y = scroll->y;
panel.buffer = win->buffer;
- panel.layout = layout;
+ panel.layout = (struct nk_panel*)nk_create_panel(ctx);
ctx->current = &panel;
nk_panel_begin(ctx, (flags & NK_WINDOW_TITLE) ? title: 0, NK_PANEL_GROUP);
win->buffer = panel.buffer;
- win->buffer.clip = layout->clip;
- layout->offset = value.s;
- layout->parent = win->layout;
- win->layout = layout;
+ win->buffer.clip = panel.layout->clip;
+ panel.layout->offset = scroll;
+ panel.layout->parent = win->layout;
+ win->layout = panel.layout;
ctx->current = win;
return 1;
+
}
NK_API void
-nk_group_end(struct nk_context *ctx)
+nk_group_scrolled_end(struct nk_context *ctx)
{
struct nk_window *win;
struct nk_panel *parent;
@@ -20048,14 +20528,119 @@ nk_group_end(struct nk_context *ctx)
return;
}
+NK_API int
+nk_group_begin(struct nk_context *ctx, const char *title, nk_flags flags)
+{
+ int title_len;
+ nk_hash title_hash;
+ union {struct nk_scroll *s; nk_uint *i;} value;
+ struct nk_window *win;
+
+ NK_ASSERT(ctx);
+ NK_ASSERT(title);
+ NK_ASSERT(ctx->current);
+ NK_ASSERT(ctx->current->layout);
+ if (!ctx || !ctx->current || !ctx->current->layout || !title)
+ return 0;
+
+ /* find persistent group scrollbar value */
+ win = ctx->current;
+ title_len = (int)nk_strlen(title);
+ title_hash = nk_murmur_hash(title, (int)title_len, NK_PANEL_GROUP);
+ value.i = nk_find_value(win, title_hash);
+ if (!value.i) {
+ value.i = nk_add_value(ctx, win, title_hash, 0);
+ NK_ASSERT(value.i);
+ if (!value.i) return 0;
+ *value.i = 0;
+ }
+ return nk_group_scrolled_begin(ctx, value.s, title, flags);
+}
+
+NK_API void
+nk_group_end(struct nk_context *ctx)
+{
+ nk_group_scrolled_end(ctx);
+}
+
+NK_API int
+nk_list_view_begin(struct nk_context *ctx, struct nk_list_view *view,
+ const char *title, nk_flags flags, int row_height, int row_count)
+{
+ int title_len;
+ nk_hash title_hash;
+ union {struct nk_scroll *s; nk_uint *i;} value;
+
+ int result;
+ struct nk_window *win;
+ struct nk_panel *layout;
+ const struct nk_style *style;
+ struct nk_vec2 item_spacing;
+
+ NK_ASSERT(ctx);
+ NK_ASSERT(view);
+ NK_ASSERT(title);
+ if (!ctx || !view || !title) return 0;
+
+ win = ctx->current;
+ style = &ctx->style;
+ item_spacing = style->window.spacing;
+ row_height += NK_MAX(0, (int)item_spacing.y);
+
+ /* find persistent group scrollbar offset */
+ title_len = (int)nk_strlen(title);
+ title_hash = nk_murmur_hash(title, (int)title_len, NK_PANEL_GROUP);
+ value.i = nk_find_value(win, title_hash);
+ if (!value.i) {
+ value.i = nk_add_value(ctx, win, title_hash, 0);
+ NK_ASSERT(value.i);
+ if (!value.i) return 0;
+ *value.i = 0;
+ }
+ view->scroll_value = value.s->y;
+ view->scroll_pointer = &value.s->y;
+
+ value.s->y = 0;
+ result = nk_group_scrolled_begin(ctx, value.s, title, flags);
+ win = ctx->current;
+ layout = win->layout;
+
+ view->total_height = row_height * NK_MAX(row_count,1);
+ view->begin = (int)NK_MAX((view->scroll_value / (float)row_height), 0.0f);
+ view->count = (int)NK_MAX(nk_iceilf((layout->clip.h)/(float)row_height), 0);
+ view->end = view->begin + view->count;
+ view->ctx = ctx;
+ return result;
+}
+
+NK_API void
+nk_list_view_end(struct nk_list_view *view)
+{
+ struct nk_context *ctx;
+ struct nk_window *win;
+ struct nk_panel *layout;
+
+ NK_ASSERT(view);
+ NK_ASSERT(view->ctx);
+ NK_ASSERT(view->scroll_pointer);
+ if (!view || !view->ctx) return;
+
+ ctx = view->ctx;
+ win = ctx->current;
+ layout = win->layout;
+ layout->at_y = layout->bounds.y + (float)view->total_height;
+ *view->scroll_pointer = (nk_ushort)(*view->scroll_pointer + view->scroll_value);
+ nk_group_end(view->ctx);
+}
+
/* --------------------------------------------------------------
*
* POPUP
*
* --------------------------------------------------------------*/
NK_API int
-nk_popup_begin(struct nk_context *ctx, struct nk_panel *layout,
- enum nk_popup_type type, const char *title, nk_flags flags, struct nk_rect rect)
+nk_popup_begin(struct nk_context *ctx, enum nk_popup_type type,
+ const char *title, nk_flags flags, struct nk_rect rect)
{
struct nk_window *popup;
struct nk_window *win;
@@ -20106,7 +20691,7 @@ nk_popup_begin(struct nk_context *ctx, struct nk_panel *layout,
popup->parent = win;
popup->bounds = rect;
popup->seq = ctx->seq;
- popup->layout = layout;
+ popup->layout = (struct nk_panel*)nk_create_panel(ctx);
popup->flags = flags;
popup->flags |= NK_WINDOW_BORDER;
if (type == NK_POPUP_DYNAMIC)
@@ -20127,8 +20712,8 @@ nk_popup_begin(struct nk_context *ctx, struct nk_panel *layout,
root = root->parent;
}
win->popup.active = 1;
- layout->offset = &popup->scrollbar;
- layout->parent = win->layout;
+ popup->layout->offset = &popup->scrollbar;
+ popup->layout->parent = win->layout;
return 1;
} else {
/* popup was closed/is invalid so cleanup */
@@ -20142,12 +20727,14 @@ nk_popup_begin(struct nk_context *ctx, struct nk_panel *layout,
win->popup.active = 0;
ctx->memory.allocated = allocated;
ctx->current = win;
+ nk_free_panel(ctx, popup->layout);
+ popup->layout = 0;
return 0;
}
}
NK_INTERN int
-nk_nonblock_begin(struct nk_panel *layout, struct nk_context *ctx,
+nk_nonblock_begin(struct nk_context *ctx,
nk_flags flags, struct nk_rect body, struct nk_rect header,
enum nk_panel_type panel_type)
{
@@ -20198,12 +20785,13 @@ nk_nonblock_begin(struct nk_panel *layout, struct nk_context *ctx,
popup->bounds = body;
popup->parent = win;
- popup->layout = layout;
+ popup->layout = (struct nk_panel*)nk_create_panel(ctx);
popup->flags = flags;
popup->flags |= NK_WINDOW_BORDER;
popup->flags |= NK_WINDOW_DYNAMIC;
popup->seq = ctx->seq;
win->popup.active = 1;
+ NK_ASSERT(popup->layout);
nk_start_popup(ctx, win);
popup->buffer = win->buffer;
@@ -20212,8 +20800,8 @@ nk_nonblock_begin(struct nk_panel *layout, struct nk_context *ctx,
nk_panel_begin(ctx, 0, panel_type);
win->buffer = popup->buffer;
- layout->parent = win->layout;
- layout->offset = &popup->scrollbar;
+ popup->layout->parent = win->layout;
+ popup->layout->offset = &popup->scrollbar;
/* set read only mode to all parent panels */
{struct nk_panel *root;
@@ -20276,7 +20864,7 @@ nk_popup_end(struct nk_context *ctx)
*
* -------------------------------------------------------------- */
NK_API int
-nk_tooltip_begin(struct nk_context *ctx, struct nk_panel *layout, float width)
+nk_tooltip_begin(struct nk_context *ctx, float width)
{
struct nk_window *win;
const struct nk_input *in;
@@ -20300,11 +20888,11 @@ nk_tooltip_begin(struct nk_context *ctx, struct nk_panel *layout, float width)
bounds.x = (in->mouse.pos.x + 1) - win->layout->clip.x;
bounds.y = (in->mouse.pos.y + 1) - win->layout->clip.y;
- ret = nk_popup_begin(ctx, layout, NK_POPUP_DYNAMIC,
+ ret = nk_popup_begin(ctx, NK_POPUP_DYNAMIC,
"__##Tooltip##__", NK_WINDOW_NO_SCROLLBAR|NK_WINDOW_BORDER, bounds);
if (ret) win->layout->flags &= ~(nk_flags)NK_WINDOW_ROM;
win->popup.type = NK_PANEL_TOOLTIP;
- layout->type = NK_PANEL_TOOLTIP;
+ ctx->current->layout->type = NK_PANEL_TOOLTIP;
return ret;
}
@@ -20313,8 +20901,8 @@ nk_tooltip_end(struct nk_context *ctx)
{
NK_ASSERT(ctx);
NK_ASSERT(ctx->current);
- if (!ctx || !ctx->current)
- return;
+ if (!ctx || !ctx->current) return;
+ ctx->current->seq--;
nk_popup_close(ctx);
nk_popup_end(ctx);
}
@@ -20324,7 +20912,6 @@ nk_tooltip(struct nk_context *ctx, const char *text)
{
const struct nk_style *style;
struct nk_vec2 padding;
- struct nk_panel layout;
int text_len;
float text_width;
@@ -20349,7 +20936,7 @@ nk_tooltip(struct nk_context *ctx, const char *text)
text_height = (style->font->height + 2 * padding.y);
/* execute tooltip and fill with text */
- if (nk_tooltip_begin(ctx, &layout, (float)text_width)) {
+ if (nk_tooltip_begin(ctx, (float)text_width)) {
nk_layout_row_dynamic(ctx, (float)text_height, 1);
nk_text(ctx, text, text_len, NK_TEXT_LEFT);
nk_tooltip_end(ctx);
@@ -20361,8 +20948,8 @@ nk_tooltip(struct nk_context *ctx, const char *text)
*
* -------------------------------------------------------------- */
NK_API int
-nk_contextual_begin(struct nk_context *ctx, struct nk_panel *layout,
- nk_flags flags, struct nk_vec2 size, struct nk_rect trigger_bounds)
+nk_contextual_begin(struct nk_context *ctx, nk_flags flags, struct nk_vec2 size,
+ struct nk_rect trigger_bounds)
{
struct nk_window *win;
struct nk_window *popup;
@@ -20405,7 +20992,7 @@ nk_contextual_begin(struct nk_context *ctx, struct nk_panel *layout,
body.h = size.y;
/* start nonblocking contextual popup */
- ret = nk_nonblock_begin(layout, ctx, flags|NK_WINDOW_NO_SCROLLBAR, body,
+ ret = nk_nonblock_begin(ctx, flags|NK_WINDOW_NO_SCROLLBAR, body,
null_rect, NK_PANEL_CONTEXTUAL);
if (ret) win->popup.type = NK_PANEL_CONTEXTUAL;
else {
@@ -20526,11 +21113,7 @@ nk_contextual_close(struct nk_context *ctx)
NK_ASSERT(ctx);
NK_ASSERT(ctx->current);
NK_ASSERT(ctx->current->layout);
- if (!ctx || !ctx->current || !ctx->current->layout)
- return;
-
- if (!ctx->current)
- return;
+ if (!ctx || !ctx->current || !ctx->current->layout) return;
nk_popup_close(ctx);
}
@@ -20550,14 +21133,14 @@ nk_contextual_end(struct nk_context *ctx)
if (panel->flags & NK_WINDOW_DYNAMIC) {
/* Close behavior
This is a bit hack solution since we do not now before we end our popup
- how big it will be. We therefore do not directly now when a
+ how big it will be. We therefore do not directly know when a
click outside the non-blocking popup must close it at that direct frame.
Instead it will be closed in the next frame.*/
struct nk_rect body = {0,0,0,0};
if (panel->at_y < (panel->bounds.y + panel->bounds.h)) {
struct nk_vec2 padding = nk_panel_get_padding(&ctx->style, panel->type);
body = panel->bounds;
- body.y = (panel->at_y + panel->footer_height + panel->border + padding.y);
+ body.y = (panel->at_y + panel->footer_height + panel->border + padding.y + panel->row.height);
body.h = (panel->bounds.y + panel->bounds.h) - body.y;
}
@@ -20578,7 +21161,7 @@ nk_contextual_end(struct nk_context *ctx)
*
* --------------------------------------------------------------*/
NK_INTERN int
-nk_combo_begin(struct nk_panel *layout, struct nk_context *ctx, struct nk_window *win,
+nk_combo_begin(struct nk_context *ctx, struct nk_window *win,
struct nk_vec2 size, int is_clicked, struct nk_rect header)
{
struct nk_window *popup;
@@ -20604,7 +21187,7 @@ nk_combo_begin(struct nk_panel *layout, struct nk_context *ctx, struct nk_window
is_active = (popup && (win->popup.name == hash) && win->popup.type == NK_PANEL_COMBO);
if ((is_clicked && is_open && !is_active) || (is_open && !is_active) ||
(!is_open && !is_active && !is_clicked)) return 0;
- if (!nk_nonblock_begin(layout, ctx, 0, body,
+ if (!nk_nonblock_begin(ctx, 0, body,
(is_clicked && is_open)?nk_rect(0,0,0,0):header, NK_PANEL_COMBO)) return 0;
win->popup.type = NK_PANEL_COMBO;
@@ -20613,8 +21196,8 @@ nk_combo_begin(struct nk_panel *layout, struct nk_context *ctx, struct nk_window
}
NK_API int
-nk_combo_begin_text(struct nk_context *ctx, struct nk_panel *layout,
- const char *selected, int len, struct nk_vec2 size)
+nk_combo_begin_text(struct nk_context *ctx, const char *selected, int len,
+ struct nk_vec2 size)
{
const struct nk_input *in;
struct nk_window *win;
@@ -20699,16 +21282,14 @@ nk_combo_begin_text(struct nk_context *ctx, struct nk_panel *layout,
nk_draw_button_symbol(&win->buffer, &button, &content, ctx->last_widget_state,
&ctx->style.combo.button, sym, style->font);
}
- return nk_combo_begin(layout, ctx, win, size, is_clicked, header);
+ return nk_combo_begin(ctx, win, size, is_clicked, header);
}
-NK_API int nk_combo_begin_label(struct nk_context *ctx, struct nk_panel *layout,
- const char *selected, struct nk_vec2 size)
-{return nk_combo_begin_text(ctx, layout, selected, nk_strlen(selected), size);}
+NK_API int nk_combo_begin_label(struct nk_context *ctx, const char *selected, struct nk_vec2 size)
+{return nk_combo_begin_text(ctx, selected, nk_strlen(selected), size);}
NK_API int
-nk_combo_begin_color(struct nk_context *ctx, struct nk_panel *layout,
- struct nk_color color, struct nk_vec2 size)
+nk_combo_begin_color(struct nk_context *ctx, struct nk_color color, struct nk_vec2 size)
{
struct nk_window *win;
struct nk_style *style;
@@ -20782,12 +21363,11 @@ nk_combo_begin_color(struct nk_context *ctx, struct nk_panel *layout,
nk_draw_button_symbol(&win->buffer, &button, &content, ctx->last_widget_state,
&ctx->style.combo.button, sym, style->font);
}
- return nk_combo_begin(layout, ctx, win, size, is_clicked, header);
+ return nk_combo_begin(ctx, win, size, is_clicked, header);
}
NK_API int
-nk_combo_begin_symbol(struct nk_context *ctx, struct nk_panel *layout,
- enum nk_symbol_type symbol, struct nk_vec2 size)
+nk_combo_begin_symbol(struct nk_context *ctx, enum nk_symbol_type symbol, struct nk_vec2 size)
{
struct nk_window *win;
struct nk_style *style;
@@ -20871,12 +21451,12 @@ nk_combo_begin_symbol(struct nk_context *ctx, struct nk_panel *layout,
nk_draw_button_symbol(&win->buffer, &bounds, &content, ctx->last_widget_state,
&ctx->style.combo.button, sym, style->font);
}
- return nk_combo_begin(layout, ctx, win, size, is_clicked, header);
+ return nk_combo_begin(ctx, win, size, is_clicked, header);
}
NK_API int
-nk_combo_begin_symbol_text(struct nk_context *ctx, struct nk_panel *layout,
- const char *selected, int len, enum nk_symbol_type symbol, struct nk_vec2 size)
+nk_combo_begin_symbol_text(struct nk_context *ctx, const char *selected, int len,
+ enum nk_symbol_type symbol, struct nk_vec2 size)
{
struct nk_window *win;
struct nk_style *style;
@@ -20968,12 +21548,11 @@ nk_combo_begin_symbol_text(struct nk_context *ctx, struct nk_panel *layout,
label.h = header.h - 2 * style->combo.content_padding.y;
nk_widget_text(&win->buffer, label, selected, len, &text, NK_TEXT_LEFT, style->font);
}
- return nk_combo_begin(layout, ctx, win, size, is_clicked, header);
+ return nk_combo_begin(ctx, win, size, is_clicked, header);
}
NK_API int
-nk_combo_begin_image(struct nk_context *ctx, struct nk_panel *layout,
- struct nk_image img, struct nk_vec2 size)
+nk_combo_begin_image(struct nk_context *ctx, struct nk_image img, struct nk_vec2 size)
{
struct nk_window *win;
struct nk_style *style;
@@ -21047,12 +21626,12 @@ nk_combo_begin_image(struct nk_context *ctx, struct nk_panel *layout,
nk_draw_button_symbol(&win->buffer, &bounds, &content, ctx->last_widget_state,
&ctx->style.combo.button, sym, style->font);
}
- return nk_combo_begin(layout, ctx, win, size, is_clicked, header);
+ return nk_combo_begin(ctx, win, size, is_clicked, header);
}
NK_API int
-nk_combo_begin_image_text(struct nk_context *ctx, struct nk_panel *layout,
- const char *selected, int len, struct nk_image img, struct nk_vec2 size)
+nk_combo_begin_image_text(struct nk_context *ctx, const char *selected, int len,
+ struct nk_image img, struct nk_vec2 size)
{
struct nk_window *win;
struct nk_style *style;
@@ -21139,16 +21718,16 @@ nk_combo_begin_image_text(struct nk_context *ctx, struct nk_panel *layout,
label.h = header.h - 2 * style->combo.content_padding.y;
nk_widget_text(&win->buffer, label, selected, len, &text, NK_TEXT_LEFT, style->font);
}
- return nk_combo_begin(layout, ctx, win, size, is_clicked, header);
+ return nk_combo_begin(ctx, win, size, is_clicked, header);
}
-NK_API int nk_combo_begin_symbol_label(struct nk_context *ctx, struct nk_panel *layout,
+NK_API int nk_combo_begin_symbol_label(struct nk_context *ctx,
const char *selected, enum nk_symbol_type type, struct nk_vec2 size)
-{return nk_combo_begin_symbol_text(ctx, layout, selected, nk_strlen(selected), type, size);}
+{return nk_combo_begin_symbol_text(ctx, selected, nk_strlen(selected), type, size);}
-NK_API int nk_combo_begin_image_label(struct nk_context *ctx, struct nk_panel *layout,
+NK_API int nk_combo_begin_image_label(struct nk_context *ctx,
const char *selected, struct nk_image img, struct nk_vec2 size)
-{return nk_combo_begin_image_text(ctx, layout, selected, nk_strlen(selected), img, size);}
+{return nk_combo_begin_image_text(ctx, selected, nk_strlen(selected), img, size);}
NK_API int nk_combo_item_text(struct nk_context *ctx, const char *text, int len,nk_flags align)
{return nk_contextual_item_text(ctx, text, len, align);}
@@ -21184,7 +21763,6 @@ nk_combo(struct nk_context *ctx, const char **items, int count,
{
int i = 0;
int max_height;
- struct nk_panel combo;
struct nk_vec2 item_spacing;
struct nk_vec2 window_padding;
@@ -21199,7 +21777,7 @@ nk_combo(struct nk_context *ctx, const char **items, int count,
max_height = count * item_height + count * (int)item_spacing.y;
max_height += (int)item_spacing.y * 2 + (int)window_padding.y * 2;
size.y = NK_MIN(size.y, (float)max_height);
- if (nk_combo_begin_label(ctx, &combo, items[selected], size)) {
+ if (nk_combo_begin_label(ctx, items[selected], size)) {
nk_layout_row_dynamic(ctx, (float)item_height, 1);
for (i = 0; i < count; ++i) {
if (nk_combo_item_label(ctx, items[i], NK_TEXT_LEFT))
@@ -21216,7 +21794,6 @@ nk_combo_separator(struct nk_context *ctx, const char *items_separated_by_separa
{
int i;
int max_height;
- struct nk_panel combo;
struct nk_vec2 item_spacing;
struct nk_vec2 window_padding;
const char *current_item;
@@ -21237,19 +21814,20 @@ nk_combo_separator(struct nk_context *ctx, const char *items_separated_by_separa
/* find selected item */
current_item = items_separated_by_separator;
- for (i = 0; i < selected; ++i) {
+ for (i = 0; i < count; ++i) {
iter = current_item;
- while (*iter != separator) iter++;
+ while (*iter && *iter != separator) iter++;
length = (int)(iter - current_item);
+ if (i == selected) break;
current_item = iter + 1;
}
- if (nk_combo_begin_text(ctx, &combo, current_item, length, size)) {
+ if (nk_combo_begin_text(ctx, current_item, length, size)) {
current_item = items_separated_by_separator;
nk_layout_row_dynamic(ctx, (float)item_height, 1);
for (i = 0; i < count; ++i) {
iter = current_item;
- while (*iter != separator) iter++;
+ while (*iter && *iter != separator) iter++;
length = (int)(iter - current_item);
if (nk_combo_item_text(ctx, current_item, length, NK_TEXT_LEFT))
selected = i;
@@ -21271,7 +21849,6 @@ nk_combo_callback(struct nk_context *ctx, void(*item_getter)(void*, int, const c
{
int i;
int max_height;
- struct nk_panel combo;
struct nk_vec2 item_spacing;
struct nk_vec2 window_padding;
const char *item;
@@ -21289,7 +21866,7 @@ nk_combo_callback(struct nk_context *ctx, void(*item_getter)(void*, int, const c
size.y = NK_MIN(size.y, (float)max_height);
item_getter(userdata, selected, &item);
- if (nk_combo_begin_label(ctx, &combo, item, size)) {
+ if (nk_combo_begin_label(ctx, item, size)) {
nk_layout_row_dynamic(ctx, (float)item_height, 1);
for (i = 0; i < count; ++i) {
item_getter(userdata, i, &item);
@@ -21327,7 +21904,7 @@ NK_API void nk_combobox_callback(struct nk_context *ctx,
* --------------------------------------------------------------
*/
NK_INTERN int
-nk_menu_begin(struct nk_panel *layout, struct nk_context *ctx, struct nk_window *win,
+nk_menu_begin(struct nk_context *ctx, struct nk_window *win,
const char *id, int is_clicked, struct nk_rect header, struct nk_vec2 size)
{
int is_open = 0;
@@ -21352,7 +21929,7 @@ nk_menu_begin(struct nk_panel *layout, struct nk_context *ctx, struct nk_window
is_active = (popup && (win->popup.name == hash) && win->popup.type == NK_PANEL_MENU);
if ((is_clicked && is_open && !is_active) || (is_open && !is_active) ||
(!is_open && !is_active && !is_clicked)) return 0;
- if (!nk_nonblock_begin(layout, ctx, NK_WINDOW_NO_SCROLLBAR, body, header, NK_PANEL_MENU))
+ if (!nk_nonblock_begin(ctx, NK_WINDOW_NO_SCROLLBAR, body, header, NK_PANEL_MENU))
return 0;
win->popup.type = NK_PANEL_MENU;
@@ -21361,8 +21938,8 @@ nk_menu_begin(struct nk_panel *layout, struct nk_context *ctx, struct nk_window
}
NK_API int
-nk_menu_begin_text(struct nk_context *ctx, struct nk_panel *layout,
- const char *title, int len, nk_flags align, struct nk_vec2 size)
+nk_menu_begin_text(struct nk_context *ctx, const char *title, int len,
+ nk_flags align, struct nk_vec2 size)
{
struct nk_window *win;
const struct nk_input *in;
@@ -21383,16 +21960,16 @@ nk_menu_begin_text(struct nk_context *ctx, struct nk_panel *layout,
if (nk_do_button_text(&ctx->last_widget_state, &win->buffer, header,
title, len, align, NK_BUTTON_DEFAULT, &ctx->style.menu_button, in, ctx->style.font))
is_clicked = nk_true;
- return nk_menu_begin(layout, ctx, win, title, is_clicked, header, size);
+ return nk_menu_begin(ctx, win, title, is_clicked, header, size);
}
-NK_API int nk_menu_begin_label(struct nk_context *ctx, struct nk_panel *layout,
+NK_API int nk_menu_begin_label(struct nk_context *ctx,
const char *text, nk_flags align, struct nk_vec2 size)
-{return nk_menu_begin_text(ctx, layout, text, nk_strlen(text), align, size);}
+{return nk_menu_begin_text(ctx, text, nk_strlen(text), align, size);}
NK_API int
-nk_menu_begin_image(struct nk_context *ctx, struct nk_panel *layout,
- const char *id, struct nk_image img, struct nk_vec2 size)
+nk_menu_begin_image(struct nk_context *ctx, const char *id, struct nk_image img,
+ struct nk_vec2 size)
{
struct nk_window *win;
struct nk_rect header;
@@ -21413,12 +21990,12 @@ nk_menu_begin_image(struct nk_context *ctx, struct nk_panel *layout,
if (nk_do_button_image(&ctx->last_widget_state, &win->buffer, header,
img, NK_BUTTON_DEFAULT, &ctx->style.menu_button, in))
is_clicked = nk_true;
- return nk_menu_begin(layout, ctx, win, id, is_clicked, header, size);
+ return nk_menu_begin(ctx, win, id, is_clicked, header, size);
}
NK_API int
-nk_menu_begin_symbol(struct nk_context *ctx, struct nk_panel *layout,
- const char *id, enum nk_symbol_type sym, struct nk_vec2 size)
+nk_menu_begin_symbol(struct nk_context *ctx, const char *id,
+ enum nk_symbol_type sym, struct nk_vec2 size)
{
struct nk_window *win;
const struct nk_input *in;
@@ -21439,12 +22016,12 @@ nk_menu_begin_symbol(struct nk_context *ctx, struct nk_panel *layout,
if (nk_do_button_symbol(&ctx->last_widget_state, &win->buffer, header,
sym, NK_BUTTON_DEFAULT, &ctx->style.menu_button, in, ctx->style.font))
is_clicked = nk_true;
- return nk_menu_begin(layout, ctx, win, id, is_clicked, header, size);
+ return nk_menu_begin(ctx, win, id, is_clicked, header, size);
}
NK_API int
-nk_menu_begin_image_text(struct nk_context *ctx, struct nk_panel *layout,
- const char *title, int len, nk_flags align, struct nk_image img, struct nk_vec2 size)
+nk_menu_begin_image_text(struct nk_context *ctx, const char *title, int len,
+ nk_flags align, struct nk_image img, struct nk_vec2 size)
{
struct nk_window *win;
struct nk_rect header;
@@ -21466,16 +22043,16 @@ nk_menu_begin_image_text(struct nk_context *ctx, struct nk_panel *layout,
header, img, title, len, align, NK_BUTTON_DEFAULT, &ctx->style.menu_button,
ctx->style.font, in))
is_clicked = nk_true;
- return nk_menu_begin(layout, ctx, win, title, is_clicked, header, size);
+ return nk_menu_begin(ctx, win, title, is_clicked, header, size);
}
-NK_API int nk_menu_begin_image_label(struct nk_context *ctx, struct nk_panel *layout,
+NK_API int nk_menu_begin_image_label(struct nk_context *ctx,
const char *title, nk_flags align, struct nk_image img, struct nk_vec2 size)
-{return nk_menu_begin_image_text(ctx, layout, title, nk_strlen(title), align, img, size);}
+{return nk_menu_begin_image_text(ctx, title, nk_strlen(title), align, img, size);}
NK_API int
-nk_menu_begin_symbol_text(struct nk_context *ctx, struct nk_panel *layout,
- const char *title, int len, nk_flags align, enum nk_symbol_type sym, struct nk_vec2 size)
+nk_menu_begin_symbol_text(struct nk_context *ctx, const char *title, int len,
+ nk_flags align, enum nk_symbol_type sym, struct nk_vec2 size)
{
struct nk_window *win;
struct nk_rect header;
@@ -21497,12 +22074,12 @@ nk_menu_begin_symbol_text(struct nk_context *ctx, struct nk_panel *layout,
if (nk_do_button_text_symbol(&ctx->last_widget_state, &win->buffer,
header, sym, title, len, align, NK_BUTTON_DEFAULT, &ctx->style.menu_button,
ctx->style.font, in)) is_clicked = nk_true;
- return nk_menu_begin(layout, ctx, win, title, is_clicked, header, size);
+ return nk_menu_begin(ctx, win, title, is_clicked, header, size);
}
-NK_API int nk_menu_begin_symbol_label(struct nk_context *ctx, struct nk_panel *layout,
+NK_API int nk_menu_begin_symbol_label(struct nk_context *ctx,
const char *title, nk_flags align, enum nk_symbol_type sym, struct nk_vec2 size )
-{return nk_menu_begin_symbol_text(ctx, layout, title, nk_strlen(title), align,sym,size);}
+{return nk_menu_begin_symbol_text(ctx, title, nk_strlen(title), align,sym,size);}
NK_API int nk_menu_item_text(struct nk_context *ctx, const char *title, int len, nk_flags align)
{return nk_contextual_item_text(ctx, title, len, align);}