From c1b9f6652517dcbf5ffd83b5db4a624f9a5b0da4 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Mon, 9 Dec 2019 21:59:31 +0100 Subject: Add `Button::height` and `Button::min_height` --- native/CHANGELOG.md | 1 + native/src/widget/button.rs | 25 +++++++++++++++++++++++-- 2 files changed, 24 insertions(+), 2 deletions(-) (limited to 'native') diff --git a/native/CHANGELOG.md b/native/CHANGELOG.md index cdf02c4b..df8852b7 100644 --- a/native/CHANGELOG.md +++ b/native/CHANGELOG.md @@ -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] - `keyboard::ModifiersState` struct which contains the state of the keyboard modifiers. [#108] - `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 - `Image::new` takes an `Into` now instead of an `Into`. [#90] diff --git a/native/src/widget/button.rs b/native/src/widget/button.rs index 3348c58c..67b49dc6 100644 --- a/native/src/widget/button.rs +++ b/native/src/widget/button.rs @@ -33,7 +33,9 @@ pub struct Button<'a, Message, Renderer> { content: Element<'a, Message, Renderer>, on_press: Option, width: Length, + height: Length, min_width: u32, + min_height: u32, padding: u16, background: Option, border_radius: u16, @@ -54,7 +56,9 @@ impl<'a, Message, Renderer> Button<'a, Message, Renderer> { content: content.into(), on_press: None, width: Length::Shrink, + height: Length::Shrink, min_width: 0, + min_height: 0, padding: 0, background: None, border_radius: 0, @@ -69,6 +73,14 @@ impl<'a, Message, Renderer> Button<'a, Message, Renderer> { 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`]. /// /// [`Button`]: struct.Button.html @@ -77,6 +89,14 @@ impl<'a, Message, Renderer> Button<'a, Message, Renderer> { 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`]. /// /// [`Button`]: struct.Button.html @@ -139,7 +159,7 @@ where } fn height(&self) -> Length { - Length::Shrink + self.height } fn layout( @@ -150,8 +170,9 @@ where let padding = f32::from(self.padding); let limits = limits .min_width(self.min_width) + .min_height(self.min_height) .width(self.width) - .height(Length::Shrink) + .height(self.height) .pad(padding); let mut content = self.content.layout(renderer, &limits); -- cgit