Add clip property to Button
This commit is contained in:
parent
1150730fc6
commit
a73386f68e
3 changed files with 19 additions and 4 deletions
|
|
@ -47,7 +47,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||||
- Support for generic `Element` in `Tooltip`. [#2228](https://github.com/iced-rs/iced/pull/2228)
|
- Support for generic `Element` in `Tooltip`. [#2228](https://github.com/iced-rs/iced/pull/2228)
|
||||||
- Container and `gap` styling for `Scrollable`. [#2239](https://github.com/iced-rs/iced/pull/2239)
|
- Container and `gap` styling for `Scrollable`. [#2239](https://github.com/iced-rs/iced/pull/2239)
|
||||||
- Use `Borrow` for both `options` and `selected` in PickList. [#2251](https://github.com/iced-rs/iced/pull/2251)
|
- Use `Borrow` for both `options` and `selected` in PickList. [#2251](https://github.com/iced-rs/iced/pull/2251)
|
||||||
- `clip` property for `Container`, `Column`, and `Row`. #[2252](https://github.com/iced-rs/iced/pull/2252)
|
- `clip` property for `Container`, `Column`, `Row`, and `Button`. #[2252](https://github.com/iced-rs/iced/pull/2252)
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
- Enable WebGPU backend in `wgpu` by default instead of WebGL. [#2068](https://github.com/iced-rs/iced/pull/2068)
|
- Enable WebGPU backend in `wgpu` by default instead of WebGL. [#2068](https://github.com/iced-rs/iced/pull/2068)
|
||||||
|
|
|
||||||
|
|
@ -61,6 +61,7 @@ where
|
||||||
width: Length,
|
width: Length,
|
||||||
height: Length,
|
height: Length,
|
||||||
padding: Padding,
|
padding: Padding,
|
||||||
|
clip: bool,
|
||||||
style: Theme::Style,
|
style: Theme::Style,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -82,6 +83,7 @@ where
|
||||||
width: size.width.fluid(),
|
width: size.width.fluid(),
|
||||||
height: size.height.fluid(),
|
height: size.height.fluid(),
|
||||||
padding: Padding::new(5.0),
|
padding: Padding::new(5.0),
|
||||||
|
clip: false,
|
||||||
style: Theme::Style::default(),
|
style: Theme::Style::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -126,6 +128,13 @@ where
|
||||||
self.style = style.into();
|
self.style = style.into();
|
||||||
self
|
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>
|
impl<'a, Message, Theme, Renderer> Widget<Message, Theme, Renderer>
|
||||||
|
|
@ -227,7 +236,7 @@ where
|
||||||
_style: &renderer::Style,
|
_style: &renderer::Style,
|
||||||
layout: Layout<'_>,
|
layout: Layout<'_>,
|
||||||
cursor: mouse::Cursor,
|
cursor: mouse::Cursor,
|
||||||
_viewport: &Rectangle,
|
viewport: &Rectangle,
|
||||||
) {
|
) {
|
||||||
let bounds = layout.bounds();
|
let bounds = layout.bounds();
|
||||||
let content_layout = layout.children().next().unwrap();
|
let content_layout = layout.children().next().unwrap();
|
||||||
|
|
@ -242,6 +251,12 @@ where
|
||||||
|| tree.state.downcast_ref::<State>(),
|
|| tree.state.downcast_ref::<State>(),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
let viewport = if self.clip {
|
||||||
|
bounds.intersection(viewport).unwrap_or(*viewport)
|
||||||
|
} else {
|
||||||
|
*viewport
|
||||||
|
};
|
||||||
|
|
||||||
self.content.as_widget().draw(
|
self.content.as_widget().draw(
|
||||||
&tree.children[0],
|
&tree.children[0],
|
||||||
renderer,
|
renderer,
|
||||||
|
|
@ -251,7 +266,7 @@ where
|
||||||
},
|
},
|
||||||
content_layout,
|
content_layout,
|
||||||
cursor,
|
cursor,
|
||||||
&bounds,
|
&viewport,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -80,7 +80,7 @@ where
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets whether the contents of the [`Column`] should be clipped on
|
/// Sets whether the contents of the [`Row`] should be clipped on
|
||||||
/// overflow.
|
/// overflow.
|
||||||
pub fn clip(mut self, clip: bool) -> Self {
|
pub fn clip(mut self, clip: bool) -> Self {
|
||||||
self.clip = clip;
|
self.clip = clip;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue