Neo  0.5.0
Developer Documentation
Neo2D::Gui::TreeView Class Reference

Implements a tree view which displays a multi-way tree of strings while providing callbacks for the selection of an entry. More...

#include <Tree.h>

+ Inheritance diagram for Neo2D::Gui::TreeView:

Public Member Functions

 TreeView (unsigned int x, unsigned int y, unsigned int width, unsigned int height, const char *label)
 
 ~TreeView ()
 
bool getAutoSize ()
 Checks if the tree widget is configured to resize itself according to its content. More...
 
void setAutoSize (bool b)
 Configures the tree widget to resize itself according to its content. More...
 
void show ()
 Shows the tree. More...
 
void clear (TreeNode< std::string > *root)
 Clears the tree from the given node downwards. More...
 
void clear ()
 Clears everything starting at the root node. More...
 
TreeNode< std::string > * getTreeModel ()
 Returns the root node of this tree. More...
 
const char * getSelected ()
 Returns the currently selected node or nullptr if none is selected. More...
 
void selectEntry (const char *name)
 
void selectEntry (TreeNode< std::string > *node)
 
TreeNode< std::string > * find (const char *name)
 
void draw (Vector2 offset)
 Draws the widget to the canvas it belongs to. More...
 
void update ()
 Updates the widget and calls the callback if necessary. More...
 
void setSize (Vector2 sz)
 
- Public Member Functions inherited from Neo2D::Widget
 Widget (unsigned int x, unsigned int y, unsigned int width, unsigned int height, const char *label)
 
 Widget ()
 
void setParent (Widget *w)
 
WidgetgetParent ()
 
float getFontSize ()
 
void setFontSize (float s)
 
void setOffset (Vector2 offset)
 
Vector2 getOffset ()
 
void setSize (unsigned int w, unsigned int h)
 
Vector2 getSize ()
 
virtual void draw ()
 Draws the widget to the canvas it belongs to. More...
 
void setCallback (NEO_CALLBACK_FUNCTION func)
 Sets the callback. More...
 
void setScriptCallback (const char *name)
 
void setCallback (NEO_CALLBACK_FUNCTION func, long int data)
 Sets the callback and appends user data to it. More...
 
long int getUserData ()
 Retrieves the user data that will be given to every callback call. More...
 
void setUserData (long int data)
 Changes the user data that will be given to every callback call. More...
 
const char * getLabel ()
 Gets the currently displayed label a C string. More...
 
void setLabel (const char *l)
 Changes the current label of the widget. More...
 
void setPosition (Vector2 pos)
 Changes the widget position. More...
 
Vector2 getPosition ()
 Retrieves the current position. More...
 
void setRotation (float rot)
 Changes the widget rotation. More...
 
float getRotation ()
 Retrieves the current rotation. More...
 
void translate (Vector2 vec)
 Translates the object. More...
 
void rotate (float value)
 Rotates the object. More...
 
void doCallback ()
 Calls the callback with the user data as an argument. More...
 
bool isVisible ()
 Returns if the widget is turned visible. More...
 
void setVisible (bool v)
 Sets the visibility status. More...
 
void setScale (Vector2 scale)
 setScale Scale this Widget More...
 
Vector2 getScale ()
 
void setFlip (Vector2 flip)
 setFlip Flip this Widget More...
 
Vector2 getFlip ()
 
const char * getStaticName ()
 
virtual bool isMouseOver ()
 

Protected Member Functions

void updateTree (TreeNode< std::string > *root, Vector2 *level)
 Walks down the tree and updates every node of it for detecting clicks on the small "+" signs and the entry itself. More...
 
void drawTree (TreeNode< std::string > *root, Vector2 *level)
 Walks down the tree and draws every node of it. More...
 
TreeNode< std::string > * find (const char *name, TreeNode< std::string > *root)
 

Protected Attributes

bool m_autoSize
 
TreeNode< std::string > m_root
 
TreeNode< std::string > * m_selected
 
Labelm_label
 
- Protected Attributes inherited from Neo2D::Widget
float m_x
 The 2D coordinates of the widget. More...
 
float m_y
 
float m_rotation
 The rotation of the widget. More...
 
unsigned int m_width
 The width and height of the widget. More...
 
unsigned int m_height
 
std::string m_label
 The label of the widget. More...
 
Vector2 m_offset
 The offset that was used for rendering in the last frame. More...
 
