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

Split NK_WINDOW_NO_SCROLLBAR into 2 flags #686

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
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
55 changes: 33 additions & 22 deletions nuklear.h
Original file line number Diff line number Diff line change
Expand Up @@ -1457,7 +1457,9 @@ NK_API const struct nk_draw_command* nk__draw_next(const struct nk_draw_command*
/// NK_WINDOW_SCALABLE | The scalable flag indicates that a window can be scaled by user input by dragging a scaler icon at the button of the window
/// NK_WINDOW_CLOSABLE | Adds a closable icon into the header
/// NK_WINDOW_MINIMIZABLE | Adds a minimize icon into the header
/// NK_WINDOW_NO_SCROLLBAR | Removes the scrollbar from the window
/// NK_WINDOW_NO_SCROLLBAR_H | Removes the horizontal scrollbar from the window
/// NK_WINDOW_NO_SCROLLBAR_V | Removes the vertical scrollbar from the window
/// NK_WINDOW_NO_SCROLLBAR | Removes both scrollbars from the window
/// NK_WINDOW_TITLE | Forces a header at the top at the window showing the title
/// NK_WINDOW_SCROLL_AUTO_HIDE | Automatically hides the window scrollbar if no user interaction: also requires delta time in `nk_context` to be set each frame
/// NK_WINDOW_BACKGROUND | Always keep window in the background
Expand All @@ -1477,12 +1479,14 @@ enum nk_panel_flags {
NK_WINDOW_SCALABLE = NK_FLAG(2),
NK_WINDOW_CLOSABLE = NK_FLAG(3),
NK_WINDOW_MINIMIZABLE = NK_FLAG(4),
NK_WINDOW_NO_SCROLLBAR = NK_FLAG(5),
NK_WINDOW_TITLE = NK_FLAG(6),
NK_WINDOW_SCROLL_AUTO_HIDE = NK_FLAG(7),
NK_WINDOW_BACKGROUND = NK_FLAG(8),
NK_WINDOW_SCALE_LEFT = NK_FLAG(9),
NK_WINDOW_NO_INPUT = NK_FLAG(10)
NK_WINDOW_NO_SCROLLBAR_H = NK_FLAG(5),
NK_WINDOW_NO_SCROLLBAR_V = NK_FLAG(6),
NK_WINDOW_NO_SCROLLBAR = NK_WINDOW_NO_SCROLLBAR_H | NK_WINDOW_NO_SCROLLBAR_V,
NK_WINDOW_TITLE = NK_FLAG(7),
NK_WINDOW_SCROLL_AUTO_HIDE = NK_FLAG(8),
NK_WINDOW_BACKGROUND = NK_FLAG(9),
NK_WINDOW_SCALE_LEFT = NK_FLAG(10),
NK_WINDOW_NO_INPUT = NK_FLAG(11)
};
/*/// #### nk_begin
/// Starts a new window; needs to be called every frame for every
Expand Down Expand Up @@ -19904,11 +19908,11 @@ nk_panel_begin(struct nk_context *ctx, const char *title, enum nk_panel_type pan
layout->row.tree_depth = 0;
layout->row.height = panel_padding.y;
layout->has_scrolling = nk_true;
if (!(win->flags & NK_WINDOW_NO_SCROLLBAR))
if (!(win->flags & NK_WINDOW_NO_SCROLLBAR_V))
layout->bounds.w -= scrollbar_size.x;
if (!nk_panel_is_nonblock(panel_type)) {
layout->footer_height = 0;
if (!(win->flags & NK_WINDOW_NO_SCROLLBAR) || win->flags & NK_WINDOW_SCALABLE)
if (!(win->flags & NK_WINDOW_NO_SCROLLBAR_H) || win->flags & NK_WINDOW_SCALABLE)
layout->footer_height = scrollbar_size.y;
layout->bounds.h -= layout->footer_height;
}
Expand Down Expand Up @@ -20114,7 +20118,7 @@ nk_panel_end(struct nk_context *ctx)
empty_space.y = layout->bounds.y;
empty_space.w = panel_padding.x + layout->border;
empty_space.h = layout->bounds.h;
if (*layout->offset_y == 0 && !(layout->flags & NK_WINDOW_NO_SCROLLBAR))
if (*layout->offset_y == 0 && !(layout->flags & NK_WINDOW_NO_SCROLLBAR_V))
empty_space.w += scrollbar_size.x;
nk_fill_rect(out, empty_space, 0, style->window.background);

Expand All @@ -20129,9 +20133,9 @@ nk_panel_end(struct nk_context *ctx)
}

/* scrollbars */
if (!(layout->flags & NK_WINDOW_NO_SCROLLBAR) &&
!(layout->flags & NK_WINDOW_MINIMIZED) &&
window->scrollbar_hiding_timer < NK_SCROLLBAR_HIDING_TIMEOUT)
if ((layout->flags & NK_WINDOW_NO_SCROLLBAR) != NK_WINDOW_NO_SCROLLBAR &&
!(layout->flags & NK_WINDOW_MINIMIZED) &&
window->scrollbar_hiding_timer < NK_SCROLLBAR_HIDING_TIMEOUT)
{
struct nk_rect scroll;
int scroll_has_scrolling;
Expand All @@ -20151,6 +20155,7 @@ nk_panel_end(struct nk_context *ctx)
while (root_window->parent)
root_window = root_window->parent;


/* only allow scrolling if parent window is active */
scroll_has_scrolling = 0;
if ((root_window == ctx->active) && layout->has_scrolling) {
Expand All @@ -20177,7 +20182,7 @@ nk_panel_end(struct nk_context *ctx)
else window->scrolled = nk_false;
} else scroll_has_scrolling = nk_false;

{
if (!(layout->flags & NK_WINDOW_NO_SCROLLBAR_V)) {
/* vertical scrollbar */
nk_flags state = 0;
scroll.x = layout->bounds.x + layout->bounds.w + panel_padding.x;
Expand All @@ -20186,17 +20191,19 @@ nk_panel_end(struct nk_context *ctx)
scroll.h = layout->bounds.h;

scroll_offset = (float)*layout->offset_y;
scroll_step = scroll.h * 0.10f;
scroll_inc = scroll.h * 0.01f;
scroll_target = (float)(int)(layout->at_y - scroll.y);
scroll_step = scroll.h * 0.10f;
scroll_inc = scroll.h * 0.01f;
scroll_offset = nk_do_scrollbarv(&state, out, scroll, scroll_has_scrolling,
scroll_offset, scroll_target, scroll_step, scroll_inc,
&ctx->style.scrollv, in, style->font);

*layout->offset_y = (nk_uint)scroll_offset;

if (in && scroll_has_scrolling)
in->mouse.scroll_delta.y = 0;
}
{
if (!(layout->flags & NK_WINDOW_NO_SCROLLBAR_H)) {
/* horizontal scrollbar */
nk_flags state = 0;
scroll.x = layout->bounds.x;
Expand All @@ -20206,11 +20213,13 @@ nk_panel_end(struct nk_context *ctx)

scroll_offset = (float)*layout->offset_x;
scroll_target = (float)(int)(layout->max_x - scroll.x);
scroll_step = layout->max_x * 0.05f;
scroll_inc = layout->max_x * 0.005f;
scroll_step = layout->max_x * 0.05f;
scroll_inc = layout->max_x * 0.005f;

scroll_offset = nk_do_scrollbarh(&state, out, scroll, scroll_has_scrolling,
scroll_offset, scroll_target, scroll_step, scroll_inc,
&ctx->style.scrollh, in, style->font);

*layout->offset_x = (nk_uint)scroll_offset;
}
}
Expand Down Expand Up @@ -20250,7 +20259,7 @@ nk_panel_end(struct nk_context *ctx)
if (layout->flags & NK_WINDOW_SCALE_LEFT)
scaler.x = layout->bounds.x - panel_padding.x * 0.5f;
else scaler.x = layout->bounds.x + layout->bounds.w + panel_padding.x;
if (layout->flags & NK_WINDOW_NO_SCROLLBAR)
if (layout->flags & NK_WINDOW_NO_SCROLLBAR_H)
scaler.x -= scaler.w;

/* draw scaler */
Expand Down Expand Up @@ -23036,10 +23045,12 @@ nk_group_scrolled_end(struct nk_context *ctx)
pan.bounds.w += 2*g->border;
pan.bounds.h += 2*g->border;
}
if (!(g->flags & NK_WINDOW_NO_SCROLLBAR)) {
if (!(g->flags & NK_WINDOW_NO_SCROLLBAR_V))
pan.bounds.w += ctx->style.window.scrollbar_size.x;

if (!(g->flags & NK_WINDOW_NO_SCROLLBAR_H))
pan.bounds.h += ctx->style.window.scrollbar_size.y;
}

pan.scrollbar.x = *g->offset_x;
pan.scrollbar.y = *g->offset_y;
pan.flags = g->flags;
Expand Down
18 changes: 11 additions & 7 deletions src/nuklear.h
Original file line number Diff line number Diff line change
Expand Up @@ -1235,7 +1235,9 @@ NK_API const struct nk_draw_command* nk__draw_next(const struct nk_draw_command*
/// NK_WINDOW_SCALABLE | The scalable flag indicates that a window can be scaled by user input by dragging a scaler icon at the button of the window
/// NK_WINDOW_CLOSABLE | Adds a closable icon into the header
/// NK_WINDOW_MINIMIZABLE | Adds a minimize icon into the header
/// NK_WINDOW_NO_SCROLLBAR | Removes the scrollbar from the window
/// NK_WINDOW_NO_SCROLLBAR_H | Removes the horizontal scrollbar from the window
/// NK_WINDOW_NO_SCROLLBAR_V | Removes the vertical scrollbar from the window
/// NK_WINDOW_NO_SCROLLBAR | Removes both scrollbars from the window
/// NK_WINDOW_TITLE | Forces a header at the top at the window showing the title
/// NK_WINDOW_SCROLL_AUTO_HIDE | Automatically hides the window scrollbar if no user interaction: also requires delta time in `nk_context` to be set each frame
/// NK_WINDOW_BACKGROUND | Always keep window in the background
Expand All @@ -1255,12 +1257,14 @@ enum nk_panel_flags {
NK_WINDOW_SCALABLE = NK_FLAG(2),
NK_WINDOW_CLOSABLE = NK_FLAG(3),
NK_WINDOW_MINIMIZABLE = NK_FLAG(4),
NK_WINDOW_NO_SCROLLBAR = NK_FLAG(5),
NK_WINDOW_TITLE = NK_FLAG(6),
NK_WINDOW_SCROLL_AUTO_HIDE = NK_FLAG(7),
NK_WINDOW_BACKGROUND = NK_FLAG(8),
NK_WINDOW_SCALE_LEFT = NK_FLAG(9),
NK_WINDOW_NO_INPUT = NK_FLAG(10)
NK_WINDOW_NO_SCROLLBAR_H = NK_FLAG(5),
NK_WINDOW_NO_SCROLLBAR_V = NK_FLAG(6),
NK_WINDOW_NO_SCROLLBAR = NK_WINDOW_NO_SCROLLBAR_H | NK_WINDOW_NO_SCROLLBAR_V,
NK_WINDOW_TITLE = NK_FLAG(7),
NK_WINDOW_SCROLL_AUTO_HIDE = NK_FLAG(8),
NK_WINDOW_BACKGROUND = NK_FLAG(9),
NK_WINDOW_SCALE_LEFT = NK_FLAG(10),
NK_WINDOW_NO_INPUT = NK_FLAG(11)
};
/*/// #### nk_begin
/// Starts a new window; needs to be called every frame for every
Expand Down
6 changes: 4 additions & 2 deletions src/nuklear_group.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,12 @@ nk_group_scrolled_end(struct nk_context *ctx)
pan.bounds.w += 2*g->border;
pan.bounds.h += 2*g->border;
}
if (!(g->flags & NK_WINDOW_NO_SCROLLBAR)) {
if (!(g->flags & NK_WINDOW_NO_SCROLLBAR_V))
pan.bounds.w += ctx->style.window.scrollbar_size.x;

if (!(g->flags & NK_WINDOW_NO_SCROLLBAR_H))
pan.bounds.h += ctx->style.window.scrollbar_size.y;
}

pan.scrollbar.x = *g->offset_x;
pan.scrollbar.y = *g->offset_y;
pan.flags = g->flags;
Expand Down
31 changes: 18 additions & 13 deletions src/nuklear_panel.c
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,11 @@ nk_panel_begin(struct nk_context *ctx, const char *title, enum nk_panel_type pan
layout->row.tree_depth = 0;
layout->row.height = panel_padding.y;
layout->has_scrolling = nk_true;
if (!(win->flags & NK_WINDOW_NO_SCROLLBAR))
if (!(win->flags & NK_WINDOW_NO_SCROLLBAR_V))
layout->bounds.w -= scrollbar_size.x;
if (!nk_panel_is_nonblock(panel_type)) {
layout->footer_height = 0;
if (!(win->flags & NK_WINDOW_NO_SCROLLBAR) || win->flags & NK_WINDOW_SCALABLE)
if (!(win->flags & NK_WINDOW_NO_SCROLLBAR_H) || win->flags & NK_WINDOW_SCALABLE)
layout->footer_height = scrollbar_size.y;
layout->bounds.h -= layout->footer_height;
}
Expand Down Expand Up @@ -383,7 +383,7 @@ nk_panel_end(struct nk_context *ctx)
empty_space.y = layout->bounds.y;
empty_space.w = panel_padding.x + layout->border;
empty_space.h = layout->bounds.h;
if (*layout->offset_y == 0 && !(layout->flags & NK_WINDOW_NO_SCROLLBAR))
if (*layout->offset_y == 0 && !(layout->flags & NK_WINDOW_NO_SCROLLBAR_V))
empty_space.w += scrollbar_size.x;
nk_fill_rect(out, empty_space, 0, style->window.background);

Expand All @@ -398,9 +398,9 @@ nk_panel_end(struct nk_context *ctx)
}

/* scrollbars */
if (!(layout->flags & NK_WINDOW_NO_SCROLLBAR) &&
!(layout->flags & NK_WINDOW_MINIMIZED) &&
window->scrollbar_hiding_timer < NK_SCROLLBAR_HIDING_TIMEOUT)
if ((layout->flags & NK_WINDOW_NO_SCROLLBAR) != NK_WINDOW_NO_SCROLLBAR &&
!(layout->flags & NK_WINDOW_MINIMIZED) &&
window->scrollbar_hiding_timer < NK_SCROLLBAR_HIDING_TIMEOUT)
{
struct nk_rect scroll;
int scroll_has_scrolling;
Expand All @@ -420,6 +420,7 @@ nk_panel_end(struct nk_context *ctx)
while (root_window->parent)
root_window = root_window->parent;


/* only allow scrolling if parent window is active */
scroll_has_scrolling = 0;
if ((root_window == ctx->active) && layout->has_scrolling) {
Expand All @@ -446,7 +447,7 @@ nk_panel_end(struct nk_context *ctx)
else window->scrolled = nk_false;
} else scroll_has_scrolling = nk_false;

{
if (!(layout->flags & NK_WINDOW_NO_SCROLLBAR_V)) {
/* vertical scrollbar */
nk_flags state = 0;
scroll.x = layout->bounds.x + layout->bounds.w + panel_padding.x;
Expand All @@ -455,17 +456,19 @@ nk_panel_end(struct nk_context *ctx)
scroll.h = layout->bounds.h;

scroll_offset = (float)*layout->offset_y;
scroll_step = scroll.h * 0.10f;
scroll_inc = scroll.h * 0.01f;
scroll_target = (float)(int)(layout->at_y - scroll.y);
scroll_step = scroll.h * 0.10f;
scroll_inc = scroll.h * 0.01f;
scroll_offset = nk_do_scrollbarv(&state, out, scroll, scroll_has_scrolling,
scroll_offset, scroll_target, scroll_step, scroll_inc,
&ctx->style.scrollv, in, style->font);

*layout->offset_y = (nk_uint)scroll_offset;

if (in && scroll_has_scrolling)
in->mouse.scroll_delta.y = 0;
}
{
if (!(layout->flags & NK_WINDOW_NO_SCROLLBAR_H)) {
/* horizontal scrollbar */
nk_flags state = 0;
scroll.x = layout->bounds.x;
Expand All @@ -475,11 +478,13 @@ nk_panel_end(struct nk_context *ctx)

scroll_offset = (float)*layout->offset_x;
scroll_target = (float)(int)(layout->max_x - scroll.x);
scroll_step = layout->max_x * 0.05f;
scroll_inc = layout->max_x * 0.005f;
scroll_step = layout->max_x * 0.05f;
scroll_inc = layout->max_x * 0.005f;

scroll_offset = nk_do_scrollbarh(&state, out, scroll, scroll_has_scrolling,
scroll_offset, scroll_target, scroll_step, scroll_inc,
&ctx->style.scrollh, in, style->font);

*layout->offset_x = (nk_uint)scroll_offset;
}
}
Expand Down Expand Up @@ -519,7 +524,7 @@ nk_panel_end(struct nk_context *ctx)
if (layout->flags & NK_WINDOW_SCALE_LEFT)
scaler.x = layout->bounds.x - panel_padding.x * 0.5f;
else scaler.x = layout->bounds.x + layout->bounds.w + panel_padding.x;
if (layout->flags & NK_WINDOW_NO_SCROLLBAR)
if (layout->flags & NK_WINDOW_NO_SCROLLBAR_H)
scaler.x -= scaler.w;

/* draw scaler */
Expand Down