nana::general_events
Defined in header <nana/gui/widgets/widget.hpp>
class general_events;
The class general_events provides some fundamental events that every widget owns.
Events
Mouse events
Occurs when the cursor enters the window.
void(const arg_mouse& arg)
Parameters
arg -
event argument, this parameter has following members
Occurs when the cursor moves on the window.
void(const arg_mouse& arg)
Parameters
arg -
event argument, this parameter has following members
Occurs when the cursor leaves the window.
void(const arg_mouse& arg)
Parameters
arg -
event argument, this parameter has following members
Occurs when the user presses the mouse button.
void(const arg_mouse& arg)
Parameters
arg -
event argument, this parameter has following members
Occurs when the user presses the mouse button.
void(const arg_mouse& arg)
Parameters
arg -
event argument, this parameter has following members
Occurs when the window is clicked. The click event occurs after mouse_down and before mouse_up.
void(const arg_mouse& arg)
Parameters
arg -
event argument, this parameter has following members
Occurs when the window is double clicked.
void(const arg_mouse& arg)
Parameters
arg -
event argument, this parameter has following members
Occurs when the mouse wheel rotates while the window has focus.
void(const arg_wheel& arg)
Parameters
arg -
event argument, this parameter has following members
Occurs when the mouse drops some external data while the window enable accepting files.
void(const arg_dropfiles& arg)
Parameters
arg -
event argument, this parameter has following members
Keyboard events
Occurs when a key is pressed while the window has focus.
void(const arg_keyboard& arg)
Parameters
arg -
event argument, this parameter has following members
Occurs when a character, whitespace or backspace is pressed.
void(const arg_keyboard& arg)
Parameters
arg -
event argument, this parameter has following members
Occurs when a key is released while the window has focus.
void(const arg_keyboard& arg)
Parameters
arg -
event argument, this parameter has following members
Occurs when a defined short key is pressed.
void(const arg_keyboard& arg)
Parameters
arg -
event argument, this parameter has following members
Status events
Occurs when the visibility changes.
void(const arg_expose& arg)
Parameters
arg -
event argument, this parameter has following members
Occurs when the window receives or loses keyboard focus.
void(const arg_focus& arg)
Parameters
arg -
event argument, this parameter has following members
Occurs when the window changes position.
void(const arg_move& arg)
Parameters
arg -
event argument, this parameter has following members
Occurs when the window is changing its size.
void(const arg_resizing& arg)
Parameters
arg -
event argument, this parameter has following members
Occurs when the window is changing its size.
void(const arg_resized& arg)
Parameters
arg -
event argument, this parameter has following members
Occurs when the window is destroy. When this event occurs, the all children have been destroyed.
void(const arg_destroy& arg)
Parameters
arg -
event argument, this parameter has following members
Event Argument
All event argument types are derived from class event_arg
class event_arg
{
public:
void stop_propagation() const;
};
{
public:
void stop_propagation() const;
};
When the stop_propagation() is called in a chain of event handler, the ignorable handlers behind the current one in the chain will not get called.
int main()
{
using namespace nana;
form fm;
fm.events().click([]{
//It will get called, but it is not the first event handler to be called.
});
fm.events().click([](const arg_mouse& arg){
arg.stop_propagation();
});
fm.events().click([]{
//It will not get called.
});
fm.events().click.connect_unignorable([]{
//It will get called because it is unignorable.
});
fm.events().click.connect_front([]{
//It will get called firstly, because it is the beginning of the chain.
});
fm.show();
exec();
}
{
using namespace nana;
form fm;
fm.events().click([]{
//It will get called, but it is not the first event handler to be called.
});
fm.events().click([](const arg_mouse& arg){
arg.stop_propagation();
});
fm.events().click([]{
//It will not get called.
});
fm.events().click.connect_unignorable([]{
//It will get called because it is unignorable.
});
fm.events().click.connect_front([]{
//It will get called firstly, because it is the beginning of the chain.
});
fm.show();
exec();
}
Example
The following code examples show how to register an event handler.
//Registering a handler without a event argument is allowed.
button.events().click([]
{
});
//Registering a handler with a event argument.
button.events().click([](const nana::arg_mouse&arg)
{
});
//It is allowed if the event argument is convertible to the provided event argument of handler.
//mouse_wheel's argument type is arg_wheel, it is convertible to arg_mouse.
button.events().mouse_wheel([](const nana::arg_mouse&arg)
{
});
//Register an event handler by using window handle.
auto window_handle = button.handle();
nana::API::events(window_handle).click([]{});
//Following code examples how to delete a handler through a specified event handle.
auto evt_handle = button.events().click([](const nana::arg_mouse&arg)
{
});
nana::API::umake_event(evt_handle); //OK
button.events().click.remove(evt_handler); //OK
button.events().mouse_move.remove(evt_handler); //Error! Deleting a handler with other event object is undefined behavior.
button.events().click([]
{
});
//Registering a handler with a event argument.
button.events().click([](const nana::arg_mouse&arg)
{
});
//It is allowed if the event argument is convertible to the provided event argument of handler.
//mouse_wheel's argument type is arg_wheel, it is convertible to arg_mouse.
button.events().mouse_wheel([](const nana::arg_mouse&arg)
{
});
//Register an event handler by using window handle.
auto window_handle = button.handle();
nana::API::events(window_handle).click([]{});
//Following code examples how to delete a handler through a specified event handle.
auto evt_handle = button.events().click([](const nana::arg_mouse&arg)
{
});
nana::API::umake_event(evt_handle); //OK
button.events().click.remove(evt_handler); //OK
button.events().mouse_move.remove(evt_handler); //Error! Deleting a handler with other event object is undefined behavior.