目录

grid.h

Overview

Defines enumerations and APIs related to Grid.

File to include: <arkui/node_attributes/grid.h>

Library: libace_ndk.z.so

System capability: SystemCapability.ArkUI.ArkUI.Full

Since: 22

Related module: ArkUI_NativeModule

Sample: NDKGridSample

Summary

[h2]Structs

Name typedef Keyword Description
ArkUI_GridItemSize ArkUI_GridItemSize Defines the return value for the onGetIrregularSizeByIndex callback in Grid layout options.
ArkUI_GridItemRect ArkUI_GridItemRect Defines the return value for the onGetRectByIndex callback in Grid layout options.
ArkUI_GridLayoutOptions ArkUI_GridLayoutOptions Defines the Grid layout options, which are used to set the layout parameters of irregular grid items in the Grid component, including the irregular item index and layout callback. An irregular grid item refers to a grid item that spans across rows and columns or has a different size in the grid layout.

[h2]Enums

Name typedef Keyword Description
ArkUI_GridItemAlignment ArkUI_GridItemAlignment Enumerates the alignment modes of the GridItem component.
ArkUI_GridItemStyle ArkUI_GridItemStyle Enumerates styles of grid items.

[h2]Functions

Name Description
ArkUI_GridLayoutOptions* OH_ArkUI_GridLayoutOptions_Create() Creates Grid layout options. Call OH_ArkUI_GridLayoutOptions_Dispose to destroy it after use.
void OH_ArkUI_GridLayoutOptions_Dispose(ArkUI_GridLayoutOptions* option) Disposes of the Grid layout options to release resources.
int32_t OH_ArkUI_GridLayoutOptions_SetIrregularIndexes(ArkUI_GridLayoutOptions* option, uint32_t* irregularIndexes, int32_t size) Sets the irregular grid item index array for the grid layout.
int32_t OH_ArkUI_GridLayoutOptions_GetIrregularIndexes(ArkUI_GridLayoutOptions* option, uint32_t* irregularIndexes, int32_t* size) Obtains the irregular grid item index array for the grid layout. When OH_ArkUI_GridLayoutOptions_RegisterGetIrregularSizeByIndexCallback is not set, the grid item specified in this parameter occupies an entire row of the grid that scrolls vertically or an entire column of the grid that scrolls horizontally.
void OH_ArkUI_GridLayoutOptions_RegisterGetIrregularSizeByIndexCallback(ArkUI_GridLayoutOptions* option, void* userData, ArkUI_GridItemSize(*callback)(int32_t itemIndex, void* userData)) Registers a callback to obtain the row and column span for the grid item at the specified index.
void OH_ArkUI_GridLayoutOptions_RegisterGetRectByIndexCallback(ArkUI_GridLayoutOptions* option, void* userData, ArkUI_GridItemRect (*callback)(int32_t itemIndex, void* userData)) Registers a callback to obtain the starting row, starting column, row span, and column span for the grid item at the specified index.

Enum Description

[h2]ArkUI_GridItemAlignment

enum ArkUI_GridItemAlignment

Description

Enumerates the alignment modes of the GridItem component.

Since: 22

Value Description
GRID_ITEM_ALIGNMENT_DEFAULT = 0 Use the default alignment mode of the grid.
GRID_ITEM_ALIGNMENT_STRETCH = 1 Use the height of the tallest grid item in a row as the height for all other grid items in that row.

[h2]ArkUI_GridItemStyle

enum ArkUI_GridItemStyle

Description

Enumerates styles of grid items.

Since: 22

Value Description
GRID_ITEM_STYLE_NONE = 0 No style.
GRID_ITEM_STYLE_PLAIN = 1 Hover or press style.

Function Description

[h2]OH_ArkUI_GridLayoutOptions_Create()

ArkUI_GridLayoutOptions* OH_ArkUI_GridLayoutOptions_Create()

Description

Creates Grid layout options. Call OH_ArkUI_GridLayoutOptions_Dispose to dispose of it after use.

Since: 22

Returns

Type Description
ArkUI_GridLayoutOptions* Pointer to the created Grid layout option array.

[h2]OH_ArkUI_GridLayoutOptions_Dispose()

