DVUI

addEventTouchMotion

Add an event that represents a finger moving while touching the screen.

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
finger:dvui.enums.Button
dvui.enums.Button
xnorm:f32
f32
ynorm:f32
f32
dxnorm:f32
f32
dynorm:f32
f32

Source

Implementation

#
pub fn addEventTouchMotion(self: *Self, finger: dvui.enums.Button, xnorm: f32, ynorm: f32, dxnorm: f32, dynorm: f32) std.mem.Allocator.Error!bool {
    self.positionMouseEventRemove();

    const newpt = (Point{ .x = xnorm * self.data().rect.w, .y = ynorm * self.data().rect.h }).scale(self.natural_scale, Point.Physical);
    //std.debug.print("touch motion {} {d} {d}\n", .{ finger, newpt.x, newpt.y });
    self.mouse_pt = newpt;

    const dp = (Point{ .x = dxnorm * self.data().rect.w, .y = dynorm * self.data().rect.h }).scale(self.natural_scale, Point.Physical);

    const winId = self.subwindows.windowFor(self.mouse_pt);

    const widget_id = if (self.capture) |cap| cap.id else null;

    self.event_num += 1;
    try self.events.append(self.arena(), Event{
        .num = self.event_num,
        .target_widgetId = widget_id,
        .evt = .{
            .mouse = .{
                .action = .{ .motion = dp },
                .button = finger,
                .mod = self.modifiers,
                .p = self.mouse_pt,
                .floating_win = winId,
            },
        },
    });

    const ret = (self.data().id != winId);
    try self.positionMouseEventAdd();
    return ret;
}