-
Notifications
You must be signed in to change notification settings - Fork 0
/
ui_util.cpp
441 lines (381 loc) · 18.8 KB
/
ui_util.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
/*
* Copyright (c) Adubbz
* Copyright (c) Ixaruz
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, or any later version, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "ui_util.hpp"
#include <stdio.h>
#include <cstring>
#include <math.h>
#include <vector>
namespace dbk {
namespace {
constexpr const char *SwitchStandardFont = "switch-standard";
constexpr const char *SwitchExtFont = "switch-ext";
constexpr float WindowCornerRadius = 10.0f;
constexpr float TextAreaCornerRadius = 10.0f;
constexpr float ButtonCornerRaidus = 6.0f;
float g_progress = 0;
std::vector<int>g_image_handle;
unsigned char *gif = nullptr;
int g_gif_w, g_gif_h, g_gif_frames;
static int g_framecounter = 0;
NVGcolor GetSelectionRGB2(u64 ns) {
/* Calculate the rgb values for the breathing colour effect. */
const double t = static_cast<double>(ns) / 1'000'000'000.0d;
const float d = -0.5 * cos(3.0f*t) + 0.5f;
const int r2 = 79 + (float)(180 - 79) * (d * 0.7f + 0.3f);
const int g2 = 55 + (float)(126 - 55) * (d * 0.7f + 0.3f);
const int b2 = 128 + (float)(230 - 128) * (d * 0.7f + 0.3f);
return nvgRGB(r2, g2, b2);
}
}
void DrawStar(NVGcontext *vg, float w, float h, float x, float y, float width, float luminosity) {
/*
nvgBeginPath(vg);
nvgRect(vg, 0, 0, w, h);
nvgFillPaint(vg, nvgRadialGradient(vg, x, y, 0, width * 3.0f, nvgRGBA(160, 255, 255, 80 + luminosity * 80), nvgRGBA(0, 0, 0, 0)));
nvgFill(vg);
*/
nvgBeginPath(vg);
nvgEllipse(vg, x, y, width, width * 3.0f);
nvgEllipse(vg, x, y, width * 3.0f, width);
nvgFillColor(vg, nvgRGBA(205, 255, 255, 100 + luminosity * 40));
nvgFill(vg);
}
void DrawBackground(NVGcontext *vg, float w, float h, u64 ns) {
/* Draw the background gradient. */
const NVGpaint bg_paint = nvgLinearGradient(vg, w / 2.0f, 0, w / 2.0f, h, nvgRGB(26, 34, 109), nvgRGB(84, 121, 196));
nvgBeginPath(vg);
nvgRect(vg, 0, 0, w, h);
nvgFillPaint(vg, bg_paint);
nvgFill(vg);
nvgBeginPath(vg);
nvgRect(vg, 0, 0, w, h);
//the first multiplier of the cosine is the deviation, the + at the end is the "mean"
float outr = w * (-0.125f * cos(ns / 1'000'000'000.0d) + 0.7f);
nvgFillPaint(vg, nvgRadialGradient(vg, w / 2.0f, h + (h * 0.1f), 10, outr, nvgRGBA(248, 95, 240, 170), nvgRGBA(0, 0, 0, 0)));
nvgFill(vg);
/*
float fontsize = 28.0f;
nvgFontSize(vg, fontsize);
nvgAddFallbackFont(vg, SwitchStandardFont, SwitchExtFont);
nvgTextAlign(vg, NVG_ALIGN_RIGHT | NVG_ALIGN_BOTTOM);
nvgFillColor(vg, nvgRGBA(255, 255, 255, 128));
nvgText(vg, w - 20.0f, h - 10.0f, (std::string("Luna ") + std::string(STRING_VERSION)).c_str(), nullptr);
*/
}
void DrawWindow(NVGcontext *vg, const char *title, float x, float y, float w, float h) {
/* Draw the window background. */
const NVGpaint window_bg_paint = nvgLinearGradient(vg, x + w / 2.0f, y, x + w / 2.0f, y + h + h / 4.0f, nvgRGB(255, 255, 255), nvgRGB(216, 210, 247));
nvgBeginPath(vg);
nvgRoundedRect(vg, x, y, w, h, WindowCornerRadius);
nvgFillPaint(vg, window_bg_paint);
nvgFill(vg);
/* Draw the shadow surrounding the window. */
NVGpaint shadowPaint = nvgBoxGradient(vg, x, y + 2, w, h, WindowCornerRadius * 1.2f, 10, nvgRGBA(0, 0, 0, 128), nvgRGBA(0, 0, 0, 0));
nvgBeginPath(vg);
nvgRect(vg, x - 10, y - 10, w + 20, h + 30);
nvgRoundedRect(vg, x, y, w, h, WindowCornerRadius);
nvgPathWinding(vg, NVG_HOLE);
nvgFillPaint(vg, shadowPaint);
nvgFill(vg);
/* Setup the font. */
nvgFontSize(vg, 32.0f);
nvgAddFallbackFont(vg, SwitchStandardFont, SwitchExtFont);
nvgTextAlign(vg, NVG_ALIGN_LEFT | NVG_ALIGN_MIDDLE);
nvgFillColor(vg, nvgRGB(0, 0, 0));
/* Draw the title. */
const float tw = nvgTextBounds(vg, 0, 0, title, nullptr, nullptr);
nvgText(vg, x + w * 0.5f - tw * 0.5f, y + 40.0f, title, nullptr);
}
void DrawDumpWindow(NVGcontext* vg, const char* title, float x, float y, float w, float h, float box_x, float box_y, float box_w, float box_h, float prog_x, float prog_y, float prog_w, float prog_h, float progress, u64 ns)
{
/* Draw the window background. */
const NVGpaint window_bg_paint = nvgLinearGradient(vg, x + w / 2.0f, y, x + w / 2.0f, y + h + h / 4.0f, nvgRGB(255, 255, 255), nvgRGB(216, 210, 247));
nvgBeginPath(vg);
nvgRoundedRect(vg, x, y, w, h, WindowCornerRadius);
nvgFillPaint(vg, window_bg_paint);
/* log box */
nvgRoundedRect(vg, box_x, box_y, box_w, box_h, TextAreaCornerRadius * 1.2f);
nvgPathWinding(vg, NVG_HOLE);
/*progess bar */
nvgRoundedRect(vg, prog_x, prog_y, prog_w, prog_h, WindowCornerRadius * 2);
nvgPathWinding(vg, NVG_HOLE);
nvgFill(vg);
/* Draw the shadow surrounding the window. */
NVGpaint shadowPaint = nvgBoxGradient(vg, x, y + 2, w, h, WindowCornerRadius * 2 * 1.2f, 10, nvgRGBA(0, 0, 0, 128), nvgRGBA(0, 0, 0, 0));
nvgBeginPath(vg);
nvgRect(vg, x - 10, y - 10, w + 20, h + 30);
nvgRoundedRect(vg, x, y, w, h, WindowCornerRadius);
nvgPathWinding(vg, NVG_HOLE);
nvgFillPaint(vg, shadowPaint);
nvgFill(vg);
/* Draw the shadow inside the window. */
shadowPaint = nvgBoxGradient(vg, box_x, box_y + 2, box_w, box_h, TextAreaCornerRadius, 10, nvgRGBA(0, 0, 0, 0), nvgRGBA(0, 0, 0, 180));
nvgBeginPath(vg);
nvgRoundedRect(vg, box_x, box_y, box_w, box_h, TextAreaCornerRadius);
nvgFillPaint(vg, shadowPaint);
nvgFill(vg);
/* log box background */
nvgBeginPath(vg);
nvgRoundedRect(vg, box_x, box_y, box_w, box_h, TextAreaCornerRadius);
nvgFillPaint(vg, nvgLinearGradient(vg, box_x + box_w / 2.0f, box_y, box_x + box_w / 2.0f, box_y + box_h, nvgRGBA(255, 255, 255, 220), nvgRGBA(242, 245, 255, 190)));
nvgFill(vg);
/* progess bar background */
nvgBeginPath(vg);
nvgRoundedRect(vg, prog_x, prog_y, prog_w, prog_h, WindowCornerRadius * 2 * 0.8f);
nvgFillColor(vg, nvgRGBA(255, 255, 255, 220));
nvgFill(vg);
/* Setup the font. */
nvgFontSize(vg, 32.0f);
nvgAddFallbackFont(vg, SwitchStandardFont, SwitchExtFont);
nvgTextAlign(vg, NVG_ALIGN_LEFT | NVG_ALIGN_MIDDLE);
nvgFillColor(vg, nvgRGB(0, 0, 0));
/* Draw the title. */
const float tw = nvgTextBounds(vg, 0, 0, title, nullptr, nullptr);
nvgText(vg, x + w * 0.5f - tw * 0.5f, y + 40.0f, title, nullptr);
/* Draw the progress bar fill. */
if (progress > 0.0f) {
g_progress += (progress - g_progress) * 0.1f;
NVGpaint progress_fill_paint = nvgLinearGradient(vg, prog_x, prog_y + 0.5f * prog_h, prog_x + prog_w * g_progress, prog_y + 0.5f * prog_h, nvgRGB(46, 64, 139), GetSelectionRGB2(ns));
nvgBeginPath(vg);
nvgRoundedRect(vg, prog_x, prog_y, WindowCornerRadius * 2 + (prog_w - WindowCornerRadius * 2) * g_progress, prog_h, WindowCornerRadius * 2);
nvgFillPaint(vg, progress_fill_paint);
nvgFill(vg);
}
}
void DrawAlertWindow(NVGcontext* vg, const char* title, float x, float y, float w, float h) {
/* Draw the window background. */
const NVGpaint window_bg_paint = nvgLinearGradient(vg, x + w / 2.0f, y, x + w / 2.0f, y + h + h / 4.0f, nvgRGB(255, 255, 255), nvgRGB(247, 210, 245));
nvgBeginPath(vg);
nvgRoundedRect(vg, x, y, w, h, WindowCornerRadius);
nvgFillPaint(vg, window_bg_paint);
nvgFill(vg);
/* Draw the shadow surrounding the window. */
NVGpaint shadowPaint = nvgBoxGradient(vg, x, y + 2, w, h, WindowCornerRadius * 2, 10, nvgRGBA(0, 0, 0, 128), nvgRGBA(0, 0, 0, 0));
nvgBeginPath(vg);
nvgRect(vg, x - 10, y - 10, w + 20, h + 30);
nvgRoundedRect(vg, x, y, w, h, WindowCornerRadius);
nvgPathWinding(vg, NVG_HOLE);
nvgFillPaint(vg, shadowPaint);
nvgFill(vg);
/* Setup the font. */
nvgFontSize(vg, 50.0f);
nvgAddFallbackFont(vg, SwitchStandardFont, SwitchExtFont);
nvgTextAlign(vg, NVG_ALIGN_LEFT | NVG_ALIGN_MIDDLE);
nvgFillColor(vg, nvgRGBA(46, 64, 139, 170));
/* Draw the title. */
const float tw = nvgTextBounds(vg, 0, 0, title, nullptr, nullptr);
nvgText(vg, x + w * 0.5f - tw * 0.5f, y + 45.0f, title, nullptr);
}
void DrawButton(NVGcontext *vg, const char *text, float x, float y, float w, float h, ButtonStyle style, u64 ns, float fontsize) {
/* Fill the background if selected. */
if (style == ButtonStyle::StandardSelected || style == ButtonStyle::FileSelectSelected) {
NVGpaint bg_paint = nvgLinearGradient(vg, x, y + h / 2.0f, x + w, y + h / 2.0f, nvgRGB(46, 64, 139), GetSelectionRGB2(ns));
nvgBeginPath(vg);
nvgRoundedRect(vg, x, y, w, h, ButtonCornerRaidus);
nvgFillPaint(vg, bg_paint);
nvgFill(vg);
}
/* Draw the shadow surrounding the button. */
if (style == ButtonStyle::Standard || style == ButtonStyle::StandardSelected || style == ButtonStyle::StandardDisabled || style == ButtonStyle::FileSelectSelected) {
const unsigned char shadow_color = style == ButtonStyle::Standard ? 128 : 64;
NVGpaint shadow_paint = nvgBoxGradient(vg, x, y, w, h, ButtonCornerRaidus, 5, nvgRGBA(0, 0, 0, shadow_color), nvgRGBA(0, 0, 0, 0));
nvgBeginPath(vg);
nvgRect(vg, x - 10, y - 10, w + 20, h + 30);
nvgRoundedRect(vg, x, y, w, h, ButtonCornerRaidus);
nvgPathWinding(vg, NVG_HOLE);
nvgFillPaint(vg, shadow_paint);
nvgFill(vg);
}
/* Setup the font. */
nvgFontSize(vg, fontsize);
nvgAddFallbackFont(vg, SwitchStandardFont, SwitchExtFont);
nvgTextAlign(vg, NVG_ALIGN_LEFT | NVG_ALIGN_MIDDLE);
/* Set the text colour. */
if (style == ButtonStyle::StandardSelected || style == ButtonStyle::FileSelectSelected) {
nvgFillColor(vg, nvgRGB(255, 255, 255));
} else {
const unsigned char alpha = style == ButtonStyle::StandardDisabled ? 64 : 255;
nvgFillColor(vg, nvgRGBA(0, 0, 0, alpha));
}
/* Draw the button text. */
const float tw = nvgTextBounds(vg, 0, 0, text, nullptr, nullptr);
if (style == ButtonStyle::Standard || style == ButtonStyle::StandardSelected || style == ButtonStyle::StandardDisabled) {
nvgText(vg, x + w * 0.5f - tw * 0.5f, y + h * 0.5f, text, nullptr);
} else {
nvgText(vg, x + 10.0f, y + h * 0.5f, text, nullptr);
}
}
void DrawTextBackground(NVGcontext *vg, float x, float y, float w, float h) {
nvgBeginPath(vg);
nvgRoundedRect(vg, x, y, w, h, TextAreaCornerRadius);
nvgFillColor(vg, nvgRGBA(0, 0, 0, 16));
nvgFill(vg);
}
void DrawText(NVGcontext *vg, float x, float y, float w, const char *text) {
float fontsize = 20.0f;
nvgFontSize(vg, fontsize);
nvgAddFallbackFont(vg, SwitchStandardFont, SwitchExtFont);
nvgTextAlign(vg, NVG_ALIGN_LEFT | NVG_ALIGN_TOP);
nvgFillColor(vg, nvgRGB(0, 0, 0));
const float tw = nvgTextBounds(vg, 0, 0, text, nullptr, nullptr);
nvgText(vg, x + w * 0.5f - tw * 0.5f, y, text, nullptr);
}
void DrawTextAlignWhite(NVGcontext* vg, float x, float y, float w, const char* text, TextStyle style) {
float fontsize = 20.0f;
/*
nvgBeginPath(vg);
nvgRoundedRect(vg, x, y - 3.0f, w, fontsize + 4.0f, ButtonCornerRaidus);
nvgFillColor(vg, nvgRGBA(0, 0, 0, 16));
nvgFill(vg);
*/
nvgFontSize(vg, fontsize);
nvgAddFallbackFont(vg, SwitchStandardFont, SwitchExtFont);
nvgTextAlign(vg, NVG_ALIGN_LEFT | NVG_ALIGN_TOP);
nvgFillColor(vg, nvgRGB(255, 255, 255));
const float tw = nvgTextBounds(vg, 0, 0, text, nullptr, nullptr);
if (style == TextStyle::CenterAlign) {
nvgText(vg, x + w * 0.5f - tw * 0.5f, y, text, nullptr);
}
else if (style == TextStyle::LeftAlign) {
nvgText(vg, x + 10.0f, y, text, nullptr);
}
else if (style == TextStyle::RightAlign) {
nvgText(vg, x + w * 0.5f + tw * 0.5f, y, text, nullptr);
}
}
void DrawTextAlign(NVGcontext* vg, float x, float y, float w, const char* text, TextStyle style) {
float fontsize = 20.0f;
/*
nvgBeginPath(vg);
nvgRoundedRect(vg, x, y - 3.0f, w, fontsize + 4.0f, ButtonCornerRaidus);
nvgFillColor(vg, nvgRGBA(0, 0, 0, 16));
nvgFill(vg);
*/
nvgFontSize(vg, fontsize);
nvgAddFallbackFont(vg, SwitchStandardFont, SwitchExtFont);
nvgTextAlign(vg, NVG_ALIGN_LEFT | NVG_ALIGN_TOP);
nvgFillColor(vg, nvgRGB(0, 0, 0));
const float tw = nvgTextBounds(vg, 0, 0, text, nullptr, nullptr);
if (style == TextStyle::CenterAlign) {
nvgTextAlign(vg, NVG_ALIGN_CENTER | NVG_ALIGN_TOP);
const float tw = nvgTextBounds(vg, 0, 0, text, nullptr, nullptr);
nvgText(vg, x + 10.0f + tw, y, text, nullptr);
}
else if (style == TextStyle::LeftAlign) {
nvgText(vg, x + 10.0f, y, text, nullptr);
}
else if (style == TextStyle::RightAlign) {
nvgTextAlign(vg, NVG_ALIGN_RIGHT | NVG_ALIGN_TOP);
const float tw = nvgTextBounds(vg, 0, 0, text, nullptr, nullptr);
nvgText(vg, x + 10.0f, y, text, nullptr);
}
}
void DrawHeadline(NVGcontext* vg, float x, float y, float w, const char* text) {
nvgFontSize(vg, 24.0f);
nvgAddFallbackFont(vg, SwitchStandardFont, SwitchExtFont);
nvgTextAlign(vg, NVG_ALIGN_LEFT | NVG_ALIGN_TOP);
nvgFillColor(vg, nvgRGB(0, 0, 0));
const float tw = nvgTextBounds(vg, 0, 0, text, nullptr, nullptr);
nvgText(vg, x + w * 0.5f - tw * 0.5f, y, text, nullptr);
}
void DrawMeta(NVGcontext* vg, float x, float y, const char *text, TextStyle style) {
if (style == TextStyle::LeftAlign) {
nvgFontSize(vg, 24.0f);
nvgAddFallbackFont(vg, SwitchStandardFont, SwitchExtFont);
nvgTextAlign(vg, NVG_ALIGN_LEFT | NVG_ALIGN_TOP);
nvgBeginPath(vg);
const float tw = nvgTextBounds(vg, x, y, text, nullptr, nullptr);
nvgRect(vg, x - 8.0f, y - 8.0f, tw + 8.0f * 2.0f, 24.0f + 8.0f + 4.0f);
nvgFillColor(vg, nvgRGBA(0, 0, 0, 128));
nvgFill(vg);
nvgFillColor(vg, nvgRGB(255, 255, 255));
nvgText(vg, x, y, text, nullptr);
}
if (style == TextStyle::RightAlign) {
nvgFontSize(vg, 24.0f);
nvgAddFallbackFont(vg, SwitchStandardFont, SwitchExtFont);
nvgTextAlign(vg, NVG_ALIGN_RIGHT | NVG_ALIGN_TOP);
nvgBeginPath(vg);
const float tw = nvgTextBounds(vg, 0, 0, text, nullptr, nullptr);
nvgRect(vg, x - 8.0f - tw, y - 8.0f, tw + 8.0f * 2.0f, 24.0f + 8.0f + 4.0f);
nvgFillColor(vg, nvgRGBA(0, 0, 0, 128));
nvgFill(vg);
nvgFillColor(vg, nvgRGB(255, 255, 255));
nvgText(vg, x, y, text, nullptr);
}
}
void DrawProgressText(NVGcontext *vg, float x, float y, float progress) {
char progress_text[32] = {};
snprintf(progress_text, sizeof(progress_text)-1, "%d%% complete", static_cast<int>(progress * 100.0f));
nvgFontSize(vg, 24.0f);
nvgAddFallbackFont(vg, SwitchStandardFont, SwitchExtFont);
nvgTextAlign(vg, NVG_ALIGN_LEFT | NVG_ALIGN_MIDDLE);
nvgFillColor(vg, nvgRGB(0, 0, 0));
nvgText(vg, x, y, progress_text, nullptr);
}
void DrawProgressBar(NVGcontext *vg, float x, float y, float w, float h, float progress) {
/* Draw the progress bar background. */
nvgBeginPath(vg);
nvgRoundedRect(vg, x, y, w, h, WindowCornerRadius);
nvgFillColor(vg, nvgRGBA(0, 0, 0, 56));
nvgFill(vg);
/* Draw the progress bar fill. */
if (progress > 0.0f) {
NVGpaint progress_fill_paint = nvgLinearGradient(vg, x, y + 0.5f * h, (x + w) * progress, y + 0.5f * h, nvgRGB(77, 136, 255), nvgRGB(181, 102, 255));
nvgBeginPath(vg);
nvgRoundedRect(vg, x, y, WindowCornerRadius + (w - WindowCornerRadius) * progress, h, WindowCornerRadius);
nvgFillPaint(vg, progress_fill_paint);
nvgFill(vg);
}
}
void DrawScrollbar(NVGcontext* vg, float x, float y, float h) {
/* Draw the shadow surrounding the window. */
NVGpaint shadowPaint = nvgBoxGradient(vg, x, y, 15.0f, h, TextAreaCornerRadius * 1.2f, 30, nvgRGBA(0, 0, 0, 20), nvgRGBA(0, 0, 0, 0));
nvgBeginPath(vg);
nvgRect(vg, x - 20, y - 20, 15.0f + 40, h + 40);
nvgRoundedRect(vg, x, y, 15.0f, h, TextAreaCornerRadius);
nvgPathWinding(vg, NVG_HOLE);
nvgFillPaint(vg, shadowPaint);
nvgFill(vg);
nvgBeginPath(vg);
nvgRoundedRect(vg, x, y, 15.0f, h, TextAreaCornerRadius);
nvgFillColor(vg, nvgRGBA(255, 255, 255, 180));
nvgFill(vg);
}
void DrawTextBlock(NVGcontext *vg, const char *text, float x, float y, float w, float h) {
/* Save state and scissor. */
nvgSave(vg);
nvgScissor(vg, x, y, w, h);
/* Configure the text. */
nvgFontSize(vg, 18.0f);
nvgAddFallbackFont(vg, SwitchStandardFont, SwitchExtFont);
nvgTextLineHeight(vg, 1.3f);
nvgTextAlign(vg, NVG_ALIGN_LEFT | NVG_ALIGN_TOP);
nvgFillColor(vg, nvgRGB(0, 0, 0));
/* Determine the bounds of the text box. */
float bounds[4];
nvgTextBoxBounds(vg, 0, 0, w, text, nullptr, bounds);
/* Adjust the y to only show the last part of the text that fits. */
float y_adjustment = 0.0f;
if (bounds[3] > h) {
y_adjustment = bounds[3] - h;
}
/* Draw the text box and restore state. */
nvgTextBox(vg, x, y - y_adjustment, w, text, nullptr);
nvgRestore(vg);
}
}