I’m starting to wonder if either you’re not reading any of the documentation links that have been posted, or if you just don’t understand what the documentation says.
once again, here’s a link to the documentation:
this is all about dealing with text.
if you read that, there’s an example right there. which, since you’re still saying is wrong, I went ahead and copied and moved into a module in rack:
struct DemoWidget : TransparentWidget {
std::shared_ptr<Font> font;
DemoWidget ( ) {
font = APP->window->loadFont(asset::plugin(pluginInstance, "res/Lato.ttf"));
}
void draw (const DrawArgs &args) override {
// draw the text
float bounds[4];
const char* txt = "DEMO";
nvgTextAlign(args.vg, NVG_ALIGN_MIDDLE);
nvgTextBounds(args.vg, 0, 0, txt, NULL, bounds);
nvgBeginPath(args.vg);
nvgFillColor(args.vg, nvgRGBA(0xff, 0xff, 0xff, 0xff));
nvgRect(args.vg, bounds[0], bounds[1], bounds[2]-bounds[0], bounds[3]-bounds[1]);
nvgFill(args.vg);
nvgFillColor(args.vg, nvgRGBA(0x00, 0xff, 0x00, 0xff));
nvgText(args.vg, 0, 0, txt, NULL);
}
};
which gives me exactly what I’d expect:
if I set the alignment to NVG_ALIGN_TOP
instead of NVG_ALIGN_MIDDLE
, it aligns to the top of the box instead of the middle. the documentation is pretty darned clear.