2 #include "nuklear_internal.h"
10 nk_tree_state_base(
struct nk_context *ctx,
enum nk_tree_type type,
11 struct nk_image *img,
const char *title,
enum nk_collapse_states *state)
19 enum nk_symbol_type symbol;
23 struct nk_rect header = {0,0,0,0};
31 NK_ASSERT(ctx->current);
32 NK_ASSERT(ctx->current->layout);
33 if (!ctx || !ctx->current || !ctx->current->layout)
41 item_spacing = style->window.spacing;
44 row_height = style->font->
height + 2 * style->tab.padding.y;
49 widget_state = nk_widget(&header, ctx);
50 if (type == NK_TREE_TAB) {
51 const struct nk_style_item *background = &style->tab.background;
53 switch(background->type) {
54 case NK_STYLE_ITEM_IMAGE:
55 nk_draw_image(out, header, &background->data.image, nk_rgb_factor(nk_white, style->tab.color_factor));
57 case NK_STYLE_ITEM_NINE_SLICE:
58 nk_draw_nine_slice(out, header, &background->data.slice, nk_rgb_factor(nk_white, style->tab.color_factor));
60 case NK_STYLE_ITEM_COLOR:
61 nk_fill_rect(out, header, 0, nk_rgb_factor(style->tab.border_color, style->tab.color_factor));
62 nk_fill_rect(out, nk_shrink_rect(header, style->tab.border),
63 style->tab.rounding, nk_rgb_factor(background->data.color, style->tab.color_factor));
66 }
else text.background = style->window.background;
71 if (nk_button_behavior(&ws, header, in, NK_BUTTON_DEFAULT))
72 *state = (*state == NK_MAXIMIZED) ? NK_MINIMIZED : NK_MAXIMIZED;
75 if (*state == NK_MAXIMIZED) {
76 symbol = style->tab.sym_maximize;
77 if (type == NK_TREE_TAB)
78 button = &style->tab.tab_maximize_button;
79 else button = &style->tab.node_maximize_button;
81 symbol = style->tab.sym_minimize;
82 if (type == NK_TREE_TAB)
83 button = &style->tab.tab_minimize_button;
84 else button = &style->tab.node_minimize_button;
88 sym.w = sym.h = style->font->
height;
89 sym.y = header.y + style->tab.padding.y;
90 sym.x = header.x + style->tab.padding.x;
91 nk_do_button_symbol(&ws, &win->buffer, sym, symbol, NK_BUTTON_DEFAULT,
92 button, 0, style->font);
96 sym.x = sym.x + sym.w + 4 * item_spacing.x;
98 sym.w = style->font->
height + style->tab.spacing.x;}
103 header.w = NK_MAX(header.w, sym.w + item_spacing.x);
104 label.x = sym.x + sym.w + item_spacing.x;
106 label.w = header.w - (sym.w + item_spacing.y + style->tab.indent);
107 label.h = style->font->
height;
108 text.text = nk_rgb_factor(style->tab.text, style->tab.color_factor);
110 nk_widget_text(out, label, title, nk_strlen(title), &text,
111 NK_TEXT_LEFT, style->font);}
114 if (*state == NK_MAXIMIZED) {
115 layout->at_x = header.x + (float)*layout->offset_x + style->tab.indent;
116 layout->bounds.w = NK_MAX(layout->bounds.w, style->tab.indent);
117 layout->bounds.w -= (style->tab.indent + style->window.padding.x);
118 layout->row.tree_depth++;
120 }
else return nk_false;
123 nk_tree_base(
struct nk_context *ctx,
enum nk_tree_type type,
124 struct nk_image *img,
const char *title,
enum nk_collapse_states initial_state,
125 const char *hash,
int len,
int line)
129 nk_hash tree_hash = 0;
134 title_len = (int)nk_strlen(title);
135 tree_hash = nk_murmur_hash(title, (
int)title_len, (nk_hash)line);
136 }
else tree_hash = nk_murmur_hash(hash, len, (nk_hash)line);
137 state = nk_find_value(win, tree_hash);
139 state = nk_add_value(ctx, win, tree_hash, 0);
140 *state = initial_state;
142 return nk_tree_state_base(ctx, type, img, title, (
enum nk_collapse_states*)state);
146 const char *title,
enum nk_collapse_states *state)
148 return nk_tree_state_base(ctx, type, 0, title, state);
152 struct nk_image img,
const char *title,
enum nk_collapse_states *state)
154 return nk_tree_state_base(ctx, type, &img, title, state);
163 NK_ASSERT(ctx->current);
164 NK_ASSERT(ctx->current->layout);
165 if (!ctx || !ctx->current || !ctx->current->layout)
169 layout = win->layout;
170 layout->at_x -= ctx->style.tab.indent + (float)*layout->offset_x;
171 layout->bounds.w += ctx->style.tab.indent + ctx->style.window.padding.x;
172 NK_ASSERT(layout->row.tree_depth);
173 layout->row.tree_depth--;
177 const char *title,
enum nk_collapse_states initial_state,
178 const char *hash,
int len,
int line)
180 return nk_tree_base(ctx, type, 0, title, initial_state, hash, len, line);
184 struct nk_image img,
const char *title,
enum nk_collapse_states initial_state,
185 const char *hash,
int len,
int seed)
187 return nk_tree_base(ctx, type, &img, title, initial_state, hash, len, seed);
195 nk_tree_element_image_push_hashed_base(
struct nk_context *ctx,
enum nk_tree_type type,
196 struct nk_image *img,
const char *title,
int title_len,
197 enum nk_collapse_states *state, nk_bool *selected)
205 enum nk_symbol_type symbol;
213 struct nk_rect header = {0,0,0,0};
214 struct nk_rect sym = {0,0,0,0};
220 NK_ASSERT(ctx->current);
221 NK_ASSERT(ctx->current->layout);
222 if (!ctx || !ctx->current || !ctx->current->layout)
227 layout = win->layout;
230 item_spacing = style->window.spacing;
231 padding = style->selectable.padding;
234 row_height = style->font->
height + 2 * style->tab.padding.y;
239 widget_state = nk_widget(&header, ctx);
240 if (type == NK_TREE_TAB) {
241 const struct nk_style_item *background = &style->tab.background;
243 switch (background->type) {
244 case NK_STYLE_ITEM_IMAGE:
245 nk_draw_image(out, header, &background->data.image, nk_rgb_factor(nk_white, style->tab.color_factor));
247 case NK_STYLE_ITEM_NINE_SLICE:
248 nk_draw_nine_slice(out, header, &background->data.slice, nk_rgb_factor(nk_white, style->tab.color_factor));
250 case NK_STYLE_ITEM_COLOR:
251 nk_fill_rect(out, header, 0, nk_rgb_factor(style->tab.border_color, style->tab.color_factor));
252 nk_fill_rect(out, nk_shrink_rect(header, style->tab.border),
253 style->tab.rounding, nk_rgb_factor(background->data.color, style->tab.color_factor));
263 if (*state == NK_MAXIMIZED) {
264 symbol = style->tab.sym_maximize;
265 if (type == NK_TREE_TAB)
266 button = &style->tab.tab_maximize_button;
267 else button = &style->tab.node_maximize_button;
269 symbol = style->tab.sym_minimize;
270 if (type == NK_TREE_TAB)
271 button = &style->tab.tab_minimize_button;
272 else button = &style->tab.node_minimize_button;
275 sym.w = sym.h = style->font->
height;
276 sym.y = header.y + style->tab.padding.y;
277 sym.x = header.x + style->tab.padding.x;
278 if (nk_do_button_symbol(&ws, &win->buffer, sym, symbol, NK_BUTTON_DEFAULT, button, in, style->font))
279 *state = (*state == NK_MAXIMIZED) ? NK_MINIMIZED : NK_MAXIMIZED;}
285 text_len = nk_strlen(title);
286 text_width = style->font->
width(style->font->userdata, style->font->
height, title, text_len);
287 text_width += (4 * padding.x);
289 header.w = NK_MAX(header.w, sym.w + item_spacing.x);
290 label.x = sym.x + sym.w + item_spacing.x;
292 label.w = NK_MIN(header.w - (sym.w + item_spacing.y + style->tab.indent), text_width);
293 label.h = style->font->
height;
296 nk_do_selectable_image(&dummy, &win->buffer, label, title, title_len, NK_TEXT_LEFT,
297 selected, img, &style->selectable, in, style->font);
298 }
else nk_do_selectable(&dummy, &win->buffer, label, title, title_len, NK_TEXT_LEFT,
299 selected, &style->selectable, in, style->font);
302 if (*state == NK_MAXIMIZED) {
303 layout->at_x = header.x + (float)*layout->offset_x + style->tab.indent;
304 layout->bounds.w = NK_MAX(layout->bounds.w, style->tab.indent);
305 layout->bounds.w -= (style->tab.indent + style->window.padding.x);
306 layout->row.tree_depth++;
308 }
else return nk_false;
311 nk_tree_element_base(
struct nk_context *ctx,
enum nk_tree_type type,
312 struct nk_image *img,
const char *title,
enum nk_collapse_states initial_state,
313 nk_bool *selected,
const char *hash,
int len,
int line)
317 nk_hash tree_hash = 0;
322 title_len = (int)nk_strlen(title);
323 tree_hash = nk_murmur_hash(title, (
int)title_len, (nk_hash)line);
324 }
else tree_hash = nk_murmur_hash(hash, len, (nk_hash)line);
325 state = nk_find_value(win, tree_hash);
327 state = nk_add_value(ctx, win, tree_hash, 0);
328 *state = initial_state;
329 }
return nk_tree_element_image_push_hashed_base(ctx, type, img, title,
330 nk_strlen(title), (
enum nk_collapse_states*)state, selected);
333 nk_tree_element_push_hashed(
struct nk_context *ctx,
enum nk_tree_type type,
334 const char *title,
enum nk_collapse_states initial_state,
335 nk_bool *selected,
const char *hash,
int len,
int seed)
337 return nk_tree_element_base(ctx, type, 0, title, initial_state, selected, hash, len, seed);
340 nk_tree_element_image_push_hashed(
struct nk_context *ctx,
enum nk_tree_type type,
341 struct nk_image img,
const char *title,
enum nk_collapse_states initial_state,
342 nk_bool *selected,
const char *hash,
int len,
int seed)
344 return nk_tree_element_base(ctx, type, &img, title, initial_state, selected, hash, len, seed);
main API and documentation file
NK_API void nk_tree_pop(struct nk_context *)
@ NK_WINDOW_ROM
sets window widgets into a read only mode and does not allow input changes
NK_API void nk_draw_image(struct nk_command_buffer *, struct nk_rect, const struct nk_image *, struct nk_color)
misc
NK_API nk_bool nk_tree_image_push_hashed(struct nk_context *, enum nk_tree_type, struct nk_image, const char *title, enum nk_collapse_states initial_state, const char *hash, int len, int seed)
NK_API void nk_fill_rect(struct nk_command_buffer *, struct nk_rect, float rounding, struct nk_color)
filled shades
NK_API nk_bool nk_tree_state_image_push(struct nk_context *, enum nk_tree_type, struct nk_image, const char *title, enum nk_collapse_states *state)
NK_API void nk_layout_row_dynamic(struct nk_context *ctx, float height, int cols)
Sets current row layout to share horizontal space between @cols number of widgets evenly.
NK_API void nk_layout_reset_min_row_height(struct nk_context *)
Reset the currently used minimum row height back to font_height + text_padding + padding
NK_API nk_bool nk_tree_state_push(struct nk_context *, enum nk_tree_type, const char *title, enum nk_collapse_states *state)
NK_API nk_bool nk_tree_push_hashed(struct nk_context *, enum nk_tree_type, const char *title, enum nk_collapse_states initial_state, const char *hash, int len, int seed)
NK_API void nk_layout_set_min_row_height(struct nk_context *, float height)
Sets the currently used minimum row height.
NK_API void nk_tree_state_pop(struct nk_context *)
@ NK_WIDGET_VALID
The widget is completely inside the window and can be updated and drawn.
nk_text_width_f width
!< max height of the font
float height
!< user provided font handle