Skip to content

Commit

Permalink
Tree View Node: implement recursive fold and unfold
Browse files Browse the repository at this point in the history
  • Loading branch information
Vultraz committed Oct 27, 2016
1 parent 7950cda commit a47fb5a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 12 deletions.
16 changes: 14 additions & 2 deletions src/gui/widgets/tree_view_node.cpp
Expand Up @@ -229,24 +229,36 @@ bool ttree_view_node::is_folded() const
return !unfolded_;
}

void ttree_view_node::fold(/*const bool recursive*/)
void ttree_view_node::fold(const bool recursive)
{
if(!is_folded()) {
fold_internal();
if(toggle_) {
toggle_->set_value(false);
}
}

if(recursive) {
for(auto& child_node : children_) {
child_node.fold(true);
}
}
}

void ttree_view_node::unfold(/*const texpand_mode mode*/)
void ttree_view_node::unfold(const bool recursive)
{
if(is_folded()) {
unfold_internal();
if(toggle_) {
toggle_->set_value(true);
}
}

if(recursive) {
for(auto& child_node : children_) {
child_node.unfold(true);
}
}
}

void ttree_view_node::fold_internal()
Expand Down
22 changes: 12 additions & 10 deletions src/gui/widgets/tree_view_node.hpp
Expand Up @@ -117,19 +117,16 @@ class ttree_view_node : public twidget
bool is_folded() const;

#if 0
enum texpand_mode
{
recursive_restore // recursively restores collapse mode
, recursive_expand // recursively expands the children
, not_recursive
// TODO: implement if different expand modes become necessary
enum texpand_mode {
recursive_restore, // recursively restores collapse mode
recursive_expand, // recursively expands the children
not_recursive
};
#endif

// If recursive all children will be closed recursively causing
// restore expaning not to expand anything
// TODO: ^ implement
void fold(/*const bool recursive*/);
void unfold(/*const texpand_mode mode*/);
void fold(const bool recursive = false);
void unfold(const bool recursive = false);

/**
* See @ref twidget::create_walker.
Expand All @@ -141,6 +138,11 @@ class ttree_view_node : public twidget
return new gui2::iterator::ttree_node(*this, children_);
}

boost::ptr_vector<ttree_view_node>& children()
{
return children_;
}

/** See @ref twidget::find_at. */
virtual twidget* find_at(const tpoint& coordinate,
const bool must_be_active) override;
Expand Down

0 comments on commit a47fb5a

Please sign in to comment.