diff options
author | 2024-02-15 01:35:55 +0100 | |
---|---|---|
committer | 2024-02-15 01:35:55 +0100 | |
commit | a73386f68e01943a28f9286f6d5a1bd017e1d7c3 (patch) | |
tree | aa0095d5c246c0fb5cee826d8da42ea8c0d4425b /widget | |
parent | 1150730fc649de5642f9bc07443934120727fc86 (diff) | |
download | iced-a73386f68e01943a28f9286f6d5a1bd017e1d7c3.tar.gz iced-a73386f68e01943a28f9286f6d5a1bd017e1d7c3.tar.bz2 iced-a73386f68e01943a28f9286f6d5a1bd017e1d7c3.zip |
Add `clip` property to `Button`
Diffstat (limited to 'widget')
-rw-r--r-- | widget/src/button.rs | 19 | ||||
-rw-r--r-- | widget/src/row.rs | 2 |
2 files changed, 18 insertions, 3 deletions
diff --git a/widget/src/button.rs b/widget/src/button.rs index d16e8c67..867fbfaf 100644 --- a/widget/src/button.rs +++ b/widget/src/button.rs @@ -61,6 +61,7 @@ where width: Length, height: Length, padding: Padding, + clip: bool, style: Theme::Style, } @@ -82,6 +83,7 @@ where width: size.width.fluid(), height: size.height.fluid(), padding: Padding::new(5.0), + clip: false, style: Theme::Style::default(), } } @@ -126,6 +128,13 @@ where self.style = style.into(); self } + + /// Sets whether the contents of the [`Button`] 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> @@ -227,7 +236,7 @@ where _style: &renderer::Style, layout: Layout<'_>, cursor: mouse::Cursor, - _viewport: &Rectangle, + viewport: &Rectangle, ) { let bounds = layout.bounds(); let content_layout = layout.children().next().unwrap(); @@ -242,6 +251,12 @@ where || tree.state.downcast_ref::<State>(), ); + let viewport = if self.clip { + bounds.intersection(viewport).unwrap_or(*viewport) + } else { + *viewport + }; + self.content.as_widget().draw( &tree.children[0], renderer, @@ -251,7 +266,7 @@ where }, content_layout, cursor, - &bounds, + &viewport, ); } diff --git a/widget/src/row.rs b/widget/src/row.rs index 460b6b0c..735fbbc0 100644 --- a/widget/src/row.rs +++ b/widget/src/row.rs @@ -80,7 +80,7 @@ where self } - /// Sets whether the contents of the [`Column`] should be clipped on + /// Sets whether the contents of the [`Row`] should be clipped on /// overflow. pub fn clip(mut self, clip: bool) -> Self { self.clip = clip; |