Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
arkui: Add native dialog and native interface
Browse files Browse the repository at this point in the history
Signed-off-by: Jonathan Schwender <[email protected]>
jschwe committed Jan 4, 2025
1 parent 178b599 commit f76e44d
Showing 2 changed files with 534 additions and 0 deletions.
456 changes: 456 additions & 0 deletions components/arkui/src/native_dialog/native_dialog_ffi.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,456 @@
// automatically generated by rust-bindgen 0.71.1

#![allow(non_upper_case_globals)]
#![allow(non_camel_case_types)]
#![allow(non_snake_case)]
use crate::native_type::*;

#[cfg(feature = "api-12")]
#[cfg_attr(docsrs, doc(cfg(feature = "api-12")))]
impl ArkUI_DismissReason {
/// Touching the system-defined Back button or pressing the Esc key.
pub const DIALOG_DISMISS_BACK_PRESS: ArkUI_DismissReason = ArkUI_DismissReason(0);
}
#[cfg(feature = "api-12")]
#[cfg_attr(docsrs, doc(cfg(feature = "api-12")))]
impl ArkUI_DismissReason {
/// Touching the mask.
pub const DIALOG_DISMISS_TOUCH_OUTSIDE: ArkUI_DismissReason = ArkUI_DismissReason(1);
}
#[cfg(feature = "api-12")]
#[cfg_attr(docsrs, doc(cfg(feature = "api-12")))]
impl ArkUI_DismissReason {
/// Touching the Close button.
pub const DIALOG_DISMISS_CLOSE_BUTTON: ArkUI_DismissReason = ArkUI_DismissReason(2);
}
#[cfg(feature = "api-12")]
#[cfg_attr(docsrs, doc(cfg(feature = "api-12")))]
impl ArkUI_DismissReason {
/// Sliding down.
pub const DIALOG_DISMISS_SLIDE_DOWN: ArkUI_DismissReason = ArkUI_DismissReason(3);
}
#[repr(transparent)]
/// Enumerates the actions for triggering closure of the dialog box.
///
///
/// Available since API-level: 12
#[cfg(feature = "api-12")]
#[cfg_attr(docsrs, doc(cfg(feature = "api-12")))]
#[derive(Clone, Hash, PartialEq, Eq)]
pub struct ArkUI_DismissReason(pub ::core::ffi::c_uint);
/// Invoked when the dialog box is closed.
///
///
/// Available since API-level: 12
#[cfg(feature = "api-12")]
#[cfg_attr(docsrs, doc(cfg(feature = "api-12")))]
pub type ArkUI_OnWillDismissEvent =
::core::option::Option<unsafe extern "C" fn(reason: i32) -> bool>;
#[repr(C)]
pub struct ArkUI_DialogDismissEvent {
_unused: [u8; 0],
}
/// Provides the custom dialog box APIs for the native side.
///
///
/// Version: 1
///
/// Available since API-level: 12
#[cfg(feature = "api-12")]
#[cfg_attr(docsrs, doc(cfg(feature = "api-12")))]
#[repr(C)]
pub struct ArkUI_NativeDialogAPI_1 {
/// Creates a custom dialog box and returns the pointer to the created dialog box.
///
///
/// Note:** This method must be called before the <b>show</b> method.
///
/// # Returns
///
/// Returns the pointer to the created custom dialog box; returns a null pointer if the creation fails.
pub create: ::core::option::Option<unsafe extern "C" fn() -> ArkUI_NativeDialogHandle>,
/// Destroys a custom dialog box.
///
/// # Arguments
///
/// `handle` - Indicates the pointer to the custom dialog box controller.
pub dispose: ::core::option::Option<unsafe extern "C" fn(handle: ArkUI_NativeDialogHandle)>,
/// Attaches the content of a custom dialog box.
///
///
/// Note:** This method must be called before the <b>show</b> method.
/// # Arguments
///
/// `handle` - Indicates the pointer to the custom dialog box controller.
///
/// `content` - Indicates the pointer to the root node of the custom dialog box content.
///
/// # Returns
///
/// Returns the error code.
/// Returns [`ARKUI_ERROR_CODE_NO_ERROR`] if the operation is successful.
/// Returns [`ARKUI_ERROR_CODE_PARAM_INVALID`] if a parameter error occurs.
pub setContent: ::core::option::Option<
unsafe extern "C" fn(handle: ArkUI_NativeDialogHandle, content: ArkUI_NodeHandle) -> i32,
>,
/// Detaches the content of a custom dialog box.
///
///
/// Note:** This method must be called before the <b>show</b> method.
/// # Arguments
///
/// `handle` - Indicates the pointer to the custom dialog box controller.
///
/// # Returns
///
/// Returns the error code.
/// Returns [`ARKUI_ERROR_CODE_NO_ERROR`] if the operation is successful.
/// Returns [`ARKUI_ERROR_CODE_PARAM_INVALID`] if a parameter error occurs.
pub removeContent:
::core::option::Option<unsafe extern "C" fn(handle: ArkUI_NativeDialogHandle) -> i32>,
/// Sets the alignment mode for a custom dialog box.
///
///
/// Note:** This method must be called before the <b>show</b> method.
/// # Arguments
///
/// `handle` - Indicates the pointer to the custom dialog box controller.
///
/// `alignment` - Indicates the alignment mode. The parameter type is [`ArkUI_Alignment`].
///
/// `offsetX` - Indicates the horizontal offset of the custom dialog box. The value is a floating point number.
///
/// `offsetY` - Indicates the vertical offset of the custom dialog box. The value is a floating point number.
///
/// # Returns
///
/// Returns the error code.
/// Returns [`ARKUI_ERROR_CODE_NO_ERROR`] if the operation is successful.
/// Returns [`ARKUI_ERROR_CODE_PARAM_INVALID`] if a parameter error occurs.
pub setContentAlignment: ::core::option::Option<
unsafe extern "C" fn(
handle: ArkUI_NativeDialogHandle,
alignment: i32,
offsetX: f32,
offsetY: f32,
) -> i32,
>,
/// Resets the alignment mode of a custom dialog box to its default settings.
///
///
/// Note:** This method must be called before the <b>show</b> method.
/// # Arguments
///
/// `handle` - Indicates the pointer to the custom dialog box controller.
///
/// # Returns
///
/// Returns the error code.
/// Returns [`ARKUI_ERROR_CODE_NO_ERROR`] if the operation is successful.
/// Returns [`ARKUI_ERROR_CODE_PARAM_INVALID`] if a parameter error occurs.
pub resetContentAlignment:
::core::option::Option<unsafe extern "C" fn(handle: ArkUI_NativeDialogHandle) -> i32>,
/// Sets the modal mode for a custom dialog box.
///
///
/// Note:** This method must be called before the <b>show</b> method.
/// # Arguments
///
/// `handle` - Indicates the pointer to the custom dialog box controller.
///
/// `isModal` - Specifies whether the custom dialog box is a modal, which has a mask applied. The value
/// <b>true</b> means that the custom dialog box is a modal, and <b>false</b> means the opposite.
///
/// # Returns
///
/// Returns the error code.
/// Returns [`ARKUI_ERROR_CODE_NO_ERROR`] if the operation is successful.
/// Returns [`ARKUI_ERROR_CODE_PARAM_INVALID`] if a parameter error occurs.
pub setModalMode: ::core::option::Option<
unsafe extern "C" fn(handle: ArkUI_NativeDialogHandle, isModal: bool) -> i32,
>,
/// Specifies whether to allow users to touch the mask to dismiss the custom dialog box.
///
///
/// Note:** This method must be called before the <b>show</b> method.
/// # Arguments
///
/// `handle` - Indicates the pointer to the custom dialog box controller.
///
/// `autoCancel` - Specifies whether to allow users to touch the mask to dismiss the dialog box.
/// The value <b>true</b> means to allow users to do so, and <b>false</b> means the opposite.
///
/// # Returns
///
/// Returns the error code.
/// Returns [`ARKUI_ERROR_CODE_NO_ERROR`] if the operation is successful.
/// Returns [`ARKUI_ERROR_CODE_PARAM_INVALID`] if a parameter error occurs.
pub setAutoCancel: ::core::option::Option<
unsafe extern "C" fn(handle: ArkUI_NativeDialogHandle, autoCancel: bool) -> i32,
>,
/// Sets the mask for a custom dialog box.
///
///
/// Note:** This method must be called before the <b>show</b> method.
/// # Arguments
///
/// `handle` - Indicates the pointer to the custom dialog box controller.
///
/// `maskColor` - Indicates the mask color, in 0xARGB format.
///
/// `maskRect` - Indicates the pointer to the mask area. Events outside the mask area are transparently
/// transmitted, and events within the mask area are not. The parameter type is [`ArkUI_Rect`].
///
/// # Returns
///
/// Returns the error code.
/// Returns [`ARKUI_ERROR_CODE_NO_ERROR`] if the operation is successful.
/// Returns [`ARKUI_ERROR_CODE_PARAM_INVALID`] if a parameter error occurs.
pub setMask: ::core::option::Option<
unsafe extern "C" fn(
handle: ArkUI_NativeDialogHandle,
maskColor: u32,
maskRect: *const ArkUI_Rect,
) -> i32,
>,
/// Sets the background color for a custom dialog box.
///
///
/// Note:** This method must be called before the <b>show</b> method.
/// # Arguments
///
/// `handle` - Indicates the pointer to the custom dialog box controller.
///
/// `backgroundColor` - Indicates the background color of the custom dialog box, in 0xARGB format.
///
/// # Returns
///
/// Returns the error code.
/// Returns [`ARKUI_ERROR_CODE_NO_ERROR`] if the operation is successful.
/// Returns [`ARKUI_ERROR_CODE_PARAM_INVALID`] if a parameter error occurs.
pub setBackgroundColor: ::core::option::Option<
unsafe extern "C" fn(handle: ArkUI_NativeDialogHandle, backgroundColor: u32) -> i32,
>,
/// Sets the background corner radius for a custom dialog box.
///
///
/// Note:** This method must be called before the <b>show</b> method.
/// # Arguments
///
/// `handle` - Indicates the pointer to the custom dialog box controller.
///
/// `topLeft` - Indicates the radius of the upper left corner of the custom dialog box background.
///
/// `topRight` - Indicates the radius of the upper right corner of the custom dialog box background.
///
/// `bottomLeft` - Indicates the radius of the lower left corner of the custom dialog box background.
///
/// `bottomRight` - Indicates the radius of the lower right corner of the custom dialog box background.
///
/// # Returns
///
/// Returns the error code.
/// Returns [`ARKUI_ERROR_CODE_NO_ERROR`] if the operation is successful.
/// Returns [`ARKUI_ERROR_CODE_PARAM_INVALID`] if a parameter error occurs.
pub setCornerRadius: ::core::option::Option<
unsafe extern "C" fn(
handle: ArkUI_NativeDialogHandle,
topLeft: f32,
topRight: f32,
bottomLeft: f32,
bottomRight: f32,
) -> i32,
>,
/// Sets the number of grid columns occupied by a custom dialog box.
///
///
/// Note:** This method must be called before the <b>show</b> method.
/// # Arguments
///
/// `handle` - Indicates the pointer to the custom dialog box controller.
///
/// `gridCount` - Indicates the number of grid columns occupied by the dialog box. The default value is subject to
/// the window size, and the maximum value is the maximum number of columns supported by the system.
///
/// # Returns
///
/// Returns the error code.
/// Returns [`ARKUI_ERROR_CODE_NO_ERROR`] if the operation is successful.
/// Returns [`ARKUI_ERROR_CODE_PARAM_INVALID`] if a parameter error occurs.
pub setGridColumnCount: ::core::option::Option<
unsafe extern "C" fn(handle: ArkUI_NativeDialogHandle, gridCount: i32) -> i32,
>,
/// Specifies whether to use a custom style for the custom dialog box.
///
///
/// Note:** This method must be called before the <b>show</b> method.
/// # Arguments
///
/// `handle` - Indicates the pointer to the custom dialog box controller.
///
/// `enableCustomStyle` - Specifies whether to use a custom style for the dialog box.
/// <b>true</b>: The dialog box automatically adapts its width to the child components; the rounded corner is 0;
/// the background color is transparent.
/// <b>false</b>: The dialog box automatically adapts its width to the grid system and its height to the child
/// components; the rounded corner is 24 vp.
///
/// # Returns
///
/// Returns the error code.
/// Returns [`ARKUI_ERROR_CODE_NO_ERROR`] if the operation is successful.
/// Returns [`ARKUI_ERROR_CODE_PARAM_INVALID`] if a parameter error occurs.
pub enableCustomStyle: ::core::option::Option<
unsafe extern "C" fn(handle: ArkUI_NativeDialogHandle, enableCustomStyle: bool) -> i32,
>,
/// Specifies whether to use a custom animation for a custom dialog box.
///
///
/// Note:** This method must be called before the <b>show</b> method.
/// # Arguments
///
/// `handle` - Indicates the pointer to the custom dialog box controller.
///
/// `enableCustomAnimation` - Specifies whether to use a custom animation. The value <b>true</b> means to use a
/// custom animation, and <b>false</b> means to use the default animation.
///
/// # Returns
///
/// Returns the error code.
/// Returns [`ARKUI_ERROR_CODE_NO_ERROR`] if the operation is successful.
/// Returns [`ARKUI_ERROR_CODE_PARAM_INVALID`] if a parameter error occurs.
pub enableCustomAnimation: ::core::option::Option<
unsafe extern "C" fn(handle: ArkUI_NativeDialogHandle, enableCustomAnimation: bool) -> i32,
>,
/// Registers a callback for a custom dialog box so that the user can decide whether to close the dialog box
/// after they touch the Back button or press the Esc key.
///
///
/// Note:** This method must be called before the <b>show</b> method.
/// # Arguments
///
/// `handle` - Indicates the pointer to the custom dialog box controller.
///
/// `eventHandler` - Indicates the callback to register. The parameter type is [`ArkUI_OnWillDismissEvent`].
///
/// # Returns
///
/// Returns the error code.
/// Returns [`ARKUI_ERROR_CODE_NO_ERROR`] if the operation is successful.
/// Returns [`ARKUI_ERROR_CODE_PARAM_INVALID`] if a parameter error occurs.
pub registerOnWillDismiss: ::core::option::Option<
unsafe extern "C" fn(
handle: ArkUI_NativeDialogHandle,
eventHandler: ArkUI_OnWillDismissEvent,
) -> i32,
>,
/// Shows a custom dialog box.
///
/// # Arguments
///
/// `handle` - Indicates the pointer to the custom dialog box controller.
///
/// `showInSubWindow` - Specifies whether to show the dialog box in a sub-window.
///
/// # Returns
///
/// Returns the error code.
/// Returns [`ARKUI_ERROR_CODE_NO_ERROR`] if the operation is successful.
/// Returns [`ARKUI_ERROR_CODE_PARAM_INVALID`] if a parameter error occurs.
pub show: ::core::option::Option<
unsafe extern "C" fn(handle: ArkUI_NativeDialogHandle, showInSubWindow: bool) -> i32,
>,
/// Closes a custom dialog box. If the dialog box has been closed, this API does not take effect.
///
/// # Arguments
///
/// `handle` - Indicates the pointer to the custom dialog box controller.
///
/// # Returns
///
/// Returns the error code.
/// Returns [`ARKUI_ERROR_CODE_NO_ERROR`] if the operation is successful.
/// Returns [`ARKUI_ERROR_CODE_PARAM_INVALID`] if a parameter error occurs.
pub close:
::core::option::Option<unsafe extern "C" fn(handle: ArkUI_NativeDialogHandle) -> i32>,
/// Registers a listener for the dismiss event of the custom dialog box.
///
/// # Arguments
///
/// `handle` - Indicates the pointer to the custom dialog box controller.
///
/// `userData` - Indicates the pointer to the custom data.
///
/// `callback` - Indicates the callback for the dismiss event of the custom dialog box.
///
/// # Returns
///
/// Returns the result code.
/// Returns [`ARKUI_ERROR_CODE_NO_ERROR`] if the operation is successful.
/// Returns [`ARKUI_ERROR_CODE_PARAM_INVALID`] if a parameter error occurs.
pub registerOnWillDismissWithUserData: ::core::option::Option<
unsafe extern "C" fn(
handle: ArkUI_NativeDialogHandle,
userData: *mut ::core::ffi::c_void,
callback: ::core::option::Option<
unsafe extern "C" fn(event: *mut ArkUI_DialogDismissEvent),
>,
) -> i32,
>,
}
extern "C" {
/// Sets whether to block the system behavior of dismissing a dialog box.
///
/// # Arguments
///
/// `event` - Indicates the pointer to a dialog box dismiss event object.
///
/// `shouldBlockDismiss` - Indicates whether to block the system behavior of dismissing the dialog box. The value
/// <b>true</b> means to block the system behavior, and <b>false</b> means the opposite.
///
/// Available since API-level: 12
#[cfg(feature = "api-12")]
#[cfg_attr(docsrs, doc(cfg(feature = "api-12")))]
pub fn OH_ArkUI_DialogDismissEvent_SetShouldBlockDismiss(
event: *mut ArkUI_DialogDismissEvent,
shouldBlockDismiss: bool,
);
/// Obtains the pointer to user data in a dialog box dismiss event object.
///
/// # Arguments
///
/// `event` - Indicates the pointer to a dialog box dismiss event object.
///
///
/// # Returns
///
/// Returns the pointer to user data.
///
/// Available since API-level: 12
#[cfg(feature = "api-12")]
#[cfg_attr(docsrs, doc(cfg(feature = "api-12")))]
pub fn OH_ArkUI_DialogDismissEvent_GetUserData(
event: *mut ArkUI_DialogDismissEvent,
) -> *mut ::core::ffi::c_void;
/// Obtains the c from a dialog box dismiss event object.
///
/// # Arguments
///
/// `event` - Indicates the pointer to a dialog box dismiss event object.
///
///
/// # Returns
///
/// Returns the dismissal reason. Returns <b>-1</b> if an exception occurs.
/// [`DIALOG_DISMISS_BACK_PRESS`]: touching the Back button, swiping left or right on the screen, or
/// pressing the Esc key.
/// [`DIALOG_DISMISS_TOUCH_OUTSIDE`]: touching the mask.
/// [`DIALOG_DISMISS_CLOSE_BUTTON`]: touching the Close button.
/// [`DIALOG_DISMISS_SLIDE_DOWN`]: sliding down.
///
/// Available since API-level: 12
#[cfg(feature = "api-12")]
#[cfg_attr(docsrs, doc(cfg(feature = "api-12")))]
pub fn OH_ArkUI_DialogDismissEvent_GetDismissReason(
event: *mut ArkUI_DialogDismissEvent,
) -> i32;
}
78 changes: 78 additions & 0 deletions components/arkui/src/native_interface/native_interface_ffi.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
// automatically generated by rust-bindgen 0.71.1

