diff --git a/docs/manual.md b/docs/manual.md index 24e3dc15ef..e0d8a0eb94 100644 --- a/docs/manual.md +++ b/docs/manual.md @@ -168,7 +168,7 @@ ## 二、基本函数库 -* [array](manual/array_t.md) 动态数组。 +* [darray](manual/darray_t.md) 动态数组。 * [slist](manual/slist_t.md) 单向链表。 * [memory](manual/tk_mem_t.md) 内存管理相关函数和宏。 * [rgba](manual/rgba_t.md) RGBA颜色值。 diff --git a/docs/manual/array_t.md b/docs/manual/array_t.md index 8f4f063295..7e2a43e6da 100644 --- a/docs/manual/array_t.md +++ b/docs/manual/array_t.md @@ -2,23 +2,7 @@ ### 概述 动态数组,根据元素个数动态调整数组的容量。 - 用array\_init初始化时,用array\_deinit释放。如: - - ```c - array_t array; - array_init(&array, 10); - ... - array_deinit(&array); - ``` - - 用array\_create创建时,用array\_destroy销毁。如: - - ```c - array_t* array = array_create(10); - ... - array_destroy(array); - ``` - + > 本类已经过时,逐步替换成darray。 ---------------------------------- diff --git a/docs/manual/darray_t.md b/docs/manual/darray_t.md new file mode 100644 index 0000000000..4b5a10c74d --- /dev/null +++ b/docs/manual/darray_t.md @@ -0,0 +1,412 @@ +## darray\_t +### 概述 + 动态数组,根据元素个数动态调整数组的容量。 + + 用darray\_init初始化时,用darray\_deinit释放。如: + + ```c + darray_t darray; + darray_init(&darray, 10, destroy, compare); + ... + darray_deinit(&darray); + ``` + + 用darray\_create创建时,用darray\_destroy销毁。如: + + ```c + darray_t* darray = darray_create(10, destroy, compare); + ... + darray_destroy(darray); + ``` + + + +---------------------------------- +### 函数 +

+ +| 函数名称 | 说明 | +| -------- | ------------ | +| darray\_clear | 清除全部元素。 | +| darray\_count | 返回满足条件元素的个数。 | +| darray\_create | 创建darray对象。 | +| darray\_deinit | 清除全部元素,并释放elms。 | +| darray\_destroy | 销毁darray对象。 | +| darray\_find | 查找第一个满足条件的元素。 | +| darray\_find\_index | 查找第一个满足条件的元素,并返回位置。 | +| darray\_init | 初始化darray对象。 | +| darray\_pop | 弹出最后一个元素。 | +| darray\_push | 在尾巴追加一个元素。 | +| darray\_remove | 删除第一个满足条件的元素。 | +| darray\_remove\_all | 删除全部满足条件的元素。 | +| darray\_remove\_index | 删除指定位置的元素。 | +### 属性 +

+ +| 名属性称 | 类型 | 说明 | +| -------- | ----- | ------------ | +| capacity | uint16\_t | 数组的容量大小。 | +| compare | tk\_compare\_t | 元素比较函数。 | +| destroy | tk\_destroy\_t | 元素销毁函数。 | +| elms | void** | 数组中的元素。 | +| size | uint16\_t | 数组中元素的个数。 | +#### darray\_clear 函数 +----------------------- + +* 函数功能: + +>

清除全部元素。 + + + + +* 函数原型: + +``` +ret_t darray_clear (darray_t* darray); +``` + +* 参数说明: + +| 参数 | 类型 | 说明 | +| -------- | ----- | --------- | +| 返回值 | ret\_t | 返回RET\_OK表示成功,否则表示失败。 | +| darray | darray\_t* | 数组对象。 | +#### darray\_count 函数 +----------------------- + +* 函数功能: + +>

返回满足条件元素的个数。 + + + + +* 函数原型: + +``` +int32_t darray_count (darray_t* darray, void* ctx); +``` + +* 参数说明: + +| 参数 | 类型 | 说明 | +| -------- | ----- | --------- | +| 返回值 | int32\_t | 返回元素个数。 | +| darray | darray\_t* | 单向链表对象。 | +| ctx | void* | 比较函数的上下文。 | +#### darray\_create 函数 +----------------------- + +* 函数功能: + +>

创建darray对象。 + + + + + +* 函数原型: + +``` +darray_t* darray_create (uint16_t* capacity, tk_destroy_t destroy, tk_compare_t compare); +``` + +* 参数说明: + +| 参数 | 类型 | 说明 | +| -------- | ----- | --------- | +| 返回值 | darray\_t* | 数组对象。 | +| capacity | uint16\_t* | 数组的初始容量。 | +| destroy | tk\_destroy\_t | 元素销毁函数。 | +| compare | tk\_compare\_t | 元素比较函数。 | +#### darray\_deinit 函数 +----------------------- + +* 函数功能: + +>

清除全部元素,并释放elms。 + + + + +* 函数原型: + +``` +ret_t darray_deinit (darray_t* darray); +``` + +* 参数说明: + +| 参数 | 类型 | 说明 | +| -------- | ----- | --------- | +| 返回值 | ret\_t | 返回RET\_OK表示成功,否则表示失败。 | +| darray | darray\_t* | 数组对象。 | +#### darray\_destroy 函数 +----------------------- + +* 函数功能: + +>

销毁darray对象。 + + + + +* 函数原型: + +``` +ret_t darray_destroy (darray_t* darray); +``` + +* 参数说明: + +| 参数 | 类型 | 说明 | +| -------- | ----- | --------- | +| 返回值 | ret\_t | 返回RET\_OK表示成功,否则表示失败。 | +| darray | darray\_t* | 数组对象。 | +#### darray\_find 函数 +----------------------- + +* 函数功能: + +>

查找第一个满足条件的元素。 + + + + +* 函数原型: + +``` +void* darray_find (darray_t* darray, void* ctx); +``` + +* 参数说明: + +| 参数 | 类型 | 说明 | +| -------- | ----- | --------- | +| 返回值 | void* | 如果找到,返回满足条件的对象,否则返回NULL。 | +| darray | darray\_t* | 数组对象。 | +| ctx | void* | 比较函数的上下文。 | +#### darray\_find\_index 函数 +----------------------- + +* 函数功能: + +>

查找第一个满足条件的元素,并返回位置。 + + + + +* 函数原型: + +``` +int darray_find_index (darray_t* darray, void* ctx); +``` + +* 参数说明: + +| 参数 | 类型 | 说明 | +| -------- | ----- | --------- | +| 返回值 | int | 如果找到,返回满足条件的对象的位置,否则返回-1。 | +| darray | darray\_t* | 数组对象。 | +| ctx | void* | 比较函数的上下文。 | +#### darray\_init 函数 +----------------------- + +* 函数功能: + +>

