wasm_bindings/
prelude.rs

1use crate::FunctionCall;
2
3#[link(wasm_import_module = "host")]
4unsafe extern "C" {
5    #[link_name = "xila_graphics_call"]
6    pub fn xila_graphics_call(
7        function: FunctionCall,
8        argument_0: usize,
9        argument_1: usize,
10        argument_2: usize,
11        argument_3: usize,
12        argument_4: usize,
13        argument_5: usize,
14        argument_6: usize,
15        argument_count: u8,
16        return_value: *mut core::ffi::c_void,
17    ) -> i32;
18}
19
20pub type Error = i32;
21
22pub type Result<T> = core::result::Result<T, Error>;
23
24#[repr(C)]
25pub struct Object {
26    _private: [u8; 0],
27}
28
29#[repr(C)]
30#[derive(Clone, Copy)]
31pub struct Color {
32    pub blue: u8,
33    pub green: u8,
34    pub red: u8,
35}
36
37#[repr(C)]
38#[derive(Clone, Copy)]
39pub struct Color16 {
40    _bitfield: u16,
41}
42
43impl Color16 {
44    pub fn new(red: u8, green: u8, blue: u8) -> Self {
45        let red = (red as u16 & 0x1F) << 11;
46        let green = (green as u16 & 0x3F) << 5;
47        let blue = blue as u16 & 0x1F;
48        Self {
49            _bitfield: red | green | blue,
50        }
51    }
52
53    pub fn red(&self) -> u8 {
54        ((self._bitfield >> 11) & 0x1F) as u8
55    }
56
57    pub fn green(&self) -> u8 {
58        ((self._bitfield >> 5) & 0x3F) as u8
59    }
60
61    pub fn blue(&self) -> u8 {
62        (self._bitfield & 0x1F) as u8
63    }
64}
65
66#[repr(C)]
67#[derive(Clone, Copy)]
68pub struct Color32 {
69    pub blue: u8,
70    pub green: u8,
71    pub red: u8,
72    pub alpha: u8,
73}
74
75#[repr(C)]
76pub struct ColorHsv {
77    pub h: u16,
78    pub s: u8,
79    pub v: u8,
80}
81
82#[repr(C)]
83pub struct Color16a {
84    pub lumi: u8,
85    pub alpha: u8,
86}
87
88#[repr(C)]
89pub struct Point {
90    pub x: i32,
91    pub y: i32,
92}
93
94#[repr(C)]
95pub struct Area {
96    pub x1: i32,
97    pub y1: i32,
98    pub x2: i32,
99    pub y2: i32,
100}
101
102pub type ValuePrecise = i32;
103
104#[repr(C)]
105pub struct PointPrecise {
106    pub x: ValuePrecise,
107    pub y: ValuePrecise,
108}
109
110#[repr(C)]
111#[derive(Clone, Copy, Debug, PartialEq, Eq)]
112pub enum ColorFormat {
113    Unknown = 0,
114    Raw = 1,
115    RawAlpha = 2,
116    L8 = 6,
117    I1 = 7,
118    I2 = 8,
119    I4 = 9,
120    I8 = 10,
121    A8 = 14,
122    Rgb565 = 18,
123    Argb8565 = 19,
124    Rgb565a8 = 20,
125    Al88 = 21,
126    Rgb565Swapped = 27,
127    Rgb888 = 15,
128    Argb8888 = 16,
129    Xrgb8888 = 17,
130    Argb8888Premultiplied = 26,
131    A1 = 11,
132    A2 = 12,
133    A4 = 13,
134    Argb1555 = 22,
135    Argb4444 = 23,
136    Argb2222 = 24,
137    I420 = 32,
138    I422 = 33,
139    I444 = 34,
140    I400 = 35,
141    Nv21 = 36,
142    Nv12 = 37,
143    Yuy2 = 38,
144    Uyvy = 39,
145    NemaTsc4 = 48,
146    NemaTsc6 = 49,
147    NemaTsc6a = 50,
148    NemaTsc6ap = 51,
149    NemaTsc12 = 52,
150    NemaTsc12a = 53,
151}
152
153#[repr(C)]
154#[derive(Clone, Copy, Debug, PartialEq, Eq)]
155pub enum FlexAlign {
156    Start,
157    End,
158    Center,
159    SpaceEvenly,
160    SpaceAround,
161    SpaceBetween,
162}
163
164pub const FLEX_COLUMN: u8 = 1 << 0;
165pub const FLEX_WRAP: u8 = 1 << 2;
166pub const FLEX_REVERSE: u8 = 1 << 3;
167
168pub type StyleProp = u8;
169pub type Opa = u8;
170
171#[repr(C)]
172#[derive(Clone, Copy, Debug, PartialEq, Eq)]
173pub enum FlexFlow {
174    Row = 0x00,
175    Column = FLEX_COLUMN as isize,
176    RowWrap = FLEX_WRAP as isize,
177    RowReverse = FLEX_REVERSE as isize,
178    RowWrapReverse = FLEX_WRAP as isize | FLEX_REVERSE as isize,
179    ColumnWrap = FLEX_COLUMN as isize | FLEX_WRAP as isize,
180    ColumnReverse = FLEX_COLUMN as isize | FLEX_REVERSE as isize,
181    ColumnWrapReverse = FLEX_COLUMN as isize | FLEX_WRAP as isize | FLEX_REVERSE as isize,
182}
183
184#[repr(C)]
185#[derive(Clone, Copy, Debug, PartialEq, Eq)]
186pub enum GradDir {
187    None,
188    Ver,
189    Hor,
190    Linear,
191    Radial,
192    Conical,
193}
194
195#[repr(C)]
196#[derive(Clone, Copy, Debug, PartialEq, Eq)]
197pub enum BlendMode {
198    Normal,
199    Additive,
200    Subtractive,
201    Multiply,
202}
203
204#[repr(C)]
205#[derive(Clone, Copy, Debug, PartialEq, Eq)]
206pub enum TextDecor {
207    None = 0x00,
208    Underline = 0x01,
209    Strikethrough = 0x02,
210}
211
212#[repr(C)]
213#[derive(Clone, Copy, Debug, PartialEq, Eq)]
214pub enum BorderSide {
215    None = 0x00,
216    Bottom = 0x01,
217    Top = 0x02,
218    Left = 0x04,
219    Right = 0x08,
220    Full = 0x0F,
221    Internal = 0x10,
222}
223
224pub type Anim = u8;
225
226#[repr(C)]
227#[derive(Clone, Copy, Debug, PartialEq, Eq)]
228pub enum StyleStateCmp {
229    Same,
230    DiffRedraw,
231    DiffDrawPad,
232    DiffLayout,
233}
234
235pub type StyleSelector = u32;
236pub type ObjectHandle = u16;
237pub type LvObject = u16;
238pub type Part = u32;
239
240#[repr(C)]
241pub struct ChartSeries {
242    pub x_points: *mut i32,
243    pub y_points: *mut i32,
244    pub color: Color,
245    pub start_point: u32,
246    _bitfield: u32,
247}
248
249impl ChartSeries {
250    pub fn hidden(&self) -> bool {
251        (self._bitfield & 0x01) != 0
252    }
253
254    pub fn set_hidden(&mut self, value: bool) {
255        if value {
256            self._bitfield |= 0x01;
257        } else {
258            self._bitfield &= !0x01;
259        }
260    }
261
262    pub fn x_ext_buf_assigned(&self) -> bool {
263        (self._bitfield & 0x02) != 0
264    }
265
266    pub fn y_ext_buf_assigned(&self) -> bool {
267        (self._bitfield & 0x04) != 0
268    }
269
270    pub fn x_axis_sec(&self) -> bool {
271        (self._bitfield & 0x08) != 0
272    }
273
274    pub fn y_axis_sec(&self) -> bool {
275        (self._bitfield & 0x10) != 0
276    }
277}
278
279#[repr(C)]
280#[derive(Clone, Copy, Debug, PartialEq, Eq)]
281pub enum ChartType {
282    None,
283    Line,
284    Bar,
285    Scatter,
286}
287
288pub type Style = *mut core::ffi::c_void;
289
290#[repr(C)]
291pub struct Font {
292    _private: [u8; 0],
293}
294
295#[repr(C)]
296#[derive(Clone, Copy, Debug, PartialEq, Eq)]
297pub enum Dir {
298    None = 0x00,
299    Left = 1 << 0,
300    Right = 1 << 1,
301    Top = 1 << 2,
302    Bottom = 1 << 3,
303    Hor = (1 << 0) | (1 << 1),
304    Ver = (1 << 2) | (1 << 3),
305    All = (1 << 0) | (1 << 1) | (1 << 2) | (1 << 3),
306}
307
308#[repr(C)]
309pub struct CalendarDate {
310    pub year: u16,
311    pub month: i8,
312    pub day: i8,
313}
314
315#[repr(C)]
316#[derive(Clone, Copy, Debug, PartialEq, Eq)]
317pub enum Align {
318    Default = 0,
319    TopLeft,
320    TopMid,
321    TopRight,
322    BottomLeft,
323    BottomMid,
324    BottomRight,
325    LeftMid,
326    RightMid,
327    Center,
328    OutTopLeft,
329    OutTopMid,
330    OutTopRight,
331    OutBottomLeft,
332    OutBottomMid,
333    OutBottomRight,
334    OutLeftTop,
335    OutLeftMid,
336    OutLeftBottom,
337    OutRightTop,
338    OutRightMid,
339    OutRightBottom,
340}
341
342#[repr(C)]
343#[derive(Clone, Copy, Debug, PartialEq, Eq)]
344pub enum GridAlign {
345    Start,
346    Center,
347    End,
348    Stretch,
349    SpaceEvenly,
350    SpaceAround,
351    SpaceBetween,
352}
353
354pub type ObjectClass = u16;
355
356#[repr(C)]
357#[derive(Clone, Copy, Debug, PartialEq, Eq)]
358pub enum ButtonmatrixCtrl {
359    Hidden = 0x0010,
360    NoRepeat = 0x0020,
361    Disabled = 0x0040,
362    Checkable = 0x0080,
363    Checked = 0x0100,
364    ClickTrig = 0x0200,
365    Popover = 0x0400,
366    Reserved1 = 0x0800,
367    Reserved2 = 0x1000,
368    Reserved3 = 0x2000,
369    Custom1 = 0x4000,
370    Custom2 = 0x8000,
371}
372
373#[repr(C)]
374#[derive(Clone, Copy, Debug, PartialEq, Eq)]
375pub enum ArcMode {
376    Normal,
377    Symmetrical,
378    Reverse,
379}
380
381#[repr(C)]
382#[derive(Clone, Copy, Debug, PartialEq, Eq)]
383pub enum MenuModeHeader {
384    TopFixed,
385    TopUnfixed,
386    BottomFixed,
387}
388
389#[repr(C)]
390#[derive(Clone, Copy, Debug, PartialEq, Eq)]
391pub enum MenuModeRootBackButton {
392    Disabled,
393    Enabled,
394}
395
396#[repr(C)]
397#[derive(Clone, Copy, Debug, PartialEq, Eq)]
398pub enum RollerMode {
399    Normal,
400    Infinite,
401}
402
403#[repr(C)]
404#[derive(Clone, Copy, Debug, PartialEq, Eq)]
405pub enum TableCellCtrl {
406    MergeRight = 1 << 0,
407    TextCrop = 1 << 1,
408    Custom1 = 1 << 4,
409    Custom2 = 1 << 5,
410    Custom3 = 1 << 6,
411    Custom4 = 1 << 7,
412}
413
414#[repr(C)]
415#[derive(Clone, Copy, Debug, PartialEq, Eq)]
416pub enum ObjectFlag {
417    Hidden = 1 << 0,
418    Clickable = 1 << 1,
419    ClickFocusable = 1 << 2,
420    Checkable = 1 << 3,
421    Scrollable = 1 << 4,
422    ScrollElastic = 1 << 5,
423    ScrollMomentum = 1 << 6,
424    ScrollOne = 1 << 7,
425    ScrollChainHor = 1 << 8,
426    ScrollChainVer = 1 << 9,
427    ScrollChain = (1 << 8) | (1 << 9),
428    ScrollOnFocus = 1 << 10,
429    ScrollWithArrow = 1 << 11,
430    Snappable = 1 << 12,
431    PressLock = 1 << 13,
432    EventBubble = 1 << 14,
433    GestureBubble = 1 << 15,
434    AdvHittest = 1 << 16,
435    IgnoreLayout = 1 << 17,
436    Floating = 1 << 18,
437    SendDrawTaskEvents = 1 << 19,
438    OverflowVisible = 1 << 20,
439    FlexInNewTrack = 1 << 21,
440    Layout1 = 1 << 23,
441    Layout2 = 1 << 24,
442    Widget1 = 1 << 25,
443    Widget2 = 1 << 26,
444    User1 = 1 << 27,
445    User2 = 1 << 28,
446    User3 = 1 << 29,
447    User4 = 1 << 30,
448}
449
450pub type State = u16;
451
452pub const STATE_DEFAULT: u16 = 0x0000;
453pub const STATE_CHECKED: u16 = 0x0001;
454pub const STATE_FOCUSED: u16 = 0x0002;
455pub const STATE_FOCUS_KEY: u16 = 0x0004;
456pub const STATE_EDITED: u16 = 0x0008;
457pub const STATE_HOVERED: u16 = 0x0010;
458pub const STATE_PRESSED: u16 = 0x0020;
459pub const STATE_SCROLLED: u16 = 0x0040;
460pub const STATE_DISABLED: u16 = 0x0080;
461pub const STATE_USER_1: u16 = 0x1000;
462pub const STATE_USER_2: u16 = 0x2000;
463pub const STATE_USER_3: u16 = 0x4000;
464pub const STATE_USER_4: u16 = 0x8000;
465pub const STATE_ANY: u16 = 0xFFFF;
466
467pub const PART_MAIN: u32 = 0x000000;
468pub const PART_SCROLLBAR: u32 = 0x010000;
469pub const PART_INDICATOR: u32 = 0x020000;
470pub const PART_KNOB: u32 = 0x030000;
471pub const PART_SELECTED: u32 = 0x040000;
472pub const PART_ITEMS: u32 = 0x050000;
473pub const PART_CURSOR: u32 = 0x060000;
474pub const PART_CUSTOM_FIRST: u32 = 0x080000;
475pub const PART_ANY: u32 = 0x0F0000;
476
477#[repr(C)]
478#[derive(Clone, Copy, Debug, PartialEq, Eq)]
479pub enum TextFlag {
480    None = 0x00,
481    Expand = 0x01,
482    Fit = 0x02,
483    BreakAll = 0x04,
484}
485
486#[repr(C)]
487#[derive(Clone, Copy, Debug, PartialEq, Eq)]
488pub enum TextAlign {
489    Auto,
490    Left,
491    Center,
492    Right,
493}
494
495#[repr(C)]
496#[derive(Clone, Copy, Debug, PartialEq, Eq)]
497pub enum ObjectPointTransformFlag {
498    None = 0x00,
499    Recursive = 0x01,
500    Inverse = 0x02,
501    InverseRecursive = 0x03,
502}
503
504#[repr(C)]
505pub struct Group {
506    _private: [u8; 0],
507}
508
509#[repr(C)]
510#[derive(Clone, Copy, Debug, PartialEq, Eq)]
511pub enum AnimEnable {
512    Off,
513    On,
514}
515
516#[repr(C)]
517#[derive(Clone, Copy, Debug, PartialEq, Eq)]
518pub enum BaseDir {
519    Ltr = 0x00,
520    Rtl = 0x01,
521    Auto = 0x02,
522    Neutral = 0x20,
523    Weak = 0x21,
524}
525
526#[repr(C)]
527pub struct Display {
528    _private: [u8; 0],
529}
530
531#[repr(C)]
532#[derive(Clone, Copy, Debug, PartialEq, Eq)]
533pub enum ScrollbarMode {
534    Off,
535    On,
536    Active,
537    Auto,
538}
539
540#[repr(C)]
541#[derive(Clone, Copy, Debug, PartialEq, Eq)]
542pub enum ScrollSnap {
543    None,
544    Start,
545    End,
546    Center,
547}
548
549#[repr(C)]
550#[derive(Clone, Copy, Debug, PartialEq, Eq)]
551pub enum ScaleMode {
552    HorizontalTop = 0x00,
553    HorizontalBottom = 0x01,
554    VerticalLeft = 0x02,
555    VerticalRight = 0x04,
556    RoundInner = 0x08,
557    RoundOuter = 0x10,
558    Last,
559}
560
561#[repr(C)]
562pub struct ScaleSection {
563    _private: [u8; 0],
564}
565
566#[repr(C)]
567#[derive(Clone, Copy, Debug, PartialEq, Eq)]
568pub enum BarMode {
569    Normal,
570    Symmetrical,
571    Range,
572}
573
574#[repr(C)]
575#[derive(Clone, Copy, Debug, PartialEq, Eq)]
576pub enum SliderMode {
577    Normal = 0,
578    Symmetrical = 1,
579    Range = 2,
580}
581
582#[repr(C)]
583#[derive(Clone, Copy, Debug, PartialEq, Eq)]
584pub enum BarOrientation {
585    Auto,
586    Horizontal,
587    Vertical,
588}
589
590#[repr(C)]
591#[derive(Clone, Copy, Debug, PartialEq, Eq)]
592pub enum SpanOverflow {
593    Clip,
594    Ellipsis,
595    Last,
596}
597
598#[repr(C)]
599#[derive(Clone, Copy, Debug, PartialEq, Eq)]
600pub enum SpanMode {
601    Fixed,
602    Expand,
603    Break,
604    Last,
605}
606
607#[repr(C)]
608pub struct ChartCursor {
609    _private: [u8; 0],
610}
611
612#[repr(C)]
613#[derive(Clone, Copy)]
614pub union StyleValue {
615    pub num: i32,
616    pub ptr: *const core::ffi::c_void,
617    pub color: Color,
618}
619
620#[repr(C)]
621pub struct Layer {
622    _private: [u8; 0],
623}
624
625#[repr(C)]
626#[derive(Clone, Copy, Debug, PartialEq, Eq)]
627pub enum ChartUpdateMode {
628    Shift,
629    Circular,
630}
631
632#[repr(C)]
633#[derive(Clone, Copy, Debug, PartialEq, Eq)]
634pub enum ChartAxis {
635    PrimaryY = 0x00,
636    SecondaryY = 0x01,
637    PrimaryX = 0x02,
638    SecondaryX = 0x04,
639    Last,
640}
641
642#[repr(C)]
643#[derive(Clone, Copy, Debug, PartialEq, Eq)]
644pub enum LvglResult {
645    Invalid = 0,
646    Ok,
647}
648
649#[repr(C)]
650#[derive(Clone, Copy, Debug, PartialEq, Eq)]
651pub enum StyleRes {
652    NotFound,
653    Found,
654}
655
656#[repr(C)]
657#[derive(Clone, Copy, Debug, PartialEq)]
658pub enum EventCode {
659    All = 0,
660    Pressed,
661    Pressing,
662    PressLost,
663    ShortClicked,
664    SingleClicked,
665    DoubleClicked,
666    TripleClicked,
667    LongPressed,
668    LongPressedRepeat,
669    Clicked,
670    Released,
671    ScrollBegin,
672    ScrollThrowBegin,
673    ScrollEnd,
674    Scroll,
675    Gesture,
676    Key,
677    Rotary,
678    Focused,
679    Defocused,
680    Leave,
681    HitTest,
682    IndevReset,
683    HoverOver,
684    HoverLeave,
685    CoverCheck,
686    RefreshExtDrawSize,
687    DrawMainBegin,
688    DrawMain,
689    DrawMainEnd,
690    DrawPostBegin,
691    DrawPost,
692    DrawPostEnd,
693    DrawTaskAdded,
694    ValueChanged,
695    Insert,
696    Refresh,
697    Ready,
698    Cancel,
699    Create,
700    Delete,
701    ChildChanged,
702    ChildCreated,
703    ChildDeleted,
704    ScreenUnloadStart,
705    ScreenLoadStart,
706    ScreenLoaded,
707    ScreenUnloaded,
708    SizeChanged,
709    StyleChanged,
710    LayoutChanged,
711    GetSelfSize,
712    InvalidateArea,
713    ResolutionChanged,
714    ColorFormatChanged,
715    RefreshRequest,
716    RefreshStart,
717    RefreshReady,
718    RenderStart,
719    RenderReady,
720    FlushStart,
721    FlushFinish,
722    FlushWaitStart,
723    FlushWaitFinish,
724    Vsync,
725    VsyncRequest,
726    Last,
727    Preprocess = 0x8000,
728    MarkedDeleting = 0x10000,
729}
730
731#[repr(C)]
732#[derive(Clone, Copy, Debug, PartialEq, Eq)]
733pub enum LabelLongMode {
734    Wrap,
735    Dot,
736    Scroll,
737    ScrollCircular,
738    Clip,
739}
740
741#[repr(C)]
742#[derive(Clone, Copy, Debug, PartialEq, Eq)]
743pub enum ScreenLoadAnim {
744    None,
745    OverLeft,
746    OverRight,
747    OverTop,
748    OverBottom,
749    MoveLeft,
750    MoveRight,
751    MoveTop,
752    MoveBottom,
753    FadeInOrOn,
754    FadeOut,
755    OutLeft,
756    OutRight,
757    OutTop,
758    OutBottom,
759}
760
761#[repr(C)]
762#[derive(Clone, Copy, Debug, PartialEq, Eq)]
763pub enum SliderOrientation {
764    Auto,
765    Horizontal,
766    Vertical,
767}
768
769#[repr(C)]
770pub struct Matrix {
771    pub m: [[f32; 3]; 3],
772}
773
774// Coordinate type constants
775pub const COORD_TYPE_SHIFT: u32 = 29;
776pub const COORD_TYPE_MASK: i32 = 3 << COORD_TYPE_SHIFT;
777pub const COORD_TYPE_PX: i32 = 0 << COORD_TYPE_SHIFT;
778pub const COORD_TYPE_SPEC: i32 = 1 << COORD_TYPE_SHIFT;
779pub const COORD_TYPE_PX_NEG: i32 = 3 << COORD_TYPE_SHIFT;
780pub const COORD_MAX: i32 = (1 << COORD_TYPE_SHIFT) - 1;
781pub const COORD_MIN: i32 = -COORD_MAX;
782
783// Helper functions for coordinates
784#[inline]
785pub fn coord_type(x: i32) -> i32 {
786    x & COORD_TYPE_MASK
787}
788
789#[inline]
790pub fn coord_plain(x: i32) -> i32 {
791    x & !COORD_TYPE_MASK
792}
793
794#[inline]
795pub fn coord_is_px(x: i32) -> bool {
796    coord_type(x) == COORD_TYPE_PX || coord_type(x) == COORD_TYPE_PX_NEG
797}
798
799#[inline]
800pub fn coord_is_spec(x: i32) -> bool {
801    coord_type(x) == COORD_TYPE_SPEC
802}
803
804#[inline]
805pub fn coord_set_spec(x: i32) -> i32 {
806    x | COORD_TYPE_SPEC
807}
808
809#[inline]
810pub fn max(a: i32, b: i32) -> i32 {
811    if a > b { a } else { b }
812}
813
814#[inline]
815pub fn min(a: i32, b: i32) -> i32 {
816    if a < b { a } else { b }
817}
818
819#[inline]
820pub fn pct(x: i32) -> i32 {
821    coord_set_spec(x)
822}
823
824#[inline]
825pub fn coord_is_pct(x: i32) -> bool {
826    coord_is_spec(x)
827}
828
829#[inline]
830pub fn coord_get_pct(x: i32) -> i32 {
831    coord_plain(x)
832}
833
834#[inline]
835pub fn size_content() -> i32 {
836    coord_set_spec(COORD_MAX)
837}
838
839pub fn as_usize<T: Copy>(value: T) -> usize {
840    assert!(size_of::<T>() <= size_of::<usize>());
841
842    let mut bytes = [0u8; size_of::<usize>()];
843    let src =
844        unsafe { core::slice::from_raw_parts(&value as *const _ as *const u8, size_of::<T>()) };
845    bytes[..size_of::<T>()].copy_from_slice(src);
846    usize::from_ne_bytes(bytes)
847}