diff --git a/demo/common/overview.c b/demo/common/overview.c index 86cb9f210..ab66c844f 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 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'-like 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); } diff --git a/nuklear.h b/nuklear.h index 2d754a6b8..06e7fee69 100644 --- a/nuklear.h +++ b/nuklear.h @@ -2004,6 +2004,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 @@ -20730,6 +20743,15 @@ 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); +} @@ -29680,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 diff --git a/src/CHANGELOG b/src/CHANGELOG index 4bcdfdb94..9c8c65748 100644 --- a/src/CHANGELOG +++ b/src/CHANGELOG @@ -15,6 +15,7 @@ /// - 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 diff --git a/src/nuklear.h b/src/nuklear.h index 5111d9bee..142d342ea 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 486b912b3..e69ad396d 100644 --- a/src/nuklear_window.c +++ b/src/nuklear_window.c @@ -669,3 +669,12 @@ 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); +}