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;
63 std::vector<std::shared_ptr<Node>> nodes;
105 static TreeView::Ptr
copy(TreeView::ConstPtr treeView);
141 bool addItem(
const std::vector<sf::String>& hierarchy,
bool createParents =
true);
149 void expand(
const std::vector<sf::String>& hierarchy);
163 void collapse(
const std::vector<sf::String>& hierarchy);
196 bool removeItem(
const std::vector<sf::String>& hierarchy,
bool removeParentsWhenEmpty =
true);
288 void leftMousePressed(
Vector2f pos)
override;
293 void leftMouseReleased(
Vector2f pos)
override;
298 void rightMousePressed(
Vector2f pos)
override;
303 void mouseMoved(
Vector2f pos)
override;
308 bool mouseWheelScrolled(
float delta,
Vector2f pos)
override;
313 void mouseNoLongerOnWidget()
override;
318 void leftMouseButtonNoLongerDown()
override;
323 void markNodesDirty();
333 void draw(sf::RenderTarget& target, sf::RenderStates states)
const override;
364 std::unique_ptr<DataIO::Node>
save(SavingRenderersMap& renderers)
const override;
370 void load(
const std::unique_ptr<DataIO::Node>& node,
const LoadingRenderersMap& renderers)
override;
382 void updateIconBounds();
388 bool update(sf::Time elapsedTime)
override;
396 return std::make_shared<TreeView>(*
this);
403 void updateTextColors(std::vector<std::shared_ptr<Node>>& nodes);
409 void createNode(std::vector<std::shared_ptr<Node>>& menus, Node* parent,
const sf::String& text);
415 Node* findParentNode(
const std::vector<sf::String>& hierarchy,
unsigned int parentIndex, std::vector<std::shared_ptr<Node>>& nodes, Node* parent,
bool createParents);
421 void toggleNodeInternal(std::size_t index);
427 bool expandOrCollapse(
const std::vector<sf::String>& hierarchy,
bool expand);
433 void loadItems(
const std::unique_ptr<DataIO::Node>& node, std::vector<std::shared_ptr<Node>>& items, Node* parent);
439 unsigned int updateVisibleNodes(std::vector<std::shared_ptr<Node>>& nodes, Node* selectedNode,
float textPadding,
unsigned int pos);
445 void updateSelectedAndHoveringItemColors();
451 void updateHoveredItem(
int item);
457 void updateSelectedItem(
int item);
473 std::vector<std::shared_ptr<Node>> m_nodes;
474 std::vector<std::shared_ptr<Node>> m_visibleNodes;
476 int m_selectedItem = -1;
477 int m_hoveredItem = -1;
480 unsigned int m_itemHeight = 0;
481 unsigned int m_requestedTextSize = 0;
482 float m_maxRight = 0;
490 bool m_possibleDoubleClick =
false;
491 int m_doubleClickNodeIndex = -1;
493 Sprite m_spriteBranchExpanded;
494 Sprite m_spriteBranchCollapsed;
500 Color m_borderColorCached;
501 Color m_backgroundColorCached;
502 Color m_textColorCached;
503 Color m_textColorHoverCached;
504 Color m_selectedTextColorCached;
505 Color m_selectedTextColorHoverCached;
506 Color m_selectedBackgroundColorCached;
507 Color m_selectedBackgroundColorHoverCached;
508 Color m_backgroundColorHoverCached;
Wrapper for colors.
Definition: Color.hpp:49
Definition: CopiedSharedPtr.hpp:40
Class to store the position or size of a widget.
Definition: Layout.hpp:260
Definition: Outline.hpp:39
Signal to which the user can subscribe to get callbacks from.
Definition: Signal.hpp:739
Signal to which the user can subscribe to get callbacks from.
Definition: Signal.hpp:231
Definition: Sprite.hpp:46
Wrapper for text styles.
Definition: TextStyle.hpp:47
Definition: TreeViewRenderer.hpp:37
Tree view widget.
Definition: TreeView.hpp:42
bool removeItem(const std::vector< sf::String > &hierarchy, bool removeParentsWhenEmpty=true)
Removes an item.
void draw(sf::RenderTarget &target, sf::RenderStates states) const override
Draw the widget to a render target.
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:394
void expand(const std::vector< sf::String > &hierarchy)
Expands the given item.
unsigned int getHorizontalScrollbarValue() const
Returns the thumb position of the horizontal scrollbar.
bool mouseOnWidget(Vector2f pos) const override
Returns whether the mouse position (which is relative to the parent widget) lies on top of the widget...
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< sf::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.
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 rendererChanged(const std::string &property) override
Function called when one of the properties of the renderer is changed.
bool selectItem(const std::vector< sf::String > &hierarchy)
Selects an item in the tree view.
void setItemHeight(unsigned int itemHeight)
Changes the height of the items in the tree view.
void collapse(const std::vector< sf::String > &hierarchy)
Collapses the given item.
void expandAll()
Expands all items.
void setVerticalScrollbarValue(unsigned int value)
Changes the thumb position of the vertical scrollbar.
void removeAllItems()
Removes all items.
TreeViewRenderer * getRenderer()
Returns the renderer, which gives access to functions that determine how the widget is displayed.
std::vector< sf::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.
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.
Signal & getSignal(std::string signalName) override
Retrieves a signal based on its name.
void setSize(const Layout2d &size) override
Changes the size of the tree view.
Definition: Vector2f.hpp:39
Namespace that contains all TGUI functions and classes.
Definition: AbsoluteOrRelativeValue.hpp:37
Read-only node representation used by getNodes.
Definition: TreeView.hpp:50
Internal representation of a node.
Definition: TreeView.hpp:58