Make Button::background generic

This commit is contained in:
Héctor Ramón Jiménez 2019-12-05 01:57:35 +01:00
parent f87ddf1056
commit e92ea48e88
7 changed files with 21 additions and 20 deletions

View file

@ -1,6 +1,6 @@
use iced::{ use iced::{
button, image, Align, Application, Button, Color, Column, button, image, Align, Application, Button, Color, Column, Command,
Command, Container, Element, Image, Length, Row, Settings, Text, Container, Element, Image, Length, Row, Settings, Text,
}; };
pub fn main() { pub fn main() {
@ -225,7 +225,7 @@ impl From<reqwest::Error> for Error {
fn button<'a>(state: &'a mut button::State, text: &str) -> Button<'a, Message> { fn button<'a>(state: &'a mut button::State, text: &str) -> Button<'a, Message> {
Button::new(state, Text::new(text).color(Color::WHITE)) Button::new(state, Text::new(text).color(Color::WHITE))
.background(Color::from_rgb(0.11, 0.42, 0.87).into()) .background(Color::from_rgb(0.11, 0.42, 0.87))
.border_radius(10) .border_radius(10)
.padding(10) .padding(10)
} }

View file

@ -1,7 +1,7 @@
use iced::{ use iced::{
button, scrollable, text_input, Align, Application, Button, button, scrollable, text_input, Align, Application, Button, Checkbox,
Checkbox, Color, Column, Command, Container, Element, Font, Color, Column, Command, Container, Element, Font, HorizontalAlignment,
HorizontalAlignment, Length, Row, Scrollable, Settings, Text, TextInput, Length, Row, Scrollable, Settings, Text, TextInput,
}; };
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
@ -332,7 +332,7 @@ impl Task {
.on_press(TaskMessage::Delete) .on_press(TaskMessage::Delete)
.padding(10) .padding(10)
.border_radius(5) .border_radius(5)
.background(Color::from_rgb(0.8, 0.2, 0.2).into()), .background(Color::from_rgb(0.8, 0.2, 0.2)),
) )
.into() .into()
} }
@ -361,7 +361,7 @@ impl Controls {
let label = Text::new(label).size(16).width(Length::Shrink); let label = Text::new(label).size(16).width(Length::Shrink);
let button = if filter == current_filter { let button = if filter == current_filter {
Button::new(state, label.color(Color::WHITE)) Button::new(state, label.color(Color::WHITE))
.background(Color::from_rgb(0.2, 0.2, 0.7).into()) .background(Color::from_rgb(0.2, 0.2, 0.7))
} else { } else {
Button::new(state, label) Button::new(state, label)
}; };

View file

@ -1,7 +1,7 @@
use iced::{ use iced::{
button, scrollable, slider, text_input, Button, Checkbox, button, scrollable, slider, text_input, Button, Checkbox, Color, Column,
Color, Column, Container, Element, HorizontalAlignment, Image, Length, Container, Element, HorizontalAlignment, Image, Length, Radio, Row,
Radio, Row, Sandbox, Scrollable, Settings, Slider, Text, TextInput, Sandbox, Scrollable, Settings, Slider, Text, TextInput,
}; };
pub fn main() { pub fn main() {
@ -684,17 +684,14 @@ fn primary_button<'a, Message>(
state: &'a mut button::State, state: &'a mut button::State,
label: &str, label: &str,
) -> Button<'a, Message> { ) -> Button<'a, Message> {
button(state, label) button(state, label).background(Color::from_rgb(0.11, 0.42, 0.87))
.background(Color::from_rgb(0.11, 0.42, 0.87).into())
} }
fn secondary_button<'a, Message>( fn secondary_button<'a, Message>(
state: &'a mut button::State, state: &'a mut button::State,
label: &str, label: &str,
) -> Button<'a, Message> { ) -> Button<'a, Message> {
button(state, label) button(state, label).background(Color::from_rgb(0.4, 0.4, 0.4))
.background(Color::from_rgb(0.4, 0.4, 0.4).into())
} }
#[derive(Debug, Clone, Copy, PartialEq, Eq)] #[derive(Debug, Clone, Copy, PartialEq, Eq)]

View file

@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### 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]
- `Button::background` takes an `Into<Background>` now instead of a `Background`.
### Fixed ### Fixed
- `Image` widget not keeping aspect ratio consistently. [#90] - `Image` widget not keeping aspect ratio consistently. [#90]

View file

@ -89,8 +89,8 @@ impl<'a, Message, Renderer> Button<'a, Message, Renderer> {
/// ///
/// [`Button`]: struct.Button.html /// [`Button`]: struct.Button.html
/// [`Background`]: ../../struct.Background.html /// [`Background`]: ../../struct.Background.html
pub fn background(mut self, background: Background) -> Self { pub fn background<T: Into<Background>>(mut self, background: T) -> Self {
self.background = Some(background); self.background = Some(background.into());
self self
} }

View file

@ -5,6 +5,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [Unreleased] ## [Unreleased]
### Changed
- `Button::background` takes an `Into<Background>` now instead of a `Background`.
### Fixed ### Fixed
- Render not being scheduled after `Command` futures finishing. - Render not being scheduled after `Command` futures finishing.

View file

@ -81,8 +81,8 @@ impl<'a, Message> Button<'a, Message> {
/// ///
/// [`Button`]: struct.Button.html /// [`Button`]: struct.Button.html
/// [`Background`]: ../../struct.Background.html /// [`Background`]: ../../struct.Background.html
pub fn background(mut self, background: Background) -> Self { pub fn background<T: Into<Background>>(mut self, background: T) -> Self {
self.background = Some(background); self.background = Some(background.into());
self self
} }