Dynamic Height For TextEditor

Hi :slight_smile:

I have a TextEditor with some text in it.
I want its height to be minimal given its width (the width of its parent).

So what I did was:

int textWidth = te.getFont().getStringWidth(te.getText()); //didn't just use te.getTextWidth() because the TextEditor doesn't have a size yet.

double numLines = (double)textWidth / getWidth();

if (numLines - (int)numLines != 0) // please tell me if there's a juce method to ceil and not just round to closest int.
    numLines = (int)numLines;

The problem with this code is that when word wrapping is active, an additional line may be required.

Any advice on how to approach this?


After reading a lot of your posts, it seems like you are consistently over-complicating your user interface. Either that, or you are choosing difficult solutions when easier solutions exist. I would re-think whatever it is that you are doing, perhaps seek advice from someone about how to architect your system so that these complicated implementations are not necessary. Keep It Simple!