From 6473a45543192da995cf07722afe01dd30c728f7 Mon Sep 17 00:00:00 2001 From: diggit Date: Sun, 26 Aug 2018 02:10:40 +0200 Subject: [PATCH 1/3] Regenerate nukelar.h, unfortunately reverts #718 this elimites changes from #718 because they were done in generated file and not in sources. See PR thread for more info. --- nuklear.h | 51 +++++++++++++++++++++++++-------------------------- 1 file changed, 25 insertions(+), 26 deletions(-) diff --git a/nuklear.h b/nuklear.h index c6689b7..150ad77 100644 --- a/nuklear.h +++ b/nuklear.h @@ -671,8 +671,8 @@ NK_API void nk_set_user_data(struct nk_context*, nk_handle handle); /*/// ### Input /// The input API is responsible for holding the current input state composed of /// mouse, key and text input states. -/// It is worth noting that no direct OS or window handling is done in nuklear. -/// Instead all input state has to be provided by platform specific code. This on one hand +/// It is worth noting that no direct os or window handling is done in nuklear. +/// Instead all input state has to be provided by platform specific code. This in one hand /// expects more work from the user and complicates usage but on the other hand /// provides simple abstraction over a big number of platforms, libraries and other /// already provided functionality. @@ -773,7 +773,7 @@ enum nk_buttons { }; /*/// #### nk_input_begin /// Begins the input mirroring process by resetting text, scroll -/// mouse, previous mouse position and movement as well as key state transitions, +/// mouse previous mouse position and movement as well as key state transitions, /// /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c /// void nk_input_begin(struct nk_context*); @@ -799,7 +799,7 @@ NK_API void nk_input_begin(struct nk_context*); */ NK_API void nk_input_motion(struct nk_context*, int x, int y); /*/// #### nk_input_key -/// Mirrors the state of a specific key to nuklear +/// Mirrors state of a specific key to nuklear /// /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c /// void nk_input_key(struct nk_context*, enum nk_keys key, int down); @@ -831,7 +831,6 @@ NK_API void nk_input_button(struct nk_context*, enum nk_buttons, int x, int y, i /*/// #### nk_input_scroll /// Copies the last mouse scroll value to nuklear. Is generally /// a scroll value. So does not have to come from mouse and could also originate -/// TODO finish this sentence /// /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c /// void nk_input_scroll(struct nk_context *ctx, struct nk_vec2 val); @@ -896,7 +895,7 @@ NK_API void nk_input_glyph(struct nk_context*, const nk_glyph); NK_API void nk_input_unicode(struct nk_context*, nk_rune); /*/// #### nk_input_end /// End the input mirroring process by resetting mouse grabbing -/// state to ensure the mouse cursor is not grabbed indefinitely. +/// state to ensure the mouse cursor is not grabbed indefinitely./// /// /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c /// void nk_input_end(struct nk_context *ctx); @@ -1170,7 +1169,7 @@ struct nk_convert_config { */ NK_API const struct nk_command* nk__begin(struct nk_context*); /*/// #### nk__next -/// Returns draw command pointer pointing to the next command inside the draw command list +/// Returns a draw command list iterator to iterate all draw /// /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c /// const struct nk_command* nk__next(struct nk_context*, const struct nk_command*); @@ -1196,7 +1195,7 @@ NK_API const struct nk_command* nk__next(struct nk_context*, const struct nk_com /// __ctx__ | Must point to an previously initialized `nk_context` struct at the end of a frame /// __cmd__ | Command pointer initialized to NULL /// -/// Iterates over each draw command inside the context draw command list +/// Returns draw command pointer pointing to the next command inside the draw command list */ #define nk_foreach(c, ctx) for((c) = nk__begin(ctx); (c) != 0; (c) = nk__next(ctx,c)) #ifdef NK_INCLUDE_VERTEX_BUFFER_OUTPUT @@ -1231,7 +1230,7 @@ NK_API const struct nk_command* nk__next(struct nk_context*, const struct nk_com */ NK_API nk_flags nk_convert(struct nk_context*, struct nk_buffer *cmds, struct nk_buffer *vertices, struct nk_buffer *elements, const struct nk_convert_config*); /*/// #### nk__draw_begin -/// Returns a draw vertex command buffer iterator to iterate over the vertex draw command buffer +/// Returns a draw vertex command buffer iterator to iterate each the vertex draw command buffer /// /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c /// const struct nk_draw_command* nk__draw_begin(const struct nk_context*, const struct nk_buffer*); @@ -1299,7 +1298,7 @@ NK_API const struct nk_draw_command* nk__draw_next(const struct nk_draw_command* /// ### Window /// Windows are the main persistent state used inside nuklear and are life time /// controlled by simply "retouching" (i.e. calling) each window each frame. -/// All widgets inside nuklear can only be added inside the function pair `nk_begin_xxx` +/// All widgets inside nuklear can only be added inside function pair `nk_begin_xxx` /// and `nk_end`. Calling any widgets outside these two functions will result in an /// assert in debug or no state change in release mode.

