29namespace TabbedComponentHelpers
31 const Identifier deleteComponentId (
"deleteByTabComp_");
33 static void deleteIfNecessary (Component* comp)
35 if (comp !=
nullptr && (
bool) comp->getProperties() [deleteComponentId])
39 static Rectangle<int> getTabArea (Rectangle<int>& content, BorderSize<int>& outline,
44 case TabbedButtonBar::TabsAtTop: outline.
setTop (0);
return content.removeFromTop (tabDepth);
45 case TabbedButtonBar::TabsAtBottom: outline.setBottom (0);
return content.removeFromBottom (tabDepth);
46 case TabbedButtonBar::TabsAtLeft: outline.setLeft (0);
return content.removeFromLeft (tabDepth);
47 case TabbedButtonBar::TabsAtRight: outline.setRight (0);
return content.removeFromRight (tabDepth);
51 return Rectangle<int>();
75 return owner.tabs->getTabBackgroundColour (
tabIndex);
91 tabs.reset (
new ButtonBar (*
this, orientation));
104 tabs->setOrientation (orientation);
110 return tabs->getOrientation();
130 if (panelComponent !=
nullptr)
132 panelComponent->setVisible (
false);
134 panelComponent =
nullptr;
139 for (
int i = contentComponents.size(); --i >= 0;)
140 TabbedComponentHelpers::deleteIfNecessary (contentComponents.getReference (i));
142 contentComponents.clear();
154 contentComponent->
getProperties().
set (TabbedComponentHelpers::deleteComponentId,
true);
162 tabs->setTabName (
tabIndex, newName);
169 TabbedComponentHelpers::deleteIfNecessary (contentComponents.getReference (
tabIndex).get());
170 contentComponents.remove (
tabIndex);
183 return tabs->getNumTabs();
188 return tabs->getTabNames();
193 return contentComponents[
tabIndex].get();
198 return tabs->getTabBackgroundColour (
tabIndex);
211 tabs->setCurrentTabIndex (
newTabIndex, sendChangeMessage);
216 return tabs->getCurrentTabIndex();
221 return tabs->getCurrentTabName();
226 outlineThickness = thickness;
244 TabbedComponentHelpers::getTabArea (content, outline,
getOrientation(), tabDepth);
249 if (outlineThickness > 0)
264 tabs->setBounds (TabbedComponentHelpers::getTabArea (content, outline,
getOrientation(), tabDepth));
267 for (
auto& c : contentComponents)
268 if (
auto comp = c.get())
269 comp->setBounds (content);
274 for (
auto& c : contentComponents)
275 if (
auto comp = c.get())
276 comp->lookAndFeelChanged();
285 if (panelComponent !=
nullptr)
287 panelComponent->setVisible (
false);
293 if (panelComponent !=
nullptr)
298 panelComponent->sendLookAndFeelChange();
299 panelComponent->setVisible (
true);
300 panelComponent->toFront (
true);
316 return std::make_unique<AccessibilityHandler> (*
this, AccessibilityRole::group);
Specifies a set of gaps to be left around the sides of a rectangle.
Rectangle< ValueType > subtractedFrom(const Rectangle< ValueType > &original) const noexcept
Returns a rectangle with these borders removed from it.
Represents a colour, also including a transparency value.
The base class for all JUCE user-interface objects.
void addAndMakeVisible(Component *child, int zOrder=-1)
Adds a child component to this one, and also makes the child visible if it isn't already.
void repaint()
Marks the whole component as needing to be redrawn.
NamedValueSet & getProperties() noexcept
Returns the set of properties that belong to this component.
void removeChildComponent(Component *childToRemove)
Removes one of this component's child-components.
Colour findColour(int colourID, bool inheritFromParent=false) const
Looks for a colour that has been registered with the given colour ID number.
Rectangle< int > getLocalBounds() const noexcept
Returns the component's bounds, relative to its own origin.
void addChildComponent(Component *child, int zOrder=-1)
Adds a child component to this one.
A graphics context, used for drawing a component or image.
bool reduceClipRegion(int x, int y, int width, int height)
Intersects the current clipping region with another region.
void fillAll() const
Fills the context's entire clip region with the current colour or brush.
bool set(const Identifier &name, const var &newValue)
Changes or adds a named value.
Maintains a set of rectangles as a complex region.
void setTop(ValueType newTop) noexcept
Moves the y position, adjusting the height so that the bottom edge remains in the same place.
A special array for holding a list of strings.
A component with a TabbedButtonBar along one of its sides.
void clearTabs()
Removes all the tabs from the bar.
void addTab(const String &tabName, Colour tabBackgroundColour, Component *contentComponent, bool deleteComponentWhenNotNeeded, int insertIndex=-1)
Adds a tab to the tab-bar.
void paint(Graphics &) override
Components can override this method to draw their content.
~TabbedComponent() override
Destructor.
virtual TabBarButton * createTabButton(const String &tabName, int tabIndex)
This creates one of the tab buttons.
int getCurrentTabIndex() const
Returns the index of the currently selected tab.
void setTabBarDepth(int newDepth)
Specifies how many pixels wide or high the tab-bar should be.
void setOutline(int newThickness)
Specifies the thickness of an outline that should be drawn around the content component.
@ outlineColourId
The colour to use to draw an outline around the content.
@ backgroundColourId
The colour to fill the background behind the tabs.
int getNumTabs() const
Returns the number of tabs in the bar.
virtual void popupMenuClickOnTab(int tabIndex, const String &tabName)
Callback method to indicate that the user has right-clicked on a tab.
virtual void currentTabChanged(int newCurrentTabIndex, const String &newCurrentTabName)
Callback method to indicate the selected tab has been changed.
void removeTab(int tabIndex)
Gets rid of one of the tabs.
void resized() override
Called when this component's size has been changed.
void setCurrentTabIndex(int newTabIndex, bool sendChangeMessage=true)
Changes the currently-selected tab.
void setTabBackgroundColour(int tabIndex, Colour newColour)
Changes the background colour of one of the tabs.
TabbedComponent(TabbedButtonBar::Orientation orientation)
Creates a TabbedComponent, specifying where the tabs should be placed.
Colour getTabBackgroundColour(int tabIndex) const noexcept
Returns the colour of one of the tabs.
void setTabName(int tabIndex, const String &newName)
Changes the name of one of the tabs.
void setIndent(int indentThickness)
Specifies a gap to leave around the edge of the content component.
void setOrientation(TabbedButtonBar::Orientation orientation)
Changes the placement of the tabs.
TabbedButtonBar::Orientation getOrientation() const noexcept
Returns the current tab placement.
StringArray getTabNames() const
Returns a list of all the tab names in the bar.
void lookAndFeelChanged() override
Called to let the component react to a change in the look-and-feel setting.
Component * getTabContentComponent(int tabIndex) const noexcept
Returns the content component that was added for the given index.
std::unique_ptr< AccessibilityHandler > createAccessibilityHandler() override
Override this method to return a custom AccessibilityHandler for this component.
String getCurrentTabName() const
Returns the name of the currently selected tab.
void moveTab(int currentIndex, int newIndex, bool animate=false)
Moves a tab to a new index in the list.
This class acts as a pointer which will automatically become null if the object to which it points is...
Type unalignedPointerCast(void *ptr) noexcept
Casts a pointer to another type via void*, which suppresses the cast-align warning which sometimes ar...
bool isPositiveAndBelow(Type1 valueToTest, Type2 upperLimit) noexcept
Returns true if a value is at least zero, and also below a specified upper limit.