refactor(dropdown): create dropdown with NewAppMessage for popup
This commit is contained in:
parent
c916c89b03
commit
fdf5ac1a61
2 changed files with 45 additions and 17 deletions
|
|
@ -27,7 +27,6 @@ pub fn dropdown<
|
||||||
Dropdown::new(selections, selected, on_selected)
|
Dropdown::new(selections, selected, on_selected)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(all(feature = "winit", feature = "wayland"))]
|
|
||||||
/// Displays a list of options in a popover menu on select.
|
/// Displays a list of options in a popover menu on select.
|
||||||
/// AppMessage must be the App's toplevel message.
|
/// AppMessage must be the App's toplevel message.
|
||||||
pub fn popup_dropdown<
|
pub fn popup_dropdown<
|
||||||
|
|
@ -39,13 +38,14 @@ pub fn popup_dropdown<
|
||||||
selections: &'a [S],
|
selections: &'a [S],
|
||||||
selected: Option<usize>,
|
selected: Option<usize>,
|
||||||
on_selected: impl Fn(usize) -> Message + Send + Sync + 'static,
|
on_selected: impl Fn(usize) -> Message + Send + Sync + 'static,
|
||||||
parent_id: window::Id,
|
_parent_id: window::Id,
|
||||||
on_surface_action: impl Fn(surface::Action) -> Message + Send + Sync + 'static,
|
_on_surface_action: impl Fn(surface::Action) -> Message + Send + Sync + 'static,
|
||||||
map_action: impl Fn(Message) -> AppMessage + Send + Sync + 'static,
|
_map_action: impl Fn(Message) -> AppMessage + Send + Sync + 'static,
|
||||||
) -> Dropdown<'a, S, Message, AppMessage> {
|
) -> Dropdown<'a, S, Message, AppMessage> {
|
||||||
Dropdown::new(selections, selected, on_selected).with_popup(
|
let dropdown = Dropdown::new(selections, selected, on_selected);
|
||||||
parent_id,
|
|
||||||
on_surface_action,
|
#[cfg(all(feature = "winit", feature = "wayland"))]
|
||||||
map_action,
|
let dropdown = dropdown.with_popup(_parent_id, _on_surface_action, _map_action);
|
||||||
)
|
|
||||||
|
dropdown
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -99,16 +99,43 @@ where
|
||||||
#[cfg(all(feature = "winit", feature = "wayland"))]
|
#[cfg(all(feature = "winit", feature = "wayland"))]
|
||||||
/// Handle dropdown requests for popup creation.
|
/// Handle dropdown requests for popup creation.
|
||||||
/// Intended to be used with [`crate::app::message::get_popup`]
|
/// Intended to be used with [`crate::app::message::get_popup`]
|
||||||
pub fn with_popup(
|
pub fn with_popup<NewAppMessage>(
|
||||||
mut self,
|
mut self,
|
||||||
parent_id: window::Id,
|
parent_id: window::Id,
|
||||||
on_surface_action: impl Fn(surface::Action) -> Message + Send + Sync + 'static,
|
on_surface_action: impl Fn(surface::Action) -> Message + Send + Sync + 'static,
|
||||||
action_map: impl Fn(Message) -> AppMessage + Send + Sync + 'static,
|
action_map: impl Fn(Message) -> NewAppMessage + Send + Sync + 'static,
|
||||||
) -> Self {
|
) -> Dropdown<'a, S, Message, NewAppMessage> {
|
||||||
self.window_id = Some(parent_id);
|
let Self {
|
||||||
self.on_surface_action = Some(Arc::new(on_surface_action));
|
on_selected,
|
||||||
self.action_map = Some(Arc::new(action_map));
|
selections,
|
||||||
self
|
icons,
|
||||||
|
selected,
|
||||||
|
width,
|
||||||
|
gap,
|
||||||
|
padding,
|
||||||
|
text_size,
|
||||||
|
text_line_height,
|
||||||
|
font,
|
||||||
|
positioner,
|
||||||
|
..
|
||||||
|
} = self;
|
||||||
|
|
||||||
|
Dropdown::<'a, S, Message, NewAppMessage> {
|
||||||
|
on_selected,
|
||||||
|
selections,
|
||||||
|
icons,
|
||||||
|
selected,
|
||||||
|
width,
|
||||||
|
gap,
|
||||||
|
padding,
|
||||||
|
text_size,
|
||||||
|
text_line_height,
|
||||||
|
font,
|
||||||
|
on_surface_action: Some(Arc::new(on_surface_action)),
|
||||||
|
action_map: Some(Arc::new(action_map)),
|
||||||
|
window_id: Some(parent_id),
|
||||||
|
positioner,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(all(feature = "winit", feature = "wayland"))]
|
#[cfg(all(feature = "winit", feature = "wayland"))]
|
||||||
|
|
@ -525,7 +552,8 @@ pub fn update<
|
||||||
positioner: SctkPositioner {
|
positioner: SctkPositioner {
|
||||||
size: Some((selections_width as u32 + gap as u32 + pad_width as u32 + icon_width as u32, 10)),
|
size: Some((selections_width as u32 + gap as u32 + pad_width as u32 + icon_width as u32, 10)),
|
||||||
anchor_rect,
|
anchor_rect,
|
||||||
anchor: cctk::wayland_protocols::xdg::shell::client::xdg_positioner::Anchor::Top,
|
// TODO: left or right alignment based on direction?
|
||||||
|
anchor: cctk::wayland_protocols::xdg::shell::client::xdg_positioner::Anchor::Bottom,
|
||||||
gravity: cctk::wayland_protocols::xdg::shell::client::xdg_positioner::Gravity::Bottom,
|
gravity: cctk::wayland_protocols::xdg::shell::client::xdg_positioner::Gravity::Bottom,
|
||||||
reactive: true,
|
reactive: true,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue