Skip to content

Commit

Permalink
Add scroll() method in WidgetExt (#1600)
Browse files Browse the repository at this point in the history
* Add .scroll() method in WidgetExt

* Update Changelog
  • Loading branch information
totsteps authored Feb 18, 2021
1 parent 131b0a6 commit 33b6048
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ You can find its changes [documented below](#070---2021-01-01).
### Highlights

### Added
- Add `scroll()` method in WidgetExt ([#1600] by [@totsteps])
- `write!` for `RichTextBuilder` ([#1596] by [@Maan2003])
- Sub windows: Allow opening windows that share state with arbitrary parts of the widget hierarchy ([#1254] by [@rjwittams])
- WindowCloseRequested/WindowDisconnected event when a window is closing ([#1254] by [@rjwittams])
Expand Down Expand Up @@ -619,6 +620,7 @@ Last release without a changelog :(
[#1562]: https://github.com/linebender/druid/pull/1562
[#1592]: https://github.com/linebender/druid/pull/1592
[#1596]: https://github.com/linebender/druid/pull/1596
[#1600]: https://github.com/linebender/druid/pull/1600

[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
6 changes: 3 additions & 3 deletions druid/examples/scroll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
use druid::kurbo::Circle;
use druid::piet::RadialGradient;
use druid::widget::prelude::*;
use druid::widget::{Flex, Padding, Scroll};
use druid::{AppLauncher, Data, Insets, LocalizedString, Rect, WindowDesc};
use druid::widget::{Flex, Padding};
use druid::{AppLauncher, Data, Insets, LocalizedString, Rect, WidgetExt, WindowDesc};

pub fn main() {
let window = WindowDesc::new(build_widget())
Expand All @@ -35,7 +35,7 @@ fn build_widget() -> impl Widget<u32> {
for i in 0..30 {
col.add_child(Padding::new(3.0, OverPainter(i)));
}
Scroll::new(col)
col.scroll()
}

/// A widget that paints outside of its bounds.
Expand Down
8 changes: 8 additions & 0 deletions druid/src/widget/widget_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use super::{
Added, Align, BackgroundBrush, Click, Container, Controller, ControllerHost, EnvScope,
IdentityWrapper, LensWrap, Padding, Parse, SizedBox, WidgetId,
};
use crate::widget::Scroll;
use crate::{
Color, Data, Env, EventCtx, Insets, KeyOrValue, Lens, LifeCycleCtx, UnitPoint, Widget,
};
Expand Down Expand Up @@ -262,6 +263,13 @@ pub trait WidgetExt<T: Data>: Widget<T> + Sized + 'static {
fn boxed(self) -> Box<dyn Widget<T>> {
Box::new(self)
}

/// Wrap this widget in a [`Scroll`] widget.
///
/// [`Scroll`]: widget/struct.Scroll.html
fn scroll(self) -> Scroll<T, Self> {
Scroll::new(self)
}
}

impl<T: Data, W: Widget<T> + 'static> WidgetExt<T> for W {}
Expand Down

0 comments on commit 33b6048

Please sign in to comment.