processEvent
Parameters
- self:*HeaderResizeWidget
- *HeaderResizeWidget
- e:*Event
- *Event
Source
Implementation
pub fn processEvent(self: *HeaderResizeWidget, e: *Event) void {
if (e.evt == .mouse) {
const rs = self.data().rectScale();
const cursor: Cursor = switch (self.direction) {
.vertical => .arrow_w_e,
.horizontal => .arrow_n_s,
};
if (e.evt.mouse.action == .press and e.evt.mouse.button.pointer()) {
e.handle(@src(), self.data());
// capture and start drag
dvui.captureMouse(self.data(), e.num);
dvui.dragPreStart(e.evt.mouse.button, e.evt.mouse.p, .{ .cursor = cursor });
self.offset = .{};
} else if (e.evt.mouse.action == .release and e.evt.mouse.button.pointer()) {
e.handle(@src(), self.data());
// stop possible drag and capture
dvui.captureMouse(null, e.num);
dvui.dragEnd();
self.offset = .{};
} else if (e.evt.mouse.action == .motion and dvui.captured(self.data().id)) {
e.handle(@src(), self.data());
// move if dragging
if (dvui.dragging(e.evt.mouse.p, null)) |dps| {
dvui.refresh(null, @src(), self.data().id);
const unclamped_size =
switch (self.direction) {
.vertical => self.size() + dps.x / rs.s + self.offset.x,
.horizontal => self.size() + dps.y / rs.s + self.offset.y,
};
const clamped_size = std.math.clamp(
unclamped_size,
self.init_opts.min_size orelse 1,
self.init_opts.max_size orelse dvui.max_float_safe,
);
self.sizeSet(clamped_size);
switch (self.direction) {
.vertical => self.offset.x = unclamped_size - self.size(),
.horizontal => self.offset.y = unclamped_size - self.size(),
}
}
} else if (e.evt.mouse.action == .position) {
dvui.cursorSet(cursor);
}
}
}