updated examples to new font callback
This commit is contained in:
parent
c3f02270dd
commit
61a527f0d7
@ -616,14 +616,15 @@ file_browser_run(struct file_browser *browser, int width, int height)
|
|||||||
* APP
|
* APP
|
||||||
*
|
*
|
||||||
* ================================================================= */
|
* ================================================================= */
|
||||||
static zr_size
|
static size_t
|
||||||
font_get_width(zr_handle handle, const char *text, zr_size len)
|
font_get_width(zr_handle handle, float height, const char *text, size_t len)
|
||||||
{
|
{
|
||||||
zr_size width;
|
size_t width;
|
||||||
float bounds[4];
|
float bounds[4];
|
||||||
NVGcontext *ctx = (NVGcontext*)handle.ptr;
|
NVGcontext *ctx = (NVGcontext*)handle.ptr;
|
||||||
|
nvgFontSize(ctx, (float)height);
|
||||||
nvgTextBounds(ctx, 0, 0, text, &text[len], bounds);
|
nvgTextBounds(ctx, 0, 0, text, &text[len], bounds);
|
||||||
width = (zr_size)(bounds[2] - bounds[0]);
|
width = (size_t)(bounds[2] - bounds[0]);
|
||||||
return width;
|
return width;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -700,6 +701,7 @@ draw(NVGcontext *nvg, struct zr_command_queue *queue, int width, int height)
|
|||||||
nvgBeginPath(nvg);
|
nvgBeginPath(nvg);
|
||||||
nvgFillColor(nvg, nvgRGBA(t->foreground.r, t->foreground.g,
|
nvgFillColor(nvg, nvgRGBA(t->foreground.r, t->foreground.g,
|
||||||
t->foreground.b, t->foreground.a));
|
t->foreground.b, t->foreground.a));
|
||||||
|
nvgFontSize(nvg, (float)t->height);
|
||||||
nvgTextAlign(nvg, NVG_ALIGN_MIDDLE);
|
nvgTextAlign(nvg, NVG_ALIGN_MIDDLE);
|
||||||
nvgText(nvg, t->x, t->y + t->h * 0.5f, t->string, &t->string[t->length]);
|
nvgText(nvg, t->x, t->y + t->h * 0.5f, t->string, &t->string[t->length]);
|
||||||
nvgFill(nvg);
|
nvgFill(nvg);
|
||||||
@ -829,7 +831,7 @@ main(int argc, char *argv[])
|
|||||||
if (!vg) die("[NVG]: failed to init\n");
|
if (!vg) die("[NVG]: failed to init\n");
|
||||||
nvgCreateFont(vg, "fixed", font_path);
|
nvgCreateFont(vg, "fixed", font_path);
|
||||||
nvgFontFace(vg, "fixed");
|
nvgFontFace(vg, "fixed");
|
||||||
nvgFontSize(vg, 10);
|
nvgFontSize(vg, 14);
|
||||||
nvgTextAlign(vg, NVG_ALIGN_LEFT|NVG_ALIGN_MIDDLE);
|
nvgTextAlign(vg, NVG_ALIGN_LEFT|NVG_ALIGN_MIDDLE);
|
||||||
|
|
||||||
/* GUI */
|
/* GUI */
|
||||||
|
@ -435,14 +435,15 @@ die(const char *fmt, ...)
|
|||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
static zr_size
|
static size_t
|
||||||
font_get_width(zr_handle handle, const char *text, zr_size len)
|
font_get_width(zr_handle handle, float height, const char *text, size_t len)
|
||||||
{
|
{
|
||||||
zr_size width;
|
size_t width;
|
||||||
float bounds[4];
|
float bounds[4];
|
||||||
NVGcontext *ctx = (NVGcontext*)handle.ptr;
|
NVGcontext *ctx = (NVGcontext*)handle.ptr;
|
||||||
|
nvgFontSize(ctx, (float)height);
|
||||||
nvgTextBounds(ctx, 0, 0, text, &text[len], bounds);
|
nvgTextBounds(ctx, 0, 0, text, &text[len], bounds);
|
||||||
width = (zr_size)(bounds[2] - bounds[0]);
|
width = (size_t)(bounds[2] - bounds[0]);
|
||||||
return width;
|
return width;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -519,6 +520,7 @@ draw(NVGcontext *nvg, struct zr_command_queue *queue, int width, int height)
|
|||||||
nvgBeginPath(nvg);
|
nvgBeginPath(nvg);
|
||||||
nvgFillColor(nvg, nvgRGBA(t->foreground.r, t->foreground.g,
|
nvgFillColor(nvg, nvgRGBA(t->foreground.r, t->foreground.g,
|
||||||
t->foreground.b, t->foreground.a));
|
t->foreground.b, t->foreground.a));
|
||||||
|
nvgFontSize(nvg, (float)t->height);
|
||||||
nvgTextAlign(nvg, NVG_ALIGN_MIDDLE);
|
nvgTextAlign(nvg, NVG_ALIGN_MIDDLE);
|
||||||
nvgText(nvg, t->x, t->y + t->h * 0.5f, t->string, &t->string[t->length]);
|
nvgText(nvg, t->x, t->y + t->h * 0.5f, t->string, &t->string[t->length]);
|
||||||
nvgFill(nvg);
|
nvgFill(nvg);
|
||||||
@ -627,7 +629,7 @@ main(int argc, char *argv[])
|
|||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
font_path = argv[1];
|
font_path = argv[1];
|
||||||
font_height = 12;
|
font_height = 14;
|
||||||
|
|
||||||
/* SDL */
|
/* SDL */
|
||||||
SDL_Init(SDL_INIT_VIDEO|SDL_INIT_TIMER|SDL_INIT_EVENTS);
|
SDL_Init(SDL_INIT_VIDEO|SDL_INIT_TIMER|SDL_INIT_EVENTS);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user