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);
22 label.x = 0; label.w = 0;
23 label.y = b.y + t->padding.y;
24 label.h = NK_MIN(f->
height, b.h - 2 * t->padding.y);
26 text_width = f->
width(f->userdata, f->
height, (
const char*)
string, len);
27 text_width += (2.0f * t->padding.x);
30 if (a & NK_TEXT_ALIGN_LEFT) {
31 label.x = b.x + t->padding.x;
32 label.w = NK_MAX(0, b.w - 2 * t->padding.x);
33 }
else if (a & NK_TEXT_ALIGN_CENTERED) {
34 label.w = NK_MAX(1, 2 * t->padding.x + (
float)text_width);
35 label.x = (b.x + t->padding.x + ((b.w - 2 * t->padding.x) - label.w) / 2);
36 label.x = NK_MAX(b.x + t->padding.x, label.x);
37 label.w = NK_MIN(b.x + b.w, label.x + label.w);
38 if (label.w >= label.x) label.w -= label.x;
39 }
else if (a & NK_TEXT_ALIGN_RIGHT) {
40 label.x = NK_MAX(b.x + t->padding.x, (b.x + b.w) - (2 * t->padding.x + (
float)text_width));
41 label.w = (float)text_width + 2 * t->padding.x;
45 if (a & NK_TEXT_ALIGN_MIDDLE) {
46 label.y = b.y + b.h/2.0f - (float)f->
height/2.0f;
47 label.h = NK_MAX(b.h/2.0f, b.h - (b.h/2.0f + f->
height/2.0f));
48 }
else if (a & NK_TEXT_ALIGN_BOTTOM) {
49 label.y = b.y + b.h - f->
height;
52 nk_draw_text(o, label, (
const char*)
string, len, f, t->background, t->text);
56 const char *
string,
int len,
const struct nk_text *t,
65 NK_INTERN nk_rune seperator[] = {
' '};
72 text.background = t->background;
75 b.w = NK_MAX(b.w, 2 * t->padding.x);
76 b.h = NK_MAX(b.h, 2 * t->padding.y);
77 b.h = b.h - 2 * t->padding.y;
79 line.x = b.x + t->padding.x;
80 line.y = b.y + t->padding.y;
81 line.w = b.w - 2 * t->padding.x;
82 line.h = 2 * t->padding.y + f->
height;
84 fitting = nk_text_clamp(f,
string, len, line.w, &glyphs, &width, seperator,NK_LEN(seperator));
86 if (!fitting || line.y + line.h >= (b.y + b.h))
break;
87 nk_widget_text(o, line, &
string[done], fitting, &text, NK_TEXT_LEFT, f);
89 line.y += f->
height + 2 * t->padding.y;
90 fitting = nk_text_clamp(f, &
string[done], len - done, line.w, &glyphs, &width, seperator,NK_LEN(seperator));
94nk_text_colored(
struct nk_context *ctx,
const char *str,
int len,
95 nk_flags alignment,
struct nk_color color)
105 NK_ASSERT(ctx->current);
106 NK_ASSERT(ctx->current->layout);
107 if (!ctx || !ctx->current || !ctx->current->layout)
return;
111 nk_panel_alloc_space(&bounds, ctx);
112 item_padding = style->text.padding;
114 text.padding.x = item_padding.x;
115 text.padding.y = item_padding.y;
116 text.background = style->window.background;
117 text.text = nk_rgb_factor(color, style->text.color_factor);
118 nk_widget_text(&win->buffer, bounds, str, len, &text, alignment, style->font);
121nk_text_wrap_colored(
struct nk_context *ctx,
const char *str,
132 NK_ASSERT(ctx->current);
133 NK_ASSERT(ctx->current->layout);
134 if (!ctx || !ctx->current || !ctx->current->layout)
return;
138 nk_panel_alloc_space(&bounds, ctx);
139 item_padding = style->text.padding;
141 text.padding.x = item_padding.x;
142 text.padding.y = item_padding.y;
143 text.background = style->window.background;
144 text.text = nk_rgb_factor(color, style->text.color_factor);
145 nk_widget_text_wrap(&win->buffer, bounds, str, len, &text, style->font);
147#ifdef NK_INCLUDE_STANDARD_VARARGS
149nk_labelf_colored(
struct nk_context *ctx, nk_flags flags,
150 struct nk_color color,
const char *fmt, ...)
154 nk_labelfv_colored(ctx, flags, color, fmt, args);
159 const char *fmt, ...)
163 nk_labelfv_colored_wrap(ctx, color, fmt, args);
167nk_labelf(
struct nk_context *ctx, nk_flags flags,
const char *fmt, ...)
171 nk_labelfv(ctx, flags, fmt, args);
175nk_labelf_wrap(
struct nk_context *ctx,
const char *fmt,...)
179 nk_labelfv_wrap(ctx, fmt, args);
183nk_labelfv_colored(
struct nk_context *ctx, nk_flags flags,
184 struct nk_color color,
const char *fmt, va_list args)
187 nk_strfmt(buf, NK_LEN(buf), fmt, args);
188 nk_label_colored(ctx, buf, flags, color);
193 const char *fmt, va_list args)
196 nk_strfmt(buf, NK_LEN(buf), fmt, args);
197 nk_label_colored_wrap(ctx, buf, color);
201nk_labelfv(
struct nk_context *ctx, nk_flags flags,
const char *fmt, va_list args)
204 nk_strfmt(buf, NK_LEN(buf), fmt, args);
205 nk_label(ctx, buf, flags);
209nk_labelfv_wrap(
struct nk_context *ctx,
const char *fmt, va_list args)
212 nk_strfmt(buf, NK_LEN(buf), fmt, args);
213 nk_label_wrap(ctx, buf);
217nk_value_bool(
struct nk_context *ctx,
const char *prefix,
int value)
219 nk_labelf(ctx, NK_TEXT_LEFT,
"%s: %s", prefix, ((value) ?
"true":
"false"));
222nk_value_int(
struct nk_context *ctx,
const char *prefix,
int value)
224 nk_labelf(ctx, NK_TEXT_LEFT,
"%s: %d", prefix, value);
227nk_value_uint(
struct nk_context *ctx,
const char *prefix,
unsigned int value)
229 nk_labelf(ctx, NK_TEXT_LEFT,
"%s: %u", prefix, value);
232nk_value_float(
struct nk_context *ctx,
const char *prefix,
float value)
234 double double_value = (double)value;
235 nk_labelf(ctx, NK_TEXT_LEFT,
"%s: %.3f", prefix, double_value);
240 nk_labelf(ctx, NK_TEXT_LEFT,
"%s: (%d, %d, %d, %d)", p, c.r, c.g, c.b, c.a);
245 double c[4]; nk_color_dv(c, color);
246 nk_labelf(ctx, NK_TEXT_LEFT,
"%s: (%.2f, %.2f, %.2f, %.2f)",
247 p, c[0], c[1], c[2], c[3]);
253 nk_color_hex_rgba(hex, color);
254 nk_labelf(ctx, NK_TEXT_LEFT,
"%s: %s", prefix, hex);
262 nk_text_colored(ctx, str, len, alignment, ctx->style.text.color);
265nk_text_wrap(
struct nk_context *ctx,
const char *str,
int len)
269 nk_text_wrap_colored(ctx, str, len, ctx->style.text.color);
272nk_label(
struct nk_context *ctx,
const char *str, nk_flags alignment)
274 nk_text(ctx, str, nk_strlen(str), alignment);
277nk_label_colored(
struct nk_context *ctx,
const char *str, nk_flags align,
280 nk_text_colored(ctx, str, nk_strlen(str), align, color);
283nk_label_wrap(
struct nk_context *ctx,
const char *str)
285 nk_text_wrap(ctx, str, nk_strlen(str));
290 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