How to adress the Label that shows a TextEditor inside of textEditorReturnKeyPressed?


#1

Hello Juce-people,
I’m relatively new to Juce and am stuck for the first time:

I attempt to create an audio plugin and I have a number of Labels which are editable.
User entry should be limited to a range Integers (f.e. 0-60) and if the user enters something else the label should show the value it had before the edit.
My attempt:

void GUI::editorShown(Label* labelThatShowsEditor, TextEditor& textEditorThatIsShown)

 {
    labelTextEditor = &textEditorThatisShown;
    if(labelThatShowsEditor == Label1)
    {
        Duration1 = std::stoi(textEditorThatisShown.getText().toStdString());
    }
    else if(labelThatShowsEditor == Label2)
    {
        Duration2 = std::stoi(textEditorThatisShown.getText().toStdString());
    }
}

So I store the momentary values in the variables Duration1 and Duration2 and the adress of the Texteditor in labelTextEditor.

Then i want to check inside textEditorReturnKeyPressed:

void GUI::textEditorReturnKeyPressed (TextEditor& textEditor)
{
    if(&textEditor == labelTextEditor)
    {
        String text = textEditor.getText();
        if(Helper::isInt(text))
        {
            //check for range
            //assign it to the "parent" label's text
        }
    }
}

Any advice on how to do that correctly?
Thanks!


#2

There is also a

virtual void labelTextChanged (Label *labelThatHasChanged)=0

You can use this instead of textEditorReturnKeyPressed