A component that can be used as one of the items in a Toolbar. More...
Inherits Button.
Inherited by ToolbarButton.
Public Types | |
| enum | ToolbarEditingMode { normalMode = 0, editableOnToolbar, editableOnPalette } |
Editing modes. More... | |
Public Member Functions | |
| ToolbarItemComponent (int itemId, const String &labelText, bool isBeingUsedAsAButton) | |
| Constructor. | |
| ~ToolbarItemComponent () | |
| Destructor. | |
| int | getItemId () const noexcept |
| Returns the item type ID that this component represents. | |
| Toolbar * | getToolbar () const |
| Returns the toolbar that contains this component, or 0 if it's not currently inside one. | |
| bool | isToolbarVertical () const |
| Returns true if this component is currently inside a toolbar which is vertical. | |
| Toolbar::ToolbarItemStyle | getStyle () const noexcept |
| Returns the current style setting of this item. | |
| virtual void | setStyle (const Toolbar::ToolbarItemStyle &newStyle) |
| Changes the current style setting of this item. | |
| const Rectangle< int > | getContentArea () const noexcept |
| Returns the area of the component that should be used to display the button image or other contents of the item. | |
| virtual bool | getToolbarItemSizes (int toolbarThickness, bool isToolbarVertical, int &preferredSize, int &minSize, int &maxSize)=0 |
| This method must return the size criteria for this item, based on a given toolbar size and orientation. | |
| virtual void | paintButtonArea (Graphics &g, int width, int height, bool isMouseOver, bool isMouseDown)=0 |
| Your subclass should use this method to draw its content area. | |
| virtual void | contentAreaChanged (const Rectangle< int > &newBounds)=0 |
| Callback to indicate that the content area of this item has changed. | |
| void | setEditingMode (const ToolbarEditingMode newMode) |
| Changes the editing mode of this component. | |
| ToolbarEditingMode | getEditingMode () const noexcept |
| Returns the current editing mode of this component. | |
| void | paintButton (Graphics &g, bool isMouseOver, bool isMouseDown) |
| Subclasses should override this to actually paint the button's contents. | |
| void | resized () |
| Called when this component's size has been changed. | |
A component that can be used as one of the items in a Toolbar.
Each of the items on a toolbar must be a component derived from ToolbarItemComponent, and these objects are always created by a ToolbarItemFactory - see the ToolbarItemFactory class for further info about creating them.
The ToolbarItemComponent class is actually a button, but can be used to hold non-button components too. To do this, set the value of isBeingUsedAsAButton to false when calling the constructor, and override contentAreaChanged(), in which you can position any sub-components you need to add.
To add basic buttons without writing a special subclass, have a look at the ToolbarButton class.
Editing modes.
These are used by setEditingMode(), but will be rarely needed in user code.
| ToolbarItemComponent::ToolbarItemComponent | ( | int | itemId, |
| const String & | labelText, | ||
| bool | isBeingUsedAsAButton | ||
| ) |
Constructor.
| itemId | the ID of the type of toolbar item which this represents |
| labelText | the text to display if the toolbar's style is set to Toolbar::iconsWithText or Toolbar::textOnly |
| isBeingUsedAsAButton | set this to false if you don't want the button to draw itself with button over/down states when the mouse moves over it or clicks |
| ToolbarItemComponent::~ToolbarItemComponent | ( | ) |
Destructor.
| int ToolbarItemComponent::getItemId | ( | ) | const |
Returns the item type ID that this component represents.
This value is in the constructor.
| Toolbar* ToolbarItemComponent::getToolbar | ( | ) | const |
Returns the toolbar that contains this component, or 0 if it's not currently inside one.
| bool ToolbarItemComponent::isToolbarVertical | ( | ) | const |
Returns true if this component is currently inside a toolbar which is vertical.
| Toolbar::ToolbarItemStyle ToolbarItemComponent::getStyle | ( | ) | const |
Returns the current style setting of this item.
Styles are listed in the Toolbar::ToolbarItemStyle enum.
| virtual void ToolbarItemComponent::setStyle | ( | const Toolbar::ToolbarItemStyle & | newStyle ) | [virtual] |
Changes the current style setting of this item.
Styles are listed in the Toolbar::ToolbarItemStyle enum, and are automatically updated by the toolbar that holds this item.
| const Rectangle<int> ToolbarItemComponent::getContentArea | ( | ) | const |
Returns the area of the component that should be used to display the button image or other contents of the item.
This content area may change when the item's style changes, and may leave a space around the edge of the component where the text label can be shown.
| virtual bool ToolbarItemComponent::getToolbarItemSizes | ( | int | toolbarThickness, |
| bool | isToolbarVertical, | ||
| int & | preferredSize, | ||
| int & | minSize, | ||
| int & | maxSize | ||
| ) | [pure virtual] |
This method must return the size criteria for this item, based on a given toolbar size and orientation.
The preferredSize, minSize and maxSize values must all be set by your implementation method. If the toolbar is horizontal, these will be the width of the item; for a vertical toolbar, they refer to the item's height.
The preferredSize is the size that the component would like to be, and this must be between the min and max sizes. For a fixed-size item, simply set all three variables to the same value.
The toolbarThickness parameter tells you the depth of the toolbar - the same as calling Toolbar::getThickness().
The isToolbarVertical parameter tells you whether the bar is oriented horizontally or vertically.
Implemented in ToolbarButton.
| virtual void ToolbarItemComponent::paintButtonArea | ( | Graphics & | g, |
| int | width, | ||
| int | height, | ||
| bool | isMouseOver, | ||
| bool | isMouseDown | ||
| ) | [pure virtual] |
Your subclass should use this method to draw its content area.
The graphics object that is passed-in will have been clipped and had its origin moved to fit the content area as specified get getContentArea(). The width and height parameters are the width and height of the content area.
If the component you're writing isn't a button, you can just do nothing in this method.
Implemented in ToolbarButton.
| virtual void ToolbarItemComponent::contentAreaChanged | ( | const Rectangle< int > & | newBounds ) | [pure virtual] |
Callback to indicate that the content area of this item has changed.
This might be because the component was resized, or because the style changed and the space needed for the text label is different.
See getContentArea() for a description of what the area is.
Implemented in ToolbarButton.
| void ToolbarItemComponent::setEditingMode | ( | const ToolbarEditingMode | newMode ) |
Changes the editing mode of this component.
This is used by the ToolbarItemPalette and related classes for making the items draggable, and is unlikely to be of much use in end-user-code.
| ToolbarEditingMode ToolbarItemComponent::getEditingMode | ( | ) | const |
Returns the current editing mode of this component.
This is used by the ToolbarItemPalette and related classes for making the items draggable, and is unlikely to be of much use in end-user-code.
| void ToolbarItemComponent::paintButton | ( | Graphics & | g, |
| bool | isMouseOverButton, | ||
| bool | isButtonDown | ||
| ) | [virtual] |
Subclasses should override this to actually paint the button's contents.
It's better to use this than the paint method, because it gives you information about the over/down state of the button.
| g | the graphics context to use |
| isMouseOverButton | true if the button is either in the 'over' or 'down' state |
| isButtonDown | true if the button should be drawn in the 'down' position |
Implements Button.
| void ToolbarItemComponent::resized | ( | ) | [virtual] |
Called when this component's size has been changed.
A component can implement this method to do things such as laying out its child components when its width or height changes.
The method is called synchronously as a result of the setBounds or setSize methods, so repeatedly changing a components size will repeatedly call its resized method (unlike things like repainting, where multiple calls to repaint are coalesced together).
If the component is a top-level window on the desktop, its size could also be changed by operating-system factors beyond the application's control.
Reimplemented from Component.
Reimplemented in ToolbarButton.