cosmic/widget/dropdown/operation.rs
1// Copyright 2025 System76 <info@system76.com>
2// SPDX-License-Identifier: MPL-2.0 AND MIT
3//! Operate on dropdown widgets.
4
5use super::State;
6use iced::Rectangle;
7use iced_core::widget::{Id, Operation};
8
9pub trait Dropdown {
10 fn close(&mut self);
11 fn open(&mut self);
12}
13
14// /// Produces a [`Task`] that closes a [`Dropdown`] popup.
15// pub fn close<T>(id: Id) -> impl Operation<T> {
16// struct Close(Id);
17
18// impl<T> Operation<T> for Close {
19// fn custom(&mut self, state: &mut dyn std::any::Any, id: Option<&Id>) {
20// if id.map_or(true, |id| id != &self.0) {
21// return;
22// }
23
24// let Some(state) = state.downcast_mut::<State>() else {
25// return;
26// };
27
28// state.close();
29// }
30
31// fn container(
32// &mut self,
33// _id: Option<&Id>,
34// _bounds: Rectangle,
35// operate_on_children: &mut dyn FnMut(&mut dyn Operation<T>),
36// ) {
37// operate_on_children(self)
38// }
39// }
40
41// Close(id)
42// }
43
44// /// Produces a [`Task`] that opens a [`Dropdown`] popup.
45// pub fn open<T>(id: Id) -> impl Operation<T> {
46// struct Open(Id);
47
48// impl<T> Operation<T> for Open {
49// fn custom(&mut self, state: &mut dyn std::any::Any, id: Option<&Id>) {
50// if id.map_or(true, |id| id != &self.0) {
51// return;
52// }
53
54// let Some(state) = state.downcast_mut::<State>() else {
55// return;
56// };
57
58// state.open();
59// }
60
61// fn container(
62// &mut self,
63// _id: Option<&Id>,
64// _bounds: Rectangle,
65// operate_on_children: &mut dyn FnMut(&mut dyn Operation<T>),
66// ) {
67// operate_on_children(self)
68// }
69// }
70
71// Open(id)
72// }