How to get Label's current value?


#1

It seems user forced to press ENTER in Slider’s Label before clicking on dialog’s OK button. Otherwise chenges in Label doesn’t apply. How to get latest user changes from Slider’s Label (when user clicks dialog’s Ok button)?

class Slider_labelcentric : 
	public JUCE::Slider
{
	typedef JUCE::Slider parent;
public:
	Slider_labelcentric(JUCE::String const& componentName)
		: parent(componentName)
	{
	}
	JUCE::String get_label_current_value(void)
	{
		return valueBox->getText();
	}
	void update_value_from_label(void)
	{
		textChange(true, false);
	}
protected:
	void textEditorTextChanged(TextEditor& editor)
	{
		textChange(true, false);
	}
};

In my OnOk handler I call update_value_from_label, but it doesn’t help because valueBox->getText() returns old value.


#2

Good question.

Simplest plan would just be to call Label::hideEditor (false) before you call Label::getText().

But I might also add this parameter to Label::getText() so it’s possible to do it without necessarily getting rid of the editor:

const String Label::getText (const bool returnActiveEditorContents) const
{
return (returnActiveEditorContents && isBeingEdited())
? editor->getText()
: text;
}


#3

Thank you for your prompt answer.

(Notice that valueBox field in Slider is private and getValue member is non-virtual)


#4