DVUI

Parameters

#
self:*FloatingTooltipWidget
*FloatingTooltipWidget

Source

Implementation

#
pub fn shown(self: *FloatingTooltipWidget) bool {
    // protect against this being called multiple times
    if (self.installed) {
        return true;
    }

    // check for mouse position in active_rect
    const evts = dvui.events();
    for (evts) |*e| {
        if (!dvui.eventMatch(e, .{ .id = self.data().id, .r = self.init_options.active_rect })) {
            continue;
        }

        if (e.evt == .mouse and e.evt.mouse.action == .position) {
            self.mouse_good_this_frame = true;
            if (!self.showing) {
                self.showing = true;
            }
        }
    }

    if (self.showing) {
        switch (self.init_options.position) {
            .horizontal, .vertical => |o| {
                const ar = self.init_options.active_rect.toNatural();
                const r = Rect.Natural.fromPoint(ar.topLeft()).toSize(.cast(self.data().rect.size()));
                self.data().rect = .cast(dvui.placeOnScreen(dvui.windowRect(), ar, if (o == .horizontal) .horizontal else .vertical, r));
            },
            .sticky => {
                if (dvui.firstFrame(self.data().id)) {
                    const mp = dvui.currentWindow().mouse_pt.toNatural();
                    dvui.dataSet(null, self.data().id, "_sticky_pt", mp);
                } else {
                    const mp = dvui.dataGet(null, self.data().id, "_sticky_pt", dvui.Point.Natural) orelse dvui.Point.Natural{};
                    var r = Rect.Natural.fromPoint(mp).toSize(.cast(self.data().rect.size()));
                    r.x += 10;
                    r.y -= r.h + 10;
                    self.data().rect = .cast(dvui.placeOnScreen(dvui.windowRect(), .{}, .none, r));
                }
            },
            .absolute => {},
        }
        //std.debug.print("rect {}\n", .{self.data().rect});

        self.install();

        if (self.init_options.interactive) {
            // check for mouse position in tooltip window rect
            for (evts) |*e| {
                if (!dvui.eventMatch(e, .{ .id = self.data().id, .r = self.data().borderRectScale().r })) {
                    continue;
                }

                if (e.evt == .mouse and e.evt.mouse.action == .position) {
                    self.mouse_good_this_frame = true;
                }
            }
        }

        return true;
    }

    return false;
}