Class TreeView#

Nested Relationships#

Nested Types#

Inheritance Relationships#

Base Type#

Class Documentation#

class TreeView : public Karana::WebUI::Widget#

Widget displaying an interactable tree using hierarchical html.

Although the class is named TreeView, general acyclic graphs are supported. In this case a Node and its descendants will appear under each of its parents.

Public Types

using NodeList = std::vector<Node>#

Alias for a list of nodes.

using EdgeList = std::vector<Edge>#

Alias for a list of edges.

Public Functions

TreeView(Router &router, const NodeList &nodes = {}, const EdgeList &edges = {}, std::function<void(const Selection&)> on_select = {}, std::function<void()> on_refresh = {}, const Karana::Core::ks_ptr<State> &selection = nullptr)#

TreeView constructor.

Parameters:
  • router – The connection router to use

  • nodes – The initial list of nodes in the tree

  • edges – The initial list of edges in the tree

  • on_select – Called when a node is selected in the UI

  • on_refresh – Called when a node is refreshed in the UI

  • selection – Optional existing State for the selection

virtual ~TreeView()#

TreeView destructor.

void select(const Selection &selection = Selection{})#

Select the given items.

Note that calling this does not invoke the on_select callback passed into the constructor

Parameters:

selection – The new Selection

void setNodeLabel(Karana::Core::id_t id, std::string_view label)#

Update the label for the node with the given id.

Parameters:
  • id – The node id.

  • label – The new label text for the node.

void setTree(const NodeList &nodes, const EdgeList &edges)#

Use a new set of nodes.

Parameters:
  • nodes – The new list of nodes.

  • edges – The new list of edges.

void refresh() const#

Forces a refresh of the TreeView via its on_refresh() callback, if any was set.

Do not call this from the on_refresh callback itself, since that would create a cycle.

Protected Functions

virtual void _onConnect(int client_id) override#

First setup on initial connection.

Parameters:

client_id – The ID of the client connecting.

virtual void _onMessage(std::string_view message, int client_id) override#

Used to handle refresh messages.

Parameters:
  • message – The refresh message.

  • client_id – The ID of the client to refresh.

struct Node#

Data for a node in a TreeView.

Public Members

Karana::Core::id_t id#

Id of an object to associate the node with.

std::string label = "unnamed"#

Display name of the node.

std::string style_class = ""#

Extra css class to apply to the node on the frontend.

std::string tooltip = ""#

Optional tooltip text.

bool collapsed = false#

Whether the node should start collapsed.

struct Edge#

Data for an edge in a TreeView.

Public Members

Karana::Core::id_t parent_id#

Id of the parent node.

Karana::Core::id_t child_id#

Id of the child node.