xcomponent_sys/
lib.rs

1// Native XComponent bindings
2//
3// ## When to Use
4//
5// NativeXComponent provides an instance for the <XComponent> at the native layer, which can be
6// used as a bridge for binding with the <XComponent> at the JS layer. The NDK APIs provided by the
7// <XComponent> depend on this instance. The provided APIs include those for obtaining a native
8// window, obtaining the layout or event information of the <XComponent>, registering the lifecycle
9// callbacks of the <XComponent>, and registering the callbacks for the touch, mouse, and key events
10// of the <XComponent>. You can use the provided APIs in the following scenarios:
11//
12//  * Register the lifecycle and event callbacks of the <XComponent>.
13//  * Initialize the environment, obtain the current state, and respond to various events via these callbacks.
14//  * Use the native window and EGL APIs to develop custom drawing content, and apply for and submit buffers to the graphics queue.
15//! Source:
16//!
17//! [English Documentation](https://docs.openharmony.cn/pages/v5.0/en/application-dev/ui/napi-xcomponent-guidelines.md)
18//! [Chinese Documentation](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/ui/napi-xcomponent-guidelines.md)
19//!
20//! ## Feature flags
21#![cfg_attr(
22    feature = "document-features",
23    cfg_attr(doc, doc = ::document_features::document_features!())
24)]
25#![cfg_attr(docsrs, feature(doc_cfg))]
26
27#[link(name = "ace_ndk.z")]
28extern "C" {}
29
30mod xcomponent_ffi;
31pub use xcomponent_ffi::*;
32
33#[cfg(feature = "arkui")]
34mod xcomponent_arkui_ffi;
35#[cfg(feature = "arkui")]
36pub use xcomponent_arkui_ffi::*;
37
38mod xcomponent_result_ffi;
39
40/// Enumerates the API access states.
41///
42/// Available since API 8.
43#[repr(transparent)]
44pub struct XcomponentResult(pub std::ffi::c_int);
45
46impl XcomponentResult {
47    pub const SUCCESS: Self = Self(0);
48    pub const FAILED: Self = Self(-1);
49    pub const BAD_PARAMETER: Self = Self(-2);
50}
51
52// assert that our handwritten binding matches the size of the generated binding.
53// needs to be updated when regenerating the bindings, since the bindgen type name
54// may change.
55#[allow(dead_code)]
56const ASSERT_SIZE_OK: () =
57    assert!(size_of::<XcomponentResult>() == size_of::<xcomponent_result_ffi::_bindgen_ty_13>());
58
59#[cfg(feature = "keyboard-types")]
60#[cfg_attr(docsrs, doc(cfg(feature = "keyboard-types")))]
61pub mod keyboard_types_compat;