Update lvgl to v8.4.0

This commit is contained in:
lewisxhe
2024-09-13 11:35:47 +08:00
parent 1a57bfcf2b
commit f285d52d61
641 changed files with 25425 additions and 30726 deletions
+263 -23
View File
@@ -21,6 +21,10 @@
#define MY_CLASS &lv_arc_class
#define VALUE_UNSET INT16_MIN
#define CLICK_OUTSIDE_BG_ANGLES ((uint32_t) 0x00U)
#define CLICK_INSIDE_BG_ANGLES ((uint32_t) 0x01U)
#define CLICK_CLOSER_TO_MAX_END ((uint32_t) 0x00U)
#define CLICK_CLOSER_TO_MIN_END ((uint32_t) 0x01U)
/**********************
* TYPEDEFS
@@ -35,9 +39,12 @@ static void lv_arc_draw(lv_event_t * e);
static void lv_arc_event(const lv_obj_class_t * class_p, lv_event_t * e);
static void inv_arc_area(lv_obj_t * arc, uint16_t start_angle, uint16_t end_angle, lv_part_t part);
static void inv_knob_area(lv_obj_t * obj);
static void get_center(lv_obj_t * obj, lv_point_t * center, lv_coord_t * arc_r);
static void get_center(const lv_obj_t * obj, lv_point_t * center, lv_coord_t * arc_r);
static lv_coord_t get_angle(const lv_obj_t * obj);
static void get_knob_area(lv_obj_t * arc, const lv_point_t * center, lv_coord_t r, lv_area_t * knob_area);
static void value_update(lv_obj_t * arc);
static lv_coord_t knob_get_extra_size(lv_obj_t * obj);
static bool lv_arc_angle_within_bg_bounds(lv_obj_t * obj, const uint32_t angle, const uint32_t tolerance_deg);
/**********************
* STATIC VARIABLES
@@ -317,6 +324,58 @@ lv_arc_mode_t lv_arc_get_mode(const lv_obj_t * obj)
return ((lv_arc_t *) obj)->type;
}
/*=====================
* Other functions
*====================*/
void lv_arc_align_obj_to_angle(const lv_obj_t * obj, lv_obj_t * obj_to_align, lv_coord_t r_offset)
{
LV_ASSERT_OBJ(obj, MY_CLASS);
LV_ASSERT_NULL(obj_to_align);
lv_obj_update_layout(obj);
lv_point_t center;
lv_coord_t arc_r;
get_center(obj, &center, &arc_r);
lv_coord_t indic_width = lv_obj_get_style_arc_width(obj, LV_PART_INDICATOR);
lv_coord_t indic_width_half = indic_width / 2;
arc_r -= indic_width_half;
arc_r += r_offset;
uint16_t angle = get_angle(obj);
lv_coord_t knob_x = (arc_r * lv_trigo_sin(angle + 90)) >> LV_TRIGO_SHIFT;
lv_coord_t knob_y = (arc_r * lv_trigo_sin(angle)) >> LV_TRIGO_SHIFT;
lv_obj_align_to(obj_to_align, obj, LV_ALIGN_CENTER, knob_x, knob_y);
}
void lv_arc_rotate_obj_to_angle(const lv_obj_t * obj, lv_obj_t * obj_to_rotate, lv_coord_t r_offset)
{
LV_ASSERT_OBJ(obj, MY_CLASS);
LV_ASSERT_NULL(obj_to_rotate);
lv_obj_update_layout(obj);
lv_point_t center;
lv_coord_t arc_r;
get_center(obj, &center, &arc_r);
lv_coord_t indic_width = lv_obj_get_style_arc_width(obj, LV_PART_INDICATOR);
lv_coord_t indic_width_half = indic_width / 2;
arc_r -= indic_width_half;
arc_r += r_offset;
lv_obj_align_to(obj_to_rotate, obj, LV_ALIGN_CENTER, 0, -arc_r);
lv_obj_update_layout(obj);
uint16_t angle = get_angle(obj);
lv_coord_t pivot_x = obj_to_rotate->coords.x1 - center.x;
lv_coord_t pivot_y = obj_to_rotate->coords.y1 - center.y;
lv_obj_set_style_transform_pivot_x(obj_to_rotate, -pivot_x, 0);
lv_obj_set_style_transform_pivot_y(obj_to_rotate, -pivot_y, 0);
lv_obj_set_style_transform_angle(obj_to_rotate, angle * 10 + 900, 0);
}
/**********************
* STATIC FUNCTIONS
**********************/
@@ -343,12 +402,12 @@ static void lv_arc_constructor(const lv_obj_class_t * class_p, lv_obj_t * obj)
arc->chg_rate = 720;
arc->last_tick = lv_tick_get();
arc->last_angle = arc->indic_angle_end;
arc->in_out = CLICK_OUTSIDE_BG_ANGLES;
lv_obj_add_flag(obj, LV_OBJ_FLAG_CLICKABLE);
lv_obj_clear_flag(obj, LV_OBJ_FLAG_SCROLL_CHAIN);
lv_obj_clear_flag(obj, LV_OBJ_FLAG_SCROLL_CHAIN | LV_OBJ_FLAG_SCROLLABLE);
lv_obj_set_ext_click_area(obj, LV_DPI_DEF / 10);
LV_TRACE_OBJ_CREATE("finished");
}
@@ -422,29 +481,54 @@ static void lv_arc_event(const lv_obj_class_t * class_p, lv_event_t * e)
angle -= arc->rotation;
angle -= arc->bg_angle_start; /*Make the angle relative to the start angle*/
/* If we click near the bg_angle_start the angle will be close to 360° instead of an small angle */
if(angle < 0) angle += 360;
int16_t deg_range = bg_end - arc->bg_angle_start;
const uint32_t circumference = (uint32_t)((2U * r * 314U) / 100U); /* Equivalent to: 2r * 3.14, avoiding floats */
const uint32_t tolerance_deg = (360U * LV_DPX(50U)) / circumference;
const uint32_t min_close_prev = (uint32_t) arc->min_close;
const bool is_angle_within_bg_bounds = lv_arc_angle_within_bg_bounds(obj, (uint32_t) angle, tolerance_deg);
if(!is_angle_within_bg_bounds) {
return;
}
int16_t deg_range = bg_end - arc->bg_angle_start;
int16_t last_angle_rel = arc->last_angle - arc->bg_angle_start;
int16_t delta_angle = angle - last_angle_rel;
/*Do not allow big jumps.
/*Do not allow big jumps (jumps bigger than 280°).
*It's mainly to avoid jumping to the opposite end if the "dead" range between min. and max. is crossed.
*Check which end was closer on the last valid press (arc->min_close) and prefer that end*/
if(LV_ABS(delta_angle) > 280) {
if(arc->min_close) angle = 0;
else angle = deg_range;
}
else {
if(angle < deg_range / 2)arc->min_close = 1;
else arc->min_close = 0;
/* Check if click was outside the background arc start and end angles */
else if(CLICK_OUTSIDE_BG_ANGLES == arc->in_out) {
if(arc->min_close) angle = -deg_range;
else angle = deg_range;
}
else { /* Keep the angle value */ }
/* Prevent big jumps when the click goes from start to end angle in the invisible
* part of the background arc without being released */
if(((min_close_prev == CLICK_CLOSER_TO_MIN_END) && (arc->min_close == CLICK_CLOSER_TO_MAX_END))
&& ((CLICK_OUTSIDE_BG_ANGLES == arc->in_out) && (LV_ABS(delta_angle) > 280))) {
angle = 0;
}
else if(((min_close_prev == CLICK_CLOSER_TO_MAX_END) && (arc->min_close == CLICK_CLOSER_TO_MIN_END))
&& (CLICK_OUTSIDE_BG_ANGLES == arc->in_out)) {
angle = deg_range;
}
else { /* Keep the angle value */ }
/*Calculate the slew rate limited angle based on change rate (degrees/sec)*/
delta_angle = angle - last_angle_rel;
uint32_t delta_tick = lv_tick_elaps(arc->last_tick);
int16_t delta_angle_max = (arc->chg_rate * delta_tick) / 1000;
/* delta_angle_max can never be signed. delta_tick is always signed, same for ch_rate */
const uint16_t delta_angle_max = (arc->chg_rate * delta_tick) / 1000;
if(delta_angle > delta_angle_max) {
delta_angle = delta_angle_max;
@@ -452,6 +536,7 @@ static void lv_arc_event(const lv_obj_class_t * class_p, lv_event_t * e)
else if(delta_angle < -delta_angle_max) {
delta_angle = -delta_angle_max;
}
else { /* Nothing to do */ }
angle = last_angle_rel + delta_angle; /*Apply the limited angle change*/
@@ -508,7 +593,7 @@ static void lv_arc_event(const lv_obj_class_t * class_p, lv_event_t * e)
}
}
else if(code == LV_EVENT_HIT_TEST) {
lv_hit_test_info_t * info = lv_event_get_param(e);;
lv_hit_test_info_t * info = lv_event_get_param(e);
lv_point_t p;
lv_coord_t r;
@@ -545,8 +630,11 @@ static void lv_arc_event(const lv_obj_class_t * class_p, lv_event_t * e)
lv_coord_t knob_bottom = lv_obj_get_style_pad_bottom(obj, LV_PART_KNOB);
lv_coord_t knob_pad = LV_MAX4(knob_left, knob_right, knob_top, knob_bottom) + 2;
lv_coord_t knob_extra_size = knob_pad - bg_pad;
knob_extra_size += knob_get_extra_size(obj);
lv_coord_t * s = lv_event_get_param(e);
*s = LV_MAX(*s, knob_pad - bg_pad);
*s = LV_MAX(*s, knob_extra_size);
}
else if(code == LV_EVENT_DRAW_MAIN) {
lv_arc_draw(e);
@@ -661,6 +749,7 @@ static void inv_arc_area(lv_obj_t * obj, uint16_t start_angle, uint16_t end_angl
lv_area_t inv_area;
lv_draw_arc_get_area(c.x, c.y, r, start_angle, end_angle, w, rounded, &inv_area);
lv_obj_invalidate_area(obj, &inv_area);
}
@@ -672,10 +761,17 @@ static void inv_knob_area(lv_obj_t * obj)
lv_area_t a;
get_knob_area(obj, &c, r, &a);
lv_coord_t knob_extra_size = knob_get_extra_size(obj);
if(knob_extra_size > 0) {
lv_area_increase(&a, knob_extra_size, knob_extra_size);
}
lv_obj_invalidate_area(obj, &a);
}
static void get_center(lv_obj_t * obj, lv_point_t * center, lv_coord_t * arc_r)
static void get_center(const lv_obj_t * obj, lv_point_t * center, lv_coord_t * arc_r)
{
lv_coord_t left_bg = lv_obj_get_style_pad_left(obj, LV_PART_MAIN);
lv_coord_t right_bg = lv_obj_get_style_pad_right(obj, LV_PART_MAIN);
@@ -691,15 +787,9 @@ static void get_center(lv_obj_t * obj, lv_point_t * center, lv_coord_t * arc_r)
if(arc_r) *arc_r = r;
}
static void get_knob_area(lv_obj_t * obj, const lv_point_t * center, lv_coord_t r, lv_area_t * knob_area)
static lv_coord_t get_angle(const lv_obj_t * obj)
{
LV_ASSERT_OBJ(obj, MY_CLASS);
lv_arc_t * arc = (lv_arc_t *)obj;
lv_coord_t indic_width = lv_obj_get_style_arc_width(obj, LV_PART_INDICATOR);
lv_coord_t indic_width_half = indic_width / 2;
r -= indic_width_half;
uint16_t angle = arc->rotation;
if(arc->type == LV_ARC_MODE_NORMAL) {
angle += arc->indic_angle_end;
@@ -708,10 +798,27 @@ static void get_knob_area(lv_obj_t * obj, const lv_point_t * center, lv_coord_t
angle += arc->indic_angle_start;
}
else if(arc->type == LV_ARC_MODE_SYMMETRICAL) {
int32_t range_midpoint = (int32_t)(arc->min_value + arc->max_value) / 2;
if(arc->value < range_midpoint) angle += arc->indic_angle_start;
else angle += arc->indic_angle_end;
int16_t bg_end = arc->bg_angle_end;
if(arc->bg_angle_end < arc->bg_angle_start) bg_end = arc->bg_angle_end + 360;
int16_t indic_end = arc->indic_angle_end;
if(arc->indic_angle_end < arc->indic_angle_start) indic_end = arc->indic_angle_end + 360;
int32_t angle_midpoint = (int32_t)(arc->bg_angle_start + bg_end) / 2;
if(arc->indic_angle_start < angle_midpoint) angle += arc->indic_angle_start;
else if(indic_end > angle_midpoint) angle += arc->indic_angle_end;
else angle += angle_midpoint;
}
return angle;
}
static void get_knob_area(lv_obj_t * obj, const lv_point_t * center, lv_coord_t r, lv_area_t * knob_area)
{
lv_coord_t indic_width = lv_obj_get_style_arc_width(obj, LV_PART_INDICATOR);
lv_coord_t indic_width_half = indic_width / 2;
r -= indic_width_half;
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_y = (r * lv_trigo_sin(angle)) >> LV_TRIGO_SHIFT;
@@ -759,12 +866,13 @@ static void value_update(lv_obj_t * obj)
}
break;
case LV_ARC_MODE_REVERSE:
angle = lv_map(arc->value, arc->min_value, arc->max_value, arc->bg_angle_start, bg_end);
angle = lv_map(arc->value, arc->min_value, arc->max_value, bg_end, arc->bg_angle_start);
lv_arc_set_angles(obj, angle, arc->bg_angle_end);
break;
case LV_ARC_MODE_NORMAL:
angle = lv_map(arc->value, arc->min_value, arc->max_value, arc->bg_angle_start, bg_end);
lv_arc_set_angles(obj, arc->bg_angle_start, angle);
break;
default:
LV_LOG_WARN("Invalid mode: %d", arc->type);
@@ -773,4 +881,136 @@ static void value_update(lv_obj_t * obj)
arc->last_angle = angle; /*Cache angle for slew rate limiting*/
}
static lv_coord_t knob_get_extra_size(lv_obj_t * obj)
{
lv_coord_t knob_shadow_size = 0;
knob_shadow_size += lv_obj_get_style_shadow_width(obj, LV_PART_KNOB);
knob_shadow_size += lv_obj_get_style_shadow_spread(obj, LV_PART_KNOB);
knob_shadow_size += LV_ABS(lv_obj_get_style_shadow_ofs_x(obj, LV_PART_KNOB));
knob_shadow_size += LV_ABS(lv_obj_get_style_shadow_ofs_y(obj, LV_PART_KNOB));
lv_coord_t knob_outline_size = 0;
knob_outline_size += lv_obj_get_style_outline_width(obj, LV_PART_KNOB);
knob_outline_size += lv_obj_get_style_outline_pad(obj, LV_PART_KNOB);
return LV_MAX(knob_shadow_size, knob_outline_size);
}
/**
* Check if angle is within arc background bounds
*
* In order to avoid unexpected value update of the arc value when the user clicks
* outside of the arc background we need to check if the angle (of the clicked point)
* is within the bounds of the background.
*
* A tolerance (extra room) also should be taken into consideration.
*
* E.g. Arc with start angle of 0° and end angle of 90°, the background is only visible in
* that range, from 90° to 360° the background is invisible. Click in 150° should not update
* the arc value, click within the arc angle range should.
*
* IMPORTANT NOTE: angle is always relative to bg_angle_start, e.g. if bg_angle_start is 30
* and we click a bit to the left, angle is 10, not the expected 40.
*
* @param obj Pointer to lv_arc
* @param angle Angle to be checked
* @param tolerance_deg Tolerance
*
* @return true if angle is within arc background bounds, false otherwise
*/
static bool lv_arc_angle_within_bg_bounds(lv_obj_t * obj, const uint32_t angle, const uint32_t tolerance_deg)
{
LV_ASSERT_OBJ(obj, MY_CLASS);
lv_arc_t * arc = (lv_arc_t *)obj;
uint32_t smaller_angle = 0;
uint32_t bigger_angle = 0;
/* Determine which background angle is smaller and bigger */
if(arc->bg_angle_start < arc->bg_angle_end) {
bigger_angle = arc->bg_angle_end;
smaller_angle = arc->bg_angle_start;
}
else {
bigger_angle = (360 - arc->bg_angle_start) + arc->bg_angle_end;
smaller_angle = 0;
}
/* Angle is between both background angles */
if((smaller_angle <= angle) && (angle <= bigger_angle)) {
if(((bigger_angle - smaller_angle) / 2U) >= angle) {
arc->min_close = 1;
}
else {
arc->min_close = 0;
}
arc->in_out = CLICK_INSIDE_BG_ANGLES;
return true;
}
/* Distance between background start and end angles is less than tolerance,
* consider the click inside the arc */
else if(((smaller_angle - tolerance_deg) <= 0U) &&
(360U - (bigger_angle + (smaller_angle - tolerance_deg)))) {
arc->min_close = 1;
arc->in_out = CLICK_INSIDE_BG_ANGLES;
return true;
}
else { /* Case handled below */ }
/* Legends:
* 0° = angle 0
* 360° = angle 360
* T: Tolerance
* A: Angle
* S: Arc background start angle
* E: Arc background end angle
*
* Start angle is bigger or equal to tolerance */
if((smaller_angle >= tolerance_deg)
/* (360° - T) --- A --- 360° */
&& ((angle >= (360U - tolerance_deg)) && (angle <= 360U))) {
arc->min_close = 1;
arc->in_out = CLICK_OUTSIDE_BG_ANGLES;
return true;
}
/* Tolerance is bigger than bg start angle */
else if((smaller_angle < tolerance_deg)
/* (360° - (T - S)) --- A --- 360° */
&& (((360U - (tolerance_deg - smaller_angle)) <= angle)) && (angle <= 360U)) {
arc->min_close = 1;
arc->in_out = CLICK_OUTSIDE_BG_ANGLES;
return true;
}
/* 360° is bigger than background end angle + tolerance */
else if((360U >= (bigger_angle + tolerance_deg))
/* E --- A --- (E + T) */
&& ((bigger_angle <= (angle + smaller_angle)) &&
((angle + smaller_angle) <= (bigger_angle + tolerance_deg)))) {
arc->min_close = 0;
arc->in_out = CLICK_OUTSIDE_BG_ANGLES;
return true;
}
/* Background end angle + tolerance is bigger than 360° and bg_start_angle + tolerance is not near 0° + ((bg_end_angle + tolerance) - 360°)
* Here we can assume background is not near 0° because of the first two initial checks */
else if((360U < (bigger_angle + tolerance_deg))
&& (angle <= 0U + ((bigger_angle + tolerance_deg) - 360U)) && (angle > bigger_angle)) {
arc->min_close = 0;
arc->in_out = CLICK_OUTSIDE_BG_ANGLES;
return true;
}
else {
/* Nothing to do */
}
return false;
}
#endif
+53 -36
View File
@@ -44,10 +44,11 @@ typedef struct {
int16_t value; /*Current value of the arc*/
int16_t min_value; /*Minimum value of the arc*/
int16_t max_value; /*Maximum value of the arc*/
uint16_t dragging : 1;
uint16_t type : 2;
uint16_t min_close : 1; /*1: the last pressed angle was closer to minimum end*/
uint16_t chg_rate; /*Drag angle rate of change of the arc (degrees/sec)*/
uint32_t dragging : 1;
uint32_t type : 2;
uint32_t min_close : 1; /*1: the last pressed angle was closer to minimum end*/
uint32_t in_out : 1; /* 1: The click was within the background arc angles. 0: Click outside */
uint32_t chg_rate; /*Drag angle rate of change of the arc (degrees/sec)*/
uint32_t last_tick; /*Last dragging event timestamp of the arc*/
int16_t last_angle; /*Last dragging angle of the arc*/
} lv_arc_t;
@@ -85,83 +86,83 @@ lv_obj_t * lv_arc_create(lv_obj_t * parent);
/**
* Set the start angle of an arc. 0 deg: right, 90 bottom, etc.
* @param arc pointer to an arc object
* @param obj pointer to an arc object
* @param start the start angle
*/
void lv_arc_set_start_angle(lv_obj_t * arc, uint16_t start);
void lv_arc_set_start_angle(lv_obj_t * obj, uint16_t start);
/**
* Set the end angle of an arc. 0 deg: right, 90 bottom, etc.
* @param arc pointer to an arc object
* @param obj pointer to an arc object
* @param end the end angle
*/
void lv_arc_set_end_angle(lv_obj_t * arc, uint16_t end);
void lv_arc_set_end_angle(lv_obj_t * obj, uint16_t end);
/**
* Set the start and end angles
* @param arc pointer to an arc object
* @param obj pointer to an arc object
* @param start the start angle
* @param end the end angle
*/
void lv_arc_set_angles(lv_obj_t * arc, uint16_t start, uint16_t end);
void lv_arc_set_angles(lv_obj_t * obj, uint16_t start, uint16_t end);
/**
* Set the start angle of an arc background. 0 deg: right, 90 bottom, etc.
* @param arc pointer to an arc object
* @param obj pointer to an arc object
* @param start the start angle
*/
void lv_arc_set_bg_start_angle(lv_obj_t * arc, uint16_t start);
void lv_arc_set_bg_start_angle(lv_obj_t * obj, uint16_t start);
/**
* Set the start angle of an arc background. 0 deg: right, 90 bottom etc.
* @param arc pointer to an arc object
* @param obj pointer to an arc object
* @param end the end angle
*/
void lv_arc_set_bg_end_angle(lv_obj_t * arc, uint16_t end);
void lv_arc_set_bg_end_angle(lv_obj_t * obj, uint16_t end);
/**
* Set the start and end angles of the arc background
* @param arc pointer to an arc object
* @param obj pointer to an arc object
* @param start the start angle
* @param end the end angle
*/
void lv_arc_set_bg_angles(lv_obj_t * arc, uint16_t start, uint16_t end);
void lv_arc_set_bg_angles(lv_obj_t * obj, uint16_t start, uint16_t end);
/**
* Set the rotation for the whole arc
* @param arc pointer to an arc object
* @param obj pointer to an arc object
* @param rotation rotation angle
*/
void lv_arc_set_rotation(lv_obj_t * arc, uint16_t rotation);
void lv_arc_set_rotation(lv_obj_t * obj, uint16_t rotation);
/**
* Set the type of arc.
* @param arc pointer to arc object
* @param obj pointer to arc object
* @param mode arc's mode
*/
void lv_arc_set_mode(lv_obj_t * arc, lv_arc_mode_t type);
void lv_arc_set_mode(lv_obj_t * obj, lv_arc_mode_t type);
/**
* Set a new value on the arc
* @param arc pointer to an arc object
* @param obj pointer to an arc object
* @param value new value
*/
void lv_arc_set_value(lv_obj_t * arc, int16_t value);
void lv_arc_set_value(lv_obj_t * obj, int16_t value);
/**
* Set minimum and the maximum values of an arc
* @param arc pointer to the arc object
* @param obj pointer to the arc object
* @param min minimum value
* @param max maximum value
*/
void lv_arc_set_range(lv_obj_t * arc, int16_t min, int16_t max);
void lv_arc_set_range(lv_obj_t * obj, int16_t min, int16_t max);
/**
* Set a change rate to limit the speed how fast the arc should reach the pressed point.
* @param arc pointer to an arc object
* @param obj pointer to an arc object
* @param rate the change rate
*/
void lv_arc_set_change_rate(lv_obj_t * arc, uint16_t rate);
void lv_arc_set_change_rate(lv_obj_t * obj, uint16_t rate);
/*=====================
* Getter functions
@@ -169,56 +170,56 @@ void lv_arc_set_change_rate(lv_obj_t * arc, uint16_t rate);
/**
* Get the start angle of an arc.
* @param arc pointer to an arc object
* @param obj pointer to an arc object
* @return the start angle [0..360]
*/
uint16_t lv_arc_get_angle_start(lv_obj_t * obj);
/**
* Get the end angle of an arc.
* @param arc pointer to an arc object
* @param obj pointer to an arc object
* @return the end angle [0..360]
*/
uint16_t lv_arc_get_angle_end(lv_obj_t * obj);
/**
* Get the start angle of an arc background.
* @param arc pointer to an arc object
* @return the start angle [0..360]
* @param obj pointer to an arc object
* @return the start angle [0..360]
*/
uint16_t lv_arc_get_bg_angle_start(lv_obj_t * obj);
/**
* Get the end angle of an arc background.
* @param arc pointer to an arc object
* @param obj pointer to an arc object
* @return the end angle [0..360]
*/
uint16_t lv_arc_get_bg_angle_end(lv_obj_t * obj);
/**
* Get the value of an arc
* @param arc pointer to an arc object
* @return the value of the arc
* @param obj pointer to an arc object
* @return the value of the arc
*/
int16_t lv_arc_get_value(const lv_obj_t * obj);
/**
* Get the minimum value of an arc
* @param arc pointer to an arc object
* @param obj pointer to an arc object
* @return the minimum value of the arc
*/
int16_t lv_arc_get_min_value(const lv_obj_t * obj);
/**
* Get the maximum value of an arc
* @param arc pointer to an arc object
* @param obj pointer to an arc object
* @return the maximum value of the arc
*/
int16_t lv_arc_get_max_value(const lv_obj_t * obj);
/**
* Get whether the arc is type or not.
* @param arc pointer to an arc object
* @param obj pointer to an arc object
* @return arc's mode
*/
lv_arc_mode_t lv_arc_get_mode(const lv_obj_t * obj);
@@ -227,6 +228,22 @@ lv_arc_mode_t lv_arc_get_mode(const lv_obj_t * obj);
* Other functions
*====================*/
/**
* Align an object to the current position of the arc (knob)
* @param obj pointer to an arc object
* @param obj_to_align pointer to an object to align
* @param r_offset consider the radius larger with this value (< 0: for smaller radius)
*/
void lv_arc_align_obj_to_angle(const lv_obj_t * obj, lv_obj_t * obj_to_align, lv_coord_t r_offset);
/**
* Rotate an object to the current position of the arc (knob)
* @param obj pointer to an arc object
* @param obj_to_align pointer to an object to rotate
* @param r_offset consider the radius larger with this value (< 0: for smaller radius)
*/
void lv_arc_rotate_obj_to_angle(const lv_obj_t * obj, lv_obj_t * obj_to_rotate, lv_coord_t r_offset);
/**********************
* MACROS
**********************/
+2
View File
@@ -571,6 +571,8 @@ static void lv_bar_set_value_with_anim(lv_obj_t * obj, int32_t new_value, int32_
_lv_bar_anim_t * anim_info, lv_anim_enable_t en)
{
if(en == LV_ANIM_OFF) {
lv_anim_del(anim_info, NULL);
anim_info->anim_state = LV_BAR_ANIM_STATE_INV;
*value_ptr = new_value;
lv_obj_invalidate((lv_obj_t *)obj);
}
+49 -12
View File
@@ -23,7 +23,7 @@
#define MY_CLASS &lv_btnmatrix_class
#define BTN_EXTRA_CLICK_AREA_MAX (LV_DPI_DEF / 10)
#define LV_BTNMATRIX_WIDTH_MASK 0x0007
#define LV_BTNMATRIX_WIDTH_MASK 0x000F
/**********************
* TYPEDEFS
@@ -208,7 +208,7 @@ void lv_btnmatrix_set_btn_ctrl(lv_obj_t * obj, uint16_t btn_id, lv_btnmatrix_ctr
{
LV_ASSERT_OBJ(obj, MY_CLASS);
lv_btnmatrix_t * btnm = (lv_btnmatrix_t *)obj;;
lv_btnmatrix_t * btnm = (lv_btnmatrix_t *)obj;
if(btn_id >= btnm->btn_cnt) return;
@@ -216,6 +216,19 @@ void lv_btnmatrix_set_btn_ctrl(lv_obj_t * obj, uint16_t btn_id, lv_btnmatrix_ctr
lv_btnmatrix_clear_btn_ctrl_all(obj, LV_BTNMATRIX_CTRL_CHECKED);
}
/* If we hide a button if all buttons are now hidden hide the whole button matrix to make focus behave correctly */
if(ctrl & LV_BTNMATRIX_CTRL_HIDDEN) {
bool all_buttons_hidden = true;
if(btnm->btn_cnt > 1) {
for(uint16_t btn_idx = 0; btn_idx < btnm->btn_cnt; btn_idx++) {
if(btn_idx == btn_id) continue;
if(!(btnm->ctrl_bits[btn_idx] & LV_BTNMATRIX_CTRL_HIDDEN)) all_buttons_hidden = false;
}
}
if(all_buttons_hidden) lv_obj_add_flag(obj, LV_OBJ_FLAG_HIDDEN);
}
btnm->ctrl_bits[btn_id] |= ctrl;
invalidate_button_area(obj, btn_id);
@@ -228,10 +241,15 @@ void lv_btnmatrix_clear_btn_ctrl(lv_obj_t * obj, uint16_t btn_id, lv_btnmatrix_c
{
LV_ASSERT_OBJ(obj, MY_CLASS);
lv_btnmatrix_t * btnm = (lv_btnmatrix_t *)obj;;
lv_btnmatrix_t * btnm = (lv_btnmatrix_t *)obj;
if(btn_id >= btnm->btn_cnt) return;
/* If all buttons were hidden the whole button matrix is hidden so we need to check and remove hidden flag if present */
if(ctrl & LV_BTNMATRIX_CTRL_HIDDEN) {
if(lv_obj_has_flag(obj, LV_OBJ_FLAG_HIDDEN)) lv_obj_clear_flag(obj, LV_OBJ_FLAG_HIDDEN);
}
btnm->ctrl_bits[btn_id] &= (~ctrl);
invalidate_button_area(obj, btn_id);
@@ -399,13 +417,10 @@ static void lv_btnmatrix_event(const lv_obj_class_t * class_p, lv_event_t * e)
lv_point_t p;
if(code == LV_EVENT_REFR_EXT_DRAW_SIZE) {
lv_coord_t * s = lv_event_get_param(e);
if(has_popovers_in_top_row(obj)) {
/*reserve one row worth of extra space to account for popovers in the top row*/
*s = btnm->row_cnt > 0 ? lv_obj_get_content_height(obj) / btnm->row_cnt : 0;
}
else {
*s = 0;
lv_coord_t s = btnm->row_cnt > 0 ? lv_obj_get_content_height(obj) / btnm->row_cnt : 0;
lv_event_set_ext_draw_size(e, s);
}
}
if(code == LV_EVENT_STYLE_CHANGED) {
@@ -425,6 +440,7 @@ static void lv_btnmatrix_event(const lv_obj_class_t * class_p, lv_event_t * e)
lv_indev_get_point(param, &p);
btn_pr = get_button_from_point(obj, &p);
/*Handle the case where there is no button there*/
btnm->btn_id_sel = LV_BTNMATRIX_BTN_NONE;
if(btn_pr != LV_BTNMATRIX_BTN_NONE) {
if(button_is_inactive(btnm->ctrl_bits[btn_pr]) == false &&
button_is_hidden(btnm->ctrl_bits[btn_pr]) == false) {
@@ -432,6 +448,9 @@ static void lv_btnmatrix_event(const lv_obj_class_t * class_p, lv_event_t * e)
invalidate_button_area(obj, btnm->btn_id_sel); /*Invalidate the new area*/
}
}
else {
btnm->btn_id_sel = LV_BTNMATRIX_BTN_NONE;
}
}
if(btnm->btn_id_sel != LV_BTNMATRIX_BTN_NONE) {
@@ -492,7 +511,6 @@ static void lv_btnmatrix_event(const lv_obj_class_t * class_p, lv_event_t * e)
if(btnm->one_check) make_one_button_checked(obj, btnm->btn_id_sel);
}
if((button_is_click_trig(btnm->ctrl_bits[btnm->btn_id_sel]) == true ||
button_is_popover(btnm->ctrl_bits[btnm->btn_id_sel]) == true) &&
button_is_inactive(btnm->ctrl_bits[btnm->btn_id_sel]) == false &&
@@ -523,6 +541,8 @@ static void lv_btnmatrix_event(const lv_obj_class_t * class_p, lv_event_t * e)
btnm->btn_id_sel = LV_BTNMATRIX_BTN_NONE;
}
else if(code == LV_EVENT_FOCUSED) {
if(btnm->btn_cnt == 0) return;
lv_indev_t * indev = lv_event_get_param(e);
lv_indev_type_t indev_type = lv_indev_get_type(indev);
@@ -566,9 +586,15 @@ static void lv_btnmatrix_event(const lv_obj_class_t * class_p, lv_event_t * e)
else btnm->btn_id_sel++;
if(btnm->btn_id_sel >= btnm->btn_cnt) btnm->btn_id_sel = 0;
uint16_t btn_id_start = btnm->btn_id_sel;
while(button_is_hidden(btnm->ctrl_bits[btnm->btn_id_sel]) || button_is_inactive(btnm->ctrl_bits[btnm->btn_id_sel])) {
btnm->btn_id_sel++;
if(btnm->btn_id_sel >= btnm->btn_cnt) btnm->btn_id_sel = 0;
if(btnm->btn_id_sel == btn_id_start) {
btnm->btn_id_sel = LV_BTNMATRIX_BTN_NONE;
break;
}
}
}
else if(c == LV_KEY_LEFT) {
@@ -577,9 +603,15 @@ static void lv_btnmatrix_event(const lv_obj_class_t * class_p, lv_event_t * e)
if(btnm->btn_id_sel == 0) btnm->btn_id_sel = btnm->btn_cnt - 1;
else if(btnm->btn_id_sel > 0) btnm->btn_id_sel--;
uint16_t btn_id_start = btnm->btn_id_sel;
while(button_is_hidden(btnm->ctrl_bits[btnm->btn_id_sel]) || button_is_inactive(btnm->ctrl_bits[btnm->btn_id_sel])) {
if(btnm->btn_id_sel > 0) btnm->btn_id_sel--;
else btnm->btn_id_sel = btnm->btn_cnt - 1;
if(btnm->btn_id_sel == btn_id_start) {
btnm->btn_id_sel = LV_BTNMATRIX_BTN_NONE;
break;
}
}
}
else if(c == LV_KEY_DOWN) {
@@ -589,7 +621,10 @@ static void lv_btnmatrix_event(const lv_obj_class_t * class_p, lv_event_t * e)
btnm->btn_id_sel = 0;
while(button_is_hidden(btnm->ctrl_bits[btnm->btn_id_sel]) || button_is_inactive(btnm->ctrl_bits[btnm->btn_id_sel])) {
btnm->btn_id_sel++;
if(btnm->btn_id_sel >= btnm->btn_cnt) btnm->btn_id_sel = 0;
if(btnm->btn_id_sel >= btnm->btn_cnt) {
btnm->btn_id_sel = LV_BTNMATRIX_BTN_NONE;
break;
}
}
}
else {
@@ -617,7 +652,10 @@ static void lv_btnmatrix_event(const lv_obj_class_t * class_p, lv_event_t * e)
btnm->btn_id_sel = 0;
while(button_is_hidden(btnm->ctrl_bits[btnm->btn_id_sel]) || button_is_inactive(btnm->ctrl_bits[btnm->btn_id_sel])) {
btnm->btn_id_sel++;
if(btnm->btn_id_sel >= btnm->btn_cnt) btnm->btn_id_sel = 0;
if(btnm->btn_id_sel >= btnm->btn_cnt) {
btnm->btn_id_sel = LV_BTNMATRIX_BTN_NONE;
break;
}
}
}
else {
@@ -746,7 +784,6 @@ static void draw_main(lv_event_t * e)
if(recolor) draw_label_dsc_act.flag |= LV_TEXT_FLAG_RECOLOR;
else draw_label_dsc_act.flag &= ~LV_TEXT_FLAG_RECOLOR;
part_draw_dsc.draw_area = &btn_area;
part_draw_dsc.id = btn_i;
lv_event_send(obj, LV_EVENT_DRAW_PART_BEGIN, &part_draw_dsc);
+13 -12
View File
@@ -32,18 +32,19 @@ LV_EXPORT_CONST_INT(LV_BTNMATRIX_BTN_NONE);
/** Type to store button control bits (disabled, hidden etc.)
* The first 3 bits are used to store the width*/
enum {
_LV_BTNMATRIX_WIDTH = 0x0007, /**< Reserved to stire the size units*/
LV_BTNMATRIX_CTRL_HIDDEN = 0x0008, /**< Button hidden*/
LV_BTNMATRIX_CTRL_NO_REPEAT = 0x0010, /**< Do not repeat press this button.*/
LV_BTNMATRIX_CTRL_DISABLED = 0x0020, /**< Disable this button.*/
LV_BTNMATRIX_CTRL_CHECKABLE = 0x0040, /**< The button can be toggled.*/
LV_BTNMATRIX_CTRL_CHECKED = 0x0080, /**< Button is currently toggled (e.g. checked).*/
LV_BTNMATRIX_CTRL_CLICK_TRIG = 0x0100, /**< 1: Send LV_EVENT_VALUE_CHANGE on CLICK, 0: Send LV_EVENT_VALUE_CHANGE on PRESS*/
LV_BTNMATRIX_CTRL_POPOVER = 0x0200, /**< Show a popover when pressing this key*/
LV_BTNMATRIX_CTRL_RECOLOR = 0x1000, /**< Enable text recoloring with `#color`*/
_LV_BTNMATRIX_CTRL_RESERVED = 0x2000, /**< Reserved for later use*/
LV_BTNMATRIX_CTRL_CUSTOM_1 = 0x4000, /**< Custom free to use flag*/
LV_BTNMATRIX_CTRL_CUSTOM_2 = 0x8000, /**< Custom free to use flag*/
_LV_BTNMATRIX_WIDTH = 0x000F, /**< Reserved to store the size units*/
LV_BTNMATRIX_CTRL_HIDDEN = 0x0010, /**< Button hidden*/
LV_BTNMATRIX_CTRL_NO_REPEAT = 0x0020, /**< Do not repeat press this button.*/
LV_BTNMATRIX_CTRL_DISABLED = 0x0040, /**< Disable this button.*/
LV_BTNMATRIX_CTRL_CHECKABLE = 0x0080, /**< The button can be toggled.*/
LV_BTNMATRIX_CTRL_CHECKED = 0x0100, /**< Button is currently toggled (e.g. checked).*/
LV_BTNMATRIX_CTRL_CLICK_TRIG = 0x0200, /**< 1: Send LV_EVENT_VALUE_CHANGE on CLICK, 0: Send LV_EVENT_VALUE_CHANGE on PRESS*/
LV_BTNMATRIX_CTRL_POPOVER = 0x0400, /**< Show a popover when pressing this key*/
LV_BTNMATRIX_CTRL_RECOLOR = 0x0800, /**< Enable text recoloring with `#color`*/
_LV_BTNMATRIX_CTRL_RESERVED_1 = 0x1000, /**< Reserved for later use*/
_LV_BTNMATRIX_CTRL_RESERVED_2 = 0x2000, /**< Reserved for later use*/
LV_BTNMATRIX_CTRL_CUSTOM_1 = 0x4000, /**< Custom free to use flag*/
LV_BTNMATRIX_CTRL_CUSTOM_2 = 0x8000, /**< Custom free to use flag*/
};
typedef uint16_t lv_btnmatrix_ctrl_t;
+34 -75
View File
@@ -158,98 +158,58 @@ void lv_canvas_copy_buf(lv_obj_t * obj, const void * to_copy, lv_coord_t x, lv_c
}
}
void lv_canvas_transform(lv_obj_t * obj, lv_img_dsc_t * img, int16_t angle, uint16_t zoom, lv_coord_t offset_x,
void lv_canvas_transform(lv_obj_t * obj, lv_img_dsc_t * src_img, int16_t angle, uint16_t zoom, lv_coord_t offset_x,
lv_coord_t offset_y,
int32_t pivot_x, int32_t pivot_y, bool antialias)
{
#if LV_DRAW_COMPLEX
LV_ASSERT_OBJ(obj, MY_CLASS);
LV_ASSERT_NULL(img);
LV_ASSERT_NULL(src_img);
lv_canvas_t * canvas = (lv_canvas_t *)obj;
lv_color_t color = lv_obj_get_style_img_recolor(obj, LV_PART_MAIN);
int32_t dest_width = canvas->dsc.header.w;
int32_t dest_height = canvas->dsc.header.h;
lv_img_dsc_t * dest_img = &canvas->dsc;
int32_t x;
int32_t y;
bool ret;
lv_img_transform_dsc_t dsc;
dsc.cfg.angle = angle;
dsc.cfg.zoom = zoom;
dsc.cfg.src = img->data;
dsc.cfg.src_w = img->header.w;
dsc.cfg.src_h = img->header.h;
dsc.cfg.cf = img->header.cf;
dsc.cfg.pivot_x = pivot_x;
dsc.cfg.pivot_y = pivot_y;
dsc.cfg.color = color;
dsc.cfg.antialias = antialias;
_lv_img_buf_transform_init(&dsc);
lv_draw_img_dsc_t draw_dsc;
lv_draw_img_dsc_init(&draw_dsc);
draw_dsc.angle = angle;
draw_dsc.zoom = zoom;
draw_dsc.pivot.x = pivot_x;
draw_dsc.pivot.y = pivot_y;
draw_dsc.antialias = antialias;
for(y = -offset_y; y < dest_height - offset_y; y++) {
for(x = -offset_x; x < dest_width - offset_x; x++) {
lv_area_t dest_area;
dest_area.x1 = -offset_x;
dest_area.x2 = dest_area.x1 + dest_img->header.w - 1;
dest_area.y1 = -offset_y;
dest_area.y2 = -offset_y;
ret = _lv_img_buf_transform(&dsc, x, y);
lv_color_t * cbuf = lv_mem_alloc(dest_img->header.w * sizeof(lv_color_t));
lv_opa_t * abuf = lv_mem_alloc(dest_img->header.w * sizeof(lv_opa_t));
for(y = 0; y < dest_img->header.h; y++) {
lv_draw_sw_transform(NULL, &dest_area, src_img->data, src_img->header.w, src_img->header.h, src_img->header.w,
&draw_dsc, canvas->dsc.header.cf, cbuf, abuf);
if(ret == false) continue;
if(x + offset_x >= 0 && x + offset_x < dest_width && y + offset_y >= 0 && y + offset_y < dest_height) {
/*If the image has no alpha channel just simple set the result color on the canvas*/
if(lv_img_cf_has_alpha(img->header.cf) == false) {
lv_img_buf_set_px_color(&canvas->dsc, x + offset_x, y + offset_y, dsc.res.color);
}
else {
lv_color_t bg_color = lv_img_buf_get_px_color(&canvas->dsc, x + offset_x, y + offset_y, dsc.cfg.color);
/*If the canvas has no alpha but the image has mix the image's color with
* canvas*/
if(lv_img_cf_has_alpha(canvas->dsc.header.cf) == false) {
if(dsc.res.opa < LV_OPA_MAX) dsc.res.color = lv_color_mix(dsc.res.color, bg_color, dsc.res.opa);
lv_img_buf_set_px_color(&canvas->dsc, x + offset_x, y + offset_y, dsc.res.color);
}
/*Both the image and canvas has alpha channel. Some extra calculation is
required*/
else {
lv_opa_t bg_opa = lv_img_buf_get_px_alpha(&canvas->dsc, x + offset_x, y + offset_y);
/*Pick the foreground if it's fully opaque or the Background is fully
*transparent*/
if(dsc.res.opa >= LV_OPA_MAX || bg_opa <= LV_OPA_MIN) {
lv_img_buf_set_px_color(&canvas->dsc, x + offset_x, y + offset_y, dsc.res.color);
lv_img_buf_set_px_alpha(&canvas->dsc, x + offset_x, y + offset_y, dsc.res.opa);
}
/*Opaque background: use simple mix*/
else if(bg_opa >= LV_OPA_MAX) {
lv_img_buf_set_px_color(&canvas->dsc, x + offset_x, y + offset_y,
lv_color_mix(dsc.res.color, bg_color, dsc.res.opa));
}
/*Both colors have alpha. Expensive calculation need to be applied*/
else {
/*Info:
* https://en.wikipedia.org/wiki/Alpha_compositing#Analytical_derivation_of_the_over_operator*/
lv_opa_t opa_res_2 = 255 - ((uint16_t)((uint16_t)(255 - dsc.res.opa) * (255 - bg_opa)) >> 8);
if(opa_res_2 == 0) {
opa_res_2 = 1; /*never happens, just to be sure*/
}
lv_opa_t ratio = (uint16_t)((uint16_t)dsc.res.opa * 255) / opa_res_2;
lv_img_buf_set_px_color(&canvas->dsc, x + offset_x, y + offset_y,
lv_color_mix(dsc.res.color, bg_color, ratio));
lv_img_buf_set_px_alpha(&canvas->dsc, x + offset_x, y + offset_y, opa_res_2);
}
}
}
for(x = 0; x < dest_img->header.w; x++) {
if(abuf[x]) {
lv_img_buf_set_px_color(dest_img, x, y, cbuf[x]);
lv_img_buf_set_px_alpha(dest_img, x, y, abuf[x]);
}
}
dest_area.y1++;
dest_area.y2++;
}
lv_mem_free(cbuf);
lv_mem_free(abuf);
lv_obj_invalidate(obj);
#else
LV_UNUSED(obj);
LV_UNUSED(img);
LV_UNUSED(src_img);
LV_UNUSED(angle);
LV_UNUSED(zoom);
LV_UNUSED(offset_x);
@@ -696,7 +656,6 @@ void lv_canvas_draw_line(lv_obj_t * canvas, const lv_point_t points[], uint32_t
lv_disp_t * refr_ori = _lv_refr_get_disp_refreshing();
_lv_refr_set_disp_refreshing(&fake_disp);
/*Disable anti-aliasing if drawing with transparent color to chroma keyed canvas*/
lv_color_t ctransp = LV_COLOR_CHROMA_KEY;
if(dsc->header.cf == LV_IMG_CF_TRUE_COLOR_CHROMA_KEYED &&
@@ -829,7 +788,6 @@ static void lv_canvas_destructor(const lv_obj_class_t * class_p, lv_obj_t * obj)
lv_img_cache_invalidate_src(&canvas->dsc);
}
static void init_fake_disp(lv_obj_t * canvas, lv_disp_t * disp, lv_disp_drv_t * drv, lv_area_t * clip_area)
{
lv_img_dsc_t * dsc = lv_canvas_get_img(canvas);
@@ -857,6 +815,9 @@ static void init_fake_disp(lv_obj_t * canvas, lv_disp_t * disp, lv_disp_drv_t *
draw_ctx->buf = (void *)dsc->data;
lv_disp_drv_use_generic_set_px_cb(disp->driver, dsc->header.cf);
if(LV_COLOR_SCREEN_TRANSP && dsc->header.cf != LV_IMG_CF_TRUE_COLOR_ALPHA) {
drv->screen_transp = 0;
}
}
static void deinit_fake_disp(lv_obj_t * canvas, lv_disp_t * disp)
@@ -866,6 +827,4 @@ static void deinit_fake_disp(lv_obj_t * canvas, lv_disp_t * disp)
lv_mem_free(disp->driver->draw_ctx);
}
#endif
-1
View File
@@ -91,7 +91,6 @@ static inline void lv_canvas_set_px(lv_obj_t * canvas, lv_coord_t x, lv_coord_t
*/
void lv_canvas_set_px_opa(lv_obj_t * canvas, lv_coord_t x, lv_coord_t y, lv_opa_t opa);
/**
* Set the palette color of a canvas with index format. Valid only for `LV_IMG_CF_INDEXED1/2/4/8`
* @param canvas pointer to canvas object
+8 -6
View File
@@ -74,14 +74,16 @@ void lv_checkbox_set_text(lv_obj_t * obj, const char * txt)
size_t len = strlen(txt);
#endif
if(!cb->static_txt) cb->txt = lv_mem_realloc(cb->txt, len + 1);
else cb->txt = lv_mem_alloc(len + 1);
char * _txt = (char *)cb->txt;
if(!cb->static_txt) _txt = lv_mem_realloc(_txt, len + 1);
else _txt = lv_mem_alloc(len + 1);
#if LV_USE_ARABIC_PERSIAN_CHARS
_lv_txt_ap_proc(txt, cb->txt);
_lv_txt_ap_proc(txt, _txt);
#else
strcpy(cb->txt, txt);
strcpy(_txt, txt);
#endif
cb->txt = _txt;
cb->static_txt = 0;
lv_obj_refresh_self_size(obj);
@@ -92,7 +94,7 @@ void lv_checkbox_set_text_static(lv_obj_t * obj, const char * txt)
{
lv_checkbox_t * cb = (lv_checkbox_t *)obj;
if(!cb->static_txt) lv_mem_free(cb->txt);
if(!cb->static_txt) lv_mem_free((void *)cb->txt);
cb->txt = (char *)txt;
cb->static_txt = 1;
@@ -138,7 +140,7 @@ static void lv_checkbox_destructor(const lv_obj_class_t * class_p, lv_obj_t * ob
lv_checkbox_t * cb = (lv_checkbox_t *)obj;
if(!cb->static_txt) {
lv_mem_free(cb->txt);
lv_mem_free((void *)cb->txt);
cb->txt = NULL;
}
LV_TRACE_OBJ_CREATE("finished");
+1 -1
View File
@@ -28,7 +28,7 @@ extern "C" {
typedef struct {
lv_obj_t obj;
char * txt;
const char * txt;
uint32_t static_txt : 1;
} lv_checkbox_t;
+11 -6
View File
@@ -79,7 +79,6 @@ const lv_obj_class_t lv_dropdownlist_class = {
.base_class = &lv_obj_class
};
/**********************
* MACROS
**********************/
@@ -285,6 +284,10 @@ void lv_dropdown_set_selected(lv_obj_t * obj, uint16_t sel_opt)
dropdown->sel_opt_id = sel_opt < dropdown->option_cnt ? sel_opt : dropdown->option_cnt - 1;
dropdown->sel_opt_id_orig = dropdown->sel_opt_id;
if(dropdown->list) {
position_to_selected(obj);
}
lv_obj_invalidate(obj);
}
@@ -403,21 +406,25 @@ int32_t lv_dropdown_get_option_index(lv_obj_t * obj, const char * option)
const char * opts = lv_dropdown_get_options(obj);
uint32_t char_i = 0;
uint32_t opt_i = 0;
uint32_t option_len = strlen(option);
const char * start = opts;
while(start[char_i] != '\0') {
for(char_i = 0; (start[char_i] != '\n') && (start[char_i] != '\0'); char_i++);
if(memcmp(start, option, LV_MIN(strlen(option), char_i)) == 0) return opt_i;
if(option_len == char_i && memcmp(start, option, LV_MIN(option_len, char_i)) == 0) {
return opt_i;
}
start = &start[char_i];
if(start[0] == '\n') start++;
char_i = 0;
opt_i++;
}
return -1;
}
const char * lv_dropdown_get_symbol(lv_obj_t * obj)
{
LV_ASSERT_OBJ(obj, MY_CLASS);
@@ -535,7 +542,7 @@ void lv_dropdown_open(lv_obj_t * dropdown_obj)
lv_obj_align(label, LV_ALIGN_TOP_RIGHT, 0, 0);
break;
case LV_TEXT_ALIGN_CENTER:
lv_obj_align(label, LV_ALIGN_CENTER, 0, 0);
lv_obj_align(label, LV_ALIGN_TOP_MID, 0, 0);
break;
}
@@ -769,7 +776,6 @@ static void lv_dropdown_list_event(const lv_obj_class_t * class_p, lv_event_t *
}
}
static void draw_main(lv_event_t * e)
{
lv_obj_t * obj = lv_event_get_target(e);
@@ -1004,7 +1010,6 @@ static void draw_box_label(lv_obj_t * dropdown_obj, lv_draw_ctx_t * draw_ctx, ui
list_obj->skip_trans = 0;
}
static lv_res_t btn_release_handler(lv_obj_t * obj)
{
lv_dropdown_t * dropdown = (lv_dropdown_t *)obj;
+50 -76
View File
@@ -9,6 +9,7 @@
#include "lv_img.h"
#if LV_USE_IMG != 0
#include "../core/lv_disp.h"
#include "../misc/lv_assert.h"
#include "../draw/lv_img_decoder.h"
#include "../misc/lv_fs.h"
@@ -165,8 +166,6 @@ void lv_img_set_offset_x(lv_obj_t * obj, lv_coord_t x)
lv_img_t * img = (lv_img_t *)obj;
x = x % img->w;
img->offset.x = x;
lv_obj_invalidate(obj);
}
@@ -177,29 +176,23 @@ void lv_img_set_offset_y(lv_obj_t * obj, lv_coord_t y)
lv_img_t * img = (lv_img_t *)obj;
y = y % img->h;
img->offset.y = y;
lv_obj_invalidate(obj);
}
void lv_img_set_angle(lv_obj_t * obj, int16_t angle)
{
if(angle < 0 || angle >= 3600) angle = angle % 3600;
while(angle >= 3600) angle -= 3600;
while(angle < 0) angle += 3600;
lv_img_t * img = (lv_img_t *)obj;
if(angle == img->angle) return;
lv_coord_t transf_zoom = lv_obj_get_style_transform_zoom(obj, LV_PART_MAIN);
transf_zoom = ((int32_t)transf_zoom * img->zoom) >> 8;
lv_coord_t transf_angle = lv_obj_get_style_transform_angle(obj, LV_PART_MAIN);
lv_obj_update_layout(obj); /*Be sure the object's size is calculated*/
lv_coord_t w = lv_obj_get_width(obj);
lv_coord_t h = lv_obj_get_height(obj);
lv_area_t a;
_lv_img_buf_get_transformed_area(&a, w, h, transf_angle + img->angle, transf_zoom, &img->pivot);
_lv_img_buf_get_transformed_area(&a, w, h, img->angle, img->zoom, &img->pivot);
a.x1 += obj->coords.x1;
a.y1 += obj->coords.y1;
a.x2 += obj->coords.x1;
@@ -207,9 +200,15 @@ void lv_img_set_angle(lv_obj_t * obj, int16_t angle)
lv_obj_invalidate_area(obj, &a);
img->angle = angle;
lv_obj_refresh_ext_draw_size(obj);
_lv_img_buf_get_transformed_area(&a, w, h, transf_angle + img->angle, transf_zoom, &img->pivot);
/* Disable invalidations because lv_obj_refresh_ext_draw_size would invalidate
* the whole ext draw area */
lv_disp_t * disp = lv_obj_get_disp(obj);
lv_disp_enable_invalidation(disp, false);
lv_obj_refresh_ext_draw_size(obj);
lv_disp_enable_invalidation(disp, true);
_lv_img_buf_get_transformed_area(&a, w, h, img->angle, img->zoom, &img->pivot);
a.x1 += obj->coords.x1;
a.y1 += obj->coords.y1;
a.x2 += obj->coords.x1;
@@ -222,17 +221,11 @@ void lv_img_set_pivot(lv_obj_t * obj, lv_coord_t x, lv_coord_t y)
lv_img_t * img = (lv_img_t *)obj;
if(img->pivot.x == x && img->pivot.y == y) return;
lv_coord_t transf_zoom = lv_obj_get_style_transform_zoom(obj, LV_PART_MAIN);
transf_zoom = ((int32_t)transf_zoom * img->zoom) >> 8;
lv_coord_t transf_angle = lv_obj_get_style_transform_angle(obj, LV_PART_MAIN);
transf_angle += img->angle;
lv_obj_update_layout(obj); /*Be sure the object's size is calculated*/
lv_coord_t w = lv_obj_get_width(obj);
lv_coord_t h = lv_obj_get_height(obj);
lv_area_t a;
_lv_img_buf_get_transformed_area(&a, w, h, transf_angle, transf_zoom, &img->pivot);
_lv_img_buf_get_transformed_area(&a, w, h, img->angle, img->zoom, &img->pivot);
a.x1 += obj->coords.x1;
a.y1 += obj->coords.y1;
a.x2 += obj->coords.x1;
@@ -241,9 +234,15 @@ void lv_img_set_pivot(lv_obj_t * obj, lv_coord_t x, lv_coord_t y)
img->pivot.x = x;
img->pivot.y = y;
lv_obj_refresh_ext_draw_size(obj);
_lv_img_buf_get_transformed_area(&a, w, h, transf_angle, transf_zoom, &img->pivot);
/* Disable invalidations because lv_obj_refresh_ext_draw_size would invalidate
* the whole ext draw area */
lv_disp_t * disp = lv_obj_get_disp(obj);
lv_disp_enable_invalidation(disp, false);
lv_obj_refresh_ext_draw_size(obj);
lv_disp_enable_invalidation(disp, true);
_lv_img_buf_get_transformed_area(&a, w, h, img->angle, img->zoom, &img->pivot);
a.x1 += obj->coords.x1;
a.y1 += obj->coords.y1;
a.x2 += obj->coords.x1;
@@ -258,16 +257,11 @@ void lv_img_set_zoom(lv_obj_t * obj, uint16_t zoom)
if(zoom == 0) zoom = 1;
lv_coord_t transf_zoom = lv_obj_get_style_transform_zoom(obj, LV_PART_MAIN);
lv_coord_t transf_angle = lv_obj_get_style_transform_angle(obj, LV_PART_MAIN);
transf_angle += img->angle;
lv_obj_update_layout(obj); /*Be sure the object's size is calculated*/
lv_coord_t w = lv_obj_get_width(obj);
lv_coord_t h = lv_obj_get_height(obj);
lv_area_t a;
_lv_img_buf_get_transformed_area(&a, w, h, transf_angle, ((int32_t)transf_zoom * img->zoom) >> 8, &img->pivot);
_lv_img_buf_get_transformed_area(&a, w, h, img->angle, img->zoom >> 8, &img->pivot);
a.x1 += obj->coords.x1 - 1;
a.y1 += obj->coords.y1 - 1;
a.x2 += obj->coords.x1 + 1;
@@ -275,9 +269,15 @@ void lv_img_set_zoom(lv_obj_t * obj, uint16_t zoom)
lv_obj_invalidate_area(obj, &a);
img->zoom = zoom;
lv_obj_refresh_ext_draw_size(obj);
_lv_img_buf_get_transformed_area(&a, w, h, transf_angle, ((int32_t)transf_zoom * img->zoom) >> 8, &img->pivot);
/* Disable invalidations because lv_obj_refresh_ext_draw_size would invalidate
* the whole ext draw area */
lv_disp_t * disp = lv_obj_get_disp(obj);
lv_disp_enable_invalidation(disp, false);
lv_obj_refresh_ext_draw_size(obj);
lv_disp_enable_invalidation(disp, true);
_lv_img_buf_get_transformed_area(&a, w, h, img->angle, img->zoom, &img->pivot);
a.x1 += obj->coords.x1 - 1;
a.y1 += obj->coords.y1 - 1;
a.x2 += obj->coords.x1 + 1;
@@ -424,14 +424,9 @@ static lv_point_t lv_img_get_transformed_size(lv_obj_t * obj)
{
lv_img_t * img = (lv_img_t *)obj;
int32_t zoom_final = lv_obj_get_style_transform_zoom(obj, LV_PART_MAIN);
zoom_final = (zoom_final * img->zoom) >> 8;
int32_t angle_final = lv_obj_get_style_transform_angle(obj, LV_PART_MAIN);
angle_final += img->angle;
lv_area_t area_transform;
_lv_img_buf_get_transformed_area(&area_transform, img->w, img->h,
angle_final, zoom_final, &img->pivot);
img->angle, img->zoom, &img->pivot);
return (lv_point_t) {
lv_area_get_width(&area_transform), lv_area_get_height(&area_transform)
@@ -467,42 +462,31 @@ static void lv_img_event(const lv_obj_class_t * class_p, lv_event_t * e)
else if(code == LV_EVENT_REFR_EXT_DRAW_SIZE) {
lv_coord_t * s = lv_event_get_param(e);
lv_coord_t transf_zoom = lv_obj_get_style_transform_zoom(obj, LV_PART_MAIN);
transf_zoom = ((int32_t)transf_zoom * img->zoom) >> 8;
lv_coord_t transf_angle = lv_obj_get_style_transform_angle(obj, LV_PART_MAIN);
transf_angle += img->angle;
/*If the image has angle provide enough room for the rotated corners*/
if(transf_angle || transf_zoom != LV_IMG_ZOOM_NONE) {
if(img->angle || img->zoom != LV_IMG_ZOOM_NONE) {
lv_area_t a;
lv_coord_t w = lv_obj_get_width(obj);
lv_coord_t h = lv_obj_get_height(obj);
_lv_img_buf_get_transformed_area(&a, w, h, transf_angle, transf_zoom, &img->pivot);
lv_coord_t pad_ori = *s;
*s = LV_MAX(*s, pad_ori - a.x1);
*s = LV_MAX(*s, pad_ori - a.y1);
*s = LV_MAX(*s, pad_ori + a.x2 - w);
*s = LV_MAX(*s, pad_ori + a.y2 - h);
_lv_img_buf_get_transformed_area(&a, w, h, img->angle, img->zoom, &img->pivot);
*s = LV_MAX(*s, -a.x1);
*s = LV_MAX(*s, -a.y1);
*s = LV_MAX(*s, a.x2 - w);
*s = LV_MAX(*s, a.y2 - h);
}
}
else if(code == LV_EVENT_HIT_TEST) {
lv_hit_test_info_t * info = lv_event_get_param(e);
lv_coord_t zoom = lv_obj_get_style_transform_zoom(obj, LV_PART_MAIN);
zoom = (zoom * img->zoom) >> 8;
lv_coord_t angle = lv_obj_get_style_transform_angle(obj, LV_PART_MAIN);
angle += img->angle;
/*If the object is exactly image sized (not cropped, not mosaic) and transformed
*perform hit test on its transformed area*/
if(img->w == lv_obj_get_width(obj) && img->h == lv_obj_get_height(obj) &&
(zoom != LV_IMG_ZOOM_NONE || angle != 0 || img->pivot.x != img->w / 2 || img->pivot.y != img->h / 2)) {
(img->zoom != LV_IMG_ZOOM_NONE || img->angle != 0 || img->pivot.x != img->w / 2 || img->pivot.y != img->h / 2)) {
lv_coord_t w = lv_obj_get_width(obj);
lv_coord_t h = lv_obj_get_height(obj);
lv_area_t coords;
_lv_img_buf_get_transformed_area(&coords, w, h, angle, zoom, &img->pivot);
_lv_img_buf_get_transformed_area(&coords, w, h, img->angle, img->zoom, &img->pivot);
coords.x1 += obj->coords.x1;
coords.y1 += obj->coords.y1;
coords.x2 += obj->coords.x1;
@@ -556,19 +540,13 @@ static void draw_img(lv_event_t * e)
return;
}
int32_t angle_final = lv_obj_get_style_transform_angle(obj, LV_PART_MAIN);
angle_final += img->angle;
if(angle_final != 0) {
if(img->angle != 0) {
info->res = LV_COVER_RES_NOT_COVER;
return;
}
int32_t zoom_final = lv_obj_get_style_transform_zoom(obj, LV_PART_MAIN);
zoom_final = (zoom_final * img->zoom) >> 8;
const lv_area_t * clip_area = lv_event_get_param(e);
if(zoom_final == LV_IMG_ZOOM_NONE) {
if(img->zoom == LV_IMG_ZOOM_NONE) {
if(_lv_area_is_in(clip_area, &obj->coords, 0) == false) {
info->res = LV_COVER_RES_NOT_COVER;
return;
@@ -576,7 +554,7 @@ static void draw_img(lv_event_t * e)
}
else {
lv_area_t a;
_lv_img_buf_get_transformed_area(&a, lv_obj_get_width(obj), lv_obj_get_height(obj), 0, zoom_final, &img->pivot);
_lv_img_buf_get_transformed_area(&a, lv_obj_get_width(obj), lv_obj_get_height(obj), 0, img->zoom, &img->pivot);
a.x1 += obj->coords.x1;
a.y1 += obj->coords.y1;
a.x2 += obj->coords.x1;
@@ -590,12 +568,6 @@ static void draw_img(lv_event_t * e)
}
else if(code == LV_EVENT_DRAW_MAIN || code == LV_EVENT_DRAW_POST) {
int32_t zoom_final = lv_obj_get_style_transform_zoom(obj, LV_PART_MAIN);
zoom_final = (zoom_final * img->zoom) >> 8;
int32_t angle_final = lv_obj_get_style_transform_angle(obj, LV_PART_MAIN);
angle_final += img->angle;
lv_coord_t obj_w = lv_obj_get_width(obj);
lv_coord_t obj_h = lv_obj_get_height(obj);
@@ -616,7 +588,7 @@ static void draw_img(lv_event_t * e)
}
else {
_lv_img_buf_get_transformed_area(&bg_coords, obj_w, obj_h,
angle_final, zoom_final, &bg_pivot);
img->angle, img->zoom, &bg_pivot);
/*Modify the coordinates to draw the background for the rotated and scaled coordinates*/
bg_coords.x1 += obj->coords.x1;
@@ -636,7 +608,7 @@ static void draw_img(lv_event_t * e)
if(code == LV_EVENT_DRAW_MAIN) {
if(img->h == 0 || img->w == 0) return;
if(zoom_final == 0) return;
if(img->zoom == 0) return;
lv_draw_ctx_t * draw_ctx = lv_event_get_draw_ctx(e);
@@ -666,8 +638,8 @@ static void draw_img(lv_event_t * e)
lv_draw_img_dsc_init(&img_dsc);
lv_obj_init_draw_img_dsc(obj, LV_PART_MAIN, &img_dsc);
img_dsc.zoom = zoom_final;
img_dsc.angle = angle_final;
img_dsc.zoom = img->zoom;
img_dsc.angle = img->angle;
img_dsc.pivot.x = img->pivot.x;
img_dsc.pivot.y = img->pivot.y;
img_dsc.antialias = img->antialias;
@@ -683,12 +655,14 @@ static void draw_img(lv_event_t * e)
draw_ctx->clip_area = &img_clip_area;
lv_area_t coords_tmp;
coords_tmp.y1 = img_max_area.y1 + img->offset.y;
lv_coord_t offset_x = img->offset.x % img->w;
lv_coord_t offset_y = img->offset.y % img->h;
coords_tmp.y1 = img_max_area.y1 + offset_y;
if(coords_tmp.y1 > img_max_area.y1) coords_tmp.y1 -= img->h;
coords_tmp.y2 = coords_tmp.y1 + img->h - 1;
for(; coords_tmp.y1 < img_max_area.y2; coords_tmp.y1 += img_size_final.y, coords_tmp.y2 += img_size_final.y) {
coords_tmp.x1 = img_max_area.x1 + img->offset.x;
coords_tmp.x1 = img_max_area.x1 + offset_x;
if(coords_tmp.x1 > img_max_area.x1) coords_tmp.x1 -= img->w;
coords_tmp.x2 = coords_tmp.x1 + img->w - 1;
+3 -3
View File
@@ -110,10 +110,10 @@ void lv_img_set_offset_x(lv_obj_t * obj, lv_coord_t x);
*/
void lv_img_set_offset_y(lv_obj_t * obj, lv_coord_t y);
/**
* Set the rotation angle of the image.
* The image will be rotated around the set pivot set by `lv_img_set_pivot()`
* Note that indexed and alpha only images can't be transformed.
* @param obj pointer to an image object
* @param angle rotation angle in degree with 0.1 degree resolution (0..3600: clock wise)
*/
@@ -121,16 +121,16 @@ void lv_img_set_angle(lv_obj_t * obj, int16_t angle);
/**
* Set the rotation center of the image.
* The image will be rotated around this point
* The image will be rotated around this point.
* @param obj pointer to an image object
* @param x rotation center x of the image
* @param y rotation center y of the image
*/
void lv_img_set_pivot(lv_obj_t * obj, lv_coord_t x, lv_coord_t y);
/**
* Set the zoom factor of the image.
* Note that indexed and alpha only images can't be transformed.
* @param img pointer to an image object
* @param zoom the zoom factor.
* @example 256 or LV_ZOOM_IMG_NONE for no zoom
+1 -6
View File
@@ -1,4 +1,4 @@
/**
/**
* @file lv_label.c
*
*/
@@ -717,7 +717,6 @@ static void lv_label_constructor(const lv_obj_class_t * class_p, lv_obj_t * obj)
lv_label_set_long_mode(obj, LV_LABEL_LONG_WRAP);
lv_label_set_text(obj, "Text");
LV_TRACE_OBJ_CREATE("finished");
}
@@ -787,7 +786,6 @@ static void lv_label_event(const lv_obj_class_t * class_p, lv_event_t * e)
}
}
static void draw_main(lv_event_t * e)
{
lv_obj_t * obj = lv_event_get_target(e);
@@ -1168,7 +1166,6 @@ static void lv_label_refr_text(lv_obj_t * obj)
lv_obj_invalidate(obj);
}
static void lv_label_revert_dots(lv_obj_t * obj)
{
@@ -1255,7 +1252,6 @@ static void lv_label_dot_tmp_free(lv_obj_t * obj)
label->dot.tmp_ptr = NULL;
}
static void set_ofs_x_anim(void * obj, int32_t v)
{
lv_label_t * label = (lv_label_t *)obj;
@@ -1270,5 +1266,4 @@ static void set_ofs_y_anim(void * obj, int32_t v)
lv_obj_invalidate(obj);
}
#endif
+3 -7
View File
@@ -254,7 +254,6 @@ void lv_roller_get_selected_str(const lv_obj_t * obj, char * buf, uint32_t buf_s
buf[c] = '\0';
}
/**
* Get the options of a roller
* @param roller pointer to roller object
@@ -267,7 +266,6 @@ const char * lv_roller_get_options(const lv_obj_t * obj)
return lv_label_get_text(get_label(obj));
}
/**
* Get the total number of options
* @param roller pointer to a roller object
@@ -290,7 +288,6 @@ uint16_t lv_roller_get_option_cnt(const lv_obj_t * obj)
* STATIC FUNCTIONS
**********************/
static void lv_roller_constructor(const lv_obj_class_t * class_p, lv_obj_t * obj)
{
LV_UNUSED(class_p);
@@ -446,7 +443,6 @@ static void lv_roller_label_event(const lv_obj_class_t * class_p, lv_event_t * e
}
}
static void draw_main(lv_event_t * e)
{
lv_event_code_t code = lv_event_get_code(e);
@@ -477,6 +473,7 @@ static void draw_main(lv_event_t * e)
area_ok = _lv_area_intersect(&mask_sel, draw_ctx->clip_area, &sel_area);
if(area_ok) {
lv_obj_t * label = get_label(obj);
if(lv_label_get_recolor(label)) label_dsc.flag |= LV_TEXT_FLAG_RECOLOR;
/*Get the size of the "selected text"*/
lv_point_t res_p;
@@ -529,6 +526,8 @@ static void draw_label(lv_event_t * e)
lv_draw_label_dsc_t label_draw_dsc;
lv_draw_label_dsc_init(&label_draw_dsc);
lv_obj_init_draw_label_dsc(roller, LV_PART_MAIN, &label_draw_dsc);
if(lv_label_get_recolor(label_obj)) label_draw_dsc.flag |= LV_TEXT_FLAG_RECOLOR;
lv_draw_ctx_t * draw_ctx = lv_event_get_draw_ctx(e);
/*If the roller has shadow or outline it has some ext. draw size
@@ -744,7 +743,6 @@ static void inf_normalize(lv_obj_t * obj)
lv_obj_t * label = get_label(obj);
lv_coord_t sel_y1 = roller->sel_opt_id * (font_h + line_space);
lv_coord_t mid_y1 = h / 2 - font_h / 2;
lv_coord_t new_y = mid_y1 - sel_y1;
@@ -757,7 +755,6 @@ static lv_obj_t * get_label(const lv_obj_t * obj)
return lv_obj_get_child(obj, 0);
}
static lv_coord_t get_selected_label_width(const lv_obj_t * obj)
{
lv_obj_t * label = get_label(obj);
@@ -777,7 +774,6 @@ static void scroll_anim_ready_cb(lv_anim_t * a)
inf_normalize(obj);
}
static void set_y_anim(void * obj, int32_t v)
{
lv_obj_set_y(obj, v);
-2
View File
@@ -52,7 +52,6 @@ typedef struct {
extern const lv_obj_class_t lv_roller_class;
/**********************
* GLOBAL PROTOTYPES
**********************/
@@ -110,7 +109,6 @@ uint16_t lv_roller_get_selected(const lv_obj_t * obj);
*/
void lv_roller_get_selected_str(const lv_obj_t * obj, char * buf, uint32_t buf_size);
/**
* Get the options of a roller
* @param obj pointer to roller object
+14 -10
View File
@@ -212,7 +212,7 @@ static void lv_slider_event(const lv_obj_class_t * class_p, lv_event_t * e)
/*Make the point relative to the indicator*/
new_value = p.x - (obj->coords.x1 + bg_left);
}
new_value = (new_value * range) / indic_w;
new_value = (new_value * range + indic_w / 2) / indic_w;
new_value += slider->bar.min_value;
}
else {
@@ -223,7 +223,7 @@ static void lv_slider_event(const lv_obj_class_t * class_p, lv_event_t * e)
/*Make the point relative to the indicator*/
new_value = p.y - (obj->coords.y2 + bg_bottom);
new_value = (-new_value * range) / indic_h;
new_value = (-new_value * range + indic_h / 2) / indic_h;
new_value += slider->bar.min_value;
}
@@ -238,10 +238,13 @@ static void lv_slider_event(const lv_obj_class_t * class_p, lv_event_t * e)
}
new_value = LV_CLAMP(real_min_value, new_value, real_max_value);
if(*slider->value_to_set != new_value) {
*slider->value_to_set = new_value;
lv_obj_invalidate(obj);
if(slider->value_to_set == &slider->bar.start_value) {
lv_bar_set_start_value(obj, new_value, LV_ANIM_ON);
}
else {
lv_bar_set_value(obj, new_value, LV_ANIM_ON);
}
res = lv_event_send(obj, LV_EVENT_VALUE_CHANGED, NULL);
if(res != LV_RES_OK) return;
}
@@ -337,15 +340,16 @@ static void draw_knob(lv_event_t * e)
lv_area_t knob_area;
lv_coord_t knob_size;
bool is_symmetrical = false;
if(slider->bar.mode == LV_BAR_MODE_SYMMETRICAL && slider->bar.min_value < 0 &&
slider->bar.max_value > 0) is_symmetrical = true;
if(is_horizontal) {
knob_size = lv_obj_get_height(obj);
knob_area.x1 = LV_SLIDER_KNOB_COORD(is_rtl, slider->bar.indic_area);
if(is_symmetrical && slider->bar.cur_value < 0) knob_area.x1 = slider->bar.indic_area.x1;
else knob_area.x1 = LV_SLIDER_KNOB_COORD(is_rtl, slider->bar.indic_area);
}
else {
bool is_symmetrical = false;
if(slider->bar.mode == LV_BAR_MODE_SYMMETRICAL && slider->bar.min_value < 0 &&
slider->bar.max_value > 0) is_symmetrical = true;
knob_size = lv_obj_get_width(obj);
if(is_symmetrical && slider->bar.cur_value < 0) knob_area.y1 = slider->bar.indic_area.y2;
else knob_area.y1 = slider->bar.indic_area.y1;
-1
View File
@@ -273,5 +273,4 @@ static void lv_switch_trigger_anim(lv_obj_t * obj)
}
}
#endif
+157 -44
View File
@@ -40,8 +40,9 @@ static void refr_size_form_row(lv_obj_t * obj, uint32_t start_row);
static void refr_cell_size(lv_obj_t * obj, uint32_t row, uint32_t col);
static lv_res_t get_pressed_cell(lv_obj_t * obj, uint16_t * row, uint16_t * col);
static size_t get_cell_txt_len(const char * txt);
static void copy_cell_txt(char * dst, const char * txt);
static void copy_cell_txt(lv_table_cell_t * dst, const char * txt);
static void get_cell_area(lv_obj_t * obj, uint16_t row, uint16_t col, lv_area_t * area);
static void scroll_to_selected_cell(lv_obj_t * obj);
static inline bool is_cell_empty(void * cell)
{
@@ -97,7 +98,14 @@ void lv_table_set_cell_value(lv_obj_t * obj, uint16_t row, uint16_t col, const c
lv_table_cell_ctrl_t ctrl = 0;
/*Save the control byte*/
if(table->cell_data[cell]) ctrl = table->cell_data[cell][0];
if(table->cell_data[cell]) ctrl = table->cell_data[cell]->ctrl;
#if LV_USE_USER_DATA
void * user_data = NULL;
/*Save the user data*/
if(table->cell_data[cell]) user_data = table->cell_data[cell]->user_data;
#endif
size_t to_allocate = get_cell_txt_len(txt);
@@ -107,7 +115,10 @@ void lv_table_set_cell_value(lv_obj_t * obj, uint16_t row, uint16_t col, const c
copy_cell_txt(table->cell_data[cell], txt);
table->cell_data[cell][0] = ctrl;
table->cell_data[cell]->ctrl = ctrl;
#if LV_USE_USER_DATA
table->cell_data[cell]->user_data = user_data;
#endif
refr_cell_size(obj, row, col);
}
@@ -130,7 +141,14 @@ void lv_table_set_cell_value_fmt(lv_obj_t * obj, uint16_t row, uint16_t col, con
lv_table_cell_ctrl_t ctrl = 0;
/*Save the control byte*/
if(table->cell_data[cell]) ctrl = table->cell_data[cell][0];
if(table->cell_data[cell]) ctrl = table->cell_data[cell]->ctrl;
#if LV_USE_USER_DATA
void * user_data = NULL;
/*Save the user_data*/
if(table->cell_data[cell]) user_data = table->cell_data[cell]->user_data;
#endif
va_list ap, ap2;
va_start(ap, fmt);
@@ -153,32 +171,35 @@ void lv_table_set_cell_value_fmt(lv_obj_t * obj, uint16_t row, uint16_t col, con
/*Get the size of the Arabic text and process it*/
size_t len_ap = _lv_txt_ap_calc_bytes_cnt(raw_txt);
table->cell_data[cell] = lv_mem_realloc(table->cell_data[cell], len_ap + 1);
table->cell_data[cell] = lv_mem_realloc(table->cell_data[cell], sizeof(lv_table_cell_t) + len_ap + 1);
LV_ASSERT_MALLOC(table->cell_data[cell]);
if(table->cell_data[cell] == NULL) {
va_end(ap2);
return;
}
_lv_txt_ap_proc(raw_txt, &table->cell_data[cell][1]);
_lv_txt_ap_proc(raw_txt, table->cell_data[cell]->txt);
lv_mem_buf_release(raw_txt);
#else
table->cell_data[cell] = lv_mem_realloc(table->cell_data[cell], len + 2); /*+1: trailing '\0; +1: format byte*/
table->cell_data[cell] = lv_mem_realloc(table->cell_data[cell],
sizeof(lv_table_cell_t) + len + 1); /*+1: trailing '\0; */
LV_ASSERT_MALLOC(table->cell_data[cell]);
if(table->cell_data[cell] == NULL) {
va_end(ap2);
return;
}
table->cell_data[cell][len + 1] = 0; /*Ensure NULL termination*/
table->cell_data[cell]->txt[len] = 0; /*Ensure NULL termination*/
lv_vsnprintf(&table->cell_data[cell][1], len + 1, fmt, ap2);
lv_vsnprintf(table->cell_data[cell]->txt, len + 1, fmt, ap2);
#endif
va_end(ap2);
table->cell_data[cell][0] = ctrl;
table->cell_data[cell]->ctrl = ctrl;
#if LV_USE_USER_DATA
table->cell_data[cell]->user_data = user_data;
#endif
refr_cell_size(obj, row, col);
}
@@ -203,11 +224,17 @@ void lv_table_set_row_cnt(lv_obj_t * obj, uint16_t row_cnt)
uint32_t new_cell_cnt = table->col_cnt * table->row_cnt;
uint32_t i;
for(i = new_cell_cnt; i < old_cell_cnt; i++) {
#if LV_USE_USER_DATA
if(table->cell_data[i]->user_data) {
lv_mem_free(table->cell_data[i]->user_data);
table->cell_data[i]->user_data = NULL;
}
#endif
lv_mem_free(table->cell_data[i]);
}
}
table->cell_data = lv_mem_realloc(table->cell_data, table->row_cnt * table->col_cnt * sizeof(char *));
table->cell_data = lv_mem_realloc(table->cell_data, table->row_cnt * table->col_cnt * sizeof(lv_table_cell_t *));
LV_ASSERT_MALLOC(table->cell_data);
if(table->cell_data == NULL) return;
@@ -232,7 +259,7 @@ void lv_table_set_col_cnt(lv_obj_t * obj, uint16_t col_cnt)
uint16_t old_col_cnt = table->col_cnt;
table->col_cnt = col_cnt;
char ** new_cell_data = lv_mem_alloc(table->row_cnt * table->col_cnt * sizeof(char *));
lv_table_cell_t ** new_cell_data = lv_mem_alloc(table->row_cnt * table->col_cnt * sizeof(lv_table_cell_t *));
LV_ASSERT_MALLOC(new_cell_data);
if(new_cell_data == NULL) return;
uint32_t new_cell_cnt = table->col_cnt * table->row_cnt;
@@ -255,6 +282,12 @@ void lv_table_set_col_cnt(lv_obj_t * obj, uint16_t col_cnt)
int32_t i;
for(i = 0; i < (int32_t)old_col_cnt - col_cnt; i++) {
uint32_t idx = old_col_start + min_col_cnt + i;
#if LV_USE_USER_DATA
if(table->cell_data[idx]->user_data) {
lv_mem_free(table->cell_data[idx]->user_data);
table->cell_data[idx]->user_data = NULL;
}
#endif
lv_mem_free(table->cell_data[idx]);
table->cell_data[idx] = NULL;
}
@@ -273,7 +306,6 @@ void lv_table_set_col_cnt(lv_obj_t * obj, uint16_t col_cnt)
table->col_w[col] = LV_DPI_DEF;
}
refr_size_form_row(obj, 0) ;
}
@@ -303,15 +335,18 @@ void lv_table_add_cell_ctrl(lv_obj_t * obj, uint16_t row, uint16_t col, lv_table
uint32_t cell = row * table->col_cnt + col;
if(is_cell_empty(table->cell_data[cell])) {
table->cell_data[cell] = lv_mem_alloc(2); /*+1: trailing '\0; +1: format byte*/
table->cell_data[cell] = lv_mem_alloc(sizeof(lv_table_cell_t) + 1); /*+1: trailing '\0 */
LV_ASSERT_MALLOC(table->cell_data[cell]);
if(table->cell_data[cell] == NULL) return;
table->cell_data[cell][0] = 0;
table->cell_data[cell][1] = '\0';
table->cell_data[cell]->ctrl = 0;
#if LV_USE_USER_DATA
table->cell_data[cell]->user_data = NULL;
#endif
table->cell_data[cell]->txt[0] = '\0';
}
table->cell_data[cell][0] |= ctrl;
table->cell_data[cell]->ctrl |= ctrl;
}
void lv_table_clear_cell_ctrl(lv_obj_t * obj, uint16_t row, uint16_t col, lv_table_cell_ctrl_t ctrl)
@@ -327,17 +362,51 @@ void lv_table_clear_cell_ctrl(lv_obj_t * obj, uint16_t row, uint16_t col, lv_tab
uint32_t cell = row * table->col_cnt + col;
if(is_cell_empty(table->cell_data[cell])) {
table->cell_data[cell] = lv_mem_alloc(2); /*+1: trailing '\0; +1: format byte*/
table->cell_data[cell] = lv_mem_alloc(sizeof(lv_table_cell_t) + 1); /*+1: trailing '\0 */
LV_ASSERT_MALLOC(table->cell_data[cell]);
if(table->cell_data[cell] == NULL) return;
table->cell_data[cell][0] = 0;
table->cell_data[cell][1] = '\0';
table->cell_data[cell]->ctrl = 0;
#if LV_USE_USER_DATA
table->cell_data[cell]->user_data = NULL;
#endif
table->cell_data[cell]->txt[0] = '\0';
}
table->cell_data[cell][0] &= (~ctrl);
table->cell_data[cell]->ctrl &= (~ctrl);
}
#if LV_USE_USER_DATA
void lv_table_set_cell_user_data(lv_obj_t * obj, uint16_t row, uint16_t col, void * user_data)
{
LV_ASSERT_OBJ(obj, MY_CLASS);
lv_table_t * table = (lv_table_t *)obj;
/*Auto expand*/
if(col >= table->col_cnt) lv_table_set_col_cnt(obj, col + 1);
if(row >= table->row_cnt) lv_table_set_row_cnt(obj, row + 1);
uint32_t cell = row * table->col_cnt + col;
if(is_cell_empty(table->cell_data[cell])) {
table->cell_data[cell] = lv_mem_alloc(sizeof(lv_table_cell_t) + 1); /*+1: trailing '\0 */
LV_ASSERT_MALLOC(table->cell_data[cell]);
if(table->cell_data[cell] == NULL) return;
table->cell_data[cell]->ctrl = 0;
table->cell_data[cell]->user_data = NULL;
table->cell_data[cell]->txt[0] = '\0';
}
if(table->cell_data[cell]->user_data) {
lv_mem_free(table->cell_data[cell]->user_data);
}
table->cell_data[cell]->user_data = user_data;
}
#endif
/*=====================
* Getter functions
*====================*/
@@ -355,7 +424,7 @@ const char * lv_table_get_cell_value(lv_obj_t * obj, uint16_t row, uint16_t col)
if(is_cell_empty(table->cell_data[cell])) return "";
return &table->cell_data[cell][1]; /*Skip the format byte*/
return table->cell_data[cell]->txt;
}
uint16_t lv_table_get_row_cnt(lv_obj_t * obj)
@@ -400,7 +469,7 @@ bool lv_table_has_cell_ctrl(lv_obj_t * obj, uint16_t row, uint16_t col, lv_table
uint32_t cell = row * table->col_cnt + col;
if(is_cell_empty(table->cell_data[cell])) return false;
else return (table->cell_data[cell][0] & ctrl) == ctrl;
else return (table->cell_data[cell]->ctrl & ctrl) == ctrl;
}
void lv_table_get_selected_cell(lv_obj_t * obj, uint16_t * row, uint16_t * col)
@@ -410,6 +479,24 @@ void lv_table_get_selected_cell(lv_obj_t * obj, uint16_t * row, uint16_t * col)
*col = table->col_act;
}
#if LV_USE_USER_DATA
void * lv_table_get_cell_user_data(lv_obj_t * obj, uint16_t row, uint16_t col)
{
LV_ASSERT_OBJ(obj, MY_CLASS);
lv_table_t * table = (lv_table_t *)obj;
if(row >= table->row_cnt || col >= table->col_cnt) {
LV_LOG_WARN("invalid row or column");
return NULL;
}
uint32_t cell = row * table->col_cnt + col;
if(is_cell_empty(table->cell_data[cell])) return NULL;
return table->cell_data[cell]->user_data;
}
#endif
/**********************
* STATIC FUNCTIONS
**********************/
@@ -427,7 +514,7 @@ static void lv_table_constructor(const lv_obj_class_t * class_p, lv_obj_t * obj)
table->row_h = lv_mem_alloc(table->row_cnt * sizeof(table->row_h[0]));
table->col_w[0] = LV_DPI_DEF;
table->row_h[0] = LV_DPI_DEF;
table->cell_data = lv_mem_realloc(table->cell_data, table->row_cnt * table->col_cnt * sizeof(char *));
table->cell_data = lv_mem_realloc(table->cell_data, table->row_cnt * table->col_cnt * sizeof(lv_table_cell_t *));
table->cell_data[0] = NULL;
LV_TRACE_OBJ_CREATE("finished");
@@ -441,6 +528,12 @@ static void lv_table_destructor(const lv_obj_class_t * class_p, lv_obj_t * obj)
uint16_t i;
for(i = 0; i < table->col_cnt * table->row_cnt; i++) {
if(table->cell_data[i]) {
#if LV_USE_USER_DATA
if(table->cell_data[i]->user_data) {
lv_mem_free(table->cell_data[i]->user_data);
table->cell_data[i]->user_data = NULL;
}
#endif
lv_mem_free(table->cell_data[i]);
table->cell_data[i] = NULL;
}
@@ -516,6 +609,7 @@ static void lv_table_event(const lv_obj_class_t * class_p, lv_event_t * e)
if(col == LV_TABLE_CELL_NONE || row == LV_TABLE_CELL_NONE) {
table->col_act = 0;
table->row_act = 0;
scroll_to_selected_cell(obj);
lv_obj_invalidate(obj);
return;
}
@@ -560,6 +654,8 @@ static void lv_table_event(const lv_obj_class_t * class_p, lv_event_t * e)
table->row_act = row;
lv_obj_invalidate(obj);
scroll_to_selected_cell(obj);
res = lv_event_send(obj, LV_EVENT_VALUE_CHANGED, NULL);
if(res != LV_RES_OK) return;
}
@@ -569,7 +665,6 @@ static void lv_table_event(const lv_obj_class_t * class_p, lv_event_t * e)
}
}
static void draw_main(lv_event_t * e)
{
lv_obj_t * obj = lv_event_get_target(e);
@@ -635,7 +730,7 @@ static void draw_main(lv_event_t * e)
for(col = 0; col < table->col_cnt; col++) {
lv_table_cell_ctrl_t ctrl = 0;
if(table->cell_data[cell]) ctrl = table->cell_data[cell][0];
if(table->cell_data[cell]) ctrl = table->cell_data[cell]->ctrl;
if(rtl) {
cell_area.x2 = cell_area.x1 - 1;
@@ -648,11 +743,11 @@ static void draw_main(lv_event_t * e)
uint16_t col_merge = 0;
for(col_merge = 0; col_merge + col < table->col_cnt - 1; col_merge++) {
char * next_cell_data = table->cell_data[cell + col_merge];
lv_table_cell_t * next_cell_data = table->cell_data[cell + col_merge];
if(is_cell_empty(next_cell_data)) break;
lv_table_cell_ctrl_t merge_ctrl = (lv_table_cell_ctrl_t) next_cell_data[0];
lv_table_cell_ctrl_t merge_ctrl = (lv_table_cell_ctrl_t) next_cell_data->ctrl;
if(merge_ctrl & LV_TABLE_CELL_CTRL_MERGE_RIGHT) {
lv_coord_t offset = table->col_w[col + col_merge + 1];
@@ -735,7 +830,7 @@ static void draw_main(lv_event_t * e)
bool crop = ctrl & LV_TABLE_CELL_CTRL_TEXT_CROP ? true : false;
if(crop) txt_flags = LV_TEXT_FLAG_EXPAND;
lv_txt_get_size(&txt_size, table->cell_data[cell] + 1, label_dsc_def.font,
lv_txt_get_size(&txt_size, table->cell_data[cell]->txt, label_dsc_def.font,
label_dsc_act.letter_space, label_dsc_act.line_space,
lv_area_get_width(&txt_area), txt_flags);
@@ -750,7 +845,7 @@ static void draw_main(lv_event_t * e)
label_mask_ok = _lv_area_intersect(&label_clip_area, &clip_area, &cell_area);
if(label_mask_ok) {
draw_ctx->clip_area = &label_clip_area;
lv_draw_label(draw_ctx, &label_dsc_act, &txt_area, table->cell_data[cell] + 1, NULL);
lv_draw_label(draw_ctx, &label_dsc_act, &txt_area, table->cell_data[cell]->txt, NULL);
draw_ctx->clip_area = &clip_area;
}
}
@@ -792,7 +887,6 @@ static void refr_size_form_row(lv_obj_t * obj, uint32_t start_row)
lv_obj_invalidate(obj);
}
static void refr_cell_size(lv_obj_t * obj, uint32_t row, uint32_t col)
{
const lv_coord_t cell_pad_left = lv_obj_get_style_pad_left(obj, LV_PART_ITEMS);
@@ -841,7 +935,7 @@ static lv_coord_t get_row_height(lv_obj_t * obj, uint16_t row_id, const lv_font_
uint16_t cell;
uint16_t col;
for(cell = row_start, col = 0; cell < row_start + table->col_cnt; cell++, col++) {
char * cell_data = table->cell_data[cell];
lv_table_cell_t * cell_data = table->cell_data[cell];
if(is_cell_empty(cell_data)) {
continue;
@@ -854,11 +948,11 @@ static lv_coord_t get_row_height(lv_obj_t * obj, uint16_t row_id, const lv_font_
* exit the traversal when the current cell control is not LV_TABLE_CELL_CTRL_MERGE_RIGHT */
uint16_t col_merge = 0;
for(col_merge = 0; col_merge + col < table->col_cnt - 1; col_merge++) {
char * next_cell_data = table->cell_data[cell + col_merge];
lv_table_cell_t * next_cell_data = table->cell_data[cell + col_merge];
if(is_cell_empty(next_cell_data)) break;
lv_table_cell_ctrl_t ctrl = (lv_table_cell_ctrl_t) next_cell_data[0];
lv_table_cell_ctrl_t ctrl = (lv_table_cell_ctrl_t) next_cell_data->ctrl;
if(ctrl & LV_TABLE_CELL_CTRL_MERGE_RIGHT) {
txt_w += table->col_w[col + col_merge + 1];
}
@@ -867,7 +961,7 @@ static lv_coord_t get_row_height(lv_obj_t * obj, uint16_t row_id, const lv_font_
}
}
lv_table_cell_ctrl_t ctrl = (lv_table_cell_ctrl_t) cell_data[0];
lv_table_cell_ctrl_t ctrl = (lv_table_cell_ctrl_t) cell_data->ctrl;
/*When cropping the text we can assume the row height is equal to the line height*/
if(ctrl & LV_TABLE_CELL_CTRL_TEXT_CROP) {
@@ -879,7 +973,7 @@ static lv_coord_t get_row_height(lv_obj_t * obj, uint16_t row_id, const lv_font_
lv_point_t txt_size;
txt_w -= cell_left + cell_right;
lv_txt_get_size(&txt_size, table->cell_data[cell] + 1, font,
lv_txt_get_size(&txt_size, table->cell_data[cell]->txt, font,
letter_space, line_space, txt_w, LV_TEXT_FLAG_NONE);
h_max = LV_MAX(txt_size.y + cell_top + cell_bottom, h_max);
@@ -949,23 +1043,21 @@ static size_t get_cell_txt_len(const char * txt)
size_t retval = 0;
#if LV_USE_ARABIC_PERSIAN_CHARS
retval = _lv_txt_ap_calc_bytes_cnt(txt) + 1;
retval = sizeof(lv_table_cell_t) + _lv_txt_ap_calc_bytes_cnt(txt) + 1;
#else
/* cell_data layout: [ctrl][txt][trailing '\0' terminator]
* +2 because of the trailing '\0' and the ctrl */
retval = strlen(txt) + 2;
retval = sizeof(lv_table_cell_t) + strlen(txt) + 1;
#endif
return retval;
}
/* Copy txt into dst skipping the format byte */
static void copy_cell_txt(char * dst, const char * txt)
static void copy_cell_txt(lv_table_cell_t * dst, const char * txt)
{
#if LV_USE_ARABIC_PERSIAN_CHARS
_lv_txt_ap_proc(txt, &dst[1]);
_lv_txt_ap_proc(txt, dst->txt);
#else
strcpy(&dst[1], txt);
strcpy(dst->txt, txt);
#endif
}
@@ -1004,4 +1096,25 @@ static void get_cell_area(lv_obj_t * obj, uint16_t row, uint16_t col, lv_area_t
}
static void scroll_to_selected_cell(lv_obj_t * obj)
{
lv_table_t * table = (lv_table_t *)obj;
lv_area_t a;
get_cell_area(obj, table->row_act, table->col_act, &a);
if(a.x1 < 0) {
lv_obj_scroll_by_bounded(obj, -a.x1, 0, LV_ANIM_ON);
}
else if(a.x2 > lv_obj_get_width(obj)) {
lv_obj_scroll_by_bounded(obj, lv_obj_get_width(obj) - a.x2, 0, LV_ANIM_ON);
}
if(a.y1 < 0) {
lv_obj_scroll_by_bounded(obj, 0, -a.y1, LV_ANIM_ON);
}
else if(a.y2 > lv_obj_get_height(obj)) {
lv_obj_scroll_by_bounded(obj, 0, lv_obj_get_height(obj) - a.y2, LV_ANIM_ON);
}
}
#endif
+31 -2
View File
@@ -46,12 +46,21 @@ enum {
typedef uint8_t lv_table_cell_ctrl_t;
/*Data of cell*/
typedef struct {
lv_table_cell_ctrl_t ctrl;
#if LV_USE_USER_DATA
void * user_data; /**< Custom user data*/
#endif
char txt[];
} lv_table_cell_t;
/*Data of table*/
typedef struct {
lv_obj_t obj;
uint16_t col_cnt;
uint16_t row_cnt;
char ** cell_data;
lv_table_cell_t ** cell_data;
lv_coord_t * row_h;
lv_coord_t * col_w;
uint16_t col_act;
@@ -134,7 +143,6 @@ void lv_table_set_col_width(lv_obj_t * obj, uint16_t col_id, lv_coord_t w);
*/
void lv_table_add_cell_ctrl(lv_obj_t * obj, uint16_t row, uint16_t col, lv_table_cell_ctrl_t ctrl);
/**
* Clear control bits of the cell.
* @param obj pointer to a Table object
@@ -144,6 +152,17 @@ void lv_table_add_cell_ctrl(lv_obj_t * obj, uint16_t row, uint16_t col, lv_table
*/
void lv_table_clear_cell_ctrl(lv_obj_t * obj, uint16_t row, uint16_t col, lv_table_cell_ctrl_t ctrl);
#if LV_USE_USER_DATA
/**
* Add custom user data to the cell.
* @param obj pointer to a Table object
* @param row id of the row [0 .. row_cnt -1]
* @param col id of the column [0 .. col_cnt -1]
* @param user_data pointer to the new user_data. It must be allocated by user as it will be freed automatically
*/
void lv_table_set_cell_user_data(lv_obj_t * obj, uint16_t row, uint16_t col, void * user_data);
#endif
/*=====================
* Getter functions
*====================*/
@@ -197,6 +216,16 @@ bool lv_table_has_cell_ctrl(lv_obj_t * obj, uint16_t row, uint16_t col, lv_table
*/
void lv_table_get_selected_cell(lv_obj_t * obj, uint16_t * row, uint16_t * col);
#if LV_USE_USER_DATA
/**
* Get custom user data to the cell.
* @param obj pointer to a Table object
* @param row id of the row [0 .. row_cnt -1]
* @param col id of the column [0 .. col_cnt -1]
*/
void * lv_table_get_cell_user_data(lv_obj_t * obj, uint16_t row, uint16_t col);
#endif
/**********************
* MACROS
**********************/
+53 -10
View File
@@ -435,6 +435,36 @@ void lv_textarea_set_password_mode(lv_obj_t * obj, bool en)
refr_cursor_area(obj);
}
void lv_textarea_set_password_bullet(lv_obj_t * obj, const char * bullet)
{
LV_ASSERT_OBJ(obj, MY_CLASS);
LV_ASSERT_NULL(bullet);
lv_textarea_t * ta = (lv_textarea_t *)obj;
if(!bullet && (ta->pwd_bullet)) {
lv_mem_free(ta->pwd_bullet);
ta->pwd_bullet = NULL;
}
else {
size_t txt_len = strlen(bullet);
/*Allocate memory for the pwd_bullet text*/
/*NOTE: Using special realloc behavior, malloc-like when data_p is NULL*/
ta->pwd_bullet = lv_mem_realloc(ta->pwd_bullet, txt_len + 1);
LV_ASSERT_MALLOC(ta->pwd_bullet);
if(ta->pwd_bullet == NULL) {
LV_LOG_ERROR("lv_textarea_set_password_bullet: couldn't allocate memory for bullet");
return;
}
strcpy(ta->pwd_bullet, bullet);
ta->pwd_bullet[txt_len] = '\0';
}
lv_obj_invalidate(obj);
}
void lv_textarea_set_one_line(lv_obj_t * obj, bool en)
{
LV_ASSERT_OBJ(obj, MY_CLASS);
@@ -590,6 +620,23 @@ bool lv_textarea_get_password_mode(const lv_obj_t * obj)
return ta->pwd_mode == 1U;
}
const char * lv_textarea_get_password_bullet(lv_obj_t * obj)
{
LV_ASSERT_OBJ(obj, MY_CLASS);
lv_textarea_t * ta = (lv_textarea_t *)obj;
if(ta->pwd_bullet) return ta->pwd_bullet;
lv_font_glyph_dsc_t g;
const lv_font_t * font = lv_obj_get_style_text_font(obj, LV_PART_MAIN);
/*If the textarea's font has the bullet character use it else fallback to "*"*/
if(lv_font_get_glyph_dsc(font, &g, LV_TEXTAREA_PWD_BULLET_UNICODE, 0))
return LV_SYMBOL_BULLET;
return "*";
}
bool lv_textarea_get_one_line(const lv_obj_t * obj)
{
LV_ASSERT_OBJ(obj, MY_CLASS);
@@ -764,6 +811,7 @@ static void lv_textarea_constructor(const lv_obj_class_t * class_p, lv_obj_t * o
ta->pwd_mode = 0;
ta->pwd_tmp = NULL;
ta->pwd_bullet = NULL;
ta->pwd_show_time = LV_TEXTAREA_DEF_PWD_SHOW_TIME;
ta->accepted_chars = NULL;
ta->max_length = 0;
@@ -800,6 +848,10 @@ static void lv_textarea_destructor(const lv_obj_class_t * class_p, lv_obj_t * ob
lv_mem_free(ta->pwd_tmp);
ta->pwd_tmp = NULL;
}
if(ta->pwd_bullet != NULL) {
lv_mem_free(ta->pwd_bullet);
ta->pwd_bullet = NULL;
}
if(ta->placeholder_txt != NULL) {
lv_mem_free(ta->placeholder_txt);
ta->placeholder_txt = NULL;
@@ -870,8 +922,6 @@ static void label_event_cb(lv_event_t * e)
}
}
/**
* Called to blink the cursor
* @param ta pointer to a text area
@@ -931,13 +981,7 @@ static void pwd_char_hider(lv_obj_t * obj)
uint32_t enc_len = _lv_txt_get_encoded_length(txt);
if(enc_len == 0) return;
/*If the textarea's font has "bullet" character use it else fallback to "*"*/
lv_font_glyph_dsc_t g;
const char * bullet = "*";
const lv_font_t * font = lv_obj_get_style_text_font(obj, LV_PART_MAIN);
if(lv_font_get_glyph_dsc(font, &g, LV_TEXTAREA_PWD_BULLET_UNICODE, 0)) bullet = LV_SYMBOL_BULLET;
const char * bullet = lv_textarea_get_password_bullet(obj);
const size_t bullet_len = strlen(bullet);
char * txt_tmp = lv_mem_buf_get(enc_len * bullet_len + 1);
@@ -1263,7 +1307,6 @@ static void draw_cursor(lv_event_t * e)
lv_area_t cur_area;
lv_area_copy(&cur_area, &ta->cursor.area);
cur_area.x1 += ta->label->coords.x1;
cur_area.y1 += ta->label->coords.y1;
cur_area.x2 += ta->label->coords.x1;
+15
View File
@@ -42,6 +42,7 @@ typedef struct {
lv_obj_t * label; /*Label of the text area*/
char * placeholder_txt; /*Place holder label. only visible if text is an empty string*/
char * pwd_tmp; /*Used to store the original text in password mode*/
char * pwd_bullet; /*Replacement characters displayed in password mode*/
const char * accepted_chars; /*Only these characters will be accepted. NULL: accept all*/
uint32_t max_length; /*The max. number of characters. 0: no limit*/
uint16_t pwd_show_time; /*Time to show characters in password mode before change them to '*'*/
@@ -154,6 +155,13 @@ void lv_textarea_set_cursor_click_pos(lv_obj_t * obj, bool en);
*/
void lv_textarea_set_password_mode(lv_obj_t * obj, bool en);
/**
* Set the replacement characters to show in password mode
* @param obj pointer to a text area object
* @param bullet pointer to the replacement text
*/
void lv_textarea_set_password_bullet(lv_obj_t * obj, const char * bullet);
/**
* Configure the text area to one line or back to normal
* @param obj pointer to a text area object
@@ -254,6 +262,13 @@ bool lv_textarea_get_cursor_click_pos(lv_obj_t * obj);
*/
bool lv_textarea_get_password_mode(const lv_obj_t * obj);
/**
* Get the replacement characters to show in password mode
* @param obj pointer to a text area object
* @return pointer to the replacement text
*/
const char * lv_textarea_get_password_bullet(lv_obj_t * obj);
/**
* Get the one line configuration attribute
* @param obj pointer to a text area object