|
|
b53a5c |
#include "nuklear.h"
|
|
|
b53a5c |
#include "nuklear_internal.h"
|
|
|
b53a5c |
|
|
|
b53a5c |
/* ===============================================================
|
|
|
b53a5c |
*
|
|
|
b53a5c |
* GROUP
|
|
|
b53a5c |
*
|
|
|
b53a5c |
* ===============================================================*/
|
|
|
b53a5c |
NK_API nk_bool
|
|
|
b53a5c |
nk_group_scrolled_offset_begin(struct nk_context *ctx,
|
|
|
b53a5c |
nk_uint *x_offset, nk_uint *y_offset, const char *title, nk_flags flags)
|
|
|
b53a5c |
{
|
|
|
b53a5c |
struct nk_rect bounds;
|
|
|
b53a5c |
struct nk_window panel;
|
|
|
b53a5c |
struct nk_window *win;
|
|
|
b53a5c |
|
|
|
b53a5c |
win = ctx->current;
|
|
|
b53a5c |
nk_panel_alloc_space(&bounds, ctx);
|
|
|
b53a5c |
{const struct nk_rect *c = &win->layout->clip;
|
|
|
b53a5c |
if (!NK_INTERSECT(c->x, c->y, c->w, c->h, bounds.x, bounds.y, bounds.w, bounds.h) &&
|
|
|
b53a5c |
!(flags & NK_WINDOW_MOVABLE)) {
|
|
|
b53a5c |
return 0;
|
|
|
b53a5c |
}}
|
|
|
b53a5c |
if (win->flags & NK_WINDOW_ROM)
|
|
|
b53a5c |
flags |= NK_WINDOW_ROM;
|
|
|
b53a5c |
|
|
|
b53a5c |
/* initialize a fake window to create the panel from */
|
|
|
b53a5c |
nk_zero(&panel, sizeof(panel));
|
|
|
b53a5c |
panel.bounds = bounds;
|
|
|
b53a5c |
panel.flags = flags;
|
|
|
b53a5c |
panel.scrollbar.x = *x_offset;
|
|
|
b53a5c |
panel.scrollbar.y = *y_offset;
|
|
|
b53a5c |
panel.buffer = win->buffer;
|
|
|
b53a5c |
panel.layout = (struct nk_panel*)nk_create_panel(ctx);
|
|
|
b53a5c |
ctx->current = &panel;
|
|
|
b53a5c |
nk_panel_begin(ctx, (flags & NK_WINDOW_TITLE) ? title: 0, NK_PANEL_GROUP);
|
|
|
b53a5c |
|
|
|
b53a5c |
win->buffer = panel.buffer;
|
|
|
b53a5c |
win->buffer.clip = panel.layout->clip;
|
|
|
b53a5c |
panel.layout->offset_x = x_offset;
|
|
|
b53a5c |
panel.layout->offset_y = y_offset;
|
|
|
b53a5c |
panel.layout->parent = win->layout;
|
|
|
b53a5c |
win->layout = panel.layout;
|
|
|
b53a5c |
|
|
|
b53a5c |
ctx->current = win;
|
|
|
b53a5c |
if ((panel.layout->flags & NK_WINDOW_CLOSED) ||
|
|
|
b53a5c |
(panel.layout->flags & NK_WINDOW_MINIMIZED))
|
|
|
b53a5c |
{
|
|
|
b53a5c |
nk_flags f = panel.layout->flags;
|
|
|
b53a5c |
nk_group_scrolled_end(ctx);
|
|
|
b53a5c |
if (f & NK_WINDOW_CLOSED)
|
|
|
b53a5c |
return NK_WINDOW_CLOSED;
|
|
|
b53a5c |
if (f & NK_WINDOW_MINIMIZED)
|
|
|
b53a5c |
return NK_WINDOW_MINIMIZED;
|
|
|
b53a5c |
}
|
|
|
b53a5c |
return 1;
|
|
|
b53a5c |
}
|
|
|
b53a5c |
NK_API void
|
|
|
b53a5c |
nk_group_scrolled_end(struct nk_context *ctx)
|
|
|
b53a5c |
{
|
|
|
b53a5c |
struct nk_window *win;
|
|
|
b53a5c |
struct nk_panel *parent;
|
|
|
b53a5c |
struct nk_panel *g;
|
|
|
b53a5c |
|
|
|
b53a5c |
struct nk_rect clip;
|
|
|
b53a5c |
struct nk_window pan;
|
|
|
b53a5c |
struct nk_vec2 panel_padding;
|
|
|
b53a5c |
|
|
|
b53a5c |
NK_ASSERT(ctx);
|
|
|
b53a5c |
NK_ASSERT(ctx->current);
|
|
|
b53a5c |
if (!ctx || !ctx->current)
|
|
|
b53a5c |
return;
|
|
|
b53a5c |
|
|
|
b53a5c |
/* make sure nk_group_begin was called correctly */
|
|
|
b53a5c |
NK_ASSERT(ctx->current);
|
|
|
b53a5c |
win = ctx->current;
|
|
|
b53a5c |
NK_ASSERT(win->layout);
|
|
|
b53a5c |
g = win->layout;
|
|
|
b53a5c |
NK_ASSERT(g->parent);
|
|
|
b53a5c |
parent = g->parent;
|
|
|
b53a5c |
|
|
|
b53a5c |
/* dummy window */
|
|
|
b53a5c |
nk_zero_struct(pan);
|
|
|
b53a5c |
panel_padding = nk_panel_get_padding(&ctx->style, NK_PANEL_GROUP);
|
|
|
b53a5c |
pan.bounds.y = g->bounds.y - (g->header_height + g->menu.h);
|
|
|
b53a5c |
pan.bounds.x = g->bounds.x - panel_padding.x;
|
|
|
b53a5c |
pan.bounds.w = g->bounds.w + 2 * panel_padding.x;
|
|
|
b53a5c |
pan.bounds.h = g->bounds.h + g->header_height + g->menu.h;
|
|
|
b53a5c |
if (g->flags & NK_WINDOW_BORDER) {
|
|
|
b53a5c |
pan.bounds.x -= g->border;
|
|
|
b53a5c |
pan.bounds.y -= g->border;
|
|
|
b53a5c |
pan.bounds.w += 2*g->border;
|
|
|
b53a5c |
pan.bounds.h += 2*g->border;
|
|
|
b53a5c |
}
|
|
|
b53a5c |
if (!(g->flags & NK_WINDOW_NO_SCROLLBAR)) {
|
|
|
b53a5c |
pan.bounds.w += ctx->style.window.scrollbar_size.x;
|
|
|
b53a5c |
pan.bounds.h += ctx->style.window.scrollbar_size.y;
|
|
|
b53a5c |
}
|
|
|
b53a5c |
pan.scrollbar.x = *g->offset_x;
|
|
|
b53a5c |
pan.scrollbar.y = *g->offset_y;
|
|
|
b53a5c |
pan.flags = g->flags;
|
|
|
b53a5c |
pan.buffer = win->buffer;
|
|
|
b53a5c |
pan.layout = g;
|
|
|
b53a5c |
pan.parent = win;
|
|
|
b53a5c |
ctx->current = &pan;
|
|
|
b53a5c |
|
|
|
b53a5c |
/* make sure group has correct clipping rectangle */
|
|
|
b53a5c |
nk_unify(&clip, &parent->clip, pan.bounds.x, pan.bounds.y,
|
|
|
b53a5c |
pan.bounds.x + pan.bounds.w, pan.bounds.y + pan.bounds.h + panel_padding.x);
|
|
|
b53a5c |
nk_push_scissor(&pan.buffer, clip);
|
|
|
b53a5c |
nk_end(ctx);
|
|
|
b53a5c |
|
|
|
b53a5c |
win->buffer = pan.buffer;
|
|
|
b53a5c |
nk_push_scissor(&win->buffer, parent->clip);
|
|
|
b53a5c |
ctx->current = win;
|
|
|
b53a5c |
win->layout = parent;
|
|
|
b53a5c |
g->bounds = pan.bounds;
|
|
|
b53a5c |
return;
|
|
|
b53a5c |
}
|
|
|
b53a5c |
NK_API nk_bool
|
|
|
b53a5c |
nk_group_scrolled_begin(struct nk_context *ctx,
|
|
|
b53a5c |
struct nk_scroll *scroll, const char *title, nk_flags flags)
|
|
|
b53a5c |
{
|
|
|
b53a5c |
return nk_group_scrolled_offset_begin(ctx, &scroll->x, &scroll->y, title, flags);
|
|
|
b53a5c |
}
|
|
|
b53a5c |
NK_API nk_bool
|
|
|
b53a5c |
nk_group_begin_titled(struct nk_context *ctx, const char *id,
|
|
|
b53a5c |
const char *title, nk_flags flags)
|
|
|
b53a5c |
{
|
|
|
b53a5c |
int id_len;
|
|
|
b53a5c |
nk_hash id_hash;
|
|
|
b53a5c |
struct nk_window *win;
|
|
|
b53a5c |
nk_uint *x_offset;
|
|
|
b53a5c |
nk_uint *y_offset;
|
|
|
b53a5c |
|
|
|
b53a5c |
NK_ASSERT(ctx);
|
|
|
b53a5c |
NK_ASSERT(id);
|
|
|
b53a5c |
NK_ASSERT(ctx->current);
|
|
|
b53a5c |
NK_ASSERT(ctx->current->layout);
|
|
|
b53a5c |
if (!ctx || !ctx->current || !ctx->current->layout || !id)
|
|
|
b53a5c |
return 0;
|
|
|
b53a5c |
|
|
|
b53a5c |
/* find persistent group scrollbar value */
|
|
|
b53a5c |
win = ctx->current;
|
|
|
b53a5c |
id_len = (int)nk_strlen(id);
|
|
|
b53a5c |
id_hash = nk_murmur_hash(id, (int)id_len, NK_PANEL_GROUP);
|
|
|
b53a5c |
x_offset = nk_find_value(win, id_hash);
|
|
|
b53a5c |
if (!x_offset) {
|
|
|
b53a5c |
x_offset = nk_add_value(ctx, win, id_hash, 0);
|
|
|
b53a5c |
y_offset = nk_add_value(ctx, win, id_hash+1, 0);
|
|
|
b53a5c |
|
|
|
b53a5c |
NK_ASSERT(x_offset);
|
|
|
b53a5c |
NK_ASSERT(y_offset);
|
|
|
b53a5c |
if (!x_offset || !y_offset) return 0;
|
|
|
b53a5c |
*x_offset = *y_offset = 0;
|
|
|
b53a5c |
} else y_offset = nk_find_value(win, id_hash+1);
|
|
|
b53a5c |
return nk_group_scrolled_offset_begin(ctx, x_offset, y_offset, title, flags);
|
|
|
b53a5c |
}
|
|
|
b53a5c |
NK_API nk_bool
|
|
|
b53a5c |
nk_group_begin(struct nk_context *ctx, const char *title, nk_flags flags)
|
|
|
b53a5c |
{
|
|
|
b53a5c |
return nk_group_begin_titled(ctx, title, title, flags);
|
|
|
b53a5c |
}
|
|
|
b53a5c |
NK_API void
|
|
|
b53a5c |
nk_group_end(struct nk_context *ctx)
|
|
|
b53a5c |
{
|
|
|
b53a5c |
nk_group_scrolled_end(ctx);
|
|
|
b53a5c |
}
|
|
|
b53a5c |
NK_API void
|
|
|
b53a5c |
nk_group_get_scroll(struct nk_context *ctx, const char *id, nk_uint *x_offset, nk_uint *y_offset)
|
|
|
b53a5c |
{
|
|
|
b53a5c |
int id_len;
|
|
|
b53a5c |
nk_hash id_hash;
|
|
|
b53a5c |
struct nk_window *win;
|
|
|
b53a5c |
nk_uint *x_offset_ptr;
|
|
|
b53a5c |
nk_uint *y_offset_ptr;
|
|
|
b53a5c |
|
|
|
b53a5c |
NK_ASSERT(ctx);
|
|
|
b53a5c |
NK_ASSERT(id);
|
|
|
b53a5c |
NK_ASSERT(ctx->current);
|
|
|
b53a5c |
NK_ASSERT(ctx->current->layout);
|
|
|
b53a5c |
if (!ctx || !ctx->current || !ctx->current->layout || !id)
|
|
|
b53a5c |
return;
|
|
|
b53a5c |
|
|
|
b53a5c |
/* find persistent group scrollbar value */
|
|
|
b53a5c |
win = ctx->current;
|
|
|
b53a5c |
id_len = (int)nk_strlen(id);
|
|
|
b53a5c |
id_hash = nk_murmur_hash(id, (int)id_len, NK_PANEL_GROUP);
|
|
|
b53a5c |
x_offset_ptr = nk_find_value(win, id_hash);
|
|
|
b53a5c |
if (!x_offset_ptr) {
|
|
|
b53a5c |
x_offset_ptr = nk_add_value(ctx, win, id_hash, 0);
|
|
|
b53a5c |
y_offset_ptr = nk_add_value(ctx, win, id_hash+1, 0);
|
|
|
b53a5c |
|
|
|
b53a5c |
NK_ASSERT(x_offset_ptr);
|
|
|
b53a5c |
NK_ASSERT(y_offset_ptr);
|
|
|
b53a5c |
if (!x_offset_ptr || !y_offset_ptr) return;
|
|
|
b53a5c |
*x_offset_ptr = *y_offset_ptr = 0;
|
|
|
b53a5c |
} else y_offset_ptr = nk_find_value(win, id_hash+1);
|
|
|
b53a5c |
if (x_offset)
|
|
|
b53a5c |
*x_offset = *x_offset_ptr;
|
|
|
b53a5c |
if (y_offset)
|
|
|
b53a5c |
*y_offset = *y_offset_ptr;
|
|
|
b53a5c |
}
|
|
|
b53a5c |
NK_API void
|
|
|
b53a5c |
nk_group_set_scroll(struct nk_context *ctx, const char *id, nk_uint x_offset, nk_uint y_offset)
|
|
|
b53a5c |
{
|
|
|
b53a5c |
int id_len;
|
|
|
b53a5c |
nk_hash id_hash;
|
|
|
b53a5c |
struct nk_window *win;
|
|
|
b53a5c |
nk_uint *x_offset_ptr;
|
|
|
b53a5c |
nk_uint *y_offset_ptr;
|
|
|
b53a5c |
|
|
|
b53a5c |
NK_ASSERT(ctx);
|
|
|
b53a5c |
NK_ASSERT(id);
|
|
|
b53a5c |
NK_ASSERT(ctx->current);
|
|
|
b53a5c |
NK_ASSERT(ctx->current->layout);
|
|
|
b53a5c |
if (!ctx || !ctx->current || !ctx->current->layout || !id)
|
|
|
b53a5c |
return;
|
|
|
b53a5c |
|
|
|
b53a5c |
/* find persistent group scrollbar value */
|
|
|
b53a5c |
win = ctx->current;
|
|
|
b53a5c |
id_len = (int)nk_strlen(id);
|
|
|
b53a5c |
id_hash = nk_murmur_hash(id, (int)id_len, NK_PANEL_GROUP);
|
|
|
b53a5c |
x_offset_ptr = nk_find_value(win, id_hash);
|
|
|
b53a5c |
if (!x_offset_ptr) {
|
|
|
b53a5c |
x_offset_ptr = nk_add_value(ctx, win, id_hash, 0);
|
|
|
b53a5c |
y_offset_ptr = nk_add_value(ctx, win, id_hash+1, 0);
|
|
|
b53a5c |
|
|
|
b53a5c |
NK_ASSERT(x_offset_ptr);
|
|
|
b53a5c |
NK_ASSERT(y_offset_ptr);
|
|
|
b53a5c |
if (!x_offset_ptr || !y_offset_ptr) return;
|
|
|
b53a5c |
*x_offset_ptr = *y_offset_ptr = 0;
|
|
|
b53a5c |
} else y_offset_ptr = nk_find_value(win, id_hash+1);
|
|
|
b53a5c |
*x_offset_ptr = x_offset;
|
|
|
b53a5c |
*y_offset_ptr = y_offset;
|
|
|
b53a5c |
}
|