Skip to content

Make slider behave like progress bar #802

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion clib.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nuklear",
"version": "4.12.7",
"version": "4.12.8",
"repo": "Immediate-Mode-UI/Nuklear",
"description": "A small ANSI C gui toolkit",
"keywords": ["gl", "ui", "toolkit"],
Expand Down
11 changes: 9 additions & 2 deletions nuklear.h
Original file line number Diff line number Diff line change
Expand Up @@ -25923,6 +25923,7 @@ nk_do_slider(nk_flags *state,

struct nk_rect visual_cursor;
struct nk_rect logical_cursor;
struct nk_rect cursor;

NK_ASSERT(style);
NK_ASSERT(out);
Expand Down Expand Up @@ -25986,8 +25987,13 @@ nk_do_slider(nk_flags *state,
visual_cursor.y = (bounds.y + bounds.h*0.5f) - visual_cursor.h*0.5f;
visual_cursor.x = logical_cursor.x - visual_cursor.w*0.5f;

slider_value = nk_slider_behavior(state, &logical_cursor, &visual_cursor,
in, bounds, slider_min, slider_max, slider_value, step, slider_steps);
cursor.w = NK_MAX(bounds.w, 2 * style->padding.x + 2 * style->border);
cursor.h = NK_MAX(bounds.h, 2 * style->padding.y + 2 * style->border);
cursor = nk_pad_rect(bounds, nk_vec2(style->padding.x + style->border, style->padding.y + style->border));

NK_UNUSED(nk_slider_behavior);
slider_value = (nk_float)nk_progress_behavior(state, in, bounds, cursor,
(nk_size)(slider_max - slider_min), (nk_size)(slider_value - slider_min), nk_true) + slider_min;
visual_cursor.x = logical_cursor.x - visual_cursor.w*0.5f;

/* draw slider */
Expand Down Expand Up @@ -30716,6 +30722,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
///
/// - 2025/04/19 (4.12.8) - Make slider behave like progress bar
/// - 2025/04/06 (4.12.7) - Fix text input navigation and mouse scrolling
/// - 2025/03/29 (4.12.6) - Fix unitialized data in nk_input_char
/// - 2025/03/05 (4.12.5) - Fix scrolling knob also scrolling parent window, remove dead code
Expand Down
1 change: 1 addition & 0 deletions src/CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
/// - [y]: Minor version with non-breaking API and library changes
/// - [z]: Patch version with no direct changes to the API
///
/// - 2025/04/19 (4.12.8) - Make slider behave like progress bar
/// - 2025/04/06 (4.12.7) - Fix text input navigation and mouse scrolling
/// - 2025/03/29 (4.12.6) - Fix unitialized data in nk_input_char
/// - 2025/03/05 (4.12.5) - Fix scrolling knob also scrolling parent window, remove dead code
Expand Down
10 changes: 8 additions & 2 deletions src/nuklear_slider.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ nk_do_slider(nk_flags *state,

struct nk_rect visual_cursor;
struct nk_rect logical_cursor;
struct nk_rect cursor;

NK_ASSERT(style);
NK_ASSERT(out);
Expand Down Expand Up @@ -194,8 +195,13 @@ nk_do_slider(nk_flags *state,
visual_cursor.y = (bounds.y + bounds.h*0.5f) - visual_cursor.h*0.5f;
visual_cursor.x = logical_cursor.x - visual_cursor.w*0.5f;

slider_value = nk_slider_behavior(state, &logical_cursor, &visual_cursor,
in, bounds, slider_min, slider_max, slider_value, step, slider_steps);
cursor.w = NK_MAX(bounds.w, 2 * style->padding.x + 2 * style->border);
cursor.h = NK_MAX(bounds.h, 2 * style->padding.y + 2 * style->border);
cursor = nk_pad_rect(bounds, nk_vec2(style->padding.x + style->border, style->padding.y + style->border));

NK_UNUSED(nk_slider_behavior);
slider_value = (nk_float)nk_progress_behavior(state, in, bounds, cursor,
(nk_size)(slider_max - slider_min), (nk_size)(slider_value - slider_min), nk_true) + slider_min;
visual_cursor.x = logical_cursor.x - visual_cursor.w*0.5f;

/* draw slider */
Expand Down