aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHanspeter Portner <dev@open-music-kontrollers.ch>2017-07-05 22:53:05 +0200
committerHanspeter Portner <dev@open-music-kontrollers.ch>2017-07-05 22:53:05 +0200
commit478835fd732a9123710340c5feadf445e8e911ff (patch)
tree2fd981adbedd0c8a474f2f798077efe472720a61
parentb280370fc8e89bfc835ca99d16c3298d2e7af6a8 (diff)
downloadsherlock.lv2-478835fd732a9123710340c5feadf445e8e911ff.tar.xz
Squashed 'nuklear/' changes from b280370..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. fe785e5 Fix segfault git-subtree-dir: nuklear git-subtree-split: 12257a487ecd6adbc2c43a58ff407bab10387807
-rw-r--r--CHANGELOG.md21
-rw-r--r--demo/calculator.c6
-rw-r--r--demo/d3d11/nuklear_d3d11.h2
-rw-r--r--demo/gdi/nuklear_gdi.h2
-rw-r--r--demo/gdip/nuklear_gdip.h2
-rw-r--r--demo/overview.c2
-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/nuklear_sdl_gl2.h4
-rw-r--r--demo/sdl_opengl3/nuklear_sdl_gl3.h4
-rw-r--r--demo/x11_opengl2/nuklear_xlib_gl2.h2
-rw-r--r--demo/x11_opengl3/nuklear_xlib_gl3.h2
-rw-r--r--example/file_browser.c2
-rw-r--r--nuklear.h897
15 files changed, 665 insertions, 912 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 4daf5fb..17f1858 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,4 +1,25 @@
# 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
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/nuklear_d3d11.h b/demo/d3d11/nuklear_d3d11.h
index 68b067f..efddf0d 100644
--- a/demo/d3d11/nuklear_d3d11.h
+++ b/demo/d3d11/nuklear_d3d11.h
@@ -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/nuklear_gdi.h b/demo/gdi/nuklear_gdi.h
index e2792e4..6d3a84a 100644
--- a/demo/gdi/nuklear_gdi.h
+++ b/demo/gdi/nuklear_gdi.h
@@ -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/nuklear_gdip.h b/demo/gdip/nuklear_gdip.h
index 592887a..66ccc0d 100644
--- a/demo/gdip/nuklear_gdip.h
+++ b/demo/gdip/nuklear_gdip.h
@@ -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/overview.c b/demo/overview.c
index 7772378..e271318 100644
--- a/demo/overview.c
+++ b/demo/overview.c
@@ -36,7 +36,7 @@ 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", NK_TEXT_LEFT, nk_vec2(120, 200)))
{
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/nuklear_sdl_gl2.h b/demo/sdl_opengl2/nuklear_sdl_gl2.h
index 94bfca8..45c5970 100644
--- a/demo/sdl_opengl2/nuklear_sdl_gl2.h
+++ b/demo/sdl_opengl2/nuklear_sdl_gl2.h
@@ -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/nuklear_sdl_gl3.h b/demo/sdl_opengl3/nuklear_sdl_gl3.h
index a55c45c..17c0899 100644
--- a/demo/sdl_opengl3/nuklear_sdl_gl3.h
+++ b/demo/sdl_opengl3/nuklear_sdl_gl3.h
@@ -382,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_opengl2/nuklear_xlib_gl2.h b/demo/x11_opengl2/nuklear_xlib_gl2.h
index 38787df..a814455 100644
--- a/demo/x11_opengl2/nuklear_xlib_gl2.h
+++ b/demo/x11_opengl2/nuklear_xlib_gl2.h
@@ -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/nuklear_xlib_gl3.h b/demo/x11_opengl3/nuklear_xlib_gl3.h
index f176c5f..b0f56b9 100644
--- a/demo/x11_opengl3/nuklear_xlib_gl3.h
+++ b/demo/x11_opengl3/nuklear_xlib_gl3.h
@@ -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/file_browser.c b/example/file_browser.c
index 6ca0e85..ece4cb8 100644
--- a/example/file_browser.c
+++ b/example/file_browser.c
@@ -403,7 +403,6 @@ file_browser_run(struct file_browser *browser, struct nk_context *ctx)
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;
@@ -503,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/nuklear.h b/nuklear.h
index 93094da..b1f229e 100644
--- a/nuklear.h
+++ b/nuklear.h
@@ -1,5 +1,5 @@
/*
- Nuklear - v1.17 - 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
@@ -270,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
@@ -305,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))
+
/*
* ===============================================================
*
@@ -425,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;};
@@ -438,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};
@@ -482,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,
@@ -649,7 +678,6 @@ 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 */
@@ -737,6 +765,12 @@ NK_API float nk_layout_ratio_from_pixel(struct nk_context*, f
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)
@@ -746,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);
@@ -773,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);
@@ -783,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);
@@ -1099,7 +1146,7 @@ NK_API const char* nk_utf_at(const char *buffer, int length, int in
1.) Using your own implementation without vertex buffer output
--------------------------------------------------------------
- So first of the easiest way to do font handling is by just providing a
+ 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
@@ -1109,20 +1156,20 @@ NK_API const char* nk_utf_at(const char *buffer, int length, int in
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;
- }
+ 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_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);
+ struct nk_context ctx;
+ nk_init_default(&ctx, &font);
2.) Using your own implementation with vertex buffer output
--------------------------------------------------------------
@@ -1134,35 +1181,35 @@ NK_API const char* nk_utf_at(const char *buffer, int length, int in
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 = ...;
- }
+ 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_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);
+ struct nk_context ctx;
+ nk_init_default(&ctx, &font);
3.) Nuklear font baker
------------------------------------
@@ -1185,8 +1232,8 @@ NK_API const char* nk_utf_at(const char *buffer, int length, int in
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 and font config inside
- the font atlas and allows to reuse the font atlas. If you don't want to reuse
+ 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).
@@ -1616,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;
@@ -1634,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 */
@@ -1707,7 +1767,7 @@ NK_API void nk_textedit_redo(struct nk_text_edit*);
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 onl draw and
+ 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 {
@@ -2076,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 */
@@ -2088,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);
@@ -2106,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);
@@ -2605,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;
@@ -2754,7 +2815,7 @@ struct nk_window {
*
* 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 in compile time.
+ * which can be changed at compile time.
*/
#ifndef NK_BUTTON_BEHAVIOR_STACK_SIZE
#define NK_BUTTON_BEHAVIOR_STACK_SIZE 8
@@ -2825,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;
@@ -2847,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];
};
@@ -2870,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
@@ -2884,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;
@@ -2907,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
@@ -3197,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;
}
@@ -4446,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
}
@@ -4462,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
}
@@ -4624,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);
}
@@ -4967,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};
@@ -6008,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;
@@ -6017,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
@@ -6419,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;
@@ -8993,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;
@@ -10323,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);
@@ -10581,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;
}
@@ -11021,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);
@@ -11096,7 +11176,7 @@ nk_font_atlas_end(struct nk_font_atlas *atlas, nk_handle texture,
}
if (null) {
null->texture = texture;
- null->uv.x = (atlas->custom.x + 0.5f)/(float)atlas->tex_width,
+ 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) {
@@ -11592,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;
}
@@ -11865,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
@@ -12009,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)
@@ -12056,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)
@@ -12171,6 +12250,8 @@ retry:
--state->cursor;
}} break;
}
+
+ state->lexer.needs_refresh = 1;
}
NK_INTERN void
@@ -12563,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)
@@ -12573,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);
@@ -12591,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));
}
}
@@ -13979,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);
@@ -14016,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++;
@@ -14050,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,
@@ -14070,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);
@@ -14083,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 */
@@ -14102,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)
@@ -14207,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;
}}
}
@@ -14238,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;
@@ -14303,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);
@@ -14336,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;
}
@@ -14397,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);
}
@@ -14440,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 */
@@ -14447,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){
@@ -14456,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) {
@@ -14470,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))
@@ -14479,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);
}
}
@@ -14529,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;
@@ -14547,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;
@@ -15601,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];
@@ -15618,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);
@@ -15981,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 */
@@ -16452,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;
}
}
@@ -16696,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 */
@@ -16853,7 +17056,7 @@ nk_link_page_element_into_freelist(struct nk_context *ctx,
NK_INTERN void
nk_free_page_element(struct nk_context *ctx, struct nk_page_element *elem)
{
- /* fixed size pool so just add to free list */
+ /* we have a pool so just add to free list */
if (ctx->use_pool) {
nk_link_page_element_into_freelist(ctx, elem);
return;
@@ -16967,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;
@@ -17266,11 +17469,14 @@ nk_begin_titled(struct nk_context *ctx, const char *name, const char *title,
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;
}
@@ -17821,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;
@@ -17848,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;
@@ -18171,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 */
@@ -18259,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;
@@ -18277,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);
@@ -18311,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;
@@ -18379,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;
@@ -18410,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
@@ -18770,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)
@@ -18892,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));}
@@ -18959,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;
@@ -18976,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;
@@ -19004,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;
@@ -19033,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);
@@ -19041,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;
@@ -19067,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);
@@ -19075,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
@@ -19240,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;
@@ -19497,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;
}
@@ -19963,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) &&
@@ -19987,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)) {
@@ -20157,40 +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, 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);
- /* 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;
@@ -20198,8 +20448,8 @@ nk_group_begin(struct nk_context *ctx, const char *title, nk_flags flags)
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 = (struct nk_panel*)nk_create_panel(ctx);
ctx->current = &panel;
@@ -20207,15 +20457,16 @@ nk_group_begin(struct nk_context *ctx, const char *title, nk_flags flags)
win->buffer = panel.buffer;
win->buffer.clip = panel.layout->clip;
- panel.layout->offset = value.s;
+ 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;
@@ -20277,6 +20528,111 @@ 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
@@ -20371,6 +20727,8 @@ nk_popup_begin(struct nk_context *ctx, enum nk_popup_type type,
win->popup.active = 0;
ctx->memory.allocated = allocated;
ctx->current = win;
+ nk_free_panel(ctx, popup->layout);
+ popup->layout = 0;
return 0;
}
}
@@ -20543,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);
}
@@ -20755,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);
}
@@ -20779,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;
}
@@ -21460,10 +21814,11 @@ 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;
}
@@ -21472,7 +21827,7 @@ nk_combo_separator(struct nk_context *ctx, const char *items_separated_by_separa
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;