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)
|
||||
}
|
||||
|
||||
#[cfg(all(feature = "winit", feature = "wayland"))]
|
||||
/// Displays a list of options in a popover menu on select.
|
||||
/// AppMessage must be the App's toplevel message.
|
||||
pub fn popup_dropdown<
|
||||
|
|
@ -39,13 +38,14 @@ pub fn popup_dropdown<
|
|||
selections: &'a [S],
|
||||
selected: Option<usize>,
|
||||
on_selected: impl Fn(usize) -> Message + Send + Sync + 'static,
|
||||
parent_id: window::Id,
|
||||
on_surface_action: impl Fn(surface::Action) -> Message + Send + Sync + 'static,
|
||||
map_action: impl Fn(Message) -> AppMessage + Send + Sync + 'static,
|
||||
_parent_id: window::Id,
|
||||
_on_surface_action: impl Fn(surface::Action) -> Message + Send + Sync + 'static,
|
||||
_map_action: impl Fn(Message) -> AppMessage + Send + Sync + 'static,
|
||||
) -> Dropdown<'a, S, Message, AppMessage> {
|
||||
Dropdown::new(selections, selected, on_selected).with_popup(
|
||||
parent_id,
|
||||
on_surface_action,
|
||||
map_action,
|
||||
)
|
||||
let dropdown = Dropdown::new(selections, selected, on_selected);
|
||||
|
||||
#[cfg(all(feature = "winit", feature = "wayland"))]
|
||||
let dropdown = dropdown.with_popup(_parent_id, _on_surface_action, _map_action);
|
||||
|
||||
dropdown
|
||||
}
|
||||
|
|
|
|||
|
|
@ -99,16 +99,43 @@ where
|
|||
#[cfg(all(feature = "winit", feature = "wayland"))]
|
||||
/// Handle dropdown requests for popup creation.
|
||||
/// Intended to be used with [`crate::app::message::get_popup`]
|
||||
pub fn with_popup(
|
||||
pub fn with_popup<NewAppMessage>(
|
||||
mut self,
|
||||
parent_id: window::Id,
|
||||
on_surface_action: impl Fn(surface::Action) -> Message + Send + Sync + 'static,
|
||||
action_map: impl Fn(Message) -> AppMessage + Send + Sync + 'static,
|
||||
) -> Self {
|
||||
self.window_id = Some(parent_id);
|
||||
self.on_surface_action = Some(Arc::new(on_surface_action));
|
||||
self.action_map = Some(Arc::new(action_map));
|
||||
self
|
||||
action_map: impl Fn(Message) -> NewAppMessage + Send + Sync + 'static,
|
||||
) -> Dropdown<'a, S, Message, NewAppMessage> {
|
||||
let Self {
|
||||
on_selected,
|
||||
selections,
|
||||
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"))]
|
||||
|
|
@ -525,7 +552,8 @@ pub fn update<
|
|||
positioner: SctkPositioner {
|
||||
size: Some((selections_width as u32 + gap as u32 + pad_width as u32 + icon_width as u32, 10)),
|
||||
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,
|
||||
reactive: true,
|
||||
..Default::default()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue