PDA

View Full Version : Mixed fonts in a single label?


Zelxyb
11-23-2011, 01:52 PM
I'm still trying to learn the limits of what Lua can do, so bear with me on any dumb questions!

I've got a label where I want to emphasize part of the text but not all of it.

Example: This line would be an example.
Example: This line would be another example.

Is this possible to do? If so, could someone give me some sample code for the example lines above?

If not, I can always create multiple labels next to each other, but I'm worried about that working out with translations (as in, I don't want to have to re-layout the screen when the German words are longer than the English ones).

Thanks in advance for any help!

Galuhad
11-23-2011, 02:19 PM
To my knowledge it's not possible as you assign the font to the label as a whole ( label:SetFont() ).

Garan
11-23-2011, 02:53 PM
Galuhad is correct. There is no mixing fonts within a single label. Additionally, there are no font metrics so you have to use the scrollbar trick to figure out the needed width for the control if you intend to use multiple controls to build your text. It gets messy REAL quick if the text is variable. If it's just fixed text and will only need to highlight a specific series of words it can be done, but it's still ugly.

Zelxyb
11-23-2011, 03:21 PM
Thanks, both of you. I was afraid of that, but thought I should ask just in case!

I'll never take flashbuilder for granted again...

Digital_Utopia
11-24-2011, 10:20 PM
Turbine has given us enough psuedo-OOP utillity to seriously improve upon the basic API. For instance, while having more than one font in a label is not possible, it is more than possible to make a custom class that combines multiple lables to achieve the same effect. To get around the issue of handling size based on text length, one posibility is to store pre-defined character widths based on font size.

While there are things we just can't do (mostly game API and graphics limitations), never feel that the API or stock Lua functions are what ultimately decides your limits.

Equendil
11-25-2011, 12:23 PM
Turbine has given us enough psuedo-OOP utillity to seriously improve upon the basic API. For instance, while having more than one font in a label is not possible, it is more than possible to make a custom class that combines multiple lables to achieve the same effect. To get around the issue of handling size based on text length, one posibility is to store pre-defined character widths based on font size.

While there are things we just can't do (mostly game API and graphics limitations), never feel that the API or stock Lua functions are what ultimately decides your limits.
Hehe I like to say "impossible" in software developer jargon is merely a synonym for "very time consuming".

Situation #1:
Boss: Hey, can you implement that new feature our customer requested ?
Dev: Well it would take months and the feature is rather minor
Boss: Get on it ! We need it for yesterday !

Situation #2:
Boss: Hey, can you implement that new feature our customer requested ?
Dev: Nah, not possible.
Boss: Isn't there any way ?
Dev: Nope.

Digital_Utopia
11-25-2011, 05:33 PM
Hehe I like to say "impossible" in software developer jargon is merely a synonym for "very time consuming".

Situation #1:
Boss: Hey, can you implement that new feature our customer requested ?
Dev: Well it would take months and the feature is rather minor
Boss: Get on it ! We need it for yesterday !

Situation #2:
Boss: Hey, can you implement that new feature our customer requested ?
Dev: Nah, not possible.
Boss: Isn't there any way ?
Dev: Nope.

Haha certainly! Thankfully, in this case we're all our own "boss", but on the other side, there really is an "impossible" here. Well, at least in limiting ourselves within the plugin system, within the client. There is also however, a "reasonably possible" as well - and that kinda goes hand in hand with what you were saying. Just because you technically could do it, doesn't mean that what you would need it for is that crucial to make it worth the effort.

For instance, in this multi-font label thing, if the author's goal was to (for some reason) create a plugin that renders HTML/CSS, then the effort required would probably be worth it (at least for the goal). On the other hand, if they just wanted to make their options panel prettier, then...that's probably a different story. Even still, since we are all our own "boss", it's up to the individual author to make that final decision - whether their effort, is worth (to them) the result.

The message though, is you'll be able to accomplish and pull off a lot more if you go into a project asking "This is what I want to do, now how do I use what exists to pull it off?" instead of "This is what I want to do, now does the API/Language have a "whatIWantToDo(justLikeThis);" function?". Unless you're dealing with PHP, or love spending time searching for and downloading 3rd-party libraries, there's probably not going to be such a function - until you make it of course.