processScrollDrag
Parameters
- self:*ScrollContainerWidget
- *ScrollContainerWidget
- sd:dvui.ScrollDragOptions
- dvui.ScrollDragOptions
Source
Implementation
pub fn processScrollDrag(
self: *ScrollContainerWidget,
sd: dvui.ScrollDragOptions,
) void {
const rs = self.data().contentRectScale();
var scrolly: f32 = 0;
if (sd.mouse_pt.y <= rs.r.y and // want to scroll up
sd.screen_rect.y < rs.r.y and // scrolling would show more of child
self.si.viewport.y > 0) // can scroll up
{
scrolly = if (!self.seen_scroll_drag) -200 * dvui.secondsSinceLastFrame() else -5;
}
if (sd.mouse_pt.y >= (rs.r.y + rs.r.h) and
(sd.screen_rect.y + sd.screen_rect.h) > (rs.r.y + rs.r.h) and
self.si.viewport.y < self.si.scrollMax(.vertical))
{
scrolly = if (!self.seen_scroll_drag) 200 * dvui.secondsSinceLastFrame() else 5;
}
var scrollx: f32 = 0;
if (sd.mouse_pt.x <= rs.r.x and // want to scroll left
sd.screen_rect.x < rs.r.x and // scrolling would show more of child
self.si.viewport.x > 0) // can scroll left
{
scrollx = if (!self.seen_scroll_drag) -200 * dvui.secondsSinceLastFrame() else -5;
}
if (sd.mouse_pt.x >= (rs.r.x + rs.r.w) and
(sd.screen_rect.x + sd.screen_rect.w) > (rs.r.x + rs.r.w) and
self.si.viewport.x < self.si.scrollMax(.horizontal))
{
scrollx = if (!self.seen_scroll_drag) 200 * dvui.secondsSinceLastFrame() else 5;
}
const before = self.si.viewport.topLeft();
if (scrolly != 0 or scrollx != 0) {
if (scrolly != 0) {
self.si.scrollByOffset(.vertical, scrolly);
}
if (scrollx != 0) {
self.si.scrollByOffset(.horizontal, scrollx);
}
dvui.refresh(null, @src(), self.data().id);
// if we are scrolling, then we need a motion event next
// frame so that the child widget can adjust selection
dvui.currentWindow().inject_motion_event = true;
}
if (self.init_opts.user_scroll) |us| us.* = us.*.plus(self.si.viewport.topLeft().diff(before));
self.seen_scroll_drag = true;
}