25#ifndef TGUI_TREE_VIEW_HPP
26#define TGUI_TREE_VIEW_HPP
28#include <TGUI/Widgets/Scrollbar.hpp>
29#include <TGUI/Renderers/TreeViewRenderer.hpp>
30#include <TGUI/Text.hpp>
34TGUI_MODULE_EXPORT
namespace tgui
43 using Ptr = std::shared_ptr<TreeView>;
44 using ConstPtr = std::shared_ptr<const TreeView>;
46 static constexpr const char StaticWidgetType[] =
"TreeView";
53 std::vector<ConstNode> nodes;
60 unsigned int depth = 0;
62 Node* parent =
nullptr;
63 std::vector<std::shared_ptr<Node>> nodes;
73 TreeView(
const char* typeName = StaticWidgetType,
bool initRenderer =
true);
99 TGUI_NODISCARD
static TreeView::Ptr
create();
106 TGUI_NODISCARD
static TreeView::Ptr
copy(
const TreeView::ConstPtr& treeView);
127 using Widget::setSize;
147 bool addItem(
const std::vector<String>& hierarchy,
bool createParents =
true);
171 void expand(
const std::vector<String>& hierarchy);
183 void collapse(
const std::vector<String>& hierarchy);
212 bool removeItem(
const std::vector<String>& hierarchy,
bool removeParentsWhenEmpty =
true);
299 bool changeItemHierarchy(
const std::vector<String>& oldHierarchy,
const std::vector<String>& newHierarchy);
319 TGUI_NODISCARD std::vector<ConstNode>
getNodes()
const;
338 TGUI_DEPRECATED(
"Use getVerticalScrollbar()->setValue(value) instead") void setVerticalScrollbarValue(
unsigned int value);
345 TGUI_DEPRECATED("Use getVerticalScrollbar()->getValue() instead") TGUI_NODISCARD
unsigned int getVerticalScrollbarValue() const;
354 TGUI_DEPRECATED("Use getVerticalScrollbar()->getMaxValue() instead") TGUI_NODISCARD
unsigned int getVerticalScrollbarMaxValue() const;
361 TGUI_DEPRECATED("Use getHorizontalScrollbar()->setValue(value) instead")
void setHorizontalScrollbarValue(
unsigned int value);
368 TGUI_DEPRECATED("Use getHorizontalScrollbar()->getValue() instead") TGUI_NODISCARD
unsigned int getHorizontalScrollbarValue() const;
377 TGUI_DEPRECATED("Use getHorizontalScrollbar()->getMaxValue() instead") TGUI_NODISCARD
unsigned int getHorizontalScrollbarMaxValue() const;
384 TGUI_NODISCARD
bool isMouseOnWidget(
Vector2f pos) const override;
394 void leftMouseReleased(
Vector2f pos) override;
399 void rightMousePressed(
Vector2f pos) override;
404 void mouseMoved(
Vector2f pos) override;
409 bool scrolled(
float delta,
Vector2f pos,
bool touch) override;
414 void mouseNoLongerOnWidget() override;
419 void leftMouseButtonNoLongerDown() override;
424 void keyPressed(const
Event::KeyEvent& event) override;
435 bool canHandleKeyPress(const
Event::KeyEvent& event) override;
440 void markNodesDirty();
469 void rendererChanged(const
String& property) override;
474 TGUI_NODISCARD std::unique_ptr<DataIO::
Node> save(SavingRenderersMap& renderers) const override;
479 void load(const std::unique_ptr<DataIO::
Node>& node, const LoadingRenderersMap& renderers) override;
484 void updateTextSize() override;
497 TGUI_NODISCARD
Vector2f getInnerSize() const;
502 void updateIconBounds();
507 bool updateTime(
Duration elapsedTime) override;
512 TGUI_NODISCARD
Widget::Ptr clone() const override;
517 void updateTextColors(std::vector<std::shared_ptr<
Node>>& nodes);
522 void createNode(std::vector<std::shared_ptr<
Node>>& menus,
Node* parent, const
String& text);
527 TGUI_NODISCARD
Node* findParentNode(const std::vector<
String>& hierarchy,
unsigned int parentIndex, std::vector<std::shared_ptr<
Node>>& nodes,
Node* parent,
bool createParents);
532 void toggleNodeInternal(std::
size_t index);
537 bool expandOrCollapse(const std::vector<
String>& hierarchy,
bool expand);
542 void loadItems(const std::unique_ptr<DataIO::
Node>& node, std::vector<std::shared_ptr<
Node>>& items,
Node* parent);
547 unsigned int updateVisibleNodes(std::vector<std::shared_ptr<
Node>>& nodes,
Node* selectedNode,
float textPadding,
unsigned int pos);
552 void updateSelectedAndHoveringItemColors();
557 void updateHoveredItem(
int item);
562 void updateSelectedItem(
int item);
577 std::vector<std::shared_ptr<Node>> m_nodes;
578 std::vector<std::shared_ptr<Node>> m_visibleNodes;
580 int m_selectedItem = -1;
581 int m_hoveredItem = -1;
583 unsigned int m_itemHeight = 0;
584 float m_maxRight = 0;
588 bool m_possibleDoubleClick =
false;
589 int m_doubleClickNodeIndex = -1;
591 Sprite m_spriteBackground;
592 Sprite m_spriteBranchExpanded;
593 Sprite m_spriteBranchCollapsed;
599 Color m_borderColorCached;
600 Color m_backgroundColorCached;
601 Color m_textColorCached;
602 Color m_textColorHoverCached;
603 Color m_selectedTextColorCached;
604 Color m_selectedTextColorHoverCached;
605 Color m_selectedBackgroundColorCached;
606 Color m_selectedBackgroundColorHoverCached;
607 Color m_backgroundColorHoverCached;
Base class for render targets.
Definition BackendRenderTarget.hpp:46
Wrapper for colors.
Definition Color.hpp:73
Wrapper for durations.
Definition Duration.hpp:55
Class to store the position or size of a widget.
Definition Layout.hpp:313
Definition Outline.hpp:38
Signal to which the user can subscribe to get callbacks from.
Definition Signal.hpp:61
Signal to which the user can subscribe to get callbacks from.
Definition Signal.hpp:1060
Wrapper class to store strings.
Definition String.hpp:96
Backend-independent wrapper around the backend-specific text class.
Definition Text.hpp:48
Wrapper for text styles.
Definition TextStyle.hpp:55
Tree view widget.
Definition TreeView.hpp:40
TGUI_NODISCARD TreeViewRenderer * getSharedRenderer() override
Returns the renderer, which gives access to functions that determine how the widget is displayed.
TGUI_NODISCARD ConstNode getNode(const std::vector< String > &hierarchy) const
Returns the node in the tree view at a given hierarchy.
void deselectItem()
Deselect the item if one was selected.
int getItemIndexInParent(const std::vector< String > &hierarchy)
Returns the index of an item, based on the items that share the same parent.
bool addItem(const std::vector< String > &hierarchy, bool createParents=true)
Adds a new item to the tree view.
static TGUI_NODISCARD TreeView::Ptr create()
Creates a new tree view widget.
void collapseAll()
Collapses all items.
void collapse(const std::vector< String > &hierarchy)
Collapses the given item.
bool changeItem(const std::vector< String > &hierarchy, const String &leafText)
Changes the text of a leaf item.
bool selectItem(const std::vector< String > &hierarchy)
Selects an item in the tree view.
TGUI_NODISCARD std::vector< String > getSelectedItem() const
Returns the selected item.
bool removeItem(const std::vector< String > &hierarchy, bool removeParentsWhenEmpty=true)
Removes an item.
void setItemHeight(unsigned int itemHeight)
Changes the height of the items in the tree view.
void expandAll()
Expands all items.
void expand(const std::vector< String > &hierarchy)
Expands the given item.
void removeAllItems()
Removes all items.
bool setItemIndexInParent(const std::vector< String > &hierarchy, std::size_t index)
Sets the index of an item, based on the items that share the same parent.
TGUI_NODISCARD std::vector< String > getHoveredItem() const
Returns the item currently below the mouse cursor.
static TGUI_NODISCARD TreeView::Ptr copy(const TreeView::ConstPtr &treeView)
Makes a copy of another tree view.
TGUI_NODISCARD TreeViewRenderer * getRenderer() override
Returns the renderer, which gives access to functions that determine how the widget is displayed.
TGUI_NODISCARD unsigned int getItemHeight() const
Returns the height of the items in the tree view.
bool changeItemHierarchy(const std::vector< String > &oldHierarchy, const std::vector< String > &newHierarchy)
Moves one item and its children from one location in the hierarchy to a completely different location...
TGUI_NODISCARD std::vector< ConstNode > getNodes() const
Returns the nodes in the tree view.
void setSize(const Layout2d &size) override
Changes the size of the tree view.
Definition TreeViewRenderer.hpp:35
Namespace that contains all TGUI functions and classes.
Definition AbsoluteOrRelativeValue.hpp:38
Orientation
Orientation of the object.
Definition Layout.hpp:51
States used for drawing.
Definition RenderStates.hpp:38
Read-only node representation used by getNode and getNodes.
Definition TreeView.hpp:50
Internal representation of a node.
Definition TreeView.hpp:58