void OH_ArkUI_GridLayoutOptions_Dispose(ArkUI_GridLayoutOptions* option)

Description

Disposes of the Grid layout options to release resources.

Since: 22

Parameters

Parameter Item Description
ArkUI_GridLayoutOptions* option Pointer to the Grid layout option array to dispose of.

[h2]OH_ArkUI_GridLayoutOptions_SetIrregularIndexes()

int32_t OH_ArkUI_GridLayoutOptions_SetIrregularIndexes(ArkUI_GridLayoutOptions* option, uint32_t* irregularIndexes, int32_t size)

Description

Sets the irregular grid item index array for the grid layout.

Since: 22

Parameters

Name Description
ArkUI_GridLayoutOptions* option Pointer to the Grid layout option array to set.
uint32_t* irregularIndexes Pointer to the array of irregular grid item indexes used to set the Grid layout options.
int32_t size Number of elements in the irregularIndexes array.

Returns

Type Description
int32_t

Result code.

Returns ARKUI_ERROR_CODE_NO_ERROR if the operation is successful.

Returns ARKUI_ERROR_CODE_PARAM_INVALID if a parameter error occurs.

A possible cause is that mandatory parameters are left unspecified.

[h2]OH_ArkUI_GridLayoutOptions_GetIrregularIndexes()

int32_t OH_ArkUI_GridLayoutOptions_GetIrregularIndexes(ArkUI_GridLayoutOptions* option, uint32_t* irregularIndexes, int32_t* size)

Description

Obtains the irregular grid item index array for the grid layout. When OH_ArkUI_GridLayoutOptions_RegisterGetIrregularSizeByIndexCallback is not set, the grid item specified in this parameter occupies an entire row of the grid that scrolls vertically or an entire column of the grid that scrolls horizontally.

Since: 22

Parameters

Name Description
ArkUI_GridLayoutOptions* option Pointer to the Grid layout option array to be obtained.
uint32_t* irregularIndexes Pointer to the buffer for receiving the irregular grid item index array.
int32_t* size Pointer to the number of elements that the irregularIndexes buffer can hold. Pass the buffer capacity before calling, and it will be updated to the actual number of indexes actually written after a successful call.

Returns

Type Description
int32_t

Result code.

Returns ARKUI_ERROR_CODE_NO_ERROR if the operation is successful.

Returns ARKUI_ERROR_CODE_PARAM_INVALID if a parameter error occurs.

Returns ARKUI_ERROR_CODE_BUFFER_SIZE_ERROR if the array size is insufficient.

A possible cause is that mandatory parameters are left unspecified.

[h2]OH_ArkUI_GridLayoutOptions_RegisterGetIrregularSizeByIndexCallback()

void OH_ArkUI_GridLayoutOptions_RegisterGetIrregularSizeByIndexCallback(ArkUI_GridLayoutOptions* option, void* userData, ArkUI_GridItemSize (*callback)(int32_t itemIndex, void* userData))

Description

Registers a callback to obtain the row and column span for the grid item at the specified index.

Since: 22

Parameters

Name Description
ArkUI_GridLayoutOptions* option Pointer to the Grid layout option array.
void* userData Pointer to the user-defined data.
ArkUI_GridItemSize (*callback)(int32_t itemIndex, void* userData)

Pointer to the callback used to obtain the row and column count occupied by a specified item based on the index.

itemIndex: grid item index, with the value range from OH_ArkUI_GridLayoutOptions_SetIrregularIndexes.

[h2]OH_ArkUI_GridLayoutOptions_RegisterGetRectByIndexCallback()

void OH_ArkUI_GridLayoutOptions_RegisterGetRectByIndexCallback(ArkUI_GridLayoutOptions* option, void* userData, ArkUI_GridItemRect (*callback)(int32_t itemIndex, void* userData))

Description

Registers a callback to obtain the starting row, starting column, row span, and column span for the grid item at the specified index.

Since: 22

Parameters

Name Description
ArkUI_GridLayoutOptions* option Pointer to the Grid layout option array.
void* userData Pointer to the user-defined data.
ArkUI_GridItemRect (*callback)(int32_t itemIndex, void* userData)

Pointer to the callback used to obtain the start row and column and the occupied row and column count of the specified item based on the index.

itemIndex: grid item index.