LMMS
Loading...
Searching...
No Matches
juce::Button Class Referenceabstract

#include <juce_Button.h>

Inheritance diagram for juce::Button:
juce::Component juce::SettableTooltipClient juce::MouseListener juce::TooltipClient juce::ArrowButton juce::DrawableButton juce::HyperlinkButton juce::ImageButton juce::KeyMappingEditorComponent::ChangeKeyButton juce::LookAndFeel_V2::GlassWindowButton juce::LookAndFeel_V3_DocumentWindowButton juce::LookAndFeel_V4_DocumentWindowButton juce::ScrollBar::ScrollbarButton juce::ShapeButton juce::TabBarButton juce::TextButton juce::ToggleButton juce::ToolbarItemComponent

Classes

class  Listener
struct  LookAndFeelMethods
struct  CallbackHelper

Public Types

enum  ConnectedEdgeFlags { ConnectedOnLeft = 1 , ConnectedOnRight = 2 , ConnectedOnTop = 4 , ConnectedOnBottom = 8 }
enum  ButtonState { buttonNormal , buttonOver , buttonDown }
Public Types inherited from juce::Component
enum class  FocusContainerType { none , focusContainer , keyboardFocusContainer }
enum  FocusChangeType { focusChangedByMouseClick , focusChangedByTabKey , focusChangedDirectly }

Public Member Functions

 ~Button () override
void setButtonText (const String &newText)
const StringgetButtonText () const
bool isDown () const noexcept
bool isOver () const noexcept
void setToggleable (bool shouldBeToggleable)
bool isToggleable () const noexcept
void setToggleState (bool shouldBeOn, NotificationType notification)
bool getToggleState () const noexcept
ValuegetToggleStateValue () noexcept
void setClickingTogglesState (bool shouldAutoToggleOnClick) noexcept
bool getClickingTogglesState () const noexcept
void setRadioGroupId (int newGroupId, NotificationType notification=sendNotification)
int getRadioGroupId () const noexcept
void addListener (Listener *newListener)
void removeListener (Listener *listener)
virtual void triggerClick ()
void setCommandToTrigger (ApplicationCommandManager *commandManagerToUse, CommandID commandID, bool generateTooltip)
CommandID getCommandID () const noexcept
void addShortcut (const KeyPress &)
void clearShortcuts ()
bool isRegisteredForShortcut (const KeyPress &) const
void setRepeatSpeed (int initialDelayInMillisecs, int repeatDelayInMillisecs, int minimumDelayInMillisecs=-1) noexcept
void setTriggeredOnMouseDown (bool isTriggeredOnMouseDown) noexcept
bool getTriggeredOnMouseDown () const noexcept
uint32 getMillisecondsSinceButtonDown () const noexcept
void setTooltip (const String &newTooltip) override
void setConnectedEdges (int connectedEdgeFlags)
int getConnectedEdgeFlags () const noexcept
bool isConnectedOnLeft () const noexcept
bool isConnectedOnRight () const noexcept
bool isConnectedOnTop () const noexcept
bool isConnectedOnBottom () const noexcept
void setState (ButtonState newState)
ButtonState getState () const noexcept
void setToggleState (bool, bool)
Public Member Functions inherited from juce::Component
 Component () noexcept
 ~Component () override
 Component (const String &componentName) noexcept
String getName () const noexcept
virtual void setName (const String &newName)
String getComponentID () const noexcept
void setComponentID (const String &newID)
virtual void setVisible (bool shouldBeVisible)
bool isVisible () const noexcept
bool isShowing () const
virtual void addToDesktop (int windowStyleFlags, void *nativeWindowToAttachTo=nullptr)
void removeFromDesktop ()
bool isOnDesktop () const noexcept
ComponentPeergetPeer () const
virtual void userTriedToCloseWindow ()
virtual void minimisationStateChanged (bool isNowMinimised)
virtual float getDesktopScaleFactor () const
void toFront (bool shouldAlsoGainKeyboardFocus)
void toBack ()
void toBehind (Component *other)
void setAlwaysOnTop (bool shouldStayOnTop)
bool isAlwaysOnTop () const noexcept
int getX () const noexcept
int getY () const noexcept
int getWidth () const noexcept
int getHeight () const noexcept
int getRight () const noexcept
Point< intgetPosition () const noexcept
int getBottom () const noexcept
Rectangle< intgetBounds () const noexcept
Rectangle< intgetLocalBounds () const noexcept
Rectangle< intgetBoundsInParent () const noexcept
int getScreenX () const
int getScreenY () const
Point< intgetScreenPosition () const
Rectangle< intgetScreenBounds () const
Point< intgetLocalPoint (const Component *sourceComponent, Point< int > pointRelativeToSourceComponent) const
Point< float > getLocalPoint (const Component *sourceComponent, Point< float > pointRelativeToSourceComponent) const
Rectangle< intgetLocalArea (const Component *sourceComponent, Rectangle< int > areaRelativeToSourceComponent) const
Rectangle< float > getLocalArea (const Component *sourceComponent, Rectangle< float > areaRelativeToSourceComponent) const
Point< intlocalPointToGlobal (Point< int > localPoint) const
Point< float > localPointToGlobal (Point< float > localPoint) const
Rectangle< intlocalAreaToGlobal (Rectangle< int > localArea) const
Rectangle< float > localAreaToGlobal (Rectangle< float > localArea) const
void setTopLeftPosition (int x, int y)
void setTopLeftPosition (Point< int > newTopLeftPosition)
void setTopRightPosition (int x, int y)
void setSize (int newWidth, int newHeight)
void setBounds (int x, int y, int width, int height)
void setBounds (Rectangle< int > newBounds)
void setBoundsRelative (float proportionalX, float proportionalY, float proportionalWidth, float proportionalHeight)
void setBoundsRelative (Rectangle< float > proportionalArea)
void setBoundsInset (BorderSize< int > borders)
void setBoundsToFit (Rectangle< int > targetArea, Justification justification, bool onlyReduceInSize)
void setCentrePosition (int x, int y)
void setCentrePosition (Point< int > newCentrePosition)
void setCentreRelative (float x, float y)
void centreWithSize (int width, int height)
void setTransform (const AffineTransform &transform)
AffineTransform getTransform () const
bool isTransformed () const noexcept
int proportionOfWidth (float proportion) const noexcept
int proportionOfHeight (float proportion) const noexcept
int getParentWidth () const noexcept
int getParentHeight () const noexcept
Rectangle< intgetParentMonitorArea () const
int getNumChildComponents () const noexcept
ComponentgetChildComponent (int index) const noexcept
int getIndexOfChildComponent (const Component *child) const noexcept
const Array< Component * > & getChildren () const noexcept
ComponentfindChildWithID (StringRef componentID) const noexcept
void addChildComponent (Component *child, int zOrder=-1)
void addChildComponent (Component &child, int zOrder=-1)
void addAndMakeVisible (Component *child, int zOrder=-1)
void addAndMakeVisible (Component &child, int zOrder=-1)
void addChildAndSetID (Component *child, const String &componentID)
void removeChildComponent (Component *childToRemove)
ComponentremoveChildComponent (int childIndexToRemove)
void removeAllChildren ()
void deleteAllChildren ()
ComponentgetParentComponent () const noexcept
template<class TargetClass>
TargetClass * findParentComponentOfClass () const
ComponentgetTopLevelComponent () const noexcept
bool isParentOf (const Component *possibleChild) const noexcept
virtual void childrenChanged ()
virtual bool hitTest (int x, int y)
void setInterceptsMouseClicks (bool allowClicksOnThisComponent, bool allowClicksOnChildComponents) noexcept
void getInterceptsMouseClicks (bool &allowsClicksOnThisComponent, bool &allowsClicksOnChildComponents) const noexcept
bool contains (Point< int > localPoint)
bool contains (Point< float > localPoint)
bool reallyContains (Point< int > localPoint, bool returnTrueIfWithinAChild)
bool reallyContains (Point< float > localPoint, bool returnTrueIfWithinAChild)
ComponentgetComponentAt (int x, int y)
ComponentgetComponentAt (Point< int > position)
ComponentgetComponentAt (Point< float > position)
void repaint ()
void repaint (int x, int y, int width, int height)
void repaint (Rectangle< int > area)
void setBufferedToImage (bool shouldBeBuffered)
Image createComponentSnapshot (Rectangle< int > areaToGrab, bool clipImageToComponentBounds=true, float scaleFactor=1.0f)
void paintEntireComponent (Graphics &context, bool ignoreAlphaLevel)
void setPaintingIsUnclipped (bool shouldPaintWithoutClipping) noexcept
bool isPaintingUnclipped () const noexcept
void setComponentEffect (ImageEffectFilter *newEffect)
ImageEffectFiltergetComponentEffect () const noexcept
LookAndFeelgetLookAndFeel () const noexcept
void setLookAndFeel (LookAndFeel *newLookAndFeel)
virtual void lookAndFeelChanged ()
void sendLookAndFeelChange ()
void setOpaque (bool shouldBeOpaque)
bool isOpaque () const noexcept
void setBroughtToFrontOnMouseClick (bool shouldBeBroughtToFront) noexcept
bool isBroughtToFrontOnMouseClick () const noexcept
void setExplicitFocusOrder (int newFocusOrderIndex)
int getExplicitFocusOrder () const
void setFocusContainerType (FocusContainerType containerType) noexcept
bool isFocusContainer () const noexcept
bool isKeyboardFocusContainer () const noexcept
ComponentfindFocusContainer () const
ComponentfindKeyboardFocusContainer () const
void setWantsKeyboardFocus (bool wantsFocus) noexcept
bool getWantsKeyboardFocus () const noexcept
void setMouseClickGrabsKeyboardFocus (bool shouldGrabFocus)
bool getMouseClickGrabsKeyboardFocus () const noexcept
void grabKeyboardFocus ()
void giveAwayKeyboardFocus ()
bool hasKeyboardFocus (bool trueIfChildIsFocused) const
void moveKeyboardFocusToSibling (bool moveToNext)
virtual std::unique_ptr< ComponentTraversercreateFocusTraverser ()
virtual std::unique_ptr< ComponentTraversercreateKeyboardFocusTraverser ()
void setHasFocusOutline (bool hasFocusOutline) noexcept
bool hasFocusOutline () const noexcept
bool isEnabled () const noexcept
void setEnabled (bool shouldBeEnabled)
float getAlpha () const noexcept
void setAlpha (float newAlpha)
virtual void alphaChanged ()
void setMouseCursor (const MouseCursor &cursorType)
virtual MouseCursor getMouseCursor ()
void updateMouseCursor () const
virtual void paintOverChildren (Graphics &g)
void mouseMove (const MouseEvent &event) override
void mouseEnter (const MouseEvent &event) override
void mouseExit (const MouseEvent &event) override
void mouseDown (const MouseEvent &event) override
void mouseDrag (const MouseEvent &event) override
void mouseUp (const MouseEvent &event) override
void mouseDoubleClick (const MouseEvent &event) override
void mouseWheelMove (const MouseEvent &event, const MouseWheelDetails &wheel) override
void mouseMagnify (const MouseEvent &event, float scaleFactor) override
void setRepaintsOnMouseActivity (bool shouldRepaint) noexcept
void addMouseListener (MouseListener *newListener, bool wantsEventsForAllNestedChildComponents)
void removeMouseListener (MouseListener *listenerToRemove)
void addKeyListener (KeyListener *newListener)
void removeKeyListener (KeyListener *listenerToRemove)
virtual void modifierKeysChanged (const ModifierKeys &modifiers)
virtual void focusOfChildComponentChanged (FocusChangeType cause)
bool isMouseOver (bool includeChildren=false) const
bool isMouseButtonDown (bool includeChildren=false) const
bool isMouseOverOrDragging (bool includeChildren=false) const
Point< intgetMouseXYRelative () const
virtual void resized ()
virtual void moved ()
virtual void childBoundsChanged (Component *child)
virtual void parentSizeChanged ()
virtual void broughtToFront ()
void addComponentListener (ComponentListener *newListener)
void removeComponentListener (ComponentListener *listenerToRemove)
void postCommandMessage (int commandId)
void enterModalState (bool takeKeyboardFocus=true, ModalComponentManager::Callback *callback=nullptr, bool deleteWhenDismissed=false)
void exitModalState (int returnValue)
bool isCurrentlyModal (bool onlyConsiderForemostModalComponent=true) const noexcept
bool isCurrentlyBlockedByAnotherModalComponent () const
virtual bool canModalEventBeSentToComponent (const Component *targetComponent)
virtual void inputAttemptWhenModal ()
NamedValueSetgetProperties () noexcept
const NamedValueSetgetProperties () const noexcept
Colour findColour (int colourID, bool inheritFromParent=false) const
void setColour (int colourID, Colour newColour)
void removeColour (int colourID)
bool isColourSpecified (int colourID) const
void copyAllExplicitColoursTo (Component &target) const
virtual void colourChanged ()
voidgetWindowHandle () const
PositionergetPositioner () const noexcept
void setPositioner (Positioner *newPositioner)
void setCachedComponentImage (CachedComponentImage *newCachedImage)
CachedComponentImagegetCachedComponentImage () const noexcept
void setViewportIgnoreDragFlag (bool ignoreDrag) noexcept
bool getViewportIgnoreDragFlag () const noexcept
String getTitle () const noexcept
void setTitle (const String &newTitle)
String getDescription () const noexcept
void setDescription (const String &newDescription)
String getHelpText () const noexcept
void setHelpText (const String &newHelpText)
void setAccessible (bool shouldBeAccessible)
bool isAccessible () const noexcept
AccessibilityHandlergetAccessibilityHandler ()
void invalidateAccessibilityHandler ()
void setFocusContainer (bool shouldBeFocusContainer) noexcept
void contains (int, int)=delete
Public Member Functions inherited from juce::MouseListener
virtual ~MouseListener ()=default
Public Member Functions inherited from juce::SettableTooltipClient
 ~SettableTooltipClient () override=default
String getTooltip () override
Public Member Functions inherited from juce::TooltipClient
virtual ~TooltipClient ()=default

Public Attributes

std::function< void()> onClick
std::function< void()> onStateChange

Protected Member Functions

 Button (const String &buttonName)
virtual void clicked ()
virtual void clicked (const ModifierKeys &modifiers)
virtual void paintButton (Graphics &g, bool shouldDrawButtonAsHighlighted, bool shouldDrawButtonAsDown)=0
virtual void buttonStateChanged ()
virtual void internalClickCallback (const ModifierKeys &)
void handleCommandMessage (int commandId) override
void mouseEnter (const MouseEvent &) override
void mouseExit (const MouseEvent &) override
void mouseDown (const MouseEvent &) override
void mouseDrag (const MouseEvent &) override
void mouseUp (const MouseEvent &) override
bool keyPressed (const KeyPress &) override
void paint (Graphics &) override
void parentHierarchyChanged () override
void visibilityChanged () override
void focusGained (FocusChangeType) override
void focusLost (FocusChangeType) override
void enablementChanged () override
virtual bool keyStateChanged (bool isKeyDown)
Protected Member Functions inherited from juce::Component
virtual ComponentPeercreateNewPeer (int styleFlags, void *nativeWindowToAttachTo)
Protected Member Functions inherited from juce::SettableTooltipClient
 SettableTooltipClient ()=default

Private Member Functions

std::unique_ptr< AccessibilityHandlercreateAccessibilityHandler () override
void checkToggleableState (bool wasToggleable)
void repeatTimerCallback ()
bool keyStateChangedCallback ()
void applicationCommandListChangeCallback ()
void updateAutomaticTooltip (const ApplicationCommandInfo &)
ButtonState updateState ()
ButtonState updateState (bool isOver, bool isDown)
bool isShortcutPressed () const
void turnOffOtherButtonsInGroup (NotificationType click, NotificationType state)
void flashButtonState ()
void sendClickMessage (const ModifierKeys &)
void sendStateMessage ()
void setToggleState (bool shouldBeOn, NotificationType click, NotificationType state)
bool isMouseSourceOver (const MouseEvent &e)

Private Attributes

Array< KeyPressshortcuts
WeakReference< ComponentkeySource
String text
ListenerList< ListenerbuttonListeners
std::unique_ptr< CallbackHelpercallbackHelper
uint32 buttonPressTime = 0
uint32 lastRepeatTime = 0
ApplicationCommandManagercommandManagerToUse = nullptr
int autoRepeatDelay = -1
int autoRepeatSpeed = 0
int autoRepeatMinimumDelay = -1
int radioGroupId = 0
int connectedEdgeFlags = 0
CommandID commandID = {}
ButtonState buttonState = buttonNormal
ButtonState lastStatePainted = buttonNormal
Value isOn
bool canBeToggled = false
bool lastToggleState = false
bool clickTogglesState = false
bool needsToRelease = false
bool needsRepainting = false
bool isKeyDown = false
bool triggerOnMouseDown = false
bool generateTooltip = false

Additional Inherited Members

Static Public Member Functions inherited from juce::Component
static float JUCE_CALLTYPE getApproximateScaleFactorForComponent (const Component *targetComponent)
static Component *JUCE_CALLTYPE getCurrentlyFocusedComponent () noexcept
static void JUCE_CALLTYPE unfocusAllComponents ()
static void JUCE_CALLTYPE beginDragAutoRepeat (int millisecondsBetweenCallbacks)
static bool JUCE_CALLTYPE isMouseButtonDownAnywhere () noexcept
static int JUCE_CALLTYPE getNumCurrentlyModalComponents () noexcept
static Component *JUCE_CALLTYPE getCurrentlyModalComponent (int index=0) noexcept
Static Protected Member Functions inherited from juce::Component
static std::unique_ptr< AccessibilityHandlercreateIgnoredAccessibilityHandler (Component &)

Detailed Description

A base class for buttons.

This contains all the logic for button behaviours such as enabling/disabling, responding to shortcut keystrokes, auto-repeating when held down, toggle-buttons and radio groups, etc.

See also
TextButton, DrawableButton, ToggleButton

@tags{GUI}

Member Enumeration Documentation

◆ ButtonState

enum juce::Button::ButtonState

Used by setState().

Enumerator
buttonNormal 
buttonOver 
buttonDown 

◆ ConnectedEdgeFlags

enum juce::Button::ConnectedEdgeFlags

A combination of these flags are used by setConnectedEdges().

Enumerator
ConnectedOnLeft 
ConnectedOnRight 
ConnectedOnTop 
ConnectedOnBottom 

Constructor & Destructor Documentation

◆ Button()

juce::Button::Button ( const String & buttonName)
explicitprotected

Creates a button.

Parameters
buttonNamethe text to put in the button (the component's name is also initially set to this string, but these can be changed later using the setName() and setButtonText() methods)

◆ ~Button()

juce::Button::~Button ( )
override

Destructor.

Member Function Documentation

◆ addListener()

void juce::Button::addListener ( Listener * newListener)

Registers a listener to receive events when this button's state changes. If the listener is already registered, this will not register it again.

See also
removeListener

◆ addShortcut()

void juce::Button::addShortcut ( const KeyPress & key)

Assigns a shortcut key to trigger the button.

The button registers itself with its top-level parent component for keypresses.

Note that a different way of linking buttons to keypresses is by using the setCommandToTrigger() method to invoke a command.

See also
clearShortcuts

◆ applicationCommandListChangeCallback()

void juce::Button::applicationCommandListChangeCallback ( )
private

◆ buttonStateChanged()

void juce::Button::buttonStateChanged ( )
protectedvirtual

Called when the button's up/down/over state changes.

Subclasses can override this if they need to do something special when the button goes up or down.

See also
isDown, isOver

Reimplemented in juce::DrawableButton, and juce::ToolbarButton.

◆ checkToggleableState()

void juce::Button::checkToggleableState ( bool wasToggleable)
private

◆ clearShortcuts()

void juce::Button::clearShortcuts ( )

Removes all key shortcuts that had been set for this button.

See also
addShortcut

◆ clicked() [1/2]

void juce::Button::clicked ( )
protectedvirtual

This method is called when the button has been clicked.

Subclasses can override this to perform whatever 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 also
triggerClick, onClick

Reimplemented in juce::HyperlinkButton, juce::KeyMappingEditorComponent::ChangeKeyButton, juce::ScrollBar::ScrollbarButton, and juce::TabBarButton.

◆ clicked() [2/2]

void juce::Button::clicked ( const ModifierKeys & modifiers)
protectedvirtual

This method is called when the button has been clicked.

By default it just calls clicked(), but you might want to override it to handle things like clicking when a modifier key is pressed, etc.

See also
ModifierKeys

Reimplemented in juce::HyperlinkButton, juce::KeyMappingEditorComponent::ChangeKeyButton, juce::ScrollBar::ScrollbarButton, and juce::TabBarButton.

◆ createAccessibilityHandler()

std::unique_ptr< AccessibilityHandler > juce::Button::createAccessibilityHandler ( )
overrideprivatevirtual

Override this method to return a custom AccessibilityHandler for this component.

The default implementation creates and returns a AccessibilityHandler object with an unspecified role, meaning that it will be visible to accessibility clients but without a specific role, action callbacks or interfaces. To control how accessibility clients see and interact with your component subclass AccessibilityHandler, implement the desired behaviours, and return an instance of it from this method in your component subclass.

The accessibility handler you return here is guaranteed to be destroyed before its Component, so it's safe to store and use a reference back to the Component inside the AccessibilityHandler if necessary.

See also
getAccessibilityHandler

Reimplemented from juce::Component.

Reimplemented in juce::ToggleButton, and juce::ToolbarItemComponent.

◆ enablementChanged()

void juce::Button::enablementChanged ( )
overrideprotectedvirtual

Callback to indicate that this component has been enabled or disabled.

This can be triggered by one of the component's parent components being enabled or disabled, as well as changes to the component itself.

The default implementation of this method does nothing; your class may wish to repaint itself or something when this happens.

See also
setEnabled, isEnabled

Reimplemented from juce::Component.

Reimplemented in juce::DrawableButton, and juce::ToolbarButton.

◆ flashButtonState()

void juce::Button::flashButtonState ( )
private

◆ focusGained()

void juce::Button::focusGained ( FocusChangeType cause)
overrideprotectedvirtual

Called to indicate that this component has just acquired the keyboard focus.

See also
focusLost, setWantsKeyboardFocus, getCurrentlyFocusedComponent, hasKeyboardFocus

Reimplemented from juce::Component.

◆ focusLost()

void juce::Button::focusLost ( FocusChangeType cause)
overrideprotectedvirtual

Called to indicate that this component has just lost the keyboard focus.

See also
focusGained, setWantsKeyboardFocus, getCurrentlyFocusedComponent, hasKeyboardFocus

Reimplemented from juce::Component.

◆ getButtonText()

const String & juce::Button::getButtonText ( ) const
inline

Returns the text displayed in the button.

See also
setButtonText

◆ getClickingTogglesState()

bool juce::Button::getClickingTogglesState ( ) const
inlinenoexcept

Returns true if this button is set to be an automatic toggle-button. This returns the last value that was passed to setClickingTogglesState().

◆ getCommandID()

CommandID juce::Button::getCommandID ( ) const
inlinenoexcept

Returns the command ID that was set by setCommandToTrigger().

◆ getConnectedEdgeFlags()

int juce::Button::getConnectedEdgeFlags ( ) const
inlinenoexcept

Returns the set of flags passed into setConnectedEdges().

◆ getMillisecondsSinceButtonDown()

uint32 juce::Button::getMillisecondsSinceButtonDown ( ) const
noexcept

Returns the number of milliseconds since the last time the button went into the 'down' state.

◆ getRadioGroupId()

int juce::Button::getRadioGroupId ( ) const
inlinenoexcept

Returns the ID of the group to which this button belongs. (See setRadioGroupId() for an explanation of this).

◆ getState()

ButtonState juce::Button::getState ( ) const
inlinenoexcept

Returns the button's current over/down/up state.

◆ getToggleState()

bool juce::Button::getToggleState ( ) const
inlinenoexcept

Returns true if the button is 'on'.

By default buttons are 'off' and for simple buttons that you click to perform an action you won't change this. Toggle buttons, however will want to change their state when turned on or off.

See also
setToggleState

◆ getToggleStateValue()

Value & juce::Button::getToggleStateValue ( )
inlinenoexcept

Returns the Value object that represents the button's toggle state.

You can use this Value object to connect the button's state to external values or setters, either by taking a copy of the Value, or by using Value::referTo() to make it point to your own Value object.

See also
getToggleState, Value

◆ getTriggeredOnMouseDown()

bool juce::Button::getTriggeredOnMouseDown ( ) const
noexcept

Returns whether the button click happens when the mouse is pressed or released.

See also
setTriggeredOnMouseDown

◆ handleCommandMessage()

void juce::Button::handleCommandMessage ( int commandId)
overrideprotectedvirtual

Called to handle a command that was sent by postCommandMessage().

This is called by the message thread when a command message arrives, and the component can override this method to process it in any way it needs to.

See also
postCommandMessage

Reimplemented from juce::Component.

◆ internalClickCallback()

void juce::Button::internalClickCallback ( const ModifierKeys & modifiers)
protectedvirtual

◆ isConnectedOnBottom()

bool juce::Button::isConnectedOnBottom ( ) const
inlinenoexcept

Indicates whether the button adjoins another one on its bottom edge.

See also
setConnectedEdges

◆ isConnectedOnLeft()

bool juce::Button::isConnectedOnLeft ( ) const
inlinenoexcept

Indicates whether the button adjoins another one on its left edge.

See also
setConnectedEdges

◆ isConnectedOnRight()

bool juce::Button::isConnectedOnRight ( ) const
inlinenoexcept

Indicates whether the button adjoins another one on its right edge.

See also
setConnectedEdges

◆ isConnectedOnTop()

bool juce::Button::isConnectedOnTop ( ) const
inlinenoexcept

Indicates whether the button adjoins another one on its top edge.

See also
setConnectedEdges

◆ isDown()

bool juce::Button::isDown ( ) const
noexcept

Returns true if the button is currently being held down.

See also
isOver

◆ isMouseSourceOver()

bool juce::Button::isMouseSourceOver ( const MouseEvent & e)
private

◆ isOver()

bool juce::Button::isOver ( ) const
noexcept

Returns true if the mouse is currently over the button. This will be also be true if the button is being held down.

See also
isDown

◆ isRegisteredForShortcut()

bool juce::Button::isRegisteredForShortcut ( const KeyPress & key) const

Returns true if the given keypress is a shortcut for this button.

See also
addShortcut

◆ isShortcutPressed()

bool juce::Button::isShortcutPressed ( ) const
private

◆ isToggleable()

bool juce::Button::isToggleable ( ) const
inlinenoexcept

Returns true if the button's on/off state is toggleable.

See also
setToggleable, setClickingTogglesState

◆ keyPressed()

bool juce::Button::keyPressed ( const KeyPress & key)
overrideprotectedvirtual

Called when a key is pressed.

When a key is pressed, the component that has the keyboard focus will have this method called. Remember that a component will only be given the focus if its setWantsKeyboardFocus() method has been used to enable this.

If your implementation returns true, the event will be consumed and not passed on to any other listeners. If it returns false, the key will be passed to any KeyListeners that have been registered with this component. As soon as one of these returns true, the process will stop, but if they all return false, the event will be passed upwards to this component's parent, and so on.

The default implementation of this method does nothing and returns false.

See also
keyStateChanged, getCurrentlyFocusedComponent, addKeyListener

Reimplemented from juce::Component.

◆ keyStateChanged()

bool juce::Component::keyStateChanged ( bool isKeyDown)
protectedvirtual

Called when a key is pressed or released.

Whenever a key on the keyboard is pressed or released (including modifier keys like shift and ctrl), this method will be called on the component that currently has the keyboard focus. Remember that a component will only be given the focus if its setWantsKeyboardFocus() method has been used to enable this.

If your implementation returns true, the event will be consumed and not passed on to any other listeners. If it returns false, then any KeyListeners that have been registered with this component will have their keyStateChanged methods called. As soon as one of these returns true, the process will stop, but if they all return false, the event will be passed upwards to this component's parent, and so on.

The default implementation of this method does nothing and returns false.

To find out which keys are up or down at any time, see the KeyPress::isKeyCurrentlyDown() method.

Parameters
isKeyDowntrue if a key has been pressed; false if it has been released
See also
keyPressed, KeyPress, getCurrentlyFocusedComponent, addKeyListener

Reimplemented from juce::Component.

◆ keyStateChangedCallback()

bool juce::Button::keyStateChangedCallback ( )
private

◆ mouseDown()

void juce::Button::mouseDown ( const MouseEvent & event)
overrideprotectedvirtual

Called when a mouse button is pressed.

The MouseEvent object passed in contains lots of methods for finding out which button was pressed, as well as which modifier keys (e.g. shift, ctrl) were held down at the time.

Once a button is held down, the mouseDrag method will be called when the mouse moves, until the button is released.

Parameters
Eventdetails about the position and status of the mouse event, including the source component in which it occurred
See also
mouseUp, mouseDrag, mouseDoubleClick, contains

Reimplemented from juce::MouseListener.

◆ mouseDrag()

void juce::Button::mouseDrag ( const MouseEvent & event)
overrideprotectedvirtual

Called when the mouse is moved while a button is held down.

When a mouse button is pressed inside a component, that component receives mouseDrag callbacks each time the mouse moves, even if the mouse strays outside the component's bounds.

Parameters
Eventdetails about the position and status of the mouse event, including the source component in which it occurred
See also
mouseDown, mouseUp, mouseMove, contains, setDragRepeatInterval

Reimplemented from juce::MouseListener.

◆ mouseEnter()

void juce::Button::mouseEnter ( const MouseEvent & event)
overrideprotectedvirtual

Called when the mouse first enters a component.

If the mouse button isn't pressed and the mouse moves into a component, this will be called to let the component react to this.

When the mouse button is pressed and held down while being moved in or out of a component, no mouseEnter or mouseExit callbacks are made - only mouseDrag messages are sent to the component that the mouse was originally clicked on, until the button is released.

Parameters
Eventdetails about the position and status of the mouse event, including the source component in which it occurred
See also
mouseExit, mouseDrag, mouseMove, contains

Reimplemented from juce::MouseListener.

◆ mouseExit()

void juce::Button::mouseExit ( const MouseEvent & event)
overrideprotectedvirtual

Called when the mouse moves out of a component.

This will be called when the mouse moves off the edge of this component.

If the mouse button was pressed, and it was then dragged off the edge of the component and released, then this callback will happen when the button is released, after the mouseUp callback.

Parameters
Eventdetails about the position and status of the mouse event, including the source component in which it occurred
See also
mouseEnter, mouseDrag, mouseMove, contains

Reimplemented from juce::MouseListener.

◆ mouseUp()

void juce::Button::mouseUp ( const MouseEvent & event)
overrideprotectedvirtual

Called when a mouse button is released.

A mouseUp callback is sent to the component in which a button was pressed even if the mouse is actually over a different component when the button is released.

The MouseEvent object passed in contains lots of methods for finding out which buttons were down just before they were released.

Parameters
Eventdetails about the position and status of the mouse event, including the source component in which it occurred
See also
mouseDown, mouseDrag, mouseDoubleClick, contains

Reimplemented from juce::MouseListener.

◆ paint()

void juce::Button::paint ( Graphics & g)
overrideprotectedvirtual

Components can override this method to draw their content.

The paint() method gets called when a region of a component needs redrawing, either because the component's repaint() method has been called, or because something has happened on the screen that means a section of a window needs to be redrawn.

Any child components will draw themselves over whatever this method draws. If you need to paint over the top of your child components, you can also implement the paintOverChildren() method to do this.

If you want to cause a component to redraw itself, this is done asynchronously - calling the repaint() method marks a region of the component as "dirty", and the paint() method will automatically be called sometime later, by the message thread, to paint any bits that need refreshing. In JUCE (and almost all modern UI frameworks), you never redraw something synchronously.

You should never need to call this method directly - to take a snapshot of the component you could use createComponentSnapshot() or paintEntireComponent().

Parameters
gthe graphics context that must be used to do the drawing operations.
See also
repaint, paintOverChildren, Graphics

Reimplemented from juce::Component.

Reimplemented in juce::Toolbar::Spacer.

◆ paintButton()

virtual void juce::Button::paintButton ( Graphics & g,
bool shouldDrawButtonAsHighlighted,
bool shouldDrawButtonAsDown )
protectedpure virtual

Subclasses should override this to actually paint the button's contents.

It's better to use this than the paint method, because it gives you information about the over/down state of the button.

Parameters
gthe graphics context to use
shouldDrawButtonAsHighlightedtrue if the button is either in the 'over' or 'down' state
shouldDrawButtonAsDowntrue if the button should be drawn in the 'down' position

Implemented in juce::ArrowButton, juce::DrawableButton, juce::HyperlinkButton, juce::ImageButton, juce::KeyMappingEditorComponent::ChangeKeyButton, juce::LookAndFeel_V2::GlassWindowButton, juce::LookAndFeel_V3_DocumentWindowButton, juce::LookAndFeel_V4_DocumentWindowButton, juce::ScrollBar::ScrollbarButton, juce::ShapeButton, juce::TabBarButton, juce::TextButton, juce::ToggleButton, and juce::ToolbarItemComponent.

◆ parentHierarchyChanged()

void juce::Button::parentHierarchyChanged ( )
overrideprotectedvirtual

Called to indicate that the component's parents have changed.

When a component is added or removed from its parent, this method will be called on all of its children (recursively - so all children of its children will also be called as well).

Subclasses can override this if they need to react to this in some way.

See also
getParentComponent, isShowing, ComponentListener::componentParentHierarchyChanged

Reimplemented from juce::Component.

◆ removeListener()

void juce::Button::removeListener ( Listener * listener)

Removes a previously-registered button listener

See also
addListener

◆ repeatTimerCallback()

void juce::Button::repeatTimerCallback ( )
private

◆ sendClickMessage()

void juce::Button::sendClickMessage ( const ModifierKeys & modifiers)
private

◆ sendStateMessage()

void juce::Button::sendStateMessage ( )
private

◆ setButtonText()

void juce::Button::setButtonText ( const String & newText)

Changes the button's text.

See also
getButtonText

◆ setClickingTogglesState()

void juce::Button::setClickingTogglesState ( bool shouldAutoToggleOnClick)
noexcept

This tells the button to automatically flip the toggle state when the button is clicked.

If set to true, then before the clicked() callback occurs, the toggle-state of the button is flipped. This will also cause isToggleable() to return true.

See also
isToggleable

◆ setCommandToTrigger()

void juce::Button::setCommandToTrigger ( ApplicationCommandManager * commandManagerToUse,
CommandID commandID,
bool generateTooltip )

Sets a command ID for this button to automatically invoke when it's clicked.

When the button is pressed, it will use the given manager to trigger the command ID.

Obviously be careful that the ApplicationCommandManager doesn't get deleted before this button is. To disable the command triggering, call this method and pass nullptr as the command manager.

If generateTooltip is true, then the button's tooltip will be automatically generated based on the name of this command and its current shortcut key.

See also
addShortcut, getCommandID

◆ setConnectedEdges()

void juce::Button::setConnectedEdges ( int connectedEdgeFlags)

Hints about which edges of the button might be connected to adjoining buttons.

The value passed in is a bitwise combination of any of the values in the ConnectedEdgeFlags enum.

E.g. if you are placing two buttons adjacent to each other, you could use this to indicate which edges are touching, and the LookAndFeel might choose to drawn them without rounded corners on the edges that connect. It's only a hint, so the LookAndFeel can choose to ignore it if it's not relevant for this type of button.

◆ setRadioGroupId()

void juce::Button::setRadioGroupId ( int newGroupId,
NotificationType notification = sendNotification )

Enables the button to act as a member of a mutually-exclusive group of 'radio buttons'.

If the group ID is set to a non-zero number, then this button will act as part of a group of buttons with the same ID, only one of which can be 'on' at the same time. Note that when it's part of a group, clicking a toggle-button that's 'on' won't turn it off.

To find other buttons with the same ID, this button will search through its sibling components for ToggleButtons, so all the buttons for a particular group must be placed inside the same parent component.

Set the group ID back to zero if you want it to act as a normal toggle button again.

The notification argument lets you specify how other buttons should react to being turned on or off in response to this call.

See also
getRadioGroupId

◆ setRepeatSpeed()

void juce::Button::setRepeatSpeed ( int initialDelayInMillisecs,
int repeatDelayInMillisecs,
int minimumDelayInMillisecs = -1 )
noexcept

Sets an auto-repeat speed for the button when it is held down.

(Auto-repeat is disabled by default).

Parameters
initialDelayInMillisecshow long to wait after the mouse is pressed before triggering the next click. If this is zero, auto-repeat is disabled
repeatDelayInMillisecsthe frequently subsequent repeated clicks should be triggered
minimumDelayInMillisecsif this is greater than 0, the auto-repeat speed will get faster, the longer the button is held down, up to the minimum interval specified here

◆ setState()

void juce::Button::setState ( ButtonState newState)

Can be used to force the button into a particular state.

This only changes the button's appearance, it won't trigger a click, or stop any mouse-clicks from happening.

The state that you set here will only last until it is automatically changed when the mouse enters or exits the button, or the mouse-button is pressed or released.

◆ setToggleable()

void juce::Button::setToggleable ( bool shouldBeToggleable)

Indicates that the button's on/off state is toggleable.

By default this is false, and will only be true for ToggleButtons, buttons that are a part of a radio button group, and buttons for which getClickingTogglesState() == true, however you can use this method to manually indicate that a button is toggleable.

This will present the button as toggleable to accessibility clients and add an accessible "toggle" action for the button that invokes setToggleState().

See also
ToggleButton, isToggleable, setToggleState, setClickingTogglesState, setRadioGroupId

◆ setToggleState() [1/3]

void juce::Button::setToggleState ( bool shouldBeOn,
NotificationType click,
NotificationType state )
private

◆ setToggleState() [2/3]

void juce::Button::setToggleState ( bool shouldBeOn,
NotificationType notification )

A button has an on/off state associated with it, and this changes that.

By default buttons are 'off' and for simple buttons that you click to perform an action you won't change this. Toggle buttons, however will want to change their state when turned on or off.

Parameters
shouldBeOnwhether to set the button's toggle state to be on or off. If it's a member of a button group, this will always try to turn it on, and to turn off any other buttons in the group
notificationdetermines the behaviour if the value changes - this can invoke a synchronous call to clicked(), but sendNotificationAsync is not supported
See also
getToggleState, setRadioGroupId

◆ setToggleState() [3/3]

void juce::Button::setToggleState ( bool shouldBeOn,
bool sendChange )

◆ setTooltip()

void juce::Button::setTooltip ( const String & newTooltip)
overridevirtual

Sets the tooltip for this button.

See also
TooltipClient, TooltipWindow

Reimplemented from juce::SettableTooltipClient.

◆ setTriggeredOnMouseDown()

void juce::Button::setTriggeredOnMouseDown ( bool isTriggeredOnMouseDown)
noexcept

Sets whether the button click should happen when the mouse is pressed or released.

By default the button is only considered to have been clicked when the mouse is released, but setting this to true will make it call the clicked() method as soon as the button is pressed.

This is useful if the button is being used to show a pop-up menu, as it allows the click to be used as a drag onto the menu.

◆ triggerClick()

void juce::Button::triggerClick ( )
virtual

Causes the button to act as if it's been clicked.

This will asynchronously make the button draw itself going down and up, and will then call back the clicked() method as if mouse was clicked on it.

See also
clicked

◆ turnOffOtherButtonsInGroup()

void juce::Button::turnOffOtherButtonsInGroup ( NotificationType click,
NotificationType state )
private

◆ updateAutomaticTooltip()

void juce::Button::updateAutomaticTooltip ( const ApplicationCommandInfo & info)
private

◆ updateState() [1/2]

Button::ButtonState juce::Button::updateState ( )
private

◆ updateState() [2/2]

Button::ButtonState juce::Button::updateState ( bool isOver,
bool isDown )
private

◆ visibilityChanged()

void juce::Button::visibilityChanged ( )
overrideprotectedvirtual

Called when this component's visibility changes.

See also
setVisible, isVisible

Reimplemented from juce::Component.

Member Data Documentation

◆ autoRepeatDelay

int juce::Button::autoRepeatDelay = -1
private

◆ autoRepeatMinimumDelay

int juce::Button::autoRepeatMinimumDelay = -1
private

◆ autoRepeatSpeed

int juce::Button::autoRepeatSpeed = 0
private

◆ buttonListeners

ListenerList<Listener> juce::Button::buttonListeners
private

◆ buttonPressTime

uint32 juce::Button::buttonPressTime = 0
private

◆ buttonState

ButtonState juce::Button::buttonState = buttonNormal
private

◆ callbackHelper

std::unique_ptr<CallbackHelper> juce::Button::callbackHelper
private

◆ canBeToggled

bool juce::Button::canBeToggled = false
private

◆ clickTogglesState

bool juce::Button::clickTogglesState = false
private

◆ commandID

CommandID juce::Button::commandID = {}
private

◆ commandManagerToUse

ApplicationCommandManager* juce::Button::commandManagerToUse = nullptr
private

◆ connectedEdgeFlags

int juce::Button::connectedEdgeFlags = 0
private

◆ generateTooltip

bool juce::Button::generateTooltip = false
private

◆ isKeyDown

bool juce::Button::isKeyDown = false
private

◆ isOn

Value juce::Button::isOn
private

◆ keySource

WeakReference<Component> juce::Button::keySource
private

◆ lastRepeatTime

uint32 juce::Button::lastRepeatTime = 0
private

◆ lastStatePainted

ButtonState juce::Button::lastStatePainted = buttonNormal
private

◆ lastToggleState

bool juce::Button::lastToggleState = false
private

◆ needsRepainting

bool juce::Button::needsRepainting = false
private

◆ needsToRelease

bool juce::Button::needsToRelease = false
private

◆ onClick

std::function<void()> juce::Button::onClick

You can assign a lambda to this callback object to have it called when the button is clicked.

◆ onStateChange

std::function<void()> juce::Button::onStateChange

You can assign a lambda to this callback object to have it called when the button's state changes.

◆ radioGroupId

int juce::Button::radioGroupId = 0
private

◆ shortcuts

Array<KeyPress> juce::Button::shortcuts
private

◆ text

String juce::Button::text
private

◆ triggerOnMouseDown

bool juce::Button::triggerOnMouseDown = false
private

The documentation for this class was generated from the following files: