Browse Source

Use lambda callbacks instead of listeners with Slider, Button, Label, ComboBox and TextEditor classes

tags/2021-05-28
Noah Dayan 7 years ago
parent
commit
e690350df3
30 changed files with 114 additions and 258 deletions
  1. +2
    -8
      extras/Projucer/Source/Application/Windows/jucer_GlobalSearchPathsWindowComponent.h
  2. +3
    -13
      extras/Projucer/Source/Application/Windows/jucer_SVGPathDataWindowComponent.h
  3. +4
    -14
      extras/Projucer/Source/Application/Windows/jucer_UTF8WindowComponent.h
  4. +4
    -7
      extras/Projucer/Source/CodeEditor/jucer_LiveBuildCodeEditor.h
  5. +9
    -17
      extras/Projucer/Source/CodeEditor/jucer_SourceCodeEditor.cpp
  6. +6
    -13
      extras/Projucer/Source/Project/UI/Sidebar/jucer_TabComponents.h
  7. +1
    -8
      extras/Projucer/Source/Project/UI/jucer_HeaderComponent.h
  8. +9
    -15
      extras/Projucer/Source/Utility/UI/PropertyComponents/jucer_DependencyPathPropertyComponent.cpp
  9. +4
    -11
      extras/Projucer/Source/Utility/UI/PropertyComponents/jucer_DependencyPathPropertyComponent.h
  10. +3
    -6
      extras/Projucer/Source/Utility/UI/PropertyComponents/jucer_FilePathPropertyComponent.h
  11. +4
    -8
      extras/Projucer/Source/Utility/UI/jucer_JucerTreeViewBase.cpp
  12. +9
    -23
      extras/Projucer/Source/Wizards/jucer_NewProjectWizardComponent.h
  13. +4
    -9
      extras/Projucer/Source/Wizards/jucer_TemplateThumbnailsComponent.h
  14. +9
    -17
      modules/juce_gui_basics/filebrowser/juce_FileBrowserComponent.cpp
  15. +1
    -9
      modules/juce_gui_basics/filebrowser/juce_FileBrowserComponent.h
  16. +2
    -2
      modules/juce_gui_basics/properties/juce_ChoicePropertyComponent.cpp
  17. +2
    -3
      modules/juce_gui_basics/properties/juce_ChoicePropertyComponent.h
  18. +5
    -7
      modules/juce_gui_basics/properties/juce_SliderPropertyComponent.cpp
  19. +1
    -4
      modules/juce_gui_basics/properties/juce_SliderPropertyComponent.h
  20. +1
    -7
      modules/juce_gui_basics/widgets/juce_ComboBox.cpp
  21. +0
    -3
      modules/juce_gui_basics/widgets/juce_ComboBox.h
  22. +3
    -4
      modules/juce_gui_basics/widgets/juce_Slider.cpp
  23. +2
    -2
      modules/juce_gui_basics/windows/juce_AlertWindow.cpp
  24. +2
    -4
      modules/juce_gui_basics/windows/juce_AlertWindow.h
  25. +2
    -2
      modules/juce_gui_extra/misc/juce_ColourSelector.cpp
  26. +2
    -3
      modules/juce_gui_extra/misc/juce_ColourSelector.h
  27. +14
    -28
      modules/juce_gui_extra/misc/juce_LiveConstantEditor.cpp
  28. +1
    -5
      modules/juce_gui_extra/misc/juce_LiveConstantEditor.h
  29. +2
    -2
      modules/juce_gui_extra/misc/juce_PreferencesPanel.cpp
  30. +3
    -4
      modules/juce_gui_extra/misc/juce_PreferencesPanel.h

+ 2
- 8
extras/Projucer/Source/Application/Windows/jucer_GlobalSearchPathsWindowComponent.h View File

