use lambda instead of std::bind

This commit is contained in:
Jinhao
2015-09-27 05:31:42 +08:00
parent 90533b3a83
commit 2f47e89af1
8 changed files with 212 additions and 28 deletions

View File

@@ -213,8 +213,35 @@ namespace checkbox
element_tag el;
el.uiobj = &uiobj;
el.eh_checked = uiobj.events().click.connect_unignorable(std::bind(&radio_group::_m_checked, this, std::placeholders::_1), true);
el.eh_destroy = uiobj.events().destroy.connect_unignorable(std::bind(&radio_group::_m_destroy, this, std::placeholders::_1));
//el.eh_checked = uiobj.events().click.connect_unignorable(std::bind(&radio_group::_m_checked, this, std::placeholders::_1), true); //deprecated
el.eh_checked = uiobj.events().click.connect_unignorable([this](const arg_click& arg)
{
for (auto & i : ui_container_)
i.uiobj->check(arg.window_handle == i.uiobj->handle());
}, true);
//el.eh_destroy = uiobj.events().destroy.connect_unignorable(std::bind(&radio_group::_m_destroy, this, std::placeholders::_1)); //deprecated
el.eh_destroy = uiobj.events().destroy.connect_unignorable([this](const arg_destroy& arg)
{
/*
auto i = std::find_if(ui_container_.begin(), ui_container_.end(), [&arg](decltype(*ui_container_.begin()) & x)
{
return (arg.window_handle == x.uiobj->handle());
});
if (i != ui_container_.end())
ui_container_.erase(i);
*/
for (auto i = ui_container_.begin(); i != ui_container_.end(); ++i)
{
if (arg.window_handle == i->uiobj->handle())
{
ui_container_.erase(i);
return;
}
}
});
ui_container_.push_back(el);
}
@@ -231,14 +258,16 @@ namespace checkbox
{
return ui_container_.size();
}
void radio_group::_m_checked(const arg_click& arg)
/*
void radio_group::_m_checked(const arg_click& arg) //deprecated
{
for (auto & i : ui_container_)
i.uiobj->check(arg.window_handle == i.uiobj->handle());
}
*/
void radio_group::_m_destroy(const arg_destroy& arg)
/*
void radio_group::_m_destroy(const arg_destroy& arg) //deprecated
{
auto i = std::find_if(ui_container_.begin(), ui_container_.end(), [&arg](decltype(*ui_container_.begin()) & x)
{
@@ -247,5 +276,6 @@ namespace checkbox
if(i != ui_container_.end())
ui_container_.erase(i);
}
*/
//end class radio_group
}//end namespace nana

View File

