|
| | TreeViewItem () |
| virtual | ~TreeViewItem () |
| int | getNumSubItems () const noexcept |
| TreeViewItem * | getSubItem (int index) const noexcept |
| void | clearSubItems () |
| void | addSubItem (TreeViewItem *newItem, int insertPosition=-1) |
| template<class ElementComparator> |
| void | addSubItemSorted (ElementComparator &comparator, TreeViewItem *newItem) |
| void | removeSubItem (int index, bool deleteItem=true) |
| template<class ElementComparator> |
| void | sortSubItems (ElementComparator &comparator) |
| TreeView * | getOwnerView () const noexcept |
| TreeViewItem * | getParentItem () const noexcept |
| bool | isOpen () const noexcept |
| void | setOpen (bool shouldBeOpen) |
| Openness | getOpenness () const noexcept |
| void | setOpenness (Openness newOpenness) |
| bool | isSelected () const noexcept |
| void | setSelected (bool shouldBeSelected, bool deselectOtherItemsFirst, NotificationType shouldNotify=sendNotification) |
| Rectangle< int > | getItemPosition (bool relativeToTreeViewTopLeft) const noexcept |
| void | treeHasChanged () const noexcept |
| void | repaintItem () const |
| int | getRowNumberInTree () const noexcept |
| bool | areAllParentsOpen () const noexcept |
| void | setLinesDrawnForSubItems (bool shouldDrawLines) noexcept |
| virtual bool | mightContainSubItems ()=0 |
| virtual String | getUniqueName () const |
| virtual void | itemOpennessChanged (bool isNowOpen) |
| virtual int | getItemWidth () const |
| virtual int | getItemHeight () const |
| virtual bool | canBeSelected () const |
| virtual std::unique_ptr< Component > | createItemComponent () |
| virtual void | paintItem (Graphics &g, int width, int height) |
| virtual void | paintOpenCloseButton (Graphics &, const Rectangle< float > &area, Colour backgroundColour, bool isMouseOver) |
| virtual void | paintHorizontalConnectingLine (Graphics &, const Line< float > &line) |
| virtual void | paintVerticalConnectingLine (Graphics &, const Line< float > &line) |
| virtual bool | customComponentUsesTreeViewMouseHandler () const |
| virtual void | itemClicked (const MouseEvent &) |
| virtual void | itemDoubleClicked (const MouseEvent &) |
| virtual void | itemSelectionChanged (bool isNowSelected) |
| virtual void | ownerViewChanged (TreeView *newOwner) |
| virtual String | getTooltip () |
| virtual String | getAccessibilityName () |
| virtual var | getDragSourceDescription () |
| virtual bool | isInterestedInFileDrag (const StringArray &files) |
| virtual void | filesDropped (const StringArray &files, int insertIndex) |
| virtual bool | isInterestedInDragSource (const DragAndDropTarget::SourceDetails &dragSourceDetails) |
| virtual void | itemDropped (const DragAndDropTarget::SourceDetails &dragSourceDetails, int insertIndex) |
| void | setDrawsInLeftMargin (bool canDrawInLeftMargin) noexcept |
| void | setDrawsInRightMargin (bool canDrawInRightMargin) noexcept |
| std::unique_ptr< XmlElement > | getOpennessState () const |
| void | restoreOpennessState (const XmlElement &xml) |
| int | getIndexInParent () const noexcept |
| bool | isLastOfSiblings () const noexcept |
| String | getItemIdentifierString () const |
An item in a TreeView.
A TreeViewItem can either be a leaf-node in the tree, or it can contain its own sub-items.
To implement an item that contains sub-items, override the itemOpennessChanged() method so that when it is opened, it adds the new sub-items to itself using the addSubItem method. Depending on the nature of the item it might choose to only do this the first time it's opened, or it might want to refresh itself each time. It also has the option of deleting its sub-items when it is closed, or leaving them in place.
@tags{GUI}
| virtual std::unique_ptr< Component > juce::TreeViewItem::createItemComponent |
( |
| ) |
|
|
inlinevirtual |
Creates a component that will be used to represent this item.
You don't have to implement this method - if it returns nullptr then no component will be used for the item, and you can just draw it using the paintItem() callback. But if you do return a component, it will be positioned in the TreeView so that it can be used to represent this item.
The component returned will be managed by the TreeView and will be deleted later when it goes off the screen or is no longer needed. Its position and size will be completely managed by the tree, so don't attempt to move it around.
Something you may want to do with your component is to give it a pointer to the TreeView that created it. This is perfectly safe, and there's no danger of it becoming a dangling pointer because the TreeView will always delete the component before it is itself deleted.
As long as you stick to these rules you can return whatever kind of component you like. It's most useful if you're doing things like drag-and-drop of items, or want to use a Label component to edit item names, etc.
Reimplemented in juce::KeyMappingEditorComponent::MappingItem, juce::ParamControlItem, and juce::ParameterGroupItem.
When files are dropped into this item, this callback is invoked.
For this to work, you'll need to have also implemented isInterestedInFileDrag(). The insertIndex value indicates where in the list of sub-items the files were dropped. If files are dropped onto an area of the tree where there are no visible items, this method is called on the root item of the tree, with an insert index of 0.
- See also
- FileDragAndDropTarget::filesDropped, isInterestedInFileDrag
| var juce::TreeViewItem::getDragSourceDescription |
( |
| ) |
|
|
virtual |
To allow items from your TreeView to be dragged-and-dropped, implement this method.
If this returns a non-null variant then when the user drags an item, the TreeView will try to find a DragAndDropContainer in its parent hierarchy, and will use it to trigger a drag-and-drop operation, using this string as the source description, with the TreeView itself as the source component.
If you need more complex drag-and-drop behaviour, you can use custom components for the items, and use those to trigger the drag.
To accept drag-and-drop in your tree, see isInterestedInDragSource(), isInterestedInFileDrag(), etc.
- See also
- DragAndDropContainer::startDragging
Reimplemented in juce::FileListTreeItem.
| virtual int juce::TreeViewItem::getItemWidth |
( |
| ) |
const |
|
inlinevirtual |
Must return the width required by this item.
If your item needs to have a particular width in pixels, return that value; if you'd rather have it just fill whatever space is available in the TreeView, return -1.
If all your items return -1, no horizontal scrollbar will be shown, but if any items have fixed widths and extend beyond the width of the TreeView, a scrollbar will appear.
Each item can be a different width, but if they change width, you should call treeHasChanged() to update the tree.
| std::unique_ptr< XmlElement > juce::TreeViewItem::getOpennessState |
( |
| ) |
const |
Saves the current state of open/closed nodes so it can be restored later.
This takes a snapshot of which sub-nodes have been explicitly opened or closed, and records it as XML. To identify node objects it uses the TreeViewItem::getUniqueName() method to create named paths. This means that the same state of open/closed nodes can be restored to a completely different instance of the tree, as long as it contains nodes whose unique names are the same.
You'd normally want to use TreeView::getOpennessState() rather than call it for a specific item, but this can be handy if you need to briefly save the state for a section of the tree.
Note that if all nodes of the tree are in their default state, then this may return a nullptr.
- See also
- TreeView::getOpennessState, restoreOpennessState
| String juce::TreeViewItem::getUniqueName |
( |
| ) |
const |
|
virtual |
If you want your item to be able to have files drag-and-dropped onto it, implement this method and return true.
If you return true and allow some files to be dropped, you'll also need to implement the filesDropped() method to do something with them.
Note that this will be called often, so make your implementation very quick! There's certainly no time to try opening the files and having a think about what's inside them!
For responding to internal drag-and-drop of other types of object, see isInterestedInDragSource().
- See also
- FileDragAndDropTarget::isInterestedInFileDrag, isInterestedInDragSource
Called when the user clicks on this item.
If you're using createItemComponent() to create a custom component for the item, the mouse-clicks might not make it through to the TreeView, but this is how you find out about clicks when just drawing each item individually.
The associated mouse-event details are passed in, so you can find out about which button, where it was, etc.
- See also
- itemDoubleClicked
Reimplemented in juce::FileListTreeItem.
Called when the user double-clicks on this item.
If you're using createItemComponent() to create a custom component for the item, the mouse-clicks might not make it through to the TreeView, but this is how you find out about clicks when just drawing each item individually.
The associated mouse-event details are passed in, so you can find out about which button, where it was, etc.
If not overridden, the base class method here will open or close the item as if the 'plus' button had been clicked.
- See also
- itemClicked
Reimplemented in juce::FileListTreeItem.
When a things are dropped into this item, this callback is invoked.
For this to work, you need to have also implemented isInterestedInDragSource(). The insertIndex value indicates where in the list of sub-items the new items should be placed. If files are dropped onto an area of the tree where there are no visible items, this method is called on the root item of the tree, with an insert index of 0.
- See also
- isInterestedInDragSource, DragAndDropTarget::itemDropped
| void juce::TreeViewItem::itemOpennessChanged |
( |
bool | isNowOpen | ) |
|
|
virtual |
Called when an item is opened or closed.
When setOpen() is called and the item has specified that it might have sub-items with the mightContainSubItems() method, this method is called to let the item create or manage its sub-items.
So when this is called with isNowOpen set to true (i.e. when the item is being opened), a subclass might choose to use clearSubItems() and addSubItem() to refresh its sub-item list.
When this is called with isNowOpen set to false, the subclass might want to use clearSubItems() to save on space, or it might choose to leave them, depending on the nature of the tree.
You could also use this callback as a trigger to start a background process which asynchronously creates sub-items and adds them, if that's more appropriate for the task in hand.
- See also
- mightContainSubItems
Reimplemented in juce::FileListTreeItem, and juce::KeyMappingEditorComponent::CategoryItem.
Draws the item's contents.
You can choose to either implement this method and draw each item, or you can use createItemComponent() to create a component that will represent the item.
If all you need in your tree is to be able to draw the items and detect when the user selects or double-clicks one of them, it's probably enough to use paintItem(), itemClicked() and itemDoubleClicked(). If you need more complicated interactions, you may need to use createItemComponent() instead.
- Parameters
-
| g | the graphics context to draw into |
| width | the width of the area available for drawing |
| height | the height of the area available for drawing |
Reimplemented in juce::FileListTreeItem, and juce::KeyMappingEditorComponent::CategoryItem.
| void juce::TreeViewItem::setDrawsInLeftMargin |
( |
bool | canDrawInLeftMargin | ) |
|
|
noexcept |
Sets a flag to indicate that the item wants to be allowed to draw all the way across to the left edge of the TreeView.
By default this is false, which means that when the paintItem() method is called, its graphics context is clipped to only allow drawing within the item's rectangle. If this flag is set to true, then the graphics context isn't clipped on its left side, so it can draw all the way across to the left margin. Note that the context will still have its origin in the same place though, so the coordinates of anything to its left will be negative. It's mostly useful if you want to draw a wider bar behind the highlighted item.
| void juce::TreeViewItem::setDrawsInRightMargin |
( |
bool | canDrawInRightMargin | ) |
|
|
noexcept |
Sets a flag to indicate that the item wants to be allowed to draw all the way across to the right edge of the TreeView.
Similar to setDrawsInLeftMargin: when this flag is set to true, then the graphics context isn't clipped on the right side. Unlike setDrawsInLeftMargin, you will very rarely need to use this function, as this method won't clip the right margin unless your TreeViewItem overrides getItemWidth to return a positive value.
- See also
- setDrawsInLeftMargin, getItemWidth
| void juce::TreeViewItem::setOpen |
( |
bool | shouldBeOpen | ) |
|
Opens or closes the item.
When opened or closed, the item's itemOpennessChanged() method will be called, and a subclass should use this callback to create and add any sub-items that it needs to.
Note that if this is called when the item is in its default openness state, and this call would not change whether it's open or closed, then no change will be stored. If you want to explicitly set the openness state to be non-default then you should use setOpenness instead.
- See also
- setOpenness, itemOpennessChanged, mightContainSubItems
template<class ElementComparator>
| void juce::TreeViewItem::sortSubItems |
( |
ElementComparator & | comparator | ) |
|
|
inline |
Sorts the list of sub-items using a standard array comparator.
This will use a comparator object to sort the elements into order. The comparator object must have a method of the form:
TreeViewItem()
Definition juce_TreeView.cpp:1472
..and this method must return:
- a value of < 0 if the first comes before the second
- a value of 0 if the two objects are equivalent
- a value of > 0 if the second comes before the first
To improve performance, the compareElements() method can be declared as static or const.