Optimizing text drawing of TextButtons in a TableListBox


#1

I feel like it might have been addressed in the past already, but I can’t find a similar post.

On Juce 5.2.0,

I’m drawing a small (~15 rows / ~20 cols) TableListBox which includes a third of custom cells in the form of inc/dec sliders. Hence these sliders make use of TextButton to show the +/- sign buttons.

Since the table has quite a few columns, it is required to scroll the viewport to see all of them. But doing so impacts the performance a lot.

It seems the performance hit comes from drawing the text in the TextButtons. I tried caching the custom components with setBufferedToImage(true) but it does not seem to have any effect because of the Viewport.

Using a default <Sans-Serif> font instead of my custom one seems to drastically reduce the performance hit. But is there any way to optimize the use of a custom font (created with Typeface::createSystemTypefaceFor) when drawing text?

Here is the profiler’s stack:
21


#2

In refreshComponentForRow, are you creating the TextButton every time, or just when existingComponentToUpdate is nullptr?


#3

Ah! Rookie mistake! :expressionless:
I was checking existingComponentToUpdate with a dynamic_cast against the wrong component type, thus deleting it every time…
Thanks @SamSpreadborough !


#4

Ahh, nice one. I had a similar problem before.