improve image value

This commit is contained in:
xianjimli 2020-03-03 17:29:11 +08:00
parent 8ab5ffd733
commit f133bf5995
8 changed files with 299 additions and 46 deletions

View File

@ -410,7 +410,7 @@
#include "assets/default/inc/images/arrow_left_n.data"
#include "assets/default/inc/images/edit_clear_p.data"
#include "assets/default/inc/images/battery_2.data"
#endif /*WITH_STB_IMAGE*/
#endif/*WITH_STB_IMAGE*/
#ifdef WITH_VGCANVAS
#include "assets/default/inc/images/pointer_4.bsvg"
#include "assets/default/inc/images/htest.bsvg"
@ -419,13 +419,13 @@
#include "assets/default/inc/images/pointer_1.bsvg"
#include "assets/default/inc/images/pointer.bsvg"
#include "assets/default/inc/images/girl.bsvg"
#endif /*WITH_VGCANVAS*/
#endif/*WITH_VGCANVAS*/
#if defined(WITH_TRUETYPE_FONT)
#include "assets/default/inc/fonts/default.res"
#else /*WITH_TRUETYPE_FONT*/
#else/*WITH_TRUETYPE_FONT*/
#include "assets/default/inc/fonts/default.data"
#endif /*WITH_TRUETYPE_FONT*/
#endif /*WITH_FS_RES*/
#endif/*WITH_TRUETYPE_FONT*/
#endif/*WITH_FS_RES*/
ret_t assets_init(void) {
assets_manager_t* am = assets_manager();
@ -726,7 +726,7 @@ ret_t assets_init(void) {
assets_manager_add(am, image_pointer_1);
assets_manager_add(am, image_pointer);
assets_manager_add(am, image_girl);
#endif /*WITH_VGCANVAS*/
#endif/*WITH_VGCANVAS*/
#endif
tk_init_assets();

View File

@ -1,5 +1,5 @@
TK_CONST_DATA_ALIGN(const unsigned char ui_image_value[]) = {
0x04,0x00,0x01,0x01,0x52,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x69,0x6d,0x61,0x67,0x65,0x5f,0x76,0x61,
0x04,0x00,0x01,0x01,0x42,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x69,0x6d,0x61,0x67,0x65,0x5f,0x76,0x61,
0x6c,0x75,0x65,0x00,0x64,0x61,0x74,0x61,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x12,0x12,0x22,0x11,0x77,0x69,0x6e,0x64,0x6f,0x77,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
@ -14,46 +14,45 @@ TK_CONST_DATA_ALIGN(const unsigned char ui_image_value[]) = {
0x29,0x00,0x00,0x69,0x6d,0x61,0x67,0x65,0x5f,0x76,0x61,0x6c,0x75,0x65,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x76,0x61,0x6c,0x75,0x65,0x00,0x30,0x00,0x69,
0x6d,0x61,0x67,0x65,0x00,0x62,0x61,0x74,0x74,0x65,0x72,0x79,0x5f,0x00,0x61,0x6e,0x69,0x6d,0x61,0x74,
0x69,0x6f,0x6e,0x00,0x76,0x61,0x6c,0x75,0x65,0x28,0x66,0x72,0x6f,0x6d,0x3d,0x30,0x2c,0x20,0x74,0x6f,
0x3d,0x35,0x2c,0x20,0x64,0x75,0x72,0x61,0x74,0x69,0x6f,0x6e,0x3d,0x31,0x30,0x30,0x30,0x30,0x29,0x00,
0x00,0x00,0x69,0x6d,0x61,0x67,0x65,0x5f,0x76,0x61,0x6c,0x75,0x65,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x6d,0x61,0x67,0x65,0x00,0x62,0x61,0x74,0x74,0x65,0x72,0x79,0x5f,0x00,0x63,0x6c,0x69,0x63,0x6b,0x5f,
0x61,0x64,0x64,0x5f,0x64,0x65,0x6c,0x74,0x61,0x00,0x31,0x00,0x6d,0x69,0x6e,0x00,0x30,0x00,0x6d,0x61,
0x78,0x00,0x35,0x00,0x00,0x00,0x69,0x6d,0x61,0x67,0x65,0x5f,0x76,0x61,0x6c,0x75,0x65,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x76,0x61,0x6c,0x75,0x65,0x00,0x30,0x00,0x69,0x6d,
0x61,0x67,0x65,0x00,0x62,0x61,0x74,0x74,0x65,0x72,0x79,0x5f,0x00,0x61,0x6e,0x69,0x6d,0x61,0x74,0x69,
0x6f,0x6e,0x00,0x76,0x61,0x6c,0x75,0x65,0x28,0x66,0x72,0x6f,0x6d,0x3d,0x30,0x2c,0x20,0x74,0x6f,0x3d,
0x35,0x2c,0x20,0x64,0x75,0x72,0x61,0x74,0x69,0x6f,0x6e,0x3d,0x31,0x30,0x30,0x30,0x30,0x29,0x00,0x00,
0x00,0x69,0x6d,0x61,0x67,0x65,0x5f,0x76,0x61,0x6c,0x75,0x65,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x76,0x61,0x6c,0x75,0x65,0x00,0x30,0x00,0x66,0x6f,0x72,
0x6d,0x61,0x74,0x00,0x25,0x30,0x32,0x64,0x00,0x69,0x6d,0x61,0x67,0x65,0x00,0x6e,0x75,0x6d,0x5f,0x00,
0x61,0x6e,0x69,0x6d,0x61,0x74,0x69,0x6f,0x6e,0x00,0x76,0x61,0x6c,0x75,0x65,0x28,0x66,0x72,0x6f,0x6d,
0x3d,0x31,0x30,0x2c,0x20,0x74,0x6f,0x3d,0x31,0x30,0x30,0x2c,0x20,0x64,0x75,0x72,0x61,0x74,0x69,0x6f,
0x6e,0x3d,0x31,0x30,0x30,0x30,0x30,0x30,0x29,0x00,0x00,0x00,0x69,0x6d,0x61,0x67,0x65,0x5f,0x76,0x61,
0x6c,0x75,0x65,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x76,0x61,0x6c,0x75,0x65,0x00,0x30,0x00,0x66,0x6f,0x72,0x6d,0x61,0x74,0x00,0x25,0x30,0x34,0x64,0x00,
0x69,0x6d,0x61,0x67,0x65,0x00,0x6e,0x75,0x6d,0x5f,0x00,0x61,0x6e,0x69,0x6d,0x61,0x74,0x69,0x6f,0x6e,
0x00,0x76,0x61,0x6c,0x75,0x65,0x28,0x66,0x72,0x6f,0x6d,0x3d,0x31,0x30,0x2c,0x20,0x74,0x6f,0x3d,0x31,
0x30,0x30,0x30,0x30,0x2c,0x20,0x64,0x75,0x72,0x61,0x74,0x69,0x6f,0x6e,0x3d,0x31,0x30,0x30,0x30,0x30,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x76,0x61,0x6c,0x75,0x65,0x00,
0x30,0x00,0x69,0x6d,0x61,0x67,0x65,0x00,0x62,0x61,0x74,0x74,0x65,0x72,0x79,0x5f,0x00,0x61,0x6e,0x69,
0x6d,0x61,0x74,0x69,0x6f,0x6e,0x00,0x76,0x61,0x6c,0x75,0x65,0x28,0x66,0x72,0x6f,0x6d,0x3d,0x30,0x2c,
0x20,0x74,0x6f,0x3d,0x35,0x2c,0x20,0x64,0x75,0x72,0x61,0x74,0x69,0x6f,0x6e,0x3d,0x31,0x30,0x30,0x30,
0x30,0x29,0x00,0x00,0x00,0x69,0x6d,0x61,0x67,0x65,0x5f,0x76,0x61,0x6c,0x75,0x65,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x76,0x61,0x6c,0x75,0x65,0x00,0x30,
0x00,0x66,0x6f,0x72,0x6d,0x61,0x74,0x00,0x25,0x30,0x32,0x2e,0x32,0x66,0x00,0x69,0x6d,0x61,0x67,0x65,
0x00,0x6e,0x75,0x6d,0x5f,0x00,0x61,0x6e,0x69,0x6d,0x61,0x74,0x69,0x6f,0x6e,0x00,0x76,0x61,0x6c,0x75,
0x65,0x28,0x66,0x72,0x6f,0x6d,0x3d,0x30,0x2c,0x20,0x74,0x6f,0x3d,0x31,0x30,0x30,0x2c,0x20,0x64,0x75,
0x72,0x61,0x74,0x69,0x6f,0x6e,0x3d,0x31,0x30,0x30,0x30,0x30,0x30,0x30,0x29,0x00,0x00,0x00,0x69,0x6d,
0x61,0x67,0x65,0x5f,0x76,0x61,0x6c,0x75,0x65,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x66,0x6f,0x72,0x6d,0x61,0x74,0x00,0x25,0x30,0x32,0x64,0x00,0x69,0x6d,0x61,0x67,0x65,0x00,0x6e,
0x75,0x6d,0x5f,0x00,0x61,0x6e,0x69,0x6d,0x61,0x74,0x69,0x6f,0x6e,0x00,0x76,0x61,0x6c,0x75,0x65,0x28,
0x66,0x72,0x6f,0x6d,0x3d,0x31,0x30,0x2c,0x20,0x74,0x6f,0x3d,0x31,0x30,0x30,0x2c,0x20,0x64,0x75,0x72,
0x61,0x74,0x69,0x6f,0x6e,0x3d,0x31,0x30,0x30,0x30,0x30,0x30,0x29,0x00,0x00,0x00,0x69,0x6d,0x61,0x67,
0x65,0x5f,0x76,0x61,0x6c,0x75,0x65,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x76,0x61,0x6c,0x75,0x65,0x00,0x30,0x00,0x66,0x6f,0x72,0x6d,0x61,0x74,
0x00,0x25,0x2e,0x34,0x66,0x00,0x69,0x6d,0x61,0x67,0x65,0x00,0x6e,0x75,0x6d,0x5f,0x00,0x61,0x6e,0x69,
0x6d,0x61,0x74,0x69,0x6f,0x6e,0x00,0x76,0x61,0x6c,0x75,0x65,0x28,0x66,0x72,0x6f,0x6d,0x3d,0x30,0x2c,
0x20,0x74,0x6f,0x3d,0x31,0x30,0x30,0x2c,0x20,0x64,0x75,0x72,0x61,0x74,0x69,0x6f,0x6e,0x3d,0x31,0x30,
0x30,0x30,0x30,0x30,0x30,0x29,0x00,0x00,0x00,0x00,0x62,0x75,0x74,0x74,0x6f,0x6e,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x76,0x61,0x6c,0x75,0x65,0x00,0x30,0x00,0x66,0x6f,0x72,0x6d,0x61,0x74,0x00,0x25,
0x30,0x34,0x64,0x00,0x69,0x6d,0x61,0x67,0x65,0x00,0x6e,0x75,0x6d,0x5f,0x00,0x61,0x6e,0x69,0x6d,0x61,
0x74,0x69,0x6f,0x6e,0x00,0x76,0x61,0x6c,0x75,0x65,0x28,0x66,0x72,0x6f,0x6d,0x3d,0x31,0x30,0x2c,0x20,
0x74,0x6f,0x3d,0x31,0x30,0x30,0x30,0x30,0x2c,0x20,0x64,0x75,0x72,0x61,0x74,0x69,0x6f,0x6e,0x3d,0x31,
0x30,0x30,0x30,0x30,0x30,0x29,0x00,0x00,0x00,0x69,0x6d,0x61,0x67,0x65,0x5f,0x76,0x61,0x6c,0x75,0x65,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x6e,0x61,
0x6d,0x65,0x00,0x63,0x6c,0x6f,0x73,0x65,0x00,0x73,0x65,0x6c,0x66,0x5f,0x6c,0x61,0x79,0x6f,0x75,0x74,
0x00,0x64,0x65,0x66,0x61,0x75,0x6c,0x74,0x28,0x78,0x3d,0x63,0x65,0x6e,0x74,0x65,0x72,0x2c,0x79,0x3d,
0x62,0x6f,0x74,0x74,0x6f,0x6d,0x3a,0x31,0x30,0x2c,0x77,0x3d,0x35,0x30,0x25,0x2c,0x68,0x3d,0x33,0x30,
0x29,0x00,0x66,0x6c,0x6f,0x61,0x74,0x69,0x6e,0x67,0x00,0x74,0x72,0x75,0x65,0x00,0x74,0x65,0x78,0x74,
0x00,0x43,0x6c,0x6f,0x73,0x65,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,};/*1154*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x76,0x61,0x6c,
0x75,0x65,0x00,0x30,0x00,0x66,0x6f,0x72,0x6d,0x61,0x74,0x00,0x25,0x30,0x32,0x2e,0x32,0x66,0x00,0x69,
0x6d,0x61,0x67,0x65,0x00,0x6e,0x75,0x6d,0x5f,0x00,0x61,0x6e,0x69,0x6d,0x61,0x74,0x69,0x6f,0x6e,0x00,
0x76,0x61,0x6c,0x75,0x65,0x28,0x66,0x72,0x6f,0x6d,0x3d,0x30,0x2c,0x20,0x74,0x6f,0x3d,0x31,0x30,0x30,
0x2c,0x20,0x64,0x75,0x72,0x61,0x74,0x69,0x6f,0x6e,0x3d,0x31,0x30,0x30,0x30,0x30,0x30,0x30,0x29,0x00,
0x00,0x00,0x69,0x6d,0x61,0x67,0x65,0x5f,0x76,0x61,0x6c,0x75,0x65,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x76,0x61,0x6c,0x75,0x65,0x00,0x30,0x00,0x66,0x6f,
0x72,0x6d,0x61,0x74,0x00,0x25,0x2e,0x34,0x66,0x00,0x69,0x6d,0x61,0x67,0x65,0x00,0x6e,0x75,0x6d,0x5f,
0x00,0x61,0x6e,0x69,0x6d,0x61,0x74,0x69,0x6f,0x6e,0x00,0x76,0x61,0x6c,0x75,0x65,0x28,0x66,0x72,0x6f,
0x6d,0x3d,0x30,0x2c,0x20,0x74,0x6f,0x3d,0x31,0x30,0x30,0x2c,0x20,0x64,0x75,0x72,0x61,0x74,0x69,0x6f,
0x6e,0x3d,0x31,0x30,0x30,0x30,0x30,0x30,0x30,0x29,0x00,0x00,0x00,0x00,0x62,0x75,0x74,0x74,0x6f,0x6e,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x6e,0x61,0x6d,0x65,0x00,0x63,0x6c,0x6f,0x73,0x65,0x00,0x73,0x65,0x6c,0x66,0x5f,0x6c,0x61,
0x79,0x6f,0x75,0x74,0x00,0x64,0x65,0x66,0x61,0x75,0x6c,0x74,0x28,0x78,0x3d,0x63,0x65,0x6e,0x74,0x65,
0x72,0x2c,0x79,0x3d,0x62,0x6f,0x74,0x74,0x6f,0x6d,0x3a,0x31,0x30,0x2c,0x77,0x3d,0x35,0x30,0x25,0x2c,
0x68,0x3d,0x33,0x30,0x29,0x00,0x66,0x6c,0x6f,0x61,0x74,0x69,0x6e,0x67,0x00,0x74,0x72,0x75,0x65,0x00,
0x74,0x65,0x78,0x74,0x00,0x43,0x6c,0x6f,0x73,0x65,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,};/*1138*/

View File

@ -1,7 +1,6 @@
<window anim_hint="htranslate">
<view x="0" y="0" w="100%" h="100%" children_layout="default(c=2,r=3)">
<image_value value="0" image="battery_"
animation="value(from=0, to=5, duration=10000)"/>
<image_value value="0" image="battery_" click_add_delta="1" min="0" max="5"/>
<image_value value="0" image="battery_"
animation="value(from=0, to=5, duration=10000)"/>

View File

@ -6,6 +6,7 @@
* 完善窗口管理器事件分发,窗口相关事件同时分发到控件。
* 完善SVG (感谢钟伟提供补丁)。
* 完善OpenGL shader感谢智明提供补丁
* 完善image value支持点击时加上一个增量增加到最大值后回到最小值。
* 2020/03/02
* 完善 README 中 Ubuntu 依赖软件包(感谢陈谭提供补丁)。

View File

@ -107,12 +107,21 @@ static ret_t image_value_get_prop(widget_t* widget, const char* name, value_t* v
if (tk_str_eq(name, WIDGET_PROP_VALUE)) {
value_set_float(v, image_value->value);
return RET_OK;
} else if (tk_str_eq(name, WIDGET_PROP_MIN)) {
value_set_float(v, image_value->min);
return RET_OK;
} else if (tk_str_eq(name, WIDGET_PROP_MAX)) {
value_set_float(v, image_value->max);
return RET_OK;
} else if (tk_str_eq(name, WIDGET_PROP_IMAGE)) {
value_set_str(v, image_value->image);
return RET_OK;
} else if (tk_str_eq(name, WIDGET_PROP_FORMAT)) {
value_set_str(v, image_value->format);
return RET_OK;
} else if (tk_str_eq(name, WIDGET_PROP_CLICK_ADD_DELTA)) {
value_set_float(v, image_value->click_add_delta);
return RET_OK;
}
return RET_NOT_FOUND;
@ -123,10 +132,16 @@ static ret_t image_value_set_prop(widget_t* widget, const char* name, const valu
if (tk_str_eq(name, WIDGET_PROP_VALUE)) {
return image_value_set_value(widget, value_float(v));
} else if (tk_str_eq(name, WIDGET_PROP_MIN)) {
return image_value_set_min(widget, value_float(v));
} else if (tk_str_eq(name, WIDGET_PROP_MAX)) {
return image_value_set_max(widget, value_float(v));
} else if (tk_str_eq(name, WIDGET_PROP_IMAGE)) {
return image_value_set_image(widget, value_str(v));
} else if (tk_str_eq(name, WIDGET_PROP_FORMAT)) {
return image_value_set_format(widget, value_str(v));
} else if (tk_str_eq(name, WIDGET_PROP_CLICK_ADD_DELTA)) {
return image_value_set_click_add_delta(widget, value_float(v));
}
return RET_NOT_FOUND;
@ -142,11 +157,79 @@ static ret_t image_value_on_destroy(widget_t* widget) {
return RET_OK;
}
ret_t image_value_add_delta(widget_t* widget) {
image_value_t* image_value = IMAGE_VALUE(widget);
return_value_if_fail(image_value != NULL, RET_BAD_PARAMS);
if (image_value->click_add_delta) {
float_t min = tk_min(image_value->min, image_value->max);
float_t max = tk_max(image_value->min, image_value->max);
return_value_if_fail(min < max, RET_BAD_PARAMS);
widget_dispatch_simple_event(widget, EVT_VALUE_WILL_CHANGE);
image_value->value += image_value->click_add_delta;
if (image_value->value > max) {
image_value->value = min;
} else if (image_value->value < min) {
image_value->value = max;
}
widget_dispatch_simple_event(widget, EVT_VALUE_CHANGED);
widget_invalidate(widget, NULL);
}
return RET_OK;
}
static ret_t image_value_on_event(widget_t* widget, event_t* e) {
uint16_t type = e->type;
image_value_t* image_value = IMAGE_VALUE(widget);
return_value_if_fail(image_value != NULL && widget != NULL, RET_BAD_PARAMS);
switch (type) {
case EVT_POINTER_DOWN: {
image_value->pressed = TRUE;
widget_grab(widget->parent, widget);
break;
}
case EVT_POINTER_DOWN_ABORT: {
image_value->pressed = FALSE;
widget_ungrab(widget->parent, widget);
break;
}
case EVT_POINTER_UP: {
if (image_value->pressed) {
image_value_add_delta(widget);
}
image_value->pressed = FALSE;
widget_ungrab(widget->parent, widget);
break;
}
default:
break;
}
return RET_OK;
}
static const char* s_image_value_properties[] = {WIDGET_PROP_VALUE,
WIDGET_PROP_MIN,
WIDGET_PROP_MAX,
WIDGET_PROP_FORMAT,
WIDGET_PROP_IMAGE,
WIDGET_PROP_CLICK_ADD_DELTA,
NULL};
TK_DECL_VTABLE(image_value) = {.size = sizeof(image_value_t),
.type = WIDGET_TYPE_IMAGE_VALUE,
.parent = TK_PARENT_VTABLE(widget),
.inputable = TRUE,
.clone_properties = s_image_value_properties,
.persistent_properties = s_image_value_properties,
.create = image_value_create,
.on_destroy = image_value_on_destroy,
.on_event = image_value_on_event,
.get_prop = image_value_get_prop,
.set_prop = image_value_set_prop,
.on_paint_self = image_value_on_paint_self};
@ -194,6 +277,33 @@ ret_t image_value_set_value(widget_t* widget, float_t value) {
return RET_OK;
}
ret_t image_value_set_click_add_delta(widget_t* widget, float_t click_add_delta) {
image_value_t* image_value = IMAGE_VALUE(widget);
return_value_if_fail(image_value != NULL, RET_BAD_PARAMS);
image_value->click_add_delta = click_add_delta;
return RET_OK;
}
ret_t image_value_set_min(widget_t* widget, float_t min) {
image_value_t* image_value = IMAGE_VALUE(widget);
return_value_if_fail(image_value != NULL, RET_BAD_PARAMS);
image_value->min = min;
return RET_OK;
}
ret_t image_value_set_max(widget_t* widget, float_t max) {
image_value_t* image_value = IMAGE_VALUE(widget);
return_value_if_fail(image_value != NULL, RET_BAD_PARAMS);
image_value->max = max;
return RET_OK;
}
widget_t* image_value_cast(widget_t* widget) {
return_value_if_fail(WIDGET_IS_INSTANCE_OF(widget, image_value), NULL);

View File

@ -40,6 +40,9 @@ BEGIN_C_DECLS
* * 2.image()
* * 3.
*
* click\_add\_delta为非0,
*
*
*image\_value\_t是[widget\_t](widget_t.md)widget\_t的函数均适用于image\_value\_t控件
*
*xml中使用"image\_value"
@ -82,14 +85,48 @@ typedef struct _image_value_t {
*/
char* format;
/**
* @property {float_t} click_add_delta
* @annotation ["set_prop","get_prop","readable","persitent","design","scriptable"]
*
*/
float_t click_add_delta;
/**
* @property {float_t} value
* @annotation ["set_prop","get_prop","readable","persitent","design","scriptable"]
*
*/
float_t value;
/**
* @property {float_t} min
* @annotation ["set_prop","get_prop","readable","persitent","design","scriptable"]
* (click\_add\_delta)
*/
float_t min;
/**
* @property {float_t} max
* @annotation ["set_prop","get_prop","readable","persitent","design","scriptable"]
* (click\_add\_delta)
*/
float_t max;
/*private*/
bool_t pressed;
} image_value_t;
/**
* @event {event_t} EVT_VALUE_WILL_CHANGE
* (click_add_delta为非0时)
*/
/**
* @event {event_t} EVT_VALUE_CHANGED
* (click_add_delta为非0时)
*/
/**
* @method image_value_create
* image_value对象
@ -126,6 +163,17 @@ ret_t image_value_set_image(widget_t* widget, const char* image);
*/
ret_t image_value_set_format(widget_t* widget, const char* format);
/**
* @method image_value_set_click_add_delta
*
* @annotation ["scriptable"]
* @param {widget_t*} widget image_value对象
* @param {float_t} delta
*
* @return {ret_t} RET_OK表示成功
*/
ret_t image_value_set_click_add_delta(widget_t* widget, float_t click_add_delta);
/**
* @method image_value_set_value
*
@ -137,6 +185,28 @@ ret_t image_value_set_format(widget_t* widget, const char* format);
*/
ret_t image_value_set_value(widget_t* widget, float_t value);
/**
* @method image_value_set_min
*
* @annotation ["scriptable"]
* @param {widget_t*} widget image_min对象
* @param {float_t} min
*
* @return {ret_t} RET_OK表示成功
*/
ret_t image_value_set_min(widget_t* widget, float_t min);
/**
* @method image_value_set_max
*
* @annotation ["scriptable"]
* @param {widget_t*} widget image_max对象
* @param {float_t} max
*
* @return {ret_t} RET_OK表示成功
*/
ret_t image_value_set_max(widget_t* widget, float_t max);
/**
* @method image_value_cast
* image_value对象(使)
@ -154,6 +224,8 @@ widget_t* image_value_cast(widget_t* widget);
/* "/"不是有效的文件名,所以把字符"/"映射成"slash" */
#define IMAGE_VALUE_MAP_SLASH "slash"
#define WIDGET_PROP_CLICK_ADD_DELTA "click_add_delta"
#ifndef IMAGE_VALUE_MAX_CHAR_NR
#define IMAGE_VALUE_MAX_CHAR_NR 8
#endif /*IMAGE_VALUE_MAX_CHAR_NR*/
@ -163,6 +235,9 @@ widget_t* image_value_cast(widget_t* widget);
/*public for subclass and runtime type check*/
TK_EXTERN_VTABLE(image_value);
/*public for test*/
ret_t image_value_add_delta(widget_t* widget);
END_C_DECLS
#endif /*TK_IMAGE_VALUE_H*/

View File

@ -35,3 +35,72 @@ TEST(ImageValue, cast) {
widget_destroy(w);
}
TEST(ImageValue, min_max) {
widget_t* w = image_value_create(NULL, 10, 20, 30, 40);
ASSERT_EQ(widget_set_prop_int(w, WIDGET_PROP_MIN, 1), RET_OK);
ASSERT_EQ(widget_get_prop_int(w, WIDGET_PROP_MIN, 0), 1);
ASSERT_EQ(widget_set_prop_int(w, WIDGET_PROP_MAX, 5), RET_OK);
ASSERT_EQ(widget_get_prop_int(w, WIDGET_PROP_MAX, 0), 5);
ASSERT_EQ(widget_set_prop_int(w, WIDGET_PROP_VALUE, 3), RET_OK);
ASSERT_EQ(widget_get_prop_int(w, WIDGET_PROP_VALUE, 0), 3);
widget_destroy(w);
}
TEST(ImageValue, add_delta_p) {
widget_t* w = image_value_create(NULL, 10, 20, 30, 40);
ASSERT_EQ(widget_set_prop_int(w, WIDGET_PROP_MIN, 1), RET_OK);
ASSERT_EQ(widget_get_prop_int(w, WIDGET_PROP_MIN, 0), 1);
ASSERT_EQ(widget_set_prop_int(w, WIDGET_PROP_MAX, 5), RET_OK);
ASSERT_EQ(widget_get_prop_int(w, WIDGET_PROP_MAX, 0), 5);
ASSERT_EQ(widget_set_prop_int(w, WIDGET_PROP_VALUE, 3), RET_OK);
ASSERT_EQ(widget_get_prop_int(w, WIDGET_PROP_VALUE, 0), 3);
ASSERT_EQ(widget_set_prop_int(w, WIDGET_PROP_CLICK_ADD_DELTA, 1), RET_OK);
ASSERT_EQ(widget_get_prop_int(w, WIDGET_PROP_CLICK_ADD_DELTA, 0), 1);
ASSERT_EQ(image_value_add_delta(w), RET_OK);
ASSERT_EQ(widget_get_prop_int(w, WIDGET_PROP_VALUE, 0), 4);
ASSERT_EQ(image_value_add_delta(w), RET_OK);
ASSERT_EQ(widget_get_prop_int(w, WIDGET_PROP_VALUE, 0), 5);
ASSERT_EQ(image_value_add_delta(w), RET_OK);
ASSERT_EQ(widget_get_prop_int(w, WIDGET_PROP_VALUE, 0), 1);
widget_destroy(w);
}
TEST(ImageValue, add_delta_n) {
widget_t* w = image_value_create(NULL, 10, 20, 30, 40);
ASSERT_EQ(widget_set_prop_int(w, WIDGET_PROP_MIN, 1), RET_OK);
ASSERT_EQ(widget_get_prop_int(w, WIDGET_PROP_MIN, 0), 1);
ASSERT_EQ(widget_set_prop_int(w, WIDGET_PROP_MAX, 5), RET_OK);
ASSERT_EQ(widget_get_prop_int(w, WIDGET_PROP_MAX, 0), 5);
ASSERT_EQ(widget_set_prop_int(w, WIDGET_PROP_VALUE, 3), RET_OK);
ASSERT_EQ(widget_get_prop_int(w, WIDGET_PROP_VALUE, 0), 3);
ASSERT_EQ(widget_set_prop_int(w, WIDGET_PROP_CLICK_ADD_DELTA, -1), RET_OK);
ASSERT_EQ(widget_get_prop_int(w, WIDGET_PROP_CLICK_ADD_DELTA, 0), -1);
ASSERT_EQ(image_value_add_delta(w), RET_OK);
ASSERT_EQ(widget_get_prop_int(w, WIDGET_PROP_VALUE, 0), 2);
ASSERT_EQ(image_value_add_delta(w), RET_OK);
ASSERT_EQ(widget_get_prop_int(w, WIDGET_PROP_VALUE, 0), 1);
ASSERT_EQ(image_value_add_delta(w), RET_OK);
ASSERT_EQ(widget_get_prop_int(w, WIDGET_PROP_VALUE, 0), 5);
widget_destroy(w);
}