Skip to main content

theframework/
thetrait.rs

1use crate::prelude::*;
2
3#[allow(unused)]
4pub trait TheTrait {
5    fn new() -> Self
6    where
7        Self: Sized;
8
9    fn init(&mut self, ctx: &mut TheContext) {}
10
11    fn default_window_size(&self) -> (usize, usize) {
12        (1200, 700)
13    }
14
15    /// Minimum resizable window size.
16    /// Defaults to `default_window_size()` but can be overridden independently.
17    fn min_window_size(&self) -> (usize, usize) {
18        self.default_window_size()
19    }
20
21    fn default_window_position(&self) -> Option<(i32, i32)> {
22        None
23    }
24
25    fn window_title(&self) -> String {
26        "TheFramework based App".to_string()
27    }
28
29    fn target_fps(&self) -> f64 {
30        30.0
31    }
32
33    fn window_icon(&self) -> Option<(Vec<u8>, u32, u32)> {
34        None
35    }
36
37    #[cfg(feature = "i18n")]
38    fn fonts_to_load(&self) -> Vec<TheFontScript> {
39        vec![]
40    }
41
42    fn set_cmd_line_args_early(&mut self, args: Vec<String>) {}
43    fn set_cmd_line_args(&mut self, args: Vec<String>, ctx: &mut TheContext) {}
44
45    #[cfg(feature = "ui")]
46    fn init_ui(&mut self, ui: &mut TheUI, ctx: &mut TheContext) {}
47
48    fn draw(&mut self, pixels: &mut [u8], ctx: &mut TheContext) {}
49
50    fn update(&mut self, ctx: &mut TheContext) -> bool {
51        false
52    }
53
54    #[cfg(feature = "ui")]
55    fn update_ui(&mut self, ui: &mut TheUI, ctx: &mut TheContext) -> bool {
56        false
57    }
58
59    fn touch_down(&mut self, x: f32, y: f32, ctx: &mut TheContext) -> bool {
60        false
61    }
62
63    fn touch_dragged(&mut self, x: f32, y: f32, ctx: &mut TheContext) -> bool {
64        false
65    }
66
67    fn touch_up(&mut self, x: f32, y: f32, ctx: &mut TheContext) -> bool {
68        false
69    }
70
71    fn hover(&mut self, _x: f32, _y: f32, ctx: &mut TheContext) -> bool {
72        false
73    }
74
75    fn key_down(
76        &mut self,
77        char: Option<char>,
78        key: Option<TheKeyCode>,
79        ctx: &mut TheContext,
80    ) -> bool {
81        false
82    }
83
84    fn key_up(
85        &mut self,
86        char: Option<char>,
87        key: Option<TheKeyCode>,
88        ctx: &mut TheContext,
89    ) -> bool {
90        false
91    }
92
93    fn mouse_wheel(&mut self, delta: (isize, isize), ctx: &mut TheContext) -> bool {
94        false
95    }
96
97    fn modifier_changed(&mut self, shift: bool, ctrl: bool, alt: bool, logo: bool) -> bool {
98        false
99    }
100
101    fn dropped_file(&mut self, _path: String) -> bool {
102        false
103    }
104
105    fn closing(&self) -> bool {
106        false
107    }
108
109    // Life Circles
110
111    #[cfg(feature = "ui")]
112    fn post_ui(&mut self, ctx: &mut TheContext) {}
113
114    #[cfg(feature = "ui")]
115    fn pre_ui(&mut self, ctx: &mut TheContext) {}
116
117    /// Open a file requester
118    fn open(&mut self) {}
119
120    /// Save the file
121    fn save(&mut self) {}
122
123    /// Save the file as...
124    fn save_as(&mut self) {}
125
126    // Cut / Copy / Paste
127
128    fn cut(&mut self) -> String {
129        "".to_string()
130    }
131
132    fn copy(&mut self) -> String {
133        "".to_string()
134    }
135
136    fn paste(&mut self, text: String) {}
137
138    // Undo / Redo
139
140    fn undo(&mut self) {}
141
142    fn redo(&mut self) {}
143
144    //
145
146    /// Returns true if the app has internal changes.
147    fn has_changes(&self) -> bool {
148        false
149    }
150
151    fn window_moved(&mut self, _x: i32, _y: i32) {}
152
153    fn window_resized(&mut self, _width: usize, _height: usize) {}
154}