diff --git a/demos/assets.c b/demos/assets.c index a76a92787..fb5fec326 100644 --- a/demos/assets.c +++ b/demos/assets.c @@ -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(); diff --git a/demos/assets/default/inc/ui/image_value.data b/demos/assets/default/inc/ui/image_value.data index 19227e079..2bd37d896 100644 --- a/demos/assets/default/inc/ui/image_value.data +++ b/demos/assets/default/inc/ui/image_value.data @@ -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*/ diff --git a/demos/assets/default/raw/ui/image_value.bin b/demos/assets/default/raw/ui/image_value.bin index cec1cf2f6..de728fc6b 100644 Binary files a/demos/assets/default/raw/ui/image_value.bin and b/demos/assets/default/raw/ui/image_value.bin differ diff --git a/demos/assets/default/raw/ui/image_value.xml b/demos/assets/default/raw/ui/image_value.xml index 5f1e03a58..8b8f811f9 100644 --- a/demos/assets/default/raw/ui/image_value.xml +++ b/demos/assets/default/raw/ui/image_value.xml @@ -1,7 +1,6 @@ - + diff --git a/docs/changes.md b/docs/changes.md index 2f681752b..fb4b967c6 100644 --- a/docs/changes.md +++ b/docs/changes.md @@ -6,6 +6,7 @@ * 完善窗口管理器事件分发,窗口相关事件同时分发到控件。 * 完善SVG (感谢钟伟提供补丁)。 * 完善OpenGL shader(感谢智明提供补丁)。 + * 完善image value,支持点击时加上一个增量,增加到最大值后回到最小值。 * 2020/03/02 * 完善 README 中 Ubuntu 依赖软件包(感谢陈谭提供补丁)。 diff --git a/src/ext_widgets/image_value/image_value.c b/src/ext_widgets/image_value/image_value.c index 91e04e90a..64e639095 100644 --- a/src/ext_widgets/image_value/image_value.c +++ b/src/ext_widgets/image_value/image_value.c @@ -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); diff --git a/src/ext_widgets/image_value/image_value.h b/src/ext_widgets/image_value/image_value.h index b5e7bdf71..aa543076e 100644 --- a/src/ext_widgets/image_value/image_value.h +++ b/src/ext_widgets/image_value/image_value.h @@ -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*/ diff --git a/tests/image_value_test.cc b/tests/image_value_test.cc index 9929f5f34..c75b88c7f 100644 --- a/tests/image_value_test.cc +++ b/tests/image_value_test.cc @@ -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); +}