Skip to main content

lingxia_platform/traits/
ui.rs

1use std::future::Future;
2
3use crate::error::PlatformError;
4
5#[derive(Debug, Clone, Copy, PartialEq, Eq)]
6pub enum ToastIcon {
7    Success,
8    Error,
9    Loading,
10    None,
11}
12
13#[derive(Debug, Clone, Copy, PartialEq, Eq)]
14pub enum ToastPosition {
15    Top,
16    Center,
17    Bottom,
18}
19
20#[derive(Debug, Clone)]
21pub struct ToastOptions {
22    pub title: String,
23    pub icon: ToastIcon,
24    pub image: Option<String>,
25    pub duration: f64,
26    pub mask: bool,
27    pub position: ToastPosition,
28}
29
30#[derive(Debug, Clone)]
31pub struct ModalOptions {
32    pub title: String,
33    pub content: String,
34    pub show_cancel: bool,
35    pub cancel_text: String,
36    pub cancel_color: Option<String>,
37    pub confirm_text: String,
38    pub confirm_color: Option<String>,
39}
40
41#[repr(i32)]
42#[derive(Debug, Clone, Copy, PartialEq, Eq)]
43pub enum SurfaceKind {
44    Window = 0,
45    Overlay = 1,
46}
47
48#[repr(i32)]
49#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
50pub enum SurfaceContent {
51    #[default]
52    Page = 0,
53    Url = 1,
54}
55
56#[repr(i32)]
57#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
58pub enum SurfacePosition {
59    #[default]
60    Center = 0,
61    Bottom = 1,
62    Left = 2,
63    Right = 3,
64    Top = 4,
65}
66
67#[derive(Debug, Clone)]
68pub struct SurfaceRequest {
69    pub id: String,
70    pub app_id: String,
71    pub path: String,
72    pub session_id: u64,
73    pub page_instance_id: String,
74    pub content: SurfaceContent,
75    pub kind: SurfaceKind,
76    pub width: f64,
77    pub height: f64,
78    pub width_ratio: f64,
79    pub height_ratio: f64,
80    pub position: SurfacePosition,
81}
82
83pub trait SurfacePresenter: Send + Sync + 'static {
84    fn present_surface(&self, _request: SurfaceRequest) -> Result<(), PlatformError> {
85        Err(PlatformError::NotSupported(
86            "surface is not supported on this platform".to_string(),
87        ))
88    }
89
90    fn close_surface(&self, _app_id: &str, _id: &str, _reason: &str) -> Result<(), PlatformError> {
91        Err(PlatformError::NotSupported(
92            "surface close is not supported on this platform".to_string(),
93        ))
94    }
95
96    fn show_surface(&self, _app_id: &str, _id: &str) -> Result<(), PlatformError> {
97        Err(PlatformError::NotSupported(
98            "surface show is not supported on this platform".to_string(),
99        ))
100    }
101
102    fn hide_surface(&self, _app_id: &str, _id: &str) -> Result<(), PlatformError> {
103        Err(PlatformError::NotSupported(
104            "surface hide is not supported on this platform".to_string(),
105        ))
106    }
107}
108
109pub trait UIUpdate: Send + Sync + 'static {
110    fn update_navbar_ui(&self, appid: String) -> Result<(), PlatformError>;
111    fn update_tabbar_ui(&self, appid: String) -> Result<(), PlatformError>;
112
113    fn update_orientation_ui(&self, _appid: String) -> Result<(), PlatformError> {
114        Err(PlatformError::NotSupported(
115            "update_orientation_ui not implemented for this platform".to_string(),
116        ))
117    }
118}
119
120pub trait UserFeedback: Send + Sync + 'static {
121    fn show_toast(&self, options: ToastOptions) -> Result<(), PlatformError>;
122    fn hide_toast(&self) -> Result<(), PlatformError>;
123
124    fn show_modal(
125        &self,
126        options: ModalOptions,
127    ) -> impl Future<Output = Result<String, PlatformError>> + Send;
128
129    fn show_action_sheet(
130        &self,
131        options: Vec<String>,
132        cancel_text: String,
133        item_color: String,
134    ) -> impl Future<Output = Result<String, PlatformError>> + Send;
135}