26#ifndef TGUI_TREE_VIEW_HPP
27#define TGUI_TREE_VIEW_HPP
29#include <TGUI/CopiedSharedPtr.hpp>
30#include <TGUI/Widgets/Scrollbar.hpp>
31#include <TGUI/Renderers/TreeViewRenderer.hpp>
32#include <TGUI/Text.hpp>
36TGUI_MODULE_EXPORT
namespace tgui
45 using Ptr = std::shared_ptr<TreeView>;
46 using ConstPtr = std::shared_ptr<const TreeView>;
48 static constexpr const char StaticWidgetType[] =
"TreeView";
56 std::vector<ConstNode> nodes;
63 unsigned int depth = 0;
65 Node* parent =
nullptr;
66 std::vector<std::shared_ptr<Node>> nodes;
77 TreeView(
const char* typeName = StaticWidgetType,
bool initRenderer =
true);
105 TGUI_NODISCARD
static TreeView::Ptr
create();
113 TGUI_NODISCARD
static TreeView::Ptr
copy(
const TreeView::ConstPtr& treeView);
137 using Widget::setSize;
158 bool addItem(
const std::vector<String>& hierarchy,
bool createParents =
true);
166 void expand(
const std::vector<String>& hierarchy);
180 void collapse(
const std::vector<String>& hierarchy);
213 bool removeItem(
const std::vector<String>& hierarchy,
bool removeParentsWhenEmpty =
true);
233 TGUI_NODISCARD std::vector<ConstNode>
getNodes()
const;
292 bool leftMousePressed(
Vector2f pos)
override;
297 void leftMouseReleased(
Vector2f pos)
override;
302 void rightMousePressed(
Vector2f pos)
override;
307 void mouseMoved(
Vector2f pos)
override;
312 bool scrolled(
float delta,
Vector2f pos,
bool touch)
override;
317 void mouseNoLongerOnWidget()
override;
322 void leftMouseButtonNoLongerDown()
override;
332 void markNodesDirty();
373 TGUI_NODISCARD std::unique_ptr<DataIO::Node>
save(SavingRenderersMap& renderers)
const override;
379 void load(
const std::unique_ptr<DataIO::Node>& node,
const LoadingRenderersMap& renderers)
override;
391 TGUI_NODISCARD
Vector2f getInnerSize()
const;
397 void updateIconBounds();
403 bool updateTime(
Duration elapsedTime)
override;
415 void updateTextColors(std::vector<std::shared_ptr<Node>>& nodes);
421 void createNode(std::vector<std::shared_ptr<Node>>& menus,
Node* parent,
const String& text);
427 TGUI_NODISCARD
Node* findParentNode(
const std::vector<String>& hierarchy,
unsigned int parentIndex, std::vector<std::shared_ptr<Node>>& nodes,
Node* parent,
bool createParents);
433 void toggleNodeInternal(std::size_t index);
439 bool expandOrCollapse(
const std::vector<String>& hierarchy,
bool expand);
445 void loadItems(
const std::unique_ptr<DataIO::Node>& node, std::vector<std::shared_ptr<Node>>& items,
Node* parent);
451 unsigned int updateVisibleNodes(std::vector<std::shared_ptr<Node>>& nodes,
Node* selectedNode,
float textPadding,
unsigned int pos);
457 void updateSelectedAndHoveringItemColors();
463 void updateHoveredItem(
int item);
469 void updateSelectedItem(
int item);
485 std::vector<std::shared_ptr<Node>> m_nodes;
486 std::vector<std::shared_ptr<Node>> m_visibleNodes;
488 int m_selectedItem = -1;
489 int m_hoveredItem = -1;
491 unsigned int m_itemHeight = 0;
492 float m_maxRight = 0;
500 bool m_possibleDoubleClick =
false;
501 int m_doubleClickNodeIndex = -1;
503 Sprite m_spriteBackground;
504 Sprite m_spriteBranchExpanded;
505 Sprite m_spriteBranchCollapsed;
511 Color m_borderColorCached;
512 Color m_backgroundColorCached;
513 Color m_textColorCached;
514 Color m_textColorHoverCached;
515 Color m_selectedTextColorCached;
516 Color m_selectedTextColorHoverCached;
517 Color m_selectedBackgroundColorCached;
518 Color m_selectedBackgroundColorHoverCached;
519 Color m_backgroundColorHoverCached;
Base class for render targets.
Definition BackendRenderTarget.hpp:48
Wrapper for colors.
Definition Color.hpp:72
Definition CopiedSharedPtr.hpp:45
Wrapper for durations.
Definition Duration.hpp:56
Class to store the position or size of a widget.
Definition Layout.hpp:289
Definition Outline.hpp:39
Signal to which the user can subscribe to get callbacks from.
Definition Signal.hpp:1131
Signal to which the user can subscribe to get callbacks from.
Definition Signal.hpp:62
Wrapper class to store strings.
Definition String.hpp:101
Wrapper for text styles.
Definition TextStyle.hpp:57
Backend-independent wrapper around the backend-specific text class.
Definition Text.hpp:50
Definition TreeViewRenderer.hpp:37
Tree view widget.
Definition TreeView.hpp:42
void draw(BackendRenderTarget &target, RenderStates states) const override
Draw the widget to a render target.
TGUI_NODISCARD TreeViewRenderer * getSharedRenderer() override
Returns the renderer, which gives access to functions that determine how the widget is displayed.
void deselectItem()
Deselect the item if one was selected.
TGUI_NODISCARD Signal & getSignal(String signalName) override
Retrieves a signal based on its name.
bool addItem(const std::vector< String > &hierarchy, bool createParents=true)
Adds a new item to the tree view.
void updateTextSize() override
Called when the text size is changed (either by setTextSize or via the renderer)
static TGUI_NODISCARD TreeView::Ptr create()
Creates a new tree view widget.
void load(const std::unique_ptr< DataIO::Node > &node, const LoadingRenderersMap &renderers) override
Loads the widget from a tree of nodes.
void collapseAll()
Collapses all items.
void collapse(const std::vector< String > &hierarchy)
Collapses the given 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.
TGUI_NODISCARD std::unique_ptr< DataIO::Node > save(SavingRenderersMap &renderers) const override
Saves the widget as a tree node in order to save it to a file.
TGUI_NODISCARD unsigned int getVerticalScrollbarValue() const
Returns the thumb position of the vertical scrollbar.
TGUI_NODISCARD unsigned int getHorizontalScrollbarValue() const
Returns the thumb position of the horizontal scrollbar.
TGUI_NODISCARD bool isMouseOnWidget(Vector2f pos) const override
Returns whether the mouse position (which is relative to the parent widget) lies on top of the widget...
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 setVerticalScrollbarValue(unsigned int value)
Changes the thumb position of the vertical scrollbar.
void expand(const std::vector< String > &hierarchy)
Expands the given item.
void removeAllItems()
Removes all items.
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.
void setHorizontalScrollbarValue(unsigned int value)
Changes the thumb position of the horizontal scrollbar.
void rendererChanged(const String &property) override
Function called when one of the properties of the renderer is changed.
TGUI_NODISCARD std::vector< ConstNode > getNodes() const
Returns the nodes in the tree view.
TGUI_NODISCARD Widget::Ptr clone() const override
Makes a copy of the widget if you don't know its exact type.
void setSize(const Layout2d &size) override
Changes the size of the tree view.
Namespace that contains all TGUI functions and classes.
Definition AbsoluteOrRelativeValue.hpp:39
KeyPressed event parameters.
Definition Event.hpp:169
States used for drawing.
Definition RenderStates.hpp:39
Read-only node representation used by getNodes.
Definition TreeView.hpp:53
Internal representation of a node.
Definition TreeView.hpp:61