lingxia_platform/traits/
ui.rs1use crate::error::PlatformError;
2
3#[derive(Debug, Clone, Copy, PartialEq, Eq)]
4pub enum ToastIcon {
5 Success,
6 Error,
7 Loading,
8 None,
9}
10
11#[derive(Debug, Clone, Copy, PartialEq, Eq)]
12pub enum ToastPosition {
13 Top,
14 Center,
15 Bottom,
16}
17
18#[derive(Debug, Clone)]
19pub struct ToastOptions {
20 pub title: String,
21 pub icon: ToastIcon,
22 pub image: Option<String>,
23 pub duration: f64,
24 pub mask: bool,
25 pub position: ToastPosition,
26}
27
28#[derive(Debug, Clone)]
29pub struct ModalOptions {
30 pub title: String,
31 pub content: String,
32 pub show_cancel: bool,
33 pub cancel_text: String,
34 pub cancel_color: Option<String>,
35 pub confirm_text: String,
36 pub confirm_color: Option<String>,
37}
38
39#[repr(i32)]
40#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
41pub enum PopupPosition {
42 Center = 0,
43 #[default]
44 Bottom = 1,
45 Left = 2,
46 Right = 3,
47}
48
49#[derive(Debug, Clone)]
50pub struct PopupRequest {
51 pub app_id: String,
52 pub path: String,
53 pub width_ratio: f64,
54 pub height_ratio: f64,
55 pub position: PopupPosition,
56}
57
58impl PopupRequest {
59 pub fn new(app_id: String, path: String) -> Self {
60 Self {
61 app_id,
62 path,
63 width_ratio: f64::NAN,
64 height_ratio: f64::NAN,
65 position: PopupPosition::Bottom,
66 }
67 }
68}
69
70pub trait PopupPresenter: Send + Sync + 'static {
71 fn show_popup(&self, request: PopupRequest) -> Result<(), PlatformError>;
72 fn hide_popup(&self, app_id: &str) -> Result<(), PlatformError>;
73}
74
75pub trait UIUpdate: Send + Sync + 'static {
76 fn update_navbar_ui(&self, appid: String) -> Result<(), PlatformError>;
77 fn update_tabbar_ui(&self, appid: String) -> Result<(), PlatformError>;
78
79 fn update_orientation_ui(&self, _appid: String) -> Result<(), PlatformError> {
80 Err(PlatformError::Platform(
81 "update_orientation_ui not implemented for this platform".to_string(),
82 ))
83 }
84}
85
86pub trait UserFeedback: Send + Sync + 'static {
87 fn show_toast(&self, options: ToastOptions) -> Result<(), PlatformError>;
88 fn hide_toast(&self) -> Result<(), PlatformError>;
89 fn show_modal(&self, options: ModalOptions, callback_id: u64) -> Result<(), PlatformError>;
90 fn show_action_sheet(
91 &self,
92 options: Vec<String>,
93 cancel_text: String,
94 item_color: String,
95 callback_id: u64,
96 ) -> Result<(), PlatformError>;
97}