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

Add scroll() method in WidgetExt #1600

Merged
merged 2 commits into from
Feb 18, 2021
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
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