question on Label positioning

Hi, I’m studying the VCV API to create text labels. But I’m kind of confused.

I would expect the following code to put the “Yolow” string at the bottom of a 6HP module centralized. I mean positioning letter “l” more or less in the middle. Instead the string is placed far right outside of the visible 6HP width of the module.

What do I get wrong? How to place the string in the middle of the panel?

		Label* labelYolow = new Label;
		labelYolow->box.pos = mm2px(Vec(HP * 0, HP * 24)); // Set position
		// labelYolow->box.size = mm2px(Vec(HP * 1, HP * 6)); // Optional: Set size
		labelYolow->text = "Yolow";
		labelYolow->fontSize = 14;
		labelYolow->color = nvgRGB(0, 0, 0); // Black text
		labelYolow->alignment = Label::CENTER_ALIGNMENT; // Center alignment
		addChild(labelYolow);

I think there’s a mismatch between box-position and box-size. Both have to be defined. And there’s also a mismatch between width and height of the box.

this works for me:

// I assume HP is 5.08 mm
float HP = 5.08; 
Label* labelYolow = new Label;
// Set position and not the size of the box:
// posX = 0; posY = 24 HP;
labelYolow->box.pos = mm2px(Vec(HP * 0, HP * 24));
// required: Set size of the box to:
// width = 6 HP; height = 3 HP;
labelYolow->box.size = mm2px(Vec(HP * 6, HP * 3)); 
labelYolow->text = "Yolow";
labelYolow->fontSize = 14;
// Black text
labelYolow->color = nvgRGB(0, 0, 0); 
// Center alignment
labelYolow->alignment = Label::CENTER_ALIGNMENT;
addChild(labelYolow);
1 Like

Yes, it was the box.size :no_mouth:

Thank you! It makes total sense now.

1 Like