Improved REPL

This commit is contained in:
John Alanbrook 2022-12-19 15:12:34 +00:00
parent d13d4ece9a
commit 0f90215b7a
8 changed files with 152 additions and 45 deletions

View file

@ -569,15 +569,21 @@ void editor_project_gui() {
NK_MENU_START(repl) NK_MENU_START(repl)
/*
nk_layout_row_dynamic(ctx, 300, 1); nk_layout_row_dynamic(ctx, 300, 1);
nk_flags active; static char bigbuf[10000] = {\0'};
nuke_label(bigbuf);
*/
static char buffer[512] = {'\0'}; static char buffer[512] = {'\0'};
nk_layout_row_dynamic(ctx, 25, 2);
active = nk_edit_string_zero_terminated(ctx, NK_EDIT_BOX | NK_EDIT_SIG_ENTER, buffer, 512 - 1, nk_filter_ascii); nk_flags active = nk_edit_string_zero_terminated(ctx, NK_EDIT_BOX | NK_EDIT_SIG_ENTER, buffer, 512-1, nk_filter_ascii);
if (active && NK_EDIT_COMMITED) { if (active & NK_EDIT_COMMITED || nuke_btn("Submit")) {
script_run(buffer); char bigbuf[1024];
snprintf(bigbuf, 1024, "(loginfo %s)", buffer);
script_run(bigbuf);
buffer[0] = '\0'; buffer[0] = '\0';
} }

View file

@ -186,6 +186,15 @@ s7_pointer s7_gui_hook(s7_scheme *sc, s7_pointer args) {
return cb; return cb;
} }
s7_pointer s7_register(s7_scheme *sc, s7_pointer args) {
int hook = s7_integer(s7_car(args));
s7_pointer expr = s7_cadr(args);
register_update(s7_cadr(args));
return expr;
}
/* /*
mrb_value mrb_nuke_cb(mrb_state *mrb, mrb_value self) { mrb_value mrb_nuke_cb(mrb_state *mrb, mrb_value self) {
mrb_float win; mrb_float win;
@ -222,5 +231,6 @@ void ffi_load() {
S7_FUNC(sys_cmd, 1); S7_FUNC(sys_cmd, 1);
S7_FUNC(sound_cmd, 2); S7_FUNC(sound_cmd, 2);
S7_FUNC(gui_hook, 1); S7_FUNC(gui_hook, 1);
S7_FUNC(register, 2);
} }

View file

@ -126,7 +126,7 @@ void openglRender(struct window *window)
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
////// TEXT && GUI ////// TEXT && GUI
// script_call_sym(window->gui_cb); //script_call_sym(window->gui_cb);
///// Sprites ///// Sprites
glDepthFunc(GL_LESS); glDepthFunc(GL_LESS);

View file

@ -5,8 +5,12 @@
#include "mrbffi.h" #include "mrbffi.h"
#include "stb_ds.h"
s7_scheme *s7 = NULL; s7_scheme *s7 = NULL;
s7_pointer *updates;
static void my_print(s7_scheme *sc, uint8_t c, s7_pointer port) { static void my_print(s7_scheme *sc, uint8_t c, s7_pointer port) {
static char buffer[1024]; static char buffer[1024];
static char *p = buffer; static char *p = buffer;
@ -28,6 +32,13 @@ void script_init() {
void script_run(const char *script) { void script_run(const char *script) {
s7_eval_c_string(s7, script); s7_eval_c_string(s7, script);
const char *errmsg = s7_get_output_string(s7, s7_current_error_port(s7));
if (errmsg && (*errmsg))
mYughLog(1, 2, 0, "script", "Scripting error: %s", errmsg);
s7_flush_output_port(s7, s7_current_error_port(s7));
} }
int script_dofile(const char *file) { int script_dofile(const char *file) {
@ -73,3 +84,12 @@ void script_call_sym(s7_pointer sym)
int script_has_sym(s7_pointer sym) { int script_has_sym(s7_pointer sym) {
return 1; return 1;
} }
void register_update(s7_pointer sym) {
arrput(updates, sym);
}
void call_updates() {
for (int i = 0; i < arrlen(updates); i++)
script_call_sym(updates[i]);
}

View file

@ -13,4 +13,7 @@ void script_call(const char *f);
void script_call_sym(s7_pointer sym); void script_call_sym(s7_pointer sym);
int script_has_sym(s7_pointer sym); int script_has_sym(s7_pointer sym);
void register_update(s7_pointer sym);
void call_updates();
#endif #endif

View file

@ -1,6 +1,5 @@
<meta charset='utf-8' emacsmode='-*- markdown -*-'> <meta charset='utf-8' emacsmode='-*- markdown -*-'>
<link rel='stylesheet' href='https://casual-effects.com/markdeep/latest/apidoc.css?'> <link rel='stylesheet' href='https://casual-effects.com/markdeep/latest/apidoc.css?'>
<title>Nuklear</title> <!--Page Title-->
# Nuklear # Nuklear
![](https://cloud.githubusercontent.com/assets/8057201/11761525/ae06f0ca-a0c6-11e5-819d-5610b25f6ef4.gif) ![](https://cloud.githubusercontent.com/assets/8057201/11761525/ae06f0ca-a0c6-11e5-819d-5610b25f6ef4.gif)
## Contents ## Contents
@ -90,7 +89,8 @@ NK_PRIVATE | If defined declares all functions as static, s
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_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_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_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 <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_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_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_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
@ -109,6 +109,7 @@ NK_KEYSTATE_BASED_INPUT | Define this if your backend uses key state for
- NK_INCLUDE_FIXED_TYPES - NK_INCLUDE_FIXED_TYPES
- NK_INCLUDE_DEFAULT_ALLOCATOR - NK_INCLUDE_DEFAULT_ALLOCATOR
- NK_INCLUDE_STANDARD_VARARGS - NK_INCLUDE_STANDARD_VARARGS
- NK_INCLUDE_STANDARD_BOOL
- NK_INCLUDE_VERTEX_BUFFER_OUTPUT - NK_INCLUDE_VERTEX_BUFFER_OUTPUT
- NK_INCLUDE_FONT_BAKING - NK_INCLUDE_FONT_BAKING
- NK_INCLUDE_DEFAULT_FONT - NK_INCLUDE_DEFAULT_FONT
@ -132,7 +133,7 @@ Function | Description
NK_ASSERT | If you don't define this, nuklear will use <assert.h> with assert(). 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_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_MEMCPY | You can define this to 'memcpy' or your own memcpy implementation replacement. If not nuklear will use its own version.
NK_SQRT | You can define this to 'sqrt' or your own sqrt implementation replacement. If not nuklear will use its own slow and not highly accurate 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_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_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_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!).
@ -221,7 +222,7 @@ __nk_set_user_data__| Utility function to pass user data to draw command
Initializes a `nk_context` struct with a default standard library allocator. Initializes a `nk_context` struct with a default standard library allocator.
Should be used if you don't want to be bothered with memory management in nuklear. Should be used if you don't want to be bothered with memory management in nuklear.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
int nk_init_default(struct nk_context *ctx, const struct nk_user_font *font); nk_bool nk_init_default(struct nk_context *ctx, const struct nk_user_font *font);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Parameter | Description Parameter | Description
------------|--------------------------------------------------------------- ------------|---------------------------------------------------------------
@ -235,7 +236,7 @@ Especially recommended for system with little memory or systems with virtual mem
For the later case you can just allocate for example 16MB of virtual memory For the later case you can just allocate for example 16MB of virtual memory
and only the required amount of memory will actually be committed. and only the required amount of memory will actually be committed.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
int nk_init_fixed(struct nk_context *ctx, void *memory, nk_size size, const struct nk_user_font *font); nk_bool nk_init_fixed(struct nk_context *ctx, void *memory, nk_size size, const struct nk_user_font *font);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! Warning !!! Warning
make sure the passed memory block is aligned correctly for `nk_draw_commands`. make sure the passed memory block is aligned correctly for `nk_draw_commands`.
@ -251,7 +252,7 @@ Initializes a `nk_context` struct with memory allocation callbacks for nuklear t
memory from. Used internally for `nk_init_default` and provides a kitchen sink allocation memory from. Used internally for `nk_init_default` and provides a kitchen sink allocation
interface to nuklear. Can be useful for cases like monitoring memory consumption. interface to nuklear. Can be useful for cases like monitoring memory consumption.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
int nk_init(struct nk_context *ctx, struct nk_allocator *alloc, const struct nk_user_font *font); nk_bool nk_init(struct nk_context *ctx, struct nk_allocator *alloc, const struct nk_user_font *font);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Parameter | Description Parameter | Description
------------|--------------------------------------------------------------- ------------|---------------------------------------------------------------
@ -264,7 +265,7 @@ Initializes a `nk_context` struct from two different either fixed or growing
buffers. The first buffer is for allocating draw commands while the second buffer is buffers. The first buffer is for allocating draw commands while the second buffer is
used for allocating windows, panels and state tables. used for allocating windows, panels and state tables.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
int nk_init_custom(struct nk_context *ctx, struct nk_buffer *cmds, struct nk_buffer *pool, const struct nk_user_font *font); nk_bool nk_init_custom(struct nk_context *ctx, struct nk_buffer *cmds, struct nk_buffer *pool, const struct nk_user_font *font);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Parameter | Description Parameter | Description
------------|--------------------------------------------------------------- ------------|---------------------------------------------------------------
@ -379,7 +380,7 @@ __y__ | Must hold an integer describing the current mouse cursor y-positio
#### nk_input_key #### nk_input_key
Mirrors the state of a specific key to nuklear Mirrors the state of a specific key to nuklear
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
void nk_input_key(struct nk_context*, enum nk_keys key, int down); void nk_input_key(struct nk_context*, enum nk_keys key, nk_bool down);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Parameter | Description Parameter | Description
------------|----------------------------------------------------------- ------------|-----------------------------------------------------------
@ -389,7 +390,7 @@ __down__ | Must be 0 for key is up and 1 for key is down
#### nk_input_button #### nk_input_button
Mirrors the state of a specific mouse button to nuklear Mirrors the state of a specific mouse button to nuklear
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
void nk_input_button(struct nk_context *ctx, enum nk_buttons btn, int x, int y, int down); void nk_input_button(struct nk_context *ctx, enum nk_buttons btn, int x, int y, nk_bool down);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Parameter | Description Parameter | Description
------------|----------------------------------------------------------- ------------|-----------------------------------------------------------
@ -891,7 +892,7 @@ __NK_MAXIMIZED__| UI section is extended and visible until minimized
Starts a new window; needs to be called every frame for every Starts a new window; needs to be called every frame for every
window (unless hidden) or otherwise the window gets removed window (unless hidden) or otherwise the window gets removed
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
int nk_begin(struct nk_context *ctx, const char *title, struct nk_rect bounds, nk_flags flags); nk_bool nk_begin(struct nk_context *ctx, const char *title, struct nk_rect bounds, nk_flags flags);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Parameter | Description Parameter | Description
------------|----------------------------------------------------------- ------------|-----------------------------------------------------------
@ -905,7 +906,7 @@ until `nk_end` or `false(0)` otherwise for example if minimized
Extended window start with separated title and identifier to allow multiple Extended window start with separated title and identifier to allow multiple
windows with same title but not name windows with same title but not name
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
int nk_begin_titled(struct nk_context *ctx, const char *name, const char *title, struct nk_rect bounds, nk_flags flags); nk_bool nk_begin_titled(struct nk_context *ctx, const char *name, const char *title, struct nk_rect bounds, nk_flags flags);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Parameter | Description Parameter | Description
------------|----------------------------------------------------------- ------------|-----------------------------------------------------------
@ -1086,7 +1087,7 @@ Returns if the currently processed window is currently active
!!! WARNING !!! WARNING
Only call this function between calls `nk_begin_xxx` and `nk_end` Only call this function between calls `nk_begin_xxx` and `nk_end`
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
int nk_window_has_focus(const struct nk_context *ctx); nk_bool nk_window_has_focus(const struct nk_context *ctx);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Parameter | Description Parameter | Description
------------|----------------------------------------------------------- ------------|-----------------------------------------------------------
@ -1097,7 +1098,7 @@ Return if the current window is being hovered
!!! WARNING !!! WARNING
Only call this function between calls `nk_begin_xxx` and `nk_end` Only call this function between calls `nk_begin_xxx` and `nk_end`
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
int nk_window_is_hovered(struct nk_context *ctx); nk_bool nk_window_is_hovered(struct nk_context *ctx);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Parameter | Description Parameter | Description
------------|----------------------------------------------------------- ------------|-----------------------------------------------------------
@ -1106,7 +1107,7 @@ Returns `true(1)` if current window is hovered or `false(0)` otherwise
#### nk_window_is_collapsed #### nk_window_is_collapsed
Returns if the window with given name is currently minimized/collapsed Returns if the window with given name is currently minimized/collapsed
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
int nk_window_is_collapsed(struct nk_context *ctx, const char *name); nk_bool nk_window_is_collapsed(struct nk_context *ctx, const char *name);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Parameter | Description Parameter | Description
------------|----------------------------------------------------------- ------------|-----------------------------------------------------------
@ -1117,7 +1118,7 @@ found or is not minimized
#### nk_window_is_closed #### nk_window_is_closed
Returns if the window with given name was closed by calling `nk_close` Returns if the window with given name was closed by calling `nk_close`
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
int nk_window_is_closed(struct nk_context *ctx, const char *name); nk_bool nk_window_is_closed(struct nk_context *ctx, const char *name);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Parameter | Description Parameter | Description
------------|----------------------------------------------------------- ------------|-----------------------------------------------------------
@ -1127,7 +1128,7 @@ Returns `true(1)` if current window was closed or `false(0)` window not found or
#### nk_window_is_hidden #### nk_window_is_hidden
Returns if the window with given name is hidden Returns if the window with given name is hidden
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
int nk_window_is_hidden(struct nk_context *ctx, const char *name); nk_bool nk_window_is_hidden(struct nk_context *ctx, const char *name);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Parameter | Description Parameter | Description
------------|----------------------------------------------------------- ------------|-----------------------------------------------------------
@ -1137,7 +1138,7 @@ Returns `true(1)` if current window is hidden or `false(0)` window not found or
#### nk_window_is_active #### nk_window_is_active
Same as nk_window_has_focus for some reason Same as nk_window_has_focus for some reason
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
int nk_window_is_active(struct nk_context *ctx, const char *name); nk_bool nk_window_is_active(struct nk_context *ctx, const char *name);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Parameter | Description Parameter | Description
------------|----------------------------------------------------------- ------------|-----------------------------------------------------------
@ -1147,7 +1148,7 @@ Returns `true(1)` if current window is active or `false(0)` window not found or
#### nk_window_is_any_hovered #### nk_window_is_any_hovered
Returns if the any window is being hovered Returns if the any window is being hovered
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
int nk_window_is_any_hovered(struct nk_context*); nk_bool nk_window_is_any_hovered(struct nk_context*);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Parameter | Description Parameter | Description
------------|----------------------------------------------------------- ------------|-----------------------------------------------------------
@ -1158,7 +1159,7 @@ Returns if the any window is being hovered or any widget is currently active.
Can be used to decide if input should be processed by UI or your specific input handling. Can be used to decide if input should be processed by UI or your specific input handling.
Example could be UI and 3D camera to move inside a 3D space. Example could be UI and 3D camera to move inside a 3D space.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
int nk_item_is_any_active(struct nk_context*); nk_bool nk_item_is_any_active(struct nk_context*);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Parameter | Description Parameter | Description
------------|----------------------------------------------------------- ------------|-----------------------------------------------------------
@ -1731,6 +1732,14 @@ Parameter | Description
__ctx__ | Must point to an previously initialized `nk_context` struct after call `nk_layout_space_begin` __ctx__ | Must point to an previously initialized `nk_context` struct after call `nk_layout_space_begin`
__bounds__ | Rectangle to convert from layout space into screen space __bounds__ | Rectangle to convert from layout space into screen space
Returns transformed `nk_rect` in layout space coordinates Returns transformed `nk_rect` in layout space coordinates
#### nk_spacer
Spacer is a dummy widget that consumes space as usual but doesn't draw anything
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
void nk_spacer(struct nk_context* );
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Parameter | Description
------------|-----------------------------------------------------------
__ctx__ | Must point to an previously initialized `nk_context` struct after call `nk_layout_space_begin`
### Groups ### Groups
Groups are basically windows inside windows. They allow to subdivide space Groups are basically windows inside windows. They allow to subdivide space
in a window to layout widgets as a group. Almost all more complex widget in a window to layout widgets as a group. Almost all more complex widget
@ -1812,7 +1821,7 @@ nk_group_set_scroll | Sets the scroll offset for the given group
#### nk_group_begin #### nk_group_begin
Starts a new widget group. Requires a previous layouting function to specify a pos/size. Starts a new widget group. Requires a previous layouting function to specify a pos/size.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
int nk_group_begin(struct nk_context*, const char *title, nk_flags); nk_bool nk_group_begin(struct nk_context*, const char *title, nk_flags);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Parameter | Description Parameter | Description
------------|----------------------------------------------------------- ------------|-----------------------------------------------------------
@ -1823,7 +1832,7 @@ Returns `true(1)` if visible and fillable with widgets or `false(0)` otherwise
#### nk_group_begin_titled #### nk_group_begin_titled
Starts a new widget group. Requires a previous layouting function to specify a pos/size. Starts a new widget group. Requires a previous layouting function to specify a pos/size.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
int nk_group_begin_titled(struct nk_context*, const char *name, const char *title, nk_flags); nk_bool nk_group_begin_titled(struct nk_context*, const char *name, const char *title, nk_flags);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Parameter | Description Parameter | Description
------------|----------------------------------------------------------- ------------|-----------------------------------------------------------
@ -1844,7 +1853,7 @@ __ctx__ | Must point to an previously initialized `nk_context` struct
starts a new widget group. requires a previous layouting function to specify starts a new widget group. requires a previous layouting function to specify
a size. Does not keep track of scrollbar. a size. Does not keep track of scrollbar.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
int nk_group_scrolled_offset_begin(struct nk_context*, nk_uint *x_offset, nk_uint *y_offset, const char *title, nk_flags flags); nk_bool nk_group_scrolled_offset_begin(struct nk_context*, nk_uint *x_offset, nk_uint *y_offset, const char *title, nk_flags flags);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Parameter | Description Parameter | Description
------------|----------------------------------------------------------- ------------|-----------------------------------------------------------
@ -1858,7 +1867,7 @@ Returns `true(1)` if visible and fillable with widgets or `false(0)` otherwise
Starts a new widget group. requires a previous Starts a new widget group. requires a previous
layouting function to specify a size. Does not keep track of scrollbar. layouting function to specify a size. Does not keep track of scrollbar.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
int nk_group_scrolled_begin(struct nk_context*, struct nk_scroll *off, const char *title, nk_flags); nk_bool nk_group_scrolled_begin(struct nk_context*, struct nk_scroll *off, const char *title, nk_flags);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Parameter | Description Parameter | Description
------------|----------------------------------------------------------- ------------|-----------------------------------------------------------
@ -1986,7 +1995,7 @@ Returns `true(1)` if visible and fillable with widgets or `false(0)` otherwise
Start a collapsible UI section with internal state management with full Start a collapsible UI section with internal state management with full
control over internal unique ID used to store state control over internal unique ID used to store state
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
int nk_tree_push_hashed(struct nk_context*, enum nk_tree_type, const char *title, enum nk_collapse_states initial_state, const char *hash, int len,int seed); nk_bool nk_tree_push_hashed(struct nk_context*, enum nk_tree_type, const char *title, enum nk_collapse_states initial_state, const char *hash, int len,int seed);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Parameter | Description Parameter | Description
------------|----------------------------------------------------------- ------------|-----------------------------------------------------------
@ -2035,7 +2044,7 @@ Returns `true(1)` if visible and fillable with widgets or `false(0)` otherwise
Start a collapsible UI section with internal state management with full Start a collapsible UI section with internal state management with full
control over internal unique ID used to store state control over internal unique ID used to store state
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
int nk_tree_image_push_hashed(struct nk_context*, enum nk_tree_type, struct nk_image, const char *title, enum nk_collapse_states initial_state, const char *hash, int len,int seed); nk_bool nk_tree_image_push_hashed(struct nk_context*, enum nk_tree_type, struct nk_image, const char *title, enum nk_collapse_states initial_state, const char *hash, int len,int seed);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Parameter | Description Parameter | Description
------------|----------------------------------------------------------- ------------|-----------------------------------------------------------
@ -2059,7 +2068,7 @@ __ctx__ | Must point to an previously initialized `nk_context` struct after
#### nk_tree_state_push #### nk_tree_state_push
Start a collapsible UI section with external state management Start a collapsible UI section with external state management
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
int nk_tree_state_push(struct nk_context*, enum nk_tree_type, const char *title, enum nk_collapse_states *state); nk_bool nk_tree_state_push(struct nk_context*, enum nk_tree_type, const char *title, enum nk_collapse_states *state);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Parameter | Description Parameter | Description
------------|----------------------------------------------------------- ------------|-----------------------------------------------------------
@ -2071,7 +2080,7 @@ Returns `true(1)` if visible and fillable with widgets or `false(0)` otherwise
#### nk_tree_state_image_push #### nk_tree_state_image_push
Start a collapsible UI section with image and label header and external state management Start a collapsible UI section with image and label header and external state management
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
int nk_tree_state_image_push(struct nk_context*, enum nk_tree_type, struct nk_image, const char *title, enum nk_collapse_states *state); nk_bool nk_tree_state_image_push(struct nk_context*, enum nk_tree_type, struct nk_image, const char *title, enum nk_collapse_states *state);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Parameter | Description Parameter | Description
------------|----------------------------------------------------------- ------------|-----------------------------------------------------------
@ -2306,13 +2315,49 @@ X...XXXXXXXXXXXXX...X - "
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
## Changelog ## Changelog
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~none ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~none
[date][x.yy.zz]-[description] [date] ([x.y.z]) - [description]
-[date]: date on which the change has been pushed - [date]: date on which the change has been pushed
-[x.yy.zz]: Numerical version string representation. Each version number on the right - [x.y.z]: Version string, represented in Semantic Versioning format
resets back to zero if version on the left is incremented. - [x]: Major version with API and library breaking changes
- [x]: Major version with API and library breaking changes - [y]: Minor version with non-breaking API and library changes
- [yy]: Minor version with non-breaking API and library changes - [z]: Patch version with no direct changes to the API
- [zz]: Bug fix version with no direct changes to API - 2022/05/27 (4.10.0) - Add nk_input_has_mouse_click_in_button_rect() to fix window move bug
- 2022/04/18 (4.9.7) - Change button behavior when NK_BUTTON_TRIGGER_ON_RELEASE is defined to
only trigger when the mouse position was inside the same button on down
- 2022/02/03 (4.9.6) - Allow overriding the NK_INV_SQRT function, similar to NK_SIN and NK_COS
- 2021/12/22 (4.9.5) - Revert layout bounds not accounting for padding due to regressions
- 2021/12/22 (4.9.4) - Fix checking hovering when window is minimized
- 2021/12/22 (4.09.3) - Fix layout bounds not accounting for padding
- 2021/12/19 (4.09.2) - Update to stb_rect_pack.h v1.01 and stb_truetype.h v1.26
- 2021/12/16 (4.09.1) - Fix the majority of GCC warnings
- 2021/10/16 (4.09.0) - Added nk_spacer() widget
- 2021/09/22 (4.08.6) - Fix "may be used uninitialized" warnings in nk_widget
- 2021/09/22 (4.08.5) - GCC __builtin_offsetof only exists in version 4 and later
- 2021/09/15 (4.08.4) - Fix "'num_len' may be used uninitialized" in nk_do_property
- 2021/09/15 (4.08.3) - Fix "Templates cannot be declared to have 'C' Linkage"
- 2021/09/08 (4.08.2) - Fix warnings in C89 builds
- 2021/09/08 (4.08.1) - Use compiler builtins for NK_OFFSETOF when possible
- 2021/08/17 (4.08.0) - Implemented 9-slice scaling support for widget styles
- 2021/08/16 (4.07.5) - Replace usage of memset in nk_font_atlas_bake with NK_MEMSET
- 2021/08/15 (4.07.4) - Fix conversion and sign conversion warnings
- 2021/08/08 (4.07.3) - Fix crash when baking merged fonts
- 2021/08/08 (4.07.2) - Fix Multiline Edit wrong offset
- 2021/03/17 (4.07.1) - Fix warning about unused parameter
- 2021/03/17 (4.07.0) - Fix nk_property hover bug
- 2021/03/15 (4.06.4) - Change nk_propertyi back to int
- 2021/03/15 (4.06.3) - Update documentation for functions that now return nk_bool
- 2020/12/19 (4.06.2) - Fix additional C++ style comments which are not allowed in ISO C90.
- 2020/10/11 (4.06.1) - Fix C++ style comments which are not allowed in ISO C90.
- 2020/10/07 (4.06.0) - Fix nk_combo return type wrongly changed to nk_bool
- 2020/09/05 (4.05.0) - Use the nk_font_atlas allocator for stb_truetype memory management.
- 2020/09/04 (4.04.1) - Replace every boolean int by nk_bool
- 2020/09/04 (4.04.0) - Add nk_bool with NK_INCLUDE_STANDARD_BOOL
- 2020/06/13 (4.03.1) - Fix nk_pool allocation sizes.
- 2020/06/04 (4.03.0) - Made nk_combo header symbols optional.
- 2020/05/27 (4.02.5) - Fix nk_do_edit: Keep scroll position when re-activating edit widget.
- 2020/05/09 (4.02.4) - Fix nk_menubar height calculation bug
- 2020/05/08 (4.02.3) - Fix missing stdarg.h with NK_INCLUDE_STANDARD_VARARGS
- 2020/04/30 (4.02.2) - Fix nk_edit border drawing bug
- 2020/04/09 (4.02.1) - Removed unused nk_sqrt function to fix compiler warnings - 2020/04/09 (4.02.1) - Removed unused nk_sqrt function to fix compiler warnings
- Fixed compiler warnings if you bring your own methods for - Fixed compiler warnings if you bring your own methods for
nk_cos/nk_sin/nk_strtod/nk_memset/nk_memcopy/nk_dtoa nk_cos/nk_sin/nk_strtod/nk_memset/nk_memcopy/nk_dtoa

View file

@ -161,6 +161,8 @@ int main(int argc, char **args) {
//timer_update(lastTick); //timer_update(lastTick);
call_updates();
//renderlag += elapsed; //renderlag += elapsed;
//physlag += elapsed; //physlag += elapsed;

View file

@ -13,11 +13,20 @@
(define-macro (funcsrc func) (define-macro (funcsrc func)
`(funcinfo ,func 'source)) `(funcinfo ,func 'source))
;(define-macro (glog data lvl)
; (let ((z (gensym)))
; `(begin
; (define (,z) ())
; (log ,lvl ,data (funcinfo ,z 'file) (funcinfo ,z 'line)))))
(define-macro (glog data lvl) (define-macro (glog data lvl)
(let ((f (gensym))) `(log ,lvl ,data (port-filename (current-input-port)) (port-line-number (current-input-port))))
`(begin
(define (,f) ()) (define-macro (flog data lvl)
(log ,lvl ,data (funcinfo ,f 'file) (funcinfo ,f 'line))))) `(log ,lvl ,data (funcinfo (*function*) 'file) (funcinfo (*function*) 'line)))
;(define-macro (glog data lvl)
; `(log ,lvl ,data (pair-line-number (cddr (procedure-source
(define (loginfo data) (glog data 0)) (define (loginfo data) (glog data 0))
(define (logwarn data) (glog data 1)) (define (logwarn data) (glog data 1))
@ -39,8 +48,20 @@
(define (quit) (sys_cmd 0)) (define (quit) (sys_cmd 0))
(define (exit) (quit)) (define (exit) (quit))
(define (sound_play sound) (sound_cmd sound 0)) (define (sound_play sound) (sound_cmd sound 0))
(define (sound_pause sound) (sound_cmd sound 1)) (define (sound_pause sound) (sound_cmd sound 1))
(define (sound_stop sound) (sound_cmd sound 2)) (define (sound_stop sound) (sound_cmd sound 2))
(define (sound_restart sound) (sound_cmd sound 3)) (define (sound_restart sound) (sound_cmd sound 3))
(define-macro (update . expr)
(let ((f (gensym)))
`(begin
(define (,f) (begin . ,expr))
(register 0 ,f))))
(define-macro (while condition . body)
(let ((loop (gensym)))
`(let ,loop ()
(cond (,condition
(begin . ,body)
(,loop))))))