Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Horizontal rule #447

Merged
merged 8 commits into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions demo/common/overview.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
23 changes: 23 additions & 0 deletions nuklear.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}



Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions src/nuklear.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions src/nuklear_window.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}