diff options
| author | 2024-02-15 01:48:36 +0100 | |
|---|---|---|
| committer | 2024-02-15 01:48:36 +0100 | |
| commit | 5827023ccc3f80012b17dbfe778fbd8b63186c99 (patch) | |
| tree | aa0095d5c246c0fb5cee826d8da42ea8c0d4425b /widget/src/row.rs | |
| parent | 75b19646d3d17b9b44bb495e239cbbc2d139c0e9 (diff) | |
| parent | a73386f68e01943a28f9286f6d5a1bd017e1d7c3 (diff) | |
| download | iced-5827023ccc3f80012b17dbfe778fbd8b63186c99.tar.gz iced-5827023ccc3f80012b17dbfe778fbd8b63186c99.tar.bz2 iced-5827023ccc3f80012b17dbfe778fbd8b63186c99.zip | |
Merge pull request #2252 from iced-rs/feature/clip-property
Add `clip` property to `Container`, `Column`, and `Row`
Diffstat (limited to 'widget/src/row.rs')
| -rw-r--r-- | widget/src/row.rs | 23 | 
1 files changed, 21 insertions, 2 deletions
| diff --git a/widget/src/row.rs b/widget/src/row.rs index 7f8c3354..735fbbc0 100644 --- a/widget/src/row.rs +++ b/widget/src/row.rs @@ -18,6 +18,7 @@ pub struct Row<'a, Message, Theme = crate::Theme, Renderer = crate::Renderer> {      width: Length,      height: Length,      align_items: Alignment, +    clip: bool,      children: Vec<Element<'a, Message, Theme, Renderer>>,  } @@ -33,6 +34,7 @@ where              width: Length::Shrink,              height: Length::Shrink,              align_items: Alignment::Start, +            clip: false,              children: Vec::new(),          }      } @@ -78,6 +80,13 @@ where          self      } +    /// Sets whether the contents of the [`Row`] should be clipped on +    /// overflow. +    pub fn clip(mut self, clip: bool) -> Self { +        self.clip = clip; +        self +    } +      /// Adds an [`Element`] to the [`Row`].      pub fn push(          mut self, @@ -229,7 +238,7 @@ where          cursor: mouse::Cursor,          viewport: &Rectangle,      ) { -        if let Some(viewport) = layout.bounds().intersection(viewport) { +        if let Some(clipped_viewport) = layout.bounds().intersection(viewport) {              for ((child, state), layout) in self                  .children                  .iter() @@ -237,7 +246,17 @@ where                  .zip(layout.children())              {                  child.as_widget().draw( -                    state, renderer, theme, style, layout, cursor, &viewport, +                    state, +                    renderer, +                    theme, +                    style, +                    layout, +                    cursor, +                    if self.clip { +                        &clipped_viewport +                    } else { +                        viewport +                    },                  );              }          } | 
