diff --git a/CHANGELOG.md b/CHANGELOG.md index fe266f6cd6..894e9c2cdc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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]) @@ -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 diff --git a/druid/examples/scroll.rs b/druid/examples/scroll.rs index cd6d932962..0e98e31b39 100644 --- a/druid/examples/scroll.rs +++ b/druid/examples/scroll.rs @@ -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()) @@ -35,7 +35,7 @@ fn build_widget() -> impl Widget { 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. diff --git a/druid/src/widget/widget_ext.rs b/druid/src/widget/widget_ext.rs index 4aca8bc8bc..ff33c5318e 100644 --- a/druid/src/widget/widget_ext.rs +++ b/druid/src/widget/widget_ext.rs @@ -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, }; @@ -262,6 +263,13 @@ pub trait WidgetExt: Widget + Sized + 'static { fn boxed(self) -> Box> { Box::new(self) } + + /// Wrap this widget in a [`Scroll`] widget. + /// + /// [`Scroll`]: widget/struct.Scroll.html + fn scroll(self) -> Scroll { + Scroll::new(self) + } } impl + 'static> WidgetExt for W {}