fix detach
This commit is contained in:
@@ -27,6 +27,8 @@ namespace example
|
|||||||
VE_PUSH_FONT(REGULAR, 20);
|
VE_PUSH_FONT(REGULAR, 20);
|
||||||
if (ImGui::Button("Test signal_double", ImVec2(128, 130)))
|
if (ImGui::Button("Test signal_double", ImVec2(128, 130)))
|
||||||
VE::EMIT(test_event::TEST_EVEN, std::string("test event message ui_layer_double"));
|
VE::EMIT(test_event::TEST_EVEN, std::string("test event message ui_layer_double"));
|
||||||
|
|
||||||
|
if (ImGui::Button("Test on_detach", ImVec2(128, 130))) on_detach();
|
||||||
VE_POP_FONT();
|
VE_POP_FONT();
|
||||||
|
|
||||||
ImGui::End();
|
ImGui::End();
|
||||||
|
|||||||
@@ -26,17 +26,15 @@ namespace VE
|
|||||||
event_handler handler;
|
event_handler handler;
|
||||||
handler.m_func = std::bind(method, obj, std::placeholders::_1);
|
handler.m_func = std::bind(method, obj, std::placeholders::_1);
|
||||||
handler.m_obj = obj;
|
handler.m_obj = obj;
|
||||||
handler.m_func_ptr = reinterpret_cast<void*>(&method);
|
|
||||||
m_funcs.push_back(handler);
|
m_funcs.push_back(handler);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void disconnect(T* obj, void (T::*method)(event))
|
void disconnect(T* obj, void (T::*method)(event))
|
||||||
{
|
{
|
||||||
auto func_ptr = reinterpret_cast<void*>(&method);
|
|
||||||
m_funcs.erase(std::remove_if(m_funcs.begin(), m_funcs.end(),
|
m_funcs.erase(std::remove_if(m_funcs.begin(), m_funcs.end(),
|
||||||
[obj, func_ptr](const event_handler& handler) {
|
[obj](const event_handler& handler) {
|
||||||
return handler.m_obj == obj && handler.m_func_ptr == func_ptr;
|
return handler.m_obj == obj;
|
||||||
}),
|
}),
|
||||||
m_funcs.end()
|
m_funcs.end()
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user