Create a Label, use setJustificationType( Justification::centred ), and allow editing.
Result: The label text is centered, but when the user clicks to edit the label, the resulting text editor is left justified, causing the text to jump to the left.
It would be desirable if, when entering edit mode, the text editor activated in such a way that the text did not visibly shift at all, to create the appearance that it is being changed in-place (i.e. displaying using the Label’s Justification).
In addition, if a Label is editable, but the editor is not active, the cursor should probably change to an I-beam to indicate that the text can be edited. And if you want to provide the option to pass the click that activated edit mode, on to the text editor, so that the insertion point can be set to the place where the user clicked to get into edit mode, hey I’m not going to hold that against you (but if you don’t do it, I won’t complain either).
Jules - I Imagine your to-do list is horrible. But I'm working on an app with someone where this would be nice. Is it anywhere near the top of the to-do list yet? :)
It's only the one-line case this is normally annoying for.
I see why this isn't simple. The way the Iterator object builds it up from the left isn't really encouraging justification.
It'd be easier to add SimpleTextEditor which ditched with most of the font/colour/multi-line code but offered Justification. But I'm not sure that the easy path is the right solution.
Going to have a look at how that Iterator is used and see if there's not another level of abstraction that'll sort it out. [... moderately long pause ...].
I think it'd be possible to add something like JustifyingIterator in as a wrapper over Iterator. It can deal with offsetting the horizontal axis and deal with adjusting indexToX type function calls.
Adding in an Iterator::getGlyphArrangement to replace Iterator::draw() gets me half of the way there. I can then join the Glyphs on one line to a single GlyphArrangement and draw them so they look justified.
I'm not sure how to handle vertical justification yet mind you ...
Hey there @jimc
I understand this is a pretty old thread but I was just wondering if you found a solution that worked well for you? I am hitting a similar thing right now.
If I understand the issue, I got rid of this problem a long time ago. It seems my “fix” was to add a line to Label::showEditor():
void Label::showEditor()
{
if (editor == nullptr)
{
editor.reset (createEditorComponent());
editor->setSize (10, 10);
addAndMakeVisible (editor.get());
editor->setText (getText(), false);
editor->setKeyboardType (keyboardType);
editor->addListener (this);
editor->grabKeyboardFocus();
// makes the editor have the same justification as the label
editor->setJustification(getJustificationType());
if (editor == nullptr) // may be deleted by a callback
return;
editor->setHighlightedRegion (Range<int> (0, textValue.toString().length()));
resized();
repaint();
editorShown (editor.get());
enterModalState (false);
editor->grabKeyboardFocus();
}
}
This keeps the Editor centered when the label is. The text may still shift slightly left, right, up or down depending on the font you are using. I then tweak its positioning in LookAndFeel::fillTextEditorBackground() by shifting the textArea with either textEditor.setIndents() or textArea.translate() (on the rectangle of the text area).
Thanks. Would be great to get this officially fixed in JUCE. It just looks really unprofessional and subclassing every label or forking JUCE for this one little thing is hard to swallow.