Simplify theming for TextInput widget

This commit is contained in:
Héctor Ramón Jiménez 2024-03-05 15:53:59 +01:00
parent d681aaa57e
commit 704ec9cb5c
No known key found for this signature in database
GPG key ID: 7CC46565708259A7
9 changed files with 855 additions and 1056 deletions

View file

@ -32,7 +32,7 @@ pub struct ComboBox<
Theme = crate::Theme,
Renderer = crate::Renderer,
> where
Theme: text_input::StyleSheet + menu::StyleSheet,
Theme: text_input::Style + menu::StyleSheet,
Renderer: text::Renderer,
{
state: &'a State<T>,
@ -51,7 +51,7 @@ pub struct ComboBox<
impl<'a, T, Message, Theme, Renderer> ComboBox<'a, T, Message, Theme, Renderer>
where
T: std::fmt::Display + Clone,
Theme: text_input::StyleSheet + menu::StyleSheet,
Theme: text_input::Style + menu::StyleSheet,
Renderer: text::Renderer,
{
/// Creates a new [`ComboBox`] with the given list of options, a placeholder,
@ -121,20 +121,17 @@ where
// TODO: Define its own `StyleSheet` trait
pub fn style<S>(mut self, style: S) -> Self
where
S: Into<<Theme as text_input::StyleSheet>::Style>
+ Into<<Theme as menu::StyleSheet>::Style>
+ Clone,
S: Into<<Theme as menu::StyleSheet>::Style>,
{
self.menu_style = style.clone().into();
self.text_input = self.text_input.style(style);
self.menu_style = style.into();
self
}
/// Sets the style of the [`TextInput`] of the [`ComboBox`].
pub fn text_input_style<S>(mut self, style: S) -> Self
where
S: Into<<Theme as text_input::StyleSheet>::Style> + Clone,
{
pub fn text_input_style(
mut self,
style: fn(&Theme, text_input::Status) -> text_input::Appearance,
) -> Self {
self.text_input = self.text_input.style(style);
self
}
@ -300,8 +297,8 @@ where
T: Display + Clone + 'static,
Message: Clone,
Theme: container::Style
+ text_input::StyleSheet
+ scrollable::Tradition
+ text_input::Style
+ scrollable::Style
+ menu::StyleSheet,
Renderer: text::Renderer,
{
@ -720,8 +717,8 @@ where
T: Display + Clone + 'static,
Message: Clone + 'a,
Theme: container::Style
+ text_input::StyleSheet
+ scrollable::Tradition
+ text_input::Style
+ scrollable::Style
+ menu::StyleSheet
+ 'a,
Renderer: text::Renderer + 'a,

View file

@ -104,7 +104,7 @@ pub fn scrollable<'a, Message, Theme, Renderer>(
content: impl Into<Element<'a, Message, Theme, Renderer>>,
) -> Scrollable<'a, Message, Theme, Renderer>
where
Theme: scrollable::Tradition,
Theme: scrollable::Style,
Renderer: core::Renderer,
{
Scrollable::new(content)
@ -209,7 +209,7 @@ pub fn text_input<'a, Message, Theme, Renderer>(
) -> TextInput<'a, Message, Theme, Renderer>
where
Message: Clone,
Theme: text_input::StyleSheet,
Theme: text_input::Style,
Renderer: core::text::Renderer,
{
TextInput::new(placeholder, value)
@ -276,7 +276,7 @@ where
Message: Clone,
Renderer: core::text::Renderer,
Theme: pick_list::StyleSheet
+ scrollable::Tradition
+ scrollable::Style
+ overlay::menu::StyleSheet
+ container::Style,
<Theme as overlay::menu::StyleSheet>::Style:
@ -296,7 +296,7 @@ pub fn combo_box<'a, T, Message, Theme, Renderer>(
) -> ComboBox<'a, T, Message, Theme, Renderer>
where
T: std::fmt::Display + Clone,
Theme: text_input::StyleSheet + overlay::menu::StyleSheet,
Theme: text_input::Style + overlay::menu::StyleSheet,
Renderer: core::text::Renderer,
{
ComboBox::new(state, placeholder, selection, on_selected)

View file

@ -47,7 +47,7 @@ impl<'a, T, Message, Theme, Renderer> Menu<'a, T, Message, Theme, Renderer>
where
T: ToString + Clone,
Message: 'a,
Theme: StyleSheet + container::Style + scrollable::Tradition + 'a,
Theme: StyleSheet + container::Style + scrollable::Style + 'a,
Renderer: text::Renderer + 'a,
{
/// Creates a new [`Menu`] with the given [`State`], a list of options, and
@ -179,7 +179,7 @@ where
impl<'a, Message, Theme, Renderer> Overlay<'a, Message, Theme, Renderer>
where
Message: 'a,
Theme: StyleSheet + container::Style + scrollable::Tradition + 'a,
Theme: StyleSheet + container::Style + scrollable::Style + 'a,
Renderer: text::Renderer + 'a,
{
pub fn new<T>(

View file

@ -61,10 +61,7 @@ where
L: Borrow<[T]> + 'a,
V: Borrow<T> + 'a,
Message: Clone,
Theme: StyleSheet
+ scrollable::Tradition
+ menu::StyleSheet
+ container::Style,
Theme: StyleSheet + scrollable::Style + menu::StyleSheet + container::Style,
<Theme as menu::StyleSheet>::Style: From<<Theme as StyleSheet>::Style>,
Renderer: text::Renderer,
{
@ -176,10 +173,7 @@ where
L: Borrow<[T]>,
V: Borrow<T>,
Message: Clone + 'a,
Theme: StyleSheet
+ scrollable::Tradition
+ menu::StyleSheet
+ container::Style,
Theme: StyleSheet + scrollable::Style + menu::StyleSheet + container::Style,
<Theme as menu::StyleSheet>::Style: From<<Theme as StyleSheet>::Style>,
Renderer: text::Renderer + 'a,
{
@ -318,7 +312,7 @@ where
V: Borrow<T> + 'a,
Message: Clone + 'a,
Theme: StyleSheet
+ scrollable::Tradition
+ scrollable::Style
+ menu::StyleSheet
+ container::Style
+ 'a,
@ -628,7 +622,7 @@ where
T: Clone + ToString,
Message: 'a,
Theme: StyleSheet
+ scrollable::Tradition
+ scrollable::Style
+ menu::StyleSheet
+ container::Style
+ 'a,

View file

@ -49,7 +49,7 @@ where
content: impl Into<Element<'a, Message, Theme, Renderer>>,
) -> Self
where
Theme: Tradition,
Theme: Style,
{
Self::with_direction(content, Direction::default())
}
@ -60,7 +60,7 @@ where
direction: Direction,
) -> Self
where
Theme: Tradition,
Theme: Style,
{
let content = content.into();
@ -83,7 +83,7 @@ where
direction,
content,
on_scroll: None,
style: Theme::tradition(),
style: Theme::style(),
}
}
@ -1653,14 +1653,14 @@ pub struct Scroller {
pub border: Border,
}
/// The definition of the traditional style of a [`Scrollable`].
pub trait Tradition {
/// Returns the traditional style of a [`Scrollable`].
fn tradition() -> fn(&Self, Status) -> Appearance;
/// The definition of the default style of a [`Scrollable`].
pub trait Style {
/// Returns the default style of a [`Scrollable`].
fn style() -> fn(&Self, Status) -> Appearance;
}
impl Tradition for Theme {
fn tradition() -> fn(&Self, Status) -> Appearance {
impl Style for Theme {
fn style() -> fn(&Self, Status) -> Appearance {
default
}
}

File diff suppressed because it is too large Load diff