Compare commits

...

75 Commits

Author SHA1 Message Date
Xeverous
a315d25b4c
Update Nuklear 2024-11-07 19:45:55 -05:00
Alexander W. Schultz
a13a60e998 updates nuklear.h after paq'ing 2024-11-07 19:24:40 -05:00
Alexander W. Schultz
2a4e3fbc92 updates gitignore 2024-11-07 19:24:40 -05:00
Alexander W. Schultz
80805cdfc0 updates makefile to handle documentaion generation a little better 2024-11-07 19:24:40 -05:00
Alexander W. Schultz
d1821eebc7 removing old documentation generator 2024-11-07 19:24:40 -05:00
Alexander W. Schultz
7cb39a360d C89 style comment blocks
nuklear.h has been converted to C89 style comment blocks instead of the
amalgamation it was before (presummably a relic of the other
documentation system).

examples compile. more testing is required.
2024-11-07 19:24:40 -05:00
Alexander W. Schultz
d3ea630a84 Adds HEADER to the doxygen output
HEADER is the intro API section of the paq'd files, which is the most
critical part of our documentation. Ideally, this file needs to stay the
same style because it needs to be incorporated into the header file;
however, we can make a minor modification to allow doxygen to render it.
with this commit, I change the name to HEADER.c to allow doxygen
processing. This shouldn't have any affect on the generated paq file.
Eventually, I would like to move this HEADER file into a different name
and the overall mainpage of the documentation.
2024-11-07 19:24:40 -05:00
Alexander W. Schultz
2ac678a94d converts nuklear.h to doxygen comment styles
the difference isnt staggering by any means. the original comment blocks
had most everything we needed. More work is required and there are still
questions to be had about how much information / styling is desired to
be retained in the code comments, verses removing some styling because
doxygen handles that conversion into html with styling automatically.
2024-11-07 19:24:40 -05:00
Alexander W. Schultz
050fbbaf9a whoops. forgot to add Doxyfile to previous commit 2024-11-07 19:24:40 -05:00
Alexander W. Schultz
3723ca585b adds source file processing to doxygen.
this commit adds the proper source file directory, so now doxygen picks
up all of the C files for processing. Some minor cleanup and file
exclusions have also been added such that things like `paq.sh` and sub
`Readme.md` files are not picked up.
2024-11-07 19:24:40 -05:00
Alexander W. Schultz
abb3e406aa initial commit of doxygen files
Adds initial doxyfile for doxygen configuration. Has some basic settings
for getting up and running with decent results.