@@ -172,10 +172,31 @@ namespace nana
{
editor_->editable(enb);
/*
if(enb)
editor_->ext_renderer().background = nullptr;
else
editor_->ext_renderer().background = std::bind(&drawer_impl::_m_draw_background, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3);
editor_->ext_renderer().background = std::bind(&drawer_impl::_m_draw_background, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3); //deprecated
*/
if (!enb)
{
editor_->ext_renderer().background = [this](graph_reference graph, const ::nana::rectangle&, const ::nana::color&)
{
auto clr_from = colors::button_face_shadow_start;
auto clr_to = colors::button_face_shadow_end;
int pare_off_px = 1;
if (element_state::pressed == state_.button_state)
{
pare_off_px = 2;
std::swap(clr_from, clr_to);
}
graph.gradual_rectangle(::nana::rectangle(graph.size()).pare_off(pare_off_px), clr_from, clr_to, true);
};
}
else
editor_->ext_renderer().background = nullptr;
editor_->enable_background(enb);
editor_->enable_background_counterpart(!enb);
@@ -433,8 +454,8 @@ namespace nana
API::refresh_window(*widget_);
}
}
void _m_draw_background(graph_reference graph, const rectangle&, const ::nana::color&)
/*
void _m_draw_background(graph_reference graph, const rectangle&, const ::nana::color&) //deprecated
{
auto clr_from = colors::button_face_shadow_start;
auto clr_to = colors::button_face_shadow_end;
@@ -448,7 +469,7 @@ namespace nana
graph.gradual_rectangle(::nana::rectangle(graph.size()).pare_off(pare_off_px), clr_from, clr_to, true);
}
*/
void _m_draw_push_button(bool enabled)
{
::nana::rectangle r{graph_->size()};

View File

@@ -767,20 +767,28 @@ namespace nana
{
menulister_.clear();
auto f = std::bind(&layouter::_m_click_menulister, this, std::placeholders::_1);
//auto f = std::bind(&layouter::_m_click_menulister, this, std::placeholders::_1); //deprecated
auto fn = [this](::nana::menu::item_proxy& ipx)
{
if (this->activate(ipx.index()))
API::refresh_window(basis_.wd);
};
for(auto & m : list_)
menulister_.append(m.text, f);
menulister_.append(m.text, fn);
auto r = toolbox_.area(toolbox_.ButtonList, basis_.graph->height());
r.x += _m_toolbox_pos();
menulister_.popup(basis_.wd, r.x, r.bottom());
}
void _m_click_menulister(nana::menu::item_proxy& ip)
/*
void _m_click_menulister(nana::menu::item_proxy& ip) //deprecated
{
if(this->activate(ip.index()))
API::refresh_window(basis_.wd);
}
*/
//the begin pos of toolbox
int _m_toolbox_pos() const

View File

@@ -1491,7 +1491,60 @@ namespace nana
impl_->data.trigger_ptr = this;
impl_->data.renderer = nana::pat::cloneable<renderer_interface>(internal_renderer());
impl_->data.comp_placer = nana::pat::cloneable<compset_placer_interface>(internal_placer());
impl_->adjust.timer.elapse(std::bind(&trigger::_m_deal_adjust, this));
//impl_->adjust.timer.elapse(std::bind(&trigger::_m_deal_adjust, this)); //deprecated
impl_->adjust.timer.elapse([this]
{
auto & adjust = impl_->adjust;
if (adjust.scroll_timestamp && (nana::system::timestamp() - adjust.scroll_timestamp >= 500))
{
if (0 == adjust.offset_x_adjust)
{
if (!impl_->make_adjust(adjust.node ? adjust.node : impl_->shape.first, 1))
{
adjust.offset_x_adjust = 0;
adjust.node = nullptr;
adjust.scroll_timestamp = 0;
adjust.timer.stop();
return;
}
}
auto & shape = impl_->shape;
const int delta = 5;
int old = shape.offset_x;
if (shape.offset_x < adjust.offset_x_adjust)
{
shape.offset_x += delta;
if (shape.offset_x > adjust.offset_x_adjust)
shape.offset_x = adjust.offset_x_adjust;
}
else if (shape.offset_x > adjust.offset_x_adjust)
{
shape.offset_x -= delta;
if (shape.offset_x < adjust.offset_x_adjust)
shape.offset_x = adjust.offset_x_adjust;
}
impl_->draw(false);
API::update_window(impl_->data.widget_ptr->handle());
if (impl_->node_state.tooltip)
{
nana::point pos = impl_->node_state.tooltip->pos();
impl_->node_state.tooltip->move(pos.x - shape.offset_x + old, pos.y);
}
if (shape.offset_x == adjust.offset_x_adjust)
{
adjust.offset_x_adjust = 0;
adjust.node = nullptr;
adjust.scroll_timestamp = 0;
adjust.timer.stop();
}
}
});
impl_->adjust.timer.interval(16);
impl_->adjust.timer.start();
}
@@ -2099,7 +2152,8 @@ namespace nana
}
}
void trigger::_m_deal_adjust()
/*
void trigger::_m_deal_adjust() //deprecated
{
auto & adjust = impl_->adjust;
if(adjust.scroll_timestamp && (nana::system::timestamp() - adjust.scroll_timestamp >= 500))
@@ -2151,6 +2205,7 @@ namespace nana
}
}
}
//*/
//end class trigger
}//end namespace treebox
}//end namespace drawerbase