初始化darray对象。 + + + + + +* 函数原型: + +``` +darray_t* darray_init (darray_t* darray, uint16_t* capacity, tk_destroy_t destroy, tk_compare_t compare); +``` + +* 参数说明: + +| 参数 | 类型 | 说明 | +| -------- | ----- | --------- | +| 返回值 | darray\_t* | 数组对象。 | +| darray | darray\_t* | 数组对象。 | +| capacity | uint16\_t* | 数组的初始容量。 | +| destroy | tk\_destroy\_t | 元素销毁函数。 | +| compare | tk\_compare\_t | 元素比较函数。 | +#### darray\_pop 函数 +----------------------- + +* 函数功能: + +>

弹出最后一个元素。 + + + + +* 函数原型: + +``` +void* darray_pop (darray_t* darray); +``` + +* 参数说明: + +| 参数 | 类型 | 说明 | +| -------- | ----- | --------- | +| 返回值 | void* | 成功返回最后一个元素,失败返回NULL。 | +| darray | darray\_t* | 数组对象。 | +#### darray\_push 函数 +----------------------- + +* 函数功能: + +>

在尾巴追加一个元素。 + + + + +* 函数原型: + +``` +ret_t darray_push (darray_t* darray, void* data); +``` + +* 参数说明: + +| 参数 | 类型 | 说明 | +| -------- | ----- | --------- | +| 返回值 | ret\_t | 返回RET\_OK表示成功,否则表示失败。 | +| darray | darray\_t* | 数组对象。 | +| data | void* | 待追加的元素。 | +#### darray\_remove 函数 +----------------------- + +* 函数功能: + +>

删除第一个满足条件的元素。 + + + + +* 函数原型: + +``` +ret_t darray_remove (darray_t* darray, void* ctx); +``` + +* 参数说明: + +| 参数 | 类型 | 说明 | +| -------- | ----- | --------- | +| 返回值 | ret\_t | 返回RET\_OK表示成功,否则表示失败。 | +| darray | darray\_t* | 数组对象。 | +| ctx | void* | 比较函数的上下文。 | +#### darray\_remove\_all 函数 +----------------------- + +* 函数功能: + +>

删除全部满足条件的元素。 + + + + +* 函数原型: + +``` +ret_t darray_remove_all (darray_t* darray, void* ctx); +``` + +* 参数说明: + +| 参数 | 类型 | 说明 | +| -------- | ----- | --------- | +| 返回值 | ret\_t | 返回RET\_OK表示成功,否则表示失败。 | +| darray | darray\_t* | 数组对象。 | +| ctx | void* | 比较函数的上下文。 | +#### darray\_remove\_index 函数 +----------------------- + +* 函数功能: + +>

删除指定位置的元素。 + + + + +* 函数原型: + +``` +ret_t darray_remove_index (darray_t* darray, uint32_t index); +``` + +* 参数说明: + +| 参数 | 类型 | 说明 | +| -------- | ----- | --------- | +| 返回值 | ret\_t | 返回RET\_OK表示成功,否则表示失败。 | +| darray | darray\_t* | 数组对象。 | +| index | uint32\_t | 位置序数。 | +#### capacity 属性 +----------------------- +>

数组的容量大小。 + + + +* 类型:uint16\_t + +| 特性 | 是否支持 | +| -------- | ----- | +| 可直接读取 | 是 | +| 可直接修改 | 否 | +#### compare 属性 +----------------------- +>

元素比较函数。 + + + +* 类型:tk\_compare\_t + +| 特性 | 是否支持 | +| -------- | ----- | +| 可直接读取 | 是 | +| 可直接修改 | 否 | +#### destroy 属性 +----------------------- +>

元素销毁函数。 + + + +* 类型:tk\_destroy\_t + +| 特性 | 是否支持 | +| -------- | ----- | +| 可直接读取 | 是 | +| 可直接修改 | 否 | +#### elms 属性 +----------------------- +>

数组中的元素。 + + + +* 类型:void** + +| 特性 | 是否支持 | +| -------- | ----- | +| 可直接读取 | 是 | +| 可直接修改 | 否 | +#### size 属性 +----------------------- +>

