Make defaults of composite widgets configurable
This commit is contained in:
parent
f0ae9a0c38
commit
74373cb086
3 changed files with 35 additions and 15 deletions
|
|
@ -64,7 +64,8 @@ where
|
||||||
on_selected: impl Fn(T) -> Message + 'static,
|
on_selected: impl Fn(T) -> Message + 'static,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let text_input = TextInput::new(placeholder, &state.value())
|
let text_input = TextInput::new(placeholder, &state.value())
|
||||||
.on_input(TextInputEvent::TextChanged);
|
.on_input(TextInputEvent::TextChanged)
|
||||||
|
.class(Theme::default_input());
|
||||||
|
|
||||||
let selection = selection.map(T::to_string).unwrap_or_default();
|
let selection = selection.map(T::to_string).unwrap_or_default();
|
||||||
|
|
||||||
|
|
@ -77,7 +78,7 @@ where
|
||||||
on_option_hovered: None,
|
on_option_hovered: None,
|
||||||
on_input: None,
|
on_input: None,
|
||||||
on_close: None,
|
on_close: None,
|
||||||
menu_class: <Theme as menu::Catalog>::default(),
|
menu_class: <Theme as Catalog>::default_menu(),
|
||||||
padding: text_input::DEFAULT_PADDING,
|
padding: text_input::DEFAULT_PADDING,
|
||||||
size: None,
|
size: None,
|
||||||
}
|
}
|
||||||
|
|
@ -752,7 +753,17 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The theme catalog of a [`ComboBox`].
|
/// The theme catalog of a [`ComboBox`].
|
||||||
pub trait Catalog: text_input::Catalog + menu::Catalog {}
|
pub trait Catalog: text_input::Catalog + menu::Catalog {
|
||||||
|
/// The default class for the text input of the [`ComboBox`].
|
||||||
|
fn default_input<'a>() -> <Self as text_input::Catalog>::Class<'a> {
|
||||||
|
<Self as text_input::Catalog>::default()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The default class for the menu of the [`ComboBox`].
|
||||||
|
fn default_menu<'a>() -> <Self as menu::Catalog>::Class<'a> {
|
||||||
|
<Self as menu::Catalog>::default()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Catalog for Theme {}
|
impl Catalog for Theme {}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,4 @@
|
||||||
//! Build and show dropdown menus.
|
//! Build and show dropdown menus.
|
||||||
use crate::container::{self, Container};
|
|
||||||
use crate::core::alignment;
|
use crate::core::alignment;
|
||||||
use crate::core::event::{self, Event};
|
use crate::core::event::{self, Event};
|
||||||
use crate::core::layout::{self, Layout};
|
use crate::core::layout::{self, Layout};
|
||||||
|
|
@ -165,7 +164,7 @@ where
|
||||||
{
|
{
|
||||||
position: Point,
|
position: Point,
|
||||||
state: &'a mut Tree,
|
state: &'a mut Tree,
|
||||||
container: Container<'a, Message, Theme, Renderer>,
|
list: Scrollable<'a, Message, Theme, Renderer>,
|
||||||
width: f32,
|
width: f32,
|
||||||
target_height: f32,
|
target_height: f32,
|
||||||
class: &'a <Theme as Catalog>::Class<'b>,
|
class: &'a <Theme as Catalog>::Class<'b>,
|
||||||
|
|
@ -201,7 +200,7 @@ where
|
||||||
class,
|
class,
|
||||||
} = menu;
|
} = menu;
|
||||||
|
|
||||||
let container = Container::new(Scrollable::with_direction(
|
let list = Scrollable::with_direction(
|
||||||
List {
|
List {
|
||||||
options,
|
options,
|
||||||
hovered_option,
|
hovered_option,
|
||||||
|
|
@ -215,14 +214,14 @@ where
|
||||||
class,
|
class,
|
||||||
},
|
},
|
||||||
scrollable::Direction::default(),
|
scrollable::Direction::default(),
|
||||||
));
|
);
|
||||||
|
|
||||||
state.tree.diff(&container as &dyn Widget<_, _, _>);
|
state.tree.diff(&list as &dyn Widget<_, _, _>);
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
position,
|
position,
|
||||||
state: &mut state.tree,
|
state: &mut state.tree,
|
||||||
container,
|
list,
|
||||||
width,
|
width,
|
||||||
target_height,
|
target_height,
|
||||||
class,
|
class,
|
||||||
|
|
@ -255,7 +254,7 @@ where
|
||||||
)
|
)
|
||||||
.width(self.width);
|
.width(self.width);
|
||||||
|
|
||||||
let node = self.container.layout(self.state, renderer, &limits);
|
let node = self.list.layout(self.state, renderer, &limits);
|
||||||
let size = node.size();
|
let size = node.size();
|
||||||
|
|
||||||
node.move_to(if space_below > space_above {
|
node.move_to(if space_below > space_above {
|
||||||
|
|
@ -276,7 +275,7 @@ where
|
||||||
) -> event::Status {
|
) -> event::Status {
|
||||||
let bounds = layout.bounds();
|
let bounds = layout.bounds();
|
||||||
|
|
||||||
self.container.on_event(
|
self.list.on_event(
|
||||||
self.state, event, layout, cursor, renderer, clipboard, shell,
|
self.state, event, layout, cursor, renderer, clipboard, shell,
|
||||||
&bounds,
|
&bounds,
|
||||||
)
|
)
|
||||||
|
|
@ -289,7 +288,7 @@ where
|
||||||
viewport: &Rectangle,
|
viewport: &Rectangle,
|
||||||
renderer: &Renderer,
|
renderer: &Renderer,
|
||||||
) -> mouse::Interaction {
|
) -> mouse::Interaction {
|
||||||
self.container
|
self.list
|
||||||
.mouse_interaction(self.state, layout, cursor, viewport, renderer)
|
.mouse_interaction(self.state, layout, cursor, viewport, renderer)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -314,7 +313,7 @@ where
|
||||||
style.background,
|
style.background,
|
||||||
);
|
);
|
||||||
|
|
||||||
self.container.draw(
|
self.list.draw(
|
||||||
self.state, renderer, theme, defaults, layout, cursor, &bounds,
|
self.state, renderer, theme, defaults, layout, cursor, &bounds,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
@ -579,13 +578,18 @@ pub struct Style {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The theme catalog of a [`Menu`].
|
/// The theme catalog of a [`Menu`].
|
||||||
pub trait Catalog: scrollable::Catalog + container::Catalog {
|
pub trait Catalog: scrollable::Catalog {
|
||||||
/// The item class of the [`Catalog`].
|
/// The item class of the [`Catalog`].
|
||||||
type Class<'a>;
|
type Class<'a>;
|
||||||
|
|
||||||
/// The default class produced by the [`Catalog`].
|
/// The default class produced by the [`Catalog`].
|
||||||
fn default<'a>() -> <Self as Catalog>::Class<'a>;
|
fn default<'a>() -> <Self as Catalog>::Class<'a>;
|
||||||
|
|
||||||
|
/// The default class for the scrollable of the [`Menu`].
|
||||||
|
fn default_scrollable<'a>() -> <Self as scrollable::Catalog>::Class<'a> {
|
||||||
|
<Self as scrollable::Catalog>::default()
|
||||||
|
}
|
||||||
|
|
||||||
/// The [`Style`] of a class with the given status.
|
/// The [`Style`] of a class with the given status.
|
||||||
fn style(&self, class: &<Self as Catalog>::Class<'_>) -> Style;
|
fn style(&self, class: &<Self as Catalog>::Class<'_>) -> Style;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -84,7 +84,7 @@ where
|
||||||
font: None,
|
font: None,
|
||||||
handle: Handle::default(),
|
handle: Handle::default(),
|
||||||
class: <Theme as Catalog>::default(),
|
class: <Theme as Catalog>::default(),
|
||||||
menu_class: <Theme as menu::Catalog>::default(),
|
menu_class: <Theme as Catalog>::default_menu(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -700,6 +700,11 @@ pub trait Catalog: menu::Catalog {
|
||||||
/// The default class produced by the [`Catalog`].
|
/// The default class produced by the [`Catalog`].
|
||||||
fn default<'a>() -> <Self as Catalog>::Class<'a>;
|
fn default<'a>() -> <Self as Catalog>::Class<'a>;
|
||||||
|
|
||||||
|
/// The default class for the menu of the [`PickList`].
|
||||||
|
fn default_menu<'a>() -> <Self as menu::Catalog>::Class<'a> {
|
||||||
|
<Self as menu::Catalog>::default()
|
||||||
|
}
|
||||||
|
|
||||||
/// The [`Style`] of a class with the given status.
|
/// The [`Style`] of a class with the given status.
|
||||||
fn style(
|
fn style(
|
||||||
&self,
|
&self,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue