Simplify theming for Button widget

This commit is contained in:
Héctor Ramón Jiménez 2024-03-04 20:42:37 +01:00
parent db92e1c942
commit f4a4845ddb
No known key found for this signature in database
GPG key ID: 7CC46565708259A7
16 changed files with 306 additions and 412 deletions

View file

@ -290,7 +290,7 @@ fn action<'a, Message: Clone + 'a>(
.style(theme::Container::Box)
.into()
} else {
action.style(theme::Button::Secondary).into()
action.style(button::secondary).into()
}
}

View file

@ -6,7 +6,6 @@ use grid::Grid;
use preset::Preset;
use iced::executor;
use iced::theme::{self, Theme};
use iced::time;
use iced::widget::{
button, checkbox, column, container, pick_list, row, slider, text,
@ -14,6 +13,7 @@ use iced::widget::{
use iced::window;
use iced::{
Alignment, Application, Command, Element, Length, Settings, Subscription,
Theme,
};
use std::time::Duration;
@ -171,7 +171,7 @@ fn view_controls<'a>(
.on_press(Message::TogglePlayback),
button("Next")
.on_press(Message::Next)
.style(theme::Button::Secondary),
.style(button::secondary),
]
.spacing(10);
@ -195,7 +195,7 @@ fn view_controls<'a>(
.text_size(16),
button("Clear")
.on_press(Message::Clear)
.style(theme::Button::Destructive),
.style(button::destructive),
]
.padding(10)
.spacing(20)

View file

@ -1,4 +1,3 @@
use iced::theme;
use iced::widget::{
button, column, horizontal_space, lazy, pick_list, row, scrollable, text,
text_input,
@ -181,7 +180,7 @@ impl Sandbox for App {
column(items.into_iter().map(|item| {
let button = button("Delete")
.on_press(Message::DeleteItem(item.clone()))
.style(theme::Button::Destructive);
.style(button::destructive);
row![
text(&item.name).color(item.color),

View file

@ -1,13 +1,13 @@
use iced::alignment::{self, Alignment};
use iced::executor;
use iced::keyboard;
use iced::theme::{self, Theme};
use iced::widget::pane_grid::{self, PaneGrid};
use iced::widget::{
button, column, container, responsive, row, scrollable, text,
};
use iced::{
Application, Color, Command, Element, Length, Settings, Size, Subscription,
Theme,
};
pub fn main() -> iced::Result {
@ -287,10 +287,7 @@ fn view_content<'a>(
)
]
.push_maybe(if total_panes > 1 && !is_pinned {
Some(
button("Close", Message::Close(pane))
.style(theme::Button::Destructive),
)
Some(button("Close", Message::Close(pane)).style(button::destructive))
} else {
None
})
@ -327,7 +324,7 @@ fn view_controls<'a>(
Some(
button(text(content).size(14))
.style(theme::Button::Secondary)
.style(button::secondary)
.padding(3)
.on_press(message),
)
@ -336,7 +333,7 @@ fn view_controls<'a>(
});
let close = button(text("Close").size(14))
.style(theme::Button::Destructive)
.style(button::destructive)
.padding(3)
.on_press_maybe(if total_panes > 1 && !is_pinned {
Some(Message::Close(pane))

View file

@ -216,9 +216,9 @@ impl Application for Example {
)
} else {
button(centered_text("Saving..."))
.style(theme::Button::Secondary)
.style(button::secondary)
}
.style(theme::Button::Secondary)
.style(button::secondary)
.padding([10, 20, 10, 20])
.width(Length::Fill)
]
@ -227,7 +227,7 @@ impl Application for Example {
crop_controls,
button(centered_text("Crop"))
.on_press(Message::Crop)
.style(theme::Button::Destructive)
.style(button::destructive)
.padding([10, 20, 10, 20])
.width(Length::Fill),
]

View file

@ -1,11 +1,11 @@
use iced::alignment;
use iced::executor;
use iced::keyboard;
use iced::theme::{self, Theme};
use iced::time;
use iced::widget::{button, column, container, row, text};
use iced::{
Alignment, Application, Command, Element, Length, Settings, Subscription,
Theme,
};
use std::time::{Duration, Instant};
@ -136,7 +136,7 @@ impl Application for Stopwatch {
};
let reset_button = button("Reset")
.style(theme::Button::Destructive)
.style(button::destructive)
.on_press(Message::Reset);
let controls = row![toggle_button, reset_button].spacing(20);

View file

@ -1,14 +1,14 @@
use iced::alignment::{self, Alignment};
use iced::font::{self, Font};
use iced::keyboard;
use iced::theme::{self, Theme};
use iced::widget::{
self, button, checkbox, column, container, keyed_column, row, scrollable,
text, text_input, Text,
};
use iced::window;
use iced::{Application, Element};
use iced::{Command, Length, Settings, Size, Subscription};
use iced::{
Application, Command, Element, Length, Settings, Size, Subscription, Theme,
};
use once_cell::sync::Lazy;
use serde::{Deserialize, Serialize};
@ -362,7 +362,7 @@ impl Task {
button(edit_icon())
.on_press(TaskMessage::Edit)
.padding(10)
.style(theme::Button::Text),
.style(button::text),
]
.spacing(20)
.align_items(Alignment::Center)
@ -385,7 +385,7 @@ impl Task {
)
.on_press(TaskMessage::Delete)
.padding(10)
.style(theme::Button::Destructive)
.style(button::destructive)
]
.spacing(20)
.align_items(Alignment::Center)
@ -402,9 +402,9 @@ fn view_controls(tasks: &[Task], current_filter: Filter) -> Element<Message> {
let label = text(label);
let button = button(label).style(if filter == current_filter {
theme::Button::Primary
button::primary
} else {
theme::Button::Text
button::text
});
button.on_press(Message::FilterChanged(filter)).padding(8)

View file

@ -1,7 +1,6 @@
use iced::alignment::{self, Alignment};
use iced::theme;
use iced::widget::{
checkbox, column, container, horizontal_space, image, radio, row,
button, checkbox, column, container, horizontal_space, image, radio, row,
scrollable, slider, text, text_input, toggler, vertical_space,
};
use iced::widget::{Button, Column, Container, Slider};
@ -56,18 +55,17 @@ impl Sandbox for Tour {
fn view(&self) -> Element<Message> {
let Tour { steps, .. } = self;
let controls = row![]
.push_maybe(steps.has_previous().then(|| {
button("Back")
.on_press(Message::BackPressed)
.style(theme::Button::Secondary)
}))
.push(horizontal_space())
.push_maybe(
steps
.can_continue()
.then(|| button("Next").on_press(Message::NextPressed)),
);
let controls =
row![]
.push_maybe(steps.has_previous().then(|| {
padded_button("Back")
.on_press(Message::BackPressed)
.style(button::secondary)
}))
.push(horizontal_space())
.push_maybe(steps.can_continue().then(|| {
padded_button("Next").on_press(Message::NextPressed)
}));
let content: Element<_> = column![
steps.view(self.debug).map(Message::StepMessage),
@ -676,8 +674,8 @@ fn ferris<'a>(
.center_x()
}
fn button<'a, Message: Clone>(label: &str) -> Button<'a, Message> {
iced::widget::button(text(label)).padding([12, 24])
fn padded_button<'a, Message: Clone>(label: &str) -> Button<'a, Message> {
button(text(label)).padding([12, 24])
}
fn color_slider<'a>(