processEvent
Parameters
- self:*PanedWidget
- *PanedWidget
- e:*Event
- *Event
Source
Implementation
pub fn processEvent(self: *PanedWidget, e: *Event) void {
if (e.evt == .mouse) {
const rs = self.data().contentRectScale();
const handle_size = self.handleSize() * rs.s; // physical
const handle_gap = self.handleGap() * rs.s; // physical
const cursor: enums.Cursor = switch (self.init_opts.direction) {
.horizontal => .arrow_w_e,
.vertical => .arrow_n_s,
};
self.mouse_dist = switch (self.init_opts.direction) {
.horizontal => @abs(e.evt.mouse.p.x - std.math.clamp(
rs.r.x + (rs.r.w - handle_gap) * self.split_ratio.* + handle_size,
0,
rs.r.x + rs.r.w - handle_size,
)) / rs.s,
.vertical => @abs(e.evt.mouse.p.y - std.math.clamp(
rs.r.y + (rs.r.h - handle_gap) * self.split_ratio.* + handle_size,
0,
rs.r.y + rs.r.h - handle_size,
)) / rs.s,
};
if (self.init_opts.handle_dynamic) |hd| {
const mouse_dist_outside = @max(0, self.mouse_dist - hd.handle_size_max / 2);
self.handle_thick = std.math.clamp(hd.handle_size_max - mouse_dist_outside / 2, self.init_opts.handle_size, hd.handle_size_max);
}
if (self.collapsed()) return;
if (dvui.captured(self.data().id) or self.mouse_dist <= @max(self.handle_thick / 2, 2)) {
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 });
} 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();
} 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| {
_ = dps;
switch (self.init_opts.direction) {
.horizontal => {
self.split_ratio.* = (e.evt.mouse.p.x - rs.r.x - handle_gap / 2) / (rs.r.w - handle_gap);
},
.vertical => {
self.split_ratio.* = (e.evt.mouse.p.y - rs.r.y - handle_gap / 2) / (rs.r.h - handle_gap);
},
}
self.split_ratio.* = @max(0.0, @min(1.0, self.split_ratio.*));
}
} else if (e.evt.mouse.action == .position) {
dvui.cursorSet(cursor);
}
}
}
}