Align text in TooltipWindow


#1

Hi,

how can the alignment (default: centered) of a TooltipWindow be changed (to: left aligned)?

Thanks & cheers,

raketa


#2

Presumably a custom LookAndFeel could do that.


#3

... thats what I expected, but I couldn't see how this would be done other than overwriting both

void LookAndFeel_V2::drawTooltip (Graphics&, const String& text, int width, int height) override;

void getTooltipSize (const juce::String& text, int& width, int& height) override;

which - if I don't oversee anything - is pretty much a hassle since the horizontal and vertical size of the formated multi line text needs to be estimated.

 

On the other hand 

    static TextLayout layoutTooltipText (const String& text, Colour colour) noexcept
    {
        const float tooltipFontSize = 13.0f;
        const int maxToolTipWidth = 400;

        AttributedString s;
        s.setJustification (Justification::centred);
        s.append (text, Font (tooltipFontSize, Font::bold), colour);

        TextLayout tl;
        tl.createLayoutWithBalancedLineLengths (s, (float) maxToolTipWidth);
        return tl;
    }

sets it explicitly to Justification::centred which could be a parameter to the look'n'feel class...

Cheers,

raketa