#![allow(non_upper_case_globals)]
#![allow(non_camel_case_types)]
#![allow(non_snake_case)]
use crate::native_type::*;

#[cfg(feature = "api-12")]
#[cfg_attr(docsrs, doc(cfg(feature = "api-12")))]
impl ArkUI_NativeAPIVariantKind {
/// API related to UI components. For details, see the struct definition in <arkui/native_node.h>.
pub const ARKUI_NATIVE_NODE: ArkUI_NativeAPIVariantKind = ArkUI_NativeAPIVariantKind(0);
}
#[cfg(feature = "api-12")]
#[cfg_attr(docsrs, doc(cfg(feature = "api-12")))]
impl ArkUI_NativeAPIVariantKind {
/// API related to dialog boxes. For details, see the struct definition in <arkui/native_dialog.h>.
pub const ARKUI_NATIVE_DIALOG: ArkUI_NativeAPIVariantKind = ArkUI_NativeAPIVariantKind(1);
}
#[cfg(feature = "api-12")]
#[cfg_attr(docsrs, doc(cfg(feature = "api-12")))]
impl ArkUI_NativeAPIVariantKind {
/// API related to gestures. For details, see the struct definition in <arkui/native_gesture.h>.
pub const ARKUI_NATIVE_GESTURE: ArkUI_NativeAPIVariantKind = ArkUI_NativeAPIVariantKind(2);
}
#[cfg(feature = "api-12")]
#[cfg_attr(docsrs, doc(cfg(feature = "api-12")))]
impl ArkUI_NativeAPIVariantKind {
/// API related to animations. For details, see the struct definition in <arkui/native_animate.h>.
pub const ARKUI_NATIVE_ANIMATE: ArkUI_NativeAPIVariantKind = ArkUI_NativeAPIVariantKind(3);
}
#[repr(transparent)]
/// Defines the native API types.
///
///
/// Available since API-level: 12
#[cfg(feature = "api-12")]
#[cfg_attr(docsrs, doc(cfg(feature = "api-12")))]
#[derive(Clone, Hash, PartialEq, Eq)]
pub struct ArkUI_NativeAPIVariantKind(pub ::core::ffi::c_uint);
extern "C" {
/// Obtains the native API set of a specified type.
///
/// # Arguments
///
/// `type` - Indicates the type of the native API set provided by ArkUI, for example, <b>ARKUI_NATIVE_NODE</b>
/// and <b>ARKUI_NATIVE_GESTURE</b>.
///
/// `sturctName` - Indicates the name of a native struct defined in the corresponding header file, for example,
/// <b>ArkUI_NativeNodeAPI_1</b> in <arkui/native_node.h>.
///
/// # Returns
///
/// Returns the pointer to the abstract native API, which can be used after being converted into a specific type.
/// ```cpp
/// #include<arkui/native_interface.h>
/// #include<arkui/native_node.h>
/// #include<arkui/native_gesture.h>
///
/// auto* anyNativeAPI = OH_ArkUI_QueryModuleInterfaceByName(ARKUI_NATIVE_NODE, "ArkUI_NativeNodeAPI_1");
/// if (anyNativeAPI) {
/// auto nativeNodeApi = reinterpret_cast<ArkUI_NativeNodeAPI_1*>(anyNativeAPI);
/// }
/// auto anyGestureAPI = OH_ArkUI_QueryModuleInterface(ARKUI_NATIVE_GESTURE, "ArkUI_NativeGestureAPI_1");
/// if (anyNativeAPI) {
/// auto basicGestureApi = reinterpret_cast<ArkUI_NativeGestureAPI_1*>(anyGestureAPI);
/// }
/// ```
///
///
/// Available since API-level: 12
#[cfg(feature = "api-12")]
#[cfg_attr(docsrs, doc(cfg(feature = "api-12")))]
pub fn OH_ArkUI_QueryModuleInterfaceByName(
type_: ArkUI_NativeAPIVariantKind,
structName: *const ::core::ffi::c_char,
) -> *mut ::core::ffi::c_void;
}

0 comments on commit f76e44d

Please sign in to comment.