Browse Source

Updated Button::onClick and added ComboBox::onChange

tags/2021-05-28
jules 7 years ago
parent
commit
e7a5e520c6
20 changed files with 83 additions and 206 deletions
  1. +2
    -3
      examples/Demo/Source/Demos/CameraDemo.cpp
  2. +11
    -11
      examples/Demo/Source/Demos/FlexBoxDemo.cpp
  3. +3
    -9
      examples/Demo/Source/Demos/FontsDemo.cpp
  4. +2
    -9
      examples/Demo/Source/Demos/LookAndFeelDemo.cpp
  5. +11
    -19
      examples/Demo/Source/Demos/MidiDemo.cpp
  6. +2
    -11
      examples/Demo/Source/Demos/OpenGLDemo.cpp
  7. +3
    -9
      examples/Demo/Source/Demos/OpenGLDemo2D.cpp
  8. +2
    -9
      examples/Demo/Source/Demos/WidgetsDemo.cpp
  9. +8
    -13
      examples/Demo/Source/Demos/XMLandJSONDemo.cpp
  10. +15
    -17
      modules/juce_audio_utils/gui/juce_AudioDeviceSelectorComponent.cpp
  11. +2
    -2
      modules/juce_audio_utils/gui/juce_AudioDeviceSelectorComponent.h
  12. +0
    -75
      modules/juce_events/broadcasters/juce_EventHandler.h
  13. +0
    -1
      modules/juce_events/juce_events.h
  14. +4
    -2
      modules/juce_gui_basics/buttons/juce_Button.cpp
  15. +2
    -2
      modules/juce_gui_basics/buttons/juce_Button.h
  16. +1
    -6
      modules/juce_gui_basics/filebrowser/juce_FilenameComponent.cpp
  17. +1
    -3
      modules/juce_gui_basics/filebrowser/juce_FilenameComponent.h
  18. +6
    -0
      modules/juce_gui_basics/widgets/juce_ComboBox.cpp
  19. +4
    -0
      modules/juce_gui_basics/widgets/juce_ComboBox.h
  20. +4
    -5
      modules/juce_gui_basics/widgets/juce_Toolbar.cpp

+ 2
- 3
examples/Demo/Source/Demos/CameraDemo.cpp View File

@@ -30,7 +30,6 @@
//==============================================================================
class CameraDemo : public Component,
private ComboBox::Listener,
private CameraDevice::Listener,
private AsyncUpdater
{
@@ -46,7 +45,7 @@ public:
addAndMakeVisible (cameraSelectorComboBox);
updateCameraList();
cameraSelectorComboBox.setSelectedId (1);
cameraSelectorComboBox.addListener (this);
cameraSelectorComboBox.onChange = [this] { cameraChanged(); };
addAndMakeVisible (snapshotButton);
snapshotButton.onClick = [this]() { takeSnapshot(); };
@@ -117,7 +116,7 @@ private:
cameraSelectorComboBox.addItem (cameras[i], i + 2);
}
void comboBoxChanged (ComboBox*) override
void cameraChanged()
{
// This is called when the user chooses a camera from the drop-down list.
cameraDevice = nullptr;


+ 11
- 11
examples/Demo/Source/Demos/FlexBoxDemo.cpp View File

@@ -30,8 +30,7 @@
#if JUCE_COMPILER_SUPPORTS_INITIALIZER_LISTS
struct DemoFlexPanel : public juce::Component,
private juce::TextEditor::Listener,
private juce::ComboBox::Listener
private juce::TextEditor::Listener
{
DemoFlexPanel (juce::Colour col, FlexItem& item) : flexItem (item), colour (col)
{
@@ -61,7 +60,7 @@ struct DemoFlexPanel : public juce::Component,
alignSelfCombo.addItem ("stretch", 5);
alignSelfCombo.setBounds (x, y, 90, 18);
alignSelfCombo.addListener (this);
alignSelfCombo.onChange = [this] { updateAssignSelf(); };
alignSelfCombo.setSelectedId (5);
alignSelfCombo.setColour (ComboBox::outlineColourId, Colours::transparentBlack);
addAndMakeVisible (alignSelfCombo);
@@ -85,15 +84,16 @@ struct DemoFlexPanel : public juce::Component,
addAndMakeVisible (label);
}
void comboBoxChanged (ComboBox* cb) override
void updateAssignSelf()
{
auto selectedID = cb->getSelectedId();
if (selectedID == 1) flexItem.alignSelf = FlexItem::AlignSelf::autoAlign;
if (selectedID == 2) flexItem.alignSelf = FlexItem::AlignSelf::flexStart;
if (selectedID == 3) flexItem.alignSelf = FlexItem::AlignSelf::flexEnd;
if (selectedID == 4) flexItem.alignSelf = FlexItem::AlignSelf::center;
if (selectedID == 5) flexItem.alignSelf = FlexItem::AlignSelf::stretch;
switch (alignSelfCombo.getSelectedId())
{
case 1: flexItem.alignSelf = FlexItem::AlignSelf::autoAlign; break;
case 2: flexItem.alignSelf = FlexItem::AlignSelf::flexStart; break;
case 3: flexItem.alignSelf = FlexItem::AlignSelf::flexEnd; break;
case 4: flexItem.alignSelf = FlexItem::AlignSelf::center; break;
case 5: flexItem.alignSelf = FlexItem::AlignSelf::stretch; break;
}
if (auto parent = getParentComponent())
parent->resized();


+ 3
- 9
examples/Demo/Source/Demos/FontsDemo.cpp View File

@@ -30,8 +30,7 @@
//==============================================================================
class FontsDemo : public Component,
private ListBoxModel,
private Slider::Listener,
private ComboBox::Listener
private Slider::Listener
{
public:
FontsDemo()
@@ -58,9 +57,10 @@ public:
heightSlider.addListener (this);
kerningSlider.addListener (this);
scaleSlider.addListener (this);
boldToggle.onClick = [this]() { refreshPreviewBoxFont(); };
italicToggle.onClick = [this]() { refreshPreviewBoxFont(); };
styleBox.addListener (this);
styleBox.onChange = [this]() { refreshPreviewBoxFont(); };
Font::findFonts (fonts); // Generate the list of fonts
@@ -244,12 +244,6 @@ private:
}
}
void comboBoxChanged (ComboBox* box) override
{
if (box == &styleBox)
refreshPreviewBoxFont();
}
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (FontsDemo)
};


+ 2
- 9
examples/Demo/Source/Demos/LookAndFeelDemo.cpp View File

@@ -504,8 +504,7 @@ struct LookAndFeelDemoComponent : public Component
};
//==============================================================================
class LookAndFeelDemo : public Component,
private ComboBox::Listener
class LookAndFeelDemo : public Component
{
public:
LookAndFeelDemo()
@@ -536,7 +535,7 @@ public:
addLookAndFeel (slaf, "Square Look And Feel");
setupSquareLookAndFeelColours (*slaf);
lafBox.addListener (this);
lafBox.onChange = [this]() { setAllLookAndFeels (lookAndFeels[lafBox.getSelectedItemIndex()]); };
lafBox.setSelectedItemIndex (3);
addAndMakeVisible (randomButton);
@@ -612,12 +611,6 @@ private:
child->setLookAndFeel (laf);
}
void comboBoxChanged (ComboBox* comboBoxThatHasChanged) override
{
if (comboBoxThatHasChanged == &lafBox)
setAllLookAndFeels (lookAndFeels[lafBox.getSelectedItemIndex()]);
}
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (LookAndFeelDemo)
};


+ 11
- 19
examples/Demo/Source/Demos/MidiDemo.cpp View File

@@ -68,7 +68,6 @@ private:
//==============================================================================
class MidiDemo : public Component,
private ComboBox::Listener,
private MidiInputCallback,
private MidiKeyboardStateListener,
private AsyncUpdater
@@ -76,7 +75,6 @@ class MidiDemo : public Component,
public:
MidiDemo()
: deviceManager (MainAppWindow::getSharedAudioDeviceManager()),
lastInputIndex (0), isAddingFromMidiInput (false),
keyboardComponent (keyboardState, MidiKeyboardComponent::horizontalKeyboard),
midiLogListBoxModel (midiMessageList)
{
@@ -89,9 +87,10 @@ public:
addAndMakeVisible (midiInputList);
midiInputList.setTextWhenNoChoicesAvailable ("No MIDI Inputs Enabled");
const StringArray midiInputs (MidiInput::getDevices());
auto midiInputs = MidiInput::getDevices();
midiInputList.addItemList (midiInputs, 1);
midiInputList.addListener (this);
midiInputList.onChange = [this]() { setMidiInput (midiInputList.getSelectedItemIndex()); };
// find the first enabled device and use that by default
for (int i = 0; i < midiInputs.size(); ++i)
@@ -116,7 +115,7 @@ public:
addAndMakeVisible (midiOutputList);
midiOutputList.setTextWhenNoChoicesAvailable ("No MIDI Output Enabled");
midiOutputList.addItemList (MidiOutput::getDevices(), 1);
midiOutputList.addListener (this);
midiOutputList.onChange = [this]() { setMidiOutput (midiOutputList.getSelectedItemIndex()); };
addAndMakeVisible (keyboardComponent);
keyboardState.addListener (this);
@@ -129,7 +128,6 @@ public:
{
keyboardState.removeListener (this);
deviceManager.removeMidiInputCallback (MidiInput::getDevices()[midiInputList.getSelectedItemIndex()], this);
midiInputList.removeListener (this);
}
void paint (Graphics& g) override
@@ -139,7 +137,7 @@ public:
void resized() override
{
Rectangle<int> area (getLocalBounds());
auto area = getLocalBounds();
midiInputList.setBounds (area.removeFromTop (36).removeFromRight (getWidth() - 150).reduced (8));
midiOutputList.setBounds (area.removeFromTop (36).removeFromRight (getWidth() - 150).reduced (8));
keyboardComponent.setBounds (area.removeFromTop (80).reduced(8));
@@ -150,8 +148,8 @@ private:
AudioDeviceManager& deviceManager;
ComboBox midiInputList, midiOutputList;
Label midiInputListLabel, midiOutputListLabel;
int lastInputIndex;
bool isAddingFromMidiInput;
int lastInputIndex = 0;
bool isAddingFromMidiInput = false;
MidiKeyboardState keyboardState;
MidiKeyboardComponent keyboardComponent;
@@ -165,11 +163,11 @@ private:
/** Starts listening to a MIDI input device, enabling it if necessary. */
void setMidiInput (int index)
{
const StringArray list (MidiInput::getDevices());
auto list = MidiInput::getDevices();
deviceManager.removeMidiInputCallback (list[lastInputIndex], this);
const String newInput (list[index]);
auto newInput = list[index];
if (! deviceManager.isMidiInputEnabled (newInput))
deviceManager.setMidiInputEnabled (newInput, true);
@@ -192,12 +190,6 @@ private:
}
}
void comboBoxChanged (ComboBox* box) override
{
if (box == &midiInputList) setMidiInput (midiInputList.getSelectedItemIndex());
if (box == &midiOutputList) setMidiOutput (midiOutputList.getSelectedItemIndex());
}
// These methods handle callbacks from the midi device + on-screen keyboard..
void handleIncomingMidiMessage (MidiInput*, const MidiMessage& message) override
{
@@ -210,7 +202,7 @@ private:
{
if (! isAddingFromMidiInput)
{
MidiMessage m (MidiMessage::noteOn (midiChannel, midiNoteNumber, velocity));
auto m = MidiMessage::noteOn (midiChannel, midiNoteNumber, velocity);
m.setTimeStamp (Time::getMillisecondCounterHiRes() * 0.001);
postMessageToList (m);
}
@@ -220,7 +212,7 @@ private:
{
if (! isAddingFromMidiInput)
{
MidiMessage m (MidiMessage::noteOff (midiChannel, midiNoteNumber, velocity));
auto m = MidiMessage::noteOff (midiChannel, midiNoteNumber, velocity);
m.setTimeStamp (Time::getMillisecondCounterHiRes() * 0.001);
postMessageToList (m);
}


+ 2
- 11
examples/Demo/Source/Demos/OpenGLDemo.cpp View File

@@ -329,7 +329,6 @@ struct OpenGLDemoClasses
*/
class DemoControlsOverlay : public Component,
private CodeDocument::Listener,
private ComboBox::Listener,
private Slider::Listener,
private Timer
{
@@ -378,11 +377,11 @@ struct OpenGLDemoClasses
textures.add (new DynamicTexture());
addAndMakeVisible (textureBox);
textureBox.addListener (this);
textureBox.onChange = [this]() { selectTexture (textureBox.getSelectedId()); };
updateTexturesList();
addAndMakeVisible (presetBox);
presetBox.addListener (this);
presetBox.onChange = [this]() { selectPreset (presetBox.getSelectedItemIndex()); };
auto presets = getPresets();
StringArray presetNames;
@@ -539,14 +538,6 @@ struct OpenGLDemoClasses
fragmentDocument.getAllContent());
}
void comboBoxChanged (ComboBox* box) override
{
if (box == &presetBox)
selectPreset (presetBox.getSelectedItemIndex());
else if (box == &textureBox)
selectTexture (textureBox.getSelectedId());
}
void lookAndFeelChanged() override
{
auto editorBackground = getUIColourIfAvailable (LookAndFeel_V4::ColourScheme::UIColour::windowBackground,


+ 3
- 9
examples/Demo/Source/Demos/OpenGLDemo2D.cpp View File

@@ -31,7 +31,6 @@
//==============================================================================
class OpenGL2DShaderDemo : public Component,
private CodeDocument::Listener,
private ComboBox::Listener,
private Timer
{
public:
@@ -40,14 +39,14 @@ public:
{
setOpaque (true);
if (MainAppWindow* mw = MainAppWindow::getMainAppWindow())
if (auto* mw = MainAppWindow::getMainAppWindow())
mw->setOpenGLRenderingEngine();
addAndMakeVisible (statusLabel);
statusLabel.setJustificationType (Justification::topLeft);
statusLabel.setFont (Font (14.0f));
Array<ShaderPreset> presets (getPresets());
auto presets = getPresets();
StringArray presetNames;
for (int i = 0; i < presets.size(); ++i)
@@ -58,7 +57,7 @@ public:
presetLabel.attachToComponent (&presetBox, true);
addAndMakeVisible (presetBox);
presetBox.addListener (this);
presetBox.onChange = [this]() { selectPreset (presetBox.getSelectedItemIndex()); };
fragmentEditorComp.setOpaque (false);
fragmentDocument.addListener (this);
@@ -152,11 +151,6 @@ private:
repaint();
}
void comboBoxChanged (ComboBox*) override
{
selectPreset (presetBox.getSelectedItemIndex());
}
struct ShaderPreset
{
const char* name;


+ 2
- 9
examples/Demo/Source/Demos/WidgetsDemo.cpp View File

@@ -950,8 +950,7 @@ private:
//==============================================================================
// This is a custom component containing a combo box, which we're going to put inside
// our table's "rating" column.
class RatingColumnCustomComponent : public Component,
private ComboBox::Listener
class RatingColumnCustomComponent : public Component
{
public:
RatingColumnCustomComponent (TableDemoComponent& td) : owner (td)
@@ -966,8 +965,7 @@ private:
comboBox.addItem ("swingin", 6);
comboBox.addItem ("wild", 7);
// when the combo is changed, we'll get a callback.
comboBox.addListener (this);
comboBox.onChange = [this]() { owner.setRating (row, comboBox.getSelectedId()); };
comboBox.setWantsKeyboardFocus (false);
}
@@ -984,11 +982,6 @@ private:
comboBox.setSelectedId (owner.getRating (row), dontSendNotification);
}
void comboBoxChanged (ComboBox*) override
{
owner.setRating (row, comboBox.getSelectedId());
}
private:
TableDemoComponent& owner;
ComboBox comboBox;


+ 8
- 13
examples/Demo/Source/Demos/XMLandJSONDemo.cpp View File

@@ -208,7 +208,6 @@ private:
//==============================================================================
class StringsDemo : public Component,
private ComboBox::Listener,
private CodeDocument::Listener
{
public:
@@ -225,10 +224,17 @@ public:
setOpaque (true);
addAndMakeVisible (typeBox);
typeBox.addListener (this);
typeBox.addItem ("XML", 1);
typeBox.addItem ("JSON", 2);
typeBox.onChange = [this]()
{
if (typeBox.getSelectedId() == 1)
reset (xml);
else
reset (json);
};
comboBoxLabel.setText ("Database Type:", dontSendNotification);
comboBoxLabel.attachToComponent (&typeBox, true);
@@ -364,17 +370,6 @@ private:
}
}
void comboBoxChanged (ComboBox* box) override
{
if (box == &typeBox)
{
if (typeBox.getSelectedId() == 1)
reset (xml);
else
reset (json);
}
}
void codeDocumentTextInserted (const String&, int) override { rebuildTree(); }
void codeDocumentTextDeleted (int, int) override { rebuildTree(); }


+ 15
- 17
modules/juce_audio_utils/gui/juce_AudioDeviceSelectorComponent.cpp View File

@@ -985,7 +985,7 @@ AudioDeviceSelectorComponent::AudioDeviceSelectorComponent (AudioDeviceManager&
deviceTypeDropDown->addItem (types.getUnchecked(i)->getTypeName(), i + 1);
addAndMakeVisible (deviceTypeDropDown);
deviceTypeDropDown->addListener (this);
deviceTypeDropDown->onChange = [this]() { updateDeviceType(); };
deviceTypeDropDownLabel = new Label ({}, TRANS("Audio device type:"));
deviceTypeDropDownLabel->setJustificationType (Justification::centredRight);
@@ -1019,7 +1019,7 @@ AudioDeviceSelectorComponent::AudioDeviceSelectorComponent (AudioDeviceManager&
if (showMidiOutputSelector)
{
addAndMakeVisible (midiOutputSelector = new ComboBox());
midiOutputSelector->addListener (this);
midiOutputSelector->onChange = [this]() { updateMidiOutput(); };
midiOutputLabel = new Label ("lm", TRANS("MIDI Output:"));
midiOutputLabel->attachToComponent (midiOutputSelector, true);
@@ -1095,26 +1095,24 @@ void AudioDeviceSelectorComponent::timerCallback()
updateAllControls();
}
void AudioDeviceSelectorComponent::comboBoxChanged (ComboBox* comboBoxThatHasChanged)
void AudioDeviceSelectorComponent::updateDeviceType()
{
if (comboBoxThatHasChanged == deviceTypeDropDown)
if (auto* type = deviceManager.getAvailableDeviceTypes() [deviceTypeDropDown->getSelectedId() - 1])
{
if (auto* type = deviceManager.getAvailableDeviceTypes() [deviceTypeDropDown->getSelectedId() - 1])
{
audioDeviceSettingsComp.reset();
deviceManager.setCurrentAudioDeviceType (type->getTypeName(), true);
updateAllControls(); // needed in case the type hasn't actually changed
}
audioDeviceSettingsComp.reset();
deviceManager.setCurrentAudioDeviceType (type->getTypeName(), true);
updateAllControls(); // needed in case the type hasn't actually changed
}
else if (comboBoxThatHasChanged == midiOutputSelector)
{
auto midiDeviceName = midiOutputSelector->getText();
}
void AudioDeviceSelectorComponent::updateMidiOutput()
{
auto midiDeviceName = midiOutputSelector->getText();
if (midiDeviceName == getNoDeviceString())
midiDeviceName = {};
if (midiDeviceName == getNoDeviceString())
midiDeviceName = {};
deviceManager.setDefaultMidiOutput (midiDeviceName);
}
deviceManager.setDefaultMidiOutput (midiDeviceName);
}
void AudioDeviceSelectorComponent::changeListenerCallback (ChangeBroadcaster*)


+ 2
- 2
modules/juce_audio_utils/gui/juce_AudioDeviceSelectorComponent.h View File

@@ -38,7 +38,6 @@ namespace juce
*/
class JUCE_API AudioDeviceSelectorComponent : public Component,
private ChangeListener,
private ComboBox::Listener,
private Timer
{
public:
@@ -111,7 +110,8 @@ private:
ScopedPointer<TextButton> bluetoothButton;
void handleBluetoothButton();
void comboBoxChanged (ComboBox*) override;
void updateDeviceType();
void updateMidiOutput();
void changeListenerCallback (ChangeBroadcaster*) override;
void updateAllControls();


+ 0
- 75
modules/juce_events/broadcasters/juce_EventHandler.h View File

@@ -1,75 +0,0 @@
/*
==============================================================================
This file is part of the JUCE library.
Copyright (c) 2017 - ROLI Ltd.
JUCE is an open source library subject to commercial or open-source
licensing.
The code included in this file is provided under the terms of the ISC license
http://www.isc.org/downloads/software-support-policy/isc-license. Permission
To use, copy, modify, and/or distribute this software for any purpose with or
without fee is hereby granted provided that the above copyright notice and
this permission notice appear in all copies.
JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
DISCLAIMED.
==============================================================================
*/
namespace juce
{
//==============================================================================
/**
Helper class for dispatching callbacks to a lambda function.
This class probably isn't something many users will use in their own code, but
some juce classes use it as a helper to allow lambdas to be assigned to callback
hooks - e.g. see its use in Button::onClick
*/
template <typename OwnerClass>
struct EventHandler
{
EventHandler() {}
~EventHandler() {}
/** Assigns a lambda to this callback.
Note that this will replace any existing function that was previously assigned.
*/
void operator= (const std::function<void()>& callbackToAttach)
{
callback = callbackToAttach;
}
/** Assigns a lambda to this callback.
Note that this will replace any existing function that was previously assigned.
*/
void operator= (std::function<void()>&& callbackToAttach)
{
callback = static_cast<std::function<void()>&&> (callbackToAttach);
}
/** Removes any existing function that was previously assigned to the callback. */
void reset() noexcept
{
callback = {};
}
/** @internal */
void invoke()
{
if (callback != nullptr)
callback();
}
private:
std::function<void()> callback;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (EventHandler)
};
} // namespace juce

+ 0
- 1
modules/juce_events/juce_events.h View File

@@ -76,7 +76,6 @@
#include "broadcasters/juce_AsyncUpdater.h"
#include "broadcasters/juce_ChangeListener.h"
#include "broadcasters/juce_ChangeBroadcaster.h"
#include "broadcasters/juce_EventHandler.h"
#include "timers/juce_Timer.h"
#include "timers/juce_MultiTimer.h"
#include "interprocess/juce_InterprocessConnection.h"


+ 4
- 2
modules/juce_gui_basics/buttons/juce_Button.cpp View File

@@ -399,7 +399,8 @@ void Button::sendClickMessage (const ModifierKeys& modifiers)
if (checker.shouldBailOut())
return;
onClick.invoke();
if (onClick != nullptr)
onClick();
}
void Button::sendStateMessage()
@@ -416,7 +417,8 @@ void Button::sendStateMessage()
if (checker.shouldBailOut())
return;
onStateChange.invoke();
if (onStateChange != nullptr)
onStateChange();
}
//==============================================================================


+ 2
- 2
modules/juce_gui_basics/buttons/juce_Button.h View File

@@ -186,10 +186,10 @@ public:
//==============================================================================
/** You can assign a lambda to this callback object to have it called when the button is clicked. */
EventHandler<Button> onClick;
std::function<void()> onClick;
/** You can assign a lambda to this callback object to have it called when the button's state changes. */
EventHandler<Button> onStateChange;
std::function<void()> onStateChange;
//==============================================================================
/** Causes the button to act as if it's been clicked.


+ 1
- 6
modules/juce_gui_basics/filebrowser/juce_FilenameComponent.cpp View File

@@ -43,9 +43,9 @@ FilenameComponent::FilenameComponent (const String& name,
{
addAndMakeVisible (filenameBox);
filenameBox.setEditableText (canEditFilename);
filenameBox.addListener (this);
filenameBox.setTextWhenNothingSelected (textWhenNothingSelected);
filenameBox.setTextWhenNoChoicesAvailable (TRANS ("(no recently selected files)"));
filenameBox.onChange = [this]() { setCurrentFile (getCurrentFile(), true); };
setBrowseButtonText ("...");
@@ -131,11 +131,6 @@ void FilenameComponent::showChooser()
#endif
}
void FilenameComponent::comboBoxChanged (ComboBox*)
{
setCurrentFile (getCurrentFile(), true);
}
bool FilenameComponent::isInterestedInFileDrag (const StringArray&)
{
return true;


+ 1
- 3
modules/juce_gui_basics/filebrowser/juce_FilenameComponent.h View File

@@ -64,8 +64,7 @@ public:
class JUCE_API FilenameComponent : public Component,
public SettableTooltipClient,
public FileDragAndDropTarget,
private AsyncUpdater,
private ComboBox::Listener
private AsyncUpdater
{
public:
//==============================================================================
@@ -223,7 +222,6 @@ private:
ListenerList <FilenameComponentListener> listeners;
File defaultBrowseFile;
void comboBoxChanged (ComboBox*) override;
void showChooser();
void handleAsyncUpdate() override;


+ 6
- 0
modules/juce_gui_basics/widgets/juce_ComboBox.cpp View File

@@ -630,6 +630,12 @@ void ComboBox::handleAsyncUpdate()
{
Component::BailOutChecker checker (this);
listeners.callChecked (checker, [this] (Listener& l) { l.comboBoxChanged (this); });
if (checker.shouldBailOut())
return;
if (onChange != nullptr)
onChange();
}
void ComboBox::sendChange (const NotificationType notification)


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

@@ -300,6 +300,10 @@ public:
/** Deregisters a previously-registered listener. */
void removeListener (Listener* listener);
//==============================================================================
/** You can assign a lambda to this callback object to have it called when the selected ID is changed. */
std::function<void()> onChange;
//==============================================================================
/** Sets a message to display when there is no item currently selected.
@see getTextWhenNothingSelected


+ 4
- 5
modules/juce_gui_basics/widgets/juce_Toolbar.cpp View File

@@ -573,7 +573,7 @@ void Toolbar::itemDragMove (const SourceDetails& dragSourceDetails)
updateAllItemPositions (true);
}
ComponentAnimator& animator = Desktop::getInstance().getAnimator();
auto& animator = Desktop::getInstance().getAnimator();
for (int i = getNumItems(); --i >= 0;)
{
@@ -700,8 +700,7 @@ public:
private:
Toolbar& toolbar;
class CustomiserPanel : public Component,
private ComboBox::Listener
class CustomiserPanel : public Component
{
public:
CustomiserPanel (ToolbarItemFactory& tbf, Toolbar& bar, int optionFlags)
@@ -734,7 +733,7 @@ private:
styleBox.setSelectedId (selectedStyle);
styleBox.addListener (this);
styleBox.onChange = [this]() { updateStyle(); };
}
if ((optionFlags & Toolbar::showResetToDefaultsButton) != 0)
@@ -749,7 +748,7 @@ private:
setSize (500, 300);
}
void comboBoxChanged (ComboBox*) override
void updateStyle()
{
switch (styleBox.getSelectedId())
{


Loading…
Cancel
Save