Add nk_group_get_scroll and nk_group_set_scroll

master
Kevin Harrison 2018-12-16 21:11:16 -05:00 committed by Pavel Korolev
parent 9854477f0b
commit b9f84362fb
3 changed files with 186 additions and 2 deletions

View File

@ -2698,6 +2698,34 @@ NK_API int nk_group_scrolled_begin(struct nk_context*, struct nk_scroll *off, co
/// __ctx__ | Must point to an previously initialized `nk_context` struct
*/
NK_API void nk_group_scrolled_end(struct nk_context*);
/*/// #### nk_group_get_scroll
/// Gets the scroll position of the given group.
/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
/// void nk_group_get_scroll(struct nk_context*, const char *id, nk_uint *x_offset, nk_uint *y_offset);
/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
///
/// Parameter | Description
/// -------------|-----------------------------------------------------------
/// __ctx__ | Must point to an previously initialized `nk_context` struct
/// __id__ | The id of the group to get the scroll position of
/// __x_offset__ | A pointer to the x offset output
/// __y_offset__ | A pointer to the y offset output
*/
NK_API void nk_group_get_scroll(struct nk_context*, const char *id, nk_uint *x_offset, nk_uint *y_offset);
/*/// #### nk_group_set_scroll
/// Sets the scroll position of the given group.
/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
/// void nk_group_set_scroll(struct nk_context*, const char *id, nk_uint x_offset, nk_uint y_offset);
/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
///
/// Parameter | Description
/// -------------|-----------------------------------------------------------
/// __ctx__ | Must point to an previously initialized `nk_context` struct
/// __id__ | The id of the group to scroll
/// __x_offset__ | The x offset to scroll to
/// __y_offset__ | The y offset to scroll to
*/
NK_API void nk_group_set_scroll(struct nk_context*, const char *id, nk_uint x_offset, nk_uint y_offset);
/* =============================================================================
*
* TREE
@ -5615,7 +5643,6 @@ template<typename T> struct nk_alignof{struct Big {T x; char c;}; enum {
#endif /* NK_NUKLEAR_H_ */
#ifdef NK_IMPLEMENTATION
#ifndef NK_INTERNAL_H
@ -18719,7 +18746,72 @@ nk_group_end(struct nk_context *ctx)
{
nk_group_scrolled_end(ctx);
}
NK_API void
nk_group_get_scroll(struct nk_context *ctx, const char *id, nk_uint *x_offset, nk_uint *y_offset)
{
int id_len;
nk_hash id_hash;
struct nk_window *win;
nk_uint *x_offset_ptr;
nk_uint *y_offset_ptr;
NK_ASSERT(ctx);
NK_ASSERT(id);
NK_ASSERT(ctx->current);
NK_ASSERT(ctx->current->layout);
if (!ctx || !ctx->current || !ctx->current->layout || !id)
return;
/* find persistent group scrollbar value */
win = ctx->current;
id_len = (int)nk_strlen(id);
id_hash = nk_murmur_hash(id, (int)id_len, NK_PANEL_GROUP);
x_offset_ptr = nk_find_value(win, id_hash);
if (!x_offset_ptr) {
x_offset_ptr = nk_add_value(ctx, win, id_hash, 0);
y_offset_ptr = nk_add_value(ctx, win, id_hash+1, 0);
NK_ASSERT(x_offset_ptr);
NK_ASSERT(y_offset_ptr);
if (!x_offset_ptr || !y_offset_ptr) return;
*x_offset_ptr = *y_offset_ptr = 0;
} else y_offset_ptr = nk_find_value(win, id_hash+1);
*x_offset = *x_offset_ptr;
*y_offset = *y_offset_ptr;
}
NK_API void
nk_group_set_scroll(struct nk_context *ctx, const char *id, nk_uint x_offset, nk_uint y_offset)
{
int id_len;
nk_hash id_hash;
struct nk_window *win;
nk_uint *x_offset_ptr;
nk_uint *y_offset_ptr;
NK_ASSERT(ctx);
NK_ASSERT(id);
NK_ASSERT(ctx->current);
NK_ASSERT(ctx->current->layout);
if (!ctx || !ctx->current || !ctx->current->layout || !id)
return;
/* find persistent group scrollbar value */
win = ctx->current;
id_len = (int)nk_strlen(id);
id_hash = nk_murmur_hash(id, (int)id_len, NK_PANEL_GROUP);
x_offset_ptr = nk_find_value(win, id_hash);
if (!x_offset_ptr) {
x_offset_ptr = nk_add_value(ctx, win, id_hash, 0);
y_offset_ptr = nk_add_value(ctx, win, id_hash+1, 0);
NK_ASSERT(x_offset_ptr);
NK_ASSERT(y_offset_ptr);
if (!x_offset_ptr || !y_offset_ptr) return;
*x_offset_ptr = *y_offset_ptr = 0;
} else y_offset_ptr = nk_find_value(win, id_hash+1);
*x_offset_ptr = x_offset;
*y_offset_ptr = y_offset;
}

View File

@ -2479,6 +2479,34 @@ NK_API int nk_group_scrolled_begin(struct nk_context*, struct nk_scroll *off, co
/// __ctx__ | Must point to an previously initialized `nk_context` struct
*/
NK_API void nk_group_scrolled_end(struct nk_context*);
/*/// #### nk_group_get_scroll
/// Gets the scroll position of the given group.
/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
/// void nk_group_get_scroll(struct nk_context*, const char *id, nk_uint *x_offset, nk_uint *y_offset);
/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
///
/// Parameter | Description
/// -------------|-----------------------------------------------------------
/// __ctx__ | Must point to an previously initialized `nk_context` struct
/// __id__ | The id of the group to get the scroll position of
/// __x_offset__ | A pointer to the x offset output
/// __y_offset__ | A pointer to the y offset output
*/
NK_API void nk_group_get_scroll(struct nk_context*, const char *id, nk_uint *x_offset, nk_uint *y_offset);
/*/// #### nk_group_set_scroll
/// Sets the scroll position of the given group.
/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
/// void nk_group_set_scroll(struct nk_context*, const char *id, nk_uint x_offset, nk_uint y_offset);
/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
///
/// Parameter | Description
/// -------------|-----------------------------------------------------------
/// __ctx__ | Must point to an previously initialized `nk_context` struct
/// __id__ | The id of the group to scroll
/// __x_offset__ | The x offset to scroll to
/// __y_offset__ | The y offset to scroll to
*/
NK_API void nk_group_set_scroll(struct nk_context*, const char *id, nk_uint x_offset, nk_uint y_offset);
/* =============================================================================
*
* TREE
@ -5395,4 +5423,3 @@ template<typename T> struct nk_alignof{struct Big {T x; char c;}; enum {
#endif
#endif /* NK_NUKLEAR_H_ */

View File

@ -166,4 +166,69 @@ nk_group_end(struct nk_context *ctx)
{
nk_group_scrolled_end(ctx);
}
NK_API void
nk_group_get_scroll(struct nk_context *ctx, const char *id, nk_uint *x_offset, nk_uint *y_offset)
{
int id_len;
nk_hash id_hash;
struct nk_window *win;
nk_uint *x_offset_ptr;
nk_uint *y_offset_ptr;
NK_ASSERT(ctx);
NK_ASSERT(id);
NK_ASSERT(ctx->current);
NK_ASSERT(ctx->current->layout);
if (!ctx || !ctx->current || !ctx->current->layout || !id)
return;
/* find persistent group scrollbar value */
win = ctx->current;
id_len = (int)nk_strlen(id);
id_hash = nk_murmur_hash(id, (int)id_len, NK_PANEL_GROUP);
x_offset_ptr = nk_find_value(win, id_hash);
if (!x_offset_ptr) {
x_offset_ptr = nk_add_value(ctx, win, id_hash, 0);
y_offset_ptr = nk_add_value(ctx, win, id_hash+1, 0);
NK_ASSERT(x_offset_ptr);
NK_ASSERT(y_offset_ptr);
if (!x_offset_ptr || !y_offset_ptr) return;
*x_offset_ptr = *y_offset_ptr = 0;
} else y_offset_ptr = nk_find_value(win, id_hash+1);
*x_offset = *x_offset_ptr;
*y_offset = *y_offset_ptr;
}
NK_API void
nk_group_set_scroll(struct nk_context *ctx, const char *id, nk_uint x_offset, nk_uint y_offset)
{
int id_len;
nk_hash id_hash;
struct nk_window *win;
nk_uint *x_offset_ptr;
nk_uint *y_offset_ptr;
NK_ASSERT(ctx);
NK_ASSERT(id);
NK_ASSERT(ctx->current);
NK_ASSERT(ctx->current->layout);
if (!ctx || !ctx->current || !ctx->current->layout || !id)
return;
/* find persistent group scrollbar value */
win = ctx->current;
id_len = (int)nk_strlen(id);
id_hash = nk_murmur_hash(id, (int)id_len, NK_PANEL_GROUP);
x_offset_ptr = nk_find_value(win, id_hash);
if (!x_offset_ptr) {
x_offset_ptr = nk_add_value(ctx, win, id_hash, 0);
y_offset_ptr = nk_add_value(ctx, win, id_hash+1, 0);
NK_ASSERT(x_offset_ptr);
NK_ASSERT(y_offset_ptr);
if (!x_offset_ptr || !y_offset_ptr) return;
*x_offset_ptr = *y_offset_ptr = 0;
} else y_offset_ptr = nk_find_value(win, id_hash+1);
*x_offset_ptr = x_offset;
*y_offset_ptr = y_offset;
}