数组中元素的个数。 + + + +* 类型:uint16\_t + +| 特性 | 是否支持 | +| -------- | ----- | +| 可直接读取 | 是 | +| 可直接修改 | 否 | diff --git a/docs/manual/slide_menu_t.md b/docs/manual/slide_menu_t.md index cc12268109..7faf60c866 100644 --- a/docs/manual/slide_menu_t.md +++ b/docs/manual/slide_menu_t.md @@ -42,7 +42,7 @@ ```c widget_on(slide_menu, EVT_VALUE_CHANGED, on_current_changed, slide_menu); ``` - + 可按下面的方法关注当前按钮被点击的事件: ```c diff --git a/docs/manual/time_clock_t.md b/docs/manual/time_clock_t.md index 9faa285f7c..093dd94fa9 100644 --- a/docs/manual/time_clock_t.md +++ b/docs/manual/time_clock_t.md @@ -29,9 +29,9 @@ > 完整示例请参考:[time_clock demo]( https://github.com/zlgopen/awtk-c-demos/blob/master/demos/time_clock.c) - + time\_clock一般不需要设置style。 - + ---------------------------------- ### 函数 diff --git a/src/ext_widgets/slide_menu/slide_menu.h b/src/ext_widgets/slide_menu/slide_menu.h index 494b80612e..03b04b71ce 100644 --- a/src/ext_widgets/slide_menu/slide_menu.h +++ b/src/ext_widgets/slide_menu/slide_menu.h @@ -72,7 +72,7 @@ BEGIN_C_DECLS * ```c * widget_on(slide_menu, EVT_VALUE_CHANGED, on_current_changed, slide_menu); * ``` - + * 可按下面的方法关注当前按钮被点击的事件: * * ```c diff --git a/src/tkc/array.h b/src/tkc/array.h index b0652e2c4c..b2a6ff942e 100644 --- a/src/tkc/array.h +++ b/src/tkc/array.h @@ -30,23 +30,7 @@ BEGIN_C_DECLS * @class array_t * 动态数组,根据元素个数动态调整数组的容量。 * - * 用array\_init初始化时,用array\_deinit释放。如: - * - * ```c - * array_t array; - * array_init(&array, 10); - * ... - * array_deinit(&array); - * ``` - * - * 用array\_create创建时,用array\_destroy销毁。如: - * - * ```c - * array_t* array = array_create(10); - * ... - * array_destroy(array); - * ``` - * + * > 本类已经过时,逐步替换成darray。 */ typedef struct _array_t { /** diff --git a/src/tkc/darray.c b/src/tkc/darray.c new file mode 100644 index 0000000000..d02e3eb08a --- /dev/null +++ b/src/tkc/darray.c @@ -0,0 +1,235 @@ +/** + * File: darray.c + * Author: AWTK Develop Team + * Brief: dynamic darray. + * + * Copyright (c) 2018 - 2019 Guangzhou ZHIYUAN Electronics Co.,Ltd. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * License file for more details. + * + */ + +/** + * History: + * ================================================================ + * 2018-01-13 Li XianJing created + * + */ + +#include "tkc/darray.h" +#include "tkc/mem.h" + +static ret_t dummy_destroy(void* data) { + return RET_OK; +} + +static int32_t dummy_compare(const void* a, const void* b) { + return ((const char*)a - (const char*)b); +} + +darray_t* darray_create(uint16_t capacity, tk_destroy_t destroy, tk_compare_t compare) { + darray_t* darray = TKMEM_ZALLOC(darray_t); + return_value_if_fail(darray != NULL, NULL); + + if (darray_init(darray, capacity, destroy, compare)) { + return darray; + } else { + TKMEM_FREE(darray); + + return NULL; + } +} + +darray_t* darray_init(darray_t* darray, uint16_t capacity, tk_destroy_t destroy, + tk_compare_t compare) { + return_value_if_fail(darray != NULL, NULL); + + darray->size = 0; + darray->elms = NULL; + darray->destroy = destroy != NULL ? destroy : dummy_destroy; + darray->compare = compare != NULL ? compare : dummy_compare; + + if (capacity > 0) { + darray->elms = TKMEM_ZALLOCN(void*, capacity); + return_value_if_fail(darray->elms != NULL, NULL); + darray->capacity = capacity; + } + + return darray; +} + +static bool_t darray_extend(darray_t* darray) { + if (darray->elms != NULL && darray->size < darray->capacity) { + return TRUE; + } else { + void* elms = NULL; + uint16_t capacity = (darray->capacity >> 1) + darray->capacity + 1; + + elms = TKMEM_REALLOCT(void*, darray->elms, capacity); + if (elms) { + darray->elms = elms; + darray->capacity = capacity; + + return TRUE; + } else { + return FALSE; + } + } +} + +int darray_find_index(darray_t* darray, void* data) { + int32_t i = 0; + int32_t size = 0; + void** elms = NULL; + return_value_if_fail(darray != NULL, -1); + + elms = darray->elms; + size = darray->size; + for (i = 0; i < size; i++) { + void* iter = elms[i]; + if (darray->compare(iter, data) == 0) { + return i; + } + } + + return -1; +} + +ret_t darray_remove_index(darray_t* darray, uint32_t index) { + int32_t i = 0; + int32_t size = 0; + void** elms = NULL; + return_value_if_fail(darray != NULL && index < darray->size, RET_BAD_PARAMS); + + elms = darray->elms; + darray->destroy(elms[index]); + elms[index] = NULL; + + for (size = darray->size - 1, i = index; i < size; i++) { + elms[i] = elms[i + 1]; + } + + elms[i] = NULL; + darray->size--; + + return RET_OK; +} + +ret_t darray_remove(darray_t* darray, void* data) { + int32_t index = 0; + return_value_if_fail(darray != NULL, RET_BAD_PARAMS); + + index = darray_find_index(darray, data); + if (index < 0) { + return RET_NOT_FOUND; + } else { + return darray_remove_index(darray, index); + } +} + +ret_t darray_remove_all(darray_t* darray, void* data) { + int32_t i = 0; + int32_t k = 0; + int32_t size = 0; + void** elms = NULL; + + return_value_if_fail(darray != NULL, RET_BAD_PARAMS); + elms = darray->elms; + size = darray->size; + + for (i = 0, k = 0; i < size; i++) { + void* iter = elms[i]; + if (darray->compare(iter, data) == 0) { + darray->destroy(iter); + elms[i] = NULL; + } else { + if (k != i) { + elms[k] = elms[i]; + } + k++; + } + } + darray->size = k; + + return RET_OK; +} + +void* darray_find(darray_t* darray, void* data) { + int pos = darray_find_index(darray, data); + + return pos >= 0 ? darray->elms[pos] : NULL; +} + +void* darray_pop(darray_t* darray) { + return_value_if_fail(darray != NULL && darray->size > 0, NULL); + + return darray->elms[--darray->size]; +} + +ret_t darray_push(darray_t* darray, void* data) { + return_value_if_fail(darray != NULL, RET_BAD_PARAMS); + return_value_if_fail(darray_extend(darray), RET_OOM); + + darray->elms[darray->size++] = data; + + return RET_OK; +} + +int32_t darray_count(darray_t* darray, void* data) { + int32_t n = 0; + return_value_if_fail(darray != NULL, 0); + + if (darray->elms != NULL) { + uint32_t i = 0; + void** elms = darray->elms; + + for (i = 0; i < darray->size; i++) { + void* iter = elms[i]; + if (darray->compare(iter, data) == 0) { + n++; + } + } + } + + return n; +} + +ret_t darray_clear(darray_t* darray) { + return_value_if_fail(darray != NULL, RET_BAD_PARAMS); + + if (darray->elms != NULL) { + uint32_t i = 0; + void** elms = darray->elms; + + for (i = 0; i < darray->size; i++) { + void* iter = elms[i]; + darray->destroy(iter); + } + + darray->size = 0; + } + + return RET_OK; +} + +ret_t darray_deinit(darray_t* darray) { + return_value_if_fail(darray != NULL && darray->elms != NULL, RET_BAD_PARAMS); + + darray_clear(darray); + TKMEM_FREE(darray->elms); + memset(darray, 0x00, sizeof(darray_t)); + + return RET_OK; +} + +ret_t darray_destroy(darray_t* darray) { + return_value_if_fail(darray != NULL && darray->elms != NULL, RET_BAD_PARAMS); + + darray_deinit(darray); + TKMEM_FREE(darray); + + return RET_OK; +} diff --git a/src/tkc/darray.h b/src/tkc/darray.h new file mode 100644 index 0000000000..e29119e709 --- /dev/null +++ b/src/tkc/darray.h @@ -0,0 +1,220 @@ +/** + * File: darray.h + * Author: AWTK Develop Team + * Brief: dynamic darray. + * + * Copyright (c) 2018 - 2019 Guangzhou ZHIYUAN Electronics Co.,Ltd. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * License file for more details. + * + */ + +/** + * History: + * ================================================================ + * 2018-01-13 Li XianJing created + * + */ + +#ifndef TK_DARRAY_H +#define TK_DARRAY_H + +#include "tkc/types_def.h" + +BEGIN_C_DECLS + +/** + * @class darray_t + * 动态数组,根据元素个数动态调整数组的容量。 + * + * 用darray\_init初始化时,用darray\_deinit释放。如: + * + * ```c + * darray_t darray; + * darray_init(&darray, 10, destroy, compare); + * ... + * darray_deinit(&darray); + * ``` + * + * 用darray\_create创建时,用darray\_destroy销毁。如: + * + * ```c + * darray_t* darray = darray_create(10, destroy, compare); + * ... + * darray_destroy(darray); + * ``` + * + */ +typedef struct _darray_t { + /** + * @property {uint16_t} size + * @annotation ["readable"] + * 数组中元素的个数。 + */ + uint16_t size; + /** + * @property {uint16_t} capacity + * @annotation ["readable"] + * 数组的容量大小。 + */ + uint16_t capacity; + /** + * @property {void**} elms + * @annotation ["readable"] + * 数组中的元素。 + */ + void** elms; + /** + * @property {tk_destroy_t} destroy + * @annotation ["readable"] + * 元素销毁函数。 + */ + tk_destroy_t destroy; + + /** + * @property {tk_compare_t} compare + * @annotation ["readable"] + * 元素比较函数。 + */ + tk_compare_t compare; +} darray_t; + +/** + * @method darray_create + * @annotation ["constructor"] + * 创建darray对象。 + * + * @param {uint16_t*} capacity 数组的初始容量。 + * @param {tk_destroy_t} destroy 元素销毁函数。 + * @param {tk_compare_t} compare 元素比较函数。 + * + * @return {darray_t*} 数组对象。 + */ +darray_t* darray_create(uint16_t capacity, tk_destroy_t destroy, tk_compare_t compare); + +/** + * @method darray_init + * 初始化darray对象。 + * + * @param {darray_t*} darray 数组对象。 + * @param {uint16_t*} capacity 数组的初始容量。 + * @param {tk_destroy_t} destroy 元素销毁函数。 + * @param {tk_compare_t} compare 元素比较函数。 + * + * @return {darray_t*} 数组对象。 + */ +darray_t* darray_init(darray_t* darray, uint16_t capacity, tk_destroy_t destroy, + tk_compare_t compare); + +/** + * @method darray_find + * 查找第一个满足条件的元素。 + * @param {darray_t*} darray 数组对象。 + * @param {void*} ctx 比较函数的上下文。 + * + * @return {void*} 如果找到,返回满足条件的对象,否则返回NULL。 + */ +void* darray_find(darray_t* darray, void* ctx); + +/** + * @method darray_find_index + * 查找第一个满足条件的元素,并返回位置。 + * @param {darray_t*} darray 数组对象。 + * @param {void*} ctx 比较函数的上下文。 + * + * @return {int} 如果找到,返回满足条件的对象的位置,否则返回-1。 + */ +int darray_find_index(darray_t* darray, void* ctx); + +/** + * @method darray_remove + * 删除第一个满足条件的元素。 + * @param {darray_t*} darray 数组对象。 + * @param {void*} ctx 比较函数的上下文。 + * + * @return {ret_t} 返回RET_OK表示成功,否则表示失败。 + */ +ret_t darray_remove(darray_t* darray, void* ctx); + +/** + * @method darray_remove_index + * 删除指定位置的元素。 + * @param {darray_t*} darray 数组对象。 + * @param {uint32_t} index 位置序数。 + * + * @return {ret_t} 返回RET_OK表示成功,否则表示失败。 + */ +ret_t darray_remove_index(darray_t* darray, uint32_t index); + +/** + * @method darray_remove_all + * 删除全部满足条件的元素。 + * @param {darray_t*} darray 数组对象。 + * @param {void*} ctx 比较函数的上下文。 + * + * @return {ret_t} 返回RET_OK表示成功,否则表示失败。 + */ +ret_t darray_remove_all(darray_t* darray, void* ctx); + +/** + * @method darray_pop + * 弹出最后一个元素。 + * @param {darray_t*} darray 数组对象。 + * + * @return {void*} 成功返回最后一个元素,失败返回NULL。 + */ +void* darray_pop(darray_t* darray); + +/** + * @method darray_push + * 在尾巴追加一个元素。 + * @param {darray_t*} darray 数组对象。 + * @param {void*} data 待追加的元素。 + * + * @return {ret_t} 返回RET_OK表示成功,否则表示失败。 + */ +ret_t darray_push(darray_t* darray, void* data); + +/** + * @method darray_count + * 返回满足条件元素的个数。 + * @param {darray_t*} darray 单向链表对象。 + * @param {void*} ctx 比较函数的上下文。 + * + * @return {int32_t} 返回元素个数。 + */ +int32_t darray_count(darray_t* darray, void* ctx); + +/** + * @method darray_clear + * 清除全部元素。 + * @param {darray_t*} darray 数组对象。 + * + * @return {ret_t} 返回RET_OK表示成功,否则表示失败。 + */ +ret_t darray_clear(darray_t* darray); + +/** + * @method darray_deinit + * 清除全部元素,并释放elms。 + * @param {darray_t*} darray 数组对象。 + * + * @return {ret_t} 返回RET_OK表示成功,否则表示失败。 + */ +ret_t darray_deinit(darray_t* darray); + +/** + * @method darray_destroy + * 销毁darray对象。 + * @param {darray_t*} darray 数组对象。 + * + * @return {ret_t} 返回RET_OK表示成功,否则表示失败。 + */ +ret_t darray_destroy(darray_t* darray); + +END_C_DECLS + +#endif /*TK_DARRAY_H*/ diff --git a/src/tkc/types_def.h b/src/tkc/types_def.h index e864133311..7c01f9a612 100644 --- a/src/tkc/types_def.h +++ b/src/tkc/types_def.h @@ -141,6 +141,8 @@ typedef enum _ret_t { #ifdef WIN32 #include +#define random rand +#define srandom srand #define log_debug(format, ...) printf(format, __VA_ARGS__) #define log_info(format, ...) printf(format, __VA_ARGS__) #define log_warn(format, ...) printf(format, __VA_ARGS__) diff --git a/tests/darray_test.cc b/tests/darray_test.cc new file mode 100644 index 0000000000..f4a9c29620 --- /dev/null +++ b/tests/darray_test.cc @@ -0,0 +1,198 @@ +#include "tkc/darray.h" +#include "gtest/gtest.h" + +#include +#include + +#define NR 1000 + +static void test_add(darray_t* darray, void* pv) { + ASSERT_EQ(RET_OK, darray_push(darray, pv)); + ASSERT_EQ(pv, darray_find(darray, pv)); +} + +TEST(DArrayTest, init) { + darray_t darray; + darray_init(&darray, 10, NULL, NULL); + + ASSERT_EQ(darray.size, 0); + ASSERT_EQ(darray.capacity, 10); + + darray_deinit(&darray); +} + +TEST(DArrayTest, create) { + darray_t* darray = darray_create(10, NULL, NULL); + ASSERT_EQ(darray->size, 0); + ASSERT_EQ(darray->capacity, 10); + darray_destroy(darray); +} + +TEST(DArrayTest, basic) { + char* p = NULL; + darray_t* darray = darray_create(10, NULL, NULL); + ASSERT_EQ(darray->size, 0); + ASSERT_EQ(darray->capacity, 10); + + ASSERT_EQ(RET_OK, darray_push(darray, p + 1)); + ASSERT_EQ(1, darray_count(darray, p + 1)); + + ASSERT_EQ(RET_OK, darray_push(darray, p + 1)); + ASSERT_EQ(2, darray_count(darray, p + 1)); + + ASSERT_EQ(RET_OK, darray_remove(darray, p + 1)); + ASSERT_EQ(1, darray_count(darray, p + 1)); + + ASSERT_EQ(RET_OK, darray_push(darray, p + 1)); + ASSERT_EQ(2, darray_count(darray, p + 1)); + + ASSERT_EQ(RET_OK, darray_remove_all(darray, p + 1)); + ASSERT_EQ(darray->size, 0); + ASSERT_EQ(0, darray_count(darray, p + 1)); + + ASSERT_EQ(RET_OK, darray_push(darray, p + 1)); + ASSERT_EQ(RET_OK, darray_push(darray, p + 2)); + ASSERT_EQ(RET_OK, darray_push(darray, p + 3)); + ASSERT_EQ(RET_OK, darray_clear(darray)); + + ASSERT_EQ(darray->size, 0); + + darray_destroy(darray); +} + +TEST(DArrayTest, popPush) { + uint32_t i = 0; + char* p = NULL; + darray_t darray; + int cases[] = {1, 2, 13, 14, 12, 41, 34, 34, 5, 563, 12, 1, 2, 33}; + darray_init(&darray, 10, NULL, NULL); + + for (i = 0; i < ARRAY_SIZE(cases); i++) { + ASSERT_EQ(RET_OK, darray_push(&darray, p + cases[i])); + ASSERT_EQ(i + 1, darray.size); + } + + for (i = 0; i < ARRAY_SIZE(cases); i++) { + int k = ARRAY_SIZE(cases) - i - 1; + void* data = darray_pop(&darray); + ASSERT_EQ(data, p + cases[k]); + ASSERT_EQ(k, darray.size); + } + + darray_deinit(&darray); +} + +TEST(DArrayTest, random) { + int i = 0; + int n = NR; + char* p = NULL; + darray_t darray; + darray_init(&darray, 10, NULL, NULL); + + for (i = 0; i < n; i++) { + long v = random() + 1; + void* pv = p + v; + ASSERT_EQ(darray.size, i); + test_add(&darray, pv); + } + + for (i = 0; i < n; i++) { + long k = random() % darray.size; + void* pv = darray.elms[k]; + + ASSERT_EQ(RET_OK, darray_remove(&darray, pv)); + } + ASSERT_EQ(darray.size, 0); + + darray_deinit(&darray); +} + +TEST(DArrayTest, inc) { + int i = 0; + int n = NR; + char* p = NULL; + darray_t darray; + darray_init(&darray, 10, NULL, NULL); + + for (i = 0; i < n; i++) { + void* pv = p + i; + ASSERT_EQ(darray.size, i); + test_add(&darray, pv); + } + + for (i = 0; i < n; i++) { + long k = random() % darray.size; + void* pv = darray.elms[k]; + + ASSERT_EQ(RET_OK, darray_remove(&darray, pv)); + } + ASSERT_EQ(darray.size, 0); + + darray_deinit(&darray); +} + +TEST(DArrayTest, dec) { + int i = 0; + char* p = NULL; + int n = NR; + darray_t darray; + darray_init(&darray, 10, NULL, NULL); + + for (i = 0; i < n; i++) { + void* pv = p + (n - i); + ASSERT_EQ(darray.size, i); + test_add(&darray, pv); + } + + for (i = 0; i < n; i++) { + long k = random() % darray.size; + void* pv = darray.elms[k]; + + ASSERT_EQ(pv, darray_find(&darray, pv)); + ASSERT_EQ(RET_OK, darray_remove(&darray, pv)); + ASSERT_EQ(NULL, darray_find(&darray, pv)); + } + ASSERT_EQ(darray.size, 0); + + darray_deinit(&darray); +} + +TEST(DArrayTest, removeAll) { + uint32_t i = 0; + char* p = NULL; + darray_t darray; + int cases[] = {1, 2, 2, 2, 13, 14, 12, 41, 34, 34, 5, 563, 12, 1, 2, 33}; + darray_init(&darray, 10, NULL, NULL); + + for (i = 0; i < ARRAY_SIZE(cases); i++) { + ASSERT_EQ(RET_OK, darray_push(&darray, p + cases[i])); + ASSERT_EQ(i + 1, darray.size); + } + + ASSERT_EQ(darray.size, ARRAY_SIZE(cases)); + ASSERT_EQ(darray_remove_all(&darray, p + 2), RET_OK); + ASSERT_EQ(darray.size, ARRAY_SIZE(cases) - 4); + + ASSERT_EQ(darray_remove_all(&darray, p + 1), RET_OK); + ASSERT_EQ(darray.size, ARRAY_SIZE(cases) - 4 - 2); + + ASSERT_EQ(darray_remove_all(&darray, p + 12), RET_OK); + ASSERT_EQ(darray.size, ARRAY_SIZE(cases) - 4 - 2 - 2); + + ASSERT_EQ(darray_remove_all(&darray, p + 13), RET_OK); + ASSERT_EQ(darray.size, ARRAY_SIZE(cases) - 4 - 2 - 2 - 1); + + ASSERT_EQ(darray_remove_all(&darray, p + 14), RET_OK); + ASSERT_EQ(darray.size, ARRAY_SIZE(cases) - 4 - 2 - 2 - 1 - 1); + + ASSERT_EQ(darray_remove_all(&darray, p + 33), RET_OK); + ASSERT_EQ(darray.size, ARRAY_SIZE(cases) - 4 - 2 - 2 - 1 - 1 - 1); + + ASSERT_EQ(darray_remove_all(&darray, p + 34), RET_OK); + ASSERT_EQ(darray.size, ARRAY_SIZE(cases) - 4 - 2 - 2 - 1 - 1 - 1 - 2); + + ASSERT_EQ(darray_remove_all(&darray, p + 0), RET_OK); + ASSERT_EQ(darray.size, ARRAY_SIZE(cases) - 4 - 2 - 2 - 1 - 1 - 1 - 2); + + darray_deinit(&darray); +} diff --git a/tests/object_default_test.cc b/tests/object_default_test.cc index f6be8919eb..8c0f0a4d0f 100644 --- a/tests/object_default_test.cc +++ b/tests/object_default_test.cc @@ -4,11 +4,6 @@ #include #include -#ifdef WIN32 -#define random rand -#define srandom srand -#endif /*WIN32*/ - using std::string; static ret_t event_dump(void* ctx, event_t* e) { diff --git a/tools/idl_gen/idl.json b/tools/idl_gen/idl.json index 1d55224879..4274ff07ac 100644 --- a/tools/idl_gen/idl.json +++ b/tools/idl_gen/idl.json @@ -1,36 +1,32 @@ [ { "type": "enum", - "desc": " 控件边框类型。\r\n", + "desc": " 图标所在的位置。\r\n", "consts": [ { - "desc": " 无边框。\r\n", - "name": "BORDER_NONE" - }, - { - "desc": " 左边框线。\r\n", - "name": "BORDER_LEFT" + "desc": " 自动选择位置。\r\n", + "name": "ICON_AT_AUTO" }, { - "desc": " 右边框线。\r\n", - "name": "BORDER_RIGHT" + "desc": " 水平左边,垂直居中。\r\n", + "name": "ICON_AT_LEFT" }, { - "desc": " 上边框线。\r\n", - "name": "BORDER_TOP" + "desc": " 水平右边,垂直居中(not used now)。\r\n", + "name": "ICON_AT_RIGHT" }, { - "desc": " 下边框线。\r\n", - "name": "BORDER_BOTTOM" + "desc": " 水平居中,垂直顶部(not used now)。\r\n", + "name": "ICON_AT_TOP" }, { - "desc": " 全边框线。\r\n", - "name": "BORDER_ALL" + "desc": " 水平居中,垂直低部(not used now)。\r\n", + "name": "ICON_AT_BOTTOM" } ], "header": "base/types_def.h", - "name": "border_type_t", - "prefix": "BORDER_TYPE_", + "name": "icon_at_type_t", + "prefix": "ICON_AT", "level": 1 }, { @@ -6421,41 +6417,45 @@ }, { "type": "enum", - "desc": " 字体资源类型定义。\n\n", - "consts": [], - "header": "base/assets_manager.h", - "name": "asset_font_type_t", - "prefix": "ASSET_FONT_TYPE_", - "level": 1 - }, - { - "type": "enum", - "desc": " 图标所在的位置。\r\n", + "desc": " 控件边框类型。\r\n", "consts": [ { - "desc": " 自动选择位置。\r\n", - "name": "ICON_AT_AUTO" + "desc": " 无边框。\r\n", + "name": "BORDER_NONE" }, { - "desc": " 水平左边,垂直居中。\r\n", - "name": "ICON_AT_LEFT" + "desc": " 左边框线。\r\n", + "name": "BORDER_LEFT" }, { - "desc": " 水平右边,垂直居中(not used now)。\r\n", - "name": "ICON_AT_RIGHT" + "desc": " 右边框线。\r\n", + "name": "BORDER_RIGHT" }, { - "desc": " 水平居中,垂直顶部(not used now)。\r\n", - "name": "ICON_AT_TOP" + "desc": " 上边框线。\r\n", + "name": "BORDER_TOP" }, { - "desc": " 水平居中,垂直低部(not used now)。\r\n", - "name": "ICON_AT_BOTTOM" + "desc": " 下边框线。\r\n", + "name": "BORDER_BOTTOM" + }, + { + "desc": " 全边框线。\r\n", + "name": "BORDER_ALL" } ], "header": "base/types_def.h", - "name": "icon_at_type_t", - "prefix": "ICON_AT", + "name": "border_type_t", + "prefix": "BORDER_TYPE_", + "level": 1 + }, + { + "type": "enum", + "desc": " 字体资源类型定义。\n\n", + "consts": [], + "header": "base/assets_manager.h", + "name": "asset_font_type_t", + "prefix": "ASSET_FONT_TYPE_", "level": 1 }, { @@ -12045,13 +12045,56 @@ "annotation": { "private": true }, - "desc": " 初始化控件。仅在子类控件构造函数中使用。\n\n\n", + "desc": " 初始化控件。仅在子类控件构造函数中使用。\n\n > 请用widget\\_create代替本函数。\n\n @depreated\n\n\n", "name": "widget_init", "return": { "type": "widget_t*", "desc": "widget对象本身。" } }, + { + "params": [ + { + "type": "widget_t*", + "name": "parent", + "desc": "widget的父控件。" + }, + { + "type": "widget_vtable_t*", + "name": "vt", + "desc": "虚表。" + }, + { + "type": "xy_t", + "name": "x", + "desc": "x坐标" + }, + { + "type": "xy_t", + "name": "y", + "desc": "y坐标" + }, + { + "type": "wh_t", + "name": "w", + "desc": "宽度" + }, + { + "type": "wh_t", + "name": "h", + "desc": "高度" + } + ], + "annotation": { + "private": true + }, + "desc": " 创建控件。仅在子类控件构造函数中使用。\n\n\n", + "name": "widget_create", + "return": { + "type": "widget_t*", + "desc": "widget对象本身。" + } + }, { "params": [ { @@ -13147,7 +13190,7 @@ } ], "header": "tkc/array.h", - "desc": " 动态数组,根据元素个数动态调整数组的容量。\n\n 用array\\_init初始化时,用array\\_deinit释放。如:\n\n ```c\n array_t array;\n array_init(&array, 10);\n ...\n array_deinit(&array);\n ```\n\n 用array\\_create创建时,用array\\_destroy销毁。如:\n\n ```c\n array_t* array = array_create(10);\n ...\n array_destroy(array);\n ```\n\n\n", + "desc": " 动态数组,根据元素个数动态调整数组的容量。\n\n > 本类已经过时,逐步替换成darray。\n\n", "name": "array_t", "level": 1 }, @@ -14021,96 +14064,418 @@ "type": "class", "methods": [ { - "params": [], + "params": [ + { + "type": "uint16_t*", + "name": "capacity", + "desc": "数组的初始容量。" + }, + { + "type": "tk_destroy_t", + "name": "destroy", + "desc": "元素销毁函数。" + }, + { + "type": "tk_compare_t", + "name": "compare", + "desc": "元素比较函数。" + } + ], "annotation": { - "constructor": true, - "scriptable": true + "constructor": true }, - "desc": " 创建date_time对象,并初始为当前日期和时间(一般供脚本语言中使用)。\n\n\n", - "name": "date_time_create", + "desc": " 创建darray对象。\n\n\n\n", + "name": "darray_create", "return": { - "type": "date_time_t*", - "desc": "返回date_time对象。" + "type": "darray_t*", + "desc": "数组对象。" } }, { "params": [ { - "type": "date_time_t*", - "name": "dt", - "desc": "date_time对象。" + "type": "darray_t*", + "name": "darray", + "desc": "数组对象。" + }, + { + "type": "uint16_t*", + "name": "capacity", + "desc": "数组的初始容量。" + }, + { + "type": "tk_destroy_t", + "name": "destroy", + "desc": "元素销毁函数。" + }, + { + "type": "tk_compare_t", + "name": "compare", + "desc": "元素比较函数。" } ], "annotation": {}, - "desc": " 初始为当前日期和时间。\n\n\n", - "name": "date_time_init", + "desc": " 初始化darray对象。\n\n\n\n", + "name": "darray_init", "return": { - "type": "date_time_t*", - "desc": "返回date_time对象。" + "type": "darray_t*", + "desc": "数组对象。" } }, { "params": [ { - "type": "date_time_t*", - "name": "dt", - "desc": "date_time对象。" + "type": "darray_t*", + "name": "darray", + "desc": "数组对象。" + }, + { + "type": "void*", + "name": "ctx", + "desc": "比较函数的上下文。" } ], - "annotation": { - "deconstructor": true, - "scriptable": true - }, - "desc": " 销毁date_time对象(一般供脚本语言中使用)。\n\n\n\n", - "name": "date_time_destroy", + "annotation": {}, + "desc": " 查找第一个满足条件的元素。\n\n\n", + "name": "darray_find", "return": { - "type": "ret_t", - "desc": "返回RET_OK表示成功,否则表示失败。" + "type": "void*", + "desc": "如果找到,返回满足条件的对象,否则返回NULL。" } }, { "params": [ { - "type": "date_time_get_now_t", - "name": "date_time_get_now", - "desc": "获取当前日期和时间的函数。" + "type": "darray_t*", + "name": "darray", + "desc": "数组对象。" + }, + { + "type": "void*", + "name": "ctx", + "desc": "比较函数的上下文。" } ], "annotation": {}, - "desc": " 设置获取当前日期和时间的函数。\n\n > 嵌入式平台需要提供并设置获取当前日期和时间的函数,否则相关的功能(如时钟控件)将无法正常工作。\n\n\n\n", - "name": "date_time_set_impl", + "desc": " 查找第一个满足条件的元素,并返回位置。\n\n\n", + "name": "darray_find_index", "return": { - "type": "ret_t", - "desc": "返回RET_OK表示成功,否则表示失败。" + "type": "int", + "desc": "如果找到,返回满足条件的对象的位置,否则返回-1。" } - } - ], - "events": [], - "properties": [ + }, { - "name": "second", - "desc": " 秒(0 - 59)。\n\n", - "type": "int32_t", - "annotation": { - "readable": true, - "scriptable": true + "params": [ + { + "type": "darray_t*", + "name": "darray", + "desc": "数组对象。" + }, + { + "type": "void*", + "name": "ctx", + "desc": "比较函数的上下文。" + } + ], + "annotation": {}, + "desc": " 删除第一个满足条件的元素。\n\n\n", + "name": "darray_remove", + "return": { + "type": "ret_t", + "desc": "返回RET_OK表示成功,否则表示失败。" } }, { - "name": "minute", - "desc": " 分(0 - 59)。\n\n", - "type": "int32_t", - "annotation": { - "readable": true, - "scriptable": true + "params": [ + { + "type": "darray_t*", + "name": "darray", + "desc": "数组对象。" + }, + { + "type": "uint32_t", + "name": "index", + "desc": "位置序数。" + } + ], + "annotation": {}, + "desc": " 删除指定位置的元素。\n\n\n", + "name": "darray_remove_index", + "return": { + "type": "ret_t", + "desc": "返回RET_OK表示成功,否则表示失败。" } }, { - "name": "hour", - "desc": " 时(0 - 23)。\n\n", - "type": "int32_t", - "annotation": { - "readable": true, + "params": [ + { + "type": "darray_t*", + "name": "darray", + "desc": "数组对象。" + }, + { + "type": "void*", + "name": "ctx", + "desc": "比较函数的上下文。" + } + ], + "annotation": {}, + "desc": " 删除全部满足条件的元素。\n\n\n", + "name": "darray_remove_all", + "return": { + "type": "ret_t", + "desc": "返回RET_OK表示成功,否则表示失败。" + } + }, + { + "params": [ + { + "type": "darray_t*", + "name": "darray", + "desc": "数组对象。" + } + ], + "annotation": {}, + "desc": " 弹出最后一个元素。\n\n\n", + "name": "darray_pop", + "return": { + "type": "void*", + "desc": "成功返回最后一个元素,失败返回NULL。" + } + }, + { + "params": [ + { + "type": "darray_t*", + "name": "darray", + "desc": "数组对象。" + }, + { + "type": "void*", + "name": "data", + "desc": "待追加的元素。" + } + ], + "annotation": {}, + "desc": " 在尾巴追加一个元素。\n\n\n", + "name": "darray_push", + "return": { + "type": "ret_t", + "desc": "返回RET_OK表示成功,否则表示失败。" + } + }, + { + "params": [ + { + "type": "darray_t*", + "name": "darray", + "desc": "单向链表对象。" + }, + { + "type": "void*", + "name": "ctx", + "desc": "比较函数的上下文。" + } + ], + "annotation": {}, + "desc": " 返回满足条件元素的个数。\n\n\n", + "name": "darray_count", + "return": { + "type": "int32_t", + "desc": "返回元素个数。" + } + }, + { + "params": [ + { + "type": "darray_t*", + "name": "darray", + "desc": "数组对象。" + } + ], + "annotation": {}, + "desc": " 清除全部元素。\n\n\n", + "name": "darray_clear", + "return": { + "type": "ret_t", + "desc": "返回RET_OK表示成功,否则表示失败。" + } + }, + { + "params": [ + { + "type": "darray_t*", + "name": "darray", + "desc": "数组对象。" + } + ], + "annotation": {}, + "desc": " 清除全部元素,并释放elms。\n\n\n", + "name": "darray_deinit", + "return": { + "type": "ret_t", + "desc": "返回RET_OK表示成功,否则表示失败。" + } + }, + { + "params": [ + { + "type": "darray_t*", + "name": "darray", + "desc": "数组对象。" + } + ], + "annotation": {}, + "desc": " 销毁darray对象。\n\n\n", + "name": "darray_destroy", + "return": { + "type": "ret_t", + "desc": "返回RET_OK表示成功,否则表示失败。" + } + } + ], + "events": [], + "properties": [ + { + "name": "size", + "desc": " 数组中元素的个数。\n\n", + "type": "uint16_t", + "annotation": { + "readable": true + } + }, + { + "name": "capacity", + "desc": " 数组的容量大小。\n\n", + "type": "uint16_t", + "annotation": { + "readable": true + } + }, + { + "name": "elms", + "desc": " 数组中的元素。\n\n", + "type": "void**", + "annotation": { + "readable": true + } + }, + { + "name": "destroy", + "desc": " 元素销毁函数。\n\n", + "type": "tk_destroy_t", + "annotation": { + "readable": true + } + }, + { + "name": "compare", + "desc": " 元素比较函数。\n\n", + "type": "tk_compare_t", + "annotation": { + "readable": true + } + } + ], + "header": "tkc/darray.h", + "desc": " 动态数组,根据元素个数动态调整数组的容量。\n\n 用darray\\_init初始化时,用darray\\_deinit释放。如:\n\n ```c\n darray_t darray;\n darray_init(&darray, 10, destroy, compare);\n ...\n darray_deinit(&darray);\n ```\n\n 用darray\\_create创建时,用darray\\_destroy销毁。如:\n\n ```c\n darray_t* darray = darray_create(10, destroy, compare);\n ...\n darray_destroy(darray);\n ```\n\n\n", + "name": "darray_t", + "level": 1 + }, + { + "type": "class", + "methods": [ + { + "params": [], + "annotation": { + "constructor": true, + "scriptable": true + }, + "desc": " 创建date_time对象,并初始为当前日期和时间(一般供脚本语言中使用)。\n\n\n", + "name": "date_time_create", + "return": { + "type": "date_time_t*", + "desc": "返回date_time对象。" + } + }, + { + "params": [ + { + "type": "date_time_t*", + "name": "dt", + "desc": "date_time对象。" + } + ], + "annotation": {}, + "desc": " 初始为当前日期和时间。\n\n\n", + "name": "date_time_init", + "return": { + "type": "date_time_t*", + "desc": "返回date_time对象。" + } + }, + { + "params": [ + { + "type": "date_time_t*", + "name": "dt", + "desc": "date_time对象。" + } + ], + "annotation": { + "deconstructor": true, + "scriptable": true + }, + "desc": " 销毁date_time对象(一般供脚本语言中使用)。\n\n\n\n", + "name": "date_time_destroy", + "return": { + "type": "ret_t", + "desc": "返回RET_OK表示成功,否则表示失败。" + } + }, + { + "params": [ + { + "type": "date_time_get_now_t", + "name": "date_time_get_now", + "desc": "获取当前日期和时间的函数。" + } + ], + "annotation": {}, + "desc": " 设置获取当前日期和时间的函数。\n\n > 嵌入式平台需要提供并设置获取当前日期和时间的函数,否则相关的功能(如时钟控件)将无法正常工作。\n\n\n\n", + "name": "date_time_set_impl", + "return": { + "type": "ret_t", + "desc": "返回RET_OK表示成功,否则表示失败。" + } + } + ], + "events": [], + "properties": [ + { + "name": "second", + "desc": " 秒(0 - 59)。\n\n", + "type": "int32_t", + "annotation": { + "readable": true, + "scriptable": true + } + }, + { + "name": "minute", + "desc": " 分(0 - 59)。\n\n", + "type": "int32_t", + "annotation": { + "readable": true, + "scriptable": true + } + }, + { + "name": "hour", + "desc": " 时(0 - 23)。\n\n", + "type": "int32_t", + "annotation": { + "readable": true, "scriptable": true } }, @@ -18257,8 +18622,8 @@ "constructor": true, "scriptable": true }, - "desc": " 创建list_view_h对象\r\n\r\n", - "name": "list_view_h_create", + "desc": " 创建list_view对象\r\n\r\n", + "name": "list_view_create", "return": { "type": "widget_t*", "desc": "对象。" @@ -18273,161 +18638,15 @@ }, { "type": "int32_t", - "name": "item_width", - "desc": "列表项的宽度。" + "name": "item_height", + "desc": "列表项的高度。" } ], "annotation": { "scriptable": true }, - "desc": " 设置列表项的宽度。\r\n\r\n", - "name": "list_view_h_set_item_width", - "return": { - "type": "ret_t", - "desc": "返回RET_OK表示成功,否则表示失败。" - } - }, - { - "params": [ - { - "type": "widget_t*", - "name": "widget", - "desc": "控件对象。" - }, - { - "type": "int32_t", - "name": "spacing", - "desc": "列表项的间距。" - } - ], - "annotation": { - "scriptable": true - }, - "desc": " 设置列表项的间距。\r\n\r\n", - "name": "list_view_h_set_spacing", - "return": { - "type": "ret_t", - "desc": "返回RET_OK表示成功,否则表示失败。" - } - }, - { - "params": [ - { - "type": "widget_t*", - "name": "widget", - "desc": "list_view_h对象。" - } - ], - "annotation": { - "cast": true, - "scriptable": true - }, - "desc": " 转换为list_view_h对象(供脚本语言使用)。\r\n\r\n", - "name": "list_view_h_cast", - "return": { - "type": "widget_t*", - "desc": "list_view_h对象。" - } - } - ], - "events": [], - "properties": [ - { - "name": "item_width", - "desc": " 列表项的宽度。\r\n", - "type": "int32_t", - "annotation": { - "set_prop": true, - "get_prop": true, - "readable": true, - "persitent": true, - "design": true, - "scriptable": true - } - }, - { - "name": "spacing", - "desc": " 间距。\r\n", - "type": "int32_t", - "annotation": { - "set_prop": true, - "get_prop": true, - "readable": true, - "persitent": true, - "design": true, - "scriptable": true - } - } - ], - "header": "scroll_view/list_view_h.h", - "desc": " 水平ListView控件。\r\n", - "name": "list_view_h_t", - "parent": "widget_t", - "annotation": { - "scriptable": true - }, - "level": 2 - }, - { - "type": "class", - "methods": [ - { - "params": [ - { - "type": "widget_t*", - "name": "parent", - "desc": "父控件" - }, - { - "type": "xy_t", - "name": "x", - "desc": "x坐标" - }, - { - "type": "xy_t", - "name": "y", - "desc": "y坐标" - }, - { - "type": "wh_t", - "name": "w", - "desc": "宽度" - }, - { - "type": "wh_t", - "name": "h", - "desc": "高度" - } - ], - "annotation": { - "constructor": true, - "scriptable": true - }, - "desc": " 创建list_view对象\r\n\r\n", - "name": "list_view_create", - "return": { - "type": "widget_t*", - "desc": "对象。" - } - }, - { - "params": [ - { - "type": "widget_t*", - "name": "widget", - "desc": "控件对象。" - }, - { - "type": "int32_t", - "name": "item_height", - "desc": "列表项的高度。" - } - ], - "annotation": { - "scriptable": true - }, - "desc": " 设置列表项的高度。\r\n\r\n", - "name": "list_view_set_item_height", + "desc": " 设置列表项的高度。\r\n\r\n", + "name": "list_view_set_item_height", "return": { "type": "ret_t", "desc": "返回RET_OK表示成功,否则表示失败。" @@ -19406,7 +19625,7 @@ } ], "header": "slide_menu/slide_menu.h", - "desc": " 左右滑动菜单控件。\r\n\r\n 一般用一组按钮作为子控件,通过左右滑动改变当前的项。除了当菜单使用外,也可以用来切换页面。\r\n\r\n slide\\_menu\\_t是[widget\\_t](widget_t.md)的子类控件,widget\\_t的函数均适用于slide\\_menu\\_t控件。\r\n\r\n 在xml中使用\"slide\\_menu\"标签创建左右滑动菜单控件。如:\r\n\r\n ```xml\r\n \r\n