@@ -28,8 +28,7 @@
//==============================================================================
class GlobalSearchPathsWindowComponent : public Component,
private ComboBox::Listener
class GlobalSearchPathsWindowComponent : public Component
{
public:
GlobalSearchPathsWindowComponent()
@@ -60,7 +59,7 @@ public:
osSelector.addItem ("Windows", 2);
osSelector.addItem ("Linux", 3);
osSelector.addListener (this);
osSelector.onChange = [this] { updateFilePathPropertyComponents(); };
auto os = TargetOS::getThisOS();
@@ -120,11 +119,6 @@ private:
ComboBox osSelector;
InfoButton info;
void comboBoxChanged (ComboBox*) override
{
updateFilePathPropertyComponents();
}
TargetOS::OS getSelectedOS() const
{
auto selectedOS = TargetOS::unknown;


+ 3
- 13
extras/Projucer/Source/Application/Windows/jucer_SVGPathDataWindowComponent.h View File

@@ -29,8 +29,7 @@
//==============================================================================
class SVGPathDataComponent : public Component,
public FileDragAndDropTarget,
private TextEditor::Listener
public FileDragAndDropTarget
{
public:
@@ -43,7 +42,8 @@ public:
userText.setMultiLine (true, true);
userText.setReturnKeyStartsNewLine (true);
addAndMakeVisible (userText);
userText.addListener (this);
userText.onTextChange = [this] { update(); };
userText.onEscapeKey = [this] { getTopLevelComponent()->exitModalState (0); };
resultText.setFont (getAppSettings().appearance.getCodeFont().withHeight (13.0f));
resultText.setMultiLine (true, true);
@@ -65,16 +65,6 @@ public:
fillPathButton.setToggleState (true, NotificationType::dontSendNotification);
}
void textEditorTextChanged (TextEditor&) override
{
update();
}
void textEditorEscapeKeyPressed (TextEditor&) override
{
getTopLevelComponent()->exitModalState (0);
}
void update()
{
getLastText() = userText.getText();


+ 4
- 14
extras/Projucer/Source/Application/Windows/jucer_UTF8WindowComponent.h View File

@@ -28,8 +28,7 @@
//==============================================================================
class UTF8Component : public Component,
private TextEditor::Listener
class UTF8Component : public Component
{
public:
UTF8Component()
@@ -43,7 +42,8 @@ public:
userText.setMultiLine (true, true);
userText.setReturnKeyStartsNewLine (true);
addAndMakeVisible (userText);
userText.addListener (this);
userText.onTextChange = [this] { update(); };
userText.onEscapeKey = [this] { getTopLevelComponent()->exitModalState (0); };
resultText.setFont (getAppSettings().appearance.getCodeFont().withHeight (13.0f));
resultText.setMultiLine (true, true);
@@ -54,16 +54,6 @@ public:
userText.setText (getLastText());
}
void textEditorTextChanged (TextEditor&) override
{
update();
}
void textEditorEscapeKeyPressed (TextEditor&) override
{
getTopLevelComponent()->exitModalState (0);
}
void update()
{
getLastText() = userText.getText();
@@ -72,7 +62,7 @@ public:
void resized() override
{
Rectangle<int> r (getLocalBounds().reduced (8));
auto r = getLocalBounds().reduced (8);
desc.setBounds (r.removeFromTop (44));
r.removeFromTop (8);
userText.setBounds (r.removeFromTop (r.getHeight() / 2));


+ 4
- 7
extras/Projucer/Source/CodeEditor/jucer_LiveBuildCodeEditor.h View File

@@ -446,7 +446,6 @@ private:
//==============================================================================
class ControlsComponent : public Component,
private Slider::Listener,
private ChangeListener
{
public:
@@ -464,7 +463,8 @@ private:
setMouseClickGrabsKeyboardFocus (false);
addAndMakeVisible (&slider);
updateRange();
slider.addListener (this);
slider.onValueChange = [this] { updateSliderValue(); };
slider.onDragEnd = [this] { updateRange(); };
if (showColourSelector)
{
@@ -511,10 +511,10 @@ private:
g.fillRoundedRectangle (getLocalBounds().toFloat(), 8.0f);
}
void sliderValueChanged (Slider* s) override
void updateSliderValue()
{
const String oldText (document.getTextBetween (start, end));
const String newText (CppParserHelpers::getReplacementStringInSameFormat (oldText, s->getValue()));
const String newText (CppParserHelpers::getReplacementStringInSameFormat (oldText, slider.getValue()));
if (oldText != newText)
document.replaceSection (start.getPosition(), end.getPosition(), newText);
@@ -525,9 +525,6 @@ private:
updateColourSelector();
}
void sliderDragStarted (Slider*) override {}
void sliderDragEnded (Slider*) override { updateRange(); }
void changeListenerCallback (ChangeBroadcaster*) override
{
setNewColour (selector.getCurrentColour());


+ 9
- 17
extras/Projucer/Source/CodeEditor/jucer_SourceCodeEditor.cpp View File

@@ -344,8 +344,7 @@ void GenericCodeEditorComponent::removeListener (GenericCodeEditorComponent::Lis
}
//==============================================================================
class GenericCodeEditorComponent::FindPanel : public Component,
private TextEditor::Listener
class GenericCodeEditorComponent::FindPanel : public Component
{
public:
FindPanel()
@@ -376,7 +375,13 @@ public:
findNext.setWantsKeyboardFocus (false);
editor.setText (getSearchString());
editor.addListener (this);
editor.onTextChange = [this] { changeSearchString(); };
editor.onReturnKey = [this] { ProjucerApplication::getCommandManager().invokeDirectly (CommandIDs::findNext, true); };
editor.onEscapeKey = [this]
{
if (GenericCodeEditorComponent* ed = getOwner())
ed->hideFindPanel();
};
}
void setCommandManager (ApplicationCommandManager* cm)
@@ -406,7 +411,7 @@ public:
findPrev.setBounds (getWidth() - 70, y, 30, 22);
}
void textEditorTextChanged (TextEditor&) override
void changeSearchString()
{
setSearchString (editor.getText());
@@ -414,19 +419,6 @@ public:
ed->findNext (true, false);
}
void textEditorFocusLost (TextEditor&) override {}
void textEditorReturnKeyPressed (TextEditor&) override
{
ProjucerApplication::getCommandManager().invokeDirectly (CommandIDs::findNext, true);
}
void textEditorEscapeKeyPressed (TextEditor&) override
{
if (GenericCodeEditorComponent* ed = getOwner())
ed->hideFindPanel();
}
GenericCodeEditorComponent* getOwner() const
{
return findParentComponentOfClass <GenericCodeEditorComponent>();


+ 6
- 13
extras/Projucer/Source/Project/UI/Sidebar/jucer_TabComponents.h View File

@@ -91,7 +91,6 @@ private:
//==============================================================================
class FindPanel : public Component,
private TextEditor::Listener,
private Timer,
private FocusChangeListener
{
@@ -100,7 +99,12 @@ public:
: callback (cb)
{
addAndMakeVisible (editor);
editor.addListener (this);
editor.onTextChange = [this] { startTimer (250); };
editor.onFocusLost = [this]
{
isFocused = false;
repaint();
};
Desktop::getInstance().addFocusChangeListener (this);
@@ -141,17 +145,6 @@ private:
editor.setTextToShowWhenEmpty ("Filter...", findColour (widgetTextColourId).withAlpha (0.3f));
}
void textEditorTextChanged (TextEditor&) override
{
startTimer (250);
}
void textEditorFocusLost (TextEditor&) override
{
isFocused = false;
repaint();
}
void globalFocusChanged (Component* focusedComponent) override
{
if (focusedComponent == &editor)


+ 1
- 8
extras/Projucer/Source/Project/UI/jucer_HeaderComponent.h View File

@@ -31,7 +31,6 @@
//==============================================================================
class HeaderComponent : public Component,
private ComboBox::Listener,
private ValueTree::Listener,
private ChangeListener
{
@@ -42,7 +41,7 @@ public:
addAndMakeVisible (configLabel);
addAndMakeVisible (exporterBox);
exporterBox.addListener (this);
exporterBox.onChange = [this] { updateExporterButton(); };
addAndMakeVisible (juceIcon = new ImageComponent ("icon"));
juceIcon->setImage (ImageCache::getFromMemory (BinaryData::juce_icon_png, BinaryData::juce_icon_pngSize),
@@ -217,12 +216,6 @@ private:
int tabsWidth = 200;
//==========================================================================
void comboBoxChanged (ComboBox* c) override
{
if (c == &exporterBox)
updateExporterButton();
}
void changeListenerCallback (ChangeBroadcaster* source) override
{
if (source == project)


+ 9
- 15
extras/Projucer/Source/Utility/UI/PropertyComponents/jucer_DependencyPathPropertyComponent.cpp View File

@@ -77,8 +77,8 @@ try : TextPropertyComponent (propertyName, 1024, false),
getValue().addListener (this);
if (Label* label = dynamic_cast<Label*> (getChildComponent (0)))
label->addListener (this);
if (auto* label = dynamic_cast<Label*> (getChildComponent (0)))
label->onEditorShow = [this, label] { setEditorText (label); };
else
jassertfalse;
@@ -116,18 +116,11 @@ Colour DependencyPathPropertyComponent::getTextColourToDisplay() const
: Colours::red;
}
void DependencyPathPropertyComponent::labelTextChanged (Label*)
{
}
void DependencyPathPropertyComponent::editorShown (Label* /*label*/, TextEditor& editor)
void DependencyPathPropertyComponent::setEditorText (Label* label)
{
if (! pathValueSource.isUsingProjectSettings())
editor.setText (String(), dontSendNotification);
}
void DependencyPathPropertyComponent::editorHidden (Label*, TextEditor&)
{
if (auto editor = label->getCurrentTextEditor())
editor->setText (String(), dontSendNotification);
}
void DependencyPathPropertyComponent::lookAndFeelChanged()
@@ -159,7 +152,7 @@ try : TextPropertyComponent (propertyDescription, 1024, false),
getValue().addListener (this);
if (auto* label = dynamic_cast<Label*> (getChildComponent (0)))
label->addListener (this);
label->onEditorShow = [this, label] { setEditorText (label); };
else
jassertfalse;
@@ -238,10 +231,11 @@ void DependencyFilePathPropertyComponent::valueChanged (Value& value)
textWasEdited();
}
void DependencyFilePathPropertyComponent::editorShown (Label*, TextEditor& editor)
void DependencyFilePathPropertyComponent::setEditorText (Label* label)
{
if (! pathValueSource.isUsingProjectSettings())
editor.setText (String(), dontSendNotification);
if (auto editor = label->getCurrentTextEditor())
editor->setText (String(), dontSendNotification);
}
void DependencyFilePathPropertyComponent::browse()


+ 4
- 11
extras/Projucer/Source/Utility/UI/PropertyComponents/jucer_DependencyPathPropertyComponent.h View File

@@ -148,8 +148,7 @@ private:
//==============================================================================
class DependencyPathPropertyComponent : public TextPropertyComponent,
private Value::Listener,
private Label::Listener
private Value::Listener
{
public:
DependencyPathPropertyComponent (const File& pathRelativeToUse,
@@ -178,10 +177,7 @@ private:
/** a reference to the value source that this value refers to. */
DependencyPathValueSource& pathValueSource;
// Label::Listener overrides:
void labelTextChanged (Label* labelThatHasChanged) override;
void editorShown (Label*, TextEditor&) override;
void editorHidden (Label*, TextEditor&) override;
void setEditorText (Label* label);
void lookAndFeelChanged() override;
@@ -191,8 +187,7 @@ private:
//==============================================================================
class DependencyFilePathPropertyComponent : public TextPropertyComponent,
public FileDragAndDropTarget,
private Value::Listener,
private Label::Listener
private Value::Listener
{
public:
DependencyFilePathPropertyComponent (Value& value,
@@ -218,9 +213,7 @@ private:
void valueChanged (Value&) override;
void labelTextChanged (Label*) override {}
void editorHidden (Label*, TextEditor&) override {}
void editorShown (Label*, TextEditor&) override;
void setEditorText (Label* label);
void lookAndFeelChanged() override
{


+ 3
- 6
extras/Projucer/Source/Utility/UI/PropertyComponents/jucer_FilePathPropertyComponent.h View File

@@ -53,8 +53,7 @@ public:
private:
struct InnerComponent : public Component,
public FileDragAndDropTarget,
private TextEditor::Listener
public FileDragAndDropTarget
{
InnerComponent (Value v, bool isDir, const String& wc, const File& rt, const bool multiplePaths)
: value (v),
@@ -67,7 +66,8 @@ private:
{
addAndMakeVisible (textbox);
textbox.getTextValue().referTo (value);
textbox.addListener (this);
textbox.onReturnKey = [this] { updateEditorColour (textbox); };
textbox.onFocusLost = [this] { updateEditorColour (textbox); };
addAndMakeVisible (button);
button.onClick = [this] { browse(); };
@@ -130,9 +130,6 @@ private:
}
}
void textEditorReturnKeyPressed (TextEditor& editor) override { updateEditorColour (editor); }
void textEditorFocusLost (TextEditor& editor) override { updateEditorColour (editor); }
void updateEditorColour (TextEditor& editor)
{
if (supportsMultiplePaths)


+ 4
- 8
extras/Projucer/Source/Utility/UI/jucer_JucerTreeViewBase.cpp View File

@@ -132,8 +132,7 @@ Component* JucerTreeViewBase::createItemComponent()
}
//==============================================================================
class RenameTreeItemCallback : public ModalComponentManager::Callback,
public TextEditor::Listener
class RenameTreeItemCallback : public ModalComponentManager::Callback
{
public:
RenameTreeItemCallback (JucerTreeViewBase& ti, Component& parent, const Rectangle<int>& bounds)
@@ -143,7 +142,9 @@ public:
ed.setPopupMenuEnabled (false);
ed.setSelectAllWhenFocused (true);
ed.setFont (item.getFont());
ed.addListener (this);
ed.onReturnKey = [this] { ed.exitModalState (1); };
ed.onEscapeKey = [this] { ed.exitModalState (0); };
ed.onFocusLost = [this] { ed.exitModalState (0); };
ed.setText (item.getRenamingName());
ed.setBounds (bounds);
@@ -157,11 +158,6 @@ public:
item.setName (ed.getText());
}
void textEditorTextChanged (TextEditor&) override {}
void textEditorReturnKeyPressed (TextEditor& editor) override { editor.exitModalState (1); }
void textEditorEscapeKeyPressed (TextEditor& editor) override { editor.exitModalState (0); }
void textEditorFocusLost (TextEditor& editor) override { editor.exitModalState (0); }
private:
struct RenameEditor : public TextEditor
{


+ 9
- 23
extras/Projucer/Source/Wizards/jucer_NewProjectWizardComponent.h View File

@@ -28,8 +28,7 @@
//==============================================================================
class ModulesFolderPathBox : public Component,
private ComboBox::Listener
class ModulesFolderPathBox : public Component
{
public:
ModulesFolderPathBox (File initialFileOrDirectory)
@@ -45,7 +44,8 @@ public:
addAndMakeVisible (currentPathBox);
currentPathBox.setEditableText (true);
currentPathBox.addListener (this);
currentPathBox.onChange = [this] { setModulesFolder (File::getCurrentWorkingDirectory()
.getChildFile (currentPathBox.getText())); };
addAndMakeVisible (openFolderButton);
openFolderButton.setTooltip (TRANS ("Select JUCE modules folder"));
@@ -121,11 +121,6 @@ public:
}
}
void comboBoxChanged (ComboBox*) override
{
setModulesFolder (File::getCurrentWorkingDirectory().getChildFile (currentPathBox.getText()));
}
File modulesFolder;
bool isUsingGlobalPaths;
@@ -285,8 +280,6 @@ private:
a list box of platform targets to generate.
*/
class WizardComp : public Component,
private ComboBox::Listener,
private TextEditor::Listener,
private FileBrowserListener
{
public:
@@ -300,13 +293,17 @@ public:
addChildAndSetID (&projectName, "projectName");
projectName.setText ("NewProject");
nameLabel.attachToComponent (&projectName, true);
projectName.addListener (this);
projectName.onTextChange = [this]
{
updateCreateButton();
fileBrowser.setFileName (File::createLegalFileName (projectName.getText()));
};
addChildAndSetID (&projectType, "projectType");
projectType.addItemList (getWizardNames(), 1);
projectType.setSelectedId (1, dontSendNotification);
typeLabel.attachToComponent (&projectType, true);
projectType.addListener (this);
projectType.onChange = [this] { updateFileCreationTypes(); };
addChildAndSetID (&fileOutline, "fileOutline");
fileOutline.setColour (GroupComponent::outlineColourId, Colours::black.withAlpha (0.2f));
@@ -447,17 +444,6 @@ public:
filesToCreate.setSelectedId (1, dontSendNotification);
}
void comboBoxChanged (ComboBox*) override
{
updateFileCreationTypes();
}
void textEditorTextChanged (TextEditor&) override
{
updateCreateButton();
fileBrowser.setFileName (File::createLegalFileName (projectName.getText()));
}
void selectionChanged() override {}
void fileClicked (const File&, const MouseEvent&) override {}


+ 4
- 9
extras/Projucer/Source/Wizards/jucer_TemplateThumbnailsComponent.h View File

@@ -134,8 +134,7 @@ private:
Project Template Component for front page.
Features multiple icon buttons to select the type of project template
*/
class TemplateTileBrowser : public Component,
private Button::Listener
class TemplateTileBrowser : public Component
{
public:
TemplateTileBrowser (WizardComp* projectWizard)
@@ -152,7 +151,8 @@ public:
optionButtons.add (b);
addAndMakeVisible (b);
b->setDescription (wizard->getDescription());
b->addListener (this);
b->onClick = [this, b] { showWizardButton (b); };
b->onStateChange = [this] { repaint(); };
}
// Handle Open Project button functionality
@@ -262,16 +262,11 @@ private:
NewProjectWizardClasses::WizardComp* newProjectWizard;
ScopedPointer<TemplateOptionButton> blankProjectButton, openProjectButton, exampleProjectButton;
void buttonClicked (Button* b) override
void showWizardButton (Button* b)
{
if (dynamic_cast<TemplateOptionButton*> (b) != nullptr)
showWizard (b->getButtonText());
}
void buttonStateChanged (Button*) override
{
repaint();
}
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (TemplateTileBrowser)
};

+ 9
- 17
modules/juce_gui_basics/filebrowser/juce_FileBrowserComponent.cpp View File

@@ -99,7 +99,14 @@ FileBrowserComponent::FileBrowserComponent (int flags_,
filenameBox.setMultiLine (false);
filenameBox.setSelectAllWhenFocused (true);
filenameBox.setText (filename, false);
filenameBox.addListener (this);
filenameBox.onTextChange = [this] { sendListenerChangeMessage(); };
filenameBox.onReturnKey = [this] { changeFilename(); };
filenameBox.onFocusLost = [this]
{
if (! isSaveMode())
selectionChanged();
};
filenameBox.setReadOnly ((flags & (filenameBoxIsReadOnly | canSelectMultipleItems)) != 0);
addAndMakeVisible (fileLabel);
@@ -439,12 +446,7 @@ bool FileBrowserComponent::keyPressed (const KeyPress& key)
}
//==============================================================================
void FileBrowserComponent::textEditorTextChanged (TextEditor&)
{
sendListenerChangeMessage();
}
void FileBrowserComponent::textEditorReturnKeyPressed (TextEditor&)
void FileBrowserComponent::changeFilename()
{
if (filenameBox.getText().containsChar (File::getSeparatorChar()))
{
@@ -472,16 +474,6 @@ void FileBrowserComponent::textEditorReturnKeyPressed (TextEditor&)
}
}
void FileBrowserComponent::textEditorEscapeKeyPressed (TextEditor&)
{
}
void FileBrowserComponent::textEditorFocusLost (TextEditor&)
{
if (! isSaveMode())
selectionChanged();
}
//==============================================================================
void FileBrowserComponent::updateSelectedPath()
{


+ 1
- 9
modules/juce_gui_basics/filebrowser/juce_FileBrowserComponent.h View File

@@ -39,7 +39,6 @@ namespace juce
*/
class JUCE_API FileBrowserComponent : public Component,
private FileBrowserListener,
private TextEditor::Listener,
private FileFilter,
private Timer
{
@@ -235,14 +234,6 @@ public:
/** @internal */
void lookAndFeelChanged() override;
/** @internal */
void textEditorTextChanged (TextEditor&) override;
/** @internal */
void textEditorReturnKeyPressed (TextEditor&) override;
/** @internal */
void textEditorEscapeKeyPressed (TextEditor&) override;
/** @internal */
void textEditorFocusLost (TextEditor&) override;
/** @internal */
bool keyPressed (const KeyPress&) override;
/** @internal */
void selectionChanged() override;
@@ -295,6 +286,7 @@ private:
void sendListenerChangeMessage();
bool isFileOrDirSuitable (const File&) const;
void updateSelectedPath();
void changeFilename();
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (FileBrowserComponent)
};


+ 2
- 2
modules/juce_gui_basics/properties/juce_ChoicePropertyComponent.cpp View File

@@ -239,14 +239,14 @@ void ChoicePropertyComponent::refresh()
if (! comboBox.isVisible())
{
createComboBox();
comboBox.addListener (this);
comboBox.onChange = [this] { changeIndex(); };
}
comboBox.setSelectedId (getIndex() + 1, dontSendNotification);
}
}
void ChoicePropertyComponent::comboBoxChanged (ComboBox*)
void ChoicePropertyComponent::changeIndex()
{
if (isCustomClass)
{


+ 2
- 3
modules/juce_gui_basics/properties/juce_ChoicePropertyComponent.h View File

@@ -46,8 +46,7 @@ namespace juce
@see PropertyComponent, PropertyPanel
*/
class JUCE_API ChoicePropertyComponent : public PropertyComponent,
private ComboBox::Listener
class JUCE_API ChoicePropertyComponent : public PropertyComponent
{
protected:
/** Creates the component.
@@ -146,7 +145,7 @@ private:
void createComboBox();
void createComboBoxWithDefault (const String&);
void comboBoxChanged (ComboBox*) override;
void changeIndex();
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ChoicePropertyComponent)
};


+ 5
- 7
modules/juce_gui_basics/properties/juce_SliderPropertyComponent.cpp View File

@@ -41,7 +41,11 @@ SliderPropertyComponent::SliderPropertyComponent (const String& name,
slider.setSkewFactor (skewFactor, symmetricSkew);
slider.setSliderStyle (Slider::LinearBar);
slider.addListener (this);
slider.onValueChange = [this]
{
if (getValue() != slider.getValue())
setValue (slider.getValue());
};
}
SliderPropertyComponent::SliderPropertyComponent (const Value& valueToControl,
@@ -80,10 +84,4 @@ void SliderPropertyComponent::refresh()
slider.setValue (getValue(), dontSendNotification);
}
void SliderPropertyComponent::sliderValueChanged (Slider*)
{
if (getValue() != slider.getValue())
setValue (slider.getValue());
}
} // namespace juce

+ 1
- 4
modules/juce_gui_basics/properties/juce_SliderPropertyComponent.h View File

@@ -33,8 +33,7 @@ namespace juce
@see PropertyComponent, Slider
*/
class JUCE_API SliderPropertyComponent : public PropertyComponent,
private Slider::Listener
class JUCE_API SliderPropertyComponent : public PropertyComponent
{
protected:
//==============================================================================
@@ -92,8 +91,6 @@ public:
//==============================================================================
/** @internal */
void refresh();
/** @internal */
void sliderValueChanged (Slider*);
protected:
/** The slider component being used in this component.


+ 1
- 7
modules/juce_gui_basics/widgets/juce_ComboBox.cpp View File

@@ -431,7 +431,7 @@ void ComboBox::lookAndFeelChanged()
setWantsKeyboardFocus (labelEditableState == labelIsNotEditable);
}
label->addListener (this);
label->onTextChange = [this] { triggerAsyncUpdate(); };
label->addMouseListener (this, false);
label->setColour (Label::backgroundColourId, Colours::transparentBlack);
@@ -483,12 +483,6 @@ bool ComboBox::keyStateChanged (const bool isKeyDown)
void ComboBox::focusGained (FocusChangeType) { repaint(); }
void ComboBox::focusLost (FocusChangeType) { repaint(); }
void ComboBox::labelTextChanged (Label*)
{
triggerAsyncUpdate();
}
//==============================================================================
void ComboBox::showPopupIfNotActive()
{


+ 0
- 3
modules/juce_gui_basics/widgets/juce_ComboBox.h View File

@@ -43,7 +43,6 @@ namespace juce
*/
class JUCE_API ComboBox : public Component,
public SettableTooltipClient,
public Label::Listener,
public Value::Listener,
private AsyncUpdater
{
@@ -379,8 +378,6 @@ public:
//==============================================================================
/** @internal */
void labelTextChanged (Label*) override;
/** @internal */
void enablementChanged() override;
/** @internal */
void colourChanged() override;


+ 3
- 4
modules/juce_gui_basics/widgets/juce_Slider.cpp View File

@@ -29,7 +29,6 @@ namespace juce
class Slider::Pimpl : public AsyncUpdater, // this needs to be public otherwise it will cause an
// error when JUCE_DLL_BUILD=1
private Label::Listener,
private Value::Listener
{
public:
@@ -398,9 +397,9 @@ public:
setMaxValue (valueMax.getValue(), dontSendNotification, true);
}
void labelTextChanged (Label* label) override
void textChanged()
{
auto newValue = owner.snapValue (owner.getValueFromText (label->getText()), notDragging);
auto newValue = owner.snapValue (owner.getValueFromText (valueBox->getText()), notDragging);
if (newValue != static_cast<double> (currentValue.getValue()))
{
@@ -572,7 +571,7 @@ public:
valueBox->setText (previousTextBoxContent, dontSendNotification);
valueBox->setTooltip (owner.getTooltip());
updateTextBoxEnablement();
valueBox->addListener (this);
valueBox->onTextChange = [this] { textChanged(); };
if (style == LinearBar || style == LinearBarVertical)
{


+ 2
- 2
modules/juce_gui_basics/windows/juce_AlertWindow.cpp View File

@@ -81,7 +81,7 @@ void AlertWindow::setMessage (const String& message)
}
//==============================================================================
void AlertWindow::buttonClicked (Button* button)
void AlertWindow::exitAlert (Button* button)
{
if (auto* parent = button->getParentComponent())
parent->exitModalState (button->getCommandID());
@@ -101,7 +101,7 @@ void AlertWindow::addButton (const String& name,
b->setCommandToTrigger (0, returnValue, false);
b->addShortcut (shortcutKey1);
b->addShortcut (shortcutKey2);
b->addListener (this);
b->onClick = [this, b] { exitAlert (b); };
Array<TextButton*> buttonsArray (buttons.begin(), buttons.size());
auto& lf = getLookAndFeel();


+ 2
- 4
modules/juce_gui_basics/windows/juce_AlertWindow.h View File

@@ -40,8 +40,7 @@ namespace juce
@see ThreadWithProgressWindow
*/
class JUCE_API AlertWindow : public TopLevelWindow,
private Button::Listener
class JUCE_API AlertWindow : public TopLevelWindow
{
public:
//==============================================================================
@@ -455,8 +454,6 @@ protected:
/** @internal */
bool keyPressed (const KeyPress&) override;
/** @internal */
void buttonClicked (Button*) override;
/** @internal */
void lookAndFeelChanged() override;
/** @internal */
void userTriedToCloseWindow() override;
@@ -482,6 +479,7 @@ private:
Component* const associatedComponent;
bool escapeKeyCancels = true;
void exitAlert (Button* button);
void updateLayout (bool onlyIncreaseSize);
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (AlertWindow)


+ 2
- 2
modules/juce_gui_extra/misc/juce_ColourSelector.cpp View File

@@ -335,7 +335,7 @@ ColourSelector::ColourSelector (int sectionsToShow, int edge, int gapAroundColou
sliders[3]->setVisible ((flags & showAlphaChannel) != 0);
for (int i = 4; --i >= 0;)
sliders[i]->addListener (this);
sliders[i]->onValueChange = [this] { changeColour(); };
}
if ((flags & showColourspace) != 0)
@@ -554,7 +554,7 @@ void ColourSelector::resized()
}
}
void ColourSelector::sliderValueChanged (Slider*)
void ColourSelector::changeColour()
{
if (sliders[0] != nullptr)
setCurrentColour (Colour ((uint8) sliders[0]->getValue(),


+ 2
- 3
modules/juce_gui_extra/misc/juce_ColourSelector.h View File

@@ -37,8 +37,7 @@ namespace juce
when the colour changes.
*/
class JUCE_API ColourSelector : public Component,
public ChangeBroadcaster,
protected Slider::Listener
public ChangeBroadcaster
{
public:
//==============================================================================
@@ -160,7 +159,7 @@ private:
void setSV (float newS, float newV);
void updateHSV();
void update (NotificationType);
void sliderValueChanged (Slider*) override;
void changeColour();
void paint (Graphics&) override;
void resized() override;


+ 14
- 28
modules/juce_gui_extra/misc/juce_LiveConstantEditor.cpp View File

@@ -144,10 +144,10 @@ LivePropertyEditorBase::LivePropertyEditorBase (LiveValueBase& v, CodeDocument&
valueEditor.setMultiLine (v.isString());
valueEditor.setReturnKeyStartsNewLine (v.isString());
valueEditor.setText (v.getStringValue (wasHex), dontSendNotification);
valueEditor.addListener (this);
valueEditor.onTextChange = [this] { applyNewValue (valueEditor.getText()); };
sourceEditor.setReadOnly (true);
sourceEditor.setFont (sourceEditor.getFont().withHeight (13.0f));
resetButton.addListener (this);
resetButton.onClick = [this] { applyNewValue (value.getOriginalStringValue (wasHex)); };
}
void LivePropertyEditorBase::paint (Graphics& g)
@@ -181,16 +181,6 @@ void LivePropertyEditorBase::resized()
sourceEditor.setBounds (r);
}
void LivePropertyEditorBase::textEditorTextChanged (TextEditor&)
{
applyNewValue (valueEditor.getText());
}
void LivePropertyEditorBase::buttonClicked (Button*)
{
applyNewValue (value.getOriginalStringValue (wasHex));
}
void LivePropertyEditorBase::applyNewValue (const String& s)
{
value.setStringValue (s);
@@ -444,8 +434,7 @@ Component* createColourEditor (LivePropertyEditorBase& editor)
}
//==============================================================================
struct SliderComp : public Component,
private Slider::Listener
struct SliderComp : public Component
{
SliderComp (LivePropertyEditorBase& e, bool useFloat)
: editor (e), isFloat (useFloat)
@@ -453,7 +442,12 @@ struct SliderComp : public Component,
slider.setTextBoxStyle (Slider::NoTextBox, true, 0, 0);
addAndMakeVisible (slider);
updateRange();
slider.addListener (this);
slider.onDragEnd = [this] { updateRange(); };
slider.onValueChange = [this]
{
editor.applyNewValue (isFloat ? getAsString ((double) slider.getValue(), editor.wasHex)
: getAsString ((int64) slider.getValue(), editor.wasHex));
};
}
virtual void updateRange()
@@ -467,16 +461,6 @@ struct SliderComp : public Component,
slider.setValue (v, dontSendNotification);
}
void sliderValueChanged (Slider*) override
{
editor.applyNewValue (isFloat ? getAsString ((double) slider.getValue(), editor.wasHex)
: getAsString ((int64) slider.getValue(), editor.wasHex));
}
void sliderDragStarted (Slider*) override {}
void sliderDragEnded (Slider*) override { updateRange(); }
void resized() override
{
slider.setBounds (getLocalBounds().removeFromTop (25));
@@ -490,15 +474,17 @@ struct SliderComp : public Component,
//==============================================================================
struct BoolSliderComp : public SliderComp
{
BoolSliderComp (LivePropertyEditorBase& e) : SliderComp (e, false) {}
BoolSliderComp (LivePropertyEditorBase& e)
: SliderComp (e, false)
{
slider.onValueChange = [this] { editor.applyNewValue (slider.getValue() > 0.5 ? "true" : "false"); };
}
void updateRange() override
{
slider.setRange (0.0, 1.0, dontSendNotification);
slider.setValue (editor.value.getStringValue (false) == "true", dontSendNotification);
}
void sliderValueChanged (Slider*) override { editor.applyNewValue (slider.getValue() > 0.5 ? "true" : "false"); }
};
Component* createIntegerSlider (LivePropertyEditorBase& editor) { return new SliderComp (editor, false); }


+ 1
- 5
modules/juce_gui_extra/misc/juce_LiveConstantEditor.h View File

@@ -106,16 +106,12 @@ namespace LiveConstantEditor
};
//==============================================================================
struct JUCE_API LivePropertyEditorBase : public Component,
private TextEditor::Listener,
private Button::Listener
struct JUCE_API LivePropertyEditorBase : public Component
{
LivePropertyEditorBase (LiveValueBase&, CodeDocument&);
void paint (Graphics&) override;
void resized() override;
void textEditorTextChanged (TextEditor&) override;
void buttonClicked (Button*) override;
void applyNewValue (const String&);
void selectOriginalValue();


+ 2
- 2
modules/juce_gui_extra/misc/juce_PreferencesPanel.cpp View File

@@ -58,7 +58,7 @@ void PreferencesPanel::addSettingsPage (const String& title,
button->setImages (icon, overIcon, downIcon);
button->setRadioGroupId (1);
button->addListener (this);
button->onClick = [this] { clickedPage(); };
button->setClickingTogglesState (true);
button->setWantsKeyboardFocus (false);
addAndMakeVisible (button);
@@ -142,7 +142,7 @@ void PreferencesPanel::setCurrentPage (const String& pageName)
}
}
void PreferencesPanel::buttonClicked (Button*)
void PreferencesPanel::clickedPage()
{
for (auto* b : buttons)
{


+ 3
- 4
modules/juce_gui_extra/misc/juce_PreferencesPanel.h View File

@@ -44,8 +44,7 @@ namespace juce
and implement the createComponentForPage() method to create suitable components
for each of these pages.
*/
class JUCE_API PreferencesPanel : public Component,
private Button::Listener
class JUCE_API PreferencesPanel : public Component
{
public:
//==============================================================================
@@ -131,8 +130,6 @@ public:
void resized() override;
/** @internal */
void paint (Graphics&) override;
/** @internal */
void buttonClicked (Button*) override;
private:
//==============================================================================
@@ -141,6 +138,8 @@ private:
OwnedArray<DrawableButton> buttons;
int buttonSize;
void clickedPage();
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (PreferencesPanel)
};


Loading…
Cancel
Save