1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

Added ConcertinaPanel::setCustomPanelHeader() method to allow custom components to be used as ConcertinaPanel headers

This commit is contained in:
ed 2017-03-31 14:24:53 +01:00
parent 28c3faea23
commit dc10e61366
2 changed files with 50 additions and 5 deletions

View file

@ -219,16 +219,25 @@ public:
void paint (Graphics& g) override
{
const Rectangle<int> area (getWidth(), getHeaderSize());
g.reduceClipRegion (area);
if (customHeaderComponent == nullptr)
{
const Rectangle<int> area (getWidth(), getHeaderSize());
g.reduceClipRegion (area);
getLookAndFeel().drawConcertinaPanelHeader (g, area, isMouseOver(), isMouseButtonDown(),
getPanel(), *component);
getLookAndFeel().drawConcertinaPanelHeader (g, area, isMouseOver(), isMouseButtonDown(),
getPanel(), *component);
}
}
void resized() override
{
component->setBounds (getLocalBounds().withTop (getHeaderSize()));
auto bounds = getLocalBounds();
auto headerBounds = bounds.removeFromTop (getHeaderSize());
if (customHeaderComponent != nullptr)
customHeaderComponent->setBounds (headerBounds);
component->setBounds (bounds);
}
void mouseDown (const MouseEvent&) override
@ -250,11 +259,23 @@ public:
getPanel().panelHeaderDoubleClicked (component);
}
void setCustomHeaderComponent (Component* headerComponent, bool shouldTakeOwnership)
{
customHeaderComponent.set (headerComponent, shouldTakeOwnership);
if (headerComponent != nullptr)
{
addAndMakeVisible (customHeaderComponent);
customHeaderComponent->addMouseListener (this, false);
}
}
OptionalScopedPointer<Component> component;
private:
PanelSizes dragStartSizes;
int mouseDownY;
OptionalScopedPointer<Component> customHeaderComponent;
int getHeaderSize() const noexcept
{
@ -362,6 +383,17 @@ void ConcertinaPanel::setPanelHeaderSize (Component* component, int headerSize)
}
}
void ConcertinaPanel::setCustomPanelHeader (Component* component, Component* customComponent, bool takeOwnership)
{
OptionalScopedPointer<Component> optional (customComponent, takeOwnership);
const auto index = indexOfComp (component);
jassert (index >= 0); // The specified component doesn't seem to have been added!
if (index >= 0)
holders.getUnchecked (index)->setCustomHeaderComponent (optional.release(), takeOwnership);
}
void ConcertinaPanel::resized()
{
applyLayout (getFittedSizes(), false);

View file

@ -92,6 +92,19 @@ public:
/** Sets the height of the header section for one of the panels. */
void setPanelHeaderSize (Component* panelComponent, int headerSize);
/** Sets a custom header Component for one of the panels.
@param panelComponent the panel component to add the custom header to.
@param customHeaderComponent the custom component to use for the panel header.
This can be nullptr to clear the custom header component
and just use the standard LookAndFeel panel.
@param takeOwnership if true, then the PanelHolder will take ownership
of the custom header component, and will delete it later when
it's no longer needed. If false, it won't delete it, and
you must make sure it doesn't get deleted while in use.
*/
void setCustomPanelHeader (Component* panelComponent, Component* customHeaderComponent, bool takeOwnership);
//==============================================================================
/** This abstract base class is implemented by LookAndFeel classes. */
struct JUCE_API LookAndFeelMethods