NEO_CALLBACK_FUNCTION m_callback
 The callback that should be called. More...
 
String m_callbackScript
 
long int m_userData
 Some userdata that is given to the callback. More...
 
bool m_visible
 Is the widget visible? More...
 
Vector2 m_scale
 The scale vector. More...
 
Vector2 m_flip
 The flip vector. More...
 
float m_fontSize
 
Widgetm_parent
 

Friends

class TreeNode< std::string >
 

Detailed Description

Implements a tree view which displays a multi-way tree of strings while providing callbacks for the selection of an entry.

Author
Yannick Pflanzer

Constructor & Destructor Documentation

Neo2D::Gui::TreeView::TreeView ( unsigned int  x,
unsigned int  y,
unsigned int  width,
unsigned int  height,
const char *  label 
)
inline
Neo2D::Gui::TreeView::~TreeView ( )
inline

Member Function Documentation

void Neo2D::Gui::TreeView::clear ( TreeNode< std::string > *  root)

Clears the tree from the given node downwards.

Attention: Deletes all nodes so they can't be used anymore!

Invariant: The lower part of the tree is cleared after one call. Variant: The given root node walks down one level for every recursion therefore the algorithm terminates.

Parameters
Theroot node to start at.
void Neo2D::Gui::TreeView::clear ( )
inline

Clears everything starting at the root node.

See also
clear(TreeNode<std::string>* root)
void Neo2D::Gui::TreeView::draw ( Vector2  offset)
virtual

Draws the widget to the canvas it belongs to.

Parameters
offsetThe offset to apply to the position. Used for emulating a camera.
See also
Canvas

Reimplemented from Neo2D::Widget.

void Neo2D::Gui::TreeView::drawTree ( TreeNode< std::string > *  root,
Vector2 level 
)
protected

Walks down the tree and draws every node of it.

Invariant: The lower part of the tree is drawn after one call to the method. Variant: The root node progresses further down the tree by one level and thus leads the algorithm to eventually terminate.

Parameters
rootThe node to start at.
levelThe pointer to a Vector2 instance for calculating the (x|y) level of the currently handled node.
TreeNode<std::string>* Neo2D::Gui::TreeView::find ( const char *  name,
TreeNode< std::string > *  root 
)
protected
TreeNode<std::string>* Neo2D::Gui::TreeView::find ( const char *  name)
bool Neo2D::Gui::TreeView::getAutoSize ( )
inline

Checks if the tree widget is configured to resize itself according to its content.

Returns
A boolean value.
const char* Neo2D::Gui::TreeView::getSelected ( )
inline

Returns the currently selected node or nullptr if none is selected.

Returns
The name of the selected node.
TreeNode<std::string>* Neo2D::Gui::TreeView::getTreeModel ( )
inline

Returns the root node of this tree.

Returns
The root node.
void Neo2D::Gui::TreeView::selectEntry ( const char *  name)
void Neo2D::Gui::TreeView::selectEntry ( TreeNode< std::string > *  node)
inline
void Neo2D::Gui::TreeView::setAutoSize ( bool  b)
inline

Configures the tree widget to resize itself according to its content.

Parameters
bThe boolean value.
void Neo2D::Gui::TreeView::setSize ( Vector2  sz)
inline
void Neo2D::Gui::TreeView::show ( )
inline

Shows the tree.

void Neo2D::Gui::TreeView::update ( )
virtual

Updates the widget and calls the callback if necessary.

Implements Neo2D::Widget.

void Neo2D::Gui::TreeView::updateTree ( TreeNode< std::string > *  root,
Vector2 level 
)
protected

Walks down the tree and updates every node of it for detecting clicks on the small "+" signs and the entry itself.

Invariant: The lower part of the tree is updated after one call to the method. Variant: The root node progresses further down the tree by one level and thus leads the algorithm to eventually terminate.

Parameters
rootThe node to start at.
levelThe pointer to a Vector2 instance for calculating the (x|y) level of the currently handled node.

Friends And Related Function Documentation

friend class TreeNode< std::string >
friend

Member Data Documentation

bool Neo2D::Gui::TreeView::m_autoSize
protected
Label* Neo2D::Gui::TreeView::m_label
protected
TreeNode<std::string> Neo2D::Gui::TreeView::m_root
protected
TreeNode<std::string>* Neo2D::Gui::TreeView::m_selected
protected

The documentation for this class was generated from the following file: