Browse Source

Added helper objects to Label and Slider to allow lambda callbacks

tags/2021-05-28
Noah Dayan 7 years ago
parent
commit
77c3d790a5
4 changed files with 56 additions and 0 deletions
  1. +18
    -0
      modules/juce_gui_basics/widgets/juce_Label.cpp
  2. +10
    -0
      modules/juce_gui_basics/widgets/juce_Label.h
  3. +18
    -0
      modules/juce_gui_basics/widgets/juce_Slider.cpp
  4. +10
    -0
      modules/juce_gui_basics/widgets/juce_Slider.h

+ 18
- 0
modules/juce_gui_basics/widgets/juce_Label.cpp View File

@@ -191,6 +191,12 @@ void Label::editorShown (TextEditor* textEditor)
{
Component::BailOutChecker checker (this);
listeners.callChecked (checker, [this, textEditor] (Label::Listener& l) { l.editorShown (this, *textEditor); });
if (checker.shouldBailOut())
return;
if (onEditorShow != nullptr)
onEditorShow();
}
void Label::editorAboutToBeHidden (TextEditor* textEditor)
@@ -200,6 +206,12 @@ void Label::editorAboutToBeHidden (TextEditor* textEditor)
Component::BailOutChecker checker (this);
listeners.callChecked (checker, [this, textEditor] (Label::Listener& l) { l.editorHidden (this, *textEditor); });
if (checker.shouldBailOut())
return;
if (onEditorHide != nullptr)
onEditorHide();
}
void Label::showEditor()
@@ -404,6 +416,12 @@ void Label::callChangeListeners()
{
Component::BailOutChecker checker (this);
listeners.callChecked (checker, [this] (Listener& l) { l.labelTextChanged (this); });
if (checker.shouldBailOut())
return;
if (onTextChange != nullptr)
onTextChange();
}
//==============================================================================


+ 10
- 0
modules/juce_gui_basics/widgets/juce_Label.h View File

@@ -200,6 +200,16 @@ 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 label text is changed. */
std::function<void()> onTextChange;
/** You can assign a lambda to this callback object to have it called when the label's editor is shown. */
std::function<void()> onEditorShow;
/** You can assign a lambda to this callback object to have it called when the label's editor is hidden. */
std::function<void()> onEditorHide;
//==============================================================================
/** Makes the label turn into a TextEditor when clicked.


+ 18
- 0
modules/juce_gui_basics/widgets/juce_Slider.cpp View File

@@ -320,6 +320,12 @@ public:
Component::BailOutChecker checker (&owner);
listeners.callChecked (checker, [&] (Slider::Listener& l) { l.sliderValueChanged (&owner); });
if (checker.shouldBailOut())
return;
if (owner.onValueChange != nullptr)
owner.onValueChange();
}
void sendDragStart()
@@ -328,6 +334,12 @@ public:
Component::BailOutChecker checker (&owner);
listeners.callChecked (checker, [&] (Slider::Listener& l) { l.sliderDragStarted (&owner); });
if (checker.shouldBailOut())
return;
if (owner.onDragStart != nullptr)
owner.onDragStart();
}
void sendDragEnd()
@@ -337,6 +349,12 @@ public:
Component::BailOutChecker checker (&owner);
listeners.callChecked (checker, [&] (Slider::Listener& l) { l.sliderDragEnded (&owner); });
if (checker.shouldBailOut())
return;
if (owner.onDragEnd != nullptr)
owner.onDragEnd();
}
struct DragInProgress


+ 10
- 0
modules/juce_gui_basics/widgets/juce_Slider.h View File

@@ -586,6 +586,16 @@ public:
/** Removes a previously-registered listener. */
void removeListener (Listener* listener);
//==============================================================================
/** You can assign a lambda to this callback object to have it called when the slider value is changed. */
std::function<void()> onValueChange;
/** You can assign a lambda to this callback object to have it called when the slider's drag begins. */
std::function<void()> onDragStart;
/** You can assign a lambda to this callback object to have it called when the slider's drag ends. */
std::function<void()> onDragEnd;
//==============================================================================
/** This lets you choose whether double-clicking moves the slider to a given position.


Loading…
Cancel
Save