addEventPointer
Add a touch up/down event. This is similar to addEventMouseButton but also includes a normalized (0-1) touch point.
This can be called outside begin/end. You should add all the events for a frame either before begin() or just after begin() and before calling normal dvui widgets. end() clears the event list.
Parameters
- self:*Self
- *Self
- opts:AddEventPointerOptions
- AddEventPointerOptions
Source
Implementation
pub fn addEventPointer(self: *Self, opts: AddEventPointerOptions) std.mem.Allocator.Error!bool {
if (dvui.debug.target == .mouse_until_click and opts.action == .press and opts.button.pointer()) {
// a left click or touch will stop the debug stuff from following
// the mouse, but need to stop it at the end of the frame when
// we've gotten the info
dvui.debug.target = .mouse_quitting;
return true;
}
var bb = opts.button;
if (dvui.debug.touch_simulate_events and bb == .left) {
bb = .touch0;
if (opts.action == .press) {
dvui.debug.touch_simulate_down = true;
} else if (opts.action == .release) {
dvui.debug.touch_simulate_down = false;
}
}
if (opts.xynorm) |xyn| {
self.mouse_pt = (Point{ .x = xyn.x * self.data().rect.w, .y = xyn.y * self.data().rect.h }).scale(self.natural_scale, Point.Physical);
}
const target_id = opts.target_id orelse if (self.capture) |cap| cap.id else null;
const winId = self.subwindows.windowFor(self.mouse_pt);
if (opts.action == .press and bb.pointer()) {
_ = try self.addEventFocus(.{ .pt = self.mouse_pt, .button = bb });
}
self.positionMouseEventRemove();
self.event_num += 1;
try self.events.append(self.arena(), Event{
.num = self.event_num,
.target_widgetId = target_id,
.evt = .{
.mouse = .{
.action = opts.action,
.button = bb,
.mod = self.modifiers,
.p = self.mouse_pt,
.floating_win = winId,
},
},
});
const ret = (self.data().id != winId);
try self.positionMouseEventAdd();
return ret;
}