/// @@ -1470,7 +1469,7 @@ enum nk_panel_flags { NK_API int nk_begin(struct nk_context *ctx, const char *title, struct nk_rect bounds, nk_flags flags); /*/// #### nk_begin_titled /// Extended window start with separated title and identifier to allow multiple -/// windows with same title but not name +/// windows with same name but not title /// /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c /// int nk_begin_titled(struct nk_context *ctx, const char *name, const char *title, struct nk_rect bounds, nk_flags flags); @@ -1514,12 +1513,12 @@ NK_API void nk_end(struct nk_context *ctx); /// __name__ | Window identifier /// /// Returns a `nk_window` struct pointing to the identified window or NULL if -/// no window with the given name was found +/// no window with given name was found */ NK_API struct nk_window *nk_window_find(struct nk_context *ctx, const char *name); /*/// #### nk_window_get_bounds -/// Returns a rectangle with screen position and size of the currently processed window /// +/// Returns a rectangle with screen position and size of the currently processed window /// !!! WARNING /// Only call this function between calls `nk_begin_xxx` and `nk_end` /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c @@ -1533,9 +1532,9 @@ NK_API struct nk_window *nk_window_find(struct nk_context *ctx, const char *name /// Returns a `nk_rect` struct with window upper left window position and size */ NK_API struct nk_rect nk_window_get_bounds(const struct nk_context *ctx); -/*/// #### nk_window_get_position -/// Returns the position of the currently processed window. +/*/// #### nk_window_get_bounds /// +/// Returns the position of the currently processed window. /// !!! WARNING /// Only call this function between calls `nk_begin_xxx` and `nk_end` /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c @@ -1550,8 +1549,8 @@ NK_API struct nk_rect nk_window_get_bounds(const struct nk_context *ctx); */ NK_API struct nk_vec2 nk_window_get_position(const struct nk_context *ctx); /*/// #### nk_window_get_size -/// Returns the size with width and height of the currently processed window. /// +/// Returns the size with width and height of the currently processed window. /// !!! WARNING /// Only call this function between calls `nk_begin_xxx` and `nk_end` /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c @@ -1566,8 +1565,8 @@ NK_API struct nk_vec2 nk_window_get_position(const struct nk_context *ctx); */ NK_API struct nk_vec2 nk_window_get_size(const struct nk_context*); /*/// #### nk_window_get_width -/// Returns the width of the currently processed window. /// +/// Returns the width of the currently processed window. /// !!! WARNING /// Only call this function between calls `nk_begin_xxx` and `nk_end` /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c @@ -1582,8 +1581,8 @@ NK_API struct nk_vec2 nk_window_get_size(const struct nk_context*); */ NK_API float nk_window_get_width(const struct nk_context*); /*/// #### nk_window_get_height -/// Returns the height of the currently processed window. /// +/// Returns the height of the currently processed window. /// !!! WARNING /// Only call this function between calls `nk_begin_xxx` and `nk_end` /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c @@ -1598,12 +1597,12 @@ NK_API float nk_window_get_width(const struct nk_context*); */ NK_API float nk_window_get_height(const struct nk_context*); /*/// #### nk_window_get_panel -/// Returns the underlying panel which contains all processing state of the current window. /// +/// Returns the underlying panel which contains all processing state of the current window. /// !!! WARNING /// Only call this function between calls `nk_begin_xxx` and `nk_end` /// !!! WARNING -/// Do not keep the returned panel pointer around, it is only valid until `nk_end` +/// Do not keep the returned panel pointer around it is only valid until `nk_end` /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c /// struct nk_panel* nk_window_get_panel(struct nk_context *ctx); /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -1616,9 +1615,9 @@ NK_API float nk_window_get_height(const struct nk_context*); */ NK_API struct nk_panel* nk_window_get_panel(struct nk_context*); /*/// #### nk_window_get_content_region +/// /// Returns the position and size of the currently visible and non-clipped space /// inside the currently processed window. -/// /// !!! WARNING /// Only call this function between calls `nk_begin_xxx` and `nk_end` /// @@ -1635,9 +1634,9 @@ NK_API struct nk_panel* nk_window_get_panel(struct nk_context*); */ NK_API struct nk_rect nk_window_get_content_region(struct nk_context*); /*/// #### nk_window_get_content_region_min +/// /// Returns the upper left position of the currently visible and non-clipped /// space inside the currently processed window. -/// /// !!! WARNING /// Only call this function between calls `nk_begin_xxx` and `nk_end` /// @@ -1654,9 +1653,9 @@ NK_API struct nk_rect nk_window_get_content_region(struct nk_context*); */ NK_API struct nk_vec2 nk_window_get_content_region_min(struct nk_context*); /*/// #### nk_window_get_content_region_max +/// /// Returns the lower right screen position of the currently visible and /// non-clipped space inside the currently processed window. -/// /// !!! WARNING /// Only call this function between calls `nk_begin_xxx` and `nk_end` /// @@ -1673,9 +1672,9 @@ NK_API struct nk_vec2 nk_window_get_content_region_min(struct nk_context*); */ NK_API struct nk_vec2 nk_window_get_content_region_max(struct nk_context*); /*/// #### nk_window_get_content_region_size +/// /// Returns the size of the currently visible and non-clipped space inside the /// currently processed window -/// /// !!! WARNING /// Only call this function between calls `nk_begin_xxx` and `nk_end` /// @@ -2283,7 +2282,7 @@ NK_API float nk_layout_ratio_from_pixel(struct nk_context*, float pixel_width); /// __columns__ | Number of widget inside row */ NK_API void nk_layout_row_dynamic(struct nk_context *ctx, float height, int cols); -/*/// #### nk_layout_row_static +/*/// #### nk_layout_row_dynamic /// Sets current row layout to fill @cols number of widgets /// in row with same @item_width horizontal size. Once called all subsequent widget /// calls greater than @cols will allocate a new row with same layout. @@ -2473,7 +2472,7 @@ NK_API struct nk_rect nk_layout_space_bounds(struct nk_context*); /// Returns transformed `nk_vec2` in screen space coordinates */ NK_API struct nk_vec2 nk_layout_space_to_screen(struct nk_context*, struct nk_vec2); -/*/// #### nk_layout_space_to_local +/*/// #### nk_layout_space_to_screen /// Converts vector from layout space into screen space /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c /// struct nk_vec2 nk_layout_space_to_local(struct nk_context*, struct nk_vec2); From b17df7b4630cd8b95c8b827485a2cff42ad9030f Mon Sep 17 00:00:00 2001 From: diggit Date: Sun, 26 Aug 2018 11:17:39 +0200 Subject: [PATCH 2/3] fix wrong dynamic panel footer filling --- nuklear.h | 4 ++-- src/nuklear_panel.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/nuklear.h b/nuklear.h index 150ad77..c76b033 100644 --- a/nuklear.h +++ b/nuklear.h @@ -15798,11 +15798,11 @@ nk_panel_end(struct nk_context *ctx) nk_fill_rect(out, empty_space, 0, style->window.background); /* fill bottom empty space */ - if (*layout->offset_x != 0 && !(layout->flags & NK_WINDOW_NO_SCROLLBAR)) { + if (layout->footer_height > 0) { empty_space.x = window->bounds.x; empty_space.y = layout->bounds.y + layout->bounds.h; empty_space.w = window->bounds.w; - empty_space.h = scrollbar_size.y; + empty_space.h = layout->footer_height; nk_fill_rect(out, empty_space, 0, style->window.background); } } diff --git a/src/nuklear_panel.c b/src/nuklear_panel.c index 8eb680e..db72b13 100644 --- a/src/nuklear_panel.c +++ b/src/nuklear_panel.c @@ -371,11 +371,11 @@ nk_panel_end(struct nk_context *ctx) nk_fill_rect(out, empty_space, 0, style->window.background); /* fill bottom empty space */ - if (*layout->offset_x != 0 && !(layout->flags & NK_WINDOW_NO_SCROLLBAR)) { + if (layout->footer_height > 0) { empty_space.x = window->bounds.x; empty_space.y = layout->bounds.y + layout->bounds.h; empty_space.w = window->bounds.w; - empty_space.h = scrollbar_size.y; + empty_space.h = layout->footer_height; nk_fill_rect(out, empty_space, 0, style->window.background); } } From e86fcabce72a1b472e64c1a29df9cfd7391c04d6 Mon Sep 17 00:00:00 2001 From: diggit Date: Sun, 26 Aug 2018 11:26:57 +0200 Subject: [PATCH 3/3] fix scrollbar dragging behavior, similar to #688 --- nuklear.h | 4 +++- src/nuklear_scrollbar.c | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/nuklear.h b/nuklear.h index c76b033..43a51ad 100644 --- a/nuklear.h +++ b/nuklear.h @@ -21180,6 +21180,7 @@ nk_scrollbar_behavior(nk_flags *state, struct nk_input *in, { nk_flags ws = 0; int left_mouse_down; + int left_mouse_clicked; int left_mouse_click_in_cursor; float scroll_delta; @@ -21187,13 +21188,14 @@ nk_scrollbar_behavior(nk_flags *state, struct nk_input *in, if (!in) return scroll_offset; left_mouse_down = in->mouse.buttons[NK_BUTTON_LEFT].down; + left_mouse_clicked = in->mouse.buttons[NK_BUTTON_LEFT].clicked; left_mouse_click_in_cursor = nk_input_has_mouse_click_down_in_rect(in, NK_BUTTON_LEFT, *cursor, nk_true); if (nk_input_is_mouse_hovering_rect(in, *scroll)) *state = NK_WIDGET_STATE_HOVERED; scroll_delta = (o == NK_VERTICAL) ? in->mouse.scroll_delta.y: in->mouse.scroll_delta.x; - if (left_mouse_down && left_mouse_click_in_cursor) { + if (left_mouse_down && left_mouse_click_in_cursor && !left_mouse_clicked) { /* update cursor by mouse dragging */ float pixel, delta; *state = NK_WIDGET_STATE_ACTIVE; diff --git a/src/nuklear_scrollbar.c b/src/nuklear_scrollbar.c index 3a7f179..aad175d 100644 --- a/src/nuklear_scrollbar.c +++ b/src/nuklear_scrollbar.c @@ -15,6 +15,7 @@ nk_scrollbar_behavior(nk_flags *state, struct nk_input *in, { nk_flags ws = 0; int left_mouse_down; + int left_mouse_clicked; int left_mouse_click_in_cursor; float scroll_delta; @@ -22,13 +23,14 @@ nk_scrollbar_behavior(nk_flags *state, struct nk_input *in, if (!in) return scroll_offset; left_mouse_down = in->mouse.buttons[NK_BUTTON_LEFT].down; + left_mouse_clicked = in->mouse.buttons[NK_BUTTON_LEFT].clicked; left_mouse_click_in_cursor = nk_input_has_mouse_click_down_in_rect(in, NK_BUTTON_LEFT, *cursor, nk_true); if (nk_input_is_mouse_hovering_rect(in, *scroll)) *state = NK_WIDGET_STATE_HOVERED; scroll_delta = (o == NK_VERTICAL) ? in->mouse.scroll_delta.y: in->mouse.scroll_delta.x; - if (left_mouse_down && left_mouse_click_in_cursor) { + if (left_mouse_down && left_mouse_click_in_cursor && !left_mouse_clicked) { /* update cursor by mouse dragging */ float pixel, delta; *state = NK_WIDGET_STATE_ACTIVE;