Also, the beautiful doxygen-awesome-css project has been included in the
makefile such that we can pull (on your own time) a nice package to make
the doxygen output so much prettier to look at than the default.
2024-11-07 19:24:40 -05:00
Rob Loach
d5969abb86
Merge pull request #728 from Immediate-Mode-UI/revert-721-const-correctness
Revert "const correctness in public API"
2024-11-07 19:24:02 -05:00
Rob Loach
d123122a27
Revert "const correctness in public API" 2024-11-07 19:22:55 -05:00
Rob Loach
f169ee68d1
Merge pull request #721 from Xeverous/const-correctness
const correctness in public API
2024-11-07 18:52:54 -05:00
Rob Loach
985ddcbccb
Merge pull request #723 from awschult002/sdl_intrin
disables intrinsics on SDL demos
2024-11-05 09:43:49 -05:00
Alexander W. Schultz
b6a7791d13 disables intrinsics on SDL demos
SDL library has an issue where it expects intrinsics headers to be
provided, but intrinsics are not exactly part of a standard, so there is
no guarantee that they will be available. As such, the library allows
you to turn them off. I am disabling them to allow for better
portability and ease of compilation.
2024-10-20 23:17:02 -04:00
Antti Keränen
6566d9075d
Improve Vulkan demo (#717)
* demo: fix errors and warnings in GLFW Vulkan demo

* demo: improve resize handling in GLFW Vulkan demo

On my machine (x86_64 Linux, Wayland) VK_SUBOPTIMAL or
VK_OUT_OF_DATE_KHR were never returned so the resizing of the swapchain
never happened.

Fix by using GLFW's resize callback to detect a window resize and a
swapchain recreation. Vulkan tutorial uses the same approach.

fb_scale was never used in the Vulkan backend, so it was removed.

* demo: fix copy&paste typo in GLFW Vulkan demo

* demo: sync nuklear_glfw_vulkan.in.h with nuklear_glfw_vulkan.h

Over time people have not been noticing that the expected workflow is to
build nuklear_glfw_vulkan.h from nuklear_glfw_vulkan.in.h
2024-10-19 04:04:28 -04:00
Antti Keränen
b2ffce5131 demo/backend: add vulkan SDL backend and demo
Based on other SDL demos and GLFW Vulkan demo.
2024-10-19 04:03:54 -04:00
Xeverous
748f0dafe7 const correctness in public API 2024-10-15 19:27:56 +02:00
Stephen-Zulauf
03198a016b
Add Catppucin color styles (#695) 2024-10-02 23:08:10 -04:00
Rob Loach
8f45d37cf6 demo: Rename zahnrad binaries to demo 2024-10-02 23:02:35 -04:00
JS Deck
e360f267ed add up/down/ctrl-b/ctrl-e key handling to d3d11 demo 2024-10-02 12:12:51 -04:00
Rob Loach
2ad47c08f1 Rebuild nuklear.h 2024-09-30 13:41:55 -04:00
Rob Loach
0a28e3002b Fix incompatible pointer types warning 2024-09-30 13:33:55 -04:00
Kirill Rodriguez
fa9f257c7b untyped pointers fail when you use c++ compiler 2024-09-29 01:59:17 -04:00
Rob Loach
2156b95a5d
Merge pull request #709 from ryuukk/rounding
Round layout widget position to nearest 0
2024-09-29 01:59:01 -04:00
ryuukk
b6e261b508 Round layout widget position to nearest 0 2024-09-28 21:44:42 +02:00
Rob Loach
964cc81fad
Merge pull request #697 from ryuukk/patch-2
Update proggyfont urls
2024-09-25 11:34:03 -04:00
ryuukk
5c89e05538
Change proggyfont urls 2024-09-23 15:32:17 +02:00
Rob Loach
ca8aaf3f65
Merge pull request #690 from lockie/master
allegro5: take image region into account for NK_COMMAND_IMAGE
2024-09-19 10:56:09 -04:00
Andrew Kravchuk
a02e1824b8
allegro5: correctly handle subimages NK_COMMAND_IMAGE 2024-09-18 09:07:28 +02:00
Andrew Kravchuk
e4901c5358
allegro5: correctly handle zero region in NK_COMMAND_IMAGE 2024-09-18 06:46:14 +02:00
Andrew Kravchuk
19dc0131f3
allegro5: take image region into account for NK_COMMAND_IMAGE 2024-09-17 20:52:58 +02:00
Rob Loach
4ffef5eb11
Merge pull request #689 from mark-summerfield/patch-1
Update nuklear_xcb.h: eliminate two warnings in C99 mode
2024-09-14 14:20:37 -04:00
Mark
f3de6a0cb3
Update nuklear_xcb.h: eliminate two warnings in C99 mode
Function `NK_API int nk_cairo_render(struct nk_cairo_context *cairo_ctx, struct nk_context *nk_ctx)` returns an int but `return;` is used twice. Now replaced with `return nk_false;`. This makes for clean compilation with both C89 _and_ C99.
2024-09-14 10:37:45 +01:00
Rob Loach
18f7e7a948
demo: Add headers to overview.c (#684)
This adds the required C headers directly to the top of the overview.c demo so that they don't need to be added in the renders themselves.
2024-09-08 12:34:09 -04:00
Rob Loach
ec113a0f7c
Merge pull request #680 from Immediate-Mode-UI/demo-overview--time
demo: Add time.h to overview.c
2024-09-04 11:43:17 -04:00
Rob Loach
4373fd03cc
Merge pull request #682 from PROP65/func_fix
Fixes for nk_strtod, nk_strtof, and nk_strtoi
2024-09-03 20:07:35 -04:00
PROP 65
19bb57b893
Update nuklear.h 2024-09-03 03:46:11 +00:00
PROP 65
cb9dc9635a
Update nuklear_util.c 2024-09-03 03:39:49 +00:00
Rob Loach
458112efd3
demo: Add time.h to overview.c
This adds the `time.h` include to the top of overview.c so that the renders don't need to include it manually.
2024-09-02 14:15:44 -04:00
Rob Loach
f7847e6024
Add delta_time_seconds to a few renderers (#628) 2024-08-29 22:22:55 -04:00
Rob Loach
9eeb910d01
Merge pull request #672 from PROP65/delta
Add delta_time_seconds to X11 and SFML renderers
2024-08-29 10:50:22 -04:00
PROP 65
751d2bfbff
Update nuklear_sdl_gl2.h 2024-08-29 03:17:04 +00:00
PROP 65
1d03d421c5
Update nuklear_sdl_gl3.h 2024-08-29 03:16:51 +00:00
PROP 65
f180a5c423
Update nuklear_sdl_gles2.h 2024-08-29 03:16:40 +00:00
PROP 65
49fd23e13c
sfml_gl2: add delta_time_seconds 2024-08-29 03:15:45 +00:00
PROP 65
81ae780756
sfml_gl3: add delta_time_seconds 2024-08-29 03:14:25 +00:00
PROP 65
4bfc027e08
xlib: add delta_time_seconds 2024-08-29 03:13:45 +00:00
PROP 65
c3fe64a487
xlib_gl2: add delta_time_seconds 2024-08-29 03:13:22 +00:00
PROP 65
42b9ea7943
xlib_gl3: add delta_time_seconds 2024-08-29 03:11:10 +00:00
PROP 65
d043803932
xlib: add delta_time_seconds 2024-08-29 03:09:28 +00:00
PROP 65
b3b400895d
Add delta_time_seconds to the SDL OpenGL renderers (#671)
RE: #627
2024-08-28 11:18:48 -04:00
Rob Loach
b1c2227fa9
Merge pull request #669 from PROP65/knob
New Widget: Knobs
2024-08-28 11:01:42 -04:00
PROP 65
1f0c22cc10
Merge branch 'Immediate-Mode-UI:master' into knob 2024-08-28 00:51:03 +00:00
Rob Loach
29b7be6de0
knob: Add color styles 2024-08-27 11:43:39 -04:00
Rob Loach
c3282bf274
Merge pull request #665 from PROP65/assert_delete
Remove unnecessary assert
2024-08-26 11:30:45 -04:00
PROP 65
eab9f225e6
Move copyright info to its own file (#667)
* Create LICENSE

* replace license with link to license
2024-08-26 11:29:47 -04:00
PROP 65
97fb6fffd6
Rebuild nuklear.h 2024-08-19 01:13:57 +00:00
PROP 65
8306b32465
Update nuklear_style.c 2024-08-19 01:10:19 +00:00
PROP 65
a6973c2d64
Update nuklear_style.c 2024-08-19 01:08:17 +00:00
PROP 65
48434308c6
Update nuklear_style.c 2024-08-19 01:06:30 +00:00
PROP 65
820eca5858
Update overview.c 2024-08-19 01:03:06 +00:00
PROP 65
0ddaeb7043
add atan(x) and atan2(y,x) 2024-08-19 01:00:05 +00:00
PROP 65
b7125d9b10
add atan(x) and atan2(y,x) 2024-08-19 00:58:22 +00:00
PROP 65
76ad5ebd3b
add knobs 2024-08-19 00:54:52 +00:00
PROP 65
3d5eb27f85
add knob widget 2024-08-19 00:48:39 +00:00
PROP 65
d0c557dd34
Update paq.sh 2024-08-19 00:47:46 +00:00
PROP 65
728e44b0a2
Update paq.bat 2024-08-19 00:47:45 +00:00
PROP 65
c048d6fbc3
add knobs 2024-08-19 00:44:47 +00:00
PROP 65
6556884274
Update nuklear.h 2024-08-14 00:38:46 +00:00
PROP 65
a33d01bd18
Update nuklear_window.c 2024-08-14 00:38:41 +00:00
Rob Loach
be0a3f6141
Fix for NK_OFFSETOF on Emscripten (#663)
Fixes the following error with Emscripten, where `__builtin_offset` isn't available. This disables the usage of it when on Emscripten.

```
nuklear.h:8978:38: error: defining a type within '__builtin_offsetof' is a C23 extension [-Werror,-Wc23-extensions]
 8978 |     NK_STORAGE const nk_size align = NK_ALIGNOF(struct nk_command);
```
2024-07-29 11:07:32 -04:00
Rob Loach
2795d90707
Merge pull request #661 from bolt-blue/glfw_demo_quickfix
Quickfix glfw shift-key handling
2024-07-23 11:40:40 -04:00
bolt
0883109476 Quickfix glfw shift-key handling
All of the glfw demo headers unset shift keypresses when the ctrl key is not
also down.
I can't think of a reason this would be desired and it appears no other demo
code does this.
Unless I'm mistaken, simply removing these lines leaves us with the desired
behaviour.
2024-07-11 12:33:37 +01:00
76 changed files with 16693 additions and 10073 deletions

1
.gitignore vendored
View File

@ -6,6 +6,7 @@ docs/xml
docs/build
docs/src
doc/doc*
doc/*
*.tmp
*.swo
*.swp

39
LICENSE Normal file
View File

@ -0,0 +1,39 @@
------------------------------------------------------------------------------
This software is available under 2 licenses -- choose whichever you prefer.
------------------------------------------------------------------------------
ALTERNATIVE A - MIT License
Copyright (c) 2017 Micha Mettke
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
------------------------------------------------------------------------------
ALTERNATIVE B - Public Domain (www.unlicense.org)
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or distribute this
software, either in source code form or as a compiled binary, for any purpose,
commercial or non-commercial, and by any means.
In jurisdictions that recognize copyright laws, the author or authors of this
software dedicate any and all copyright interest in the software to the public
domain. We make this dedication for the benefit of the public at large and to
the detriment of our heirs and successors. We intend this dedication to be an
overt act of relinquishment in perpetuity of all present and future rights to
this software under copyright law.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-----------------------------------------------------------------------------

36
Makefile Normal file
View File

@ -0,0 +1,36 @@
docs_path:=./doc
doxyfile:=$(docs_path)/Doxyfile
.PHONY: usage
usage:
echo "make docs to create documentation"
echo "make nuke to rebuild the single header nuklear.h from source"
echo "make all to re-pack the header and create documentation"
echo "make install to "install" man files"
docs: $(docs_path)/html/index.html
$(docs_path)/html/index.html: $(docs_path)/doxygen-awesome-css/doxygen-awesome.css $(doxyfile)
doxygen $(doxyfile)
$(doxyfile):
doxygen -g $@
$(docs_path)/doxygen-awesome-css/doxygen-awesome.css:
git clone https://github.com/jothepro/doxygen-awesome-css.git $(docs_path)/doxygen-awesome-css --branch v2.3.4
nuke:
cd ./src && ./paq.sh
all: docs nuke
install:
clean:
rm -rf $(docs_path)/html

View File

@ -126,47 +126,8 @@ Barrett for his amazing single-header [libraries](https://github.com/nothings/st
in libraries and brought me to create some of my own. Finally Apoorva Joshi for his single-header [file packer](http://apoorvaj.io/single-header-packer.html).
## License
```
------------------------------------------------------------------------------
This software is available under 2 licenses -- choose whichever you prefer.
------------------------------------------------------------------------------
ALTERNATIVE A - MIT License
Copyright (c) 2017 Micha Mettke
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
------------------------------------------------------------------------------
ALTERNATIVE B - Public Domain (www.unlicense.org)
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or distribute this
software, either in source code form or as a compiled binary, for any purpose,
commercial or non-commercial, and by any means.
In jurisdictions that recognize copyright laws, the author or authors of this
software dedicate any and all copyright interest in the software to the public
domain. We make this dedication for the benefit of the public at large and to
the detriment of our heirs and successors. We intend this dedication to be an
overt act of relinquishment in perpetuity of all present and future rights to
this software under copyright law.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-----------------------------------------------------------------------------
```
Nuklear is avaliable under either the MIT License or public domain.
See [LICENSE](LICENSE) for more info.
## Reviewers guide

View File

@ -66,6 +66,7 @@ static struct nk_allegro5 {
int touch_down_id;
struct nk_context ctx;
struct nk_buffer cmds;
float delta_time_seconds_last;
} allegro5;
@ -177,6 +178,11 @@ nk_allegro5_render()
{
const struct nk_command *cmd;
/* Update the timer */
float now = (float)al_get_time();
allegro5.ctx.delta_time_seconds = now - allegro5.delta_time_seconds_last;
allegro5.delta_time_seconds_last = now;
al_set_target_backbuffer(allegro5.dsp);
nk_foreach(cmd, &allegro5.ctx)
@ -318,7 +324,17 @@ nk_allegro5_render()
} break;
case NK_COMMAND_IMAGE: {
const struct nk_command_image *i = (const struct nk_command_image *)cmd;
al_draw_bitmap_region(i->img.handle.ptr, 0, 0, i->w, i->h, i->x, i->y, 0);
nk_ushort
x = i->img.region[0],
y = i->img.region[1],
w = i->img.region[2],
h = i->img.region[3];
if(w == 0 && h == 0)
{
x = i->x; y = i->y; w = i->w; h = i->h;
}
al_draw_scaled_bitmap(i->img.handle.ptr,
x, y, w, h, i->x, i->y, i->w, i->h, 0);
} break;
case NK_COMMAND_RECT_MULTI_COLOR:
default: break;
@ -498,6 +514,7 @@ nk_allegro5_init(NkAllegro5Font *allegro5font, ALLEGRO_DISPLAY *dsp,
allegro5.height = height;
allegro5.is_touch_down = 0;
allegro5.touch_down_id = -1;
allegro5.delta_time_seconds_last = (float)al_get_time();
nk_init_default(&allegro5.ctx, font);
allegro5.ctx.clip.copy = nk_allegro5_clipboard_copy;

View File

@ -1,9 +1,12 @@
#include <limits.h> /* INT_MAX */
#include <time.h> /* struct tm, localtime */
static int
overview(struct nk_context *ctx)
{
/* window flags */
static nk_bool show_menu = nk_true;
static nk_flags window_flags = NK_WINDOW_TITLE|NK_WINDOW_BORDER|NK_WINDOW_SCALABLE|NK_WINDOW_MOVABLE|NK_WINDOW_MINIMIZABLE;
static nk_flags window_flags = NK_WINDOW_TITLE|NK_WINDOW_BORDER|NK_WINDOW_SCALABLE|NK_WINDOW_MOVABLE|NK_WINDOW_MINIMIZABLE|NK_WINDOW_SCROLL_AUTO_HIDE;
nk_flags actual_window_flags = 0;
/* widget flags */
@ -15,7 +18,8 @@ overview(struct nk_context *ctx)
#ifdef INCLUDE_STYLE
/* styles */
static const char* themes[] = {"Black", "White", "Red", "Blue", "Dark", "Dracula"};
static const char* themes[] = {"Black", "White", "Red", "Blue", "Dark", "Dracula",
"Catppucin Latte", "Catppucin Frappe", "Catppucin Macchiato", "Catppucin Mocha"};
static int current_theme = 0;
#endif
@ -225,6 +229,8 @@ overview(struct nk_context *ctx)
/* Basic widgets */
static int int_slider = 5;
static float float_slider = 2.5f;
static int int_knob = 5;
static float float_knob = 2.5f;
static nk_size prog_value = 40;
static float property_float = 2;
static int property_int = 10;
@ -264,6 +270,12 @@ overview(struct nk_context *ctx)
nk_labelf(ctx, NK_TEXT_LEFT, "Progressbar: %u" , (int)prog_value);
nk_progress(ctx, &prog_value, 100, NK_MODIFIABLE);
nk_layout_row(ctx, NK_STATIC, 40, 2, ratio);
nk_labelf(ctx, NK_TEXT_LEFT, "Knob int: %d", int_knob);
nk_knob_int(ctx, 0, &int_knob, 10, 1, NK_DOWN, 60.0f);
nk_labelf(ctx, NK_TEXT_LEFT, "Knob float: %.2f", float_knob);
nk_knob_float(ctx, 0, &float_knob, 5.0, 0.5f, NK_DOWN, 60.0f);
nk_layout_row(ctx, NK_STATIC, 25, 2, ratio);
nk_label(ctx, "Property float:", NK_TEXT_LEFT);
nk_property_float(ctx, "Float:", 0, &property_float, 64.0f, 0.1f, 0.2f);

View File

@ -1,8 +1,18 @@
enum theme {THEME_BLACK, THEME_WHITE, THEME_RED, THEME_BLUE, THEME_DARK, THEME_DRACULA};
enum theme {
THEME_BLACK,
THEME_WHITE,
THEME_RED,
THEME_BLUE,
THEME_DARK,
THEME_DRACULA,
THEME_CATPPUCCIN_LATTE,
THEME_CATPPUCCIN_FRAPPE,
THEME_CATPPUCCIN_MACCHIATO,
THEME_CATPPUCCIN_MOCHA
static void
set_style(struct nk_context *ctx, enum theme theme)
{
};
static void set_style(struct nk_context *ctx, enum theme theme) {
struct nk_color table[NK_COLOR_COUNT];
if (theme == THEME_WHITE) {
table[NK_COLOR_TEXT] = nk_rgba(70, 70, 70, 255);
@ -33,6 +43,10 @@ set_style(struct nk_context *ctx, enum theme theme)
table[NK_COLOR_SCROLLBAR_CURSOR_HOVER] = nk_rgba(150, 150, 150, 255);
table[NK_COLOR_SCROLLBAR_CURSOR_ACTIVE] = nk_rgba(160, 160, 160, 255);
table[NK_COLOR_TAB_HEADER] = nk_rgba(180, 180, 180, 255);
table[NK_COLOR_KNOB] = table[NK_COLOR_SLIDER];
table[NK_COLOR_KNOB_CURSOR] = table[NK_COLOR_SLIDER_CURSOR];
table[NK_COLOR_KNOB_CURSOR_HOVER] = table[NK_COLOR_SLIDER_CURSOR_HOVER];
table[NK_COLOR_KNOB_CURSOR_ACTIVE] = table[NK_COLOR_SLIDER_CURSOR_ACTIVE];
nk_style_from_table(ctx, table);
} else if (theme == THEME_RED) {
table[NK_COLOR_TEXT] = nk_rgba(190, 190, 190, 255);
@ -63,6 +77,10 @@ set_style(struct nk_context *ctx, enum theme theme)
table[NK_COLOR_SCROLLBAR_CURSOR_HOVER] = nk_rgba(70, 90, 100, 255);
table[NK_COLOR_SCROLLBAR_CURSOR_ACTIVE] = nk_rgba(75, 95, 105, 255);
table[NK_COLOR_TAB_HEADER] = nk_rgba(181, 45, 69, 220);
table[NK_COLOR_KNOB] = table[NK_COLOR_SLIDER];
table[NK_COLOR_KNOB_CURSOR] = table[NK_COLOR_SLIDER_CURSOR];
table[NK_COLOR_KNOB_CURSOR_HOVER] = table[NK_COLOR_SLIDER_CURSOR_HOVER];
table[NK_COLOR_KNOB_CURSOR_ACTIVE] = table[NK_COLOR_SLIDER_CURSOR_ACTIVE];
nk_style_from_table(ctx, table);
} else if (theme == THEME_BLUE) {
table[NK_COLOR_TEXT] = nk_rgba(20, 20, 20, 255);
@ -93,6 +111,10 @@ set_style(struct nk_context *ctx, enum theme theme)
table[NK_COLOR_SCROLLBAR_CURSOR_HOVER] = nk_rgba(70, 90, 100, 255);
table[NK_COLOR_SCROLLBAR_CURSOR_ACTIVE] = nk_rgba(75, 95, 105, 255);
table[NK_COLOR_TAB_HEADER] = nk_rgba(156, 193, 220, 255);
table[NK_COLOR_KNOB] = table[NK_COLOR_SLIDER];
table[NK_COLOR_KNOB_CURSOR] = table[NK_COLOR_SLIDER_CURSOR];
table[NK_COLOR_KNOB_CURSOR_HOVER] = table[NK_COLOR_SLIDER_CURSOR_HOVER];
table[NK_COLOR_KNOB_CURSOR_ACTIVE] = table[NK_COLOR_SLIDER_CURSOR_ACTIVE];
nk_style_from_table(ctx, table);
} else if (theme == THEME_DARK) {
table[NK_COLOR_TEXT] = nk_rgba(210, 210, 210, 255);
@ -123,6 +145,10 @@ set_style(struct nk_context *ctx, enum theme theme)
table[NK_COLOR_SCROLLBAR_CURSOR_HOVER] = nk_rgba(53, 88, 116, 255);
table[NK_COLOR_SCROLLBAR_CURSOR_ACTIVE] = nk_rgba(58, 93, 121, 255);
table[NK_COLOR_TAB_HEADER] = nk_rgba(48, 83, 111, 255);
table[NK_COLOR_KNOB] = table[NK_COLOR_SLIDER];
table[NK_COLOR_KNOB_CURSOR] = table[NK_COLOR_SLIDER_CURSOR];
table[NK_COLOR_KNOB_CURSOR_HOVER] = table[NK_COLOR_SLIDER_CURSOR_HOVER];
table[NK_COLOR_KNOB_CURSOR_ACTIVE] = table[NK_COLOR_SLIDER_CURSOR_ACTIVE];
nk_style_from_table(ctx, table);
} else if (theme == THEME_DRACULA) {
struct nk_color background = nk_rgba(40, 42, 54, 255);
@ -164,10 +190,252 @@ set_style(struct nk_context *ctx, enum theme theme)
table[NK_COLOR_SCROLLBAR_CURSOR_HOVER] = comment;
table[NK_COLOR_SCROLLBAR_CURSOR_ACTIVE] = purple;
table[NK_COLOR_TAB_HEADER] = currentline;
table[NK_COLOR_KNOB] = table[NK_COLOR_SLIDER];
table[NK_COLOR_KNOB_CURSOR] = table[NK_COLOR_SLIDER_CURSOR];
table[NK_COLOR_KNOB_CURSOR_HOVER] = table[NK_COLOR_SLIDER_CURSOR_HOVER];
table[NK_COLOR_KNOB_CURSOR_ACTIVE] = table[NK_COLOR_SLIDER_CURSOR_ACTIVE];
nk_style_from_table(ctx, table);
} else if (theme == THEME_CATPPUCCIN_LATTE) {
/*struct nk_color rosewater = nk_rgba(220, 138, 120, 255);*/
/*struct nk_color flamingo = nk_rgba(221, 120, 120, 255);*/
struct nk_color pink = nk_rgba(234, 118, 203, 255);
struct nk_color mauve = nk_rgba(136, 57, 239, 255);
/*struct nk_color red = nk_rgba(210, 15, 57, 255);*/
/*struct nk_color maroon = nk_rgba(230, 69, 83, 255);*/
/*struct nk_color peach = nk_rgba(254, 100, 11, 255);*/
struct nk_color yellow = nk_rgba(223, 142, 29, 255);
/*struct nk_color green = nk_rgba(64, 160, 43, 255);*/
struct nk_color teal = nk_rgba(23, 146, 153, 255);
/*struct nk_color sky = nk_rgba(4, 165, 229, 255);*/
/*struct nk_color sapphire = nk_rgba(32, 159, 181, 255);*/
/*struct nk_color blue = nk_rgba(30, 102, 245, 255);*/
/*struct nk_color lavender = nk_rgba(114, 135, 253, 255);*/
struct nk_color text = nk_rgba(76, 79, 105, 255);
/*struct nk_color subtext1 = nk_rgba(92, 95, 119, 255);*/
/*struct nk_color subtext0 = nk_rgba(108, 111, 133, 255);*/
struct nk_color overlay2 = nk_rgba(124, 127, 147, 55);
/*struct nk_color overlay1 = nk_rgba(140, 143, 161, 255);*/
struct nk_color overlay0 = nk_rgba(156, 160, 176, 255);
struct nk_color surface2 = nk_rgba(172, 176, 190, 255);
struct nk_color surface1 = nk_rgba(188, 192, 204, 255);
struct nk_color surface0 = nk_rgba(204, 208, 218, 255);
struct nk_color base = nk_rgba(239, 241, 245, 255);
struct nk_color mantle = nk_rgba(230, 233, 239, 255);
/*struct nk_color crust = nk_rgba(220, 224, 232, 255);*/
table[NK_COLOR_TEXT] = text;
table[NK_COLOR_WINDOW] = base;
table[NK_COLOR_HEADER] = mantle;
table[NK_COLOR_BORDER] = mantle;
table[NK_COLOR_BUTTON] = surface0;
table[NK_COLOR_BUTTON_HOVER] = overlay2;
table[NK_COLOR_BUTTON_ACTIVE] = overlay0;
table[NK_COLOR_TOGGLE] = surface2;
table[NK_COLOR_TOGGLE_HOVER] = overlay2;
table[NK_COLOR_TOGGLE_CURSOR] = yellow;
table[NK_COLOR_SELECT] = surface0;
table[NK_COLOR_SELECT_ACTIVE] = overlay0;
table[NK_COLOR_SLIDER] = surface1;
table[NK_COLOR_SLIDER_CURSOR] = teal;
table[NK_COLOR_SLIDER_CURSOR_HOVER] = teal;
table[NK_COLOR_SLIDER_CURSOR_ACTIVE] = teal;
table[NK_COLOR_PROPERTY] = surface0;
table[NK_COLOR_EDIT] = surface0;
table[NK_COLOR_EDIT_CURSOR] = mauve;
table[NK_COLOR_COMBO] = surface0;
table[NK_COLOR_CHART] = surface0;
table[NK_COLOR_CHART_COLOR] = teal;
table[NK_COLOR_CHART_COLOR_HIGHLIGHT] = mauve;
table[NK_COLOR_SCROLLBAR] = surface0;
table[NK_COLOR_SCROLLBAR_CURSOR] = overlay0;
table[NK_COLOR_SCROLLBAR_CURSOR_HOVER] = mauve;
table[NK_COLOR_SCROLLBAR_CURSOR_ACTIVE] = mauve;
table[NK_COLOR_TAB_HEADER] = surface0;
table[NK_COLOR_KNOB] = table[NK_COLOR_SLIDER];
table[NK_COLOR_KNOB_CURSOR] = pink;
table[NK_COLOR_KNOB_CURSOR_HOVER] = pink;
table[NK_COLOR_KNOB_CURSOR_ACTIVE] = pink;
nk_style_from_table(ctx, table);
} else if (theme == THEME_CATPPUCCIN_FRAPPE) {
/*struct nk_color rosewater = nk_rgba(242, 213, 207, 255);*/
/*struct nk_color flamingo = nk_rgba(238, 190, 190, 255);*/
struct nk_color pink = nk_rgba(244, 184, 228, 255);
/*struct nk_color mauve = nk_rgba(202, 158, 230, 255);*/
/*struct nk_color red = nk_rgba(231, 130, 132, 255);*/
/*struct nk_color maroon = nk_rgba(234, 153, 156, 255);*/
/*struct nk_color peach = nk_rgba(239, 159, 118, 255);*/
/*struct nk_color yellow = nk_rgba(229, 200, 144, 255);*/
struct nk_color green = nk_rgba(166, 209, 137, 255);
/*struct nk_color teal = nk_rgba(129, 200, 190, 255);*/
/*struct nk_color sky = nk_rgba(153, 209, 219, 255);*/
/*struct nk_color sapphire = nk_rgba(133, 193, 220, 255);*/
/*struct nk_color blue = nk_rgba(140, 170, 238, 255);*/
struct nk_color lavender = nk_rgba(186, 187, 241, 255);
struct nk_color text = nk_rgba(198, 208, 245, 255);
/*struct nk_color subtext1 = nk_rgba(181, 191, 226, 255);*/
/*struct nk_color subtext0 = nk_rgba(165, 173, 206, 255);*/
struct nk_color overlay2 = nk_rgba(148, 156, 187, 255);
struct nk_color overlay1 = nk_rgba(131, 139, 167, 255);
struct nk_color overlay0 = nk_rgba(115, 121, 148, 255);
struct nk_color surface2 = nk_rgba(98, 104, 128, 255);
struct nk_color surface1 = nk_rgba(81, 87, 109, 255);
struct nk_color surface0 = nk_rgba(65, 69, 89, 255);
struct nk_color base = nk_rgba(48, 52, 70, 255);
struct nk_color mantle = nk_rgba(41, 44, 60, 255);
/*struct nk_color crust = nk_rgba(35, 38, 52, 255);*/
table[NK_COLOR_TEXT] = text;
table[NK_COLOR_WINDOW] = base;
table[NK_COLOR_HEADER] = mantle;
table[NK_COLOR_BORDER] = mantle;
table[NK_COLOR_BUTTON] = surface0;
table[NK_COLOR_BUTTON_HOVER] = overlay1;
table[NK_COLOR_BUTTON_ACTIVE] = overlay0;
table[NK_COLOR_TOGGLE] = surface2;
table[NK_COLOR_TOGGLE_HOVER] = overlay2;
table[NK_COLOR_TOGGLE_CURSOR] = pink;
table[NK_COLOR_SELECT] = surface0;
table[NK_COLOR_SELECT_ACTIVE] = overlay0;
table[NK_COLOR_SLIDER] = surface1;
table[NK_COLOR_SLIDER_CURSOR] = green;
table[NK_COLOR_SLIDER_CURSOR_HOVER] = green;
table[NK_COLOR_SLIDER_CURSOR_ACTIVE] = green;
table[NK_COLOR_PROPERTY] = surface0;
table[NK_COLOR_EDIT] = surface0;
table[NK_COLOR_EDIT_CURSOR] = pink;
table[NK_COLOR_COMBO] = surface0;
table[NK_COLOR_CHART] = surface0;
table[NK_COLOR_CHART_COLOR] = lavender;
table[NK_COLOR_CHART_COLOR_HIGHLIGHT] = pink;
table[NK_COLOR_SCROLLBAR] = surface0;
table[NK_COLOR_SCROLLBAR_CURSOR] = overlay0;
table[NK_COLOR_SCROLLBAR_CURSOR_HOVER] = lavender;
table[NK_COLOR_SCROLLBAR_CURSOR_ACTIVE] = lavender;
table[NK_COLOR_TAB_HEADER] = surface0;
table[NK_COLOR_KNOB] = table[NK_COLOR_SLIDER];
table[NK_COLOR_KNOB_CURSOR] = pink;
table[NK_COLOR_KNOB_CURSOR_HOVER] = pink;
table[NK_COLOR_KNOB_CURSOR_ACTIVE] = pink;
nk_style_from_table(ctx, table);
} else if (theme == THEME_CATPPUCCIN_MACCHIATO) {
/*struct nk_color rosewater = nk_rgba(244, 219, 214, 255);*/
/*struct nk_color flamingo = nk_rgba(240, 198, 198, 255);*/
struct nk_color pink = nk_rgba(245, 189, 230, 255);
/*struct nk_color mauve = nk_rgba(198, 160, 246, 255);*/
/*struct nk_color red = nk_rgba(237, 135, 150, 255);*/
/*struct nk_color maroon = nk_rgba(238, 153, 160, 255);*/
/*struct nk_color peach = nk_rgba(245, 169, 127, 255);*/
struct nk_color yellow = nk_rgba(238, 212, 159, 255);
struct nk_color green = nk_rgba(166, 218, 149, 255);
/*struct nk_color teal = nk_rgba(139, 213, 202, 255);*/
/*struct nk_color sky = nk_rgba(145, 215, 227, 255);*/
/*struct nk_color sapphire = nk_rgba(125, 196, 228, 255);*/
/*struct nk_color blue = nk_rgba(138, 173, 244, 255);*/
struct nk_color lavender = nk_rgba(183, 189, 248, 255);
struct nk_color text = nk_rgba(202, 211, 245, 255);
/*struct nk_color subtext1 = nk_rgba(184, 192, 224, 255);*/
/*struct nk_color subtext0 = nk_rgba(165, 173, 203, 255);*/
struct nk_color overlay2 = nk_rgba(147, 154, 183, 255);
struct nk_color overlay1 = nk_rgba(128, 135, 162, 255);
struct nk_color overlay0 = nk_rgba(110, 115, 141, 255);
struct nk_color surface2 = nk_rgba(91, 96, 120, 255);
struct nk_color surface1 = nk_rgba(73, 77, 100, 255);
struct nk_color surface0 = nk_rgba(54, 58, 79, 255);
struct nk_color base = nk_rgba(36, 39, 58, 255);
struct nk_color mantle = nk_rgba(30, 32, 48, 255);
/*struct nk_color crust = nk_rgba(24, 25, 38, 255);*/
table[NK_COLOR_TEXT] = text;
table[NK_COLOR_WINDOW] = base;
table[NK_COLOR_HEADER] = mantle;
table[NK_COLOR_BORDER] = mantle;
table[NK_COLOR_BUTTON] = surface0;
table[NK_COLOR_BUTTON_HOVER] = overlay1;
table[NK_COLOR_BUTTON_ACTIVE] = overlay0;
table[NK_COLOR_TOGGLE] = surface2;
table[NK_COLOR_TOGGLE_HOVER] = overlay2;
table[NK_COLOR_TOGGLE_CURSOR] = yellow;
table[NK_COLOR_SELECT] = surface0;
table[NK_COLOR_SELECT_ACTIVE] = overlay0;
table[NK_COLOR_SLIDER] = surface1;
table[NK_COLOR_SLIDER_CURSOR] = green;
table[NK_COLOR_SLIDER_CURSOR_HOVER] = green;
table[NK_COLOR_SLIDER_CURSOR_ACTIVE] = green;
table[NK_COLOR_PROPERTY] = surface0;
table[NK_COLOR_EDIT] = surface0;
table[NK_COLOR_EDIT_CURSOR] = pink;
table[NK_COLOR_COMBO] = surface0;
table[NK_COLOR_CHART] = surface0;
table[NK_COLOR_CHART_COLOR] = lavender;
table[NK_COLOR_CHART_COLOR_HIGHLIGHT] = yellow;
table[NK_COLOR_SCROLLBAR] = surface0;
table[NK_COLOR_SCROLLBAR_CURSOR] = overlay0;
table[NK_COLOR_SCROLLBAR_CURSOR_HOVER] = lavender;
table[NK_COLOR_SCROLLBAR_CURSOR_ACTIVE] = lavender;
table[NK_COLOR_TAB_HEADER] = surface0;
table[NK_COLOR_KNOB] = table[NK_COLOR_SLIDER];
table[NK_COLOR_KNOB_CURSOR] = pink;
table[NK_COLOR_KNOB_CURSOR_HOVER] = pink;
table[NK_COLOR_KNOB_CURSOR_ACTIVE] = pink;
nk_style_from_table(ctx, table);
} else if (theme == THEME_CATPPUCCIN_MOCHA) {
/*struct nk_color rosewater = nk_rgba(245, 224, 220, 255);*/
/*struct nk_color flamingo = nk_rgba(242, 205, 205, 255);*/
struct nk_color pink = nk_rgba(245, 194, 231, 255);
/*struct nk_color mauve = nk_rgba(203, 166, 247, 255);*/
/*struct nk_color red = nk_rgba(243, 139, 168, 255);*/
/*struct nk_color maroon = nk_rgba(235, 160, 172, 255);*/
/*struct nk_color peach = nk_rgba(250, 179, 135, 255);*/
/*struct nk_color yellow = nk_rgba(249, 226, 175, 255);*/
struct nk_color green = nk_rgba(166, 227, 161, 255);
/*struct nk_color teal = nk_rgba(148, 226, 213, 255);*/
/*struct nk_color sky = nk_rgba(137, 220, 235, 255);*/
/*struct nk_color sapphire = nk_rgba(116, 199, 236, 255);*/
/*struct nk_color blue = nk_rgba(137, 180, 250, 255);*/
struct nk_color lavender = nk_rgba(180, 190, 254, 255);
struct nk_color text = nk_rgba(205, 214, 244, 255);
/*struct nk_color subtext1 = nk_rgba(186, 194, 222, 255);*/
/*struct nk_color subtext0 = nk_rgba(166, 173, 200, 255);*/
struct nk_color overlay2 = nk_rgba(147, 153, 178, 255);
struct nk_color overlay1 = nk_rgba(127, 132, 156, 255);
struct nk_color overlay0 = nk_rgba(108, 112, 134, 255);
struct nk_color surface2 = nk_rgba(88, 91, 112, 255);
struct nk_color surface1 = nk_rgba(69, 71, 90, 255);
struct nk_color surface0 = nk_rgba(49, 50, 68, 255);
struct nk_color base = nk_rgba(30, 30, 46, 255);
struct nk_color mantle = nk_rgba(24, 24, 37, 255);
/*struct nk_color crust = nk_rgba(17, 17, 27, 255);*/
table[NK_COLOR_TEXT] = text;
table[NK_COLOR_WINDOW] = base;
table[NK_COLOR_HEADER] = mantle;
table[NK_COLOR_BORDER] = mantle;
table[NK_COLOR_BUTTON] = surface0;
table[NK_COLOR_BUTTON_HOVER] = overlay1;
table[NK_COLOR_BUTTON_ACTIVE] = overlay0;
table[NK_COLOR_TOGGLE] = surface2;
table[NK_COLOR_TOGGLE_HOVER] = overlay2;
table[NK_COLOR_TOGGLE_CURSOR] = lavender;
table[NK_COLOR_SELECT] = surface0;
table[NK_COLOR_SELECT_ACTIVE] = overlay0;
table[NK_COLOR_SLIDER] = surface1;
table[NK_COLOR_SLIDER_CURSOR] = green;
table[NK_COLOR_SLIDER_CURSOR_HOVER] = green;
table[NK_COLOR_SLIDER_CURSOR_ACTIVE] = green;
table[NK_COLOR_PROPERTY] = surface0;
table[NK_COLOR_EDIT] = surface0;
table[NK_COLOR_EDIT_CURSOR] = lavender;
table[NK_COLOR_COMBO] = surface0;
table[NK_COLOR_CHART] = surface0;
table[NK_COLOR_CHART_COLOR] = lavender;
table[NK_COLOR_CHART_COLOR_HIGHLIGHT] = pink;
table[NK_COLOR_SCROLLBAR] = surface0;
table[NK_COLOR_SCROLLBAR_CURSOR] = overlay0;
table[NK_COLOR_SCROLLBAR_CURSOR_HOVER] = lavender;
table[NK_COLOR_SCROLLBAR_CURSOR_ACTIVE] = pink;
table[NK_COLOR_TAB_HEADER] = surface0;
table[NK_COLOR_KNOB] = table[NK_COLOR_SLIDER];
table[NK_COLOR_KNOB_CURSOR] = pink;
table[NK_COLOR_KNOB_CURSOR_HOVER] = pink;
table[NK_COLOR_KNOB_CURSOR_ACTIVE] = pink;
nk_style_from_table(ctx, table);
} else {
nk_style_default(ctx);
}
}

View File

@ -239,6 +239,14 @@ nk_d3d11_handle_event(HWND wnd, UINT msg, WPARAM wparam, LPARAM lparam)
nk_input_key(&d3d11.ctx, NK_KEY_TAB, down);
return 1;
case VK_UP:
nk_input_key(&d3d11.ctx, NK_KEY_UP, down);
return 1;
case VK_DOWN:
nk_input_key(&d3d11.ctx, NK_KEY_DOWN, down);
return 1;
case VK_LEFT:
if (ctrl)
nk_input_key(&d3d11.ctx, NK_KEY_TEXT_WORD_LEFT, down);
@ -275,6 +283,20 @@ nk_d3d11_handle_event(HWND wnd, UINT msg, WPARAM wparam, LPARAM lparam)
nk_input_key(&d3d11.ctx, NK_KEY_SCROLL_UP, down);
return 1;
case 'B':
if (ctrl) {
nk_input_key(&d3d11.ctx, NK_KEY_TEXT_LINE_START, down);
return 1;
}
break;
case 'E':
if (ctrl) {
nk_input_key(&d3d11.ctx, NK_KEY_TEXT_LINE_END, down);
return 1;
}
break;
case 'C':
if (ctrl) {
nk_input_key(&d3d11.ctx, NK_KEY_COPY, down);

View File

@ -79,6 +79,7 @@ static struct nk_glfw {
double last_button_click;
int is_double_click_down;
struct nk_vec2 double_click_pos;
float delta_time_seconds_last;
} glfw;
NK_INTERN void
@ -273,6 +274,8 @@ nk_glfw3_init(GLFWwindow *win, enum nk_glfw_init_state init_state)
glfw.is_double_click_down = nk_false;
glfw.double_click_pos = nk_vec2(0, 0);
glfw.delta_time_seconds_last = (float)glfwGetTime();
return &glfw.ctx;
}
@ -303,6 +306,11 @@ nk_glfw3_new_frame(void)
struct nk_context *ctx = &glfw.ctx;
struct GLFWwindow *win = glfw.win;
/* update the timer */
float delta_time_now = (float)glfwGetTime();
glfw.ctx.delta_time_seconds = delta_time_now - glfw.delta_time_seconds_last;
glfw.delta_time_seconds_last = delta_time_now;
glfwGetWindowSize(win, &glfw.width, &glfw.height);
glfwGetFramebufferSize(win, &glfw.display_width, &glfw.display_height);
glfw.fb_scale.x = (float)glfw.display_width/(float)glfw.width;
@ -350,7 +358,6 @@ nk_glfw3_new_frame(void)
nk_input_key(ctx, NK_KEY_COPY, 0);
nk_input_key(ctx, NK_KEY_PASTE, 0);
nk_input_key(ctx, NK_KEY_CUT, 0);
nk_input_key(ctx, NK_KEY_SHIFT, 0);
}
glfwGetCursorPos(win, &x, &y);

View File

@ -53,6 +53,7 @@ struct nk_glfw {
double last_button_click;
int is_double_click_down;
struct nk_vec2 double_click_pos;
float delta_time_seconds_last;
};
NK_API struct nk_context* nk_glfw3_init(struct nk_glfw* glfw, GLFWwindow *win, enum nk_glfw_init_state);
@ -314,7 +315,7 @@ nk_glfw3_render(struct nk_glfw* glfw, enum nk_anti_aliasing AA, int max_vertex_b
NK_API void
nk_glfw3_char_callback(GLFWwindow *win, unsigned int codepoint)
{
struct nk_glfw* glfw = glfwGetWindowUserPointer(win);
struct nk_glfw* glfw = (struct nk_glfw *)glfwGetWindowUserPointer(win);
if (glfw->text_len < NK_GLFW_TEXT_MAX)
glfw->text[glfw->text_len++] = codepoint;
}
@ -322,7 +323,7 @@ nk_glfw3_char_callback(GLFWwindow *win, unsigned int codepoint)
NK_API void
nk_gflw3_scroll_callback(GLFWwindow *win, double xoff, double yoff)
{
struct nk_glfw* glfw = glfwGetWindowUserPointer(win);
struct nk_glfw* glfw = (struct nk_glfw *)glfwGetWindowUserPointer(win);
(void)xoff;
glfw->scroll.x += (float)xoff;
glfw->scroll.y += (float)yoff;
@ -331,7 +332,7 @@ nk_gflw3_scroll_callback(GLFWwindow *win, double xoff, double yoff)
NK_API void
nk_glfw3_mouse_button_callback(GLFWwindow* win, int button, int action, int mods)
{
struct nk_glfw* glfw = glfwGetWindowUserPointer(win);
struct nk_glfw* glfw = (struct nk_glfw *)glfwGetWindowUserPointer(win);
double x, y;
NK_UNUSED(mods);
if (button != GLFW_MOUSE_BUTTON_LEFT) return;
@ -389,6 +390,8 @@ nk_glfw3_init(struct nk_glfw* glfw, GLFWwindow *win, enum nk_glfw_init_state ini
glfw->is_double_click_down = nk_false;
glfw->double_click_pos = nk_vec2(0, 0);
glfw->delta_time_seconds_last = (float)glfwGetTime();
return &glfw->ctx;
}
@ -419,6 +422,11 @@ nk_glfw3_new_frame(struct nk_glfw* glfw)
struct nk_context *ctx = &glfw->ctx;
struct GLFWwindow *win = glfw->win;
/* update the timer */
float delta_time_now = (float)glfwGetTime();
glfw->ctx.delta_time_seconds = delta_time_now - glfw->delta_time_seconds_last;
glfw->delta_time_seconds_last = delta_time_now;
glfwGetWindowSize(win, &glfw->width, &glfw->height);
glfwGetFramebufferSize(win, &glfw->display_width, &glfw->display_height);
glfw->fb_scale.x = (float)glfw->display_width/(float)glfw->width;
@ -468,7 +476,6 @@ nk_glfw3_new_frame(struct nk_glfw* glfw)
nk_input_key(ctx, NK_KEY_COPY, 0);
nk_input_key(ctx, NK_KEY_PASTE, 0);
nk_input_key(ctx, NK_KEY_CUT, 0);
nk_input_key(ctx, NK_KEY_SHIFT, 0);
}
glfwGetCursorPos(win, &x, &y);

View File

@ -619,7 +619,6 @@ nk_glfw3_new_frame(void)
nk_input_key(ctx, NK_KEY_COPY, 0);
nk_input_key(ctx, NK_KEY_PASTE, 0);
nk_input_key(ctx, NK_KEY_CUT, 0);
nk_input_key(ctx, NK_KEY_SHIFT, 0);
}
glfwGetCursorPos(win, &x, &y);

View File

@ -139,8 +139,19 @@ struct vulkan_demo {
VkDeviceMemory demo_texture_memory;
VkFence render_fence;
bool framebuffer_resized;
};
static void glfw_framebuffer_resize_callback(GLFWwindow* window, int width, int height) {
struct vulkan_demo* demo;
(void)width;
(void)height;
demo = glfwGetWindowUserPointer(window);
demo->framebuffer_resized = true;
}
static void glfw_error_callback(int e, const char *d) {
fprintf(stderr, "Error %d: %s\n", e, d);
}
@ -299,7 +310,7 @@ bool create_instance(struct vulkan_demo *demo) {
if (i > 0) {
printf(", ");
}
printf(enabled_extensions[i]);
printf("%s\n", enabled_extensions[i]);
}
printf("\n");
for (i = 0; i < enabled_extension_count; i++) {
@ -1227,8 +1238,8 @@ bool create_graphics_pipeline(struct vulkan_demo *demo) {
bool ret = false;
char *vert_shader_code = NULL;
char *frag_shader_code = NULL;
VkShaderModule vert_shader_module;
VkShaderModule frag_shader_module;
VkShaderModule vert_shader_module = VK_NULL_HANDLE;
VkShaderModule frag_shader_module = VK_NULL_HANDLE;
FILE *fp;
size_t file_len;
VkPipelineShaderStageCreateInfo vert_shader_stage_info;
@ -1246,8 +1257,9 @@ bool create_graphics_pipeline(struct vulkan_demo *demo) {
VkPipelineLayoutCreateInfo pipeline_layout_info;
VkResult result;
VkGraphicsPipelineCreateInfo pipeline_info;
size_t read_result;
fp = fopen("shaders/demo.vert.spv", "r");
fp = fopen("shaders/demo.vert.spv", "rb");
if (!fp) {
fprintf(stderr, "Couldn't open shaders/demo.vert.spv\n");
return false;
@ -1256,15 +1268,19 @@ bool create_graphics_pipeline(struct vulkan_demo *demo) {
file_len = ftell(fp);
vert_shader_code = malloc(file_len);
fseek(fp, 0, 0);
fread(vert_shader_code, 1, file_len, fp);
read_result = fread(vert_shader_code, file_len, 1, fp);
fclose(fp);
if (read_result != 1) {
fprintf(stderr, "Could not read fragment shader\n");
goto cleanup;
}
if (!create_shader_module(demo->device, vert_shader_code, file_len,
&vert_shader_module)) {
goto cleanup;
}
fp = fopen("shaders/demo.frag.spv", "r");
fp = fopen("shaders/demo.frag.spv", "rb");
if (!fp) {
fprintf(stderr, "Couldn't open shaders/demo.frag.spv\n");
return false;
@ -1273,8 +1289,12 @@ bool create_graphics_pipeline(struct vulkan_demo *demo) {
file_len = ftell(fp);
frag_shader_code = malloc(file_len);
fseek(fp, 0, 0);
fread(frag_shader_code, 1, file_len, fp);
read_result = fread(frag_shader_code, file_len, 1, fp);
fclose(fp);
if (read_result != 1) {
fprintf(stderr, "Could not read fragment shader\n");
goto cleanup;
}
if (!create_shader_module(demo->device, frag_shader_code, file_len,
&frag_shader_module)) {
@ -1862,6 +1882,8 @@ bool create_vulkan_demo(struct vulkan_demo *demo) {
return false;
}
demo->framebuffer_resized = false;
return true;
}
@ -1876,6 +1898,9 @@ bool recreate_swap_chain(struct vulkan_demo *demo) {
update_descriptor_sets(demo);
nk_glfw3_resize(demo->swap_chain_image_extent.width,
demo->swap_chain_image_extent.height);
demo->framebuffer_resized = false;
return true;
}
@ -1961,7 +1986,7 @@ bool render(struct vulkan_demo *demo, struct nk_colorf *bg,
result = vkQueuePresentKHR(demo->present_queue, &present_info);
if (result == VK_ERROR_OUT_OF_DATE_KHR || result == VK_SUBOPTIMAL_KHR) {
if (result == VK_ERROR_OUT_OF_DATE_KHR || result == VK_SUBOPTIMAL_KHR || demo->framebuffer_resized) {
recreate_swap_chain(demo);
} else if (result != VK_SUCCESS) {
fprintf(stderr, "vkQueuePresentKHR failed: %d\n", result);
@ -2073,6 +2098,8 @@ int main(void) {
memset(&demo, 0, sizeof(struct vulkan_demo));
demo.win =
glfwCreateWindow(WINDOW_WIDTH, WINDOW_HEIGHT, "Demo", NULL, NULL);
glfwSetWindowUserPointer(demo.win, &demo);
glfwSetFramebufferSizeCallback(demo.win, glfw_framebuffer_resize_callback);
if (!create_vulkan_demo(&demo)) {
fprintf(stderr, "failed to create vulkan demo!\n");
@ -2192,6 +2219,10 @@ int main(void) {
demo.image_available, NULL, &image_index);
if (result == VK_ERROR_OUT_OF_DATE_KHR) {
recreate_swap_chain(&demo);
/* If vkAcquireNextImageKHR does not successfully acquire an image,
* semaphore and fence are unaffected. */
continue;
}
if (result != VK_SUCCESS && result != VK_SUBOPTIMAL_KHR) {

View File

@ -372,13 +372,13 @@ static struct nk_glfw {
struct nk_glfw_device vulkan;
struct nk_context ctx;
struct nk_font_atlas atlas;
struct nk_vec2 fb_scale;
unsigned int text[NK_GLFW_TEXT_MAX];
int text_len;
struct nk_vec2 scroll;
double last_button_click;
int is_double_click_down;
struct nk_vec2 double_click_pos;
float delta_time_seconds_last;
} glfw;
struct Mat4f {
@ -1178,8 +1178,6 @@ NK_API void nk_glfw3_resize(uint32_t framebuffer_width,
struct nk_glfw_device *dev = &glfw.vulkan;
glfwGetWindowSize(glfw.win, &glfw.width, &glfw.height);
glfwGetFramebufferSize(glfw.win, &glfw.display_width, &glfw.display_height);
glfw.fb_scale.x = (float)glfw.display_width / (float)glfw.width;
glfw.fb_scale.y = (float)glfw.display_height / (float)glfw.height;
nk_glfw3_destroy_render_resources(dev);
nk_glfw3_create_render_resources(dev, framebuffer_width,
@ -1254,11 +1252,16 @@ NK_API void nk_glfw3_new_frame(void) {
struct nk_context *ctx = &glfw.ctx;
struct GLFWwindow *win = glfw.win;
/* update the timer */
float delta_time_now = (float)glfwGetTime();
glfw.ctx.delta_time_seconds = delta_time_now - glfw.delta_time_seconds_last;
glfw.delta_time_seconds_last = delta_time_now;
nk_input_begin(ctx);
for (i = 0; i < glfw.text_len; ++i)
nk_input_unicode(ctx, glfw.text[i]);
#ifdef NK_GLFW_GL4_MOUSE_GRABBING
#ifdef NK_GLFW_VULKAN_MOUSE_GRABBING
/* optional grabbing behavior */
if (ctx->input.mouse.grab)
glfwSetInputMode(glfw.win, GLFW_CURSOR, GLFW_CURSOR_HIDDEN);
@ -1322,12 +1325,11 @@ NK_API void nk_glfw3_new_frame(void) {
nk_input_key(ctx, NK_KEY_COPY, 0);
nk_input_key(ctx, NK_KEY_PASTE, 0);
nk_input_key(ctx, NK_KEY_CUT, 0);
nk_input_key(ctx, NK_KEY_SHIFT, 0);
}
glfwGetCursorPos(win, &x, &y);
nk_input_motion(ctx, (int)x, (int)y);
#ifdef NK_GLFW_GL4_MOUSE_GRABBING
#ifdef NK_GLFW_VULKAN_MOUSE_GRABBING
if (ctx->input.mouse.grabbed) {
glfwSetCursorPos(glfw.win, ctx->input.mouse.prev.x,
ctx->input.mouse.prev.y);

View File

@ -24,6 +24,7 @@ unsigned char nuklearshaders_nuklear_frag_spv[] = {};
unsigned int nuklearshaders_nuklear_frag_spv_len = 0;
// NUKLEAR_SHADERS_END
#include <assert.h>
#include <stddef.h>
#include <string.h>
#define GLFW_INCLUDE_VULKAN
@ -71,7 +72,6 @@ NK_API void nk_glfw3_mouse_button_callback(GLFWwindow *win, int button,
*/
#ifdef NK_GLFW_VULKAN_IMPLEMENTATION
#undef NK_GLFW_VULKAN_IMPLEMENTATION
#include <assert.h>
#include <stdlib.h>
#ifndef NK_GLFW_TEXT_MAX
@ -149,13 +149,13 @@ static struct nk_glfw {
struct nk_glfw_device vulkan;
struct nk_context ctx;
struct nk_font_atlas atlas;
struct nk_vec2 fb_scale;
unsigned int text[NK_GLFW_TEXT_MAX];
int text_len;
struct nk_vec2 scroll;
double last_button_click;
int is_double_click_down;
struct nk_vec2 double_click_pos;
float delta_time_seconds_last;
} glfw;
struct Mat4f {
@ -955,8 +955,6 @@ NK_API void nk_glfw3_resize(uint32_t framebuffer_width,
struct nk_glfw_device *dev = &glfw.vulkan;
glfwGetWindowSize(glfw.win, &glfw.width, &glfw.height);
glfwGetFramebufferSize(glfw.win, &glfw.display_width, &glfw.display_height);
glfw.fb_scale.x = (float)glfw.display_width / (float)glfw.width;
glfw.fb_scale.y = (float)glfw.display_height / (float)glfw.height;
nk_glfw3_destroy_render_resources(dev);
nk_glfw3_create_render_resources(dev, framebuffer_width,
@ -1031,11 +1029,16 @@ NK_API void nk_glfw3_new_frame(void) {
struct nk_context *ctx = &glfw.ctx;
struct GLFWwindow *win = glfw.win;
/* update the timer */
float delta_time_now = (float)glfwGetTime();
glfw.ctx.delta_time_seconds = delta_time_now - glfw.delta_time_seconds_last;
glfw.delta_time_seconds_last = delta_time_now;
nk_input_begin(ctx);
for (i = 0; i < glfw.text_len; ++i)
nk_input_unicode(ctx, glfw.text[i]);
#ifdef NK_GLFW_GL4_MOUSE_GRABBING
#ifdef NK_GLFW_VULKAN_MOUSE_GRABBING
/* optional grabbing behavior */
if (ctx->input.mouse.grab)
glfwSetInputMode(glfw.win, GLFW_CURSOR, GLFW_CURSOR_HIDDEN);
@ -1099,12 +1102,11 @@ NK_API void nk_glfw3_new_frame(void) {
nk_input_key(ctx, NK_KEY_COPY, 0);
nk_input_key(ctx, NK_KEY_PASTE, 0);
nk_input_key(ctx, NK_KEY_CUT, 0);
nk_input_key(ctx, NK_KEY_SHIFT, 0);
}
glfwGetCursorPos(win, &x, &y);
nk_input_motion(ctx, (int)x, (int)y);
#ifdef NK_GLFW_GL4_MOUSE_GRABBING
#ifdef NK_GLFW_VULKAN_MOUSE_GRABBING
if (ctx->input.mouse.grabbed) {
glfwSetCursorPos(glfw.win, ctx->input.mouse.prev.x,
ctx->input.mouse.prev.y);

View File

@ -1033,6 +1033,7 @@ nk_rawfb_render(const struct rawfb_context *rawfb,
const unsigned char enable_clear)
{
const struct nk_command *cmd;
if (enable_clear)
nk_rawfb_clear(rawfb, clear);

View File

@ -1,5 +1,5 @@
# Install
BIN = zahnrad
BIN = demo
# Flags
CFLAGS += -std=c89 -Wall -Wextra -pedantic -Wno-unused-function -O2

View File

@ -2,7 +2,7 @@
BIN = demo
# Flags
CFLAGS += -std=c89 -Wall -Wextra -pedantic -O2
CFLAGS += -std=c89 -Wall -Wextra -pedantic -O2 -DSDL_DISABLE_IMMINTRIN_H
SRC = main.c
OBJ = $(SRC:.c=.o)

View File

@ -34,7 +34,7 @@
* ===============================================================*/
/* 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 defines */
/*#define INCLUDE_ALL */
#define INCLUDE_ALL
/*#define INCLUDE_STYLE */
/*#define INCLUDE_CALCULATOR */
/*#define INCLUDE_CANVAS */

View File

@ -51,6 +51,7 @@ static struct nk_sdl {
struct nk_sdl_device ogl;
struct nk_context ctx;
struct nk_font_atlas atlas;
Uint64 time_of_last_frame;
} sdl;
NK_INTERN void
@ -74,6 +75,10 @@ nk_sdl_render(enum nk_anti_aliasing AA)
int display_width, display_height;
struct nk_vec2 scale;
Uint64 now = SDL_GetTicks64();
sdl.ctx.delta_time_seconds = (float)(now - sdl.time_of_last_frame) / 1000;
sdl.time_of_last_frame = now;
SDL_GetWindowSize(sdl.win, &width, &height);
SDL_GL_GetDrawableSize(sdl.win, &display_width, &display_height);
scale.x = (float)display_width/(float)width;
@ -212,6 +217,7 @@ nk_sdl_init(SDL_Window *win)
sdl.ctx.clip.paste = nk_sdl_clipboard_paste;
sdl.ctx.clip.userdata = nk_handle_ptr(0);
nk_buffer_init_default(&sdl.ogl.cmds);
sdl.time_of_last_frame = SDL_GetTicks64();
return &sdl.ctx;
}

View File

@ -2,7 +2,7 @@
BIN = demo
# Flags
CFLAGS += -std=c89 -Wall -Wextra -pedantic -O2
CFLAGS += -std=c89 -Wall -Wextra -pedantic -O2 -DSDL_DISABLE_IMMINTRIN_H
SRC = main.c
OBJ = $(SRC:.c=.o)

View File

@ -67,6 +67,7 @@ static struct nk_sdl {
struct nk_sdl_device ogl;
struct nk_context ctx;
struct nk_font_atlas atlas;
Uint64 time_of_last_frame;
} sdl;
#ifdef __APPLE__
@ -197,6 +198,11 @@ nk_sdl_render(enum nk_anti_aliasing AA, int max_vertex_buffer, int max_element_b
{ 0.0f, 0.0f, -1.0f, 0.0f },
{ -1.0f, 1.0f, 0.0f, 1.0f },
};
Uint64 now = SDL_GetTicks64();
sdl.ctx.delta_time_seconds = (float)(now - sdl.time_of_last_frame) / 1000;
sdl.time_of_last_frame = now;
SDL_GetWindowSize(sdl.win, &width, &height);
SDL_GL_GetDrawableSize(sdl.win, &display_width, &display_height);
ortho[0][0] /= (GLfloat)width;
@ -320,6 +326,7 @@ nk_sdl_init(SDL_Window *win)
sdl.ctx.clip.paste = nk_sdl_clipboard_paste;
sdl.ctx.clip.userdata = nk_handle_ptr(0);
nk_sdl_device_create();
sdl.time_of_last_frame = SDL_GetTicks64();
return &sdl.ctx;
}

View File

@ -2,7 +2,7 @@
BIN = demo
# Flags
CFLAGS += -std=c89 -Wall -Wextra -pedantic -O2
CFLAGS += -std=c89 -Wall -Wextra -pedantic -O2 -DSDL_DISABLE_IMMINTRIN_H
SRC = main.c
OBJ = $(SRC:.c=.o)

View File

@ -71,6 +71,7 @@ static struct nk_sdl {
struct nk_sdl_device ogl;
struct nk_context ctx;
struct nk_font_atlas atlas;
Uint64 time_of_last_frame;
} sdl;
@ -185,6 +186,11 @@ nk_sdl_render(enum nk_anti_aliasing AA, int max_vertex_buffer, int max_element_b
{ 0.0f, 0.0f, -1.0f, 0.0f },
{ -1.0f, 1.0f, 0.0f, 1.0f },
};
Uint64 now = SDL_GetTicks64();
sdl.ctx.delta_time_seconds = (float)(now - sdl.time_of_last_frame) / 1000;
sdl.time_of_last_frame = now;
SDL_GetWindowSize(sdl.win, &width, &height);
SDL_GL_GetDrawableSize(sdl.win, &display_width, &display_height);
ortho[0][0] /= (GLfloat)width;
@ -320,6 +326,7 @@ nk_sdl_init(SDL_Window *win)
sdl.ctx.clip.paste = nk_sdl_clipboard_paste;
sdl.ctx.clip.userdata = nk_handle_ptr(0);
nk_sdl_device_create();
sdl.time_of_last_frame = SDL_GetTicks64();
return &sdl.ctx;
}

View File

@ -2,7 +2,7 @@
BIN = demo
# Flags
CFLAGS += -std=c89 -pedantic -O0
CFLAGS += -std=c89 -Wall -Wextra -pedantic -O2 -DSDL_DISABLE_IMMINTRIN_H
CFLAGS += `sdl2-config --cflags`
SRC = main.c

View File

@ -64,10 +64,9 @@ static struct nk_sdl {
struct nk_sdl_device ogl;
struct nk_context ctx;
struct nk_font_atlas atlas;
Uint64 time_of_last_frame;
} sdl;
NK_INTERN void
nk_sdl_device_upload_atlas(const void *image, int width, int height)
{
@ -113,6 +112,11 @@ nk_sdl_render(enum nk_anti_aliasing AA)
{NK_VERTEX_COLOR, NK_FORMAT_R8G8B8A8, NK_OFFSETOF(struct nk_sdl_vertex, col)},
{NK_VERTEX_LAYOUT_END}
};
Uint64 now = SDL_GetTicks64();
sdl.ctx.delta_time_seconds = (float)(now - sdl.time_of_last_frame) / 1000;
sdl.time_of_last_frame = now;
NK_MEMSET(&config, 0, sizeof(config));
config.vertex_layout = vertex_layout;
config.vertex_size = sizeof(struct nk_sdl_vertex);
@ -241,6 +245,7 @@ nk_sdl_init(SDL_Window *win, SDL_Renderer *renderer)
#endif
sdl.win = win;
sdl.renderer = renderer;
sdl.time_of_last_frame = SDL_GetTicks64();
nk_init_default(&sdl.ctx, 0);
sdl.ctx.clip.copy = nk_sdl_clipboard_copy;
sdl.ctx.clip.paste = nk_sdl_clipboard_paste;

3
demo/sdl_vulkan/.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
src/nuklearshaders/*.spv
src/nuklear_sdl_vulkan.h
shaders/*.spv

30
demo/sdl_vulkan/Makefile Normal file
View File

@ -0,0 +1,30 @@
# Install
BIN = demo
# Flags
CFLAGS += -std=c89 -Wall -Wextra -pedantic -fsanitize=address -O2
CFLAGS += -DSDL_DISABLE_IMMINTRIN_H
SRC = main.c
OBJ = $(SRC:.c=.o)
ifeq ($(OS),Windows_NT)
BIN := $(BIN).exe
LIBS = -lsdl2 -lvulkan -lm
else
UNAME_S := $(shell uname -s)
SDL2 := $(shell pkg-config --libs sdl2)
LIBS = $(SDL2) -lvulkan -lm
endif
$(BIN): shaders/demo.vert.spv shaders/demo.frag.spv
@mkdir -p bin
rm -f bin/$(BIN) $(OBJS)
$(CC) $(SRC) $(CFLAGS) -o bin/$(BIN) $(LIBS)
shaders/demo.vert.spv: shaders/demo.vert
glslc --target-env=vulkan shaders/demo.vert -o shaders/demo.vert.spv
shaders/demo.frag.spv: shaders/demo.frag
glslc --target-env=vulkan shaders/demo.frag -o shaders/demo.frag.spv

52
demo/sdl_vulkan/README.md Normal file
View File

@ -0,0 +1,52 @@
# nuklear sdl vulkan
## Theory of operation
The nuklear SDL vulkan integration creates an independent graphics pipeline that will render the nuklear UI to separate render targets.
The application is responsible to fully manage these render targets. So it must ensure they are properly sized (and resized when requested).
Furthermore it is assumed that you will have a swap chain in place and the number of nuklear overlay images and number of swap chain images match.
This is how you can integrate it in your application:
```
/*
Setup: overlay_images have been created and their number match with the number
of the swap_chain_images of your application. The overlay_images in this
example have the same format as your swap_chain images (optional)
*/
struct nk_context *ctx = nk_sdl_init(
demo.win, demo.device, demo.physical_device, demo.indices.graphics,
demo.overlay_image_views, demo.swap_chain_images_len,
demo.swap_chain_image_format, 0,
MAX_VERTEX_BUFFER, MAX_ELEMENT_BUFFER);
[...]
/*
in your draw loop draw you can then render to the overlay image at
`image_index`
your own application can then wait for the semaphore and produce
the swap_chain_image at `image_index`
this should simply sample from the overlay_image (see example)
*/
nk_semaphore semaphore =
nk_sdl_render(demo.graphics_queue, image_index,
demo.image_available, NK_ANTI_ALIASING_ON);
if (!render(&demo, &bg, nk_semaphore, image_index)) {
fprintf(stderr, "render failed\n");
return false;
}
```
You must call `nk_sdl_resize` whenever the size of the overlay_images resize.
## Using images
Images can be used by providing a VkImageView as an nk_image_ptr to nuklear:
```
img = nk_image_ptr(demo.demo_texture_image_view);
```
Note that they must have SHADER_READ_OPTIMAL layout
It is currently not possible to specify how they are being sampled. The nuklear SDL vulkan integration uses a fixed sampler that does linear filtering.

2251
demo/sdl_vulkan/main.c Normal file

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,12 @@
#version 450
#extension GL_ARB_separate_shader_objects : enable
layout(binding = 0) uniform sampler2D overlay;
layout(location = 0) in vec2 inUV;
layout(location = 0) out vec4 outColor;
void main() {
outColor = texture(overlay, inUV);
}

View File

@ -0,0 +1,10 @@
#version 450
#extension GL_ARB_separate_shader_objects : enable
layout (location = 0) out vec2 outUV;
void main()
{
outUV = vec2((gl_VertexIndex << 1) & 2, gl_VertexIndex & 2);
gl_Position = vec4(outUV * 2.0f + -1.0f, 0.0f, 1.0f);
}

View File

@ -0,0 +1,11 @@
create_shader_inlined_header: nuklearshaders/nuklear.vert.spv nuklearshaders/nuklear.frag.spv
awk -v st='// NUKLEAR_SHADERS_START' -v et='// NUKLEAR_SHADERS_END' -v repl="$$(xxd -i nuklearshaders/nuklear.vert.spv && xxd -i nuklearshaders/nuklear.frag.spv)" '$$0 == st{del=1} $$0 == et{$$0 = repl; del=0} !del' nuklear_sdl_vulkan.in.h > nuklear_sdl_vulkan.h
nuklearshaders/nuklear.vert.spv: nuklearshaders/nuklear.vert
glslc --target-env=vulkan nuklearshaders/nuklear.vert -o nuklearshaders/nuklear.vert.spv
nuklearshaders/nuklear.frag.spv: nuklearshaders/nuklear.frag
glslc --target-env=vulkan nuklearshaders/nuklear.frag -o nuklearshaders/nuklear.frag.spv
clean:
rm nuklearshaders/nuklear.vert.spv nuklearshaders/nuklear.frag.spv nuklear_sdl_vulkan.h

View File

@ -0,0 +1,5 @@
Contrary to OpenGL Vulkan needs precompiled shaders in the SPIR-V format which makes it a bit more difficult to inline the shadercode.
After executing `make` the result should be a self contained `nuklear_sdl_vulkan.h`. Copy the result file to the parent directory and the "release" should be done.
You will need to have `xxd`, `glslc` and `awk` installed for this.

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,13 @@
#version 450
#extension GL_ARB_separate_shader_objects : enable
layout(binding = 0, set = 1) uniform sampler2D currentTexture;
layout(location = 0) in vec4 fragColor;
layout(location = 1) in vec2 fragUv;
layout(location = 0) out vec4 outColor;
void main() {
vec4 texColor = texture(currentTexture, fragUv);
outColor = fragColor * texColor;
}

View File

@ -0,0 +1,23 @@
#version 450
#extension GL_ARB_separate_shader_objects : enable
out gl_PerVertex {
vec4 gl_Position;
};
layout(binding = 0) uniform UniformBufferObject {
mat4 projection;
} ubo;
layout(location = 0) in vec2 position;
layout(location = 1) in vec2 uv;
layout(location = 2) in uvec4 color;
layout(location = 0) out vec4 fragColor;
layout(location = 1) out vec2 fragUv;
void main() {
gl_Position = ubo.projection * vec4(position, 0.0, 1.0);
gl_Position.y = -gl_Position.y;
fragColor = vec4(color[0]/255.0, color[1]/255.0, color[2]/255.0, color[3]/255.0);
fragUv = uv;
}

View File

@ -14,6 +14,7 @@
#define NK_SFML_GL2_H_
#include <SFML/Window.hpp>
#include <SFML/System/Clock.hpp>
NK_API struct nk_context* nk_sfml_init(sf::Window* window);
NK_API void nk_sfml_font_stash_begin(struct nk_font_atlas** atlas);
@ -51,6 +52,7 @@ static struct nk_sfml {
struct nk_sfml_device ogl;
struct nk_context ctx;
struct nk_font_atlas atlas;
sf::Clock* frame_delta_clock;
} sfml;
NK_INTERN void
@ -74,6 +76,9 @@ nk_sfml_render(enum nk_anti_aliasing AA)
int window_width = sfml.window->getSize().x;
int window_height = sfml.window->getSize().y;
sfml.ctx.delta_time_seconds = (float)((double)sfml.frame_delta_clock->getElapsedTime().asMicroseconds() / 1000000);
sfml.frame_delta_clock->restart();
glPushAttrib(GL_ENABLE_BIT | GL_COLOR_BUFFER_BIT | GL_TRANSFORM_BIT);
glDisable(GL_CULL_FACE);
glDisable(GL_DEPTH_TEST);
@ -229,6 +234,7 @@ nk_sfml_init(sf::Window* window)
sfml.ctx.clip.paste = nk_sfml_clipboard_paste;
sfml.ctx.clip.userdata = nk_handle_ptr(0);
nk_buffer_init_default(&sfml.ogl.cmds);
sfml.frame_delta_clock = new sf::Clock();
return &sfml.ctx;
}
@ -363,6 +369,7 @@ void nk_sfml_shutdown(void)
nk_free(&sfml.ctx);
glDeleteTextures(1, &dev->font_tex);
nk_buffer_free(&dev->cmds);
delete sfml.frame_delta_clock;
memset(&sfml, 0, sizeof(sfml));
}

View File

@ -66,6 +66,7 @@ static struct nk_sfml {
struct nk_sfml_device ogl;
struct nk_context ctx;
struct nk_font_atlas atlas;
sf::Clock* frame_delta_clock;
} sfml;
#ifdef __APPLE__
@ -202,6 +203,10 @@ nk_sfml_render(enum nk_anti_aliasing AA, int max_vertex_buffer, int max_element_
{ 0.0f, 0.0f, -1.0f, 0.0f },
{ -1.0f, 1.0f, 0.0f, 1.0f },
};
sfml.ctx.delta_time_seconds = (float)((double)sfml.frame_delta_clock->getElapsedTime().asMicroseconds() / 1000000);
sfml.frame_delta_clock->restart();
ortho[0][0] /= (GLfloat)window_width;
ortho[1][1] /= (GLfloat)window_height;
@ -336,6 +341,7 @@ nk_sfml_init(sf::Window* window)
sfml.ctx.clip.paste = nk_sfml_clipboard_paste;
sfml.ctx.clip.userdata = nk_handle_ptr(0);
nk_sfml_device_create();
sfml.frame_delta_clock = new sf::Clock();
return &sfml.ctx;
}
@ -469,6 +475,7 @@ void nk_sfml_shutdown()
nk_font_atlas_clear(&sfml.atlas);
nk_free(&sfml.ctx);
nk_sfml_device_destroy();
delete sfml.frame_delta_clock;
memset(&sfml, 0, sizeof(sfml));
}

View File

@ -1,5 +1,5 @@
# Install
BIN = zahnrad
BIN = demo
# Flags
CFLAGS += -std=c89 -Wall -Wextra -pedantic -Wno-unused-function -O2

View File

@ -68,10 +68,10 @@ NK_API void nk_xfont_del(Display *dpy, XFont *font);
#ifndef NK_X11_DOUBLE_CLICK_LO
#define NK_X11_DOUBLE_CLICK_LO 20
#define NK_X11_DOUBLE_CLICK_LO 0.02
#endif
#ifndef NK_X11_DOUBLE_CLICK_HI
#define NK_X11_DOUBLE_CLICK_HI 200
#define NK_X11_DOUBLE_CLICK_HI 0.20
#endif
typedef struct XSurface XSurface;
@ -112,15 +112,16 @@ static struct {
Cursor cursor;
Display *dpy;
Window root;
long last_button_click;
double last_button_click;
double time_of_last_frame;
} xlib;
NK_INTERN long
nk_timestamp(void)
NK_INTERN double
nk_get_time(void)
{
struct timeval tv;
if (gettimeofday(&tv, NULL) < 0) return 0;
return (long)((long)tv.tv_sec * 1000 + (long)tv.tv_usec/1000);
return ((double)tv.tv_sec + (double)tv.tv_usec/1000000);
}
NK_INTERN unsigned long
@ -662,6 +663,7 @@ nk_xlib_init(XFont *xfont, Display *dpy, int screen, Window root,
xlib.surf = nk_xsurf_create(screen, w, h);
nk_init_default(&xlib.ctx, font);
xlib.time_of_last_frame = nk_get_time();
return &xlib.ctx;
}
@ -793,10 +795,10 @@ nk_xlib_handle_event(Display *dpy, int screen, Window win, XEvent *evt)
const int x = evt->xbutton.x, y = evt->xbutton.y;
if (evt->xbutton.button == Button1) {
if (down) { /* Double-Click Button handler */
long dt = nk_timestamp() - xlib.last_button_click;
float dt = nk_get_time() - xlib.last_button_click;
if (dt > NK_X11_DOUBLE_CLICK_LO && dt < NK_X11_DOUBLE_CLICK_HI)
nk_input_button(ctx, NK_BUTTON_DOUBLE, x, y, nk_true);
xlib.last_button_click = nk_timestamp();
xlib.last_button_click = nk_get_time();
} else nk_input_button(ctx, NK_BUTTON_DOUBLE, x, y, nk_false);
nk_input_button(ctx, NK_BUTTON_LEFT, x, y, down);
} else if (evt->xbutton.button == Button2)
@ -905,6 +907,10 @@ nk_xlib_render(Drawable screen, struct nk_color clear)
struct nk_context *ctx = &xlib.ctx;
XSurface *surf = xlib.surf;
double now = nk_get_time();
xlib.ctx.delta_time_seconds = now - xlib.time_of_last_frame;
xlib.time_of_last_frame = now;
nk_xsurf_clear(xlib.surf, nk_color_from_byte(&clear.r));
nk_foreach(cmd, &xlib.ctx)
{

View File

@ -2,7 +2,7 @@
BIN = demo
# Compiler
CC = clang
CC ?= clang
DCC = gcc
# Flags
@ -13,11 +13,11 @@ OBJ = $(SRC:.c=.o)
# Modes
.PHONY: gcc
gcc: CC = gcc
gcc: CC ?= gcc
gcc: $(BIN)
.PHONY: clang
clang: CC = clang
clang: CC ?= clang
clang: $(BIN)
$(BIN):

View File

@ -46,10 +46,10 @@ NK_API void nk_x11_shutdown(void);
#include <GL/gl.h>
#ifndef NK_X11_DOUBLE_CLICK_LO
#define NK_X11_DOUBLE_CLICK_LO 20
#define NK_X11_DOUBLE_CLICK_LO 0.02
#endif
#ifndef NK_X11_DOUBLE_CLICK_HI
#define NK_X11_DOUBLE_CLICK_HI 200
#define NK_X11_DOUBLE_CLICK_HI 0.20
#endif
struct nk_x11_vertex {
@ -71,15 +71,16 @@ static struct nk_x11 {
Cursor cursor;
Display *dpy;
Window win;
long last_button_click;
double last_button_click;
double time_of_last_frame;
} x11;
NK_INTERN long
nk_timestamp(void)
NK_INTERN double
nk_get_time(void)
{
struct timeval tv;
if (gettimeofday(&tv, NULL) < 0) return 0;
return (long)((long)tv.tv_sec * 1000 + (long)tv.tv_usec/1000);
return ((double)tv.tv_sec + (double)tv.tv_usec/1000000);
}
NK_INTERN void
@ -102,6 +103,10 @@ nk_x11_render(enum nk_anti_aliasing AA, int max_vertex_buffer, int max_element_b
int width, height;
XWindowAttributes attr;
double now = nk_get_time();
x11.ctx.delta_time_seconds = now - x11.time_of_last_frame;
x11.time_of_last_frame = now;
NK_UNUSED(max_vertex_buffer);
NK_UNUSED(max_element_buffer);
@ -311,10 +316,10 @@ nk_x11_handle_event(XEvent *evt)
const int x = evt->xbutton.x, y = evt->xbutton.y;
if (evt->xbutton.button == Button1) {
if (down) { /* Double-Click Button handler */
long dt = nk_timestamp() - x11.last_button_click;
float dt = nk_get_time() - x11.last_button_click;
if (dt > NK_X11_DOUBLE_CLICK_LO && dt < NK_X11_DOUBLE_CLICK_HI)
nk_input_button(ctx, NK_BUTTON_DOUBLE, x, y, nk_true);
x11.last_button_click = nk_timestamp();
x11.last_button_click = nk_get_time();
} else nk_input_button(ctx, NK_BUTTON_DOUBLE, x, y, nk_false);
nk_input_button(ctx, NK_BUTTON_LEFT, x, y, down);
} else if (evt->xbutton.button == Button2)
@ -363,6 +368,7 @@ nk_x11_init(Display *dpy, Window win)
nk_buffer_init_default(&x11.ogl.cmds);
nk_init_default(&x11.ctx, 0);
x11.time_of_last_frame = nk_get_time();
return &x11.ctx;
}

View File

@ -2,7 +2,7 @@
BIN = demo
# Compiler
CC = clang
CC ?= clang
DCC = gcc
# Flags
@ -13,11 +13,11 @@ OBJ = $(SRC:.c=.o)
# Modes
.PHONY: gcc
gcc: CC = gcc
gcc: CC ?= gcc
gcc: $(BIN)
.PHONY: clang
clang: CC = clang
clang: CC ?= clang
clang: $(BIN)
$(BIN):

View File

@ -50,10 +50,10 @@ NK_API void nk_x11_device_destroy(void);
#include <GL/glx.h>
#ifndef NK_X11_DOUBLE_CLICK_LO
#define NK_X11_DOUBLE_CLICK_LO 20
#define NK_X11_DOUBLE_CLICK_LO 0.02
#endif
#ifndef NK_X11_DOUBLE_CLICK_HI
#define NK_X11_DOUBLE_CLICK_HI 200
#define NK_X11_DOUBLE_CLICK_HI 0.20
#endif
#ifdef NK_XLIB_LOAD_OPENGL_EXTENSIONS
@ -194,7 +194,8 @@ static struct nk_x11 {
Cursor cursor;
Display *dpy;
Window win;
long last_button_click;
double last_button_click;
double time_of_last_frame;
} x11;
#ifdef __APPLE__
@ -206,12 +207,12 @@ static struct nk_x11 {
#ifdef NK_XLIB_LOAD_OPENGL_EXTENSIONS
#include <GL/glx.h>
NK_INTERN long
nk_timestamp(void)
NK_INTERN double
nk_get_time(void)
{
struct timeval tv;
if (gettimeofday(&tv, NULL) < 0) return 0;
return (long)((long)tv.tv_sec * 1000 + (long)tv.tv_usec/1000);
return ((double)tv.tv_sec + (double)tv.tv_usec/1000000);
}
NK_INTERN int
@ -485,6 +486,10 @@ nk_x11_render(enum nk_anti_aliasing AA, int max_vertex_buffer, int max_element_b
{ 0.0f, 0.0f, -1.0f, 0.0f },
{ -1.0f, 1.0f, 0.0f, 1.0f },
};
double now = nk_get_time();
x11.ctx.delta_time_seconds = now - x11.time_of_last_frame;
x11.time_of_last_frame = now;
XGetWindowAttributes(x11.dpy, x11.win, &attr);
width = attr.width;
height = attr.height;
@ -678,10 +683,10 @@ nk_x11_handle_event(XEvent *evt)
const int x = evt->xbutton.x, y = evt->xbutton.y;
if (evt->xbutton.button == Button1) {
if (down) { /* Double-Click Button handler */
long dt = nk_timestamp() - x11.last_button_click;
float dt = nk_get_time() - x11.last_button_click;
if (dt > NK_X11_DOUBLE_CLICK_LO && dt < NK_X11_DOUBLE_CLICK_HI)
nk_input_button(ctx, NK_BUTTON_DOUBLE, x, y, nk_true);
x11.last_button_click = nk_timestamp();
x11.last_button_click = nk_get_time();
} else nk_input_button(ctx, NK_BUTTON_DOUBLE, x, y, nk_false);
nk_input_button(ctx, NK_BUTTON_LEFT, x, y, down);
} else if (evt->xbutton.button == Button2)
@ -730,6 +735,7 @@ nk_x11_init(Display *dpy, Window win)
XFreePixmap(dpy, blank);}
nk_init_default(&x11.ctx, 0);
x11.time_of_last_frame = nk_get_time();
return &x11.ctx;
}

View File

@ -1,5 +1,5 @@
# Install
BIN = zahnrad
BIN = demo
# Flags
CFLAGS += -std=c89 -Wall -Wextra -pedantic -Wno-unused-function -O2

View File

@ -76,10 +76,10 @@ NK_API void nk_xfont_del(Display *dpy, XFont *font);
#ifndef NK_X11_DOUBLE_CLICK_LO
#define NK_X11_DOUBLE_CLICK_LO 20
#define NK_X11_DOUBLE_CLICK_LO 0.02
#endif
#ifndef NK_X11_DOUBLE_CLICK_HI
#define NK_X11_DOUBLE_CLICK_HI 200
#define NK_X11_DOUBLE_CLICK_HI 0.20
#endif
typedef struct XSurface XSurface;
@ -131,15 +131,16 @@ static struct {
Visual *vis;
Colormap cmap;
#endif
long last_button_click;
double last_button_click;
double time_of_last_frame;
} xlib;
NK_INTERN long
nk_timestamp(void)
NK_INTERN double
nk_get_time(void)
{
struct timeval tv;
if (gettimeofday(&tv, NULL) < 0) return 0;
return (long)((long)tv.tv_sec * 1000 + (long)tv.tv_usec/1000);
return ((double)tv.tv_sec + (double)tv.tv_usec/1000000);
}
NK_INTERN unsigned long
@ -747,6 +748,7 @@ nk_xlib_init(XFont *xfont, Display *dpy, int screen, Window root,
XFreePixmap(dpy, blank);}
xlib.surf = nk_xsurf_create(screen, w, h);
nk_init_default(&xlib.ctx, font);
xlib.time_of_last_frame = nk_get_time();
return &xlib.ctx;
}
@ -878,10 +880,10 @@ nk_xlib_handle_event(Display *dpy, int screen, Window win, XEvent *evt)
const int x = evt->xbutton.x, y = evt->xbutton.y;
if (evt->xbutton.button == Button1) {
if (down) { /* Double-Click Button handler */
long dt = nk_timestamp() - xlib.last_button_click;
float dt = nk_get_time() - xlib.last_button_click;
if (dt > NK_X11_DOUBLE_CLICK_LO && dt < NK_X11_DOUBLE_CLICK_HI)
nk_input_button(ctx, NK_BUTTON_DOUBLE, x, y, nk_true);
xlib.last_button_click = nk_timestamp();
xlib.last_button_click = nk_get_time();
} else nk_input_button(ctx, NK_BUTTON_DOUBLE, x, y, nk_false);
nk_input_button(ctx, NK_BUTTON_LEFT, x, y, down);
} else if (evt->xbutton.button == Button2)
@ -990,6 +992,10 @@ nk_xlib_render(Drawable screen, struct nk_color clear)
struct nk_context *ctx = &xlib.ctx;
XSurface *surf = xlib.surf;
double now = nk_get_time();
xlib.ctx.delta_time_seconds = now - xlib.time_of_last_frame;
xlib.time_of_last_frame = now;
nk_xsurf_clear(xlib.surf, nk_color_from_byte(&clear.r));
nk_foreach(cmd, &xlib.ctx)
{

View File

@ -789,9 +789,9 @@ NK_API int nk_cairo_render(struct nk_cairo_context *cairo_ctx, struct nk_context
cairo_format_t format = CAIRO_FORMAT_ARGB32;
int stride = cairo_format_stride_for_width(format, im->img.w);
if (!im->img.handle.ptr) return;
if (!im->img.handle.ptr) return nk_false;
img_surf = cairo_image_surface_create_for_data(im->img.handle.ptr, format, im->img.w, im->img.h, stride);
if (!img_surf) return;
if (!img_surf) return nk_false;
cairo_save(cr);
cairo_rectangle(cr, im->x, im->y, im->w, im->h);

2739
doc/Doxyfile Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,26 +0,0 @@
# Install
BIN = doc
# Flags
CFLAGS += -std=c99 -pedantic -O2
SRC = stddoc.c
OBJ = $(SRC:.c=.o)
ifeq ($(OS),Windows_NT)
BIN := $(BIN).exe
LIBS =
else
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Darwin)
LIBS =
else
LIBS =
endif
endif
$(BIN): clean
$(CC) $(SRC) $(CFLAGS) -o $(BIN)
clean:
rm -f $(BIN) $(OBJS)

View File

@ -1,2 +0,0 @@
#!/bin/sh
cat ../nuklear.h|./doc > index.html

File diff suppressed because it is too large Load Diff

View File

@ -1,11 +0,0 @@
<!--
This page is here in order to allow redirecting the old nuklear.html URL over to index.html
-->
<html>
<head>
<meta http-equiv="refresh" content="0; URL=index.html" />
</head>
<body>
<p>If you are not redirected in five seconds, <a href="index.html">click here</a>.</p>
</body>
</html>

View File

@ -1,141 +0,0 @@
/// ## About
/// - _stddoc.c_ is a tiny documentation generator for 60 programming languages.
/// - This page sample was auto-generated from the code comments found in `stddoc.c` file.
///
/// ## How does it work?
/// - Markdeep code comments are extracted from stdin and printed into stdout as a HTML file.
///
/// ## Supported languages
/// - `/// Three slashes comment` [ActionScript, AngelScript, C (C99), C#, C++, ChaiScript, D,
/// GameMonkey, GML, Go, Java, JavaScript, JetScript, jtc, Jx9, Kotlin, Neko, Object Pascal (Delphi),
/// Objective-C, Pawn, PHP, QuakeC, Rust, SASS, Scala, Squirrel, Swift, Vala, Wren, Xojo].
/// - `--- Three dashes comment` [Ada, AppleScript, Eiffel, Euphoria, Haskell, Lua, Occam,
/// PL/SQL, PSL, SGML, SPARK, SQL, Terra, TSQL, VHDL].
/// - `### Three hashes comment` [AWK, Bash, Bourne shell, C shell, Cobra, Maple, Maple,
/// Perl, Perl6, PowerShell, Python, R, Ruby, Seed7, Tcl].
///
/// ## Usage
/// - `stddoc < source.code > documentation.html`
///
/// ## Changelog
/// 2018/01/07
/// : Initial version (_v1.0.0_)
///
/// ## License
/// - rlyeh, unlicensed (~public domain).
#include <stdio.h>
int main() {
printf("%s\n", "<meta charset='utf-8' emacsmode='-*- markdown -*-'>");
printf("%s\n", "<link rel='stylesheet' href='https://casual-effects.com/markdeep/latest/apidoc.css?'>");
for( int fsm_S = 0, fsm_D = 0, fsm_H = 0; !feof(stdin); ) {
int chr = getc(stdin);
if( fsm_S > 3 || fsm_D > 3 || fsm_H > 3 ) {
putc(chr, stdout);
if( chr != '\r' && chr != '\n' ) continue;
}
/**/ if( fsm_S <= 2 && chr == '/' && !fsm_D && !fsm_H ) fsm_S++;
else if( fsm_S == 3 && chr == ' ' && !fsm_D && !fsm_H ) fsm_S++;
else if( fsm_D <= 2 && chr == '-' && !fsm_S && !fsm_H ) fsm_D++;
else if( fsm_D == 3 && chr == ' ' && !fsm_S && !fsm_H ) fsm_D++;
else if( fsm_H <= 2 && chr == '#' && !fsm_S && !fsm_D ) fsm_H++;
else if( fsm_H == 3 && chr == ' ' && !fsm_S && !fsm_D ) fsm_H++;
else fsm_S = fsm_D = fsm_H = 0;
}
printf("%s\n", "<script>markdeepOptions={tocStyle:'medium'};</script>");
printf("%s\n", "<!-- Markdeep: --><script src='https://casual-effects.com/markdeep/latest/markdeep.min.js?'></script>");
}
///
/// ## **Example page!**
///
/// Imaginary documentation page. Here would be some introduction text.
///
/// The table of contents that Markdeep produces is stuffed on the right side,
/// if the browser window is wide enough. Otherwise it is hidden.
///
/// ### Basic Markdeep
///
/// Regular styling like **bold**, _italics_, ~~strikethrough~~, `inline code`, etc. Lists as:
///
/// * A
/// * Bullet
/// * List
///
/// And:
///
/// 1. A
/// 1. Numbered
/// 1. List!
///
/// Symbol substitutions: a 45-degree turn; some x -> y arrows; some whoa ==> fancy <==> arrows.
///
/// Is this a definition list?
/// : Looks like one to me
/// Is that right?
/// : Possibly!
///
/// And a code listing:
///
/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/// int main()
/// {
/// return 1;
/// }
/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
///
///
/// ### Tables
///
/// Thing Name | Description |Notes
/// ------------------------|--------------------|-----
/// Yes | Yup! |
/// No | Nope :( |
/// FileNotFound | Doesn't find files | Pass `-sFIND_FILE=maybe` to maybe find them
///
///
/// ### Diagrams
///
/// ******************************************* Here's a text to the right of the diagram,
/// * +-----------------+ .-. * ain't that fancy. Pretty fancy indeed, I
/// * |\ | .-+ | * must say! Markdeep diagrams are generally
/// * | \ A-B *---+--> .--+ '--. * enclosed into a rectangle full made of `*`
/// * | \ | | Cloud! | * symbols; and are "drawn" using ASCII-art
/// * +---+-------------+ '-------------' * style, with `- | + / \ * o` etc.
/// ******************************************* Suh-weet!
///
/// Another random diagram, just because:
///
/// ********************
/// * +-+-+-+-*-o *
/// * / / ^ / *
/// * / v / / *
/// * +-+-+-+ *
/// ********************
///
/// ### Special notes
///
/// !!! Note
/// Hey I'm a note. Don't mind me, I'm just sitting here.
///
/// !!! WARNING
/// I'm a warning, perhaps. *Something might happen!*
///
/// !!! Error: Never Pass `nullptr` to a Shader
/// Invoking a shader with a null argument can seg fault.
/// This is a multi-line admonition.
///
/// Seriously, don't call shaders like that.
///
/// ### Embedding HTML
///
/// <pre>
/// This is an embedded html node by the way!
/// </pre>
///
/// ## Credits
/// - API doc style created by [Aras Pranckevičius](https://github.com/aras-p)
/// - Markdeep by [Morgan McGuire](https://casual-effects.com/markdeep/).

6901
nuklear.h

File diff suppressed because it is too large Load Diff

View File

@ -1,216 +0,0 @@
/// # Nuklear
/// ![](https://cloud.githubusercontent.com/assets/8057201/11761525/ae06f0ca-a0c6-11e5-819d-5610b25f6ef4.gif)
///
/// ## Contents
/// 1. About section
/// 2. Highlights section
/// 3. Features section
/// 4. Usage section
/// 1. Flags section
/// 2. Constants section
/// 3. Dependencies section
/// 5. Example section
/// 6. API section
/// 1. Context section
/// 2. Input section
/// 3. Drawing section
/// 4. Window section
/// 5. Layouting section
/// 6. Groups section
/// 7. Tree section
/// 8. Properties section
/// 7. License section
/// 8. Changelog section
/// 9. Gallery section
/// 10. Credits section
///
/// ## About
/// This is a minimal state immediate mode graphical user interface toolkit
/// written in ANSI C and licensed under public domain. It was designed as a simple
/// embeddable user interface for application and does not have any dependencies,
/// a default renderbackend or OS window and input handling but instead provides a very modular
/// library approach by using simple input state for input and draw
/// commands describing primitive shapes as output. So instead of providing a
/// layered library that tries to abstract over a number of platform and
/// render backends it only focuses on the actual UI.
///
/// ## Highlights
/// - Graphical user interface toolkit
/// - Single header library
/// - Written in C89 (a.k.a. ANSI C or ISO C90)
/// - Small codebase (~18kLOC)
/// - Focus on portability, efficiency and simplicity
/// - No dependencies (not even the standard library if not wanted)
/// - Fully skinnable and customizable
/// - Low memory footprint with total memory control if needed or wanted
/// - UTF-8 support
/// - No global or hidden state
/// - Customizable library modules (you can compile and use only what you need)
/// - Optional font baker and vertex buffer output
/// - [Code available on github](https://github.com/Immediate-Mode-UI/Nuklear/)
///
/// ## Features
/// - Absolutely no platform dependent code
/// - Memory management control ranging from/to
/// - Ease of use by allocating everything from standard library
/// - Control every byte of memory inside the library
/// - Font handling control ranging from/to
/// - Use your own font implementation for everything
/// - Use this libraries internal font baking and handling API
/// - Drawing output control ranging from/to
/// - Simple shapes for more high level APIs which already have drawing capabilities
/// - Hardware accessible anti-aliased vertex buffer output
/// - Customizable colors and properties ranging from/to
/// - Simple changes to color by filling a simple color table
/// - Complete control with ability to use skinning to decorate widgets
/// - Bendable UI library with widget ranging from/to
/// - Basic widgets like buttons, checkboxes, slider, ...
/// - Advanced widget like abstract comboboxes, contextual menus,...
/// - Compile time configuration to only compile what you need
/// - Subset which can be used if you do not want to link or use the standard library
/// - Can be easily modified to only update on user input instead of frame updates
///
/// ## Usage
/// This library is self contained in one single header file and can be used either
/// in header only mode or in implementation mode. The header only mode is used
/// by default when included and allows including this header in other headers
/// and does not contain the actual implementation. <br /><br />
///
/// The implementation mode requires to define the preprocessor macro
/// NK_IMPLEMENTATION in *one* .c/.cpp file before #including this file, e.g.:
///
/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~C
/// #define NK_IMPLEMENTATION
/// #include "nuklear.h"
/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
///
/// Also optionally define the symbols listed in the section "OPTIONAL DEFINES"
/// below in header and implementation mode if you want to use additional functionality
/// or need more control over the library.
///
/// !!! WARNING
/// Every time nuklear is included define the same compiler flags. This very important not doing so could lead to compiler errors or even worse stack corruptions.
///
/// ### Flags
/// Flag | Description
/// --------------------------------|------------------------------------------
/// NK_PRIVATE | If defined declares all functions as static, so they can only be accessed inside the file that contains the implementation
/// NK_INCLUDE_FIXED_TYPES | If defined it will include header `<stdint.h>` for fixed sized types otherwise nuklear tries to select the correct type. If that fails it will throw a compiler error and you have to select the correct types yourself.
/// NK_INCLUDE_DEFAULT_ALLOCATOR | If defined it will include header `<stdlib.h>` and provide additional functions to use this library without caring for memory allocation control and therefore ease memory management.
/// NK_INCLUDE_STANDARD_IO | If defined it will include header `<stdio.h>` and provide additional functions depending on file loading.
/// NK_INCLUDE_STANDARD_VARARGS | If defined it will include header <stdarg.h> and provide additional functions depending on file loading.
/// NK_INCLUDE_STANDARD_BOOL | If defined it will include header `<stdbool.h>` for nk_bool otherwise nuklear defines nk_bool as int.
/// NK_INCLUDE_VERTEX_BUFFER_OUTPUT | Defining this adds a vertex draw command list backend to this library, which allows you to convert queue commands into vertex draw commands. This is mainly if you need a hardware accessible format for OpenGL, DirectX, Vulkan, Metal,...
/// NK_INCLUDE_FONT_BAKING | Defining this adds `stb_truetype` and `stb_rect_pack` implementation to this library and provides font baking and rendering. If you already have font handling or do not want to use this font handler you don't have to define it.
/// NK_INCLUDE_DEFAULT_FONT | Defining this adds the default font: ProggyClean.ttf into this library which can be loaded into a font atlas and allows using this library without having a truetype font
/// NK_INCLUDE_COMMAND_USERDATA | Defining this adds a userdata pointer into each command. Can be useful for example if you want to provide custom shaders depending on the used widget. Can be combined with the style structures.
/// NK_BUTTON_TRIGGER_ON_RELEASE | Different platforms require button clicks occurring either on buttons being pressed (up to down) or released (down to up). By default this library will react on buttons being pressed, but if you define this it will only trigger if a button is released.
/// NK_ZERO_COMMAND_MEMORY | Defining this will zero out memory for each drawing command added to a drawing queue (inside nk_command_buffer_push). Zeroing command memory is very useful for fast checking (using memcmp) if command buffers are equal and avoid drawing frames when nothing on screen has changed since previous frame.
/// NK_UINT_DRAW_INDEX | Defining this will set the size of vertex index elements when using NK_VERTEX_BUFFER_OUTPUT to 32bit instead of the default of 16bit
/// NK_KEYSTATE_BASED_INPUT | Define this if your backend uses key state for each frame rather than key press/release events
///
/// !!! WARNING
/// The following flags will pull in the standard C library:
/// - NK_INCLUDE_DEFAULT_ALLOCATOR
/// - NK_INCLUDE_STANDARD_IO
/// - NK_INCLUDE_STANDARD_VARARGS
///
/// !!! WARNING
/// The following flags if defined need to be defined for both header and implementation:
/// - NK_INCLUDE_FIXED_TYPES
/// - NK_INCLUDE_DEFAULT_ALLOCATOR
/// - NK_INCLUDE_STANDARD_VARARGS
/// - NK_INCLUDE_STANDARD_BOOL
/// - NK_INCLUDE_VERTEX_BUFFER_OUTPUT
/// - NK_INCLUDE_FONT_BAKING
/// - NK_INCLUDE_DEFAULT_FONT
/// - NK_INCLUDE_STANDARD_VARARGS
/// - NK_INCLUDE_COMMAND_USERDATA
/// - NK_UINT_DRAW_INDEX
///
/// ### Constants
/// Define | Description
/// --------------------------------|---------------------------------------
/// NK_BUFFER_DEFAULT_INITIAL_SIZE | Initial buffer size allocated by all buffers while using the default allocator functions included by defining NK_INCLUDE_DEFAULT_ALLOCATOR. If you don't want to allocate the default 4k memory then redefine it.
/// NK_MAX_NUMBER_BUFFER | Maximum buffer size for the conversion buffer between float and string Under normal circumstances this should be more than sufficient.
/// NK_INPUT_MAX | Defines the max number of bytes which can be added as text input in one frame. Under normal circumstances this should be more than sufficient.
///
/// !!! WARNING
/// The following constants if defined need to be defined for both header and implementation:
/// - NK_MAX_NUMBER_BUFFER
/// - NK_BUFFER_DEFAULT_INITIAL_SIZE
/// - NK_INPUT_MAX
///
/// ### Dependencies
/// Function | Description
/// ------------|---------------------------------------------------------------
/// NK_ASSERT | If you don't define this, nuklear will use <assert.h> with assert().
/// NK_MEMSET | You can define this to 'memset' or your own memset implementation replacement. If not nuklear will use its own version.
/// NK_MEMCPY | You can define this to 'memcpy' or your own memcpy implementation replacement. If not nuklear will use its own version.
/// NK_INV_SQRT | You can define this to your own inverse sqrt implementation replacement. If not nuklear will use its own slow and not highly accurate version.
/// NK_SIN | You can define this to 'sinf' or your own sine implementation replacement. If not nuklear will use its own approximation implementation.
/// NK_COS | You can define this to 'cosf' or your own cosine implementation replacement. If not nuklear will use its own approximation implementation.
/// NK_STRTOD | You can define this to `strtod` or your own string to double conversion implementation replacement. If not defined nuklear will use its own imprecise and possibly unsafe version (does not handle nan or infinity!).
/// NK_DTOA | You can define this to `dtoa` or your own double to string conversion implementation replacement. If not defined nuklear will use its own imprecise and possibly unsafe version (does not handle nan or infinity!).
/// NK_VSNPRINTF| If you define `NK_INCLUDE_STANDARD_VARARGS` as well as `NK_INCLUDE_STANDARD_IO` and want to be safe define this to `vsnprintf` on compilers supporting later versions of C or C++. By default nuklear will check for your stdlib version in C as well as compiler version in C++. if `vsnprintf` is available it will define it to `vsnprintf` directly. If not defined and if you have older versions of C or C++ it will be defined to `vsprintf` which is unsafe.
///
/// !!! WARNING
/// The following dependencies will pull in the standard C library if not redefined:
/// - NK_ASSERT
///
/// !!! WARNING
/// The following dependencies if defined need to be defined for both header and implementation:
/// - NK_ASSERT
///
/// !!! WARNING
/// The following dependencies if defined need to be defined only for the implementation part:
/// - NK_MEMSET
/// - NK_MEMCPY
/// - NK_SQRT
/// - NK_SIN
/// - NK_COS
/// - NK_STRTOD
/// - NK_DTOA
/// - NK_VSNPRINTF
///
/// ## Example
///
/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
/// // init gui state
/// enum {EASY, HARD};
/// static int op = EASY;
/// static float value = 0.6f;
/// static int i = 20;
/// struct nk_context ctx;
///
/// nk_init_fixed(&ctx, calloc(1, MAX_MEMORY), MAX_MEMORY, &font);
/// if (nk_begin(&ctx, "Show", nk_rect(50, 50, 220, 220),
/// NK_WINDOW_BORDER|NK_WINDOW_MOVABLE|NK_WINDOW_CLOSABLE)) {
/// // fixed widget pixel width
/// nk_layout_row_static(&ctx, 30, 80, 1);
/// if (nk_button_label(&ctx, "button")) {
/// // event handling
/// }
///
/// // fixed widget window ratio width
/// 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;
///
/// // custom widget pixel width
/// nk_layout_row_begin(&ctx, NK_STATIC, 30, 2);
/// {
/// nk_layout_row_push(&ctx, 50);
/// nk_label(&ctx, "Volume:", NK_TEXT_LEFT);
/// nk_layout_row_push(&ctx, 110);
/// nk_slider_float(&ctx, 0, &value, 1.0f, 0.1f);
/// }
/// nk_layout_row_end(&ctx);
/// }
/// nk_end(&ctx);
/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
///
/// ![](https://cloud.githubusercontent.com/assets/8057201/10187981/584ecd68-675c-11e5-897c-822ef534a876.png)
///
/// ## API
///

216
src/HEADER.md Normal file
View File

@ -0,0 +1,216 @@
# Nuklear
![](https://cloud.githubusercontent.com/assets/8057201/11761525/ae06f0ca-a0c6-11e5-819d-5610b25f6ef4.gif)
## Contents
1. About section
2. Highlights section
3. Features section
4. Usage section
1. Flags section
2. Constants section
3. Dependencies section
5. Example section
6. API section
1. Context section
2. Input section
3. Drawing section
4. Window section
5. Layouting section
6. Groups section
7. Tree section
8. Properties section
7. License section
8. Changelog section
9. Gallery section
10. Credits section
## About
This is a minimal state immediate mode graphical user interface toolkit
written in ANSI C and licensed under public domain. It was designed as a simple
embeddable user interface for application and does not have any dependencies,
a default renderbackend or OS window and input handling but instead provides a very modular
library approach by using simple input state for input and draw
commands describing primitive shapes as output. So instead of providing a
layered library that tries to abstract over a number of platform and
render backends it only focuses on the actual UI.
## Highlights
- Graphical user interface toolkit
- Single header library
- Written in C89 (a.k.a. ANSI C or ISO C90)
- Small codebase (~18kLOC)
- Focus on portability, efficiency and simplicity
- No dependencies (not even the standard library if not wanted)
- Fully skinnable and customizable
- Low memory footprint with total memory control if needed or wanted
- UTF-8 support
- No global or hidden state
- Customizable library modules (you can compile and use only what you need)
- Optional font baker and vertex buffer output
- [Code available on github](https://github.com/Immediate-Mode-UI/Nuklear/)
## Features
- Absolutely no platform dependent code
- Memory management control ranging from/to
- Ease of use by allocating everything from standard library
- Control every byte of memory inside the library
- Font handling control ranging from/to
- Use your own font implementation for everything
- Use this libraries internal font baking and handling API
- Drawing output control ranging from/to
- Simple shapes for more high level APIs which already have drawing capabilities
- Hardware accessible anti-aliased vertex buffer output
- Customizable colors and properties ranging from/to
- Simple changes to color by filling a simple color table
- Complete control with ability to use skinning to decorate widgets
- Bendable UI library with widget ranging from/to
- Basic widgets like buttons, checkboxes, slider, ...
- Advanced widget like abstract comboboxes, contextual menus,...
- Compile time configuration to only compile what you need
- Subset which can be used if you do not want to link or use the standard library
- Can be easily modified to only update on user input instead of frame updates
## Usage
This library is self contained in one single header file and can be used either
in header only mode or in implementation mode. The header only mode is used
by default when included and allows including this header in other headers
and does not contain the actual implementation. <br /><br />
The implementation mode requires to define the preprocessor macro
NK_IMPLEMENTATION in *one* .c/.cpp file before #including this file, e.g.:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~C
#define NK_IMPLEMENTATION
#include "nuklear.h"
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Also optionally define the symbols listed in the section "OPTIONAL DEFINES"
below in header and implementation mode if you want to use additional functionality
or need more control over the library.
!!! WARNING
Every time nuklear is included define the same compiler flags. This very important not doing so could lead to compiler errors or even worse stack corruptions.
### Flags
Flag | Description
--------------------------------|------------------------------------------
NK_PRIVATE | If defined declares all functions as static, so they can only be accessed inside the file that contains the implementation
NK_INCLUDE_FIXED_TYPES | If defined it will include header `<stdint.h>` for fixed sized types otherwise nuklear tries to select the correct type. If that fails it will throw a compiler error and you have to select the correct types yourself.
NK_INCLUDE_DEFAULT_ALLOCATOR | If defined it will include header `<stdlib.h>` and provide additional functions to use this library without caring for memory allocation control and therefore ease memory management.
NK_INCLUDE_STANDARD_IO | If defined it will include header `<stdio.h>` and provide additional functions depending on file loading.
NK_INCLUDE_STANDARD_VARARGS | If defined it will include header <stdarg.h> and provide additional functions depending on file loading.
NK_INCLUDE_STANDARD_BOOL | If defined it will include header `<stdbool.h>` for nk_bool otherwise nuklear defines nk_bool as int.
NK_INCLUDE_VERTEX_BUFFER_OUTPUT | Defining this adds a vertex draw command list backend to this library, which allows you to convert queue commands into vertex draw commands. This is mainly if you need a hardware accessible format for OpenGL, DirectX, Vulkan, Metal,...
NK_INCLUDE_FONT_BAKING | Defining this adds `stb_truetype` and `stb_rect_pack` implementation to this library and provides font baking and rendering. If you already have font handling or do not want to use this font handler you don't have to define it.
NK_INCLUDE_DEFAULT_FONT | Defining this adds the default font: ProggyClean.ttf into this library which can be loaded into a font atlas and allows using this library without having a truetype font
NK_INCLUDE_COMMAND_USERDATA | Defining this adds a userdata pointer into each command. Can be useful for example if you want to provide custom shaders depending on the used widget. Can be combined with the style structures.
NK_BUTTON_TRIGGER_ON_RELEASE | Different platforms require button clicks occurring either on buttons being pressed (up to down) or released (down to up). By default this library will react on buttons being pressed, but if you define this it will only trigger if a button is released.
NK_ZERO_COMMAND_MEMORY | Defining this will zero out memory for each drawing command added to a drawing queue (inside nk_command_buffer_push). Zeroing command memory is very useful for fast checking (using memcmp) if command buffers are equal and avoid drawing frames when nothing on screen has changed since previous frame.
NK_UINT_DRAW_INDEX | Defining this will set the size of vertex index elements when using NK_VERTEX_BUFFER_OUTPUT to 32bit instead of the default of 16bit
NK_KEYSTATE_BASED_INPUT | Define this if your backend uses key state for each frame rather than key press/release events
!!! WARNING
The following flags will pull in the standard C library:
- NK_INCLUDE_DEFAULT_ALLOCATOR
- NK_INCLUDE_STANDARD_IO
- NK_INCLUDE_STANDARD_VARARGS
!!! WARNING
The following flags if defined need to be defined for both header and implementation:
- NK_INCLUDE_FIXED_TYPES
- NK_INCLUDE_DEFAULT_ALLOCATOR
- NK_INCLUDE_STANDARD_VARARGS
- NK_INCLUDE_STANDARD_BOOL
- NK_INCLUDE_VERTEX_BUFFER_OUTPUT
- NK_INCLUDE_FONT_BAKING
- NK_INCLUDE_DEFAULT_FONT
- NK_INCLUDE_STANDARD_VARARGS
- NK_INCLUDE_COMMAND_USERDATA
- NK_UINT_DRAW_INDEX
### Constants
Define | Description
--------------------------------|---------------------------------------
NK_BUFFER_DEFAULT_INITIAL_SIZE | Initial buffer size allocated by all buffers while using the default allocator functions included by defining NK_INCLUDE_DEFAULT_ALLOCATOR. If you don't want to allocate the default 4k memory then redefine it.
NK_MAX_NUMBER_BUFFER | Maximum buffer size for the conversion buffer between float and string Under normal circumstances this should be more than sufficient.
NK_INPUT_MAX | Defines the max number of bytes which can be added as text input in one frame. Under normal circumstances this should be more than sufficient.
!!! WARNING
The following constants if defined need to be defined for both header and implementation:
- NK_MAX_NUMBER_BUFFER
- NK_BUFFER_DEFAULT_INITIAL_SIZE
- NK_INPUT_MAX
### Dependencies
Function | Description
------------|---------------------------------------------------------------
NK_ASSERT | If you don't define this, nuklear will use <assert.h> with assert().
NK_MEMSET | You can define this to 'memset' or your own memset implementation replacement. If not nuklear will use its own version.
NK_MEMCPY | You can define this to 'memcpy' or your own memcpy implementation replacement. If not nuklear will use its own version.
NK_INV_SQRT | You can define this to your own inverse sqrt implementation replacement. If not nuklear will use its own slow and not highly accurate version.
NK_SIN | You can define this to 'sinf' or your own sine implementation replacement. If not nuklear will use its own approximation implementation.
NK_COS | You can define this to 'cosf' or your own cosine implementation replacement. If not nuklear will use its own approximation implementation.
NK_STRTOD | You can define this to `strtod` or your own string to double conversion implementation replacement. If not defined nuklear will use its own imprecise and possibly unsafe version (does not handle nan or infinity!).
NK_DTOA | You can define this to `dtoa` or your own double to string conversion implementation replacement. If not defined nuklear will use its own imprecise and possibly unsafe version (does not handle nan or infinity!).
NK_VSNPRINTF| If you define `NK_INCLUDE_STANDARD_VARARGS` as well as `NK_INCLUDE_STANDARD_IO` and want to be safe define this to `vsnprintf` on compilers supporting later versions of C or C++. By default nuklear will check for your stdlib version in C as well as compiler version in C++. if `vsnprintf` is available it will define it to `vsnprintf` directly. If not defined and if you have older versions of C or C++ it will be defined to `vsprintf` which is unsafe.
!!! WARNING
The following dependencies will pull in the standard C library if not redefined:
- NK_ASSERT
!!! WARNING
The following dependencies if defined need to be defined for both header and implementation:
- NK_ASSERT
!!! WARNING
The following dependencies if defined need to be defined only for the implementation part:
- NK_MEMSET
- NK_MEMCPY
- NK_SQRT
- NK_SIN
- NK_COS
- NK_STRTOD
- NK_DTOA
- NK_VSNPRINTF
## Example
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
// init gui state
enum {EASY, HARD};
static int op = EASY;
static float value = 0.6f;
static int i = 20;
struct nk_context ctx;
nk_init_fixed(&ctx, calloc(1, MAX_MEMORY), MAX_MEMORY, &font);
if (nk_begin(&ctx, "Show", nk_rect(50, 50, 220, 220),
NK_WINDOW_BORDER|NK_WINDOW_MOVABLE|NK_WINDOW_CLOSABLE)) {
// fixed widget pixel width
nk_layout_row_static(&ctx, 30, 80, 1);
if (nk_button_label(&ctx, "button")) {
// event handling
}
// fixed widget window ratio width
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;
// custom widget pixel width
nk_layout_row_begin(&ctx, NK_STATIC, 30, 2);
{
nk_layout_row_push(&ctx, 50);
nk_label(&ctx, "Volume:", NK_TEXT_LEFT);
nk_layout_row_push(&ctx, 110);
nk_slider_float(&ctx, 0, &value, 1.0f, 0.1f);
}
nk_layout_row_end(&ctx);
}
nk_end(&ctx);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
![](https://cloud.githubusercontent.com/assets/8057201/10187981/584ecd68-675c-11e5-897c-822ef534a876.png)
## API

File diff suppressed because it is too large Load Diff

View File

@ -242,7 +242,7 @@ nk_buffer_free(struct nk_buffer *b)
b->pool.free(b->pool.userdata, b->memory.ptr);
}
NK_API void
nk_buffer_info(struct nk_memory_status *s, struct nk_buffer *b)
nk_buffer_info(struct nk_memory_status *s, const struct nk_buffer *b)
{
NK_ASSERT(b);
NK_ASSERT(s);
@ -268,10 +268,9 @@ nk_buffer_memory_const(const struct nk_buffer *buffer)
return buffer->memory.ptr;
}
NK_API nk_size
nk_buffer_total(struct nk_buffer *buffer)
nk_buffer_total(const struct nk_buffer *buffer)
{
NK_ASSERT(buffer);
if (!buffer) return 0;
return buffer->memory.size;
}

View File

@ -23,7 +23,7 @@ nk_parse_hex(const char *p, int length)
return i;
}
NK_API struct nk_color
nk_rgb_factor(struct nk_color col, const float factor)
nk_rgb_factor(struct nk_color col, float factor)
{
if (factor == 1.0f)
return col;
@ -246,7 +246,7 @@ nk_hsva_colorf(float h, float s, float v, float a)
return out;
}
NK_API struct nk_colorf
nk_hsva_colorfv(float *c)
nk_hsva_colorfv(const float *c)
{
return nk_hsva_colorf(c[0], c[1], c[2], c[3]);
}
@ -421,4 +421,3 @@ nk_color_hsv_bv(nk_byte *out, struct nk_color in)
out[1] = (nk_byte)tmp[1];
out[2] = (nk_byte)tmp[2];
}

View File

@ -702,7 +702,7 @@ NK_API void nk_combo_close(struct nk_context *ctx)
nk_contextual_close(ctx);
}
NK_API int
nk_combo(struct nk_context *ctx, const char **items, int count,
nk_combo(struct nk_context *ctx, const char *const *items, int count,
int selected, int item_height, struct nk_vec2 size)
{
int i = 0;
@ -820,7 +820,7 @@ nk_combo_callback(struct nk_context *ctx, void(*item_getter)(void*, int, const c
} return selected;
}
NK_API void
nk_combobox(struct nk_context *ctx, const char **items, int count,
nk_combobox(struct nk_context *ctx, const char *const *items, int count,
int *selected, int item_height, struct nk_vec2 size)
{
*selected = nk_combo(ctx, items, count, *selected, item_height, size);
@ -845,4 +845,3 @@ nk_combobox_callback(struct nk_context *ctx,
{
*selected = nk_combo_callback(ctx, item_getter, userdata, *selected, count, item_height, size);
}

View File

@ -329,7 +329,7 @@ nk_fill_triangle(struct nk_command_buffer *b, float x0, float y0, float x1,
cmd->color = c;
}
NK_API void
nk_stroke_polygon(struct nk_command_buffer *b, float *points, int point_count,
nk_stroke_polygon(struct nk_command_buffer *b, const float *points, int point_count,
float line_thickness, struct nk_color col)
{
int i;
@ -350,7 +350,7 @@ nk_stroke_polygon(struct nk_command_buffer *b, float *points, int point_count,
}
}
NK_API void
nk_fill_polygon(struct nk_command_buffer *b, float *points, int point_count,
nk_fill_polygon(struct nk_command_buffer *b, const float *points, int point_count,
struct nk_color col)
{
int i;
@ -371,7 +371,7 @@ nk_fill_polygon(struct nk_command_buffer *b, float *points, int point_count,
}
}
NK_API void
nk_stroke_polyline(struct nk_command_buffer *b, float *points, int point_count,
nk_stroke_polyline(struct nk_command_buffer *b, const float *points, int point_count,
float line_thickness, struct nk_color col)
{
int i;
@ -555,4 +555,3 @@ nk_draw_text(struct nk_command_buffer *b, struct nk_rect r,
NK_MEMCPY(cmd->string, string, (nk_size)length);
cmd->string[length] = '\0';
}

View File

@ -504,7 +504,7 @@ nk_font_query_font_glyph(nk_handle handle, float height,
}
#endif
NK_API const struct nk_font_glyph*
nk_font_find_glyph(struct nk_font *font, nk_rune unicode)
nk_font_find_glyph(const struct nk_font *font, nk_rune unicode)
{
int i = 0;
int count;
@ -567,8 +567,8 @@ nk_font_init(struct nk_font *font, float pixel_height,
*
* ProggyClean.ttf
* Copyright (c) 2004, 2005 Tristan Grimmer
* MIT license (see License.txt in http://www.upperbounds.net/download/ProggyClean.ttf.zip)
* Download and more information at http://upperbounds.net
* MIT license https://github.com/bluescan/proggyfonts/blob/master/LICENSE
* Download and more information at https://github.com/bluescan/proggyfonts
*-----------------------------------------------------------------------------*/
#ifdef __clang__
#pragma clang diagnostic push
@ -1370,4 +1370,3 @@ nk_font_atlas_clear(struct nk_font_atlas *atlas)
nk_zero_struct(*atlas);
}
#endif

View File

@ -103,6 +103,12 @@ NK_LIB float nk_sin(float x);
#ifndef NK_COS
NK_LIB float nk_cos(float x);
#endif
#ifndef NK_ATAN
NK_LIB float nk_atan(float x);
#endif
#ifndef NK_ATAN2
NK_LIB float nk_atan2(float y, float x);
#endif
NK_LIB nk_uint nk_round_up_pow2(nk_uint v);
NK_LIB struct nk_rect nk_shrink_rect(struct nk_rect r, float amount);
NK_LIB struct nk_rect nk_pad_rect(struct nk_rect r, struct nk_vec2 pad);
@ -112,6 +118,7 @@ NK_LIB int nk_ifloord(double x);
NK_LIB int nk_ifloorf(float x);
NK_LIB int nk_iceilf(float x);
NK_LIB int nk_log10(double n);
NK_LIB float nk_roundf(float x);
/* util */
enum {NK_DO_NOT_STOP_ON_NEW_LINE, NK_STOP_ON_NEW_LINE};
@ -179,7 +186,7 @@ enum nk_window_insert_location {
NK_LIB void *nk_create_window(struct nk_context *ctx);
NK_LIB void nk_remove_window(struct nk_context*, struct nk_window*);
NK_LIB void nk_free_window(struct nk_context *ctx, struct nk_window *win);
NK_LIB struct nk_window *nk_find_window(struct nk_context *ctx, nk_hash hash, const char *name);
NK_LIB struct nk_window *nk_find_window(const struct nk_context *ctx, nk_hash hash, const char *name);
NK_LIB void nk_insert_window(struct nk_context *ctx, struct nk_window *win, enum nk_window_insert_location loc);
/* pool */
@ -199,7 +206,7 @@ NK_LIB void nk_remove_table(struct nk_window *win, struct nk_table *tbl);
NK_LIB void nk_free_table(struct nk_context *ctx, struct nk_table *tbl);
NK_LIB void nk_push_table(struct nk_window *win, struct nk_table *tbl);
NK_LIB nk_uint *nk_add_value(struct nk_context *ctx, struct nk_window *win, nk_hash name, nk_uint value);
NK_LIB nk_uint *nk_find_value(struct nk_window *win, nk_hash name);
NK_LIB nk_uint *nk_find_value(const struct nk_window *win, nk_hash name);
/* panel */
NK_LIB void *nk_create_panel(struct nk_context *ctx);
@ -220,7 +227,7 @@ NK_LIB void nk_row_layout(struct nk_context *ctx, enum nk_layout_format fmt, flo
NK_LIB void nk_panel_alloc_row(const struct nk_context *ctx, struct nk_window *win);
NK_LIB void nk_layout_widget_space(struct nk_rect *bounds, const struct nk_context *ctx, struct nk_window *win, int modify);
NK_LIB void nk_panel_alloc_space(struct nk_rect *bounds, const struct nk_context *ctx);
NK_LIB void nk_layout_peek(struct nk_rect *bounds, struct nk_context *ctx);
NK_LIB void nk_layout_peek(struct nk_rect *bounds, const struct nk_context *ctx);
/* popup */
NK_LIB nk_bool nk_nonblock_begin(struct nk_context *ctx, nk_flags flags, struct nk_rect body, struct nk_rect header, enum nk_panel_type panel_type);
@ -368,4 +375,3 @@ nk_stbtt_free(void *ptr, void *user_data) {
#endif /* NK_INCLUDE_FONT_BAKING */
#endif

250
src/nuklear_knob.c Normal file
View File

@ -0,0 +1,250 @@
#include "nuklear.h"
#include "nuklear_internal.h"
/* ===============================================================
*
* KNOB
*
* ===============================================================*/
NK_LIB float
nk_knob_behavior(nk_flags *state, struct nk_input *in,
struct nk_rect bounds, float knob_min, float knob_max, float knob_value,
float knob_step, float knob_steps,
enum nk_heading zero_direction, float dead_zone_percent)
{
struct nk_vec2 origin;
float angle = 0.0f;
origin.x = bounds.x + (bounds.w / 2);
origin.y = bounds.y + (bounds.h / 2);
nk_widget_state_reset(state);
/* handle click and drag input */
if(in &&
in->mouse.buttons[NK_BUTTON_LEFT].down &&
nk_input_has_mouse_click_down_in_rect(in, NK_BUTTON_LEFT, bounds, nk_true)){
/* calculate angle from origin and rotate */
const float direction_rads[4] = {
NK_PI * 2.5f, /* 90 NK_UP */
NK_PI * 2.0f, /* 0 NK_RIGHT */
NK_PI * 1.5f, /* 270 NK_DOWN */
NK_PI, /* 180 NK_LEFT */
};
*state = NK_WIDGET_STATE_ACTIVE;
angle = NK_ATAN2(in->mouse.pos.y - origin.y, in->mouse.pos.x - origin.x) + direction_rads[zero_direction];
angle -= (angle > NK_PI * 2) ? NK_PI * 3 : NK_PI;
/* account for dead space applied when drawing */
angle *= 1.0f / (1.0f - dead_zone_percent);
angle = NK_CLAMP(-NK_PI, angle, NK_PI);
/* convert -pi -> pi range to 0.0 -> 1.0 */
angle = (angle + NK_PI) / (NK_PI * 2);
/* click to closest step */
knob_value = knob_min + ( (int)(angle * knob_steps + (knob_step / 2)) ) * knob_step;
knob_value = NK_CLAMP(knob_min, knob_value, knob_max);
}
/* knob widget state */
if (nk_input_is_mouse_hovering_rect(in, bounds)){
*state = NK_WIDGET_STATE_HOVERED;
if (in) {
/* handle scroll and arrow inputs */
if (in->mouse.scroll_delta.y > 0 ||
(in->keyboard.keys[NK_KEY_UP].down && in->keyboard.keys[NK_KEY_UP].clicked))
knob_value += knob_step;
if (in->mouse.scroll_delta.y < 0 ||
(in->keyboard.keys[NK_KEY_DOWN].down && in->keyboard.keys[NK_KEY_DOWN].clicked))
knob_value -= knob_step;
}
knob_value = NK_CLAMP(knob_min, knob_value, knob_max);
}
if (*state & NK_WIDGET_STATE_HOVER &&
!nk_input_is_mouse_prev_hovering_rect(in, bounds))
*state |= NK_WIDGET_STATE_ENTERED;
else if (nk_input_is_mouse_prev_hovering_rect(in, bounds))
*state |= NK_WIDGET_STATE_LEFT;
return knob_value;
}
NK_LIB void
nk_draw_knob(struct nk_command_buffer *out, nk_flags state,
const struct nk_style_knob *style, const struct nk_rect *bounds, float min, float value, float max,
enum nk_heading zero_direction, float dead_zone_percent)
{
const struct nk_style_item *background;
struct nk_color knob_color, cursor;
NK_UNUSED(min);
NK_UNUSED(max);
NK_UNUSED(value);
if (state & NK_WIDGET_STATE_ACTIVED) {
background = &style->active;
knob_color = style->knob_active;
cursor = style->cursor_active;
} else if (state & NK_WIDGET_STATE_HOVER) {
background = &style->hover;
knob_color = style->knob_hover;
cursor = style->cursor_hover;
} else {
background = &style->normal;
knob_color = style->knob_normal;
cursor = style->cursor_normal;
}
/* draw background */
switch(background->type) {
case NK_STYLE_ITEM_IMAGE:
nk_draw_image(out, *bounds, &background->data.image, nk_rgb_factor(nk_white, style->color_factor));
break;
case NK_STYLE_ITEM_NINE_SLICE:
nk_draw_nine_slice(out, *bounds, &background->data.slice, nk_rgb_factor(nk_white, style->color_factor));
break;
case NK_STYLE_ITEM_COLOR:
nk_fill_rect(out, *bounds, 0, nk_rgb_factor(background->data.color, style->color_factor));
nk_stroke_rect(out, *bounds, 0, style->border, nk_rgb_factor(style->border_color, style->color_factor));
break;
}
/* draw knob */
nk_fill_circle(out, *bounds, nk_rgb_factor(knob_color, style->color_factor));
if(style->knob_border > 0){
struct nk_rect border_bounds = *bounds;
border_bounds.x += style->knob_border / 2;
border_bounds.y += style->knob_border / 2;
border_bounds.w -= style->knob_border;
border_bounds.h -= style->knob_border;
nk_stroke_circle(out, border_bounds, style->knob_border, nk_rgb_factor(style->knob_border_color, style->color_factor));
}
{ /* calculate cursor line cords */
float half_circle_size = (bounds->w / 2);
float angle = (value - min) / (max - min);
float alive_zone = 1.0f - dead_zone_percent;
struct nk_vec2 cursor_start, cursor_end;
const float direction_rads[4] = {
NK_PI * 1.5f, /* 90 NK_UP */
0.0f, /* 0 NK_RIGHT */
NK_PI * 0.5f, /* 270 NK_DOWN */
NK_PI, /* 180 NK_LEFT */
};
/* calculate + apply dead zone */
angle = (angle * alive_zone) + (dead_zone_percent / 2);
/* percentage 0.0 -> 1.0 to radians, rads are 0.0 to (2*pi) NOT -pi to pi */
angle *= NK_PI * 2;
/* apply zero angle */
angle += direction_rads[zero_direction];
if(angle > NK_PI * 2)
angle -= NK_PI * 2;
cursor_start.x = bounds->x + half_circle_size + (angle > NK_PI);
cursor_start.y = bounds->y + half_circle_size + (angle < NK_PI_HALF || angle > (NK_PI * 1.5f));
cursor_end.x = cursor_start.x + (half_circle_size * NK_COS(angle));
cursor_end.y = cursor_start.y + (half_circle_size * NK_SIN(angle));
/* cut off half of the cursor */
cursor_start.x = (cursor_start.x + cursor_end.x) / 2;
cursor_start.y = (cursor_start.y + cursor_end.y) / 2;
/* draw cursor */
nk_stroke_line(out, cursor_start.x, cursor_start.y, cursor_end.x, cursor_end.y, 2, nk_rgb_factor(cursor, style->color_factor));
}
}
NK_LIB float
nk_do_knob(nk_flags *state,
struct nk_command_buffer *out, struct nk_rect bounds,
float min, float val, float max, float step,
enum nk_heading zero_direction, float dead_zone_percent,
const struct nk_style_knob *style, struct nk_input *in)
{
float knob_range;
float knob_min;
float knob_max;
float knob_value;
float knob_steps;
NK_ASSERT(style);
NK_ASSERT(out);
if (!out || !style)
return 0;
/* remove padding from knob bounds */
bounds.y = bounds.y + style->padding.y;
bounds.x = bounds.x + style->padding.x;
bounds.h = NK_MAX(bounds.h, 2*style->padding.y);
bounds.w = NK_MAX(bounds.w, 2*style->padding.x);
bounds.w -= 2 * style->padding.x;
bounds.h -= 2 * style->padding.y;
if(bounds.h < bounds.w){
bounds.x += (bounds.w - bounds.h) / 2;
bounds.w = bounds.h;
}
/* make sure the provided values are correct */
knob_max = NK_MAX(min, max);
knob_min = NK_MIN(min, max);
knob_value = NK_CLAMP(knob_min, val, knob_max);
knob_range = knob_max - knob_min;
knob_steps = knob_range / step;
knob_value = nk_knob_behavior(state, in, bounds, knob_min, knob_max, knob_value, step, knob_steps, zero_direction, dead_zone_percent);
/* draw knob */
if (style->draw_begin) style->draw_begin(out, style->userdata);
nk_draw_knob(out, *state, style, &bounds, knob_min, knob_value, knob_max, zero_direction, dead_zone_percent);
if (style->draw_end) style->draw_end(out, style->userdata);
return knob_value;
}
NK_API nk_bool
nk_knob_float(struct nk_context *ctx, float min_value, float *value, float max_value,
float value_step, enum nk_heading zero_direction, float dead_zone_degrees)
{
struct nk_window *win;
struct nk_panel *layout;
struct nk_input *in;
const struct nk_style *style;
int ret = 0;
float old_value;
struct nk_rect bounds;
enum nk_widget_layout_states state;
NK_ASSERT(ctx);
NK_ASSERT(ctx->current);
NK_ASSERT(ctx->current->layout);
NK_ASSERT(value);
NK_ASSERT(NK_BETWEEN(dead_zone_degrees, 0.0f, 360.0f));
if (!ctx || !ctx->current || !ctx->current->layout || !value)
return ret;
win = ctx->current;
style = &ctx->style;
layout = win->layout;
state = nk_widget(&bounds, ctx);
if (!state) return ret;
in = (state == NK_WIDGET_DISABLED || layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input;
old_value = *value;
*value = nk_do_knob(&ctx->last_widget_state, &win->buffer, bounds, min_value,
old_value, max_value, value_step, zero_direction, dead_zone_degrees / 360.0f, &style->knob, in);
return (old_value > *value || old_value < *value);
}
NK_API nk_bool
nk_knob_int(struct nk_context *ctx, int min, int *val, int max, int step,
enum nk_heading zero_direction, float dead_zone_degrees)
{
int ret;
float value = (float)*val;
ret = nk_knob_float(ctx, (float)min, &value, (float)max, (float)step, zero_direction, dead_zone_degrees);
*val = (int)value;
return ret;
}

View File

@ -134,7 +134,7 @@ nk_row_layout(struct nk_context *ctx, enum nk_layout_format fmt,
win->layout->row.item_width = (float)width;
}
NK_API float
nk_layout_ratio_from_pixel(struct nk_context *ctx, float pixel_width)
nk_layout_ratio_from_pixel(const struct nk_context *ctx, float pixel_width)
{
struct nk_window *win;
NK_ASSERT(ctx);
@ -463,7 +463,7 @@ nk_layout_space_push(struct nk_context *ctx, struct nk_rect rect)
layout->row.item = rect;
}
NK_API struct nk_rect
nk_layout_space_bounds(struct nk_context *ctx)
nk_layout_space_bounds(const struct nk_context *ctx)
{
struct nk_rect ret;
struct nk_window *win;
@ -482,7 +482,7 @@ nk_layout_space_bounds(struct nk_context *ctx)
return ret;
}
NK_API struct nk_rect
nk_layout_widget_bounds(struct nk_context *ctx)
nk_layout_widget_bounds(const struct nk_context *ctx)
{
struct nk_rect ret;
struct nk_window *win;
@ -501,7 +501,7 @@ nk_layout_widget_bounds(struct nk_context *ctx)
return ret;
}
NK_API struct nk_vec2
nk_layout_space_to_screen(struct nk_context *ctx, struct nk_vec2 ret)
nk_layout_space_to_screen(const struct nk_context *ctx, struct nk_vec2 ret)
{
struct nk_window *win;
struct nk_panel *layout;
@ -517,7 +517,7 @@ nk_layout_space_to_screen(struct nk_context *ctx, struct nk_vec2 ret)
return ret;
}
NK_API struct nk_vec2
nk_layout_space_to_local(struct nk_context *ctx, struct nk_vec2 ret)
nk_layout_space_to_local(const struct nk_context *ctx, struct nk_vec2 ret)
{
struct nk_window *win;
struct nk_panel *layout;
@ -533,7 +533,7 @@ nk_layout_space_to_local(struct nk_context *ctx, struct nk_vec2 ret)
return ret;
}
NK_API struct nk_rect
nk_layout_space_rect_to_screen(struct nk_context *ctx, struct nk_rect ret)
nk_layout_space_rect_to_screen(const struct nk_context *ctx, struct nk_rect ret)
{
struct nk_window *win;
struct nk_panel *layout;
@ -549,7 +549,7 @@ nk_layout_space_rect_to_screen(struct nk_context *ctx, struct nk_rect ret)
return ret;
}
NK_API struct nk_rect
nk_layout_space_rect_to_local(struct nk_context *ctx, struct nk_rect ret)
nk_layout_space_rect_to_local(const struct nk_context *ctx, struct nk_rect ret)
{
struct nk_window *win;
struct nk_panel *layout;
@ -601,7 +601,7 @@ nk_layout_widget_space(struct nk_rect *bounds, const struct nk_context *ctx,
panel_space = nk_layout_row_calculate_usable_space(&ctx->style, layout->type,
layout->bounds.w, layout->row.columns);
#define NK_FRAC(x) (x - (float)(int)x) /* will be used to remove fookin gaps */
#define NK_FRAC(x) (x - (float)(int)nk_roundf(x)) /* will be used to remove fookin gaps */
/* calculate the width of one item inside the current layout space */
switch (layout->row.type) {
case NK_LAYOUT_DYNAMIC_FIXED: {
@ -730,7 +730,7 @@ nk_panel_alloc_space(struct nk_rect *bounds, const struct nk_context *ctx)
layout->row.index++;
}
NK_LIB void
nk_layout_peek(struct nk_rect *bounds, struct nk_context *ctx)
nk_layout_peek(struct nk_rect *bounds, const struct nk_context *ctx)
{
float y;
int index;

View File

@ -84,6 +84,52 @@ nk_cos(float x)
return a0 + x*(a1 + x*(a2 + x*(a3 + x*(a4 + x*(a5 + x*(a6 + x*(a7 + x*a8)))))));
}
#endif
#ifndef NK_ATAN
#define NK_ATAN nk_atan
NK_LIB float
nk_atan(float x)
{
/* ./lolremez --progress --float -d 9 -r "0:pi*2" "atan(x)" */
float u = -1.0989005e-05f;
NK_ASSERT(x >= 0.0f && "TODO support negative floats");
u = u * x + 0.00034117949f;
u = u * x + -0.0044932296f;
u = u * x + 0.032596264f;
u = u * x + -0.14088021f;
u = u * x + 0.36040401f;
u = u * x + -0.47017866f;
u = u * x + 0.00050198776f;
u = u * x + 1.0077682f;
u = u * x + -0.0004765437f;
return u;
}
#endif
#ifndef NK_ATAN2
#define NK_ATAN2 nk_atan2
NK_LIB float
nk_atan2(float y, float x)
{
float ax = NK_ABS(x),
ay = NK_ABS(y);
/* 0 = +y +x 1 = -y +x
2 = +y -x 3 = -y -x */
nk_uint signs = (y < 0) | ((x < 0) << 1);
float a;
if(y == 0.0 && x == 0.0) return 0.0f;
a = (ay > ax)
? NK_PI_HALF - NK_ATAN(ax / ay)
: NK_ATAN(ay / ax);
switch(signs){
case 0: return a;
case 1: return -a;
case 2: return -a + NK_PI;
case 3: return a - NK_PI;
}
return 0.0f; /* prevents warning */
}
#endif
NK_LIB nk_uint
nk_round_up_pow2(nk_uint v)
{
@ -151,6 +197,11 @@ nk_log10(double n)
if (neg) exp = -exp;
return exp;
}
NK_LIB float
nk_roundf(float x)
{
return (x >= 0.0) ? nk_ifloorf(x + 0.5) : nk_iceilf(x - 0.5);
}
NK_API struct nk_rect
nk_get_null_rect(void)
{

View File

@ -230,7 +230,7 @@ nk_popup_end(struct nk_context *ctx)
nk_push_scissor(&win->buffer, win->layout->clip);
}
NK_API void
nk_popup_get_scroll(struct nk_context *ctx, nk_uint *offset_x, nk_uint *offset_y)
nk_popup_get_scroll(const struct nk_context *ctx, nk_uint *offset_x, nk_uint *offset_y)
{
struct nk_window *popup;

View File

@ -419,14 +419,14 @@ nk_str_get_const(const struct nk_str *s)
return (const char*)s->buffer.memory.ptr;
}
NK_API int
nk_str_len(struct nk_str *s)
nk_str_len(const struct nk_str *s)
{
NK_ASSERT(s);
if (!s || !s->len || !s->buffer.allocated) return 0;
return s->len;
}
NK_API int
nk_str_len_char(struct nk_str *s)
nk_str_len_char(const struct nk_str *s)
{
NK_ASSERT(s);
if (!s || !s->len || !s->buffer.allocated) return 0;
@ -446,4 +446,3 @@ nk_str_free(struct nk_str *str)
nk_buffer_free(&str->buffer);
str->len = 0;
}

View File

@ -35,7 +35,11 @@ NK_API void nk_style_default(struct nk_context *ctx){nk_style_from_table(ctx, 0)
NK_COLOR(NK_COLOR_SCROLLBAR_CURSOR, 100,100,100,255) \
NK_COLOR(NK_COLOR_SCROLLBAR_CURSOR_HOVER, 120,120,120,255) \
NK_COLOR(NK_COLOR_SCROLLBAR_CURSOR_ACTIVE, 150,150,150,255) \
NK_COLOR(NK_COLOR_TAB_HEADER, 40, 40, 40,255)
NK_COLOR(NK_COLOR_TAB_HEADER, 40, 40, 40,255) \
NK_COLOR(NK_COLOR_KNOB, 38, 38, 38, 255) \
NK_COLOR(NK_COLOR_KNOB_CURSOR, 100,100,100,255) \
NK_COLOR(NK_COLOR_KNOB_CURSOR_HOVER, 120,120,120,255) \
NK_COLOR(NK_COLOR_KNOB_CURSOR_ACTIVE, 150,150,150,255)
NK_GLOBAL const struct nk_color
nk_default_color_style[NK_COLOR_COUNT] = {
@ -95,6 +99,7 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table)
struct nk_style_toggle *toggle;
struct nk_style_selectable *select;
struct nk_style_slider *slider;
struct nk_style_knob *knob;
struct nk_style_progress *prog;
struct nk_style_scrollbar *scroll;
struct nk_style_edit *edit;
@ -303,6 +308,32 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table)
button->draw_end = 0;
style->slider.dec_button = style->slider.inc_button;
/* knob */
knob = &style->knob;
nk_zero_struct(*knob);
knob->normal = nk_style_item_hide();
knob->hover = nk_style_item_hide();
knob->active = nk_style_item_hide();
knob->knob_normal = table[NK_COLOR_KNOB];
knob->knob_hover = table[NK_COLOR_KNOB];
knob->knob_active = table[NK_COLOR_KNOB];
knob->cursor_normal = table[NK_COLOR_KNOB_CURSOR];
knob->cursor_hover = table[NK_COLOR_KNOB_CURSOR_HOVER];
knob->cursor_active = table[NK_COLOR_KNOB_CURSOR_ACTIVE];
knob->knob_border_color = table[NK_COLOR_BORDER];
knob->knob_border = 1.0f;
knob->padding = nk_vec2(2,2);
knob->spacing = nk_vec2(2,2);
knob->cursor_width = 2;
knob->color_factor = 1.0f;
knob->disabled_factor = NK_WIDGET_DISABLED_FACTOR;
knob->userdata = nk_handle_ptr(0);
knob->draw_begin = 0;
knob->draw_end = 0;
/* progressbar */
prog = &style->progress;
nk_zero_struct(*prog);
@ -819,7 +850,7 @@ nk_style_load_cursor(struct nk_context *ctx, enum nk_style_cursor cursor,
style->cursors[cursor] = c;
}
NK_API void
nk_style_load_all_cursors(struct nk_context *ctx, struct nk_cursor *cursors)
nk_style_load_all_cursors(struct nk_context *ctx, const struct nk_cursor *cursors)
{
int i = 0;
struct nk_style *style;
@ -830,4 +861,3 @@ nk_style_load_all_cursors(struct nk_context *ctx, struct nk_cursor *cursors)
style->cursors[i] = &cursors[i];
style->cursor_visible = nk_true;
}

View File

@ -71,7 +71,7 @@ nk_add_value(struct nk_context *ctx, struct nk_window *win,
return &win->tables->values[win->tables->size++];
}
NK_LIB nk_uint*
nk_find_value(struct nk_window *win, nk_hash name)
nk_find_value(const struct nk_window *win, nk_hash name)
{
struct nk_table *iter = win->tables;
while (iter) {
@ -87,4 +87,3 @@ nk_find_value(struct nk_window *win, nk_hash name)
}
return 0;
}

View File

@ -141,7 +141,7 @@ nk_strlen(const char *str)
return siz;
}
NK_API int
nk_strtoi(const char *str, const char **endptr)
nk_strtoi(const char *str, char **endptr)
{
int neg = 1;
const char *p = str;
@ -161,15 +161,15 @@ nk_strtoi(const char *str, const char **endptr)
p++;
}
if (endptr)
*endptr = p;
*endptr = (char *)p;
return neg*value;
}
NK_API double
nk_strtod(const char *str, const char **endptr)
nk_strtod(const char *str, char **endptr)
{
double m;
double neg = 1.0;
const char *p = str;
char *p = (char *)str;
double value = 0;
double number = 0;
@ -222,7 +222,7 @@ nk_strtod(const char *str, const char **endptr)
return number;
}
NK_API float
nk_strtof(const char *str, const char **endptr)
nk_strtof(const char *str, char **endptr)
{
float float_value;
double double_value;

View File

@ -7,7 +7,7 @@
*
* ===============================================================*/
NK_API struct nk_rect
nk_widget_bounds(struct nk_context *ctx)
nk_widget_bounds(const struct nk_context *ctx)
{
struct nk_rect bounds;
NK_ASSERT(ctx);
@ -18,7 +18,7 @@ nk_widget_bounds(struct nk_context *ctx)
return bounds;
}
NK_API struct nk_vec2
nk_widget_position(struct nk_context *ctx)
nk_widget_position(const struct nk_context *ctx)
{
struct nk_rect bounds;
NK_ASSERT(ctx);
@ -30,7 +30,7 @@ nk_widget_position(struct nk_context *ctx)
return nk_vec2(bounds.x, bounds.y);
}
NK_API struct nk_vec2
nk_widget_size(struct nk_context *ctx)
nk_widget_size(const struct nk_context *ctx)
{
struct nk_rect bounds;
NK_ASSERT(ctx);
@ -42,7 +42,7 @@ nk_widget_size(struct nk_context *ctx)
return nk_vec2(bounds.w, bounds.h);
}
NK_API float
nk_widget_width(struct nk_context *ctx)
nk_widget_width(const struct nk_context *ctx)
{
struct nk_rect bounds;
NK_ASSERT(ctx);
@ -54,7 +54,7 @@ nk_widget_width(struct nk_context *ctx)
return bounds.w;
}
NK_API float
nk_widget_height(struct nk_context *ctx)
nk_widget_height(const struct nk_context *ctx)
{
struct nk_rect bounds;
NK_ASSERT(ctx);
@ -66,7 +66,7 @@ nk_widget_height(struct nk_context *ctx)
return bounds.h;
}
NK_API nk_bool
nk_widget_is_hovered(struct nk_context *ctx)
nk_widget_is_hovered(const struct nk_context *ctx)
{
struct nk_rect c, v;
struct nk_rect bounds;
@ -88,7 +88,7 @@ nk_widget_is_hovered(struct nk_context *ctx)
return nk_input_is_mouse_hovering_rect(&ctx->input, bounds);
}
NK_API nk_bool
nk_widget_is_mouse_clicked(struct nk_context *ctx, enum nk_buttons btn)
nk_widget_is_mouse_clicked(const struct nk_context *ctx, enum nk_buttons btn)
{
struct nk_rect c, v;
struct nk_rect bounds;
@ -110,7 +110,7 @@ nk_widget_is_mouse_clicked(struct nk_context *ctx, enum nk_buttons btn)
return nk_input_mouse_clicked(&ctx->input, btn, bounds);
}
NK_API nk_bool
nk_widget_has_mouse_click_down(struct nk_context *ctx, enum nk_buttons btn, nk_bool down)
nk_widget_has_mouse_click_down(const struct nk_context *ctx, enum nk_buttons btn, nk_bool down)
{
struct nk_rect c, v;
struct nk_rect bounds;
@ -182,7 +182,7 @@ nk_widget(struct nk_rect *bounds, const struct nk_context *ctx)
return NK_WIDGET_VALID;
}
NK_API enum nk_widget_layout_states
nk_widget_fitting(struct nk_rect *bounds, struct nk_context *ctx,
nk_widget_fitting(struct nk_rect *bounds, const struct nk_context *ctx,
struct nk_vec2 item_padding)
{
/* update the bounds to stand without padding */

View File

@ -43,7 +43,7 @@ nk_free_window(struct nk_context *ctx, struct nk_window *win)
nk_free_page_element(ctx, pe);}
}
NK_LIB struct nk_window*
nk_find_window(struct nk_context *ctx, nk_hash hash, const char *name)
nk_find_window(const struct nk_context *ctx, nk_hash hash, const char *name)
{
struct nk_window *iter;
iter = ctx->begin;
@ -352,7 +352,7 @@ nk_window_get_height(const struct nk_context *ctx)
return ctx->current->bounds.h;
}
NK_API struct nk_rect
nk_window_get_content_region(struct nk_context *ctx)
nk_window_get_content_region(const struct nk_context *ctx)
{
NK_ASSERT(ctx);
NK_ASSERT(ctx->current);
@ -360,7 +360,7 @@ nk_window_get_content_region(struct nk_context *ctx)
return ctx->current->layout->clip;
}
NK_API struct nk_vec2
nk_window_get_content_region_min(struct nk_context *ctx)
nk_window_get_content_region_min(const struct nk_context *ctx)
{
NK_ASSERT(ctx);
NK_ASSERT(ctx->current);
@ -369,7 +369,7 @@ nk_window_get_content_region_min(struct nk_context *ctx)
return nk_vec2(ctx->current->layout->clip.x, ctx->current->layout->clip.y);
}
NK_API struct nk_vec2
nk_window_get_content_region_max(struct nk_context *ctx)
nk_window_get_content_region_max(const struct nk_context *ctx)
{
NK_ASSERT(ctx);
NK_ASSERT(ctx->current);
@ -379,7 +379,7 @@ nk_window_get_content_region_max(struct nk_context *ctx)
ctx->current->layout->clip.y + ctx->current->layout->clip.h);
}
NK_API struct nk_vec2
nk_window_get_content_region_size(struct nk_context *ctx)
nk_window_get_content_region_size(const struct nk_context *ctx)
{
NK_ASSERT(ctx);
NK_ASSERT(ctx->current);
@ -388,7 +388,7 @@ nk_window_get_content_region_size(struct nk_context *ctx)
return nk_vec2(ctx->current->layout->clip.w, ctx->current->layout->clip.h);
}
NK_API struct nk_command_buffer*
nk_window_get_canvas(struct nk_context *ctx)
nk_window_get_canvas(const struct nk_context *ctx)
{
NK_ASSERT(ctx);
NK_ASSERT(ctx->current);
@ -397,7 +397,7 @@ nk_window_get_canvas(struct nk_context *ctx)
return &ctx->current->buffer;
}
NK_API struct nk_panel*
nk_window_get_panel(struct nk_context *ctx)
nk_window_get_panel(const struct nk_context *ctx)
{
NK_ASSERT(ctx);
NK_ASSERT(ctx->current);
@ -405,7 +405,7 @@ nk_window_get_panel(struct nk_context *ctx)
return ctx->current->layout;
}
NK_API void
nk_window_get_scroll(struct nk_context *ctx, nk_uint *offset_x, nk_uint *offset_y)
nk_window_get_scroll(const struct nk_context *ctx, nk_uint *offset_x, nk_uint *offset_y)
{
struct nk_window *win;
NK_ASSERT(ctx);
@ -428,7 +428,7 @@ nk_window_has_focus(const struct nk_context *ctx)
return ctx->current == ctx->active;
}
NK_API nk_bool
nk_window_is_hovered(struct nk_context *ctx)
nk_window_is_hovered(const struct nk_context *ctx)
{
NK_ASSERT(ctx);
NK_ASSERT(ctx->current);
@ -443,7 +443,7 @@ nk_window_is_hovered(struct nk_context *ctx)
}
}
NK_API nk_bool
nk_window_is_any_hovered(struct nk_context *ctx)
nk_window_is_any_hovered(const struct nk_context *ctx)
{
struct nk_window *iter;
NK_ASSERT(ctx);
@ -470,14 +470,14 @@ nk_window_is_any_hovered(struct nk_context *ctx)
return 0;
}
NK_API nk_bool
nk_item_is_any_active(struct nk_context *ctx)
nk_item_is_any_active(const struct nk_context *ctx)
{
int any_hovered = nk_window_is_any_hovered(ctx);
int any_active = (ctx->last_widget_state & NK_WIDGET_STATE_MODIFIED);
return any_hovered || any_active;
}
NK_API nk_bool
nk_window_is_collapsed(struct nk_context *ctx, const char *name)
nk_window_is_collapsed(const struct nk_context *ctx, const char *name)
{
int title_len;
nk_hash title_hash;
@ -492,7 +492,7 @@ nk_window_is_collapsed(struct nk_context *ctx, const char *name)
return win->flags & NK_WINDOW_MINIMIZED;
}
NK_API nk_bool
nk_window_is_closed(struct nk_context *ctx, const char *name)
nk_window_is_closed(const struct nk_context *ctx, const char *name)
{
int title_len;
nk_hash title_hash;
@ -507,7 +507,7 @@ nk_window_is_closed(struct nk_context *ctx, const char *name)
return (win->flags & NK_WINDOW_CLOSED);
}
NK_API nk_bool
nk_window_is_hidden(struct nk_context *ctx, const char *name)
nk_window_is_hidden(const struct nk_context *ctx, const char *name)
{
int title_len;
nk_hash title_hash;
@ -522,7 +522,7 @@ nk_window_is_hidden(struct nk_context *ctx, const char *name)
return (win->flags & NK_WINDOW_HIDDEN);
}
NK_API nk_bool
nk_window_is_active(struct nk_context *ctx, const char *name)
nk_window_is_active(const struct nk_context *ctx, const char *name)
{
int title_len;
nk_hash title_hash;
@ -537,7 +537,7 @@ nk_window_is_active(struct nk_context *ctx, const char *name)
return win == ctx->active;
}
NK_API struct nk_window*
nk_window_find(struct nk_context *ctx, const char *name)
nk_window_find(const struct nk_context *ctx, const char *name)
{
int title_len;
nk_hash title_hash;
@ -567,7 +567,6 @@ nk_window_set_bounds(struct nk_context *ctx,
if (!ctx) return;
win = nk_window_find(ctx, name);
if (!win) return;
NK_ASSERT(ctx->current != win && "You cannot update a currently in procecss window");
win->bounds = bounds;
}
NK_API void

View File

@ -1 +1 @@
build.py --macro NK --intro HEADER --pub nuklear.h --priv1 nuklear_internal.h,nuklear_math.c,nuklear_util.c,nuklear_color.c,nuklear_utf8.c,nuklear_buffer.c,nuklear_string.c,nuklear_draw.c,nuklear_vertex.c --extern stb_rect_pack.h,stb_truetype.h --priv2 nuklear_font.c,nuklear_input.c,nuklear_style.c,nuklear_context.c,nuklear_pool.c,nuklear_page_element.c,nuklear_table.c,nuklear_panel.c,nuklear_window.c,nuklear_popup.c,nuklear_contextual.c,nuklear_menu.c,nuklear_layout.c,nuklear_tree.c,nuklear_group.c,nuklear_list_view.c,nuklear_widget.c,nuklear_text.c,nuklear_image.c,nuklear_9slice.c,nuklear_button.c,nuklear_toggle.c,nuklear_selectable.c,nuklear_slider.c,nuklear_progress.c,nuklear_scrollbar.c,nuklear_text_editor.c,nuklear_edit.c,nuklear_property.c,nuklear_chart.c,nuklear_color_picker.c,nuklear_combo.c,nuklear_tooltip.c --outro LICENSE,CHANGELOG,CREDITS > ..\nuklear.h
build.py --macro NK --intro HEADER.md --pub nuklear.h --priv1 nuklear_internal.h,nuklear_math.c,nuklear_util.c,nuklear_color.c,nuklear_utf8.c,nuklear_buffer.c,nuklear_string.c,nuklear_draw.c,nuklear_vertex.c --extern stb_rect_pack.h,stb_truetype.h --priv2 nuklear_font.c,nuklear_input.c,nuklear_style.c,nuklear_context.c,nuklear_pool.c,nuklear_page_element.c,nuklear_table.c,nuklear_panel.c,nuklear_window.c,nuklear_popup.c,nuklear_contextual.c,nuklear_menu.c,nuklear_layout.c,nuklear_tree.c,nuklear_group.c,nuklear_list_view.c,nuklear_widget.c,nuklear_text.c,nuklear_image.c,nuklear_9slice.c,nuklear_button.c,nuklear_toggle.c,nuklear_selectable.c,nuklear_slider.c,nuklear_knob.c,nuklear_progress.c,nuklear_scrollbar.c,nuklear_text_editor.c,nuklear_edit.c,nuklear_property.c,nuklear_chart.c,nuklear_color_picker.c,nuklear_combo.c,nuklear_tooltip.c --outro LICENSE,CHANGELOG,CREDITS > ..\nuklear.h

View File

@ -1,3 +1,2 @@
#!/bin/sh
python build.py --macro NK --intro HEADER --pub nuklear.h --priv1 nuklear_internal.h,nuklear_math.c,nuklear_util.c,nuklear_color.c,nuklear_utf8.c,nuklear_buffer.c,nuklear_string.c,nuklear_draw.c,nuklear_vertex.c --extern stb_rect_pack.h,stb_truetype.h --priv2 nuklear_font.c,nuklear_input.c,nuklear_style.c,nuklear_context.c,nuklear_pool.c,nuklear_page_element.c,nuklear_table.c,nuklear_panel.c,nuklear_window.c,nuklear_popup.c,nuklear_contextual.c,nuklear_menu.c,nuklear_layout.c,nuklear_tree.c,nuklear_group.c,nuklear_list_view.c,nuklear_widget.c,nuklear_text.c,nuklear_image.c,nuklear_9slice.c,nuklear_button.c,nuklear_toggle.c,nuklear_selectable.c,nuklear_slider.c,nuklear_progress.c,nuklear_scrollbar.c,nuklear_text_editor.c,nuklear_edit.c,nuklear_property.c,nuklear_chart.c,nuklear_color_picker.c,nuklear_combo.c,nuklear_tooltip.c --outro LICENSE,CHANGELOG,CREDITS > ../nuklear.h
python3 build.py --macro NK --intro HEADER.md --pub nuklear.h --priv1 nuklear_internal.h,nuklear_math.c,nuklear_util.c,nuklear_color.c,nuklear_utf8.c,nuklear_buffer.c,nuklear_string.c,nuklear_draw.c,nuklear_vertex.c --extern stb_rect_pack.h,stb_truetype.h --priv2 nuklear_font.c,nuklear_input.c,nuklear_style.c,nuklear_context.c,nuklear_pool.c,nuklear_page_element.c,nuklear_table.c,nuklear_panel.c,nuklear_window.c,nuklear_popup.c,nuklear_contextual.c,nuklear_menu.c,nuklear_layout.c,nuklear_tree.c,nuklear_group.c,nuklear_list_view.c,nuklear_widget.c,nuklear_text.c,nuklear_image.c,nuklear_9slice.c,nuklear_button.c,nuklear_toggle.c,nuklear_selectable.c,nuklear_slider.c,nuklear_knob.c,nuklear_progress.c,nuklear_scrollbar.c,nuklear_text_editor.c,nuklear_edit.c,nuklear_property.c,nuklear_chart.c,nuklear_color_picker.c,nuklear_combo.c,nuklear_tooltip.c --outro LICENSE,CHANGELOG,CREDITS > ../nuklear.h