From cfb0a1176fd47e38581cf032b1d9b81a19922dba Mon Sep 17 00:00:00 2001 From: lixianjing Date: Sat, 27 Apr 2024 08:50:12 +0800 Subject: [PATCH] improve docs --- docs/changes.md | 3 +++ docs/how_to_set_custom_load_asset.md | 19 ++++++++++++++----- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/docs/changes.md b/docs/changes.md index 207cc692f..086183bab 100644 --- a/docs/changes.md +++ b/docs/changes.md @@ -1,5 +1,8 @@ # 最新动态 +2024/04/27 + * 完善自定义加载资源文档(感谢颖健提供补丁) + 2024/04/26 * 导出 main\_loop\_sdl2\_dispatch等函数。 diff --git a/docs/how_to_set_custom_load_asset.md b/docs/how_to_set_custom_load_asset.md index 44b760e3e..ca07548d5 100644 --- a/docs/how_to_set_custom_load_asset.md +++ b/docs/how_to_set_custom_load_asset.md @@ -5,10 +5,10 @@ 如果 AWTK 默认的资源加载方式无法满足需求,例如在无文件系统的嵌入式平台上使用外扩 flash 用来存储资源,可以自定义资源的加载方式,只需调用 assets_manager_set_custom_load_asset() 并注册资源加载回调函数即可,AWTK 加载资源时会优先调用用户自定义的加载方式,接口声明如下: ```c -typedef asset_info_t* (*assets_manager_load_asset_t)(assets_manager_t* am, - asset_type_t type, - uint16_t subtype, - const char* name); +typedef asset_info_t* (*assets_manager_load_asset_t)(void* ctx, /* 回调函数上下文 */ + asset_type_t type, /* 资源的类型 */ + uint16_t subtype, /* 资源的子类型 */ + const char* name); /* 资源的名称 */ /** * @method assets_manager_set_custom_load_asset @@ -63,7 +63,7 @@ W25QXX_Write((u8*)ui_home_page,0 + 260,ui_size); /* 写入资源数组 */ #define NAME_MAX_LEN 256 #define U32_SIZE 4 /* 自定义资源加载函数 */ -asset_info_t* load_assets_from_flash(assets_manager_t* am, asset_type_t type, +asset_info_t* load_assets_from_flash(void* ctx, asset_type_t type, uint16_t subtype, const char* name) { u32 assets_size; u32 start_position; @@ -96,3 +96,12 @@ asset_info_t* load_assets_from_flash(assets_manager_t* am, asset_type_t type, } ``` +最后在项目application.c代码文件的application_on_launch()中注册该自定义资源加载函数,示例代码如下: + +```c +static ret_t application_on_launch(void) { + assets_manager_set_custom_load_asset(assets_manager(), load_assets_from_flash, NULL); + return RET_OK; +} +``` +