Add Renderer::Defaults and style inheritance
This commit is contained in:
parent
89a6b8a9a1
commit
8caa66be27
32 changed files with 224 additions and 150 deletions
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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,8 +593,25 @@ 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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue