pax_message/
lib.rs

1pub mod reflection;
2
3//FUTURE: feature-flag, only for Web builds
4#[allow(unused_imports)]
5use wasm_bindgen::prelude::*;
6
7pub mod refcell_debug;
8pub use serde;
9
10use serde::{Deserialize, Serialize};
11
12#[cfg_attr(debug_assertions, derive(Debug))]
13#[derive(Serialize)]
14pub enum NativeMessage {
15    TextCreate(AnyCreatePatch),
16    TextUpdate(TextPatch),
17    TextDelete(u32),
18    FrameCreate(AnyCreatePatch),
19    FrameUpdate(FramePatch),
20    FrameDelete(u32),
21    EventBlockerCreate(AnyCreatePatch),
22    EventBlockerUpdate(EventBlockerPatch),
23    EventBlockerDelete(u32),
24    CheckboxCreate(AnyCreatePatch),
25    CheckboxUpdate(CheckboxPatch),
26    CheckboxDelete(u32),
27    NativeImageCreate(AnyCreatePatch),
28    NativeImageUpdate(NativeImagePatch),
29    NativeImageDelete(u32),
30    YoutubeVideoCreate(AnyCreatePatch),
31    YoutubeVideoUpdate(YoutubeVideoPatch),
32    YoutubeVideoDelete(u32),
33    TextboxCreate(AnyCreatePatch),
34    TextboxUpdate(TextboxPatch),
35    TextboxDelete(u32),
36    SliderCreate(AnyCreatePatch),
37    SliderUpdate(SliderPatch),
38    SliderDelete(u32),
39    DropdownCreate(AnyCreatePatch),
40    DropdownUpdate(DropdownPatch),
41    DropdownDelete(u32),
42    RadioSetCreate(AnyCreatePatch),
43    RadioSetUpdate(RadioSetPatch),
44    RadioSetDelete(u32),
45    ButtonCreate(AnyCreatePatch),
46    ButtonUpdate(ButtonPatch),
47    ButtonDelete(u32),
48    ScrollerCreate(AnyCreatePatch),
49    ScrollerUpdate(ScrollerPatch),
50    ScrollerDelete(u32),
51    ImageLoad(ImagePatch),
52    LayerAdd(LayerAddPatch), //FUTURE: native form controls
53    ShrinkLayersTo(u32),
54    OcclusionUpdate(OcclusionPatch),
55    Navigate(NavigationPatch),
56    SetCursor(SetCursorPatch),
57}
58
59#[derive(Deserialize)]
60#[repr(C)]
61pub enum NativeInterrupt {
62    ChassisResizeRequestCollection(Vec<ChassisResizeRequestArgs>),
63    SelectStart(SelectStartArgs),
64    Focus(FocusInterruptArgs),
65    Clap(ClapInterruptArgs),
66    Scroll(ScrollInterruptArgs),
67    TouchStart(TouchStartInterruptArgs),
68    TouchMove(TouchMoveInterruptArgs),
69    TouchEnd(TouchEndInterruptArgs),
70    KeyDown(KeyDownInterruptArgs),
71    KeyUp(KeyUpInterruptArgs),
72    KeyPress(KeyPressInterruptArgs),
73    Click(ClickInterruptArgs),
74    DoubleClick(DoubleClickInterruptArgs),
75    MouseMove(MouseMoveInterruptArgs),
76    Wheel(WheelInterruptArgs),
77    MouseDown(MouseDownInterruptArgs),
78    MouseUp(MouseUpInterruptArgs),
79    ContextMenu(ContextMenuInterruptArgs),
80    Image(ImageLoadInterruptArgs),
81    AddedLayer(AddedLayerArgs),
82    TextInput(TextInputArgs),
83    FormCheckboxToggle(FormCheckboxToggleArgs),
84    FormDropdownChange(FormDropdownChangeArgs),
85    FormSliderChange(FormSliderChangeArgs),
86    FormRadioSetChange(FormRadioSetChangeArgs),
87    FormTextboxChange(FormTextboxChangeArgs),
88    FormTextboxInput(FormTextboxInputArgs),
89    FormButtonClick(FormButtonClickArgs),
90    Scrollbar(ScrollbarInterruptArgs),
91    DropFile(DropFileArgs),
92}
93
94#[derive(Deserialize)]
95#[repr(C)]
96pub struct ChassisResizeRequestArgs {
97    pub id: u32,
98    pub width: f64,
99    pub height: f64,
100}
101
102#[derive(Deserialize)]
103#[repr(C)]
104pub struct FormCheckboxToggleArgs {
105    pub state: bool,
106    pub id: u32,
107}
108
109#[derive(Deserialize)]
110#[repr(C)]
111pub struct FocusInterruptArgs {}
112
113#[derive(Deserialize)]
114#[repr(C)]
115pub struct SelectStartArgs {}
116
117#[derive(Deserialize)]
118#[repr(C)]
119pub struct FormTextboxChangeArgs {
120    pub text: String,
121    pub id: u32,
122}
123
124#[derive(Deserialize)]
125#[repr(C)]
126pub struct FormDropdownChangeArgs {
127    pub id: u32,
128    pub selected_id: u32,
129}
130
131#[derive(Deserialize)]
132#[repr(C)]
133pub struct FormSliderChangeArgs {
134    pub id: u32,
135    pub value: f64,
136}
137
138#[derive(Deserialize)]
139#[repr(C)]
140pub struct FormRadioSetChangeArgs {
141    pub id: u32,
142    pub selected_id: u32,
143}
144
145#[derive(Deserialize)]
146#[repr(C)]
147pub struct TextInputArgs {
148    pub text: String,
149    pub id: u32,
150}
151
152#[derive(Deserialize)]
153#[repr(C)]
154pub struct FormTextboxInputArgs {
155    pub text: String,
156    pub id: u32,
157}
158
159#[derive(Deserialize)]
160#[repr(C)]
161pub struct FormButtonClickArgs {
162    pub id: u32,
163}
164
165#[derive(Deserialize)]
166#[repr(C)]
167pub struct ClapInterruptArgs {
168    pub x: f64,
169    pub y: f64,
170}
171
172#[derive(Deserialize)]
173#[repr(C)]
174pub struct ScrollInterruptArgs {
175    pub delta_x: f64,
176    pub delta_y: f64,
177}
178
179#[derive(Deserialize)]
180#[repr(C)]
181pub struct ScrollbarInterruptArgs {
182    pub id: u32,
183    pub scroll_x: f64,
184    pub scroll_y: f64,
185}
186
187#[derive(Deserialize)]
188#[repr(C)]
189pub struct TouchMessage {
190    pub x: f64,
191    pub y: f64,
192    pub identifier: i64,
193    pub delta_x: f64,
194    pub delta_y: f64,
195}
196
197#[derive(Deserialize)]
198#[repr(C)]
199pub struct TouchStartInterruptArgs {
200    pub touches: Vec<TouchMessage>,
201}
202
203#[derive(Deserialize)]
204#[repr(C)]
205pub struct TouchMoveInterruptArgs {
206    pub touches: Vec<TouchMessage>,
207}
208
209#[derive(Deserialize)]
210#[repr(C)]
211pub struct TouchEndInterruptArgs {
212    pub touches: Vec<TouchMessage>,
213}
214
215#[derive(Deserialize)]
216#[repr(C)]
217pub struct DropFileArgs {
218    pub x: f64,
219    pub y: f64,
220    pub name: String,
221    pub mime_type: String,
222    pub size: u64,
223}
224
225#[derive(Deserialize, Clone)]
226#[repr(C)]
227pub enum MouseButtonMessage {
228    Left,
229    Right,
230    Middle,
231    Unknown,
232}
233
234#[derive(Deserialize)]
235#[repr(C)]
236pub enum ModifierKeyMessage {
237    Shift,
238    Control,
239    Alt,
240    Command,
241}
242
243#[derive(Deserialize)]
244#[repr(C)]
245pub struct KeyDownInterruptArgs {
246    pub key: String,
247    pub modifiers: Vec<ModifierKeyMessage>,
248    pub is_repeat: bool,
249}
250
251#[derive(Deserialize)]
252#[repr(C)]
253pub struct KeyUpInterruptArgs {
254    pub key: String,
255    pub modifiers: Vec<ModifierKeyMessage>,
256    pub is_repeat: bool,
257}
258
259#[derive(Deserialize)]
260#[repr(C)]
261pub struct KeyPressInterruptArgs {
262    pub key: String,
263    pub modifiers: Vec<ModifierKeyMessage>,
264    pub is_repeat: bool,
265}
266
267#[derive(Deserialize)]
268#[repr(C)]
269pub struct ClickInterruptArgs {
270    pub x: f64,
271    pub y: f64,
272    pub button: MouseButtonMessage,
273    pub modifiers: Vec<ModifierKeyMessage>,
274}
275
276#[derive(Deserialize)]
277#[repr(C)]
278pub struct DoubleClickInterruptArgs {
279    pub x: f64,
280    pub y: f64,
281    pub button: MouseButtonMessage,
282    pub modifiers: Vec<ModifierKeyMessage>,
283}
284
285#[derive(Deserialize)]
286#[repr(C)]
287pub struct MouseMoveInterruptArgs {
288    pub x: f64,
289    pub y: f64,
290    pub button: MouseButtonMessage,
291    pub modifiers: Vec<ModifierKeyMessage>,
292}
293
294#[derive(Deserialize)]
295#[repr(C)]
296pub struct WheelInterruptArgs {
297    pub x: f64,
298    pub y: f64,
299    pub delta_x: f64,
300    pub delta_y: f64,
301    pub modifiers: Vec<ModifierKeyMessage>,
302}
303
304#[derive(Deserialize)]
305#[repr(C)]
306pub struct MouseDownInterruptArgs {
307    pub x: f64,
308    pub y: f64,
309    pub button: MouseButtonMessage,
310    pub modifiers: Vec<ModifierKeyMessage>,
311}
312
313#[derive(Deserialize)]
314#[repr(C)]
315pub struct MouseUpInterruptArgs {
316    pub x: f64,
317    pub y: f64,
318    pub button: MouseButtonMessage,
319    pub modifiers: Vec<ModifierKeyMessage>,
320}
321
322#[derive(Deserialize)]
323#[repr(C)]
324pub struct MouseOverInterruptArgs {
325    pub x: f64,
326    pub y: f64,
327    pub button: MouseButtonMessage,
328    pub modifiers: Vec<ModifierKeyMessage>,
329}
330
331#[derive(Deserialize)]
332#[repr(C)]
333pub struct MouseOutInterruptArgs {
334    pub x: f64,
335    pub y: f64,
336    pub button: MouseButtonMessage,
337    pub modifiers: Vec<ModifierKeyMessage>,
338}
339
340#[derive(Deserialize)]
341#[repr(C)]
342pub struct ContextMenuInterruptArgs {
343    pub x: f64,
344    pub y: f64,
345    pub button: MouseButtonMessage,
346    pub modifiers: Vec<ModifierKeyMessage>,
347}
348
349#[derive(Deserialize)]
350#[repr(C)]
351pub enum ImageLoadInterruptArgs {
352    Reference(ImagePointerArgs),
353    Data(ImageDataArgs),
354}
355#[derive(Deserialize)]
356#[repr(C)]
357pub struct ImagePointerArgs {
358    pub id: u32,
359    pub path: String,
360    pub image_data: u64,
361    pub image_data_length: usize,
362    pub width: usize,
363    pub height: usize,
364}
365
366#[derive(Deserialize)]
367#[repr(C)]
368pub struct ImageDataArgs {
369    pub id: u32,
370    pub path: String,
371    pub width: usize,
372    pub height: usize,
373}
374
375#[repr(C)]
376pub struct InterruptBuffer {
377    pub data_ptr: *const u8,
378    pub length: u64,
379}
380
381#[repr(C)]
382pub struct NativeMessageQueue {
383    pub data_ptr: *mut [u8],
384    pub length: u64,
385}
386
387#[derive(Serialize)]
388pub struct MessageQueue {
389    pub messages: Vec<NativeMessage>,
390}
391
392#[derive(Deserialize)]
393#[repr(C)]
394pub struct AddedLayerArgs {
395    pub num_layers_added: u32,
396}
397
398#[cfg_attr(debug_assertions, derive(Debug))]
399#[derive(Default, Serialize)]
400#[repr(C)]
401pub struct FramePatch {
402    pub id: u32,
403    pub clip_content: Option<bool>,
404    pub size_x: Option<f64>,
405    pub size_y: Option<f64>,
406    pub transform: Option<Vec<f64>>,
407}
408
409#[cfg_attr(debug_assertions, derive(Debug))]
410#[derive(Default, Serialize)]
411#[repr(C)]
412pub struct EventBlockerPatch {
413    pub id: u32,
414    pub size_x: Option<f64>,
415    pub size_y: Option<f64>,
416    pub transform: Option<Vec<f64>>,
417}
418
419#[cfg_attr(debug_assertions, derive(Debug))]
420#[derive(Default, Serialize, Clone)]
421#[repr(C)]
422pub struct CheckboxPatch {
423    pub id: u32,
424    pub background: Option<ColorMessage>,
425    pub background_checked: Option<ColorMessage>,
426    pub outline_color: Option<ColorMessage>,
427    pub outline_width: Option<f64>,
428    pub border_radius: Option<f64>,
429    pub transform: Option<Vec<f64>>,
430    pub size_x: Option<f64>,
431    pub size_y: Option<f64>,
432    pub checked: Option<bool>,
433}
434
435#[cfg_attr(debug_assertions, derive(Debug))]
436#[derive(Default, Serialize, Clone)]
437#[repr(C)]
438pub struct NativeImagePatch {
439    pub id: u32,
440    pub transform: Option<Vec<f64>>,
441    pub size_x: Option<f64>,
442    pub size_y: Option<f64>,
443    pub url: Option<String>,
444    pub fit: Option<String>,
445}
446
447#[cfg_attr(debug_assertions, derive(Debug))]
448#[derive(Default, Serialize, Clone)]
449#[repr(C)]
450pub struct YoutubeVideoPatch {
451    pub id: u32,
452    pub transform: Option<Vec<f64>>,
453    pub size_x: Option<f64>,
454    pub size_y: Option<f64>,
455    pub url: Option<String>,
456}
457
458#[cfg_attr(debug_assertions, derive(Debug))]
459#[derive(Default, Serialize, Clone)]
460#[repr(C)]
461pub struct DropdownPatch {
462    pub id: u32,
463    pub selected_id: Option<u32>,
464    pub options: Option<Vec<String>>,
465    pub transform: Option<Vec<f64>>,
466    pub size_x: Option<f64>,
467    pub size_y: Option<f64>,
468    pub background: Option<ColorMessage>,
469    pub stroke_color: Option<ColorMessage>,
470    pub stroke_width: Option<f64>,
471    pub border_radius: Option<f64>,
472    pub style: Option<TextStyleMessage>,
473}
474
475#[cfg_attr(debug_assertions, derive(Debug))]
476#[derive(Default, Serialize, Clone)]
477#[repr(C)]
478pub struct RadioSetPatch {
479    pub id: u32,
480    pub selected_id: Option<u32>,
481    pub options: Option<Vec<String>>,
482    pub style: Option<TextStyleMessage>,
483    pub background_checked: Option<ColorMessage>,
484    pub outline_color: Option<ColorMessage>,
485    pub outline_width: Option<f64>,
486    pub background: Option<ColorMessage>,
487    pub transform: Option<Vec<f64>>,
488    pub size_x: Option<f64>,
489    pub size_y: Option<f64>,
490}
491
492#[cfg_attr(debug_assertions, derive(Debug))]
493#[derive(Default, Serialize, Clone)]
494#[repr(C)]
495pub struct SliderPatch {
496    pub id: u32,
497    pub value: Option<f64>,
498    pub step: Option<f64>,
499    pub min: Option<f64>,
500    pub max: Option<f64>,
501    pub transform: Option<Vec<f64>>,
502    pub size_x: Option<f64>,
503    pub size_y: Option<f64>,
504    pub accent: Option<ColorMessage>,
505    pub background: Option<ColorMessage>,
506    pub border_radius: Option<f64>,
507}
508
509#[cfg_attr(debug_assertions, derive(Debug))]
510#[derive(Default, Serialize, Clone)]
511#[repr(C)]
512pub struct TextboxPatch {
513    pub id: u32,
514    pub transform: Option<Vec<f64>>,
515    pub size_x: Option<f64>,
516    pub size_y: Option<f64>,
517    pub text: Option<String>,
518    pub background: Option<ColorMessage>,
519    pub stroke_color: Option<ColorMessage>,
520    pub stroke_width: Option<f64>,
521    pub border_radius: Option<f64>,
522    pub style: Option<TextStyleMessage>,
523    pub focus_on_mount: Option<bool>,
524    pub placeholder: Option<String>,
525    pub outline_color: Option<ColorMessage>,
526    pub outline_width: Option<f64>,
527    pub is_text_area: Option<bool>,
528}
529
530#[cfg_attr(debug_assertions, derive(Debug))]
531#[derive(Default, Serialize)]
532#[repr(C)]
533pub struct ButtonPatch {
534    pub id: u32,
535    pub hover_color: Option<ColorMessage>,
536    pub outline_stroke_color: Option<ColorMessage>,
537    pub outline_stroke_width: Option<f64>,
538    pub border_radius: Option<f64>,
539    pub transform: Option<Vec<f64>>,
540    pub size_x: Option<f64>,
541    pub size_y: Option<f64>,
542    pub content: Option<String>,
543    pub color: Option<ColorMessage>,
544    pub style: Option<TextStyleMessage>,
545}
546
547#[derive(Default, Serialize)]
548#[repr(C)]
549pub struct CheckboxStyleMessage {
550    //pub fill: Option<ColorMessage>,
551}
552
553#[cfg_attr(debug_assertions, derive(Debug))]
554#[derive(Default, Serialize)]
555#[repr(C)]
556pub struct OcclusionPatch {
557    pub id: u32,
558    pub occlusion_layer_id: usize,
559    pub z_index: i32,
560    pub parent_frame: Option<u32>,
561}
562
563#[cfg_attr(debug_assertions, derive(Debug))]
564#[derive(Default, Serialize)]
565#[repr(C)]
566pub struct NavigationPatch {
567    pub url: String,
568    pub target: String,
569}
570
571#[cfg_attr(debug_assertions, derive(Debug))]
572#[derive(Default, Serialize)]
573#[repr(C)]
574pub struct SetCursorPatch {
575    pub cursor: String,
576}
577
578#[cfg_attr(debug_assertions, derive(Debug))]
579#[derive(Default, Serialize, Clone)]
580#[repr(C)]
581pub struct TextPatch {
582    pub id: u32,
583    pub content: Option<String>,
584    pub editable: Option<bool>,
585    pub selectable: Option<bool>,
586    pub markdown: Option<bool>,
587    pub transform: Option<Vec<f64>>,
588    pub size_x: Option<f64>,
589    pub size_y: Option<f64>,
590    pub style: Option<TextStyleMessage>,
591    pub style_link: Option<TextStyleMessage>,
592}
593
594#[cfg_attr(debug_assertions, derive(Debug))]
595#[derive(Default, Serialize, Clone, PartialEq)]
596#[repr(C)]
597pub struct TextStyleMessage {
598    pub font: Option<FontPatch>,
599    pub font_size: Option<f64>,
600    pub fill: Option<ColorMessage>,
601    pub underline: Option<bool>,
602    pub align_multiline: Option<TextAlignHorizontalMessage>,
603    pub align_vertical: Option<TextAlignVerticalMessage>,
604    pub align_horizontal: Option<TextAlignHorizontalMessage>,
605}
606
607#[cfg_attr(debug_assertions, derive(Debug))]
608#[derive(Default, Serialize)]
609#[repr(C)]
610pub struct ImagePatch {
611    pub id: u32,
612    pub path: Option<String>,
613}
614
615#[cfg_attr(debug_assertions, derive(Debug))]
616#[derive(Serialize, Clone, PartialEq)]
617#[repr(C)]
618pub enum ColorMessage {
619    Rgba([f64; 4]),
620    Rgb([f64; 3]),
621}
622
623impl Default for ColorMessage {
624    fn default() -> Self {
625        ColorMessage::Rgba([1.0, 0.5, 0.0, 1.0])
626    }
627}
628
629#[cfg_attr(debug_assertions, derive(Debug))]
630#[derive(Default, Serialize, Clone, PartialEq)]
631#[repr(C)]
632pub enum TextAlignHorizontalMessage {
633    #[default]
634    Left,
635    Center,
636    Right,
637}
638
639#[cfg_attr(debug_assertions, derive(Debug))]
640#[derive(Default, Serialize, Clone, PartialEq)]
641#[repr(C)]
642pub enum TextAlignVerticalMessage {
643    #[default]
644    Top,
645    Center,
646    Bottom,
647}
648
649#[derive(Serialize)]
650#[repr(C)]
651pub struct LinkStyleMessage {
652    pub font: Option<FontPatch>,
653    pub fill: Option<ColorMessage>,
654    pub underline: Option<bool>,
655    pub size: Option<f64>,
656}
657
658#[cfg_attr(debug_assertions, derive(Debug))]
659#[derive(Default, Serialize)]
660#[repr(C)]
661pub struct ScrollerPatch {
662    pub id: u32,
663    pub transform: Option<Vec<f64>>,
664    pub size_x: Option<f64>,
665    pub size_y: Option<f64>,
666    pub size_inner_pane_x: Option<f64>,
667    pub size_inner_pane_y: Option<f64>,
668    pub scroll_x: Option<f64>,
669    pub scroll_y: Option<f64>,
670    pub scroll_enabled_x: Option<bool>,
671    pub scroll_enabled_y: Option<bool>,
672    pub subtree_depth: u32,
673}
674
675#[cfg_attr(debug_assertions, derive(Debug))]
676#[derive(Serialize)]
677#[repr(C)]
678pub struct AnyCreatePatch {
679    pub id: u32,
680    pub parent_frame: Option<u32>,
681    pub occlusion_layer_id: u32,
682}
683
684// Possible approach to heterogeneous rich text:
685// #[repr(C)]
686// pub struct TextCommand {
687//     pub set_font: Option<String>,
688//     pub set_weight: Option<String>,
689//     pub set_fill_color: Option<String>,
690//     pub set_stroke_color: Option<String>,
691//     pub set_decoration: Option<String>,
692// }
693
694#[cfg_attr(debug_assertions, derive(Debug))]
695#[derive(Serialize, Clone, PartialEq)]
696#[repr(C)]
697pub enum FontPatch {
698    System(SystemFontMessage),
699    Web(WebFontMessage),
700    Local(LocalFontMessage),
701}
702
703impl Default for FontPatch {
704    fn default() -> Self {
705        Self::System(SystemFontMessage::default())
706    }
707}
708
709#[cfg_attr(debug_assertions, derive(Debug))]
710#[derive(Serialize, Clone, PartialEq)]
711#[repr(C)]
712pub struct SystemFontMessage {
713    pub family: Option<String>,
714    pub style: Option<FontStyleMessage>,
715    pub weight: Option<FontWeightMessage>,
716}
717
718impl Default for SystemFontMessage {
719    fn default() -> Self {
720        Self {
721            family: Some("Brush Script MT".to_string()),
722            style: Some(FontStyleMessage::Normal),
723            weight: Some(FontWeightMessage::Normal),
724        }
725    }
726}
727
728#[cfg_attr(debug_assertions, derive(Debug))]
729#[derive(Serialize, Clone, PartialEq)]
730#[repr(C)]
731pub struct WebFontMessage {
732    pub family: Option<String>,
733    pub url: Option<String>,
734    pub style: Option<FontStyleMessage>,
735    pub weight: Option<FontWeightMessage>,
736}
737
738#[cfg_attr(debug_assertions, derive(Debug))]
739#[derive(Serialize, Clone, PartialEq)]
740#[repr(C)]
741pub struct LocalFontMessage {
742    pub family: Option<String>,
743    pub path: Option<String>,
744    pub style: Option<FontStyleMessage>,
745    pub weight: Option<FontWeightMessage>,
746}
747
748#[cfg_attr(debug_assertions, derive(Debug))]
749#[derive(Clone, Serialize, PartialEq)]
750#[repr(C)]
751pub enum FontStyleMessage {
752    Normal,
753    Italic,
754    Oblique,
755}
756
757#[cfg_attr(debug_assertions, derive(Debug))]
758#[derive(Clone, Serialize, PartialEq)]
759#[repr(C)]
760pub enum FontWeightMessage {
761    Thin,
762    ExtraLight,
763    Light,
764    Normal,
765    Medium,
766    SemiBold,
767    Bold,
768    ExtraBold,
769    Black,
770}
771
772#[cfg_attr(debug_assertions, derive(Debug))]
773#[derive(Serialize)]
774#[repr(C)]
775pub struct LayerAddPatch {
776    pub num_layers_to_add: usize,
777}