|
/* |
|
============================================================================== |
|
|
|
ButtonTooltipBubble.h |
|
Created: 13 Aug 2019 2:51:47pm |
|
Author: Adam Wilson |
|
|
|
============================================================================== |
|
|
|
This class is designed to add a tooltip to a Button or Button subclass. |
|
|
|
Usage: Add and instantiate as a member in your class. E.g. for a button subclass: |
|
|
|
``` |
|
ButtonTooltipBubble tooltip { *this }; |
|
``` |
|
|
|
or for a Button member: |
|
|
|
``` |
|
ButtonTooltipBubble tooltip { myButton }; |
|
``` |
|
*/ |
|
|
|
#pragma once |
|
|
|
#include "JuceHeader.h" |
|
|
|
class ButtonTooltipBubble |
|
: private MouseListener, |
|
private Button::Listener, |
|
private Timer |
|
{ |
|
public: |
|
ButtonTooltipBubble (Button& buttonToWatch) : watchedButton (buttonToWatch) |
|
{ |
|
watchedButton.addMouseListener (this, true); |
|
watchedButton.addListener (this); |
|
|
|
if (! tooltipBubble->isOnDesktop()) |
|
{ |
|
tooltipBubble->addToDesktop(0); |
|
tooltipBubble->setVisible (true); |
|
tooltipBubble->setAllowedPlacement (BubbleComponent::BubblePlacement::below); |
|
} |
|
} |
|
|
|
~ButtonTooltipBubble() |
|
{ |
|
watchedButton.removeMouseListener (this); |
|
} |
|
|
|
void mouseEnter (const MouseEvent&) override |
|
{ |
|
startTimer(1000); |
|
} |
|
|
|
void mouseExit (const MouseEvent&) override |
|
{ |
|
tooltipBubble->setVisible (false); |
|
stopTimer(); |
|
} |
|
|
|
void buttonClicked (Button *button) override |
|
{ |
|
tooltipBubble->setVisible (false); |
|
stopTimer(); |
|
} |
|
|
|
|
|
void timerCallback() override |
|
{ |
|
auto attrString = AttributedString (watchedButton.getTooltip()); |
|
attrString.setColour (Colours::white); |
|
tooltipBubble->showAt (&watchedButton, attrString, 2000); |
|
stopTimer(); |
|
} |
|
|
|
SharedResourcePointer<BubbleMessageComponent> tooltipBubble; |
|
|
|
private: |
|
Button& watchedButton; |
|
|
|
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ButtonTooltipBubble); |
|
}; |