feat(arc): add knob offset utility (#3589)
Co-authored-by: tvanfossen <vanfosst@gmail.com> Co-authored-by: Gabor Kiss-Vamosi <kisvegabor@gmail.com>
This commit is contained in:
committed by
GitHub
parent
46f7384320
commit
5c71bc1434
@@ -41,6 +41,10 @@ The mode can be set by `lv_arc_set_mode(arc, LV_ARC_MODE_...)` and used only if
|
|||||||
If the arc is pressed the current value will set with a limited speed according to the set *change rate*.
|
If the arc is pressed the current value will set with a limited speed according to the set *change rate*.
|
||||||
The change rate is defined in degree/second unit and can be set with `lv_arc_set_change_rage(arc, rate)`
|
The change rate is defined in degree/second unit and can be set with `lv_arc_set_change_rage(arc, rate)`
|
||||||
|
|
||||||
|
### Knob offset
|
||||||
|
Changing the knob offset allows the location of the knob to be moved relative to the end of the arc
|
||||||
|
The knob offset can be set by `lv_arc_set_knob_offset(arc, offset_angle)`, will only be visible if LV_PART_KNOB is visible
|
||||||
|
|
||||||
|
|
||||||
### Setting the indicator manually
|
### Setting the indicator manually
|
||||||
It's also possible to set the angles of the indicator arc directly with `lv_arc_set_angles(arc, start_angle, end_angle)` function or `lv_arc_set_start/end_angle(arc, start_angle)`.
|
It's also possible to set the angles of the indicator arc directly with `lv_arc_set_angles(arc, start_angle, end_angle)` function or `lv_arc_set_start/end_angle(arc, start_angle)`.
|
||||||
|
|||||||
@@ -266,6 +266,14 @@ void lv_arc_set_change_rate(lv_obj_t * obj, uint16_t rate)
|
|||||||
arc->chg_rate = rate;
|
arc->chg_rate = rate;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void lv_arc_set_knob_offset(lv_obj_t * obj, int16_t offset)
|
||||||
|
{
|
||||||
|
LV_ASSERT_OBJ(obj, MY_CLASS);
|
||||||
|
lv_arc_t * arc = (lv_arc_t *)obj;
|
||||||
|
|
||||||
|
arc->knob_offset = offset;
|
||||||
|
}
|
||||||
|
|
||||||
/*=====================
|
/*=====================
|
||||||
* Getter functions
|
* Getter functions
|
||||||
*====================*/
|
*====================*/
|
||||||
@@ -324,6 +332,12 @@ int16_t lv_arc_get_rotation(const lv_obj_t * obj)
|
|||||||
return ((lv_arc_t *)obj)->rotation;
|
return ((lv_arc_t *)obj)->rotation;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int16_t lv_arc_get_knob_offset(const lv_obj_t * obj)
|
||||||
|
{
|
||||||
|
LV_ASSERT_OBJ(obj, MY_CLASS);
|
||||||
|
return ((lv_arc_t *)obj)->knob_offset;
|
||||||
|
}
|
||||||
|
|
||||||
/*=====================
|
/*=====================
|
||||||
* Other functions
|
* Other functions
|
||||||
*====================*/
|
*====================*/
|
||||||
@@ -785,8 +799,9 @@ static void get_knob_area(lv_obj_t * obj, const lv_point_t * center, lv_coord_t
|
|||||||
r -= indic_width_half;
|
r -= indic_width_half;
|
||||||
|
|
||||||
lv_coord_t angle = get_angle(obj);
|
lv_coord_t angle = get_angle(obj);
|
||||||
lv_coord_t knob_x = (r * lv_trigo_sin(angle + 90)) >> LV_TRIGO_SHIFT;
|
lv_coord_t knob_offset = lv_arc_get_knob_offset(obj);
|
||||||
lv_coord_t knob_y = (r * lv_trigo_sin(angle)) >> LV_TRIGO_SHIFT;
|
lv_coord_t knob_x = (r * lv_trigo_sin(knob_offset + angle + 90)) >> LV_TRIGO_SHIFT;
|
||||||
|
lv_coord_t knob_y = (r * lv_trigo_sin(knob_offset + angle)) >> LV_TRIGO_SHIFT;
|
||||||
|
|
||||||
lv_coord_t left_knob = lv_obj_get_style_pad_left(obj, LV_PART_KNOB);
|
lv_coord_t left_knob = lv_obj_get_style_pad_left(obj, LV_PART_KNOB);
|
||||||
lv_coord_t right_knob = lv_obj_get_style_pad_right(obj, LV_PART_KNOB);
|
lv_coord_t right_knob = lv_obj_get_style_pad_right(obj, LV_PART_KNOB);
|
||||||
|
|||||||
@@ -50,6 +50,7 @@ typedef struct {
|
|||||||
uint16_t chg_rate; /*Drag angle rate of change of the arc (degrees/sec)*/
|
uint16_t chg_rate; /*Drag angle rate of change of the arc (degrees/sec)*/
|
||||||
uint32_t last_tick; /*Last dragging event timestamp of the arc*/
|
uint32_t last_tick; /*Last dragging event timestamp of the arc*/
|
||||||
int16_t last_angle; /*Last dragging angle of the arc*/
|
int16_t last_angle; /*Last dragging angle of the arc*/
|
||||||
|
int16_t knob_offset; /*knob offset from the main arc*/
|
||||||
} lv_arc_t;
|
} lv_arc_t;
|
||||||
|
|
||||||
extern const lv_obj_class_t lv_arc_class;
|
extern const lv_obj_class_t lv_arc_class;
|
||||||
@@ -163,6 +164,13 @@ void lv_arc_set_range(lv_obj_t * obj, int16_t min, int16_t max);
|
|||||||
*/
|
*/
|
||||||
void lv_arc_set_change_rate(lv_obj_t * obj, uint16_t rate);
|
void lv_arc_set_change_rate(lv_obj_t * obj, uint16_t rate);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set an offset for the knob from the main arc object
|
||||||
|
* @param arc pointer to an arc object
|
||||||
|
* @param offset knob offset from main arc
|
||||||
|
*/
|
||||||
|
void lv_arc_set_knob_offset(lv_obj_t * arc, int16_t offset);
|
||||||
|
|
||||||
/*=====================
|
/*=====================
|
||||||
* Getter functions
|
* Getter functions
|
||||||
*====================*/
|
*====================*/
|
||||||
@@ -230,6 +238,13 @@ lv_arc_mode_t lv_arc_get_mode(const lv_obj_t * obj);
|
|||||||
*/
|
*/
|
||||||
int16_t lv_arc_get_rotation(const lv_obj_t * obj);
|
int16_t lv_arc_get_rotation(const lv_obj_t * obj);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the current knob offset
|
||||||
|
* @param arc pointer to an arc object
|
||||||
|
* @return arc's current knob offset
|
||||||
|
*/
|
||||||
|
int16_t lv_arc_get_knob_offset(const lv_obj_t * obj);
|
||||||
|
|
||||||
/*=====================
|
/*=====================
|
||||||
* Other functions
|
* Other functions
|
||||||
*====================*/
|
*====================*/
|
||||||
|
|||||||
Reference in New Issue
Block a user