JUCE-7.0.12-0-g4f43011b96 JUCE-7.0.12-0-g4f43011b96
JUCE — C++ application framework with suport for VST, VST3, LV2 audio plug-ins

« « « Anklang Documentation
Loading...
Searching...
No Matches
juce_TabbedButtonBar.h
Go to the documentation of this file.
1 /*
2 ==============================================================================
3
4 This file is part of the JUCE library.
5 Copyright (c) 2022 - Raw Material Software Limited
6
7 JUCE is an open source library subject to commercial or open-source
8 licensing.
9
10 By using JUCE, you agree to the terms of both the JUCE 7 End-User License
11 Agreement and JUCE Privacy Policy.
12
13 End User License Agreement: www.juce.com/juce-7-licence
14 Privacy Policy: www.juce.com/juce-privacy-policy
15
16 Or: You may also use this code under the terms of the GPL v3 (see
17 www.gnu.org/licenses).
18
19 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
20 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
21 DISCLAIMED.
22
23 ==============================================================================
24*/
25
26namespace juce
27{
28
29class TabbedButtonBar;
30
31
32//==============================================================================
43class JUCE_API TabBarButton : public Button
44{
45public:
46 //==============================================================================
48 TabBarButton (const String& name, TabbedButtonBar& ownerBar);
49
51 ~TabBarButton() override;
52
54 TabbedButtonBar& getTabbedButtonBar() const { return owner; }
55
56 //==============================================================================
60 {
61 beforeText,
62 afterText
63 };
64
72 void setExtraComponent (Component* extraTabComponent,
73 ExtraComponentPlacement extraComponentPlacement);
74
76 Component* getExtraComponent() const noexcept { return extraComponent.get(); }
77
79 ExtraComponentPlacement getExtraComponentPlacement() const noexcept { return extraCompPlacement; }
80
86 Rectangle<int> getActiveArea() const;
87
89 Rectangle<int> getTextArea() const;
90
92 int getIndex() const;
93
95 Colour getTabBackgroundColour() const;
96
98 bool isFrontTab() const;
99
100 //==============================================================================
107 virtual int getBestTabLength (int depth);
108
109 //==============================================================================
111 void paintButton (Graphics&, bool, bool) override;
113 void clicked (const ModifierKeys&) override;
115 bool hitTest (int x, int y) override;
117 void resized() override;
119 void childBoundsChanged (Component*) override;
120
121protected:
122 friend class TabbedButtonBar;
123 TabbedButtonBar& owner;
124 int overlapPixels = 0;
125
126 std::unique_ptr<Component> extraComponent;
127 ExtraComponentPlacement extraCompPlacement = afterText;
128
129private:
130 using Button::clicked;
131 void calcAreas (Rectangle<int>&, Rectangle<int>&) const;
132
134};
135
136
137//==============================================================================
153class JUCE_API TabbedButtonBar : public Component,
154 public ChangeBroadcaster
155{
156public:
157 //==============================================================================
162 {
163 TabsAtTop,
164 TabsAtBottom,
165 TabsAtLeft,
166 TabsAtRight
167 };
168
169 //==============================================================================
173 TabbedButtonBar (Orientation orientation);
174
176 ~TabbedButtonBar() override;
177
178 //==============================================================================
185 void setOrientation (Orientation orientation);
186
190 Orientation getOrientation() const noexcept { return orientation; }
191
193 bool isVertical() const noexcept { return orientation == TabsAtLeft || orientation == TabsAtRight; }
194
196 int getThickness() const noexcept { return isVertical() ? getWidth() : getHeight(); }
197
201 void setMinimumTabScaleFactor (double newMinimumScale);
202
203 //==============================================================================
207 void clearTabs();
208
213 void addTab (const String& tabName,
214 Colour tabBackgroundColour,
215 int insertIndex);
216
218 void setTabName (int tabIndex, const String& newName);
219
221 void removeTab (int tabIndex, bool animate = false);
222
226 void moveTab (int currentIndex, int newIndex, bool animate = false);
227
229 int getNumTabs() const;
230
232 StringArray getTabNames() const;
233
241 void setCurrentTabIndex (int newTabIndex, bool sendChangeMessage = true);
242
246 String getCurrentTabName() const;
247
251 int getCurrentTabIndex() const noexcept { return currentTabIndex; }
252
258 TabBarButton* getTabButton (int index) const;
259
261 int indexOfTabButton (const TabBarButton* button) const;
262
264 Rectangle<int> getTargetBounds (TabBarButton* button) const;
265
266 //==============================================================================
270 virtual void currentTabChanged (int newCurrentTabIndex,
271 const String& newCurrentTabName);
272
274 virtual void popupMenuClickOnTab (int tabIndex, const String& tabName);
275
279 Colour getTabBackgroundColour (int tabIndex);
280
284 void setTabBackgroundColour (int tabIndex, Colour newColour);
285
286 //==============================================================================
295 {
296 tabOutlineColourId = 0x1005812,
297 tabTextColourId = 0x1005813,
299 frontOutlineColourId = 0x1005814,
300 frontTextColourId = 0x1005815,
303 };
304
305 //==============================================================================
309 struct JUCE_API LookAndFeelMethods
310 {
311 virtual ~LookAndFeelMethods() = default;
312
313 virtual int getTabButtonSpaceAroundImage() = 0;
314 virtual int getTabButtonOverlap (int tabDepth) = 0;
315 virtual int getTabButtonBestWidth (TabBarButton&, int tabDepth) = 0;
316 virtual Rectangle<int> getTabButtonExtraComponentBounds (const TabBarButton&, Rectangle<int>& textArea, Component& extraComp) = 0;
317
318 virtual void drawTabButton (TabBarButton&, Graphics&, bool isMouseOver, bool isMouseDown) = 0;
319 virtual Font getTabButtonFont (TabBarButton&, float height) = 0;
320 virtual void drawTabButtonText (TabBarButton&, Graphics&, bool isMouseOver, bool isMouseDown) = 0;
321 virtual void drawTabbedButtonBarBackground (TabbedButtonBar&, Graphics&) = 0;
322 virtual void drawTabAreaBehindFrontButton (TabbedButtonBar&, Graphics&, int w, int h) = 0;
323
324 virtual void createTabButtonShape (TabBarButton&, Path& path, bool isMouseOver, bool isMouseDown) = 0;
325 virtual void fillTabButtonShape (TabBarButton&, Graphics&, const Path& path, bool isMouseOver, bool isMouseDown) = 0;
326
327 virtual Button* createTabBarExtrasButton() = 0;
328 };
329
330 //==============================================================================
332 void paint (Graphics&) override;
334 void resized() override;
336 void lookAndFeelChanged() override;
338 std::unique_ptr<AccessibilityHandler> createAccessibilityHandler() override;
339
340protected:
341 //==============================================================================
347 virtual TabBarButton* createTabButton (const String& tabName, int tabIndex);
348
349private:
350 struct TabInfo
351 {
353 String name;
354 Colour colour;
355 };
356
358
359 Orientation orientation;
360 double minimumScale = 0.7;
361 int currentTabIndex = -1;
362
363 class BehindFrontTabComp;
365 std::unique_ptr<Button> extraTabsButton;
366
367 void showExtraItemsMenu();
368 void updateTabPositions (bool animate);
369
371};
372
373} // namespace juce
A base class for buttons.
Definition juce_Button.h:43
Holds a list of ChangeListeners, and sends messages to them when instructed.
Represents a colour, also including a transparency value.
Definition juce_Colour.h:38
The base class for all JUCE user-interface objects.
Represents a particular font, including its size, style, etc.
Definition juce_Font.h:42
A graphics context, used for drawing a component or image.
Represents the state of the mouse buttons and modifier keys.
An array designed for holding objects.
A path is a sequence of lines and curves that may either form a closed shape or be open-ended.
Definition juce_Path.h:65
Manages a rectangle and allows geometric operations to be performed on it.
A special array for holding a list of strings.
The JUCE String class!
Definition juce_String.h:53
In a TabbedButtonBar, this component is used for each of the buttons.
ExtraComponentPlacement getExtraComponentPlacement() const noexcept
Returns the placement of the custom component, if there is one.
Component * getExtraComponent() const noexcept
Returns the custom component, if there is one.
TabbedButtonBar & getTabbedButtonBar() const
Returns the bar that contains this button.
ExtraComponentPlacement
When adding an extra component to the tab, this indicates which side of the text it should be placed ...
A vertical or horizontal bar containing tabs that you can select.
int getCurrentTabIndex() const noexcept
Returns the index of the currently selected tab.
Orientation getOrientation() const noexcept
Returns the bar's current orientation.
Orientation
The placement of the tab-bar.
ColourIds
A set of colour IDs to use to change the colour of various aspects of the component.
bool isVertical() const noexcept
Returns true if the orientation is TabsAtLeft or TabsAtRight.
int getThickness() const noexcept
Returns the thickness of the bar, which may be its width or height, depending on the orientation.
#define JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(className)
This is a shorthand way of writing both a JUCE_DECLARE_NON_COPYABLE and JUCE_LEAK_DETECTOR macro for ...
JUCE Namespace.
This abstract base class is implemented by LookAndFeel classes to provide window drawing functionalit...