mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-14 00:14:18 +00:00
Added some helper objects Button::onClick and Button::onStateChange, which let you easily assign a lambda to be called on these events
This commit is contained in:
parent
fa177328f4
commit
be5f2d62c4
2 changed files with 28 additions and 11 deletions
|
|
@ -391,8 +391,15 @@ void Button::sendClickMessage (const ModifierKeys& modifiers)
|
|||
|
||||
clicked (modifiers);
|
||||
|
||||
if (! checker.shouldBailOut())
|
||||
buttonListeners.callChecked (checker, [this] (Listener& l) { l.buttonClicked (this); });
|
||||
if (checker.shouldBailOut())
|
||||
return;
|
||||
|
||||
buttonListeners.callChecked (checker, [this] (Listener& l) { l.buttonClicked (this); });
|
||||
|
||||
if (checker.shouldBailOut())
|
||||
return;
|
||||
|
||||
onClick.invoke (*this);
|
||||
}
|
||||
|
||||
void Button::sendStateMessage()
|
||||
|
|
@ -401,8 +408,15 @@ void Button::sendStateMessage()
|
|||
|
||||
buttonStateChanged();
|
||||
|
||||
if (! checker.shouldBailOut())
|
||||
buttonListeners.callChecked (checker, [this] (Listener& l) { l.buttonStateChanged (this); });
|
||||
if (checker.shouldBailOut())
|
||||
return;
|
||||
|
||||
buttonListeners.callChecked (checker, [this] (Listener& l) { l.buttonStateChanged (this); });
|
||||
|
||||
if (checker.shouldBailOut())
|
||||
return;
|
||||
|
||||
onStateChange.invoke (*this);
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
|
|
|
|||
|
|
@ -184,6 +184,12 @@ public:
|
|||
*/
|
||||
void removeListener (Listener* listener);
|
||||
|
||||
/** You can assign a lambda to this callback object to have it called when the button is clicked. */
|
||||
EventHandler<Button> onClick;
|
||||
|
||||
/** You can assign a lambda to this callback object to have it called when the button's state changes. */
|
||||
EventHandler<Button> onStateChange;
|
||||
|
||||
//==============================================================================
|
||||
/** Causes the button to act as if it's been clicked.
|
||||
|
||||
|
|
@ -394,13 +400,10 @@ protected:
|
|||
//==============================================================================
|
||||
/** This method is called when the button has been clicked.
|
||||
|
||||
Subclasses can override this to perform whatever they actions they need
|
||||
to do.
|
||||
|
||||
Alternatively, a Button::Listener can be added to the button, and these listeners
|
||||
will be called when the click occurs.
|
||||
|
||||
@see triggerClick
|
||||
Subclasses can override this to perform whatever they actions they need to do.
|
||||
In general, you wouldn't use this method to receive clicks, but should get your callbacks
|
||||
by attaching a std::function to the onClick callback, or adding a Button::Listener.
|
||||
@see triggerClick, onClick
|
||||
*/
|
||||
virtual void clicked();
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue