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);
300 bool changeItemHierarchy(
const std::vector<String>& oldHierarchy,
const std::vector<String>& newHierarchy);
320 TGUI_NODISCARD std::vector<ConstNode>
getNodes()
const;
339 TGUI_DEPRECATED(
"Use getVerticalScrollbar()->setValue(value) instead") void setVerticalScrollbarValue(
unsigned int value);
346 TGUI_DEPRECATED("Use getVerticalScrollbar()->getValue() instead") TGUI_NODISCARD
unsigned int getVerticalScrollbarValue() const;
355 TGUI_DEPRECATED("Use getVerticalScrollbar()->getMaxValue() instead") TGUI_NODISCARD
unsigned int getVerticalScrollbarMaxValue() const;
362 TGUI_DEPRECATED("Use getHorizontalScrollbar()->setValue(value) instead")
void setHorizontalScrollbarValue(
unsigned int value);
369 TGUI_DEPRECATED("Use getHorizontalScrollbar()->getValue() instead") TGUI_NODISCARD
unsigned int getHorizontalScrollbarValue() const;
378 TGUI_DEPRECATED("Use getHorizontalScrollbar()->getMaxValue() instead") TGUI_NODISCARD
unsigned int getHorizontalScrollbarMaxValue() const;
385 TGUI_NODISCARD
bool isMouseOnWidget(
Vector2f pos) const override;
395 void leftMouseReleased(
Vector2f pos) override;
400 void rightMousePressed(
Vector2f pos) override;
405 void mouseMoved(
Vector2f pos) override;
410 bool scrolled(
float delta,
Vector2f pos,
bool touch) override;
415 void mouseNoLongerOnWidget() override;
420 void leftMouseButtonNoLongerDown() override;
425 void keyPressed(const
Event::KeyEvent& event) override;
436 bool canHandleKeyPress(const
Event::KeyEvent& event) override;
441 void markNodesDirty();
470 void rendererChanged(const
String& property) override;
475 TGUI_NODISCARD std::unique_ptr<DataIO::
Node> save(SavingRenderersMap& renderers) const override;
480 void load(const std::unique_ptr<DataIO::
Node>& node, const LoadingRenderersMap& renderers) override;
485 void updateTextSize() override;
498 TGUI_NODISCARD
Vector2f getInnerSize() const;
503 void updateIconBounds();
508 bool updateTime(
Duration elapsedTime) override;
513 TGUI_NODISCARD
Widget::Ptr clone() const override;
518 void updateTextColors(std::vector<std::shared_ptr<
Node>>& nodes);
523 void createNode(std::vector<std::shared_ptr<
Node>>& menus,
Node* parent, const
String& text);
528 TGUI_NODISCARD
Node* findParentNode(const std::vector<
String>& hierarchy,
unsigned int parentIndex, std::vector<std::shared_ptr<
Node>>& nodes,
Node* parent,
bool createParents);
533 void toggleNodeInternal(std::
size_t index);
538 bool expandOrCollapse(const std::vector<
String>& hierarchy,
bool expand);
543 void loadItems(const std::unique_ptr<DataIO::
Node>& node, std::vector<std::shared_ptr<
Node>>& items,
Node* parent);
548 unsigned int updateVisibleNodes(std::vector<std::shared_ptr<
Node>>& nodes,
Node* selectedNode,
float textPadding,
unsigned int pos);
553 void updateSelectedAndHoveringItemColors();
558 void updateHoveredItem(
int item);
563 void updateSelectedItem(
int item);
578 std::vector<std::shared_ptr<Node>> m_nodes;
579 std::vector<std::shared_ptr<Node>> m_visibleNodes;
581 int m_selectedItem = -1;
582 int m_hoveredItem = -1;
584 unsigned int m_itemHeight = 0;
585 float m_maxRight = 0;
589 bool m_possibleDoubleClick =
false;
590 int m_doubleClickNodeIndex = -1;
592 Sprite m_spriteBackground;
593 Sprite m_spriteBranchExpanded;
594 Sprite m_spriteBranchCollapsed;
600 Color m_borderColorCached;
601 Color m_backgroundColorCached;
602 Color m_textColorCached;
603 Color m_textColorHoverCached;
604 Color m_selectedTextColorCached;
605 Color m_selectedTextColorHoverCached;
606 Color m_selectedBackgroundColorCached;
607 Color m_selectedBackgroundColorHoverCached;
608 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:323
Definition Outline.hpp:38
Signal to which the user can subscribe to get callbacks from.
Definition Signal.hpp:1060
Signal to which the user can subscribe to get callbacks from.
Definition Signal.hpp:61
Wrapper class to store strings.
Definition String.hpp:96
Wrapper for text styles.
Definition TextStyle.hpp:55
Backend-independent wrapper around the backend-specific text class.
Definition Text.hpp:48
Definition TreeViewRenderer.hpp:35
Tree view widget.
Definition TreeView.hpp:40
void deselectItem()
Deselect the item if one was selected.
bool addItem(const std::vector< String > &hierarchy, bool createParents=true)
Adds a new item to the tree view.
unsigned int getItemHeight() const
Returns the height of the items in the tree view.
std::vector< ConstNode > getNodes() const
Returns the nodes in the tree view.
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.
TreeViewRenderer * getRenderer() override
Returns the renderer, which gives access to functions that determine how the widget is displayed.
ConstNode getNode(const std::vector< String > &hierarchy) const
Returns the node in the tree view at a given hierarchy.
bool removeItem(const std::vector< String > &hierarchy, bool removeParentsWhenEmpty=true)
Removes an item.
TreeViewRenderer * getSharedRenderer() override
Returns the renderer, which gives access to functions that determine how the widget is displayed.
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.
std::vector< String > getHoveredItem() const
Returns the item currently below the mouse cursor.
std::vector< String > getSelectedItem() const
Returns the selected item.
static TreeView::Ptr copy(const TreeView::ConstPtr &treeView)
Makes a copy of another tree view.
static TreeView::Ptr create()
Creates a new tree view widget.
int getItemIndexInParent(const std::vector< String > &hierarchy) const
Returns the index of an item, based on the items that share the same parent.
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...
void setSize(const Layout2d &size) override
Changes the size of the tree view.
Namespace that contains all TGUI functions and classes.
Definition AbsoluteOrRelativeValue.hpp:38
Orientation
Orientation of the object.
Definition Layout.hpp:52
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