Make Button sizing strategy adaptive

This commit is contained in:
Héctor Ramón Jiménez 2024-01-11 06:12:19 +01:00
parent fa53d9adbb
commit 03c901d49b
No known key found for this signature in database
GPG key ID: 7CC46565708259A7
3 changed files with 20 additions and 13 deletions

View file

@ -71,11 +71,14 @@ where
{
/// Creates a new [`Button`] with the given content.
pub fn new(content: impl Into<Element<'a, Message, Renderer>>) -> Self {
let content = content.into();
let size = content.as_widget().size_hint();
Button {
content: content.into(),
content,
on_press: None,
width: Length::Shrink,
height: Length::Shrink,
width: size.width.fluid(),
height: size.height.fluid(),
padding: Padding::new(5.0),
style: <Renderer::Theme as StyleSheet>::Style::default(),
}

View file

@ -52,16 +52,8 @@ where
Container {
id: None,
padding: Padding::ZERO,
width: if size.width.is_fill() {
Length::Fill
} else {
Length::Shrink
},
height: if size.height.is_fill() {
Length::Fill
} else {
Length::Shrink
},
width: size.width.fluid(),
height: size.height.fluid(),
max_width: f32::INFINITY,
max_height: f32::INFINITY,
horizontal_alignment: alignment::Horizontal::Left,