From 5a75b319e47f328a928308cb634a6bf08eb66f9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wladislav=20=E3=83=B4=E3=83=A9=E3=83=89=20Artsimovich?= Date: Fri, 15 Apr 2022 13:19:10 +0900 Subject: [PATCH 1/6] Added nk_rule_horizontal() widget --- nuklear.h | 24 ++++++++++++++++++++++++ src/CHANGELOG | 1 + src/nuklear.h | 13 +++++++++++++ src/nuklear_window.c | 10 ++++++++++ 4 files changed, 48 insertions(+) diff --git a/nuklear.h b/nuklear.h index 9a33488..933da31 100644 --- a/nuklear.h +++ b/nuklear.h @@ -2003,6 +2003,19 @@ NK_API void nk_window_show(struct nk_context*, const char *name, enum nk_show_st /// __cond__ | condition that has to be met to actually commit the visbility state change */ NK_API void nk_window_show_if(struct nk_context*, const char *name, enum nk_show_states, int cond); +/*/// #### nk_window_show_if +/// Line for visual seperation. Draws a line with thickness determined by the current row height. +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c +/// void nk_rule_horizontal(struct nk_context *ctx, struct nk_color color, NK_BOOL rounding) +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +/// +/// Parameter | Description +/// ----------------|------------------------------------------------------- +/// __ctx__ | Must point to an previously initialized `nk_context` struct +/// __color__ | Color of the horizontal line +/// __rounding__ | Whether or not to make the line round +*/ +NK_API void nk_rule_horizontal(struct nk_context *ctx, struct nk_color color, NK_BOOL rounding) /* ============================================================================= * * LAYOUT @@ -20688,6 +20701,16 @@ nk_window_set_focus(struct nk_context *ctx, const char *name) ctx->active = win; } +NK_API void +nk_rule_horizontal(struct nk_context *ctx, struct nk_color color, NK_BOOL rounding) +{ + struct nk_rect space; + enum nk_widget_layout_states state = nk_widget(&space, ctx); + struct nk_command_buffer *canvas = nk_window_get_canvas(ctx); + if (!state) return; + nk_fill_rect(canvas, space, rounding && space.h > 1.5f ? space.h / 2.0f : 0, color); +} + @@ -29629,6 +29652,7 @@ nk_tooltipfv(struct nk_context *ctx, const char *fmt, va_list args) /// - [y]: Minor version with non-breaking API and library changes /// - [z]: Patch version with no direct changes to the API /// +/// - 2022/02/03 (4.9.7) - Added nk_rule_horizontal() widget /// - 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 diff --git a/src/CHANGELOG b/src/CHANGELOG index 4be9f04..95c0879 100644 --- a/src/CHANGELOG +++ b/src/CHANGELOG @@ -7,6 +7,7 @@ /// - [y]: Minor version with non-breaking API and library changes /// - [z]: Patch version with no direct changes to the API /// +/// - 2022/04/15 (4.9.7) - Added nk_rule_horizontal() widget /// - 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 diff --git a/src/nuklear.h b/src/nuklear.h index b97c95c..d9bd435 100644 --- a/src/nuklear.h +++ b/src/nuklear.h @@ -1782,6 +1782,19 @@ NK_API void nk_window_show(struct nk_context*, const char *name, enum nk_show_st /// __cond__ | condition that has to be met to actually commit the visbility state change */ NK_API void nk_window_show_if(struct nk_context*, const char *name, enum nk_show_states, int cond); +/*/// #### nk_window_show_if +/// Line for visual seperation. Draws a line with thickness determined by the current row height. +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c +/// void nk_rule_horizontal(struct nk_context *ctx, struct nk_color color, NK_BOOL rounding) +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +/// +/// Parameter | Description +/// ----------------|------------------------------------------------------- +/// __ctx__ | Must point to an previously initialized `nk_context` struct +/// __color__ | Color of the horizontal line +/// __rounding__ | Whether or not to make the line round +*/ +NK_API void nk_rule_horizontal(struct nk_context *ctx, struct nk_color color, NK_BOOL rounding) /* ============================================================================= * * LAYOUT diff --git a/src/nuklear_window.c b/src/nuklear_window.c index 486b912..e5e90b7 100644 --- a/src/nuklear_window.c +++ b/src/nuklear_window.c @@ -669,3 +669,13 @@ nk_window_set_focus(struct nk_context *ctx, const char *name) } ctx->active = win; } + +NK_API void +nk_rule_horizontal(struct nk_context *ctx, struct nk_color color, NK_BOOL rounding) +{ + struct nk_rect space; + enum nk_widget_layout_states state = nk_widget(&space, ctx); + struct nk_command_buffer *canvas = nk_window_get_canvas(ctx); + if (!state) return; + nk_fill_rect(canvas, space, rounding && space.h > 1.5f ? space.h / 2.0f : 0, color); +} From 398e338bff91e4f7a50c842ad6a2d02371c100d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wladislav=20=E3=83=B4=E3=83=A9=E3=83=89=20Artsimovich?= Date: Fri, 15 Apr 2022 13:27:39 +0900 Subject: [PATCH 2/6] Forgot to regenerate nuklear.h --- nuklear.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nuklear.h b/nuklear.h index 933da31..b3c9528 100644 --- a/nuklear.h +++ b/nuklear.h @@ -29652,7 +29652,7 @@ nk_tooltipfv(struct nk_context *ctx, const char *fmt, va_list args) /// - [y]: Minor version with non-breaking API and library changes /// - [z]: Patch version with no direct changes to the API /// -/// - 2022/02/03 (4.9.7) - Added nk_rule_horizontal() widget +/// - 2022/04/15 (4.9.7) - Added nk_rule_horizontal() widget /// - 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 From cb0e05beeaf665f26172e35e3ef29fd3bd5e59fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wladislav=20=E3=83=B4=E3=83=A9=E3=83=89=20Artsimovich?= Date: Fri, 15 Apr 2022 13:35:13 +0900 Subject: [PATCH 3/6] Forgot the semicolon in nuklear.h --- nuklear.h | 5 ++--- src/nuklear.h | 2 +- src/nuklear_window.c | 3 +-- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/nuklear.h b/nuklear.h index b3c9528..e58e3d6 100644 --- a/nuklear.h +++ b/nuklear.h @@ -2015,7 +2015,7 @@ NK_API void nk_window_show_if(struct nk_context*, const char *name, enum nk_show /// __color__ | Color of the horizontal line /// __rounding__ | Whether or not to make the line round */ -NK_API void nk_rule_horizontal(struct nk_context *ctx, struct nk_color color, NK_BOOL rounding) +NK_API void nk_rule_horizontal(struct nk_context *ctx, struct nk_color color, nk_bool rounding); /* ============================================================================= * * LAYOUT @@ -20700,9 +20700,8 @@ nk_window_set_focus(struct nk_context *ctx, const char *name) } ctx->active = win; } - NK_API void -nk_rule_horizontal(struct nk_context *ctx, struct nk_color color, NK_BOOL rounding) +nk_rule_horizontal(struct nk_context *ctx, struct nk_color color, nk_bool rounding) { struct nk_rect space; enum nk_widget_layout_states state = nk_widget(&space, ctx); diff --git a/src/nuklear.h b/src/nuklear.h index d9bd435..615feeb 100644 --- a/src/nuklear.h +++ b/src/nuklear.h @@ -1794,7 +1794,7 @@ NK_API void nk_window_show_if(struct nk_context*, const char *name, enum nk_show /// __color__ | Color of the horizontal line /// __rounding__ | Whether or not to make the line round */ -NK_API void nk_rule_horizontal(struct nk_context *ctx, struct nk_color color, NK_BOOL rounding) +NK_API void nk_rule_horizontal(struct nk_context *ctx, struct nk_color color, nk_bool rounding); /* ============================================================================= * * LAYOUT diff --git a/src/nuklear_window.c b/src/nuklear_window.c index e5e90b7..e69ad39 100644 --- a/src/nuklear_window.c +++ b/src/nuklear_window.c @@ -669,9 +669,8 @@ nk_window_set_focus(struct nk_context *ctx, const char *name) } ctx->active = win; } - NK_API void -nk_rule_horizontal(struct nk_context *ctx, struct nk_color color, NK_BOOL rounding) +nk_rule_horizontal(struct nk_context *ctx, struct nk_color color, nk_bool rounding) { struct nk_rect space; enum nk_widget_layout_states state = nk_widget(&space, ctx); From 2ec96be4b94a51da9604ff00a0120127df5fdf56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wladislav=20=E3=83=B4=E3=83=A9=E3=83=89=20Artsimovich?= Date: Tue, 17 Oct 2023 11:37:30 +0900 Subject: [PATCH 4/6] Add horizontal rule demo --- demo/common/overview.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/demo/common/overview.c b/demo/common/overview.c index 86cb9f2..00042d5 100644 --- a/demo/common/overview.c +++ b/demo/common/overview.c @@ -590,6 +590,18 @@ overview(struct nk_context *ctx) } nk_tree_pop(ctx); } + + if (nk_tree_push(ctx, NK_TREE_NODE, "Horizontal Rule", NK_MINIMIZED)) + { + nk_layout_row_dynamic(ctx, 12, 1); + nk_label(ctx, "Use this subdivide spaces visually", NK_TEXT_LEFT); + nk_layout_row_dynamic(ctx, 4, 1); + nk_rule_horizontal(ctx, nk_white, nk_true); + nk_layout_row_dynamic(ctx, 75, 1); + nk_label_wrap(ctx, "Best used in 'Card' layouts, with a bigger title font on top. Takes on the size of the previous layout definition. Rounding optional."); + nk_tree_pop(ctx); + } + nk_tree_pop(ctx); } From 7384f0ed673ca92b2b056c9f54c203406188bb0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wladislav=20=E3=83=B4=E3=83=A9=E3=83=89=20Artsimovich?= Date: Tue, 17 Oct 2023 11:41:11 +0900 Subject: [PATCH 5/6] Regenerate Nuklear.h --- nuklear.h | 1 + 1 file changed, 1 insertion(+) diff --git a/nuklear.h b/nuklear.h index ec03865..06e7fee 100644 --- a/nuklear.h +++ b/nuklear.h @@ -29702,6 +29702,7 @@ nk_tooltipfv(struct nk_context *ctx, const char *fmt, va_list args) /// - 2022/08/01 (4.10.1) - Fix cursor jumping back to beginning of text when typing more than /// nk_edit_xxx limit /// - 2022/05/27 (4.10.0) - Add nk_input_has_mouse_click_in_button_rect() to fix window move bug +/// - 2022/04/19 (4.9.8) - Added nk_rule_horizontal() widget /// - 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 From 57d1f210561a943cf786bf70526c4a0a608a8712 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wladislav=20=E3=83=B4=E3=83=A9=E3=83=89=20Artsimovich?= Date: Tue, 17 Oct 2023 11:43:21 +0900 Subject: [PATCH 6/6] Fix demo typo --- demo/common/overview.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/demo/common/overview.c b/demo/common/overview.c index 00042d5..ab66c84 100644 --- a/demo/common/overview.c +++ b/demo/common/overview.c @@ -594,11 +594,11 @@ overview(struct nk_context *ctx) if (nk_tree_push(ctx, NK_TREE_NODE, "Horizontal Rule", NK_MINIMIZED)) { nk_layout_row_dynamic(ctx, 12, 1); - nk_label(ctx, "Use this subdivide spaces visually", NK_TEXT_LEFT); + nk_label(ctx, "Use this to subdivide spaces visually", NK_TEXT_LEFT); nk_layout_row_dynamic(ctx, 4, 1); nk_rule_horizontal(ctx, nk_white, nk_true); nk_layout_row_dynamic(ctx, 75, 1); - nk_label_wrap(ctx, "Best used in 'Card' layouts, with a bigger title font on top. Takes on the size of the previous layout definition. Rounding optional."); + nk_label_wrap(ctx, "Best used in 'Card'-like layouts, with a bigger title font on top. Takes on the size of the previous layout definition. Rounding optional."); nk_tree_pop(ctx); }