Skip to content

Commit

Permalink
Fix #1129 and add request_timer to LayoutCtx (#1278)
Browse files Browse the repository at this point in the history
* Fix #1129 and add request_timer to LayoutCtx

* Update CHANGELOG.md

* Fix formatting
  • Loading branch information
Majora320 authored Oct 5, 2020
1 parent 2961898 commit f476691
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
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

0 comments on commit f476691

Please sign in to comment.