Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #1129 and add request_timer to LayoutCtx #1278

Merged
merged 3 commits into from
Oct 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ You can find its changes [documented below](#060---2020-06-01).
- `RawLabel` widget displays text `Data`. ([#1252] by [@cmyr])
- 'Tabs' widget allowing static and dynamic tabbed layouts. ([#1160] by [@rjwittams])
- `RichText` and `Attribute` types for creating rich text ([#1255] by [@cmyr])
- `request_timer` can now be called from `LayoutCtx` ([#1278] by [@Majora320])

### Changed

Expand Down Expand Up @@ -98,6 +99,7 @@ You can find its changes [documented below](#060---2020-06-01).
- Windows: fix crash on resize from incompatible resources ([#1191 by [@raphlinus]])
- GTK: Related dependencies are now optional, facilitating a pure X11 build. ([#1241] by [@finnerale])
- `widget::Image` now computes the layout correctly when unbound in one direction. ([#1189] by [@JAicewizard])
- The scroll bar now shows when the contents of a scrollable area change size. ([#1278] by [@Majora320])

### Visual

Expand Down Expand Up @@ -484,6 +486,7 @@ Last release without a changelog :(
[#1251]: https://github.com/linebender/druid/pull/1251
[#1252]: https://github.com/linebender/druid/pull/1252
[#1255]: https://github.com/linebender/druid/pull/1255
[#1278]: https://github.com/linebender/druid/pull/1278

[Unreleased]: https://github.com/linebender/druid/compare/v0.6.0...master
[0.6.0]: https://github.com/linebender/druid/compare/v0.5.0...v0.6.0
Expand Down
18 changes: 9 additions & 9 deletions druid/src/contexts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,14 +292,6 @@ impl_context_method!(EventCtx<'_, '_>, UpdateCtx<'_, '_>, LifeCycleCtx<'_, '_>,
self.widget_state.request_anim = true;
}

/// Request a timer event.
///
/// The return value is a token, which can be used to associate the
/// request with the event.
pub fn request_timer(&mut self, deadline: Duration) -> TimerToken {
self.state.request_timer(&mut self.widget_state, deadline)
}

/// Indicate that your children have changed.
///
/// Widgets must call this method after adding a new child.
Expand All @@ -317,7 +309,7 @@ impl_context_method!(EventCtx<'_, '_>, UpdateCtx<'_, '_>, LifeCycleCtx<'_, '_>,
}
});

// methods on event, update, and lifecycle
// methods on everyone but paintctx
impl_context_method!(
EventCtx<'_, '_>,
UpdateCtx<'_, '_>,
Expand Down Expand Up @@ -346,6 +338,14 @@ impl_context_method!(
pub fn get_external_handle(&self) -> ExtEventSink {
self.state.ext_handle.clone()
}

/// Request a timer event.
///
/// The return value is a token, which can be used to associate the
/// request with the event.
pub fn request_timer(&mut self, deadline: Duration) -> TimerToken {
self.state.request_timer(&mut self.widget_state, deadline)
}
}
);

Expand Down
7 changes: 7 additions & 0 deletions druid/src/widget/scroll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,20 @@ impl<T: Data, W: Widget<T>> Widget<T> for Scroll<T, W> {
let child_bc = BoxConstraints::new(Size::ZERO, max_bc);
let child_size = self.child.layout(ctx, &child_bc, data, env);
log_size_warnings(child_size);
let old_size = self.scroll_component.content_size;
self.scroll_component.content_size = child_size;
self.child
.set_layout_rect(ctx, data, env, child_size.to_rect());

let self_size = bc.constrain(child_size);
let _ = self.scroll_component.scroll(Vec2::new(0.0, 0.0), self_size);
self.child.set_viewport_offset(self.offset());

if old_size != self.scroll_component.content_size {
self.scroll_component
.reset_scrollbar_fade(|d| ctx.request_timer(d), env);
}

self_size
}

Expand Down