Rename PickList handlers for consistency
This commit is contained in:
parent
6cf7c4645d
commit
59a79e55d4
1 changed files with 25 additions and 25 deletions
|
|
@ -34,9 +34,9 @@ pub struct PickList<
|
|||
Theme: StyleSheet,
|
||||
Renderer: text::Renderer,
|
||||
{
|
||||
on_selected: Box<dyn Fn(T) -> Message + 'a>,
|
||||
on_opened: Option<Message>,
|
||||
on_closed: Option<Message>,
|
||||
on_select: Box<dyn Fn(T) -> Message + 'a>,
|
||||
on_open: Option<Message>,
|
||||
on_close: Option<Message>,
|
||||
options: Cow<'a, [T]>,
|
||||
placeholder: Option<String>,
|
||||
selected: Option<T>,
|
||||
|
|
@ -71,12 +71,12 @@ where
|
|||
pub fn new(
|
||||
options: impl Into<Cow<'a, [T]>>,
|
||||
selected: Option<T>,
|
||||
on_selected: impl Fn(T) -> Message + 'a,
|
||||
on_select: impl Fn(T) -> Message + 'a,
|
||||
) -> Self {
|
||||
Self {
|
||||
on_selected: Box::new(on_selected),
|
||||
on_opened: None,
|
||||
on_closed: None,
|
||||
on_select: Box::new(on_select),
|
||||
on_open: None,
|
||||
on_close: None,
|
||||
options: options.into(),
|
||||
placeholder: None,
|
||||
selected,
|
||||
|
|
@ -142,15 +142,15 @@ where
|
|||
self
|
||||
}
|
||||
|
||||
/// Sets the message that will be produced when the [`PickList`] Menu is openned menu.
|
||||
pub fn on_opened(mut self, msg: Message) -> Self {
|
||||
self.on_opened = Some(msg);
|
||||
/// Sets the message that will be produced when the [`PickList`] is opened.
|
||||
pub fn on_open(mut self, on_open: Message) -> Self {
|
||||
self.on_open = Some(on_open);
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the message that will be produced when the [`PickList`] Menu is closed menu.
|
||||
pub fn on_closed(mut self, msg: Message) -> Self {
|
||||
self.on_closed = Some(msg);
|
||||
/// Sets the message that will be produced when the [`PickList`] is closed.
|
||||
pub fn on_close(mut self, on_close: Message) -> Self {
|
||||
self.on_close = Some(on_close);
|
||||
self
|
||||
}
|
||||
|
||||
|
|
@ -229,9 +229,9 @@ where
|
|||
layout,
|
||||
cursor,
|
||||
shell,
|
||||
self.on_selected.as_ref(),
|
||||
self.on_opened.as_ref(),
|
||||
self.on_closed.as_ref(),
|
||||
self.on_select.as_ref(),
|
||||
self.on_open.as_ref(),
|
||||
self.on_close.as_ref(),
|
||||
self.selected.as_ref(),
|
||||
&self.options,
|
||||
|| tree.state.downcast_mut::<State<Renderer::Paragraph>>(),
|
||||
|
|
@ -297,7 +297,7 @@ where
|
|||
self.text_shaping,
|
||||
self.font.unwrap_or_else(|| renderer.default_font()),
|
||||
&self.options,
|
||||
&self.on_selected,
|
||||
&self.on_select,
|
||||
self.style.clone(),
|
||||
)
|
||||
}
|
||||
|
|
@ -492,9 +492,9 @@ pub fn update<'a, T, P, Message>(
|
|||
layout: Layout<'_>,
|
||||
cursor: mouse::Cursor,
|
||||
shell: &mut Shell<'_, Message>,
|
||||
on_selected: &dyn Fn(T) -> Message,
|
||||
on_opened: Option<&Message>,
|
||||
on_closed: Option<&Message>,
|
||||
on_select: &dyn Fn(T) -> Message,
|
||||
on_open: Option<&Message>,
|
||||
on_close: Option<&Message>,
|
||||
selected: Option<&T>,
|
||||
options: &[T],
|
||||
state: impl FnOnce() -> &'a mut State<P>,
|
||||
|
|
@ -514,8 +514,8 @@ where
|
|||
// bounds or on the drop-down, either way we close the overlay.
|
||||
state.is_open = false;
|
||||
|
||||
if let Some(on_closed) = on_closed {
|
||||
shell.publish(on_closed.clone());
|
||||
if let Some(on_close) = on_close {
|
||||
shell.publish(on_close.clone());
|
||||
}
|
||||
|
||||
event::Status::Captured
|
||||
|
|
@ -524,8 +524,8 @@ where
|
|||
state.hovered_option =
|
||||
options.iter().position(|option| Some(option) == selected);
|
||||
|
||||
if let Some(on_opened) = on_opened {
|
||||
shell.publish(on_opened.clone());
|
||||
if let Some(on_open) = on_open {
|
||||
shell.publish(on_open.clone());
|
||||
}
|
||||
|
||||
event::Status::Captured
|
||||
|
|
@ -568,7 +568,7 @@ where
|
|||
};
|
||||
|
||||
if let Some(next_option) = next_option {
|
||||
shell.publish((on_selected)(next_option.clone()));
|
||||
shell.publish((on_select)(next_option.clone()));
|
||||
}
|
||||
|
||||
event::Status::Captured
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue