mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-10 23:44:24 +00:00
Update SidePanel visibility when shown/hidden and set always on top
This commit is contained in:
parent
af69be5346
commit
d7358d0ef1
2 changed files with 36 additions and 13 deletions
|
|
@ -39,17 +39,25 @@ SidePanel::SidePanel (StringRef title, int width, bool positionOnLeft,
|
|||
dismissButton.onClick = [this] { showOrHide (false); };
|
||||
addAndMakeVisible (dismissButton);
|
||||
|
||||
Desktop::getInstance().addGlobalMouseListener (this);
|
||||
auto& desktop = Desktop::getInstance();
|
||||
|
||||
desktop.addGlobalMouseListener (this);
|
||||
desktop.getAnimator().addChangeListener (this);
|
||||
|
||||
if (contentToDisplay != nullptr)
|
||||
setContent (contentToDisplay, deleteComponentWhenNoLongerNeeded);
|
||||
|
||||
setOpaque (false);
|
||||
setVisible (false);
|
||||
setAlwaysOnTop (true);
|
||||
}
|
||||
|
||||
SidePanel::~SidePanel()
|
||||
{
|
||||
Desktop::getInstance().removeGlobalMouseListener (this);
|
||||
auto& desktop = Desktop::getInstance();
|
||||
|
||||
desktop.removeGlobalMouseListener (this);
|
||||
desktop.getAnimator().removeChangeListener (this);
|
||||
|
||||
if (parent != nullptr)
|
||||
parent->removeComponentListener (this);
|
||||
|
|
@ -98,6 +106,9 @@ void SidePanel::showOrHide (bool show)
|
|||
Desktop::getInstance().getAnimator().animateComponent (this, calculateBoundsInParent (*parent),
|
||||
1.0f, 250, true, 1.0, 0.0);
|
||||
|
||||
if (isShowing && ! isVisible())
|
||||
setVisible (true);
|
||||
|
||||
if (onPanelShowHide != nullptr)
|
||||
onPanelShowHide (isShowing);
|
||||
}
|
||||
|
|
@ -242,6 +253,12 @@ void SidePanel::componentMovedOrResized (Component& component, bool wasMoved, bo
|
|||
setBounds (calculateBoundsInParent (component));
|
||||
}
|
||||
|
||||
void SidePanel::changeListenerCallback (ChangeBroadcaster*)
|
||||
{
|
||||
if (isVisible() && ! isShowing && ! Desktop::getInstance().getAnimator().isAnimating (this))
|
||||
setVisible (false);
|
||||
}
|
||||
|
||||
Rectangle<int> SidePanel::calculateBoundsInParent (Component& parentComp) const
|
||||
{
|
||||
auto parentBounds = parentComp.getLocalBounds();
|
||||
|
|
|
|||
|
|
@ -39,7 +39,8 @@ namespace juce
|
|||
@tags{GUI}
|
||||
*/
|
||||
class SidePanel : public Component,
|
||||
private ComponentListener
|
||||
private ComponentListener,
|
||||
private ChangeListener
|
||||
{
|
||||
public:
|
||||
//==============================================================================
|
||||
|
|
@ -144,16 +145,6 @@ public:
|
|||
/** Returns the text that is displayed in the title bar at the top of the SidePanel. */
|
||||
String getTitleText() const noexcept { return titleLabel.getText(); }
|
||||
|
||||
//==============================================================================
|
||||
void moved() override;
|
||||
void resized() override;
|
||||
void paint (Graphics& g) override;
|
||||
|
||||
void parentHierarchyChanged() override;
|
||||
|
||||
void mouseDrag (const MouseEvent&) override;
|
||||
void mouseUp (const MouseEvent&) override;
|
||||
|
||||
//==============================================================================
|
||||
/** This abstract base class is implemented by LookAndFeel classes to provide
|
||||
SidePanel drawing functionality.
|
||||
|
|
@ -191,6 +182,20 @@ public:
|
|||
/** You can assign a lambda to this callback object and it will be called when the panel is shown or hidden. */
|
||||
std::function<void (bool)> onPanelShowHide;
|
||||
|
||||
//==============================================================================
|
||||
/** @internal */
|
||||
void moved() override;
|
||||
/** @internal */
|
||||
void resized() override;
|
||||
/** @internal */
|
||||
void paint (Graphics& g) override;
|
||||
/** @internal */
|
||||
void parentHierarchyChanged() override;
|
||||
/** @internal */
|
||||
void mouseDrag (const MouseEvent&) override;
|
||||
/** @internal */
|
||||
void mouseUp (const MouseEvent&) override;
|
||||
|
||||
private:
|
||||
//==============================================================================
|
||||
Component* parent = nullptr;
|
||||
|
|
@ -218,6 +223,7 @@ private:
|
|||
//==============================================================================
|
||||
void lookAndFeelChanged() override;
|
||||
void componentMovedOrResized (Component&, bool wasMoved, bool wasResized) override;
|
||||
void changeListenerCallback (ChangeBroadcaster*) override;
|
||||
|
||||
Rectangle<int> calculateBoundsInParent (Component&) const;
|
||||
void calculateAndRemoveShadowBounds (Rectangle<int>& bounds);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue