Differentiate secondary color from primary

This commit is contained in:
Héctor Ramón Jiménez 2025-08-06 19:37:14 +02:00
parent af3125842d
commit 53c059bf88
No known key found for this signature in database
GPG key ID: 7CC46565708259A7
26 changed files with 70 additions and 45 deletions

View file

@ -4,7 +4,7 @@ use iced::widget::{
pick_list, progress_bar, row, scrollable, slider, text, text_input,
toggler, vertical_rule, vertical_space,
};
use iced::{Center, Element, Fill, Subscription, Theme};
use iced::{Center, Element, Fill, Shrink, Subscription, Theme};
pub fn main() -> iced::Result {
iced::application(Styling::default, Styling::update, Styling::view)
@ -78,16 +78,37 @@ impl Styling {
.padding(10)
.size(20);
let styled_button = |label| {
button(text(label).width(Fill).center())
.padding(10)
.on_press(Message::ButtonPressed)
};
let buttons = {
let styles = [
("Primary", button::primary as fn(&Theme, _) -> _),
("Secondary", button::secondary),
("Success", button::success),
("Warning", button::warning),
("Danger", button::danger),
];
let primary = styled_button("Primary");
let success = styled_button("Success").style(button::success);
let warning = styled_button("Warning").style(button::warning);
let danger = styled_button("Danger").style(button::danger);
let styled_button =
|label| button(text(label).width(Fill).center()).padding(10);
column![
row(styles.into_iter().map(|(name, style)| styled_button(
name
)
.on_press(Message::ButtonPressed)
.style(style)
.into()))
.spacing(10)
.align_y(Center),
row(styles.into_iter().map(|(name, style)| styled_button(
name
)
.style(style)
.into()))
.spacing(10)
.align_y(Center),
]
.spacing(10)
};
let slider =
|| slider(0.0..=100.0, self.slider_value, Message::SliderChanged);
@ -100,16 +121,21 @@ impl Styling {
"You did it!"
])
.width(Fill)
.height(100);
.height(Fill);
let checkbox = checkbox("Check me!", self.checkbox_value)
let check = checkbox("Check me!", self.checkbox_value)
.on_toggle(Message::CheckboxToggled);
let toggler = toggler(self.toggler_value)
let check_disabled = checkbox("Disabled", self.checkbox_value);
let toggle = toggler(self.toggler_value)
.label("Toggle me!")
.on_toggle(Message::TogglerToggled)
.spacing(10);
let disabled_toggle =
toggler(self.toggler_value).label("Disabled").spacing(10);
let card = {
container(
column![
@ -128,18 +154,17 @@ impl Styling {
choose_theme,
horizontal_rule(1),
text_input,
row![primary, success, warning, danger]
.spacing(10)
.align_y(Center),
buttons,
slider(),
progress_bar(),
row![
scroll_me,
row![vertical_rule(1), column![checkbox, toggler].spacing(20)]
.spacing(20)
vertical_rule(1),
column![check, check_disabled, toggle, disabled_toggle]
.spacing(10)
]
.spacing(10)
.height(100)
.height(Shrink)
.align_y(Center),
card
]