Use new JUCE button callback stuff

This commit is contained in:
xenakios 2018-01-03 17:15:57 +02:00
parent 64ad16f8cb
commit 96a88e8016
2 changed files with 7 additions and 35 deletions

View File

@ -25,20 +25,20 @@ Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
extern String g_plugintitle;
//==============================================================================
PaulstretchpluginAudioProcessorEditor::PaulstretchpluginAudioProcessorEditor (PaulstretchpluginAudioProcessor& p)
: AudioProcessorEditor (&p),
m_wavecomponent(p.m_afm),
processor (p)
PaulstretchpluginAudioProcessorEditor::PaulstretchpluginAudioProcessorEditor(PaulstretchpluginAudioProcessor& p)
: AudioProcessorEditor(&p),
m_wavecomponent(p.m_afm),
processor(p)
{
addAndMakeVisible(&m_import_button);
m_import_button.setButtonText("Import file...");
attachCallback(m_import_button, [this]() { chooseFile(); });
m_import_button.onClick = [this]() { chooseFile(); };
addAndMakeVisible(&m_settings_button);
m_settings_button.setButtonText("Settings...");
attachCallback(m_settings_button, [this]() { showSettingsMenu(); });
m_settings_button.onClick = [this]() { showSettingsMenu(); };
addAndMakeVisible(&m_info_label);
m_info_label.setJustificationType(Justification::centredRight);

View File

@ -40,34 +40,6 @@ private:
double m_elapsed = 0.0;
};
inline void attachCallback(Button& button, std::function<void()> callback)
{
struct ButtonCallback : public Button::Listener,
private ComponentListener
{
ButtonCallback(Button& b, std::function<void()> f) : target(b), fn(f)
{
target.addListener(this);
target.addComponentListener(this);
}
~ButtonCallback()
{
target.removeListener(this);
}
void componentBeingDeleted(Component&) override { delete this; }
void buttonClicked(Button*) override { fn(); }
Button& target;
std::function<void()> fn;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(ButtonCallback)
};
new ButtonCallback(button, callback);
}
class MySlider : public Slider
{
public: