Scrollable attributed string component

Sorry if this is a dumb question but I can’t seem to find an easy (out-of-the box) solution for this.

I want to display an EULA in my app. I thought I’d just use the TextEditor but I found out that it can’t handle attributed strings. I used Fabian’s fabulous RtfFileLoader to get an attributed string from an RTF file ( but I can only draw it directly to the component which doesn’t work with long text.

Do I need to cook up something myself to display an AttributedString in a scroll view?
What do you suggest?

just do a regular component which has paint() overridden to display the attributed string.
stick that component in a ViewPort with appropriate scroll bars turned on/off.

struct AttrStringViewer : public Component
    void paint(Graphics& g) override
        attrString.draw(g, getLocalBounds());
    AttributedString attrString;
1 Like

Yeah, that’s basically it. You need to add a size calculation method to set the size of the viewport’s scrolled component appropriately.

As this is really something many people will need, I was just thinking that I was missing something obvious.

Here’s what I came up with. I’m sure it can be improved but maybe it’s helpful for someone else looking for the same thing:

you don’t need to mark those functions you’re overriding as virtual. they’re already virtual in the base class.

Does it hurt if I do? Or do any harm to the performance?
I guess it just became a habit.

It’s just bad code style, but it makes no difference to the compiler output.

I guess I can live with that :wink: