mirror of
https://github.com/lvgl/lvgl.git
synced 2026-05-28 13:36:27 +08:00
feat(arc): add property API support
Signed-off-by: Neo Xu <neo.xu1990@gmail.com>
This commit is contained in:
@@ -104,6 +104,7 @@ enum _lv_prop_id_range_boundary_t {
|
|||||||
LV_PROPERTY_DROPDOWN_START = 0x0700, /* lv_dropdown.c */
|
LV_PROPERTY_DROPDOWN_START = 0x0700, /* lv_dropdown.c */
|
||||||
LV_PROPERTY_SLIDER_START = 0x0800, /* lv_slider.c */
|
LV_PROPERTY_SLIDER_START = 0x0800, /* lv_slider.c */
|
||||||
LV_PROPERTY_ANIMIMAGE_START = 0x0900, /* lv_animimage.c */
|
LV_PROPERTY_ANIMIMAGE_START = 0x0900, /* lv_animimage.c */
|
||||||
|
LV_PROPERTY_ARC_START = 0x0a00, /* lv_arc.c */
|
||||||
|
|
||||||
/*Special ID, use it to extend ID and make sure it's unique and compile time determinant*/
|
/*Special ID, use it to extend ID and make sure it's unique and compile time determinant*/
|
||||||
LV_PROPERTY_ID_BUILTIN_LAST = 0xffff, /*ID of 0x10000 ~ 0xfffffff is reserved for user*/
|
LV_PROPERTY_ID_BUILTIN_LAST = 0xffff, /*ID of 0x10000 ~ 0xfffffff is reserved for user*/
|
||||||
|
|||||||
@@ -59,6 +59,67 @@ static bool lv_arc_angle_within_bg_bounds(lv_obj_t * obj, const lv_value_precise
|
|||||||
/**********************
|
/**********************
|
||||||
* STATIC VARIABLES
|
* STATIC VARIABLES
|
||||||
**********************/
|
**********************/
|
||||||
|
|
||||||
|
#if LV_USE_OBJ_PROPERTY
|
||||||
|
static const lv_property_ops_t lv_arc_properties[] = {
|
||||||
|
{
|
||||||
|
.id = LV_PROPERTY_ARC_START_ANGLE,
|
||||||
|
.setter = lv_arc_set_start_angle,
|
||||||
|
.getter = lv_arc_get_angle_start,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
.id = LV_PROPERTY_ARC_END_ANGLE,
|
||||||
|
.setter = lv_arc_set_end_angle,
|
||||||
|
.getter = lv_arc_get_angle_end,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
.id = LV_PROPERTY_ARC_BG_START_ANGLE,
|
||||||
|
.setter = lv_arc_set_bg_start_angle,
|
||||||
|
.getter = lv_arc_get_bg_angle_start,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
.id = LV_PROPERTY_ARC_BG_END_ANGLE,
|
||||||
|
.setter = lv_arc_set_bg_end_angle,
|
||||||
|
.getter = lv_arc_get_bg_angle_end,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
.id = LV_PROPERTY_ARC_ROTATION,
|
||||||
|
.setter = lv_arc_set_rotation,
|
||||||
|
.getter = lv_arc_get_rotation,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
.id = LV_PROPERTY_ARC_MODE,
|
||||||
|
.setter = lv_arc_set_mode,
|
||||||
|
.getter = lv_arc_get_mode,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
.id = LV_PROPERTY_ARC_VALUE,
|
||||||
|
.setter = lv_arc_set_value,
|
||||||
|
.getter = lv_arc_get_value,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
.id = LV_PROPERTY_ARC_MIN_VALUE,
|
||||||
|
.setter = lv_arc_set_min_value,
|
||||||
|
.getter = lv_arc_get_min_value,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
.id = LV_PROPERTY_ARC_MAX_VALUE,
|
||||||
|
.setter = lv_arc_set_max_value,
|
||||||
|
.getter = lv_arc_get_max_value,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
.id = LV_PROPERTY_ARC_CHANGE_RATE,
|
||||||
|
.setter = lv_arc_set_change_rate,
|
||||||
|
.getter = lv_arc_get_change_rate,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
.id = LV_PROPERTY_ARC_KNOB_OFFSET,
|
||||||
|
.setter = lv_arc_set_knob_offset,
|
||||||
|
.getter = lv_arc_get_knob_offset,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
const lv_obj_class_t lv_arc_class = {
|
const lv_obj_class_t lv_arc_class = {
|
||||||
.constructor_cb = lv_arc_constructor,
|
.constructor_cb = lv_arc_constructor,
|
||||||
.event_cb = lv_arc_event,
|
.event_cb = lv_arc_event,
|
||||||
@@ -66,6 +127,7 @@ const lv_obj_class_t lv_arc_class = {
|
|||||||
.editable = LV_OBJ_CLASS_EDITABLE_TRUE,
|
.editable = LV_OBJ_CLASS_EDITABLE_TRUE,
|
||||||
.base_class = &lv_obj_class,
|
.base_class = &lv_obj_class,
|
||||||
.name = "lv_arc",
|
.name = "lv_arc",
|
||||||
|
LV_PROPERTY_CLASS_FIELDS(arc, ARC)
|
||||||
};
|
};
|
||||||
|
|
||||||
/**********************
|
/**********************
|
||||||
@@ -368,6 +430,12 @@ int32_t lv_arc_get_knob_offset(const lv_obj_t * obj)
|
|||||||
return ((lv_arc_t *)obj)->knob_offset;
|
return ((lv_arc_t *)obj)->knob_offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint32_t lv_arc_get_change_rate(lv_obj_t * obj)
|
||||||
|
{
|
||||||
|
LV_ASSERT_OBJ(obj, MY_CLASS);
|
||||||
|
return ((lv_arc_t *)obj)->chg_rate;
|
||||||
|
}
|
||||||
|
|
||||||
/*=====================
|
/*=====================
|
||||||
* Other functions
|
* Other functions
|
||||||
*====================*/
|
*====================*/
|
||||||
@@ -1080,5 +1148,4 @@ static void arc_value_observer_cb(lv_observer_t * observer, lv_subject_t * subje
|
|||||||
|
|
||||||
#endif /*LV_USE_OBSERVER*/
|
#endif /*LV_USE_OBSERVER*/
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -39,6 +39,23 @@ typedef enum {
|
|||||||
|
|
||||||
LV_ATTRIBUTE_EXTERN_DATA extern const lv_obj_class_t lv_arc_class;
|
LV_ATTRIBUTE_EXTERN_DATA extern const lv_obj_class_t lv_arc_class;
|
||||||
|
|
||||||
|
#if LV_USE_OBJ_PROPERTY
|
||||||
|
enum _lv_property_arc_id_t {
|
||||||
|
LV_PROPERTY_ID(ARC, START_ANGLE, LV_PROPERTY_TYPE_PRECISE, 0),
|
||||||
|
LV_PROPERTY_ID(ARC, END_ANGLE, LV_PROPERTY_TYPE_PRECISE, 1),
|
||||||
|
LV_PROPERTY_ID(ARC, BG_START_ANGLE, LV_PROPERTY_TYPE_PRECISE, 2),
|
||||||
|
LV_PROPERTY_ID(ARC, BG_END_ANGLE, LV_PROPERTY_TYPE_PRECISE, 3),
|
||||||
|
LV_PROPERTY_ID(ARC, ROTATION, LV_PROPERTY_TYPE_INT, 4),
|
||||||
|
LV_PROPERTY_ID(ARC, MODE, LV_PROPERTY_TYPE_INT, 5),
|
||||||
|
LV_PROPERTY_ID(ARC, VALUE, LV_PROPERTY_TYPE_INT, 6),
|
||||||
|
LV_PROPERTY_ID(ARC, MIN_VALUE, LV_PROPERTY_TYPE_INT, 7),
|
||||||
|
LV_PROPERTY_ID(ARC, MAX_VALUE, LV_PROPERTY_TYPE_INT, 8),
|
||||||
|
LV_PROPERTY_ID(ARC, CHANGE_RATE, LV_PROPERTY_TYPE_INT, 9),
|
||||||
|
LV_PROPERTY_ID(ARC, KNOB_OFFSET, LV_PROPERTY_TYPE_INT, 10),
|
||||||
|
LV_PROPERTY_ARC_END,
|
||||||
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
/**********************
|
/**********************
|
||||||
* GLOBAL PROTOTYPES
|
* GLOBAL PROTOTYPES
|
||||||
**********************/
|
**********************/
|
||||||
@@ -233,6 +250,13 @@ int32_t lv_arc_get_rotation(const lv_obj_t * obj);
|
|||||||
*/
|
*/
|
||||||
int32_t lv_arc_get_knob_offset(const lv_obj_t * obj);
|
int32_t lv_arc_get_knob_offset(const lv_obj_t * obj);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the change rate of an arc
|
||||||
|
* @param obj pointer to an arc object
|
||||||
|
* @return the change rate
|
||||||
|
*/
|
||||||
|
uint32_t lv_arc_get_change_rate(lv_obj_t * obj);
|
||||||
|
|
||||||
/*=====================
|
/*=====================
|
||||||
* Other functions
|
* Other functions
|
||||||
*====================*/
|
*====================*/
|
||||||
|
|||||||
@@ -309,4 +309,91 @@ static void dummy_event_cb2(lv_event_t * e)
|
|||||||
event_cnt2++;
|
event_cnt2++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void test_arc_properties(void)
|
||||||
|
{
|
||||||
|
#if LV_USE_OBJ_PROPERTY
|
||||||
|
lv_obj_t * obj = lv_arc_create(lv_screen_active());
|
||||||
|
lv_property_t prop = { };
|
||||||
|
|
||||||
|
/* Test START_ANGLE property (PRECISE type) */
|
||||||
|
prop.id = LV_PROPERTY_ARC_START_ANGLE;
|
||||||
|
prop.precise = 45;
|
||||||
|
TEST_ASSERT_TRUE(lv_obj_set_property(obj, &prop) == LV_RESULT_OK);
|
||||||
|
TEST_ASSERT_EQUAL_INT(45, lv_obj_get_property(obj, LV_PROPERTY_ARC_START_ANGLE).precise);
|
||||||
|
TEST_ASSERT_EQUAL_INT(45, lv_arc_get_angle_start(obj));
|
||||||
|
|
||||||
|
/* Test END_ANGLE property (PRECISE type) */
|
||||||
|
prop.id = LV_PROPERTY_ARC_END_ANGLE;
|
||||||
|
prop.precise = 270;
|
||||||
|
TEST_ASSERT_TRUE(lv_obj_set_property(obj, &prop) == LV_RESULT_OK);
|
||||||
|
TEST_ASSERT_EQUAL_INT(270, lv_obj_get_property(obj, LV_PROPERTY_ARC_END_ANGLE).precise);
|
||||||
|
TEST_ASSERT_EQUAL_INT(270, lv_arc_get_angle_end(obj));
|
||||||
|
|
||||||
|
/* Test BG_START_ANGLE property (PRECISE type) */
|
||||||
|
prop.id = LV_PROPERTY_ARC_BG_START_ANGLE;
|
||||||
|
prop.precise = 30;
|
||||||
|
TEST_ASSERT_TRUE(lv_obj_set_property(obj, &prop) == LV_RESULT_OK);
|
||||||
|
TEST_ASSERT_EQUAL_INT(30, lv_obj_get_property(obj, LV_PROPERTY_ARC_BG_START_ANGLE).precise);
|
||||||
|
TEST_ASSERT_EQUAL_INT(30, lv_arc_get_bg_angle_start(obj));
|
||||||
|
|
||||||
|
/* Test BG_END_ANGLE property (PRECISE type) */
|
||||||
|
prop.id = LV_PROPERTY_ARC_BG_END_ANGLE;
|
||||||
|
prop.precise = 300;
|
||||||
|
TEST_ASSERT_TRUE(lv_obj_set_property(obj, &prop) == LV_RESULT_OK);
|
||||||
|
TEST_ASSERT_EQUAL_INT(300, lv_obj_get_property(obj, LV_PROPERTY_ARC_BG_END_ANGLE).precise);
|
||||||
|
TEST_ASSERT_EQUAL_INT(300, lv_arc_get_bg_angle_end(obj));
|
||||||
|
|
||||||
|
/* Test ROTATION property (INT type) */
|
||||||
|
prop.id = LV_PROPERTY_ARC_ROTATION;
|
||||||
|
prop.num = 90;
|
||||||
|
TEST_ASSERT_TRUE(lv_obj_set_property(obj, &prop) == LV_RESULT_OK);
|
||||||
|
TEST_ASSERT_EQUAL_INT(90, lv_obj_get_property(obj, LV_PROPERTY_ARC_ROTATION).num);
|
||||||
|
TEST_ASSERT_EQUAL_INT(90, lv_arc_get_rotation(obj));
|
||||||
|
|
||||||
|
/* Test MODE property (INT type) */
|
||||||
|
prop.id = LV_PROPERTY_ARC_MODE;
|
||||||
|
prop.num = LV_ARC_MODE_SYMMETRICAL;
|
||||||
|
TEST_ASSERT_TRUE(lv_obj_set_property(obj, &prop) == LV_RESULT_OK);
|
||||||
|
TEST_ASSERT_EQUAL_INT(LV_ARC_MODE_SYMMETRICAL, lv_obj_get_property(obj, LV_PROPERTY_ARC_MODE).num);
|
||||||
|
TEST_ASSERT_EQUAL_INT(LV_ARC_MODE_SYMMETRICAL, lv_arc_get_mode(obj));
|
||||||
|
|
||||||
|
/* Test VALUE property (INT type) */
|
||||||
|
lv_arc_set_range(obj, 0, 100);
|
||||||
|
prop.id = LV_PROPERTY_ARC_VALUE;
|
||||||
|
prop.num = 75;
|
||||||
|
TEST_ASSERT_TRUE(lv_obj_set_property(obj, &prop) == LV_RESULT_OK);
|
||||||
|
TEST_ASSERT_EQUAL_INT(75, lv_obj_get_property(obj, LV_PROPERTY_ARC_VALUE).num);
|
||||||
|
TEST_ASSERT_EQUAL_INT(75, lv_arc_get_value(obj));
|
||||||
|
|
||||||
|
/* Test MIN_VALUE property (INT type) */
|
||||||
|
prop.id = LV_PROPERTY_ARC_MIN_VALUE;
|
||||||
|
prop.num = 10;
|
||||||
|
TEST_ASSERT_TRUE(lv_obj_set_property(obj, &prop) == LV_RESULT_OK);
|
||||||
|
TEST_ASSERT_EQUAL_INT(10, lv_obj_get_property(obj, LV_PROPERTY_ARC_MIN_VALUE).num);
|
||||||
|
TEST_ASSERT_EQUAL_INT(10, lv_arc_get_min_value(obj));
|
||||||
|
|
||||||
|
/* Test MAX_VALUE property (INT type) */
|
||||||
|
prop.id = LV_PROPERTY_ARC_MAX_VALUE;
|
||||||
|
prop.num = 200;
|
||||||
|
TEST_ASSERT_TRUE(lv_obj_set_property(obj, &prop) == LV_RESULT_OK);
|
||||||
|
TEST_ASSERT_EQUAL_INT(200, lv_obj_get_property(obj, LV_PROPERTY_ARC_MAX_VALUE).num);
|
||||||
|
TEST_ASSERT_EQUAL_INT(200, lv_arc_get_max_value(obj));
|
||||||
|
|
||||||
|
/* Test CHANGE_RATE property (INT type) */
|
||||||
|
prop.id = LV_PROPERTY_ARC_CHANGE_RATE;
|
||||||
|
prop.num = 50;
|
||||||
|
TEST_ASSERT_TRUE(lv_obj_set_property(obj, &prop) == LV_RESULT_OK);
|
||||||
|
TEST_ASSERT_EQUAL_INT(50, lv_obj_get_property(obj, LV_PROPERTY_ARC_CHANGE_RATE).num);
|
||||||
|
|
||||||
|
/* Test KNOB_OFFSET property (INT type) */
|
||||||
|
prop.id = LV_PROPERTY_ARC_KNOB_OFFSET;
|
||||||
|
prop.num = 5;
|
||||||
|
TEST_ASSERT_TRUE(lv_obj_set_property(obj, &prop) == LV_RESULT_OK);
|
||||||
|
TEST_ASSERT_EQUAL_INT(5, lv_obj_get_property(obj, LV_PROPERTY_ARC_KNOB_OFFSET).num);
|
||||||
|
TEST_ASSERT_EQUAL_INT(5, lv_arc_get_knob_offset(obj));
|
||||||
|
|
||||||
|
lv_obj_delete(obj);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user