Two Different Font Sizes in One Label?

Hey JUCE world, is there any way to use two different font sizes in one label? Here’s the story:

I’m using a UTF_8 “infinity” symbol in a Slider label to report when the slider is at negative infinity dB (all the way down). I ovverrode the default textFromValue function to do this as follows:

textFromValueFunction = [this](double value) {
  if (value == 0) {
      return String(CharPointer_UTF8("-\u221E"));
  }
  else {
      return String(20.f*std::log10(value/127.), 1);
  }
};

and I have a

setTextValueSuffix(" dB");

to display “dB” next to the label.

However I’m finding that the infinity character looks really small, and was wondering if there’s a way to increase the font size of just the infinity symbol and not the suffix in the condition where the label displays it. I tried this:

textFromValueFunction = [this](double value) {
  if (value == 0) {
      setFontSize(14.f)  //this is pseudo-code, my actual component structure is a little complicated here...
      return String(CharPointer_UTF8("-\u221E"));
  }
  else {
      setFontSize(12.f) 
      return String(20.f*std::log10(value/127.), 1);
  }
};

But that makes the “dB” larger in a way that doesn’t look good. Any help appreciated, thanks!

Have a look at JUCE: AttributedString Class Reference

You’d have to then make your own label class that uses juce::AttributedString to draw its text

1 Like

Thank you!!