Setting Justification of AlertWindow text

I’m creating a customized AlertWindow by subclassing LookAndFeel_V4 and overriding some of the methods declared in the AlertWindow::LookAndFeelMethods struct (namely createAlertWindow and drawAlertBox).

I’m currently trying to change the Justification of both the title and the message text shown in the AlertWindow, and I’m a bit stumped at the moment!

I read this previous thread on the topic, which suggests that it is possible to change the Justification in the LookAndFeel::drawAlertbox() method.

I am already overriding that method, but there does not appear to be any straightforward way to change the text Justification. One of the parameters is a TextLayout reference, and I must admit that I am not very familiar with this class. It appears to be created from an AttributedString whose Justification cannot be modified once the TextLayout has been created, which is the case by the time drawAlertBox() gets called.

It’s been a long day, so it’s very possible that I am missing something here. This is my first time really digging into the AlertWindow class, and some of the modifications have been less straightforward than I initially anticipated, so I’d love to get any pointers from fellow jucers who have done their own customizations.

Am I missing something here? Or does anyone know of a different way to change the text Justification in an AlertWindow?

Well, I’ve found a bit of a hack that might work for this specific case (wanting to use Justification::topLeft for the text, and not use an alert icon).

Looking at the code in AlertWindow::updateLayout(), the Justification is set according to whether or not an alert icon is being used: if an icon is being used, the Justification is set to topLeft, but if an icon is not being used it is set to centredTop.

I want to use topLeft, but I also don’t want to display an icon.

Since the icon drawing is done in the drawAlertBox() method that I am overriding, I can set the AlertIconType to any value besides NoIcon, and simply not draw the icon in the overridden method. This way, no icon is shown, but the text Justification gets set to the desired topLeft value in AlertWindow::updateLayout().

It’s very far from being an elegant solution, but it does work for the time being. I would love to find a more reliable and flexible solution, though, even if it involves creating a new class that re-implements a lot of the AlertWindow behaviour.

I would avoid any AlertWindows when you’re creating plug-in products, as they sometimes get hidden behind the host window (unintentionally; by the users) who are then confused why they can’t click anywhere.

We are now using our own Component that will be centered within a wrapper component that is covering the entire main-component, thus blocking all input, but since it’s just graphics, it’s impossible for the user to miss it.

That would also give you total control over the layout, icons etc.

2 Likes