diff options
author | 2024-02-15 01:18:00 +0100 | |
---|---|---|
committer | 2024-02-15 01:18:00 +0100 | |
commit | 96775b1e55917df538c729eef90b4680759f2559 (patch) | |
tree | 2afba819157005d8292fb2da264cd232a98b6e07 /widget/src/container.rs | |
parent | 75b19646d3d17b9b44bb495e239cbbc2d139c0e9 (diff) | |
download | iced-96775b1e55917df538c729eef90b4680759f2559.tar.gz iced-96775b1e55917df538c729eef90b4680759f2559.tar.bz2 iced-96775b1e55917df538c729eef90b4680759f2559.zip |
Add `clip` property to `Container`, `Column`, and `Row`
Diffstat (limited to 'widget/src/container.rs')
-rw-r--r-- | widget/src/container.rs | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/widget/src/container.rs b/widget/src/container.rs index 4eb4a5d9..e0174177 100644 --- a/widget/src/container.rs +++ b/widget/src/container.rs @@ -37,6 +37,7 @@ pub struct Container< horizontal_alignment: alignment::Horizontal, vertical_alignment: alignment::Vertical, style: Theme::Style, + clip: bool, content: Element<'a, Message, Theme, Renderer>, } @@ -63,6 +64,7 @@ where horizontal_alignment: alignment::Horizontal::Left, vertical_alignment: alignment::Vertical::Top, style: Default::default(), + clip: false, content, } } @@ -132,6 +134,13 @@ where self.style = style.into(); self } + + /// Sets whether the contents of the [`Container`] should be clipped on + /// overflow. + pub fn clip(mut self, clip: bool) -> Self { + self.clip = clip; + self + } } impl<'a, Message, Theme, Renderer> Widget<Message, Theme, Renderer> @@ -255,7 +264,7 @@ where ) { let style = theme.appearance(&self.style); - if let Some(viewport) = layout.bounds().intersection(viewport) { + if let Some(clipped_viewport) = layout.bounds().intersection(viewport) { draw_background(renderer, &style, layout.bounds()); self.content.as_widget().draw( @@ -269,7 +278,11 @@ where }, layout.children().next().unwrap(), cursor, - &viewport, + if self.clip { + &clipped_viewport + } else { + viewport + }, ); } } |