cosmic/surface/
mod.rs

1// Copyright 2025 System76 <info@system76.com>
2// SPDX-License-Identifier: MPL-2.0
3
4pub mod action;
5
6use iced::Limits;
7use iced::Size;
8use iced::Task;
9use std::future::Future;
10use std::sync::Arc;
11
12/// Ignore this message in your application. It will be intercepted.
13#[derive(Clone)]
14pub enum Action {
15    /// Create a subsurface with a view function accepting the App as a parameter
16    AppSubsurface(
17        std::sync::Arc<Box<dyn std::any::Any + Send + Sync>>,
18        Option<std::sync::Arc<Box<dyn std::any::Any + Send + Sync>>>,
19    ),
20    /// Create a subsurface with a view function
21    Subsurface(
22        std::sync::Arc<Box<dyn std::any::Any + Send + Sync>>,
23        Option<std::sync::Arc<Box<dyn std::any::Any + Send + Sync>>>,
24    ),
25    /// Destroy a subsurface with a view function
26    DestroySubsurface(iced::window::Id),
27    /// Create a popup with a view function accepting the App as a parameter
28    AppPopup(
29        std::sync::Arc<Box<dyn std::any::Any + Send + Sync>>,
30        Option<std::sync::Arc<Box<dyn std::any::Any + Send + Sync>>>,
31    ),
32    /// Create a popup
33    Popup(
34        std::sync::Arc<Box<dyn std::any::Any + Send + Sync>>,
35        Option<std::sync::Arc<Box<dyn std::any::Any + Send + Sync>>>,
36    ),
37    /// Destroy a subsurface with a view function
38    DestroyPopup(iced::window::Id),
39    /// Responsive menu bar update
40    ResponsiveMenuBar {
41        /// Id of the menu bar
42        menu_bar: crate::widget::Id,
43        /// Limits of the menu bar
44        limits: Limits,
45        /// Requested Full Size for expanded menu bar
46        size: Size,
47    },
48    Ignore,
49    Task(Arc<dyn Fn() -> Task<Action> + Send + Sync>),
50}
51
52impl std::fmt::Debug for Action {
53    #[cold]
54    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
55        match self {
56            Self::AppSubsurface(arg0, arg1) => f
57                .debug_tuple("AppSubsurface")
58                .field(arg0)
59                .field(arg1)
60                .finish(),
61            Self::Subsurface(arg0, arg1) => {
62                f.debug_tuple("Subsurface").field(arg0).field(arg1).finish()
63            }
64            Self::DestroySubsurface(arg0) => {
65                f.debug_tuple("DestroySubsurface").field(arg0).finish()
66            }
67            Self::AppPopup(arg0, arg1) => {
68                f.debug_tuple("AppPopup").field(arg0).field(arg1).finish()
69            }
70            Self::Popup(arg0, arg1) => f.debug_tuple("Popup").field(arg0).field(arg1).finish(),
71            Self::DestroyPopup(arg0) => f.debug_tuple("DestroyPopup").field(arg0).finish(),
72            Self::ResponsiveMenuBar {
73                menu_bar,
74                limits,
75                size,
76            } => f
77                .debug_struct("ResponsiveMenuBar")
78                .field("menu_bar", menu_bar)
79                .field("limits", limits)
80                .field("size", size)
81                .finish(),
82            Self::Ignore => write!(f, "Ignore"),
83            Self::Task(_) => f.debug_tuple("Future").finish(),
84        }
85    }
86}