1
0
mirror of https://github.com/lvgl/lvgl.git synced 2025-01-14 06:42:58 +08:00

feat(slider): add property interface

Signed-off-by: Neo Xu <neo.xu1990@gmail.com>
This commit is contained in:
Neo Xu 2024-11-30 23:52:22 +08:00 committed by Gabor Kiss-Vamosi
parent 133b6fc3f8
commit 4eacf15f59
5 changed files with 147 additions and 0 deletions

View File

@ -16,6 +16,7 @@
extern const lv_property_name_t lv_label_property_names[4];
extern const lv_property_name_t lv_obj_property_names[73];
extern const lv_property_name_t lv_roller_property_names[3];
extern const lv_property_name_t lv_slider_property_names[8];
extern const lv_property_name_t lv_style_property_names[115];
extern const lv_property_name_t lv_textarea_property_names[15];
#endif

View File

@ -0,0 +1,30 @@
/**
* GENERATED FILE, DO NOT EDIT IT!
* @file lv_slider_properties.c
*/
#include "../slider/lv_slider.h"
#if LV_USE_OBJ_PROPERTY && LV_USE_OBJ_PROPERTY_NAME
#if LV_USE_SLIDER
/**
* Slider widget property names, name must be in order.
* Generated code from properties.py
*/
/* *INDENT-OFF* */
const lv_property_name_t lv_slider_property_names[8] = {
{"is_dragged", LV_PROPERTY_SLIDER_IS_DRAGGED,},
{"is_symmetrical", LV_PROPERTY_SLIDER_IS_SYMMETRICAL,},
{"left_value", LV_PROPERTY_SLIDER_LEFT_VALUE,},
{"max_value", LV_PROPERTY_SLIDER_MAX_VALUE,},
{"min_value", LV_PROPERTY_SLIDER_MIN_VALUE,},
{"mode", LV_PROPERTY_SLIDER_MODE,},
{"range", LV_PROPERTY_SLIDER_RANGE,},
{"value", LV_PROPERTY_SLIDER_VALUE,},
};
#endif /*LV_USE_SLIDER*/
/* *INDENT-ON* */
#endif

View File

@ -49,6 +49,52 @@ static void update_knob_pos(lv_obj_t * obj, bool check_drag);
/**********************
* STATIC VARIABLES
**********************/
#if LV_USE_OBJ_PROPERTY
static const lv_property_ops_t properties[] = {
{
.id = LV_PROPERTY_SLIDER_VALUE,
.setter = lv_slider_set_value,
.getter = lv_slider_get_value,
},
{
.id = LV_PROPERTY_SLIDER_LEFT_VALUE,
.setter = lv_slider_set_left_value,
.getter = lv_slider_get_left_value,
},
{
.id = LV_PROPERTY_SLIDER_RANGE,
.setter = lv_slider_set_range,
.getter = NULL,
},
{
.id = LV_PROPERTY_SLIDER_MIN_VALUE,
.setter = NULL,
.getter = lv_slider_get_min_value,
},
{
.id = LV_PROPERTY_SLIDER_MAX_VALUE,
.setter = NULL,
.getter = lv_slider_get_max_value,
},
{
.id = LV_PROPERTY_SLIDER_MODE,
.setter = lv_slider_set_mode,
.getter = lv_slider_get_mode,
},
{
.id = LV_PROPERTY_SLIDER_IS_DRAGGED,
.setter = NULL,
.getter = lv_slider_is_dragged,
},
{
.id = LV_PROPERTY_SLIDER_IS_SYMMETRICAL,
.setter = NULL,
.getter = lv_slider_is_symmetrical,
},
};
#endif
const lv_obj_class_t lv_slider_class = {
.constructor_cb = lv_slider_constructor,
.event_cb = lv_slider_event,
@ -57,6 +103,17 @@ const lv_obj_class_t lv_slider_class = {
.instance_size = sizeof(lv_slider_t),
.base_class = &lv_bar_class,
.name = "slider",
#if LV_USE_OBJ_PROPERTY
.prop_index_start = LV_PROPERTY_SLIDER_START,
.prop_index_end = LV_PROPERTY_SLIDER_END,
.properties = properties,
.properties_count = sizeof(properties) / sizeof(properties[0]),
#if LV_USE_OBJ_PROPERTY_NAME
.property_names = lv_slider_property_names,
.names_count = sizeof(lv_slider_property_names) / sizeof(lv_property_name_t),
#endif
#endif
};
/**********************

View File

@ -43,6 +43,19 @@ typedef enum {
LV_ATTRIBUTE_EXTERN_DATA extern const lv_obj_class_t lv_slider_class;
#if LV_USE_OBJ_PROPERTY
enum {
LV_PROPERTY_ID2(SLIDER, VALUE, LV_PROPERTY_TYPE_INT, LV_PROPERTY_TYPE_BOOL, 0),
LV_PROPERTY_ID2(SLIDER, LEFT_VALUE, LV_PROPERTY_TYPE_INT, LV_PROPERTY_TYPE_BOOL, 1),
LV_PROPERTY_ID2(SLIDER, RANGE, LV_PROPERTY_TYPE_INT, LV_PROPERTY_TYPE_INT, 2),
LV_PROPERTY_ID(SLIDER, MIN_VALUE, LV_PROPERTY_TYPE_INT, 4),
LV_PROPERTY_ID(SLIDER, MAX_VALUE, LV_PROPERTY_TYPE_INT, 5),
LV_PROPERTY_ID(SLIDER, MODE, LV_PROPERTY_TYPE_INT, 6),
LV_PROPERTY_ID(SLIDER, IS_DRAGGED, LV_PROPERTY_TYPE_BOOL, 7),
LV_PROPERTY_ID(SLIDER, IS_SYMMETRICAL, LV_PROPERTY_TYPE_BOOL, 8),
LV_PROPERTY_SLIDER_END,
};
#endif
/**********************
* GLOBAL PROTOTYPES
**********************/

View File

@ -212,4 +212,50 @@ void test_slider_range_event_hit_test(void)
TEST_ASSERT(info.res);
}
void test_slider_properties(void)
{
#if LV_USE_OBJ_PROPERTY
lv_obj_t * obj = lv_slider_create(lv_screen_active());
lv_property_t prop = { };
prop.id = LV_PROPERTY_SLIDER_RANGE;
prop.arg1.num = 10;
prop.arg2.num = 100;
TEST_ASSERT_TRUE(lv_obj_set_property(obj, &prop) == LV_RESULT_OK);
TEST_ASSERT_EQUAL_INT(lv_slider_get_min_value(obj), 10);
TEST_ASSERT_EQUAL_INT(lv_slider_get_max_value(obj), 100);
TEST_ASSERT_EQUAL_INT(10, lv_obj_get_property(obj, LV_PROPERTY_SLIDER_MIN_VALUE).num);
TEST_ASSERT_EQUAL_INT(100, lv_obj_get_property(obj, LV_PROPERTY_SLIDER_MAX_VALUE).num);
prop.id = LV_PROPERTY_SLIDER_VALUE;
prop.arg1.num = 50;
prop.arg2.enable = false;
TEST_ASSERT_TRUE(lv_obj_set_property(obj, &prop) == LV_RESULT_OK);
TEST_ASSERT_EQUAL_INT(lv_slider_get_value(obj), 50);
TEST_ASSERT_EQUAL_INT(50, lv_obj_get_property(obj, LV_PROPERTY_SLIDER_VALUE).num);
prop.id = LV_PROPERTY_SLIDER_MODE;
prop.num = LV_SLIDER_MODE_RANGE;
TEST_ASSERT_TRUE(lv_obj_set_property(obj, &prop) == LV_RESULT_OK);
TEST_ASSERT_EQUAL_INT(LV_SLIDER_MODE_RANGE, lv_obj_get_property(obj, LV_PROPERTY_SLIDER_MODE).num);
prop.id = LV_PROPERTY_SLIDER_LEFT_VALUE;
prop.arg1.num = 40;
prop.arg2.enable = false;
TEST_ASSERT_TRUE(lv_obj_set_property(obj, &prop) == LV_RESULT_OK);
TEST_ASSERT_EQUAL_INT(40, lv_slider_get_left_value(obj));
TEST_ASSERT_EQUAL_INT(40, lv_obj_get_property(obj, LV_PROPERTY_SLIDER_LEFT_VALUE).num);
prop.id = LV_PROPERTY_SLIDER_IS_DRAGGED;
TEST_ASSERT_FALSE(lv_slider_is_dragged(obj));
TEST_ASSERT_FALSE(lv_obj_get_property(obj, LV_PROPERTY_SLIDER_IS_DRAGGED).enable);
prop.id = LV_PROPERTY_SLIDER_IS_SYMMETRICAL;
TEST_ASSERT_FALSE(lv_slider_is_dragged(obj));
TEST_ASSERT_FALSE(lv_obj_get_property(obj, LV_PROPERTY_SLIDER_IS_SYMMETRICAL).enable);
#endif
}
#endif