Event Handling
Events are triggered when a user clicks on a button,
or closes a window. The WVL supports the following events
mouse_click
is triggered when a user right clicks the mouse
mouse_dblclick
is triggered when a user double clicks the
mouse
mouse_down
is triggered when a user presss a button
of mouse
mouse_up
is triggered when a user releases the
button of mouse
mouse_move
is triggered when a user moves mouse on surface
of a widget
resize
is triggered when a user changes a widget's
size
key_press
is triggered when a user presses a key
tick
is triggered by timer in a specific
interval
Every event can be answered after the event installed, call the make_event to install an event. But an event installation requirs an event answer function, and the event answer function will be called by the WVL as CALLBACK. For example, answering the mouse_click on a form
class MyForm: public
wvl::form
{
public:
MyForm()
{
this->make_event<wvl::event::mouse_click>(wvl::bind_mem_fun(this,
&MyForm::OnClick));
this->show();
}
private:
void OnClick()
//If you want to get some information of the event, you can
use the parametor of the event, if so, you have to define the
function as void OnClick(const wvl::event_args& args)
{
//When
the member function is called, it denotes mouse was clicked on the form.
}
};
as you see, in fact, the answering function is a functor, and it must have operator(), and the parameter must be const wvl::event_args&.
wvl::bind_mem_fun creates
a binder_mem_fun_t, it holds the
this pointer and the pointer to the member function.
Not every event can be used on every widget. e.g. the event tick just can be
used on timer. Supposing that it is used on another widgets, and
it will cause a compilation error that tells you set a wrong event