Nuklear
This is a minimal-state, immediate-mode graphical user interface toolkit written in ANSI C and licensed under public domain. It was designed as a simple embeddable user interface for application and does not have any dependencies, a default render backend or OS window/input handling but instead provides a highly modular, library-based approach, with simple input state for input and draw commands describing primitive shapes as output. So instead of providing a layered library that tries to abstract over a number of platform and render backends, it focuses only on the actual UI.
 
Loading...
Searching...
No Matches
nuklear_list_view.c
1#include "nuklear.h"
2#include "nuklear_internal.h"
3
4/* ===============================================================
5 *
6 * LIST VIEW
7 *
8 * ===============================================================*/
9NK_API nk_bool
10nk_list_view_begin(struct nk_context *ctx, struct nk_list_view *view,
11 const char *title, nk_flags flags, int row_height, int row_count)
12{
13 int title_len;
14 nk_hash title_hash;
15 nk_uint *x_offset;
16 nk_uint *y_offset;
17
18 int result;
19 struct nk_window *win;
20 struct nk_panel *layout;
21 const struct nk_style *style;
22 struct nk_vec2 item_spacing;
23
24 NK_ASSERT(ctx);
25 NK_ASSERT(view);
26 NK_ASSERT(title);
27 if (!ctx || !view || !title) return 0;
28
29 win = ctx->current;
30 style = &ctx->style;
31 item_spacing = style->window.spacing;
32 row_height += NK_MAX(0, (int)item_spacing.y);
33
34 /* find persistent list view scrollbar offset */
35 title_len = (int)nk_strlen(title);
36 title_hash = nk_murmur_hash(title, (int)title_len, NK_PANEL_GROUP);
37 x_offset = nk_find_value(win, title_hash);
38 if (!x_offset) {
39 x_offset = nk_add_value(ctx, win, title_hash, 0);
40 y_offset = nk_add_value(ctx, win, title_hash+1, 0);
41
42 NK_ASSERT(x_offset);
43 NK_ASSERT(y_offset);
44 if (!x_offset || !y_offset) return 0;
45 *x_offset = *y_offset = 0;
46 } else y_offset = nk_find_value(win, title_hash+1);
47 view->scroll_value = *y_offset;
48 view->scroll_pointer = y_offset;
49
50 *y_offset = 0;
51 result = nk_group_scrolled_offset_begin(ctx, x_offset, y_offset, title, flags);
52 win = ctx->current;
53 layout = win->layout;
54
55 view->total_height = row_height * NK_MAX(row_count,1);
56 view->begin = (int)NK_MAX(((float)view->scroll_value / (float)row_height), 0.0f);
57 view->count = (int)NK_MAX(nk_iceilf((layout->clip.h)/(float)row_height),0);
58 view->count = NK_MIN(view->count, row_count - view->begin);
59 view->end = view->begin + view->count;
60 view->ctx = ctx;
61 return result;
62}
63NK_API void
64nk_list_view_end(struct nk_list_view *view)
65{
66 struct nk_context *ctx;
67 struct nk_window *win;
68 struct nk_panel *layout;
69
70 NK_ASSERT(view);
71 NK_ASSERT(view->ctx);
72 NK_ASSERT(view->scroll_pointer);
73 if (!view || !view->ctx) return;
74
75 ctx = view->ctx;
76 win = ctx->current;
77 layout = win->layout;
78 layout->at_y = layout->bounds.y + (float)view->total_height;
79 *view->scroll_pointer = *view->scroll_pointer + view->scroll_value;
80 nk_group_end(view->ctx);
81}
82
main API and documentation file
NK_API nk_bool nk_group_scrolled_offset_begin(struct nk_context *, nk_uint *x_offset, nk_uint *y_offset, const char *title, nk_flags flags)
NK_API void nk_group_end(struct nk_context *)