Lysa UI  0.0
Lysa UI —UI components for the Lysa Engine
TreeView Class Reference

Detailed Description

A widget that displays a hierarchical list of items.

+ Inheritance diagram for TreeView:

Classes

class  Item
 

Public Typedefs

using ContextMenuBuilder = std::function< std::shared_ptr< Popup >(const std::shared_ptr< Item > &item, float x, float y)>
 
using ItemFilter = std::function< bool (const Item &item)>
 

Public Member Functions

 TreeView ()
 
 ~TreeView () override
 
void setResources (const std::string &resBox, const std::string &resScroll, const std::string &resIndent, const std::string &resSelection, const std::string &resPointed)
 
const std::list< std::shared_ptr< Item > > & getItems () const
 
auto getBox () const
 
void removeAllItems ()
 
std::shared_ptr< Item > & addItem (std::shared_ptr< Widget > item)
 
std::shared_ptr< Item > & addItem (const std::shared_ptr< Item > &parent, std::shared_ptr< Widget > item)
 
void expand (const std::shared_ptr< Item > &item, bool expanded=true)
 
void expand (const std::shared_ptr< Widget > &item)
 
void expandAll (bool expanded=true)
 
void expandAll (const std::shared_ptr< Item > &item, bool expanded=true)
 
std::shared_ptr< ItemgetItem (const std::shared_ptr< Widget > &item) const
 
template<typename T >
std::shared_ptr< ItemfindByPointerUserData (const std::shared_ptr< T > &userData) const
 
template<typename T >
std::shared_ptr< ItemfindByUserData (const T &userData) const
 
std::shared_ptr< ItemgetItemAt (const float x, const float y) const
 
void setContextMenu (const ContextMenuBuilder &builder)
 
void closeContextMenu ()
 
void setFilter (const ItemFilter &filter)
 
void removeFilter ()
 
bool isFiltered () const
 
void setSelectionMode (SelectionMode mode)
 
auto getSelectionMode () const
 
void select (const std::shared_ptr< Item > &item, bool selected=true)
 
void selectWithModifiers (const std::shared_ptr< Item > &item)
 
void unselectAll ()
 
std::list< std::shared_ptr< Item > > getSelectedItems () const
 
std::shared_ptr< ItemgetSelectedItem () const
 
auto getPointedItem () const
 
void scrollToItem (const std::shared_ptr< Item > &item) const
 
- Public Member Functions inherited from Widget
 Widget (Type type=WIDGET)
 
 ~Widget () override
 
Type getType () const
 
bool isVisible () const
 
void setVisible (bool show=true)
 
bool isEnabled () const
 
void setEnabled (bool isEnabled=true)
 
virtual void setPos (float x, float y)
 
float getWidth () const
 
float getHeight () const
 
float getRequestedWidth () const
 
float getRequestedHeight () const
 
virtual void setSize (float width, float height)
 
void setWidth (const float width)
 
void setHeight (const float height)
 
const Rect & getRect () const
 
void setRect (float x, float y, float width, float height)
 
void setRect (const Rect &rect)
 
float getAspectRatio () const
 
Alignment getAlignment () const
 
void setAlignment (Alignment alignment)
 
std::shared_ptr< Font > getFont () const
 
void setFont (const std::shared_ptr< Font > &font)
 
float getFontScale () const
 
virtual void setFontScale (float fontScale)
 
bool isFocused () const
 
Widget * getParent () const
 
void setOverlap (const bool overlap)
 
template<typename T , typename... Args>
std::shared_ptr< T > create (const std::string &resource, const Alignment alignment, Args &&...args)
 
template<typename T , typename... Args>
std::shared_ptr< T > create (const Alignment alignment, Args &&...args)
 
template<typename T >
std::shared_ptr< T > add (std::shared_ptr< T > child, const Alignment alignment=Alignment::NONE, const std::string &resource="", const bool overlap=false)
 
template<typename T >
std::shared_ptr< T > addPopup (std::shared_ptr< T > child, const std::string &resource="")
 
template<typename T >
std::shared_ptr< T > addAfter (std::shared_ptr< T > child, const std::shared_ptr< Widget > &after, const Alignment alignment, const std::string &resource="", const bool overlap=false)
 
virtual void remove (const std::shared_ptr< Widget > &child)
 
virtual void removeAll ()
 
void setPadding (float padding)
 
float getPadding () const
 
float getVBorder () const
 
float getHBorder () const
 
void setVBorder (float size)
 
void setHBorder (float size)
 
bool isDrawBackground () const
 
void setDrawBackground (bool drawBackground)
 
bool isPushed () const
 
bool isPointed () const
 
bool isFreezed () const
 
bool isRedrawOnMouseEvent () const
 
bool isOverlapping () const
 
