add assets_manager_get_theme_name

This commit is contained in:
lixianjing 2022-08-31 12:34:42 +08:00
parent d82004406e
commit 512b3845bc
5 changed files with 23 additions and 1 deletions

View File

@ -7,6 +7,7 @@
* 支持image\_set\_image 检查是否相同的图片(感谢智明提供补丁)
* 支持 mutable\_image动态绑定贴图属性(感谢智明提供补丁)
* 支持widget\_set\_text支持字符串比较相同字符串不刷新和新增widget\_set\_text\_ex函数支持不检查以及测试用例(感谢智明提供补丁)
* 支持获取当前资源管理的主题名称(感谢智明提供补丁)
2022/08/30
* 完善注释(感谢雨欣提供补丁)

View File

@ -608,6 +608,11 @@ ret_t assets_manager_clear_all(assets_manager_t* am) {
return darray_clear(&(am->assets));
}
const char* assets_manager_get_theme_name(assets_manager_t* am) {
return_value_if_fail(am != NULL, NULL);
return am->theme;
}
ret_t assets_manager_set_theme(assets_manager_t* am, const char* theme) {
return_value_if_fail(am != NULL, RET_BAD_PARAMS);

View File

@ -479,6 +479,16 @@ ret_t assets_managers_set_theme(const char* theme);
*/
ret_t assets_managers_unref(assets_manager_t* am);
/**
* @method assets_manager_get_theme_name
*
* @annotation ["deconstructor"]
* @param {assets_manager_t*} am
*
* @return {const char*}
*/
const char* assets_manager_get_theme_name(assets_manager_t* am);
END_C_DECLS
#endif /*TK_ASSETS_MANAGER_H*/

View File

@ -666,7 +666,7 @@ const char* widget_get_theme_name(widget_t* widget) {
assets_manager_t* am = widget_get_assets_manager(widget);
return_value_if_fail(am != NULL, NULL);
return am->name;
return assets_manager_get_theme_name(am);
}
ret_t widget_set_theme(widget_t* widget, const char* name) {

View File

@ -48,6 +48,12 @@ TEST(AssetsManager, basic) {
ASSERT_EQ(assets_manager_ref_ex(rm, ASSET_TYPE_FONT, ASSET_TYPE_FONT_TTF, "font1"), &font1);
ASSERT_EQ(assets_manager_ref_ex(rm, ASSET_TYPE_FONT, ASSET_TYPE_FONT_BMP, "font1"), &font2);
ASSERT_EQ(assets_manager_set_theme(rm, "dark"), RET_OK);
ASSERT_STREQ(assets_manager_get_theme_name(rm), "dark");
ASSERT_EQ(assets_manager_set_theme(rm, "default"), RET_OK);
ASSERT_STREQ(assets_manager_get_theme_name(rm), "default");
assets_manager_destroy(rm);
}