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, Default)]
43pub enum PopupPosition {
44    Center = 0,
45    #[default]
46    Bottom = 1,
47    Left = 2,
48    Right = 3,
49}
50
51#[derive(Debug, Clone)]
52pub struct PopupRequest {
53    pub app_id: String,
54    pub path: String,
55    pub width_ratio: f64,
56    pub height_ratio: f64,
57    pub position: PopupPosition,
58}
59
60impl PopupRequest {
61    pub fn new(app_id: String, path: String) -> Self {
62        Self {
63            app_id,
64            path,
65            width_ratio: f64::NAN,
66            height_ratio: f64::NAN,
67            position: PopupPosition::Bottom,
68        }
69    }
70}
71
72pub trait PopupPresenter: Send + Sync + 'static {
73    fn show_popup(&self, request: PopupRequest) -> Result<(), PlatformError>;
74    fn hide_popup(&self, app_id: &str) -> Result<(), PlatformError>;
75}
76
77pub trait UIUpdate: Send + Sync + 'static {
78    fn update_navbar_ui(&self, appid: String) -> Result<(), PlatformError>;
79    fn update_tabbar_ui(&self, appid: String) -> Result<(), PlatformError>;
80
81    fn update_orientation_ui(&self, _appid: String) -> Result<(), PlatformError> {
82        Err(PlatformError::NotSupported(
83            "update_orientation_ui not implemented for this platform".to_string(),
84        ))
85    }
86}
87
88pub trait UserFeedback: Send + Sync + 'static {
89    fn show_toast(&self, options: ToastOptions) -> Result<(), PlatformError>;
90    fn hide_toast(&self) -> Result<(), PlatformError>;
91
92    fn show_modal(
93        &self,
94        options: ModalOptions,
95    ) -> impl Future<Output = Result<String, PlatformError>> + Send;
96
97    fn show_action_sheet(
98        &self,
99        options: Vec<String>,
100        cancel_text: String,
101        item_color: String,
102    ) -> impl Future<Output = Result<String, PlatformError>> + Send;
103}