2#include "nuklear_internal.h"
11 const char *
string,
int len,
const struct nk_text *t,
21 b.h = NK_MAX(b.h, 2 * t->padding.y);
23 text_width = f->
width(f->userdata, f->
height, (
const char*)
string, len);
24 text_width += (2.0f * t->padding.x);
27 if (!(a & (NK_TEXT_ALIGN_LEFT | NK_TEXT_ALIGN_CENTERED | NK_TEXT_ALIGN_RIGHT)))
28 a |= NK_TEXT_ALIGN_LEFT;
29 if (!(a & (NK_TEXT_ALIGN_TOP | NK_TEXT_ALIGN_MIDDLE | NK_TEXT_ALIGN_BOTTOM)))
30 a |= NK_TEXT_ALIGN_TOP;
33 if (a & NK_TEXT_ALIGN_LEFT) {
34 label.x = b.x + t->padding.x;
35 label.w = NK_MAX(0, b.w - 2 * t->padding.x);
36 }
else if (a & NK_TEXT_ALIGN_CENTERED) {
37 label.w = NK_MAX(1, 2 * t->padding.x + (
float)text_width);
38 label.x = (b.x + t->padding.x + ((b.w - 2 * t->padding.x) - label.w) / 2);
39 label.x = NK_MAX(b.x + t->padding.x, label.x);
40 label.w = NK_MIN(b.x + b.w, label.x + label.w);
41 if (label.w >= label.x) label.w -= label.x;
42 }
else if (a & NK_TEXT_ALIGN_RIGHT) {
43 label.x = NK_MAX(b.x + t->padding.x, (b.x + b.w) - (2 * t->padding.x + (
float)text_width));
44 label.w = (float)text_width + 2 * t->padding.x;
48 if (a & NK_TEXT_ALIGN_TOP) {
49 label.y = b.y + t->padding.y;
50 label.h = NK_MIN(f->
height, b.h - 2 * t->padding.y);
51 }
else if (a & NK_TEXT_ALIGN_MIDDLE) {
52 label.y = b.y + b.h/2.0f - (float)f->
height/2.0f;
53 label.h = NK_MAX(b.h/2.0f, b.h - (b.h/2.0f + f->
height/2.0f));
54 }
else if (a & NK_TEXT_ALIGN_BOTTOM) {
55 label.y = b.y + b.h - f->
height;
59 nk_draw_text(o, label, (
const char*)
string, len, f, t->background, t->text);
63 const char *
string,
int len,
const struct nk_text *t,
72 NK_INTERN nk_rune seperator[] = {
' '};
79 text.background = t->background;
82 b.w = NK_MAX(b.w, 2 * t->padding.x);
83 b.h = NK_MAX(b.h, 2 * t->padding.y);
84 b.h = b.h - 2 * t->padding.y;
86 line.x = b.x + t->padding.x;
87 line.y = b.y + t->padding.y;
88 line.w = b.w - 2 * t->padding.x;
89 line.h = 2 * t->padding.y + f->
height;
91 fitting = nk_text_clamp(f,
string, len, line.w, &glyphs, &width, seperator,NK_LEN(seperator));
93 if (!fitting || line.y + line.h >= (b.y + b.h))
break;
94 nk_widget_text(o, line, &
string[done], fitting, &text, NK_TEXT_LEFT, f);
96 line.y += f->
height + 2 * t->padding.y;
97 fitting = nk_text_clamp(f, &
string[done], len - done, line.w, &glyphs, &width, seperator,NK_LEN(seperator));
101nk_text_colored(
struct nk_context *ctx,
const char *str,
int len,
102 nk_flags alignment,
struct nk_color color)
112 NK_ASSERT(ctx->current);
113 NK_ASSERT(ctx->current->layout);
114 if (!ctx || !ctx->current || !ctx->current->layout)
return;
118 nk_panel_alloc_space(&bounds, ctx);
119 item_padding = style->text.padding;
121 text.padding.x = item_padding.x;
122 text.padding.y = item_padding.y;
123 text.background = style->window.background;
124 text.text = nk_rgb_factor(color, style->text.color_factor);
125 nk_widget_text(&win->buffer, bounds, str, len, &text, alignment, style->font);
128nk_text_wrap_colored(
struct nk_context *ctx,
const char *str,
139 NK_ASSERT(ctx->current);
140 NK_ASSERT(ctx->current->layout);
141 if (!ctx || !ctx->current || !ctx->current->layout)
return;
145 nk_panel_alloc_space(&bounds, ctx);
146 item_padding = style->text.padding;
148 text.padding.x = item_padding.x;
149 text.padding.y = item_padding.y;
150 text.background = style->window.background;
151 text.text = nk_rgb_factor(color, style->text.color_factor);
152 nk_widget_text_wrap(&win->buffer, bounds, str, len, &text, style->font);
154#ifdef NK_INCLUDE_STANDARD_VARARGS
156nk_labelf_colored(
struct nk_context *ctx, nk_flags flags,
157 struct nk_color color,
const char *fmt, ...)
161 nk_labelfv_colored(ctx, flags, color, fmt, args);
166 const char *fmt, ...)
170 nk_labelfv_colored_wrap(ctx, color, fmt, args);
174nk_labelf(
struct nk_context *ctx, nk_flags flags,
const char *fmt, ...)
178 nk_labelfv(ctx, flags, fmt, args);
182nk_labelf_wrap(
struct nk_context *ctx,
const char *fmt,...)
186 nk_labelfv_wrap(ctx, fmt, args);
190nk_labelfv_colored(
struct nk_context *ctx, nk_flags flags,
191 struct nk_color color,
const char *fmt, va_list args)
194 nk_strfmt(buf, NK_LEN(buf), fmt, args);
195 nk_label_colored(ctx, buf, flags, color);
200 const char *fmt, va_list args)
203 nk_strfmt(buf, NK_LEN(buf), fmt, args);
204 nk_label_colored_wrap(ctx, buf, color);
208nk_labelfv(
struct nk_context *ctx, nk_flags flags,
const char *fmt, va_list args)
211 nk_strfmt(buf, NK_LEN(buf), fmt, args);
212 nk_label(ctx, buf, flags);
216nk_labelfv_wrap(
struct nk_context *ctx,
const char *fmt, va_list args)
219 nk_strfmt(buf, NK_LEN(buf), fmt, args);
220 nk_label_wrap(ctx, buf);
224nk_value_bool(
struct nk_context *ctx,
const char *prefix,
int value)
226 nk_labelf(ctx, NK_TEXT_LEFT,
"%s: %s", prefix, ((value) ?
"true":
"false"));
229nk_value_int(
struct nk_context *ctx,
const char *prefix,
int value)
231 nk_labelf(ctx, NK_TEXT_LEFT,
"%s: %d", prefix, value);
234nk_value_uint(
struct nk_context *ctx,
const char *prefix,
unsigned int value)
236 nk_labelf(ctx, NK_TEXT_LEFT,
"%s: %u", prefix, value);
239nk_value_float(
struct nk_context *ctx,
const char *prefix,
float value)
241 double double_value = (double)value;
242 nk_labelf(ctx, NK_TEXT_LEFT,
"%s: %.3f", prefix, double_value);
247 nk_labelf(ctx, NK_TEXT_LEFT,
"%s: (%d, %d, %d, %d)", p, c.r, c.g, c.b, c.a);
252 double c[4]; nk_color_dv(c, color);
253 nk_labelf(ctx, NK_TEXT_LEFT,
"%s: (%.2f, %.2f, %.2f, %.2f)",
254 p, c[0], c[1], c[2], c[3]);
260 nk_color_hex_rgba(hex, color);
261 nk_labelf(ctx, NK_TEXT_LEFT,
"%s: %s", prefix, hex);
269 nk_text_colored(ctx, str, len, alignment, ctx->style.text.color);
272nk_text_wrap(
struct nk_context *ctx,
const char *str,
int len)
276 nk_text_wrap_colored(ctx, str, len, ctx->style.text.color);
279nk_label(
struct nk_context *ctx,
const char *str, nk_flags alignment)
281 nk_text(ctx, str, nk_strlen(str), alignment);
284nk_label_colored(
struct nk_context *ctx,
const char *str, nk_flags align,
287 nk_text_colored(ctx, str, nk_strlen(str), align, color);
290nk_label_wrap(
struct nk_context *ctx,
const char *str)
292 nk_text_wrap(ctx, str, nk_strlen(str));
297 nk_text_wrap_colored(ctx, str, nk_strlen(str), color);
main API and documentation file
nk_text_width_f width
!< max height of the font
float height
!< user provided font handle