diff options
author | 2019-12-30 12:14:26 +0100 | |
---|---|---|
committer | 2019-12-30 12:14:26 +0100 | |
commit | 8caa66be2708b1c83e20d905d69902c2567c4692 (patch) | |
tree | ee18296fc3d32f24bca90f97fc6845d97f3e4c21 /examples | |
parent | 89a6b8a9a173e767753ec777fd83c912c1be5ea3 (diff) | |
download | iced-8caa66be2708b1c83e20d905d69902c2567c4692.tar.gz iced-8caa66be2708b1c83e20d905d69902c2567c4692.tar.bz2 iced-8caa66be2708b1c83e20d905d69902c2567c4692.zip |
Add `Renderer::Defaults` and style inheritance
Diffstat (limited to '')
-rw-r--r-- | examples/custom_widget.rs | 3 | ||||
-rw-r--r-- | examples/pokedex.rs | 7 | ||||
-rw-r--r-- | examples/stopwatch.rs | 6 | ||||
-rw-r--r-- | examples/todos.rs | 86 | ||||
-rw-r--r-- | examples/tour.rs | 13 |
5 files changed, 72 insertions, 43 deletions
diff --git a/examples/custom_widget.rs b/examples/custom_widget.rs index cf2f7792..ca562ead 100644 --- a/examples/custom_widget.rs +++ b/examples/custom_widget.rs @@ -13,7 +13,7 @@ mod circle { layout, Background, Color, Element, Hasher, Layout, Length, MouseCursor, Point, Size, Widget, }; - use iced_wgpu::{Primitive, Renderer}; + use iced_wgpu::{Defaults, Primitive, Renderer}; pub struct Circle { radius: u16, @@ -54,6 +54,7 @@ mod circle { fn draw( &self, _renderer: &mut Renderer, + _defaults: &Defaults, layout: Layout<'_>, _cursor_position: Point, ) -> (Primitive, MouseCursor) { diff --git a/examples/pokedex.rs b/examples/pokedex.rs index 0dcf6981..35d38251 100644 --- a/examples/pokedex.rs +++ b/examples/pokedex.rs @@ -1,6 +1,6 @@ use iced::{ - button, image, Align, Application, Button, Color, Column, Command, - Container, Element, Image, Length, Row, Settings, Text, + button, image, Align, Application, Button, Column, Command, Container, + Element, Image, Length, Row, Settings, Text, }; pub fn main() { @@ -219,7 +219,7 @@ impl From<surf::Exception> for Error { } 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)) .padding(10) .style(style::Button::Primary) } @@ -239,6 +239,7 @@ mod style { })), border_radius: 12, shadow_offset: 1.0, + text_color: Color::WHITE, } } } diff --git a/examples/stopwatch.rs b/examples/stopwatch.rs index 0e0cdba5..99746609 100644 --- a/examples/stopwatch.rs +++ b/examples/stopwatch.rs @@ -1,6 +1,6 @@ use iced::{ - button, Align, Application, Button, Color, Column, Command, Container, - Element, HorizontalAlignment, Length, Row, Settings, Subscription, Text, + button, Align, Application, Button, Column, Command, Container, Element, + HorizontalAlignment, Length, Row, Settings, Subscription, Text, }; use std::time::{Duration, Instant}; @@ -102,7 +102,6 @@ impl Application for Stopwatch { Button::new( state, Text::new(label) - .color(Color::WHITE) .horizontal_alignment(HorizontalAlignment::Center), ) .min_width(80) @@ -199,6 +198,7 @@ mod style { })), border_radius: 12, shadow_offset: 1.0, + text_color: Color::WHITE, } } } diff --git a/examples/todos.rs b/examples/todos.rs index 00edd7fb..ca20183f 100644 --- a/examples/todos.rs +++ b/examples/todos.rs @@ -1,7 +1,7 @@ use iced::{ button, scrollable, text_input, Align, Application, Button, Checkbox, - Color, Column, Command, Container, Element, Font, HorizontalAlignment, - Length, Row, Scrollable, Settings, Text, TextInput, + Column, Command, Container, Element, Font, HorizontalAlignment, Length, + Row, Scrollable, Settings, Text, TextInput, }; use serde::{Deserialize, Serialize}; @@ -291,13 +291,10 @@ impl Task { .align_items(Align::Center) .push(checkbox) .push( - Button::new( - edit_button, - edit_icon().color([0.5, 0.5, 0.5]), - ) - .on_press(TaskMessage::Edit) - .padding(10) - .style(style::Button::NoBackground), + Button::new(edit_button, edit_icon()) + .on_press(TaskMessage::Edit) + .padding(10) + .style(style::Button::Icon), ) .into() } @@ -321,14 +318,9 @@ impl Task { .push( Button::new( delete_button, - Row::new() - .spacing(10) - .push(delete_icon().color(Color::WHITE)) - .push( - Text::new("Delete") - .width(Length::Shrink) - .color(Color::WHITE), - ), + Row::new().spacing(10).push(delete_icon()).push( + Text::new("Delete").width(Length::Shrink), + ), ) .on_press(TaskMessage::Delete) .padding(10) @@ -359,12 +351,10 @@ impl Controls { let filter_button = |state, label, filter, current_filter| { let label = Text::new(label).size(16).width(Length::Shrink); - let button = if filter == current_filter { - Button::new(state, label.color(Color::WHITE)) - .style(style::Button::FilterSelected) - } else { - Button::new(state, label).style(style::Button::NoBackground) - }; + let button = + Button::new(state, label).style(style::Button::Filter { + selected: filter == current_filter, + }); button.on_press(Message::FilterChanged(filter)).padding(8) }; @@ -564,25 +554,38 @@ mod style { use iced::{button, Background, Color}; pub enum Button { - FilterSelected, - NoBackground, + Filter { selected: bool }, + Icon, Destructive, } impl button::StyleSheet for Button { fn active(&self) -> button::Style { match self { - Button::FilterSelected => button::Style { - background: Some(Background::Color(Color::from_rgb( - 0.2, 0.2, 0.7, - ))), - border_radius: 10, - shadow_offset: 0.0, - }, - Button::NoBackground => button::Style { + Button::Filter { selected } => { + if *selected { + button::Style { + background: Some(Background::Color( + Color::from_rgb(0.2, 0.2, 0.7), + )), + border_radius: 10, + shadow_offset: 0.0, + text_color: Color::WHITE, + } + } else { + button::Style { + background: None, + border_radius: 0, + shadow_offset: 0.0, + text_color: Color::BLACK, + } + } + } + Button::Icon => button::Style { background: None, border_radius: 0, shadow_offset: 0.0, + text_color: Color::from_rgb(0.5, 0.5, 0.5), }, Button::Destructive => button::Style { background: Some(Background::Color(Color::from_rgb( @@ -590,7 +593,24 @@ mod style { ))), border_radius: 5, shadow_offset: 1.0, + text_color: Color::WHITE, + }, + } + } + + fn hovered(&self) -> button::Style { + let active = self.active(); + + button::Style { + text_color: match self { + Button::Icon => Color::from_rgb(0.2, 0.2, 0.7), + Button::Filter { selected } if !selected => { + Color::from_rgb(0.2, 0.2, 0.7) + } + _ => active.text_color, }, + shadow_offset: active.shadow_offset + 1.0, + ..active } } } diff --git a/examples/tour.rs b/examples/tour.rs index 402bf1c4..2429ca4f 100644 --- a/examples/tour.rs +++ b/examples/tour.rs @@ -694,9 +694,7 @@ fn button<'a, Message>( ) -> Button<'a, Message> { Button::new( state, - Text::new(label) - .color(Color::WHITE) - .horizontal_alignment(HorizontalAlignment::Center), + Text::new(label).horizontal_alignment(HorizontalAlignment::Center), ) .padding(12) .min_width(100) @@ -761,6 +759,15 @@ mod style { })), border_radius: 12, shadow_offset: 1.0, + text_color: Color::from_rgb8(0xEE, 0xEE, 0xEE), + } + } + + fn hovered(&self) -> button::Style { + button::Style { + text_color: Color::WHITE, + shadow_offset: 2.0, + ..self.active() } } } |