refactor
make it more readable
This commit is contained in:
parent
462aadcc26
commit
1a91511d64
@ -95,6 +95,13 @@ namespace detail
|
|||||||
typedef tree_node<element_type> node_type;
|
typedef tree_node<element_type> node_type;
|
||||||
typedef typename node_type::value_type value_type;
|
typedef typename node_type::value_type value_type;
|
||||||
|
|
||||||
|
enum class enum_order
|
||||||
|
{
|
||||||
|
stop, //Stop enumeration
|
||||||
|
proceed_with_children,
|
||||||
|
proceed
|
||||||
|
};
|
||||||
|
|
||||||
tree_cont()
|
tree_cont()
|
||||||
:root_(nullptr)
|
:root_(nullptr)
|
||||||
{}
|
{}
|
||||||
@ -234,59 +241,6 @@ namespace detail
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Functor>
|
|
||||||
void for_each(node_type* node, Functor f)
|
|
||||||
{
|
|
||||||
if(nullptr == node) node = root_.child;
|
|
||||||
int state = 0; //0: Sibling, the last is a sibling of node
|
|
||||||
//1: Owner, the last is the owner of node
|
|
||||||
//>= 2: Children, the last is is a child of the node that before this node.
|
|
||||||
while(node)
|
|
||||||
{
|
|
||||||
switch(f(*node, state))
|
|
||||||
{
|
|
||||||
case 0: return;
|
|
||||||
case 1:
|
|
||||||
{
|
|
||||||
if(node->child)
|
|
||||||
{
|
|
||||||
node = node->child;
|
|
||||||
state = 1;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
return;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(node->next)
|
|
||||||
{
|
|
||||||
node = node->next;
|
|
||||||
state = 0;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
state = 1;
|
|
||||||
if(node == &root_) return;
|
|
||||||
|
|
||||||
while(true)
|
|
||||||
{
|
|
||||||
++state;
|
|
||||||
if(node->owner->next)
|
|
||||||
{
|
|
||||||
node = node->owner->next;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
node = node->owner;
|
|
||||||
|
|
||||||
if(node == &root_) return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename Functor>
|
template<typename Functor>
|
||||||
void for_each(node_type* node, Functor f) const
|
void for_each(node_type* node, Functor f) const
|
||||||
{
|
{
|
||||||
@ -296,24 +250,18 @@ namespace detail
|
|||||||
//>= 2: Children, the last is is a child of the node that before this node.
|
//>= 2: Children, the last is is a child of the node that before this node.
|
||||||
while(node)
|
while(node)
|
||||||
{
|
{
|
||||||
switch(f(*node, state))
|
enum_order order = f(*node, state);
|
||||||
|
|
||||||
|
if (enum_order::stop == order)
|
||||||
{
|
{
|
||||||
case 0: return;
|
return;
|
||||||
case 1:
|
}
|
||||||
{
|
else if (node->child && (enum_order::proceed_with_children == order))
|
||||||
if(node->child)
|
|
||||||
{
|
{
|
||||||
node = node->child;
|
node = node->child;
|
||||||
state = 1;
|
state = 1;
|
||||||
}
|
}
|
||||||
else
|
else if(node->next)
|
||||||
return;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(node->next)
|
|
||||||
{
|
{
|
||||||
node = node->next;
|
node = node->next;
|
||||||
state = 0;
|
state = 0;
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* A Treebox Implementation
|
* A Treebox Implementation
|
||||||
* Nana C++ Library(http://www.nanapro.org)
|
* Nana C++ Library(http://www.nanapro.org)
|
||||||
* Copyright(C) 2003-2010 Jinhao(cnjinhao@hotmail.com)
|
* Copyright(C) 2003-2020 Jinhao(cnjinhao@hotmail.com)
|
||||||
*
|
*
|
||||||
* Distributed under the Boost Software License, Version 1.0.
|
* Distributed under the Boost Software License, Version 1.0.
|
||||||
* (See accompanying file LICENSE_1_0.txt or copy at
|
* (See accompanying file LICENSE_1_0.txt or copy at
|
||||||
@ -184,10 +184,11 @@ namespace nana
|
|||||||
class trigger::item_locator
|
class trigger::item_locator
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
using enum_order = tree_cont_type::enum_order;
|
||||||
using node_type = tree_cont_type::node_type;
|
using node_type = tree_cont_type::node_type;
|
||||||
|
|
||||||
item_locator(implementation * impl, int item_pos, int x, int y);
|
item_locator(implementation * impl, int item_pos, int x, int y);
|
||||||
int operator()(node_type &node, int affect);
|
enum_order operator()(node_type &node, int affect);
|
||||||
node_type * node() const;
|
node_type * node() const;
|
||||||
component what() const;
|
component what() const;
|
||||||
bool item_body() const;
|
bool item_body() const;
|
||||||
@ -228,6 +229,7 @@ namespace nana
|
|||||||
: public compset_interface
|
: public compset_interface
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
using enum_order = tree_cont_type::enum_order;
|
||||||
using node_type = tree_cont_type::node_type;
|
using node_type = tree_cont_type::node_type;
|
||||||
|
|
||||||
item_rendering_director(implementation * impl, const nana::point& pos):
|
item_rendering_director(implementation * impl, const nana::point& pos):
|
||||||
@ -240,10 +242,11 @@ namespace nana
|
|||||||
//0 = Sibling, the last is a sibling of node
|
//0 = Sibling, the last is a sibling of node
|
||||||
//1 = Owner, the last is the owner of node
|
//1 = Owner, the last is the owner of node
|
||||||
//>=2 = Children, the last is a child of a node that before this node.
|
//>=2 = Children, the last is a child of a node that before this node.
|
||||||
int operator()(const node_type& node, int affect)
|
enum_order operator()(const node_type& node, int affect)
|
||||||
{
|
{
|
||||||
iterated_node_ = &node;
|
iterated_node_ = &node;
|
||||||
|
|
||||||
|
// Increase/decrease indent
|
||||||
switch (affect)
|
switch (affect)
|
||||||
{
|
{
|
||||||
case 1:
|
case 1:
|
||||||
@ -255,7 +258,7 @@ namespace nana
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (iterated_node_->value.second.hidden) // Skip drawing if the node is hidden
|
if (iterated_node_->value.second.hidden) // Skip drawing if the node is hidden
|
||||||
return 2;
|
return enum_order::proceed;
|
||||||
|
|
||||||
auto & comp_placer = impl_->data.comp_placer;
|
auto & comp_placer = impl_->data.comp_placer;
|
||||||
|
|
||||||
@ -275,9 +278,9 @@ namespace nana
|
|||||||
pos_.y += node_r_.height;
|
pos_.y += node_r_.height;
|
||||||
|
|
||||||
if (pos_.y > static_cast<int>(impl_->data.graph->height()))
|
if (pos_.y > static_cast<int>(impl_->data.graph->height()))
|
||||||
return 0;
|
return enum_order::stop;
|
||||||
|
|
||||||
return (node.child && node.value.second.expanded ? 1 : 2);
|
return ((node.child && node.value.second.expanded) ? enum_order::proceed_with_children : enum_order::proceed);
|
||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
//Overrides compset_interface
|
//Overrides compset_interface
|
||||||
@ -1642,7 +1645,7 @@ namespace nana
|
|||||||
node_(nullptr)
|
node_(nullptr)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
int trigger::item_locator::operator()(node_type &node, int affect)
|
auto trigger::item_locator::operator()(node_type &node, int affect) -> enum_order
|
||||||
{
|
{
|
||||||
switch(affect)
|
switch(affect)
|
||||||
{
|
{
|
||||||
@ -1654,7 +1657,7 @@ namespace nana
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (node.value.second.hidden) // Do not account for hidden nodes
|
if (node.value.second.hidden) // Do not account for hidden nodes
|
||||||
return 2;
|
return enum_order::proceed;
|
||||||
|
|
||||||
impl_->assign_node_attr(node_attr_, &node);
|
impl_->assign_node_attr(node_attr_, &node);
|
||||||
nana::rectangle node_r;
|
nana::rectangle node_r;
|
||||||
@ -1687,15 +1690,12 @@ namespace nana
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0; //Stop iterating
|
return enum_order::stop; //Stop iterating
|
||||||
}
|
}
|
||||||
|
|
||||||
item_pos_.y += node_r.height;
|
item_pos_.y += node_r.height;
|
||||||
|
|
||||||
if(node.value.second.expanded && node.child)
|
return ((node.child && node.value.second.expanded) ? enum_order::proceed_with_children : enum_order::proceed);
|
||||||
return 1;
|
|
||||||
|
|
||||||
return 2;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
trigger::item_locator::node_type * trigger::item_locator::node() const
|
trigger::item_locator::node_type * trigger::item_locator::node() const
|
||||||
|
Loading…
x
Reference in New Issue
Block a user