Rect getChildrenRect () const
 
void setFreezed (const bool f)
 
void setPushed (const bool p)
 
void refresh ()
 
void setResource (std::shared_ptr< UIResource > res)
 
uint32 getGroupIndex () const
 
void setGroupIndex (int32 index)
 
template<typename T >
getUserData () const
 
template<typename T >
std::shared_ptr< T > getPointerUserData () const
 
const std::any & getUserData () const
 
void setUserData (const std::any &data)
 
float getTransparency () const
 
void setTransparency (float alpha)
 
void resizeChildren ()
 
float getChildrenOffsetX () const
 
float getChildrenOffsetY () const
 
void setChildrenOffset (float x, float y)
 
std::shared_ptr< Widget > setFocus (bool focus=true)
 
virtual void onAttach ()
 
virtual void onDetach ()
 
virtual void onShow ()
 
virtual void onHide ()
 
virtual void onResize ()
 
virtual void onMove ()
 
virtual bool onKeyDown (Key key)
 
virtual bool onTextInput (const std::string &text)
 
virtual bool onKeyUp (Key key)
 
virtual bool onMouseDown (MouseButton button, float x, float y)
 
virtual bool onMouseUp (MouseButton button, float x, float y)
 
virtual bool onMouseMove (uint32 buttonsState, float x, float y)
 
virtual void onMouseLeave ()
 
virtual void onDisable ()
 
virtual void onEnable ()
 
virtual void onGotFocus ()
 
virtual void onLostFocus ()
 
bool getConsumeMouseEvent () const
 
void setConsumeMouseEvent (const bool consumeMouseEvent)
 
const std::list< std::shared_ptr< Widget > > & getChildren () const
 
bool hasChildren () const
 
void subscribe (const event_type &type, unique_id id, EventHandlerCallback callback)
 
void subscribe (const event_type &type, EventHandlerCallback callback)
 
void unsubscribe (unique_id id)
 
bool isAttached () const
 
WindowgetWindow () const
 
StylegetStyle () const
 
Vector2DRenderer & getRenderer () const
 
RenderingWindow & getRenderingWindow () const
 
WindowManagergetWindowManager () const
 

Static Public Attributes

static constexpr auto WHEEL_ITEMS {3}
 Number of items scrolled by one mouse wheel notch. More...
 
static constexpr int32 NO_SELECTION {-1}
 Item index used when nothing is selected. More...
 
static constexpr std::chrono::milliseconds DOUBLE_CLICK_DELAY {400}
 Maximum delay between the two clicks of a double click on an item. More...
 

Additional Inherited Members

- Public Types inherited from Widget
enum  Type {
  WIDGET, PANEL, BOX, LINE,
  FRAME, BUTTON, TOGGLEBUTTON, RADIOBUTTON,
  CHECKBOX, CHECKMARK, CROSSMARK, ARROW,
  TEXT, TEXTEDIT, RICHTEXTAREA, SCROLLBAR,
  SLIDER, COLORSLIDER, COLORWHEEL, KNOB,
  TREEVIEW, IMAGE, POPUP, LIST,
  LISTBOX, SELECTION, PROGRESSBAR, SCROLLCONTAINER,
  MENU, MENUPANEL, MENUBOX, TABBAR,
  TABCONTAINER, DIALOG, FOLDABLECONTAINER, COLORPICKER,
  COLORPICKERBUTTON, SPINBOX, SPINBUTTONS, ICONIMAGE,
  ICONSVG, DROPDOWNLIST, TOOLTIP, GRIDCELL,
  GRID, TABLE
}
 
- Protected Attributes inherited from Widget
const Type type
 
Rect rect
 
float requestedWidth {0}
 
float requestedHeight {0}
 
float hborder {0}
 
float vborder {0}
 
float padding {0}
 
bool consumeMouseEvent {false}
 
bool overlap {false}
 
bool focused {false}
 
bool allowFocus {false}
 
bool allowChildren {true}
 
bool drawBackground {true}
 
bool moveChildrenOnPush {false}
 
bool scrollChildren {false}
 
bool skipInvisibleChildren {false}
 
bool redrawOnMouseEvent {false}
 
bool redrawOnMouseMove {false}
 
float transparency {1.0f}
 
Widget * parent {nullptr}
 
Alignment alignment {Alignment::NONE}
 
std::shared_ptr< UIResourceresource
 
std::list< std::shared_ptr< Widget > > children
 
bool mouseMoveOnFocus {false}
 
float childrenOffsetX {0}
 
float childrenOffsetY {0}
 

Member Typedef Documentation

using ContextMenuBuilder = std::function<std::shared_ptr<Popup>(const std::shared_ptr<Item>& item, float x, float y)>

Builds the contextual menu of an item called on a right click.

Parameters
itemItem below the cursor, already selected.
xRelativeX position of the click
yRelative Y position of the click
using ItemFilter = std::function<bool(const Item& item)>

Tells if an item must be displayed when a filter is applied.

Parameters
itemItem to test.
Returns
True to keep the item, false to hide it.

Constructor & Destructor Documentation

TreeView ( )

Creates a default TreeView widget.

~TreeView ( )
override

Member Function Documentation

std::shared_ptr<Item>& addItem ( const std::shared_ptr< Item > &  parent,
std::shared_ptr< Widget item 
)

Adds a child item to a parent item.

Parameters
parentThe parent item.
itemThe widget to add as a child item.
Returns
Shared pointer to the created tree item.
std::shared_ptr<Item>& addItem ( std::shared_ptr< Widget item)

Adds a root item to the tree view.

void closeContextMenu ( )

Closes the contextual menu.

void expand ( const std::shared_ptr< Item > &  item,
bool  expanded = true 
)

Expands or collapses an item, hiding or displaying its children.

Parameters
itemThe item to expand or collapse.
expandedTrue to display the children of the item.
void expand ( const std::shared_ptr< Widget > &  item)

Expands the item displaying a given widget.

void expandAll ( bool  expanded = true)

Expands or collapses every item of the tree at once.

void expandAll ( const std::shared_ptr< Item > &  item,
bool  expanded = true 
)

Expands or collapses every item of the tree at once.

std::shared_ptr<Item> findByPointerUserData ( const std::shared_ptr< T > &  userData) const
inline

Returns the first item whose user data is equal to a given value or nullptr if not found.

std::shared_ptr<Item> findByUserData ( const T &  userData) const
inline

Returns the first item whose user data is equal to a given value or nullptr if not found.

auto getBox ( ) const
inline

Returns the box displaying the items.

std::shared_ptr<Item> getItem ( const std::shared_ptr< Widget > &  item) const

Returns the item displaying a given widget, nullptr if not found.

std::shared_ptr<Item> getItemAt ( const float  x,
const float  y 
) const
inline

Returns the displayed item at a given position, nullptr if there is none.

const std::list<std::shared_ptr<Item> >& getItems ( ) const
inline

Returns the root items of the tree.

auto getPointedItem ( ) const
inline

Returns the displayed item currently below the mouse cursor, nullptr if none.

std::shared_ptr<Item> getSelectedItem ( ) const

Returns the first selected item in display order, nullptr if the selection is empty.

std::list<std::shared_ptr<Item> > getSelectedItems ( ) const

Returns the selected items, in display order, collapsed items included.

auto getSelectionMode ( ) const
inline

Returns the current selection behavior.

bool isFiltered ( ) const
inline

Returns true if a filter is currently applied.

void removeAllItems ( )

Removes all items from the tree view.

void removeFilter ( )

Displays all the items again, restoring the expansion states.

void scrollToItem ( const std::shared_ptr< Item > &  item) const

Scroll to a specific item

void select ( const std::shared_ptr< Item > &  item,
bool  selected = true 
)

Selects or unselects an item, the other items are left untouched except in TreeView::SELECT_SINGLE mode where the previous selection is cleared. Emits UIEvent::OnSelectItem if the selection changed.

void selectWithModifiers ( const std::shared_ptr< Item > &  item)

Selects an item the same way a direct mouse click on it would

void setContextMenu ( const ContextMenuBuilder builder)
inline

Sets the builder of the contextual menu opened by a right click on an item.

void setFilter ( const ItemFilter filter)

Hides the items rejected by a filter.

void setResources ( const std::string &  resBox,
const std::string &  resScroll,
const std::string &  resIndent,
const std::string &  resSelection,
const std::string &  resPointed 
)

Sets the UI resources for the tree view.

Parameters
resBoxResource for the background box.
resScrollResource for the scroll bar.
resIndentResource for the indentation of a level, gives the width of a level.
resSelectionResource for the highlight of the selected items.
resPointedResource for the highlight of the item below the mouse cursor.
void setSelectionMode ( SelectionMode  mode)

Sets the selection behavior, TreeView::SELECT_SINGLE by default. Leaving TreeView::SELECT_MULTI reduces the current selection to one item at most.

void unselectAll ( )

Unselects every item. Emits UIEvent::OnSelectItem if the selection changed.

Member Data Documentation

constexpr std::chrono::milliseconds DOUBLE_CLICK_DELAY {400}
staticconstexpr

Maximum delay between the two clicks of a double click on an item.

constexpr int32 NO_SELECTION {-1}
staticconstexpr

Item index used when nothing is selected.

constexpr auto WHEEL_ITEMS {3}
staticconstexpr

Number of items scrolled by one mouse wheel notch.