Skip to content

Commit 61d80f8

Browse files
Christophxarvic
authored andcommitted
- remove WidgetPod::viewport_offset and Event::with_scroll_offset
- add set_layout_dyn - changed clipbox implementation
1 parent ebfc7ec commit 61d80f8

File tree

2 files changed

+14
-56
lines changed

2 files changed

+14
-56
lines changed

druid/src/core.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,7 @@ impl<T: Data, W: Widget<T>> WidgetPod<T, W> {
573573

574574
let child_mouse_pos = ctx
575575
.mouse_pos
576-
.map(|pos| pos - self.layout_rect().origin().to_vec2() + self.viewport_offset());
576+
.map(|pos| pos - self.layout_rect().origin().to_vec2());
577577
let prev_size = self.state.size;
578578

579579
let mut child_ctx = LayoutCtx {
@@ -986,13 +986,10 @@ impl<T: Data, W: Widget<T>> WidgetPod<T, W> {
986986
}
987987
}
988988
InternalLifeCycle::ParentWindowOrigin => {
989-
let new_parent_window_origin = ctx.widget_state.window_origin();
990-
if new_parent_window_origin != self.state.parent_window_origin {
991-
self.state.parent_window_origin = new_parent_window_origin;
992-
true
993-
} else {
994-
false
995-
}
989+
let old_parent_window_origin = self.state.parent_window_origin;
990+
self.state.parent_window_origin = ctx.widget_state.window_origin();
991+
992+
old_parent_window_origin != self.state.parent_window_origin || self.state.needs_window_origin
996993
}
997994
InternalLifeCycle::DebugRequestState { widget, state_cell } => {
998995
if *widget == self.id() {
@@ -1279,7 +1276,7 @@ impl WidgetState {
12791276
.layout_rect()
12801277
.with_origin(Point::ORIGIN)
12811278
.inset(self.paint_insets);
1282-
let offset = child_state.layout_rect().origin().to_vec2() - child_state.viewport_offset;
1279+
let offset = child_state.layout_rect().origin().to_vec2();
12831280
for &r in child_state.invalid.rects() {
12841281
let r = (r + offset).intersect(clip);
12851282
if r.area() != 0.0 {

druid/src/widget/clip_box.rs

Lines changed: 8 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -339,56 +339,17 @@ impl<T, W: Widget<T>> ClipBox<T, W> {
339339
}
340340
}
341341

342-
/// Changes the viewport offset by `delta`.
343-
///
344-
/// Returns true if the offset actually changed. Even if `delta` is non-zero, the offset might
345-
/// not change. For example, if you try to move the viewport down but it is already at the
346-
/// bottom of the child widget, then the offset will not change and this function will return
347-
/// false.
348-
pub fn pan_by(&mut self, ctx: &mut EventCtx, delta: Vec2) -> bool {
349-
self.pan_to(ctx: &mut EventCtx, self.viewport_origin() + delta)
350-
}
351-
352-
/// Changes the viewport offset on the specified axis to 'position'.
353-
///
354-
/// The other axis will remain unchanged.
355-
pub fn pan_to_on_axis(&mut self, ctx: &mut EventCtx, axis: Axis, position: f64) -> bool {
356-
let new_origin = axis.pack(position, axis.minor_pos(self.viewport_origin()));
357-
self.with_port(ctx, |ctx, port| {port.pan_to(new_origin.into());})
358-
}
359-
360-
/// Sets the viewport origin to `pos`.
361-
///
362-
/// Returns true if the position changed. Note that the valid values for the viewport origin
363-
/// are constrained by the size of the child, and so the origin might not get set to exactly
364-
/// `pos`.
365-
pub fn pan_to(&mut self, ctx: &mut EventCtx, origin: Point) -> bool {
366-
self.with_port(ctx, |ctx, port|{port.pan_to(origin);})
367-
}
368-
369-
/// Adjust the viewport to display as much of the target region as is possible.
370-
///
371-
/// Returns `true` if the viewport changes.
372-
///
373-
/// This will move the viewport the smallest distance that fully shows
374-
/// the target region. If the target region is larger than the viewport,
375-
/// we will display the portion that fits, prioritizing the portion closest
376-
/// to the origin.
377-
pub fn pan_to_visible(&mut self, ctx: &mut EventCtx, region: Rect) -> bool {
378-
self.with_port(ctx, |ctx, port|{port.pan_to_visible(region);})
379-
}
380-
381342
/// Modify the `ClipBox`'s viewport rectangle with a closure.
382343
///
383344
/// The provided callback function can modify its argument, and when it is
384345
/// done then this `ClipBox` will be modified to have the new viewport rectangle.
385-
pub fn with_port<F: FnOnce(&mut EventCtx, &mut Viewport)>(&mut self, ctx: &mut EventCtx, f: F) -> bool {
346+
pub fn with_port<F: FnOnce(&mut EventCtx, &mut Viewport)>(&mut self, ctx: &mut EventCtx, data: T, env: &Env, f: F) -> bool {
386347
f(ctx, &mut self.port);
387348
let new_content_origin = -self.port.view_origin;
388349

389350
if new_content_origin != self.child.layout_rect().origin() {
390351
self.child
391-
.set_origin_dyn(ctx, new_content_origin);
352+
.set_origin_dyn(ctx, data, env, new_content_origin);
392353
true
393354
} else {
394355
false
@@ -406,7 +367,7 @@ impl<T: Data, W: Widget<T>> Widget<T> for ClipBox<T, W> {
406367
// prevent unexpected behaviour, by clipping SCROLL_TO_VIEW notifications
407368
// to this ClipBox's viewport.
408369
ctx.set_handled();
409-
self.with_port(ctx, |ctx, port| {
370+
self.with_port(ctx, data, env, |ctx, port| {
410371
port.fixed_scroll_to_view_handling(
411372
ctx,
412373
*global_highlight_rect,
@@ -416,7 +377,7 @@ impl<T: Data, W: Widget<T>> Widget<T> for ClipBox<T, W> {
416377
}
417378
}
418379
} else {
419-
self.child.event(ctx, &child_event, data, env);
380+
self.child.event(ctx, event, data, env);
420381
}
421382
}
422383

@@ -462,11 +423,11 @@ impl<T: Data, W: Widget<T>> Widget<T> for ClipBox<T, W> {
462423
};
463424

464425
self.port.content_size = content_size;
465-
self.child.set_origin(ctx, data, env, Point::ORIGIN);
466-
467426
self.port.view_size = bc.constrain(content_size);
468-
let new_offset = self.port.clamp_view_origin(self.viewport_origin());
469-
self.pan_to(new_offset);
427+
428+
let new_offset = -self.port.clamp_view_origin(-self.child.layout_rect().origin());
429+
self.child.set_origin(ctx, data, env, new_offset);
430+
470431
trace!("Computed sized: {}", self.viewport_size());
471432
self.viewport_size()
472433
}

0 commit comments

Comments
 (0)