[Solved] ColibriManager resize label but not the font Topic is solved

Discussion area about developing with Ogre-Next (2.1, 2.2 and beyond)


knn217
Halfling
Posts: 78
Joined: Wed Jan 25, 2023 9:04 am
x 5

[Solved] ColibriManager resize label but not the font

Post by knn217 »

Hello, I noticed that ColibriManger doesn't resize the font for the label class when updateDerivedTransformOnly() is called.

Should setDefaultFontSize() be called as well? This seems like the intended behavior.

Last edited by knn217 on Wed Oct 11, 2023 7:03 am, edited 2 times in total.
User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5477
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1359

Re: ColibriManager resize label but not the font

Post by dark_sylinc »

Hi.

Intended behavior is for the font size to remain constant.

Label's size (via setSize) affects clipping, text wrapping, and left/center/right text alignment (and also top/center/bottom).

Thus indeed if you want the text to shrink or grow, you can call Label::setDefaultFontSize. The most common pattern is:

Code: Select all

label->setDefaultFontSize( colibriManager->getDefaultFontSize26d6() * 30u / 16u ); // Set the font to 1.875x te global default font size
label->setText( "Hello World" );
label->sizeToFit();

The use of colibriManager->getDefaultFontSize26d6 is not mandatory, but it is very convenient because that way you can easily implement accessibility options to shrink/grow all text from one place while preserving proportions: simply call colibriManager->setDefaultFontSize26d6 in the options menu presented to the user, and all labels created afterwards will be using the new size (existing labels won't be modified unless you go through them and manually update and re-layout them).

Like this:

knn217
Halfling
Posts: 78
Joined: Wed Jan 25, 2023 9:04 am
x 5

Re: ColibriManager resize label but not the font

Post by knn217 »

Thanks for clearing that up!

If anyone else has this problem, my solution is:

  • Add a function to access the labelVec in ColibriManager.

  • Iterate through the labels and set the font size whenever my app's window changes size.

  • Since the canvas size stays constant, font size is changed based on the window's resolution.

  • If you want different font sizes for different labels, assign each label a specific m_userId and then check the IDs when iterating through them