improve custom keys

This commit is contained in:
lixianjing 2022-10-18 16:02:28 +08:00
parent 033301aef3
commit 553d9febb8
4 changed files with 30 additions and 19 deletions

View File

@ -2,6 +2,8 @@
2022/10/18
* 完善了 fscript widget 的 tr 接口,支持使用指定控件的 locale_info(感谢雨欣提供补丁)
* 完善获取自定义键值表函数(感谢兆坤提供补丁)
* 完善获取自定义键值表函数的测试和文档(感谢兆坤提供补丁)
2022/10/17
* 增加获取自定义键值表函数接口(感谢兆坤提供补丁)

View File

@ -235,11 +235,11 @@ int main(int argc, char* argv[]) {
#if defined(APP_DEFAULT_LANGUAGE) && defined(APP_DEFAULT_COUNTRY)
locale_info_change(locale_info(), APP_DEFAULT_LANGUAGE, APP_DEFAULT_COUNTRY);
#endif /*APP_DEFAULT_LANGUAGE and APP_DEFAULT_LANGUAGE*/
custom_keys_init();
custom_keys_init(TRUE);
application_init();
tk_run();
application_exit();
custom_keys_deinit();
custom_keys_deinit(TRUE);
GLOBAL_EXIT();
tk_exit();

View File

@ -6,7 +6,7 @@
#ifndef CUSTOM_KEYS_FILEPATH
#define CUSTOM_KEYS_FILEPATH "asset://custom_keys.json"
#endif/*CUSTOM_KEYS_FILEPATH*/
#endif /*CUSTOM_KEYS_FILEPATH*/
#endif /*WITH_SDL*/
@ -15,7 +15,7 @@
static uint32_t s_custom_keys_nr = 0;
static key_type_value_t* s_custom_keys = NULL;
static key_type_value_t* keys_type_custom_keys_load(uint32_t* nr) {
static key_type_value_t* custom_keys_load(uint32_t* nr) {
key_type_value_t* ret = NULL;
tk_object_t* conf = NULL;
return_value_if_fail(nr != NULL, NULL);
@ -45,7 +45,7 @@ static key_type_value_t* keys_type_custom_keys_load(uint32_t* nr) {
return ret;
}
static ret_t keys_type_custom_keys_unload(key_type_value_t* table, uint32_t nr) {
static ret_t custom_keys_unload(key_type_value_t* table, uint32_t nr) {
return_value_if_fail(table != NULL || nr == 0, RET_BAD_PARAMS);
if (table != NULL) {
@ -59,21 +59,32 @@ static ret_t keys_type_custom_keys_unload(key_type_value_t* table, uint32_t nr)
return RET_OK;
}
static ret_t custom_keys_init(void) {
s_custom_keys = keys_type_custom_keys_load(&s_custom_keys_nr);
keys_type_set_custom_keys(s_custom_keys, s_custom_keys_nr);
return RET_OK;
static void custom_keys_init(bool_t set) {
s_custom_keys = custom_keys_load(&s_custom_keys_nr);
if (set) {
keys_type_set_custom_keys(s_custom_keys, s_custom_keys_nr);
}
}
static ret_t custom_keys_deinit(void) {
keys_type_set_custom_keys(NULL, 0);
keys_type_custom_keys_unload(s_custom_keys, s_custom_keys_nr);
static void custom_keys_deinit(bool_t set) {
if (set) {
keys_type_set_custom_keys(NULL, 0);
}
custom_keys_unload(s_custom_keys, s_custom_keys_nr);
s_custom_keys = NULL;
s_custom_keys_nr = 0;
}
return RET_OK;
static inline const key_type_value_t* custom_keys(void) {
return s_custom_keys;
}
static inline uint32_t custom_keys_nr(void) {
return s_custom_keys_nr;
}
#else
#define custom_keys_init()
#define custom_keys_deinit()
#define custom_keys_init(set)
#define custom_keys_deinit(set)
#define custom_keys() (NULL)
#define custom_keys_nr() (0)
#endif /*CUSTOM_KEYS_FILEPATH*/

View File

@ -26,7 +26,6 @@
#include "base/input_method.h"
#include "base/window_animator.h"
#include "base/assets_manager.h"
#include "conf_io/conf_json.h"
static const key_type_value_t window_closable_name_value[] = {
{"yes", 0, WINDOW_CLOSABLE_YES},
@ -439,4 +438,3 @@ ret_t keys_type_set_custom_keys(const key_type_value_t* table, uint32_t nr) {
log_debug("Set custom keys : %p, nr = %d\n", table, nr);
return RET_OK;
}