ui::PointerEvent¶
Header: winui/core/Input.hpp.
One mouse / touch / pen event, in window-client DIPs, as delivered to Element::handle_pointer() and Window::handle_pointer().
A pen or a finger arrives as mouse events. device says which it was and, for a pen, the event carries its pressure, tilt and buttons. A press-and-release pair is what a control counts as a click.
Example:
// In an element of your own: a press and a release inside the bounds is a click.
class ToggleControl : public ui::Element
{
protected:
bool pointer_override(const ui::PointerEvent& e) override
{
if (e.action == ui::PointerAction::Down && e.button == ui::PointerButton::Left)
{
pressed_ = true;
return true;
}
if (e.action == ui::PointerAction::Up && pressed_)
{
pressed_ = false;
if (bounds().contains(e.position))
{
toggle();
}
return true;
}
return false;
}
// The wheel arrives through wheel_override(); return true when the element scrolled.
bool wheel_override(const ui::PointerEvent& e) override
{
offset_ += e.wheel_delta; // positive scrolls down
return true;
}
private:
void toggle();
bool pressed_ = false;
float offset_ = 0.0f;
};
| Field | Type | Default | |
|---|---|---|---|
position |
Point |
Pointer position in window-client DIPs (the same space as Element::bounds()). | |
button |
PointerButton |
PointerButton::None |
The button pressed or released; None for Move, Leave and Wheel. |
action |
PointerAction |
PointerAction::Move |
What happened; defaults to a plain move. |
wheel_delta |
float |
0.0f |
Valid only for PointerAction::Wheel: the scroll amount in DIPs. Positive scrolls down, so the content moves up, as with a non-inverted wheel. One notch of a standard mouse wheel is a few dozen DIPs. Code that constructs an event converts the platform's wheel units to DIPs first. |
modifiers |
ModifierKeys |
The modifier keys held at the time of this event. TextBox extends its selection on Shift+click, and Ctrl+wheel zooms where a plain wheel turn scrolls. | |
click_count |
int |
1 |
Valid only for PointerAction::Down: 1 for a plain click, 2/3 for a double-/triple-click. Clicks count as one sequence while they fall within the system's double-click time and distance. TextBox selects a word on a double-click and everything on a triple-click. |
horizontal_wheel |
bool |
false |
Valid only for PointerAction::Wheel: the turn came from a horizontal wheel or a sideways touchpad swipe, and wheel_delta is positive toward the right. A vertical wheel with Shift held stays a vertical turn here. A scroller decides itself whether Shift redirects it. |
device |
PointerDeviceType |
PointerDeviceType::Mouse |
The device behind the event. A pen's tip and a finger press, move and release as the left button. |
pressure |
float |
0.5f |
How hard the pen or finger presses, 0..1. 0.5 when the device does not say, which is always the case for the mouse, so pressure-sensitive drawing comes out even. |
tilt_x |
float |
0.0f |
A pen's tilt along x in degrees, -90..90, positive toward the right; 0 for any other device. |
tilt_y |
float |
0.0f |
A pen's tilt along y in degrees, -90..90, positive toward the user; 0 for any other device. |
eraser |
bool |
false |
A pen is erasing: its eraser end is down (the pen is turned over), or its eraser button is held. False for any other device. |
barrel_button |
bool |
false |
A pen's barrel button is held. With the default pen settings the system turns a press with it held into a right-click, so it shows up mostly on hover moves. |