mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-10 23:44:24 +00:00
Added some methods to SidePanel to set a custom title bar
This commit is contained in:
parent
1f770cc7c8
commit
a604c49a35
2 changed files with 72 additions and 6 deletions
|
|
@ -69,6 +69,25 @@ void SidePanel::setContent (Component* newContent, bool deleteComponentWhenNoLon
|
|||
}
|
||||
}
|
||||
|
||||
void SidePanel::setTitleBarComponent (Component* titleBarComponentToUse,
|
||||
bool keepDismissButton,
|
||||
bool deleteComponentWhenNoLongerNeeded)
|
||||
{
|
||||
if (titleBarComponent.get() != titleBarComponentToUse)
|
||||
{
|
||||
if (deleteComponentWhenNoLongerNeeded)
|
||||
titleBarComponent.setOwned (titleBarComponentToUse);
|
||||
else
|
||||
titleBarComponent.setNonOwned (titleBarComponentToUse);
|
||||
|
||||
addAndMakeVisible (titleBarComponent);
|
||||
|
||||
resized();
|
||||
}
|
||||
|
||||
shouldShowDismissButton = keepDismissButton;
|
||||
}
|
||||
|
||||
void SidePanel::showOrHide (bool show)
|
||||
{
|
||||
if (parent != nullptr)
|
||||
|
|
@ -97,11 +116,22 @@ void SidePanel::resized()
|
|||
|
||||
auto titleBounds = bounds.removeFromTop (titleBarHeight);
|
||||
|
||||
dismissButton.setBounds (isOnLeft ? titleBounds.removeFromRight (30).withTrimmedRight (10)
|
||||
: titleBounds.removeFromLeft (30).withTrimmedLeft (10));
|
||||
if (titleBarComponent != nullptr)
|
||||
{
|
||||
if (shouldShowDismissButton)
|
||||
dismissButton.setBounds (isOnLeft ? titleBounds.removeFromRight (30).withTrimmedRight (10)
|
||||
: titleBounds.removeFromLeft (30).withTrimmedLeft (10));
|
||||
|
||||
titleLabel.setBounds (isOnLeft ? titleBounds.withTrimmedRight (40)
|
||||
: titleBounds.withTrimmedLeft (40));
|
||||
titleBarComponent->setBounds (titleBounds);
|
||||
}
|
||||
else
|
||||
{
|
||||
dismissButton.setBounds (isOnLeft ? titleBounds.removeFromRight (30).withTrimmedRight (10)
|
||||
: titleBounds.removeFromLeft (30).withTrimmedLeft (10));
|
||||
|
||||
titleLabel.setBounds (isOnLeft ? titleBounds.withTrimmedRight (40)
|
||||
: titleBounds.withTrimmedLeft (40));
|
||||
}
|
||||
|
||||
if (contentComponent != nullptr)
|
||||
contentComponent->setBounds (bounds);
|
||||
|
|
|
|||
|
|
@ -71,7 +71,7 @@ public:
|
|||
(Don't add or remove any child components directly using the normal
|
||||
Component::addChildComponent() methods).
|
||||
|
||||
@param newContentComponent the component to add to this SidePanel, or null to remove
|
||||
@param newContentComponent the component to add to this SidePanel, or nullptr to remove
|
||||
the current component.
|
||||
@param deleteComponentWhenNoLongerNeeded if true, the component will be deleted automatically when
|
||||
the SidePanel is deleted or when a different component is added. If false,
|
||||
|
|
@ -86,7 +86,31 @@ public:
|
|||
|
||||
@see setViewedComponent
|
||||
*/
|
||||
Component* getContent() { return contentComponent.get(); }
|
||||
Component* getContent() const noexcept { return contentComponent.get(); }
|
||||
|
||||
/** Sets a custom component to be used for the title bar of this SidePanel, replacing
|
||||
the default. You can pass a nullptr to revert to the default title bar.
|
||||
|
||||
@param titleBarComponentToUse the component to use as the title bar, or nullptr to use
|
||||
the default
|
||||
@param keepDismissButton if false the specified component will take up the full width of
|
||||
the title bar including the dismiss button but if true, the default
|
||||
dismiss button will be kept
|
||||
@param deleteComponentWhenNoLongerNeeded if true, the component will be deleted automatically when
|
||||
the SidePanel is deleted or when a different component is added. If false,
|
||||
the caller must manage the lifetime of the component
|
||||
|
||||
@see getTitleBarComponent
|
||||
*/
|
||||
void setTitleBarComponent (Component* titleBarComponentToUse,
|
||||
bool keepDismissButton,
|
||||
bool deleteComponentWhenNoLongerNeeded = true);
|
||||
|
||||
/** Returns the component that is currently being used as the title bar of the SidePanel.
|
||||
|
||||
@see setTitleBarComponent
|
||||
*/
|
||||
Component* getTitleBarComponent() const noexcept { return titleBarComponent.get(); }
|
||||
|
||||
/** Shows or hides the SidePanel.
|
||||
|
||||
|
|
@ -108,9 +132,18 @@ public:
|
|||
/** Sets the width of the shadow that will be drawn on the side of the panel. */
|
||||
void setShadowWidth (int newWidth) noexcept { shadowWidth = newWidth; }
|
||||
|
||||
/** Returns the width of the shadow that will be drawn on the side of the panel. */
|
||||
int getShadowWidth() const noexcept { return shadowWidth; }
|
||||
|
||||
/** Sets the height of the title bar at the top of the SidePanel. */
|
||||
void setTitleBarHeight (int newHeight) noexcept { titleBarHeight = newHeight; }
|
||||
|
||||
/** Returns the height of the title bar at the top of the SidePanel. */
|
||||
int getTitleBarHeight() const noexcept { return titleBarHeight; }
|
||||
|
||||
/** 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;
|
||||
|
|
@ -162,6 +195,7 @@ private:
|
|||
//==========================================================================
|
||||
Component* parent = nullptr;
|
||||
OptionalScopedPointer<Component> contentComponent;
|
||||
OptionalScopedPointer<Component> titleBarComponent;
|
||||
|
||||
Label titleLabel;
|
||||
ShapeButton dismissButton { "dismissButton", Colours::lightgrey, Colours::lightgrey, Colours::white };
|
||||
|
|
@ -179,6 +213,8 @@ private:
|
|||
bool shouldResize = false;
|
||||
int amountMoved = 0;
|
||||
|
||||
bool shouldShowDismissButton = true;
|
||||
|
||||
//==========================================================================
|
||||
void lookAndFeelChanged() override;
|
||||
void componentMovedOrResized (Component&, bool wasMoved, bool wasResized) override;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue