2 #include "nuklear_internal.h"
16 NK_ASSERT(ctx->current);
17 NK_ASSERT(ctx->current->layout);
18 if (!ctx || !ctx->current || !ctx->current->layout)
23 layout->row.min_height = height;
32 NK_ASSERT(ctx->current);
33 NK_ASSERT(ctx->current->layout);
34 if (!ctx || !ctx->current || !ctx->current->layout)
39 layout->row.min_height = ctx->style.font->
height;
40 layout->row.min_height += ctx->style.text.padding.y*2;
41 layout->row.min_height += ctx->style.window.min_row_height_padding*2;
44 nk_layout_row_calculate_usable_space(
const struct nk_style *style,
enum nk_panel_type type,
45 float total_space,
int columns)
54 spacing = style->window.spacing;
57 panel_spacing = (float)NK_MAX(columns - 1, 0) * spacing.x;
58 panel_space = total_space - panel_spacing;
63 float height,
int cols)
73 NK_ASSERT(ctx->current);
74 NK_ASSERT(ctx->current->layout);
75 if (!ctx || !ctx->current || !ctx->current->layout)
82 color = style->window.background;
83 item_spacing = style->window.spacing;
95 layout->row.index = 0;
96 layout->at_y += layout->row.height;
97 layout->row.columns = cols;
99 layout->row.height = NK_MAX(height, layout->row.min_height) + item_spacing.y;
100 else layout->row.height = height + item_spacing.y;
102 layout->row.item_offset = 0;
106 background.x = win->bounds.x;
107 background.w = win->bounds.w;
108 background.y = layout->at_y - 1.0f;
109 background.h = layout->row.height + 1.0f;
115 float height,
int cols,
int width)
120 NK_ASSERT(ctx->current);
121 NK_ASSERT(ctx->current->layout);
122 if (!ctx || !ctx->current || !ctx->current->layout)
126 nk_panel_layout(ctx, win, height, cols);
127 if (fmt == NK_DYNAMIC)
128 win->layout->row.type = NK_LAYOUT_DYNAMIC_FIXED;
129 else win->layout->row.type = NK_LAYOUT_STATIC_FIXED;
131 win->layout->row.ratio = 0;
132 win->layout->row.filled = 0;
133 win->layout->row.item_offset = 0;
134 win->layout->row.item_width = (float)width;
141 NK_ASSERT(pixel_width);
142 if (!ctx || !ctx->current || !ctx->current->layout)
return 0;
144 return NK_CLAMP(0.0f, pixel_width/win->bounds.x, 1.0f);
158 float row_height,
int cols)
164 NK_ASSERT(ctx->current);
165 NK_ASSERT(ctx->current->layout);
166 if (!ctx || !ctx->current || !ctx->current->layout)
170 layout = win->layout;
171 nk_panel_layout(ctx, win, row_height, cols);
172 if (fmt == NK_DYNAMIC)
173 layout->row.type = NK_LAYOUT_DYNAMIC_ROW;
174 else layout->row.type = NK_LAYOUT_STATIC_ROW;
176 layout->row.ratio = 0;
177 layout->row.filled = 0;
178 layout->row.item_width = 0;
179 layout->row.item_offset = 0;
180 layout->row.columns = cols;
189 NK_ASSERT(ctx->current);
190 NK_ASSERT(ctx->current->layout);
191 if (!ctx || !ctx->current || !ctx->current->layout)
195 layout = win->layout;
196 NK_ASSERT(layout->row.type == NK_LAYOUT_STATIC_ROW || layout->row.type == NK_LAYOUT_DYNAMIC_ROW);
197 if (layout->row.type != NK_LAYOUT_STATIC_ROW && layout->row.type != NK_LAYOUT_DYNAMIC_ROW)
200 if (layout->row.type == NK_LAYOUT_DYNAMIC_ROW) {
201 float ratio = ratio_or_width;
202 if ((ratio + layout->row.filled) > 1.0f)
return;
204 layout->row.item_width = NK_SATURATE(ratio);
205 else layout->row.item_width = 1.0f - layout->row.filled;
206 }
else layout->row.item_width = ratio_or_width;
215 NK_ASSERT(ctx->current);
216 NK_ASSERT(ctx->current->layout);
217 if (!ctx || !ctx->current || !ctx->current->layout)
221 layout = win->layout;
222 NK_ASSERT(layout->row.type == NK_LAYOUT_STATIC_ROW || layout->row.type == NK_LAYOUT_DYNAMIC_ROW);
223 if (layout->row.type != NK_LAYOUT_STATIC_ROW && layout->row.type != NK_LAYOUT_DYNAMIC_ROW)
225 layout->row.item_width = 0;
226 layout->row.item_offset = 0;
230 float height,
int cols,
const float *ratio)
238 NK_ASSERT(ctx->current);
239 NK_ASSERT(ctx->current->layout);
240 if (!ctx || !ctx->current || !ctx->current->layout)
244 layout = win->layout;
245 nk_panel_layout(ctx, win, height, cols);
246 if (fmt == NK_DYNAMIC) {
249 layout->row.ratio = ratio;
250 for (i = 0; i < cols; ++i) {
255 r = NK_SATURATE(1.0f - r);
256 layout->row.type = NK_LAYOUT_DYNAMIC;
257 layout->row.item_width = (r > 0 && n_undef > 0) ? (r / (
float)n_undef):0;
259 layout->row.ratio = ratio;
260 layout->row.type = NK_LAYOUT_STATIC;
261 layout->row.item_width = 0;
262 layout->row.item_offset = 0;
264 layout->row.item_offset = 0;
265 layout->row.filled = 0;
274 NK_ASSERT(ctx->current);
275 NK_ASSERT(ctx->current->layout);
276 if (!ctx || !ctx->current || !ctx->current->layout)
280 layout = win->layout;
281 nk_panel_layout(ctx, win, height, 1);
282 layout->row.type = NK_LAYOUT_TEMPLATE;
283 layout->row.columns = 0;
284 layout->row.ratio = 0;
285 layout->row.item_width = 0;
286 layout->row.item_height = 0;
287 layout->row.item_offset = 0;
288 layout->row.filled = 0;
289 layout->row.item.x = 0;
290 layout->row.item.y = 0;
291 layout->row.item.w = 0;
292 layout->row.item.h = 0;
301 NK_ASSERT(ctx->current);
302 NK_ASSERT(ctx->current->layout);
303 if (!ctx || !ctx->current || !ctx->current->layout)
307 layout = win->layout;
308 NK_ASSERT(layout->row.type == NK_LAYOUT_TEMPLATE);
309 NK_ASSERT(layout->row.columns < NK_MAX_LAYOUT_ROW_TEMPLATE_COLUMNS);
310 if (layout->row.type != NK_LAYOUT_TEMPLATE)
return;
311 if (layout->row.columns >= NK_MAX_LAYOUT_ROW_TEMPLATE_COLUMNS)
return;
312 layout->row.templates[layout->row.columns++] = -1.0f;
321 NK_ASSERT(ctx->current);
322 NK_ASSERT(ctx->current->layout);
323 if (!ctx || !ctx->current || !ctx->current->layout)
327 layout = win->layout;
328 NK_ASSERT(layout->row.type == NK_LAYOUT_TEMPLATE);
329 NK_ASSERT(layout->row.columns < NK_MAX_LAYOUT_ROW_TEMPLATE_COLUMNS);
330 if (layout->row.type != NK_LAYOUT_TEMPLATE)
return;
331 if (layout->row.columns >= NK_MAX_LAYOUT_ROW_TEMPLATE_COLUMNS)
return;
332 layout->row.templates[layout->row.columns++] = -min_width;
341 NK_ASSERT(ctx->current);
342 NK_ASSERT(ctx->current->layout);
343 if (!ctx || !ctx->current || !ctx->current->layout)
347 layout = win->layout;
348 NK_ASSERT(layout->row.type == NK_LAYOUT_TEMPLATE);
349 NK_ASSERT(layout->row.columns < NK_MAX_LAYOUT_ROW_TEMPLATE_COLUMNS);
350 if (layout->row.type != NK_LAYOUT_TEMPLATE)
return;
351 if (layout->row.columns >= NK_MAX_LAYOUT_ROW_TEMPLATE_COLUMNS)
return;
352 layout->row.templates[layout->row.columns++] = width;
361 int variable_count = 0;
362 int min_variable_count = 0;
363 float min_fixed_width = 0.0f;
364 float total_fixed_width = 0.0f;
365 float max_variable_width = 0.0f;
368 NK_ASSERT(ctx->current);
369 NK_ASSERT(ctx->current->layout);
370 if (!ctx || !ctx->current || !ctx->current->layout)
374 layout = win->layout;
375 NK_ASSERT(layout->row.type == NK_LAYOUT_TEMPLATE);
376 if (layout->row.type != NK_LAYOUT_TEMPLATE)
return;
377 for (i = 0; i < layout->row.columns; ++i) {
378 float width = layout->row.templates[i];
380 total_fixed_width += width;
381 min_fixed_width += width;
382 }
else if (width < -1.0f) {
384 total_fixed_width += width;
385 max_variable_width = NK_MAX(max_variable_width, width);
388 min_variable_count++;
392 if (variable_count) {
393 float space = nk_layout_row_calculate_usable_space(&ctx->style, layout->type,
394 layout->bounds.w, layout->row.columns);
395 float var_width = (NK_MAX(space-min_fixed_width,0.0f)) / (
float)variable_count;
396 int enough_space = var_width >= max_variable_width;
398 var_width = (NK_MAX(space-total_fixed_width,0)) / (
float)min_variable_count;
399 for (i = 0; i < layout->row.columns; ++i) {
400 float *width = &layout->row.templates[i];
401 *width = (*width >= 0.0f)? *width: (*width < -1.0f && !enough_space)? -(*width): var_width;
407 float height,
int widget_count)
413 NK_ASSERT(ctx->current);
414 NK_ASSERT(ctx->current->layout);
415 if (!ctx || !ctx->current || !ctx->current->layout)
419 layout = win->layout;
420 nk_panel_layout(ctx, win, height, widget_count);
421 if (fmt == NK_STATIC)
422 layout->row.type = NK_LAYOUT_STATIC_FREE;
423 else layout->row.type = NK_LAYOUT_DYNAMIC_FREE;
425 layout->row.ratio = 0;
426 layout->row.filled = 0;
427 layout->row.item_width = 0;
428 layout->row.item_offset = 0;
437 NK_ASSERT(ctx->current);
438 NK_ASSERT(ctx->current->layout);
439 if (!ctx || !ctx->current || !ctx->current->layout)
443 layout = win->layout;
444 layout->row.item_width = 0;
445 layout->row.item_height = 0;
446 layout->row.item_offset = 0;
447 nk_zero(&layout->row.item,
sizeof(layout->row.item));
456 NK_ASSERT(ctx->current);
457 NK_ASSERT(ctx->current->layout);
458 if (!ctx || !ctx->current || !ctx->current->layout)
462 layout = win->layout;
463 layout->row.item = rect;
473 NK_ASSERT(ctx->current);
474 NK_ASSERT(ctx->current->layout);
476 layout = win->layout;
478 ret.x = layout->clip.x;
479 ret.y = layout->clip.y;
480 ret.w = layout->clip.w;
481 ret.h = layout->row.height;
492 NK_ASSERT(ctx->current);
493 NK_ASSERT(ctx->current->layout);
495 layout = win->layout;
497 ret.x = layout->at_x;
498 ret.y = layout->at_y;
499 ret.w = layout->bounds.w - NK_MAX(layout->at_x - layout->bounds.x,0);
500 ret.h = layout->row.height;
510 NK_ASSERT(ctx->current);
511 NK_ASSERT(ctx->current->layout);
513 layout = win->layout;
515 ret.x += layout->at_x - (float)*layout->offset_x;
516 ret.y += layout->at_y - (
float)*layout->offset_y;
526 NK_ASSERT(ctx->current);
527 NK_ASSERT(ctx->current->layout);
529 layout = win->layout;
531 ret.x += -layout->at_x + (float)*layout->offset_x;
532 ret.y += -layout->at_y + (
float)*layout->offset_y;
542 NK_ASSERT(ctx->current);
543 NK_ASSERT(ctx->current->layout);
545 layout = win->layout;
547 ret.x += layout->at_x - (float)*layout->offset_x;
548 ret.y += layout->at_y - (
float)*layout->offset_y;
558 NK_ASSERT(ctx->current);
559 NK_ASSERT(ctx->current->layout);
561 layout = win->layout;
563 ret.x += -layout->at_x + (float)*layout->offset_x;
564 ret.y += -layout->at_y + (
float)*layout->offset_y;
570 struct nk_panel *layout = win->layout;
571 struct nk_vec2 spacing = ctx->style.window.spacing;
572 const float row_height = layout->row.height - spacing.y;
573 nk_panel_layout(ctx, win, row_height, layout->row.columns);
584 float item_offset = 0;
585 float item_width = 0;
586 float item_spacing = 0;
587 float panel_space = 0;
590 NK_ASSERT(ctx->current);
591 NK_ASSERT(ctx->current->layout);
592 if (!ctx || !ctx->current || !ctx->current->layout)
596 layout = win->layout;
600 spacing = style->window.spacing;
601 panel_space = nk_layout_row_calculate_usable_space(&ctx->style, layout->type,
602 layout->bounds.w, layout->row.columns);
604 #define NK_FRAC(x) (x - (float)(int)nk_roundf(x))
606 switch (layout->row.type) {
607 case NK_LAYOUT_DYNAMIC_FIXED: {
609 float w = NK_MAX(1.0f,panel_space) / (float)layout->row.columns;
610 item_offset = (
float)layout->row.index * w;
611 item_width = w + NK_FRAC(item_offset);
612 item_spacing = (float)layout->row.index * spacing.x;
614 case NK_LAYOUT_DYNAMIC_ROW: {
616 float w = layout->row.item_width * panel_space;
617 item_offset = layout->row.item_offset;
618 item_width = w + NK_FRAC(item_offset);
622 layout->row.item_offset += w + spacing.x;
623 layout->row.filled += layout->row.item_width;
624 layout->row.index = 0;
627 case NK_LAYOUT_DYNAMIC_FREE: {
629 bounds->x = layout->at_x + (layout->bounds.w * layout->row.item.x);
630 bounds->x -= (float)*layout->offset_x;
631 bounds->y = layout->at_y + (layout->row.height * layout->row.item.y);
632 bounds->y -= (float)*layout->offset_y;
633 bounds->w = layout->bounds.w * layout->row.item.w + NK_FRAC(bounds->x);
634 bounds->h = layout->row.height * layout->row.item.h + NK_FRAC(bounds->y);
637 case NK_LAYOUT_DYNAMIC: {
640 NK_ASSERT(layout->row.ratio);
641 ratio = (layout->row.ratio[layout->row.index] < 0) ?
642 layout->row.item_width : layout->row.ratio[layout->row.index];
644 w = (ratio * panel_space);
645 item_spacing = (float)layout->row.index * spacing.x;
646 item_offset = layout->row.item_offset;
647 item_width = w + NK_FRAC(item_offset);
650 layout->row.item_offset += w;
651 layout->row.filled += ratio;
654 case NK_LAYOUT_STATIC_FIXED: {
656 item_width = layout->row.item_width;
657 item_offset = (float)layout->row.index * item_width;
658 item_spacing = (
float)layout->row.index * spacing.x;
660 case NK_LAYOUT_STATIC_ROW: {
662 item_width = layout->row.item_width;
663 item_offset = layout->row.item_offset;
664 item_spacing = (float)layout->row.index * spacing.x;
665 if (modify) layout->row.item_offset += item_width;
667 case NK_LAYOUT_STATIC_FREE: {
669 bounds->x = layout->at_x + layout->row.item.x;
670 bounds->w = layout->row.item.w;
671 if (((bounds->x + bounds->w) > layout->max_x) && modify)
672 layout->max_x = (bounds->x + bounds->w);
673 bounds->x -= (float)*layout->offset_x;
674 bounds->y = layout->at_y + layout->row.item.y;
675 bounds->y -= (
float)*layout->offset_y;
676 bounds->h = layout->row.item.h;
679 case NK_LAYOUT_STATIC: {
681 item_spacing = (float)layout->row.index * spacing.x;
682 item_width = layout->row.ratio[layout->row.index];
683 item_offset = layout->row.item_offset;
684 if (modify) layout->row.item_offset += item_width;
686 case NK_LAYOUT_TEMPLATE: {
689 NK_ASSERT(layout->row.index < layout->row.columns);
690 NK_ASSERT(layout->row.index < NK_MAX_LAYOUT_ROW_TEMPLATE_COLUMNS);
691 w = layout->row.templates[layout->row.index];
692 item_offset = layout->row.item_offset;
693 item_width = w + NK_FRAC(item_offset);
694 item_spacing = (float)layout->row.index * spacing.x;
695 if (modify) layout->row.item_offset += w;
698 default: NK_ASSERT(0);
break;
702 bounds->w = item_width;
703 bounds->h = layout->row.height - spacing.y;
704 bounds->y = layout->at_y - (float)*layout->offset_y;
705 bounds->x = layout->at_x + item_offset + item_spacing;
706 if (((bounds->x + bounds->w) > layout->max_x) && modify)
707 layout->max_x = bounds->x + bounds->w;
708 bounds->x -= (
float)*layout->offset_x;
717 NK_ASSERT(ctx->current);
718 NK_ASSERT(ctx->current->layout);
719 if (!ctx || !ctx->current || !ctx->current->layout)
724 layout = win->layout;
725 if (layout->row.index >= layout->row.columns)
726 nk_panel_alloc_row(ctx, win);
729 nk_layout_widget_space(bounds, ctx, win, nk_true);
741 NK_ASSERT(ctx->current);
742 NK_ASSERT(ctx->current->layout);
743 if (!ctx || !ctx->current || !ctx->current->layout) {
749 layout = win->layout;
751 index = layout->row.index;
752 if (layout->row.index >= layout->row.columns) {
753 layout->at_y += layout->row.height;
754 layout->row.index = 0;
756 nk_layout_widget_space(bounds, ctx, win, nk_false);
757 if (!layout->row.index) {
758 bounds->x -= layout->row.item_offset;
761 layout->row.index = index;
766 struct nk_rect dummy_rect = { 0, 0, 0, 0 };
767 nk_panel_alloc_space( &dummy_rect, ctx );
main API and documentation file
NK_API void nk_layout_row_end(struct nk_context *)
Finished previously started row.
NK_API void nk_spacer(struct nk_context *ctx)
NK_API void nk_layout_space_end(struct nk_context *)
@ NK_WINDOW_CLOSED
Directly closes and frees the window at the end of the frame.
@ NK_WINDOW_MINIMIZED
marks the window as minimized
@ NK_WINDOW_HIDDEN
Hides window and stops any window interaction and drawing.
@ NK_WINDOW_DYNAMIC
special window type growing up in height while being filled to a certain maximum height
NK_API void nk_layout_row(struct nk_context *, enum nk_layout_format, float height, int cols, const float *ratio)
Specifies row columns in array as either window ratio or size.
NK_API struct nk_vec2 nk_layout_space_to_screen(const struct nk_context *ctx, struct nk_vec2 vec)
NK_API void nk_layout_row_template_push_dynamic(struct nk_context *)
NK_API struct nk_vec2 nk_layout_space_to_local(const struct nk_context *ctx, struct nk_vec2 vec)
NK_API void nk_fill_rect(struct nk_command_buffer *, struct nk_rect, float rounding, struct nk_color)
filled shades
NK_API void nk_layout_row_template_push_static(struct nk_context *, float width)
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_row_template_end(struct nk_context *)
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 struct nk_rect nk_layout_space_rect_to_local(const struct nk_context *ctx, struct nk_rect bounds)
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_layout_row_begin(struct nk_context *ctx, enum nk_layout_format fmt, float row_height, int cols)
Starts a new dynamic or fixed row with given height and columns.
NK_API void nk_layout_space_push(struct nk_context *, struct nk_rect bounds)
NK_API void nk_layout_row_template_begin(struct nk_context *, float row_height)
NK_API float nk_layout_ratio_from_pixel(const struct nk_context *ctx, float pixel_width)
Utility functions to calculate window ratio from pixel size.
NK_API void nk_layout_row_push(struct nk_context *, float value)
\breif Specifies either window ratio or width of a single column
NK_API struct nk_rect nk_layout_widget_bounds(const struct nk_context *ctx)
Returns the width of the next row allocate by one of the layouting functions.
NK_API struct nk_rect nk_layout_space_rect_to_screen(const struct nk_context *ctx, struct nk_rect bounds)
NK_API void nk_layout_space_begin(struct nk_context *, enum nk_layout_format, float height, int widget_count)
NK_API struct nk_rect nk_layout_space_bounds(const struct nk_context *ctx)
NK_API void nk_layout_row_template_push_variable(struct nk_context *, float min_width)
NK_API void nk_layout_row_static(struct nk_context *ctx, float height, int item_width, int cols)
Sets current row layout to fill @cols number of widgets in row with same @item_width horizontal size.
float height
!< user provided font handle