Add Button::height and Button::min_height

This commit is contained in:
Héctor Ramón Jiménez 2019-12-09 21:59:31 +01:00
parent f942fc3b68
commit c1b9f66525
2 changed files with 24 additions and 2 deletions

View File

@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `Ctrl+Left` and `Ctrl+Right` cursor word jump for `TextInput`. [#108] - `Ctrl+Left` and `Ctrl+Right` cursor word jump for `TextInput`. [#108]
- `keyboard::ModifiersState` struct which contains the state of the keyboard modifiers. [#108] - `keyboard::ModifiersState` struct which contains the state of the keyboard modifiers. [#108]
- `TextInput::password` method to enable secure password input mode. [#113] - `TextInput::password` method to enable secure password input mode. [#113]
- `Button::height` and `Button::min_height` methods to control the height of a button.
### Changed ### Changed
- `Image::new` takes an `Into<image::Handle>` now instead of an `Into<String>`. [#90] - `Image::new` takes an `Into<image::Handle>` now instead of an `Into<String>`. [#90]

View File

@ -33,7 +33,9 @@ pub struct Button<'a, Message, Renderer> {
content: Element<'a, Message, Renderer>, content: Element<'a, Message, Renderer>,
on_press: Option<Message>, on_press: Option<Message>,
width: Length, width: Length,
height: Length,
min_width: u32, min_width: u32,
min_height: u32,
padding: u16, padding: u16,
background: Option<Background>, background: Option<Background>,
border_radius: u16, border_radius: u16,
@ -54,7 +56,9 @@ impl<'a, Message, Renderer> Button<'a, Message, Renderer> {
content: content.into(), content: content.into(),
on_press: None, on_press: None,
width: Length::Shrink, width: Length::Shrink,
height: Length::Shrink,
min_width: 0, min_width: 0,
min_height: 0,
padding: 0, padding: 0,
background: None, background: None,
border_radius: 0, border_radius: 0,
@ -69,6 +73,14 @@ impl<'a, Message, Renderer> Button<'a, Message, Renderer> {
self self
} }
/// Sets the height of the [`Button`].
///
/// [`Button`]: struct.Button.html
pub fn height(mut self, height: Length) -> Self {
self.height = height;
self
}
/// Sets the minimum width of the [`Button`]. /// Sets the minimum width of the [`Button`].
/// ///
/// [`Button`]: struct.Button.html /// [`Button`]: struct.Button.html
@ -77,6 +89,14 @@ impl<'a, Message, Renderer> Button<'a, Message, Renderer> {
self self
} }
/// Sets the minimum height of the [`Button`].
///
/// [`Button`]: struct.Button.html
pub fn min_height(mut self, min_height: u32) -> Self {
self.min_height = min_height;
self
}
/// Sets the padding of the [`Button`]. /// Sets the padding of the [`Button`].
/// ///
/// [`Button`]: struct.Button.html /// [`Button`]: struct.Button.html
@ -139,7 +159,7 @@ where
} }
fn height(&self) -> Length { fn height(&self) -> Length {
Length::Shrink self.height
} }
fn layout( fn layout(
@ -150,8 +170,9 @@ where
let padding = f32::from(self.padding); let padding = f32::from(self.padding);
let limits = limits let limits = limits
.min_width(self.min_width) .min_width(self.min_width)
.min_height(self.min_height)
.width(self.width) .width(self.width)
.height(Length::Shrink) .height(self.height)
.pad(padding); .pad(padding);
let mut content = self.content.layout(renderer, &limits); let mut content = self.content.layout(renderer, &limits);