diff --git a/components/arkui/Cargo.toml b/components/arkui/Cargo.toml new file mode 100644 index 0000000..7f4e528 --- /dev/null +++ b/components/arkui/Cargo.toml @@ -0,0 +1,34 @@ +[package] +name = "arkui-sys" +version = "0.1.0" +edition = "2021" +description = "Bindings to the native ArkUI API of OpenHarmony" +license = "Apache-2.0" +repository = "https://github.com/openharmony-rs/ohos-sys" +keywords = ["OpenHarmony", "HarmonyOS", "ArkUI", "UI"] +exclude = ["src/**/*_nopublish.rs"] +readme = "README.md" + +[dependencies] +document-features = { version = "0.2", optional = true } + +[features] +default = [] + +#! ### OpenHarmony API level +#! The `arkUI` native module was added in API-level 12. +#! Defaults to no bindings at all, to maintain feature composability in `ohos-sys`. +#! Optionally enable one of the `api-*` features to get access to bindings for newer +#! OpenHarmony versions. + +## Enables bindings for OpenHarmony API-level 12. +api-12 = [] + + +## Document available features when building the documentation +document-features = ["dep:document-features"] + +[package.metadata.docs.rs] +features = ["document-features"] +targets = ["aarch64-unknown-linux-ohos", "armv7-unknown-linux-ohos", "x86_64-unknown-linux-ohos"] +all-features = true diff --git a/components/arkui/LICENSE b/components/arkui/LICENSE new file mode 100644 index 0000000..1b5ec8b --- /dev/null +++ b/components/arkui/LICENSE @@ -0,0 +1,176 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + +TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + +1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + +2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + +3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + +4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + +5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + +6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + +7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + +8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + +9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + +END OF TERMS AND CONDITIONS diff --git a/components/arkui/README.md b/components/arkui/README.md new file mode 100644 index 0000000..6afeb27 --- /dev/null +++ b/components/arkui/README.md @@ -0,0 +1,12 @@ +## ArkUI native bindings for OpenHarmony + +Raw bindings to native [ArkUI](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/reference/apis-arkui/_ark_u_i___native_module.md) +APIs on OpenHarmony. + +## Development + +This crate is developed as part of the [ohos-sys](https://github.com/openharmony-rs/ohos-sys) bindings. + +## License + +This crate is licensed under the Apache-2.0 license, matching the OpenHarmony OS SDK. diff --git a/components/arkui/src/lib.rs b/components/arkui/src/lib.rs new file mode 100644 index 0000000..365f085 --- /dev/null +++ b/components/arkui/src/lib.rs @@ -0,0 +1,34 @@ +//! ArkUI Native +//! +//! A module to interact with ArkUI from native Rust code. It provides: +//! +//! - drag and drop APIs of ArkUI +//! - APIs of ArkUI to register gesture callbacks. +//! - animation callbacks of ArkUI +//! - UI capabilities such as UI component creation and destruction, tree node operations, +//! attribute setting, and event listening. +//! +//! See the official upstream documentation on [ArkUI Native] for more information. +//! +//! [ArkUI Native]: https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/reference/apis-arkui/_ark_u_i___native_module.md +//! +//! ## Feature flags +#![cfg_attr( + feature = "document-features", + cfg_attr(doc, doc = ::document_features::document_features!()) +)] +#![cfg_attr(docsrs, feature(doc_cfg))] + +#[link(name = "ace_ndk.z")] +extern "C" {} + +#[cfg(feature = "api-12")] +#[cfg_attr(docsrs, doc(cfg(feature = "api-12")))] +pub mod native_gesture; +#[cfg(feature = "api-12")] +#[cfg_attr(docsrs, doc(cfg(feature = "api-12")))] +pub mod native_type; + +#[cfg(feature = "api-12")] +#[cfg_attr(docsrs, doc(cfg(feature = "api-12")))] +pub mod ui_input_event; diff --git a/components/arkui/src/native_gesture.rs b/components/arkui/src/native_gesture.rs new file mode 100644 index 0000000..80f0c5f --- /dev/null +++ b/components/arkui/src/native_gesture.rs @@ -0,0 +1,2 @@ +mod native_gesture_api12; +pub use native_gesture_api12::*; diff --git a/components/arkui/src/native_gesture/native_gesture_api12.rs b/components/arkui/src/native_gesture/native_gesture_api12.rs new file mode 100644 index 0000000..908ec5d --- /dev/null +++ b/components/arkui/src/native_gesture/native_gesture_api12.rs @@ -0,0 +1,856 @@ +/* automatically generated by rust-bindgen 0.70.1 */ + +#![allow(non_upper_case_globals)] +#![allow(non_camel_case_types)] +#![allow(non_snake_case)] +use crate::native_type::*; +use crate::ui_input_event::ArkUI_UIInputEvent; + +#[repr(C)] +pub struct ArkUI_GestureRecognizer { + _unused: [u8; 0], +} +#[repr(C)] +pub struct ArkUI_GestureInterruptInfo { + _unused: [u8; 0], +} +#[repr(C)] +pub struct ArkUI_GestureEvent { + _unused: [u8; 0], +} +impl ArkUI_GestureEventActionType { + /// Triggered. + pub const GESTURE_EVENT_ACTION_ACCEPT: ArkUI_GestureEventActionType = + ArkUI_GestureEventActionType(1); +} +impl ArkUI_GestureEventActionType { + /// Updated. + pub const GESTURE_EVENT_ACTION_UPDATE: ArkUI_GestureEventActionType = + ArkUI_GestureEventActionType(2); +} +impl ArkUI_GestureEventActionType { + /// Ended. + pub const GESTURE_EVENT_ACTION_END: ArkUI_GestureEventActionType = + ArkUI_GestureEventActionType(4); +} +impl ArkUI_GestureEventActionType { + /// Canceled. + pub const GESTURE_EVENT_ACTION_CANCEL: ArkUI_GestureEventActionType = + ArkUI_GestureEventActionType(8); +} +#[repr(transparent)] +/** @brief Enumerates gesture event types. + +@since 12*/ +#[derive(Clone, Hash, PartialEq, Eq)] +pub struct ArkUI_GestureEventActionType(pub ::core::ffi::c_uint); +/** @brief Defines a set of gesture event types. + +Example: ArkUI_GestureEventActionTypeMask actions = GESTURE_EVENT_ACTION_ACCEPT | GESTURE_EVENT_ACTION_UPDATE;\n + +@since 12*/ +pub type ArkUI_GestureEventActionTypeMask = u32; +impl ArkUI_GesturePriority { + /// Normal. + pub const NORMAL: ArkUI_GesturePriority = ArkUI_GesturePriority(0); +} +impl ArkUI_GesturePriority { + /// High-priority. + pub const PRIORITY: ArkUI_GesturePriority = ArkUI_GesturePriority(1); +} +impl ArkUI_GesturePriority { + /// Parallel. + pub const PARALLEL: ArkUI_GesturePriority = ArkUI_GesturePriority(2); +} +#[repr(transparent)] +/** @brief Enumerates gesture event modes. + +@since 12*/ +#[derive(Clone, Hash, PartialEq, Eq)] +pub struct ArkUI_GesturePriority(pub ::core::ffi::c_uint); +impl ArkUI_GroupGestureMode { + pub const SEQUENTIAL_GROUP: ArkUI_GroupGestureMode = ArkUI_GroupGestureMode(0); +} +impl ArkUI_GroupGestureMode { + /** Parallel recognition. Registered gestures are recognized concurrently until all gestures are recognized. + The recognition result of each gesture does not affect each other.*/ + pub const PARALLEL_GROUP: ArkUI_GroupGestureMode = ArkUI_GroupGestureMode(1); +} +impl ArkUI_GroupGestureMode { + /** Exclusive recognition. Registered gestures are identified concurrently. + If one gesture is successfully recognized, gesture recognition ends.*/ + pub const EXCLUSIVE_GROUP: ArkUI_GroupGestureMode = ArkUI_GroupGestureMode(2); +} +#[repr(transparent)] +/** @brief Enumerates gesture group modes. + +@since 12*/ +#[derive(Clone, Hash, PartialEq, Eq)] +pub struct ArkUI_GroupGestureMode(pub ::core::ffi::c_uint); +impl ArkUI_GestureDirection { + /// All directions. + pub const GESTURE_DIRECTION_ALL: ArkUI_GestureDirection = ArkUI_GestureDirection(15); +} +impl ArkUI_GestureDirection { + /// Horizontal direction. + pub const GESTURE_DIRECTION_HORIZONTAL: ArkUI_GestureDirection = ArkUI_GestureDirection(3); +} +impl ArkUI_GestureDirection { + /// Vertical direction. + pub const GESTURE_DIRECTION_VERTICAL: ArkUI_GestureDirection = ArkUI_GestureDirection(12); +} +impl ArkUI_GestureDirection { + /// Leftward. + pub const GESTURE_DIRECTION_LEFT: ArkUI_GestureDirection = ArkUI_GestureDirection(1); +} +impl ArkUI_GestureDirection { + /// Rightward. + pub const GESTURE_DIRECTION_RIGHT: ArkUI_GestureDirection = ArkUI_GestureDirection(2); +} +impl ArkUI_GestureDirection { + /// Upward. + pub const GESTURE_DIRECTION_UP: ArkUI_GestureDirection = ArkUI_GestureDirection(4); +} +impl ArkUI_GestureDirection { + /// Downward. + pub const GESTURE_DIRECTION_DOWN: ArkUI_GestureDirection = ArkUI_GestureDirection(8); +} +impl ArkUI_GestureDirection { + /// None. + pub const GESTURE_DIRECTION_NONE: ArkUI_GestureDirection = ArkUI_GestureDirection(0); +} +#[repr(transparent)] +/** @brief Enumerates gesture directions. + +@since 12*/ +#[derive(Clone, Hash, PartialEq, Eq)] +pub struct ArkUI_GestureDirection(pub ::core::ffi::c_uint); +/** @brief Defines a set of gesture directions. + +Example: ArkUI_GestureDirectionMask directions = GESTURE_DIRECTION_LEFT | GESTURE_DIRECTION_RIGHT \n +This example indicates that the leftward and rightward directions are supported. \n + +@since 12*/ +pub type ArkUI_GestureDirectionMask = u32; +impl ArkUI_GestureMask { + /// The gestures of child components are enabled and recognized based on the default gesture recognition sequence. + pub const NORMAL_GESTURE_MASK: ArkUI_GestureMask = ArkUI_GestureMask(0); +} +impl ArkUI_GestureMask { + /// The gestures of child components are disabled, including the built-in gestures. + pub const IGNORE_INTERNAL_GESTURE_MASK: ArkUI_GestureMask = ArkUI_GestureMask(1); +} +#[repr(transparent)] +/** @brief Enumerates gesture masking modes. + +@since 12*/ +#[derive(Clone, Hash, PartialEq, Eq)] +pub struct ArkUI_GestureMask(pub ::core::ffi::c_uint); +impl ArkUI_GestureRecognizerType { + /// Tap. + pub const TAP_GESTURE: ArkUI_GestureRecognizerType = ArkUI_GestureRecognizerType(0); +} +impl ArkUI_GestureRecognizerType { + /// Long press. + pub const LONG_PRESS_GESTURE: ArkUI_GestureRecognizerType = ArkUI_GestureRecognizerType(1); +} +impl ArkUI_GestureRecognizerType { + /// Pan. + pub const PAN_GESTURE: ArkUI_GestureRecognizerType = ArkUI_GestureRecognizerType(2); +} +impl ArkUI_GestureRecognizerType { + /// Pinch. + pub const PINCH_GESTURE: ArkUI_GestureRecognizerType = ArkUI_GestureRecognizerType(3); +} +impl ArkUI_GestureRecognizerType { + /// Rotate. + pub const ROTATION_GESTURE: ArkUI_GestureRecognizerType = ArkUI_GestureRecognizerType(4); +} +impl ArkUI_GestureRecognizerType { + /// Swipe. + pub const SWIPE_GESTURE: ArkUI_GestureRecognizerType = ArkUI_GestureRecognizerType(5); +} +impl ArkUI_GestureRecognizerType { + /// A group of gestures. + pub const GROUP_GESTURE: ArkUI_GestureRecognizerType = ArkUI_GestureRecognizerType(6); +} +#[repr(transparent)] +/** @brief Enumerates gesture types. + +@since 12*/ +#[derive(Clone, Hash, PartialEq, Eq)] +pub struct ArkUI_GestureRecognizerType(pub ::core::ffi::c_uint); +impl ArkUI_GestureInterruptResult { + /// The gesture recognition process continues. + pub const GESTURE_INTERRUPT_RESULT_CONTINUE: ArkUI_GestureInterruptResult = + ArkUI_GestureInterruptResult(0); +} +impl ArkUI_GestureInterruptResult { + /// The gesture recognition process is paused. + pub const GESTURE_INTERRUPT_RESULT_REJECT: ArkUI_GestureInterruptResult = + ArkUI_GestureInterruptResult(1); +} +#[repr(transparent)] +/** @brief Enumerates gesture interruption results. + +@since 12*/ +#[derive(Clone, Hash, PartialEq, Eq)] +pub struct ArkUI_GestureInterruptResult(pub ::core::ffi::c_uint); +impl ArkUI_GestureRecognizerState { + /// Ready. + pub const ARKUI_GESTURE_RECOGNIZER_STATE_READY: ArkUI_GestureRecognizerState = + ArkUI_GestureRecognizerState(0); +} +impl ArkUI_GestureRecognizerState { + /// Detecting. + pub const ARKUI_GESTURE_RECOGNIZER_STATE_DETECTING: ArkUI_GestureRecognizerState = + ArkUI_GestureRecognizerState(1); +} +impl ArkUI_GestureRecognizerState { + /// Pending. + pub const ARKUI_GESTURE_RECOGNIZER_STATE_PENDING: ArkUI_GestureRecognizerState = + ArkUI_GestureRecognizerState(2); +} +impl ArkUI_GestureRecognizerState { + /// Blocked. + pub const ARKUI_GESTURE_RECOGNIZER_STATE_BLOCKED: ArkUI_GestureRecognizerState = + ArkUI_GestureRecognizerState(3); +} +impl ArkUI_GestureRecognizerState { + /// Successful. + pub const ARKUI_GESTURE_RECOGNIZER_STATE_SUCCESSFUL: ArkUI_GestureRecognizerState = + ArkUI_GestureRecognizerState(4); +} +impl ArkUI_GestureRecognizerState { + /// Failed. + pub const ARKUI_GESTURE_RECOGNIZER_STATE_FAILED: ArkUI_GestureRecognizerState = + ArkUI_GestureRecognizerState(5); +} +#[repr(transparent)] +/** @brief Enumerates the gesture recognizer states. + +@since 12*/ +#[derive(Clone, Hash, PartialEq, Eq)] +pub struct ArkUI_GestureRecognizerState(pub ::core::ffi::c_uint); +/** @brief Defines the gesture recognizer handle. + +@since 12*/ +pub type ArkUI_GestureRecognizerHandle = *mut ArkUI_GestureRecognizer; +/** @brief Defines the gesture recognizer handle array. + +@since 12*/ +pub type ArkUI_GestureRecognizerHandleArray = *mut ArkUI_GestureRecognizerHandle; +#[repr(C)] +pub struct ArkUI_GestureEventTargetInfo { + _unused: [u8; 0], +} +#[repr(C)] +pub struct ArkUI_ParallelInnerGestureEvent { + _unused: [u8; 0], +} +/** @brief Defines a callback function for notifying gesture recognizer destruction. +@since 12*/ +pub type ArkUI_GestureRecognizerDisposeNotifyCallback = ::core::option::Option< + unsafe extern "C" fn( + recognizer: *mut ArkUI_GestureRecognizer, + userData: *mut ::core::ffi::c_void, + ), +>; +/** @brief Defines the gesture APIs. + +@since 12*/ +#[repr(C)] +pub struct ArkUI_NativeGestureAPI_1 { + /// The struct version is 1. + pub version: i32, + /** @brief Creates a tap gesture. + + 1. This API is used to trigger a tap gesture with one, two, or more taps. \n + 2. If multi-tap is configured, the timeout interval between a lift and the next tap is 300 ms. \n + 3. If the distance between the last tapped position and the current tapped position exceeds 60 vp, + gesture recognition fails. \n + 4. If the value is greater than 1, the tap gesture will fail to be recognized when the number of fingers + touching the screen within 300 ms of the first finger touch is less than the required number, \n + or when the number of fingers lifted from the screen within 300 ms of the first finger's being lifted + is less than the required number. \n + 5. When the number of fingers touching the screen exceeds the set value, the gesture can be recognized. \n + + @param countNum Indicates the number of consecutive taps. If the value is less than 1 or is not set, + the default value 1 is used. + @param fingersNum Indicates the number of fingers required to trigger a tap. The value ranges + from 1 to 10. If the value is less than 1 or is not set, the default value 1 is used. + @return Returns the pointer to the created gesture.*/ + pub createTapGesture: ::core::option::Option< + unsafe extern "C" fn(countNum: i32, fingersNum: i32) -> *mut ArkUI_GestureRecognizer, + >, + /** @brief Creates a long press gesture. + + 1. This API is used to trigger a long press gesture, which requires one or more fingers with a minimum + The value ranges 500 ms hold-down time. \n + 2. In components that support drag actions by default, such as , , +