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 if (!(y_offset = nk_find_value(win, title_hash+1))) {
47 NK_ASSERT(y_offset);
48 if (!y_offset) return 0;
49 *x_offset = *y_offset = 0;
50 }
51 view->scroll_value = *y_offset;
52 view->scroll_pointer = y_offset;
53
54 *y_offset = 0;
55 result = nk_group_scrolled_offset_begin(ctx, x_offset, y_offset, title, flags);
56 win = ctx->current;
57 layout = win->layout;
58
59 view->total_height = row_height * NK_MAX(row_count,1);
60 view->begin = (int)NK_MAX(((float)view->scroll_value / (float)row_height), 0.0f);
61 view->count = (int)NK_MAX(nk_iceilf((layout->clip.h)/(float)row_height),0);
62 view->count = NK_MIN(view->count, row_count - view->begin);
63 view->end = view->begin + view->count;
64 view->ctx = ctx;
65 return result;
66}
67NK_API void
68nk_list_view_end(struct nk_list_view *view)
69{
70 struct nk_context *ctx;
71 struct nk_window *win;
72 struct nk_panel *layout;
73
74 NK_ASSERT(view);
75 NK_ASSERT(view->ctx);
76 NK_ASSERT(view->scroll_pointer);
77 if (!view || !view->ctx) return;
78
79 ctx = view->ctx;
80 win = ctx->current;
81 layout = win->layout;
82 layout->at_y = layout->bounds.y + (float)view->total_height;
83 *view->scroll_pointer = *view->scroll_pointer + view->scroll_value;
84 nk_group_end(view->ctx);
85}
86
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 *)