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>
45 typedef std::shared_ptr<TreeView> Ptr;
46 typedef std::shared_ptr<const TreeView> ConstPtr;
53 std::vector<ConstNode> nodes;
62 Node* parent =
nullptr;
63 std::vector<std::shared_ptr<Node>> nodes;
74 TreeView(
const char* typeName =
"TreeView",
bool initRenderer =
true);
110 static TreeView::Ptr
copy(TreeView::ConstPtr treeView);
135 using Widget::setSize;
146 bool addItem(
const std::vector<String>& hierarchy,
bool createParents =
true);
154 void expand(
const std::vector<String>& hierarchy);
168 void collapse(
const std::vector<String>& hierarchy);
201 bool removeItem(
const std::vector<String>& hierarchy,
bool removeParentsWhenEmpty =
true);
293 void leftMousePressed(
Vector2f pos)
override;
298 void leftMouseReleased(
Vector2f pos)
override;
303 void rightMousePressed(
Vector2f pos)
override;
308 void mouseMoved(
Vector2f pos)
override;
313 bool mouseWheelScrolled(
float delta,
Vector2f pos)
override;
318 void mouseNoLongerOnWidget()
override;
323 void leftMouseButtonNoLongerDown()
override;
333 void markNodesDirty();
374 std::unique_ptr<DataIO::Node>
save(SavingRenderersMap& renderers)
const override;
380 void load(
const std::unique_ptr<DataIO::Node>& node,
const LoadingRenderersMap& renderers)
override;
392 void updateIconBounds();
398 bool updateTime(
Duration elapsedTime)
override;
406 return std::make_shared<TreeView>(*
this);
413 void updateTextColors(std::vector<std::shared_ptr<Node>>& nodes);
419 void createNode(std::vector<std::shared_ptr<Node>>& menus, Node* parent,
const String& text);
425 Node* findParentNode(
const std::vector<String>& hierarchy,
unsigned int parentIndex, std::vector<std::shared_ptr<Node>>& nodes, Node* parent,
bool createParents);
431 void toggleNodeInternal(std::size_t index);
437 bool expandOrCollapse(
const std::vector<String>& hierarchy,
bool expand);
443 void loadItems(
const std::unique_ptr<DataIO::Node>& node, std::vector<std::shared_ptr<Node>>& items, Node* parent);
449 unsigned int updateVisibleNodes(std::vector<std::shared_ptr<Node>>& nodes, Node* selectedNode,
float textPadding,
unsigned int pos);
455 void updateSelectedAndHoveringItemColors();
461 void updateHoveredItem(
int item);
467 void updateSelectedItem(
int item);
483 std::vector<std::shared_ptr<Node>> m_nodes;
484 std::vector<std::shared_ptr<Node>> m_visibleNodes;
486 int m_selectedItem = -1;
487 int m_hoveredItem = -1;
490 unsigned int m_itemHeight = 0;
491 unsigned int m_requestedTextSize = 0;
492 float m_maxRight = 0;
500 bool m_possibleDoubleClick =
false;
501 int m_doubleClickNodeIndex = -1;
503 Sprite m_spriteBranchExpanded;
504 Sprite m_spriteBranchCollapsed;
510 Color m_borderColorCached;
511 Color m_backgroundColorCached;
512 Color m_textColorCached;
513 Color m_textColorHoverCached;
514 Color m_selectedTextColorCached;
515 Color m_selectedTextColorHoverCached;
516 Color m_selectedBackgroundColorCached;
517 Color m_selectedBackgroundColorHoverCached;
518 Color m_backgroundColorHoverCached;
Base class for render targets.
Definition BackendRenderTarget.hpp:48
Wrapper for colors.
Definition Color.hpp:63
Definition CopiedSharedPtr.hpp:40
Wrapper for durations.
Definition Duration.hpp:52
Class to store the position or size of a widget.
Definition Layout.hpp:262
Definition Outline.hpp:39
Signal to which the user can subscribe to get callbacks from.
Definition Signal.hpp:782
Signal to which the user can subscribe to get callbacks from.
Definition Signal.hpp:58
Wrapper class to store strings.
Definition String.hpp:79
Wrapper for text styles.
Definition TextStyle.hpp:58
Definition TreeViewRenderer.hpp:37
Tree view widget.
Definition TreeView.hpp:42
Signal & getSignal(String signalName) override
Retrieves a signal based on its name.
void deselectItem()
Deselect the item if one was selected.
Widget::Ptr clone() const override
Makes a copy of the widget if you don't know its exact type.
Definition TreeView.hpp:404
unsigned int getHorizontalScrollbarValue() const
Returns the thumb position of the horizontal scrollbar.
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.
bool addItem(const std::vector< String > &hierarchy, bool createParents=true)
Adds a new item to the tree view.
void draw(BackendRenderTargetBase &target, RenderStates states) const override
Draw the widget to a render target.
unsigned int getItemHeight() const
Returns the height of the items in the tree view.
void load(const std::unique_ptr< DataIO::Node > &node, const LoadingRenderersMap &renderers) override
Loads the widget from a tree of nodes.
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 selectItem(const std::vector< String > &hierarchy)
Selects an item in the tree view.
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.
TreeViewRenderer * getRenderer()
Returns the renderer, which gives access to functions that determine how the widget is displayed.
bool isMouseOnWidget(Vector2f pos) const override
Returns whether the mouse position (which is relative to the parent widget) lies on top of the widget...
std::vector< String > getSelectedItem() const
Returns the selected item.
unsigned int getVerticalScrollbarValue() const
Returns the thumb position of the vertical scrollbar.
static TreeView::Ptr create()
Creates a new tree view widget.
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.
static TreeView::Ptr copy(TreeView::ConstPtr treeView)
Makes a copy of another tree view.
TreeViewRenderer * getSharedRenderer()
Returns the renderer, which gives access to functions that determine how the widget is displayed.
void setTextSize(unsigned int textSize) override
Changes the text size of the items.
void setSize(const Layout2d &size) override
Changes the size of the tree view.
Namespace that contains all TGUI functions and classes.
Definition AbsoluteOrRelativeValue.hpp:36
KeyPressed event parameters.
Definition Event.hpp:167
States used for drawing.
Definition RenderStates.hpp:39
Read-only node representation used by getNodes.
Definition TreeView.hpp:50
Internal representation of a node.
Definition TreeView.hpp:58