mirror of
https://github.com/lvgl/lvgl.git
synced 2025-01-14 06:42:58 +08:00
add LV_SIGNAL/EVENT_LEAVE + state and indev improvments
This commit is contained in:
parent
c899edd283
commit
f2c7210232
@ -938,7 +938,6 @@ static void indev_proc_release(lv_indev_proc_t * proc)
|
||||
if(indev_reset_check(proc)) return;
|
||||
|
||||
/*Handle click focus*/
|
||||
bool click_focus_sent = false;
|
||||
#if LV_USE_GROUP
|
||||
lv_group_t * g = lv_obj_get_group(indev_obj_act);
|
||||
|
||||
@ -963,29 +962,20 @@ static void indev_proc_release(lv_indev_proc_t * proc)
|
||||
* `LV_EVENT_FOCUSED/DEFOCUSED` will be sent by `lv_group_focus_obj`*/
|
||||
if(g && parent) {
|
||||
if(lv_group_get_click_focus(g)) {
|
||||
click_focus_sent = true;
|
||||
lv_group_focus_obj(parent);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Send defocus to the lastly "active" object and foucus to the new one.
|
||||
* Do not send the events if they was sent by the click focus*/
|
||||
if(proc->types.pointer.last_pressed != indev_obj_act && click_focus_sent == false) {
|
||||
if(lv_obj_is_protected(indev_obj_act, LV_PROTECT_CLICK_FOCUS) == false) {
|
||||
lv_signal_send(proc->types.pointer.last_pressed, LV_SIGNAL_DEFOCUS, NULL);
|
||||
if(indev_reset_check(proc)) return;
|
||||
lv_event_send(proc->types.pointer.last_pressed, LV_EVENT_DEFOCUSED, NULL);
|
||||
if(indev_reset_check(proc)) return;
|
||||
/* Leave lastly "active" object */
|
||||
if(proc->types.pointer.last_pressed != indev_obj_act && lv_obj_is_protected(indev_obj_act, LV_PROTECT_CLICK_FOCUS) == false) {
|
||||
lv_signal_send(proc->types.pointer.last_pressed, LV_SIGNAL_LEAVE, NULL);
|
||||
if(indev_reset_check(proc)) return;
|
||||
lv_event_send(proc->types.pointer.last_pressed, LV_EVENT_LEAVE, NULL);
|
||||
if(indev_reset_check(proc)) return;
|
||||
|
||||
lv_signal_send(proc->types.pointer.act_obj, LV_SIGNAL_FOCUS, NULL);
|
||||
if(indev_reset_check(proc)) return;
|
||||
lv_event_send(proc->types.pointer.act_obj, LV_EVENT_FOCUSED, NULL);
|
||||
if(indev_reset_check(proc)) return;
|
||||
|
||||
proc->types.pointer.last_pressed = indev_obj_act;
|
||||
}
|
||||
proc->types.pointer.last_pressed = indev_obj_act;
|
||||
}
|
||||
|
||||
if(indev_reset_check(proc)) return;
|
||||
@ -1139,9 +1129,6 @@ static void indev_drag(lv_indev_proc_t * proc)
|
||||
/*Set new position if the vector is not zero*/
|
||||
if(proc->types.pointer.vect.x != 0 || proc->types.pointer.vect.y != 0) {
|
||||
|
||||
uint16_t inv_buf_size =
|
||||
lv_disp_get_inv_buf_size(indev_act->driver.disp); /*Get the number of currently invalidated areas*/
|
||||
|
||||
lv_coord_t prev_x = drag_obj->coords.x1;
|
||||
lv_coord_t prev_y = drag_obj->coords.y1;
|
||||
lv_coord_t prev_par_w = lv_obj_get_width(lv_obj_get_parent(drag_obj));
|
||||
@ -1157,21 +1144,18 @@ static void indev_drag(lv_indev_proc_t * proc)
|
||||
act_x += proc->types.pointer.drag_sum.x;
|
||||
act_y += proc->types.pointer.drag_sum.y;
|
||||
}
|
||||
lv_obj_set_pos(drag_obj, act_x + proc->types.pointer.vect.x, act_y + proc->types.pointer.vect.y);
|
||||
} else if(allowed_dirs == LV_DRAG_DIR_HOR) {
|
||||
if(drag_just_started) {
|
||||
proc->types.pointer.drag_dir = LV_DRAG_DIR_HOR;
|
||||
proc->types.pointer.drag_sum.y = 0;
|
||||
act_x += proc->types.pointer.drag_sum.x;
|
||||
}
|
||||
lv_obj_set_x(drag_obj, act_x + proc->types.pointer.vect.x);
|
||||
} else if(allowed_dirs == LV_DRAG_DIR_VER) {
|
||||
if(drag_just_started) {
|
||||
proc->types.pointer.drag_dir = LV_DRAG_DIR_VER;
|
||||
proc->types.pointer.drag_sum.x = 0;
|
||||
act_y += proc->types.pointer.drag_sum.y;
|
||||
}
|
||||
lv_obj_set_y(drag_obj, act_y + proc->types.pointer.vect.y);
|
||||
} else if(allowed_dirs == LV_DRAG_DIR_ONE) {
|
||||
if(drag_just_started) {
|
||||
if(LV_MATH_ABS(proc->types.pointer.drag_sum.x) > LV_MATH_ABS(proc->types.pointer.drag_sum.y)) {
|
||||
@ -1200,19 +1184,12 @@ static void indev_drag(lv_indev_proc_t * proc)
|
||||
act_y += proc->types.pointer.vect.y;
|
||||
}
|
||||
|
||||
uint16_t inv_buf_size =
|
||||
lv_disp_get_inv_buf_size(indev_act->driver.disp); /*Get the number of currently invalidated areas*/
|
||||
|
||||
lv_obj_set_pos(drag_obj, act_x, act_y);
|
||||
proc->types.pointer.drag_in_prog = 1;
|
||||
|
||||
/*Set the drag in progress flag*/
|
||||
/*Send the drag begin signal on first move*/
|
||||
if(drag_just_started) {
|
||||
drag_obj->signal_cb(drag_obj, LV_SIGNAL_DRAG_BEGIN, indev_act);
|
||||
if(indev_reset_check(proc)) return;
|
||||
|
||||
lv_event_send(drag_obj, LV_EVENT_DRAG_BEGIN, NULL);
|
||||
if(indev_reset_check(proc)) return;
|
||||
}
|
||||
|
||||
/*If the object didn't moved then clear the invalidated areas*/
|
||||
if(drag_obj->coords.x1 == prev_x && drag_obj->coords.y1 == prev_y) {
|
||||
/*In a special case if the object is moved on a page and
|
||||
@ -1225,6 +1202,17 @@ static void indev_drag(lv_indev_proc_t * proc)
|
||||
lv_disp_pop_from_inv_buf(indev_act->driver.disp, new_inv_buf_size - inv_buf_size);
|
||||
}
|
||||
}
|
||||
|
||||
/*Set the drag in progress flag*/
|
||||
/*Send the drag begin signal on first move*/
|
||||
if(drag_just_started) {
|
||||
drag_obj->signal_cb(drag_obj, LV_SIGNAL_DRAG_BEGIN, indev_act);
|
||||
if(indev_reset_check(proc)) return;
|
||||
|
||||
lv_event_send(drag_obj, LV_EVENT_DRAG_BEGIN, NULL);
|
||||
if(indev_reset_check(proc)) return;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -271,7 +271,9 @@ lv_obj_t * lv_obj_create(lv_obj_t * parent, const lv_obj_t * copy)
|
||||
new_obj->protect = LV_PROTECT_NONE;
|
||||
new_obj->parent_event = 0;
|
||||
new_obj->gesture_parent = 1;
|
||||
new_obj->state = 0;
|
||||
new_obj->state_dsc.act = LV_OBJ_STATE_NORMAL;
|
||||
new_obj->state_dsc.prev = LV_OBJ_STATE_NORMAL;
|
||||
new_obj->state_dsc.anim = 0;
|
||||
|
||||
#if LV_USE_BIDI
|
||||
if(parent == NULL) new_obj->base_dir = LV_BIDI_BASE_DIR_DEF;
|
||||
@ -1253,9 +1255,6 @@ void lv_obj_refresh_style(lv_obj_t * obj)
|
||||
{
|
||||
LV_ASSERT_OBJ(obj, LV_OBJX_NAME);
|
||||
|
||||
// /*Re-cache all children's styles first*/
|
||||
// lv_obj_update_style_cache(obj);
|
||||
|
||||
/*Send style change signals*/
|
||||
refresh_children_style(obj);
|
||||
}
|
||||
@ -1459,43 +1458,28 @@ void lv_obj_set_state(lv_obj_t * obj, lv_obj_state_t state)
|
||||
{
|
||||
LV_ASSERT_OBJ(obj, LV_OBJX_NAME);
|
||||
|
||||
lv_obj_state_t new_state = obj->state | state;
|
||||
if(obj->state != new_state) {
|
||||
/* Disabled/Enabled state change should be applied immediately without transition */
|
||||
if((obj->state & LV_OBJ_STATE_DISABLED) != (new_state & LV_OBJ_STATE_DISABLED)) {
|
||||
lv_obj_state_t new_state = obj->state_dsc.act | state;
|
||||
if(obj->state_dsc.act != new_state) {
|
||||
lv_style_int_t t = lv_obj_get_style_int(obj, LV_OBJ_PART_MAIN, LV_STYLE_TRANSITION_TIME);
|
||||
if(t == 0) {
|
||||
lv_anim_del(obj, obj_state_anim_cb);
|
||||
obj->state = new_state;
|
||||
obj->prev_state = new_state;
|
||||
obj->state_anim = 0;
|
||||
obj->state_dsc.act = new_state;
|
||||
obj->state_dsc.prev = new_state;
|
||||
obj->state_dsc.anim = 0;
|
||||
lv_obj_refresh_style(obj);
|
||||
}
|
||||
/*Start transition if set*/
|
||||
/*Set the new state for prev state too to get the TRANSITION_TIME for the new state*/
|
||||
else {
|
||||
lv_style_int_t t = lv_obj_get_style_int(obj, LV_OBJ_PART_MAIN, LV_STYLE_TRANSITION_TIME);
|
||||
if(t == 0) {
|
||||
lv_anim_del(obj, obj_state_anim_cb);
|
||||
obj->state = new_state;
|
||||
obj->prev_state = new_state;
|
||||
obj->state_anim = 0;
|
||||
lv_obj_refresh_style(obj);
|
||||
}
|
||||
/*Set the new state for prev state too to get the TRANSITION_TIME for the new state*/
|
||||
else {
|
||||
lv_obj_state_t prev_state = obj->state;
|
||||
obj->prev_state = new_state;
|
||||
obj->state = new_state;
|
||||
obj->state_anim = 0;
|
||||
obj->state_dsc.prev = obj->state_dsc.act;
|
||||
obj->state_dsc.act = new_state;
|
||||
obj->state_dsc.anim = 0;
|
||||
|
||||
/*Get the TRANSITION_TIME and set the real previous state*/
|
||||
obj->prev_state = prev_state;
|
||||
|
||||
lv_anim_t a;
|
||||
lv_anim_init(&a);
|
||||
lv_anim_set_exec_cb(&a, obj, obj_state_anim_cb);
|
||||
lv_anim_set_values(&a, 0, 255);
|
||||
lv_anim_set_time(&a, t, 0);
|
||||
lv_anim_create(&a);
|
||||
}
|
||||
lv_anim_t a;
|
||||
lv_anim_init(&a);
|
||||
lv_anim_set_exec_cb(&a, obj, obj_state_anim_cb);
|
||||
lv_anim_set_values(&a, 0, 255);
|
||||
lv_anim_set_time(&a, t, 0);
|
||||
lv_anim_create(&a);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1504,26 +1488,29 @@ void lv_obj_clear_state(lv_obj_t * obj, lv_obj_state_t state)
|
||||
{
|
||||
LV_ASSERT_OBJ(obj, LV_OBJX_NAME);
|
||||
|
||||
state = (~state) & 0xFF;
|
||||
lv_obj_state_t new_state = obj->state & state;
|
||||
if(obj->state != new_state) {
|
||||
lv_obj_state_t prev_state = obj->state;
|
||||
|
||||
/*Set the new state for prev state too to get the TRANSITION_TIME for the new state*/
|
||||
obj->prev_state = new_state;
|
||||
obj->state = new_state;
|
||||
obj->state_anim = 0;
|
||||
|
||||
/*Get the TRANSITION_TIME and set the real previous state*/
|
||||
lv_obj_state_t new_state = obj->state_dsc.act & (~state);
|
||||
if(obj->state_dsc.act != new_state) {
|
||||
lv_style_int_t t = lv_obj_get_style_int(obj, LV_OBJ_PART_MAIN, LV_STYLE_TRANSITION_TIME);
|
||||
obj->prev_state = prev_state;
|
||||
if(t == 0) {
|
||||
lv_anim_del(obj, obj_state_anim_cb);
|
||||
obj->state_dsc.act = new_state;
|
||||
obj->state_dsc.prev = new_state;
|
||||
obj->state_dsc.anim = 0;
|
||||
lv_obj_refresh_style(obj);
|
||||
}
|
||||
/*Set the new state for prev state too to get the TRANSITION_TIME for the new state*/
|
||||
else {
|
||||
obj->state_dsc.prev = obj->state_dsc.act;
|
||||
obj->state_dsc.act = new_state;
|
||||
obj->state_dsc.anim = 0;
|
||||
|
||||
lv_anim_t a;
|
||||
lv_anim_init(&a);
|
||||
lv_anim_set_exec_cb(&a, obj, obj_state_anim_cb);
|
||||
lv_anim_set_values(&a, 0, 255);
|
||||
lv_anim_set_time(&a, t, 0);
|
||||
lv_anim_create(&a);
|
||||
lv_anim_t a;
|
||||
lv_anim_init(&a);
|
||||
lv_anim_set_exec_cb(&a, obj, obj_state_anim_cb);
|
||||
lv_anim_set_values(&a, 0, 255);
|
||||
lv_anim_set_time(&a, t, 0);
|
||||
lv_anim_create(&a);
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
@ -2114,14 +2101,16 @@ lv_style_list_t * lv_obj_get_style_list(const lv_obj_t * obj, uint8_t part)
|
||||
|
||||
lv_style_int_t lv_obj_get_style_int(const lv_obj_t * obj, uint8_t part, lv_style_property_t prop)
|
||||
{
|
||||
if(obj->state == obj->prev_state) {
|
||||
lv_obj_state_dsc_t * state = lv_obj_get_state_dsc(obj, part);
|
||||
|
||||
if(state->act == state->prev) {
|
||||
return lv_obj_get_style_int_core(obj, part, prop);
|
||||
} else {
|
||||
lv_style_int_t act_int = lv_obj_get_style_int_core(obj, part, prop);
|
||||
lv_obj_state_t state_ori = obj->state;
|
||||
((lv_obj_t*)obj)->state = obj->prev_state;
|
||||
lv_obj_state_t state_ori = state->act;
|
||||
state->act = state->prev;
|
||||
lv_style_int_t prev_int = lv_obj_get_style_int_core(obj, part, prop);
|
||||
((lv_obj_t*)obj)->state = state_ori;
|
||||
state->act = state_ori;
|
||||
|
||||
if(prop == LV_STYLE_RADIUS) {
|
||||
if(act_int == LV_RADIUS_CIRCLE || prev_int == LV_RADIUS_CIRCLE) {
|
||||
@ -2138,8 +2127,8 @@ lv_style_int_t lv_obj_get_style_int(const lv_obj_t * obj, uint8_t part, lv_style
|
||||
}
|
||||
}
|
||||
|
||||
if(obj->state_anim >= 255) return act_int;
|
||||
return prev_int + (((act_int - prev_int) * obj->state_anim) >> 8);
|
||||
if(state->anim >= 255) return act_int;
|
||||
return prev_int + (((act_int - prev_int) * state->anim) >> 8);
|
||||
}
|
||||
}
|
||||
|
||||
@ -2147,47 +2136,53 @@ lv_style_int_t lv_obj_get_style_int(const lv_obj_t * obj, uint8_t part, lv_style
|
||||
|
||||
lv_color_t lv_obj_get_style_color(const lv_obj_t * obj, uint8_t part, lv_style_property_t prop)
|
||||
{
|
||||
if(obj->state == obj->prev_state) {
|
||||
lv_obj_state_dsc_t * state = lv_obj_get_state_dsc(obj, part);
|
||||
|
||||
if(state->act == state->prev) {
|
||||
return lv_obj_get_style_color_core(obj, part, prop);
|
||||
} else {
|
||||
lv_color_t act_color = lv_obj_get_style_color_core(obj, part, prop);
|
||||
lv_obj_state_t state_ori = obj->state;
|
||||
((lv_obj_t*)obj)->state = obj->prev_state;
|
||||
lv_obj_state_t state_ori = state->act;
|
||||
state->act = state->prev;
|
||||
lv_color_t prev_color = lv_obj_get_style_color_core(obj, part, prop);
|
||||
((lv_obj_t*)obj)->state = state_ori;
|
||||
state->act = state_ori;
|
||||
|
||||
return lv_color_mix(act_color, prev_color, obj->state_anim);
|
||||
return lv_color_mix(act_color, prev_color, state->anim);
|
||||
}
|
||||
}
|
||||
|
||||
lv_opa_t lv_obj_get_style_opa(const lv_obj_t * obj, uint8_t part, lv_style_property_t prop)
|
||||
{
|
||||
if(obj->state == obj->prev_state) {
|
||||
lv_obj_state_dsc_t * state = lv_obj_get_state_dsc(obj, part);
|
||||
|
||||
if(state->act == state->prev) {
|
||||
return lv_obj_get_style_opa_core(obj, part, prop);
|
||||
} else {
|
||||
lv_opa_t act_opa = lv_obj_get_style_opa_core(obj, part, prop);
|
||||
lv_obj_state_t state_ori = obj->state;
|
||||
((lv_obj_t*)obj)->state = obj->prev_state;
|
||||
lv_obj_state_t state_ori = state->act;
|
||||
state->act = state->prev;
|
||||
lv_opa_t prev_opa = lv_obj_get_style_opa_core(obj, part, prop);
|
||||
((lv_obj_t*)obj)->state = state_ori;
|
||||
state->act = state_ori;
|
||||
|
||||
if(obj->state_anim >= 255) return act_opa;
|
||||
return prev_opa + (((act_opa - prev_opa) * obj->state_anim) >> 8);
|
||||
if(state->anim >= 255) return act_opa;
|
||||
return prev_opa + (((act_opa - prev_opa) * state->anim) >> 8);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
const void * lv_obj_get_style_ptr(const lv_obj_t * obj, uint8_t part, lv_style_property_t prop)
|
||||
{
|
||||
if(obj->state == obj->prev_state) {
|
||||
lv_obj_state_dsc_t * state = lv_obj_get_state_dsc(obj, part);
|
||||
|
||||
if(state->act == state->prev) {
|
||||
return lv_obj_get_style_ptr_core(obj, part, prop);
|
||||
} else {
|
||||
if(obj->state_anim > 128) return lv_obj_get_style_ptr_core(obj, part, prop);
|
||||
if(state->anim > 128) return lv_obj_get_style_ptr_core(obj, part, prop);
|
||||
|
||||
lv_obj_state_t state_ori = obj->state;
|
||||
((lv_obj_t*)obj)->state = obj->prev_state;
|
||||
lv_obj_state_t state_ori = state->act;
|
||||
state->act = state->prev;
|
||||
const void * prev_ptr = lv_obj_get_style_ptr_core(obj, part, prop);
|
||||
((lv_obj_t*)obj)->state = state_ori;
|
||||
state->act = state_ori;
|
||||
|
||||
return prev_ptr;
|
||||
}
|
||||
@ -2358,27 +2353,38 @@ bool lv_obj_is_protected(const lv_obj_t * obj, uint8_t prot)
|
||||
return (obj->protect & prot) == 0 ? false : true;
|
||||
}
|
||||
|
||||
lv_obj_state_t lv_obj_get_state(const lv_obj_t * obj, uint8_t part)
|
||||
lv_obj_state_dsc_t * lv_obj_get_state_dsc(const lv_obj_t * obj, uint8_t part)
|
||||
{
|
||||
LV_ASSERT_OBJ(obj, LV_OBJX_NAME);
|
||||
|
||||
if(part < _LV_OBJ_PART_REAL_LAST) return obj->state;
|
||||
if(part < _LV_OBJ_PART_REAL_LAST) return &obj->state_dsc;
|
||||
|
||||
|
||||
static uint32_t x = 0;
|
||||
x++;
|
||||
printf("%d\n", x);
|
||||
|
||||
/*If a real part is asked, then use the object's signal to get its state.
|
||||
* A real object can be in different state then the main part
|
||||
* and only the object itseld knows who to get it's state. */
|
||||
lv_get_state_info_t info;
|
||||
info.part = part;
|
||||
info.result = 0;
|
||||
info.result = NULL;
|
||||
lv_res_t res;
|
||||
res = lv_signal_send((lv_obj_t*)obj, LV_SIGNAL_GET_STATE, &info);
|
||||
res = lv_signal_send((lv_obj_t*)obj, LV_SIGNAL_GET_STATE_DSC, &info);
|
||||
|
||||
if(res != LV_RES_OK) return 0;
|
||||
if(res != LV_RES_OK) return NULL;
|
||||
|
||||
return info.result;
|
||||
|
||||
}
|
||||
|
||||
lv_obj_state_t lv_obj_get_state(const lv_obj_t * obj, uint8_t part)
|
||||
{
|
||||
lv_obj_state_dsc_t * state_dsc = lv_obj_get_state_dsc(obj, part);
|
||||
return state_dsc->act;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the signal function of an object
|
||||
* @param obj pointer to an object
|
||||
@ -2928,11 +2934,11 @@ static void refresh_children_position(lv_obj_t * obj, lv_coord_t x_diff, lv_coor
|
||||
static void report_style_mod_core(void * style, lv_obj_t * obj)
|
||||
{
|
||||
uint8_t part_sub;
|
||||
for(part_sub = 0; part_sub != _LV_OBJ_PART_ALL; part_sub++) {
|
||||
for(part_sub = 0; part_sub != _LV_OBJ_PART_REAL_LAST; part_sub++) {
|
||||
lv_style_list_t * dsc = lv_obj_get_style_list(obj, part_sub);
|
||||
if(dsc == NULL) break;
|
||||
|
||||
uint8_t ci;
|
||||
uint8_t ci;
|
||||
for(ci = 0; ci < dsc->style_cnt; ci++) {
|
||||
lv_style_t * class = lv_style_list_get_style(dsc, ci);
|
||||
if(class == style) {
|
||||
@ -2972,7 +2978,6 @@ static void refresh_children_style(lv_obj_t * obj)
|
||||
|
||||
refresh_children_style(child); /*Check children too*/
|
||||
child = lv_obj_get_child(obj, child);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -3064,8 +3069,8 @@ static void base_dir_refr_children(lv_obj_t * obj)
|
||||
static void obj_state_anim_cb(void * p, lv_anim_value_t value)
|
||||
{
|
||||
lv_obj_t * obj = p;
|
||||
obj->state_anim = value;
|
||||
if(value == 255) obj->prev_state = obj->state;
|
||||
obj->state_dsc.anim = value;
|
||||
if(value == 255) obj->state_dsc.prev = obj->state_dsc.act;
|
||||
|
||||
lv_obj_refresh_style(obj);
|
||||
}
|
||||
|
@ -94,6 +94,7 @@ enum {
|
||||
LV_EVENT_KEY,
|
||||
LV_EVENT_FOCUSED,
|
||||
LV_EVENT_DEFOCUSED,
|
||||
LV_EVENT_LEAVE,
|
||||
LV_EVENT_VALUE_CHANGED, /**< The object's value has changed (i.e. slider moved) */
|
||||
LV_EVENT_INSERT,
|
||||
LV_EVENT_REFRESH,
|
||||
@ -124,7 +125,7 @@ enum {
|
||||
LV_SIGNAL_REFR_EXT_DRAW_PAD, /**< Object's extra padding has changed */
|
||||
LV_SIGNAL_GET_TYPE, /**< LittlevGL needs to retrieve the object's type */
|
||||
LV_SIGNAL_GET_STYLE, /**<Get the style of an object*/
|
||||
LV_SIGNAL_GET_STATE, /**<Get the state of the object*/
|
||||
LV_SIGNAL_GET_STATE_DSC, /**<Get the state of the object*/
|
||||
|
||||
/*Input device related*/
|
||||
LV_SIGNAL_HIT_TEST, /**< Advanced hit-testing */
|
||||
@ -137,7 +138,8 @@ enum {
|
||||
LV_SIGNAL_DRAG_BEGIN,
|
||||
LV_SIGNAL_DRAG_THROW_BEGIN,
|
||||
LV_SIGNAL_DRAG_END,
|
||||
LV_SIGNAL_GESTURE, /**< The object has been getture*/
|
||||
LV_SIGNAL_GESTURE, /**< The object has been gesture*/
|
||||
LV_SIGNAL_LEAVE, /**< Another object is clicked or chosen via an input device */
|
||||
|
||||
/*Group related*/
|
||||
LV_SIGNAL_FOCUS,
|
||||
@ -203,6 +205,7 @@ enum {
|
||||
typedef uint8_t lv_protect_t;
|
||||
|
||||
enum {
|
||||
LV_OBJ_STATE_NORMAL = 0,
|
||||
LV_OBJ_STATE_CHECKED = (LV_STYLE_STATE_CHECKED >> LV_STYLE_STATE_POS),
|
||||
LV_OBJ_STATE_FOCUS = (LV_STYLE_STATE_FOCUS >> LV_STYLE_STATE_POS),
|
||||
LV_OBJ_STATE_EDIT = (LV_STYLE_STATE_EDIT >> LV_STYLE_STATE_POS),
|
||||
@ -213,6 +216,12 @@ enum {
|
||||
|
||||
typedef uint8_t lv_obj_state_t;
|
||||
|
||||
typedef struct {
|
||||
lv_obj_state_t act;
|
||||
lv_obj_state_t prev;
|
||||
uint8_t anim;
|
||||
}lv_obj_state_dsc_t;
|
||||
|
||||
typedef struct _lv_obj_t
|
||||
{
|
||||
struct _lv_obj_t * parent; /**< Pointer to the parent object*/
|
||||
@ -257,9 +266,7 @@ typedef struct _lv_obj_t
|
||||
|
||||
uint8_t protect; /**< Automatically happening actions can be prevented.
|
||||
'OR'ed values from `lv_protect_t`*/
|
||||
uint8_t state;
|
||||
uint8_t prev_state;
|
||||
uint8_t state_anim;
|
||||
lv_obj_state_dsc_t state_dsc;
|
||||
|
||||
#if LV_USE_OBJ_REALIGN
|
||||
lv_realign_t realign; /**< Information about the last call to ::lv_obj_align. */
|
||||
@ -303,7 +310,7 @@ typedef struct
|
||||
typedef struct
|
||||
{
|
||||
uint8_t part;
|
||||
lv_obj_state_t result;
|
||||
lv_obj_state_dsc_t * result;
|
||||
} lv_get_state_info_t;
|
||||
|
||||
/**********************
|
||||
@ -1003,6 +1010,8 @@ uint8_t lv_obj_get_protect(const lv_obj_t * obj);
|
||||
*/
|
||||
bool lv_obj_is_protected(const lv_obj_t * obj, uint8_t prot);
|
||||
|
||||
lv_obj_state_dsc_t * lv_obj_get_state_dsc(const lv_obj_t * obj, uint8_t part);
|
||||
|
||||
lv_obj_state_t lv_obj_get_state(const lv_obj_t * obj, uint8_t part);
|
||||
|
||||
/**
|
||||
|
@ -67,7 +67,6 @@ void lv_style_built_in_init(void)
|
||||
void lv_style_init(lv_style_t * style)
|
||||
{
|
||||
style->map = NULL;
|
||||
style->size = 0;
|
||||
}
|
||||
|
||||
void lv_style_copy(lv_style_t * style_dest, const lv_style_t * style_src)
|
||||
@ -76,9 +75,10 @@ void lv_style_copy(lv_style_t * style_dest, const lv_style_t * style_src)
|
||||
|
||||
if(style_src->map == NULL) return;
|
||||
|
||||
style_dest->map = lv_mem_alloc(style_src->size);
|
||||
memcpy(style_dest->map, style_src->map, style_src->size);
|
||||
style_dest->size = style_src->size;
|
||||
uint16_t size = lv_style_get_size(style_src);
|
||||
|
||||
style_dest->map = lv_mem_alloc(size);
|
||||
memcpy(style_dest->map, style_src->map, size);
|
||||
}
|
||||
|
||||
void lv_style_list_init(lv_style_list_t * list)
|
||||
@ -198,7 +198,24 @@ void lv_style_reset(lv_style_t * style)
|
||||
{
|
||||
lv_mem_free(style->map);
|
||||
style->map = NULL;
|
||||
style->size = 0;
|
||||
}
|
||||
|
||||
uint16_t lv_style_get_size(lv_style_t * style)
|
||||
{
|
||||
if(style->map == NULL) return 0;
|
||||
|
||||
size_t i = 0;
|
||||
while(style->map[i] != _LV_STYLE_CLOSEING_PROP) {
|
||||
/*Go to the next property*/
|
||||
if((style->map[i] & 0xF) < LV_STYLE_ID_COLOR) i+= sizeof(lv_style_int_t);
|
||||
else if((style->map[i] & 0xF) < LV_STYLE_ID_OPA) i+= sizeof(lv_color_t);
|
||||
else if((style->map[i] & 0xF) < LV_STYLE_ID_PTR) i+= sizeof(lv_opa_t);
|
||||
else i+= sizeof(void*);
|
||||
|
||||
i += sizeof(lv_style_property_t);
|
||||
}
|
||||
|
||||
return i + sizeof(lv_style_property_t);
|
||||
}
|
||||
|
||||
void lv_style_set_int(lv_style_t * style, lv_style_property_t prop, lv_style_int_t value)
|
||||
@ -219,13 +236,20 @@ void lv_style_set_int(lv_style_t * style, lv_style_property_t prop, lv_style_int
|
||||
}
|
||||
|
||||
/*Add new property if not exists yet*/
|
||||
style->size += sizeof(lv_style_property_t) + sizeof(lv_style_int_t);
|
||||
style->map = lv_mem_realloc(style->map, style->size);
|
||||
uint8_t new_prop_size = (sizeof(lv_style_property_t) + sizeof(lv_style_int_t));
|
||||
lv_style_property_t end_mark = _LV_STYLE_CLOSEING_PROP;
|
||||
uint8_t end_mark_size = sizeof(end_mark);
|
||||
|
||||
uint16_t size = lv_style_get_size(style);
|
||||
if(size == 0) size += end_mark_size;
|
||||
size += sizeof(lv_style_property_t) + sizeof(lv_style_int_t);
|
||||
style->map = lv_mem_realloc(style->map, size);
|
||||
LV_ASSERT_MEM(style->map);
|
||||
if(style == NULL) return;
|
||||
|
||||
memcpy(style->map + style->size - (sizeof(lv_style_property_t) + sizeof(lv_style_int_t)), &prop, sizeof(lv_style_property_t));
|
||||
memcpy(style->map + style->size - sizeof(lv_style_int_t), &value, sizeof(lv_style_int_t));
|
||||
memcpy(style->map + size - new_prop_size - end_mark_size , &prop, sizeof(lv_style_property_t));
|
||||
memcpy(style->map + size - sizeof(lv_style_int_t) - end_mark_size, &value, sizeof(lv_style_int_t));
|
||||
memcpy(style->map + size - end_mark_size, &end_mark, sizeof(end_mark));
|
||||
}
|
||||
|
||||
void lv_style_set_color(lv_style_t * style, lv_style_property_t prop, lv_color_t color)
|
||||
@ -246,13 +270,21 @@ void lv_style_set_color(lv_style_t * style, lv_style_property_t prop, lv_color_t
|
||||
}
|
||||
|
||||
/*Add new property if not exists yet*/
|
||||
style->size += sizeof(lv_style_property_t) + sizeof(lv_color_t);
|
||||
style->map = lv_mem_realloc(style->map, style->size);
|
||||
uint8_t new_prop_size = (sizeof(lv_style_property_t) + sizeof(lv_color_t));
|
||||
lv_style_property_t end_mark = _LV_STYLE_CLOSEING_PROP;
|
||||
uint8_t end_mark_size = sizeof(end_mark);
|
||||
|
||||
uint16_t size = lv_style_get_size(style);
|
||||
if(size == 0) size += end_mark_size;
|
||||
|
||||
size += sizeof(lv_style_property_t) + sizeof(lv_color_t);
|
||||
style->map = lv_mem_realloc(style->map, size);
|
||||
LV_ASSERT_MEM(style->map);
|
||||
if(style == NULL) return;
|
||||
|
||||
memcpy(style->map + style->size - (sizeof(lv_style_property_t) + sizeof(lv_color_t)), &prop, sizeof(lv_style_property_t));
|
||||
memcpy(style->map + style->size - sizeof(lv_color_t), &color, sizeof(lv_color_t));
|
||||
memcpy(style->map + size - new_prop_size - end_mark_size, &prop, sizeof(lv_style_property_t));
|
||||
memcpy(style->map + size - sizeof(lv_color_t) - end_mark_size, &color, sizeof(lv_color_t));
|
||||
memcpy(style->map + size - end_mark_size, &end_mark, sizeof(end_mark));
|
||||
}
|
||||
|
||||
void lv_style_set_opa(lv_style_t * style, lv_style_property_t prop, lv_opa_t opa)
|
||||
@ -273,13 +305,21 @@ void lv_style_set_opa(lv_style_t * style, lv_style_property_t prop, lv_opa_t opa
|
||||
}
|
||||
|
||||
/*Add new property if not exists yet*/
|
||||
style->size += sizeof(lv_style_property_t) + sizeof(lv_opa_t);
|
||||
style->map = lv_mem_realloc(style->map, style->size);
|
||||
uint8_t new_prop_size = (sizeof(lv_style_property_t) + sizeof(lv_opa_t));
|
||||
lv_style_property_t end_mark = _LV_STYLE_CLOSEING_PROP;
|
||||
uint8_t end_mark_size = sizeof(end_mark);
|
||||
|
||||
uint16_t size = lv_style_get_size(style);
|
||||
if(size == 0) size += end_mark_size;
|
||||
|
||||
size += sizeof(lv_style_property_t) + sizeof(lv_opa_t);
|
||||
style->map = lv_mem_realloc(style->map, size);
|
||||
LV_ASSERT_MEM(style->map);
|
||||
if(style == NULL) return;
|
||||
|
||||
memcpy(style->map + style->size - (sizeof(lv_style_property_t) + sizeof(lv_opa_t)), &prop, sizeof(lv_style_property_t));
|
||||
memcpy(style->map + style->size - sizeof(lv_opa_t), &opa, sizeof(lv_opa_t));
|
||||
memcpy(style->map + size - new_prop_size - end_mark_size, &prop, sizeof(lv_style_property_t));
|
||||
memcpy(style->map + size - sizeof(lv_opa_t) - end_mark_size, &opa, sizeof(lv_opa_t));
|
||||
memcpy(style->map + size - end_mark_size, &end_mark, sizeof(end_mark));
|
||||
}
|
||||
|
||||
void lv_style_set_ptr(lv_style_t * style, lv_style_property_t prop, const void * p)
|
||||
@ -300,13 +340,21 @@ void lv_style_set_ptr(lv_style_t * style, lv_style_property_t prop, const void *
|
||||
}
|
||||
|
||||
/*Add new property if not exists yet*/
|
||||
style->size += sizeof(lv_style_property_t) + sizeof(void *);
|
||||
style->map = lv_mem_realloc(style->map, style->size);
|
||||
uint8_t new_prop_size = (sizeof(lv_style_property_t) + sizeof(void *));
|
||||
lv_style_property_t end_mark = _LV_STYLE_CLOSEING_PROP;
|
||||
uint8_t end_mark_size = sizeof(end_mark);
|
||||
|
||||
uint16_t size = lv_style_get_size(style);
|
||||
if(size == 0) size += end_mark_size;
|
||||
|
||||
size += sizeof(lv_style_property_t) + sizeof(void *);
|
||||
style->map = lv_mem_realloc(style->map, size);
|
||||
LV_ASSERT_MEM(style->map);
|
||||
if(style == NULL) return;
|
||||
|
||||
memcpy(style->map + style->size - (sizeof(lv_style_property_t) + sizeof(void *)), &prop, sizeof(lv_style_property_t));
|
||||
memcpy(style->map + style->size - sizeof(void *), &p, sizeof(void *));
|
||||
memcpy(style->map + size - new_prop_size - end_mark_size , &prop, sizeof(lv_style_property_t));
|
||||
memcpy(style->map + size - sizeof(void *) - end_mark_size , &p, sizeof(void *));
|
||||
memcpy(style->map + size - end_mark_size, &end_mark, sizeof(end_mark));
|
||||
}
|
||||
|
||||
|
||||
@ -604,6 +652,8 @@ void lv_style_anim_set_styles(lv_anim_t * a, lv_style_t * to_anim, const lv_styl
|
||||
|
||||
static inline int32_t get_property_index(const lv_style_t * style, lv_style_property_t prop)
|
||||
{
|
||||
if(style->map == NULL) return -1;
|
||||
|
||||
uint8_t id_to_find = prop & 0xFF;
|
||||
lv_style_attr_t attr;
|
||||
attr.full = (prop >> 8) & 0xFF;
|
||||
@ -611,28 +661,8 @@ static inline int32_t get_property_index(const lv_style_t * style, lv_style_prop
|
||||
int16_t weight = -1;
|
||||
int16_t id_guess = -1;
|
||||
|
||||
static const uint8_t size[16] = {
|
||||
sizeof(lv_style_int_t) + sizeof(lv_style_property_t),
|
||||
sizeof(lv_style_int_t) + sizeof(lv_style_property_t),
|
||||
sizeof(lv_style_int_t) + sizeof(lv_style_property_t),
|
||||
sizeof(lv_style_int_t) + sizeof(lv_style_property_t),
|
||||
sizeof(lv_style_int_t) + sizeof(lv_style_property_t),
|
||||
sizeof(lv_color_t) + sizeof(lv_style_property_t),
|
||||
sizeof(lv_color_t) + sizeof(lv_style_property_t),
|
||||
sizeof(lv_color_t) + sizeof(lv_style_property_t),
|
||||
sizeof(lv_color_t) + sizeof(lv_style_property_t),
|
||||
sizeof(lv_color_t) + sizeof(lv_style_property_t),
|
||||
sizeof(lv_opa_t) + sizeof(lv_style_property_t),
|
||||
sizeof(lv_opa_t) + sizeof(lv_style_property_t),
|
||||
sizeof(lv_opa_t) + sizeof(lv_style_property_t),
|
||||
sizeof(lv_opa_t) + sizeof(lv_style_property_t),
|
||||
sizeof(void*) + sizeof(lv_style_property_t),
|
||||
sizeof(void*) + sizeof(lv_style_property_t),
|
||||
};
|
||||
|
||||
size_t i = 0;
|
||||
while(i < style->size) {
|
||||
|
||||
while(style->map[i] != _LV_STYLE_CLOSEING_PROP) {
|
||||
if(style->map[i] == id_to_find) {
|
||||
lv_style_attr_t attr_act;
|
||||
attr_act.full = style->map[i + 1];
|
||||
@ -654,13 +684,12 @@ static inline int32_t get_property_index(const lv_style_t * style, lv_style_prop
|
||||
}
|
||||
|
||||
/*Go to the next property*/
|
||||
i+=size[style->map[i] & 0xF];
|
||||
// if((style->map[i] & 0xF) < LV_STYLE_ID_COLOR) i+= sizeof(lv_style_int_t);
|
||||
// else if((style->map[i] & 0xF) < LV_STYLE_ID_OPA) i+= sizeof(lv_color_t);
|
||||
// else if((style->map[i] & 0xF) < LV_STYLE_ID_PTR) i+= sizeof(lv_opa_t);
|
||||
// else i+= sizeof(void*);
|
||||
//
|
||||
// i += sizeof(lv_style_property_t);
|
||||
if((style->map[i] & 0xF) < LV_STYLE_ID_COLOR) i+= sizeof(lv_style_int_t);
|
||||
else if((style->map[i] & 0xF) < LV_STYLE_ID_OPA) i+= sizeof(lv_color_t);
|
||||
else if((style->map[i] & 0xF) < LV_STYLE_ID_PTR) i+= sizeof(lv_opa_t);
|
||||
else i+= sizeof(void*);
|
||||
|
||||
i += sizeof(lv_style_property_t);
|
||||
}
|
||||
|
||||
return id_guess;
|
||||
@ -703,7 +732,7 @@ static void style_animator(lv_style_anim_dsc_t * dsc, lv_anim_value_t val)
|
||||
|
||||
size_t i = 0;
|
||||
lv_style_property_t prop_act;
|
||||
while(i < start->size) {
|
||||
while(start->map[i] != _LV_STYLE_CLOSEING_PROP) {
|
||||
prop_act = start->map[i] + (start->map[i + 1] << 8);
|
||||
|
||||
/*Value*/
|
||||
|
@ -59,6 +59,8 @@ typedef uint8_t lv_grad_dir_t;
|
||||
#define LV_STYLE_ATTR_NONE 0
|
||||
#define LV_STYLE_ATTR_INHERIT (1 << 7)
|
||||
|
||||
#define _LV_STYLE_CLOSEING_PROP 0xFF
|
||||
|
||||
typedef union {
|
||||
struct {
|
||||
uint8_t state :7; /* To which state the property refers to*/
|
||||
@ -161,7 +163,6 @@ typedef uint16_t lv_style_state_t;
|
||||
|
||||
typedef struct {
|
||||
uint8_t * map;
|
||||
uint16_t size :9;
|
||||
}lv_style_t;
|
||||
|
||||
typedef int16_t lv_style_int_t;
|
||||
@ -218,6 +219,8 @@ static inline lv_style_t * lv_style_list_get_style(lv_style_list_t * style_dsc,
|
||||
|
||||
void lv_style_reset(lv_style_t * style);
|
||||
|
||||
uint16_t lv_style_get_size(lv_style_t * style);
|
||||
|
||||
/**
|
||||
* Copy a style to an other
|
||||
* @param dest pointer to the destination style
|
||||
|
@ -164,6 +164,8 @@ void lv_btn_toggle(lv_obj_t * btn)
|
||||
{
|
||||
LV_ASSERT_OBJ(btn, LV_OBJX_NAME);
|
||||
|
||||
|
||||
|
||||
if(lv_obj_get_state(btn, LV_BTN_PART_MAIN) & LV_OBJ_STATE_CHECKED) {
|
||||
lv_obj_clear_state(btn, LV_OBJ_STATE_CHECKED);
|
||||
} else {
|
||||
|
@ -68,8 +68,9 @@ typedef struct
|
||||
|
||||
/**Styles*/
|
||||
enum {
|
||||
LV_BTN_PART_MAIN,
|
||||
|
||||
LV_BTN_PART_MAIN = LV_OBJ_PART_MAIN ,
|
||||
_LV_BTN_PART_VIRTUAL_LAST,
|
||||
_LV_BTN_PART_REAL_LAST = _LV_OBJ_PART_REAL_LAST,
|
||||
};
|
||||
typedef uint8_t lv_btn_part_t;
|
||||
|
||||
|
@ -614,31 +614,30 @@ static lv_design_res_t lv_btnm_design(lv_obj_t * btnm, const lv_area_t * clip_ar
|
||||
|
||||
|
||||
/*The state changes without re-caching the styles, disable the use of cache*/
|
||||
uint8_t state_ori = btnm->state;
|
||||
uint8_t prev_state_ori = btnm->prev_state;
|
||||
btnm->state = 0;
|
||||
btnm->prev_state = 0;
|
||||
lv_obj_state_dsc_t state = btnm->state_dsc;
|
||||
lv_obj_state_dsc_t state_ori = btnm->state_dsc;
|
||||
btnm->state_dsc.act = LV_OBJ_STATE_NORMAL;
|
||||
btnm->state_dsc.prev = btnm->state_dsc.act;
|
||||
lv_draw_rect_dsc_init(&draw_rect_rel_dsc);
|
||||
lv_draw_label_dsc_init(&draw_label_rel_dsc);
|
||||
lv_obj_init_draw_rect_dsc(btnm, LV_BTNM_PART_BTN, &draw_rect_rel_dsc);
|
||||
lv_obj_init_draw_label_dsc(btnm, LV_BTNM_PART_BTN, &draw_label_rel_dsc);
|
||||
|
||||
btnm->state = LV_OBJ_STATE_CHECKED;
|
||||
btnm->prev_state = LV_OBJ_STATE_CHECKED;
|
||||
btnm->state_dsc.act = LV_OBJ_STATE_CHECKED;
|
||||
btnm->state_dsc.prev = btnm->state_dsc.act;
|
||||
lv_draw_rect_dsc_init(&draw_rect_chk_dsc);
|
||||
lv_draw_label_dsc_init(&draw_label_chk_dsc);
|
||||
lv_obj_init_draw_rect_dsc(btnm, LV_BTNM_PART_BTN, &draw_rect_chk_dsc);
|
||||
lv_obj_init_draw_label_dsc(btnm, LV_BTNM_PART_BTN, &draw_label_chk_dsc);
|
||||
|
||||
btnm->state = LV_OBJ_STATE_DISABLED;
|
||||
btnm->prev_state = LV_OBJ_STATE_DISABLED;
|
||||
btnm->state_dsc.act = LV_OBJ_STATE_DISABLED;
|
||||
btnm->state_dsc.prev = btnm->state_dsc.act;
|
||||
lv_draw_rect_dsc_init(&draw_rect_ina_dsc);
|
||||
lv_draw_label_dsc_init(&draw_label_ina_dsc);
|
||||
lv_obj_init_draw_rect_dsc(btnm, LV_BTNM_PART_BTN, &draw_rect_ina_dsc);
|
||||
lv_obj_init_draw_label_dsc(btnm, LV_BTNM_PART_BTN, &draw_label_ina_dsc);
|
||||
|
||||
btnm->state = state_ori;
|
||||
btnm->prev_state = state_ori;
|
||||
btnm->state_dsc = state_ori;
|
||||
|
||||
lv_style_int_t padding_top = lv_obj_get_style_int(btnm, LV_BTNM_PART_BG, LV_STYLE_PAD_TOP);
|
||||
lv_style_int_t padding_bottom = lv_obj_get_style_int(btnm, LV_BTNM_PART_BG, LV_STYLE_PAD_BOTTOM);
|
||||
@ -678,18 +677,17 @@ static lv_design_res_t lv_btnm_design(lv_obj_t * btnm, const lv_area_t * clip_ar
|
||||
}
|
||||
/*Focused and/or pressed + checked or released button*/
|
||||
else {
|
||||
if(tgl_state) btnm->state = LV_OBJ_STATE_CHECKED;
|
||||
if(ext->btn_id_pr == btn_i) btnm->state |= LV_OBJ_STATE_PRESSED;
|
||||
if(ext->btn_id_focused == btn_i) btnm->state |= LV_OBJ_STATE_FOCUS;
|
||||
btnm->prev_state = btnm->state;
|
||||
if(tgl_state) btnm->state_dsc.act = LV_OBJ_STATE_CHECKED;
|
||||
if(ext->btn_id_pr == btn_i) btnm->state_dsc.act |= LV_OBJ_STATE_PRESSED;
|
||||
if(ext->btn_id_focused == btn_i) btnm->state_dsc.act |= LV_OBJ_STATE_FOCUS;
|
||||
btnm->state_dsc.prev = btnm->state_dsc.act;
|
||||
lv_draw_rect_dsc_init(&draw_rect_tmp_dsc);
|
||||
lv_draw_label_dsc_init(&draw_label_tmp_dsc);
|
||||
lv_obj_init_draw_rect_dsc(btnm, LV_BTNM_PART_BTN, &draw_rect_tmp_dsc);
|
||||
lv_obj_init_draw_label_dsc(btnm, LV_BTNM_PART_BTN, &draw_label_tmp_dsc);
|
||||
draw_rect_dsc_act = &draw_rect_tmp_dsc;
|
||||
draw_label_dsc_act = &draw_label_tmp_dsc;
|
||||
btnm->state = state_ori;
|
||||
btnm->prev_state = prev_state_ori;
|
||||
btnm->state_dsc = state_ori;
|
||||
}
|
||||
|
||||
lv_style_int_t border_part_ori = draw_rect_dsc_act->border_side;
|
||||
|
@ -692,13 +692,12 @@ static void draw_header(lv_obj_t * calendar, const lv_area_t * mask)
|
||||
|
||||
/*The state changes without re-caching the styles, disable the use of cache*/
|
||||
// calendar->style_dsc.cache.enabled = 0;
|
||||
lv_obj_state_t state_ori = calendar->state;
|
||||
lv_obj_state_t prev_state_ori = calendar->prev_state;
|
||||
lv_obj_state_dsc_t state_ori = calendar->state_dsc;
|
||||
|
||||
if(ext->btn_pressing < 0) calendar->state |= LV_OBJ_STATE_PRESSED;
|
||||
else calendar->state &= ~(LV_OBJ_STATE_PRESSED);
|
||||
if(ext->btn_pressing < 0) calendar->state_dsc.act |= LV_OBJ_STATE_PRESSED;
|
||||
else calendar->state_dsc.act &= ~(LV_OBJ_STATE_PRESSED);
|
||||
|
||||
calendar->prev_state = calendar->state;
|
||||
calendar->state_dsc.prev = calendar->state_dsc.act;
|
||||
|
||||
header_area.x1 += left;
|
||||
|
||||
@ -706,14 +705,13 @@ static void draw_header(lv_obj_t * calendar, const lv_area_t * mask)
|
||||
lv_obj_init_draw_label_dsc(calendar, LV_CALENDAR_PART_HEADER, &label_dsc);
|
||||
lv_draw_label(&header_area, mask, &label_dsc, LV_SYMBOL_LEFT, NULL);
|
||||
|
||||
calendar->state = state_ori; /*Restore the state*/
|
||||
calendar->prev_state = prev_state_ori;
|
||||
calendar->state_dsc = state_ori; /*Restore the state*/
|
||||
|
||||
/*Add the right arrow*/
|
||||
if(ext->btn_pressing > 0) calendar->state |= LV_OBJ_STATE_PRESSED;
|
||||
else calendar->state &= ~(LV_OBJ_STATE_PRESSED);
|
||||
if(ext->btn_pressing > 0) calendar->state_dsc.act |= LV_OBJ_STATE_PRESSED;
|
||||
else calendar->state_dsc.act &= ~(LV_OBJ_STATE_PRESSED);
|
||||
|
||||
calendar->prev_state = calendar->state;
|
||||
calendar->state_dsc.prev = calendar->state_dsc.act;
|
||||
|
||||
header_area.x1 = header_area.x2 - right - lv_txt_get_width(LV_SYMBOL_RIGHT, (uint16_t)strlen(LV_SYMBOL_RIGHT), font, 0, LV_TXT_FLAG_NONE);
|
||||
|
||||
@ -721,9 +719,7 @@ static void draw_header(lv_obj_t * calendar, const lv_area_t * mask)
|
||||
lv_obj_init_draw_label_dsc(calendar, LV_CALENDAR_PART_HEADER, &label_dsc);
|
||||
lv_draw_label(&header_area, mask, &label_dsc, LV_SYMBOL_RIGHT, NULL);
|
||||
|
||||
calendar->state = state_ori; /*Restore the state*/
|
||||
calendar->prev_state = prev_state_ori;
|
||||
// calendar->style_dsc.cache.enabled = 1;
|
||||
calendar->state_dsc = state_ori; /*Restore the state*/
|
||||
}
|
||||
|
||||
/**
|
||||
@ -781,8 +777,7 @@ static void draw_days(lv_obj_t * calendar, const lv_area_t * mask)
|
||||
lv_coord_t days_h = calendar->coords.y2 - days_y1 - bg_bottom;
|
||||
|
||||
/*The state changes without re-caching the styles, disable the use of cache*/
|
||||
lv_obj_state_t state_ori = calendar->state;
|
||||
lv_obj_state_t prev_state_ori = calendar->prev_state;
|
||||
lv_obj_state_dsc_t state_ori = calendar->state_dsc;
|
||||
|
||||
lv_obj_state_t month_state = LV_OBJ_STATE_DISABLED;
|
||||
|
||||
@ -862,8 +857,8 @@ static void draw_days(lv_obj_t * calendar, const lv_area_t * mask)
|
||||
lv_draw_label_dsc_init(&label_dsc);
|
||||
label_dsc.flag = LV_TXT_FLAG_CENTER;
|
||||
|
||||
calendar->state = day_state;
|
||||
calendar->prev_state = day_state;
|
||||
calendar->state_dsc.act = day_state;
|
||||
calendar->state_dsc.prev = day_state;
|
||||
lv_obj_init_draw_label_dsc(calendar, LV_CALENDAR_PART_DATE_NUMS, &label_dsc);
|
||||
lv_obj_init_draw_rect_dsc(calendar, LV_CALENDAR_PART_DATE_NUMS, &rect_dsc);
|
||||
|
||||
@ -888,8 +883,7 @@ static void draw_days(lv_obj_t * calendar, const lv_area_t * mask)
|
||||
day_cnt++;
|
||||
}
|
||||
}
|
||||
calendar->state = state_ori;
|
||||
calendar->prev_state = prev_state_ori;
|
||||
calendar->state_dsc = state_ori;
|
||||
|
||||
|
||||
}
|
||||
|
@ -71,17 +71,17 @@ lv_obj_t * lv_cont_create(lv_obj_t * par, const lv_obj_t * copy)
|
||||
LV_LOG_TRACE("container create started");
|
||||
|
||||
/*Create a basic object*/
|
||||
lv_obj_t * new_cont = lv_obj_create(par, copy);
|
||||
LV_ASSERT_MEM(new_cont);
|
||||
if(new_cont == NULL) return NULL;
|
||||
lv_obj_t * cont = lv_obj_create(par, copy);
|
||||
LV_ASSERT_MEM(cont);
|
||||
if(cont == NULL) return NULL;
|
||||
|
||||
if(ancestor_signal == NULL) ancestor_signal = lv_obj_get_signal_cb(new_cont);
|
||||
if(ancestor_design == NULL) ancestor_design= lv_obj_get_design_cb(new_cont);
|
||||
if(ancestor_signal == NULL) ancestor_signal = lv_obj_get_signal_cb(cont);
|
||||
if(ancestor_design == NULL) ancestor_design= lv_obj_get_design_cb(cont);
|
||||
|
||||
lv_obj_allocate_ext_attr(new_cont, sizeof(lv_cont_ext_t));
|
||||
lv_cont_ext_t * ext = lv_obj_get_ext_attr(new_cont);
|
||||
lv_obj_allocate_ext_attr(cont, sizeof(lv_cont_ext_t));
|
||||
lv_cont_ext_t * ext = lv_obj_get_ext_attr(cont);
|
||||
if(ext == NULL) {
|
||||
lv_obj_del(new_cont);
|
||||
lv_obj_del(cont);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -92,15 +92,16 @@ lv_obj_t * lv_cont_create(lv_obj_t * par, const lv_obj_t * copy)
|
||||
ext->fit_bottom = LV_FIT_NONE;
|
||||
ext->layout = LV_LAYOUT_OFF;
|
||||
|
||||
lv_obj_set_signal_cb(new_cont, lv_cont_signal);
|
||||
lv_obj_set_signal_cb(cont, lv_cont_signal);
|
||||
|
||||
/*Init the new container*/
|
||||
if(copy == NULL) {
|
||||
/*Set the default styles if it's not screen*/
|
||||
if(par != NULL) {
|
||||
lv_obj_reset_style(new_cont, LV_CONT_PART_MAIN);
|
||||
lv_obj_add_style(new_cont, LV_CONT_PART_MAIN, _t(PANEL));
|
||||
lv_theme_apply(cont, LV_THEME_CONT);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
/*Copy an existing object*/
|
||||
else {
|
||||
@ -112,12 +113,12 @@ lv_obj_t * lv_cont_create(lv_obj_t * par, const lv_obj_t * copy)
|
||||
ext->layout = copy_ext->layout;
|
||||
|
||||
/*Refresh the style with new signal function*/
|
||||
lv_obj_refresh_style(new_cont);
|
||||
lv_obj_refresh_style(cont);
|
||||
}
|
||||
|
||||
LV_LOG_INFO("container created");
|
||||
|
||||
return new_cont;
|
||||
return cont;
|
||||
}
|
||||
|
||||
/*=====================
|
||||
|
@ -29,6 +29,8 @@
|
||||
#define LV_DDLIST_DEF_ANIM_TIME 0 /*No animation*/
|
||||
#endif
|
||||
|
||||
#define LV_DDLIST_PR_NONE 0xFFFF
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
@ -47,9 +49,15 @@ static lv_res_t lv_ddlist_signal(lv_obj_t * ddlist, lv_signal_t sign, void * par
|
||||
static lv_res_t lv_ddlist_page_signal(lv_obj_t * page, lv_signal_t sign, void * param);
|
||||
static lv_res_t lv_ddlist_page_scrl_signal(lv_obj_t * scrl, lv_signal_t sign, void * param);
|
||||
static lv_style_list_t * lv_ddlist_get_style(lv_obj_t * ddlist, uint8_t part);
|
||||
void draw_box(lv_obj_t * ddlist, const lv_area_t * clip_area, uint16_t id, lv_obj_state_t state);
|
||||
void draw_box_label(lv_obj_t * ddlist, const lv_area_t * clip_area, uint16_t id, lv_obj_state_t state);
|
||||
static lv_res_t page_release_handler(lv_obj_t * page);
|
||||
static void page_press_handler(lv_obj_t * page);
|
||||
static uint16_t get_id_on_point(lv_obj_t * ddlist, lv_coord_t x, lv_coord_t y);
|
||||
static void pos_selected(lv_obj_t * ddlist);
|
||||
static lv_obj_t * get_label(const lv_obj_t * ddlist);
|
||||
static void list_anim(void * p, lv_anim_value_t v);
|
||||
static void close_anim_ready(lv_anim_t * a);
|
||||
|
||||
/**********************
|
||||
* STATIC VARIABLES
|
||||
@ -103,9 +111,11 @@ lv_obj_t * lv_ddlist_create(lv_obj_t * par, const lv_obj_t * copy)
|
||||
ext->show_selected = 1;
|
||||
ext->sel_opt_id = 0;
|
||||
ext->sel_opt_id_orig = 0;
|
||||
ext->pr_opt_id = LV_DDLIST_PR_NONE;
|
||||
ext->option_cnt = 0;
|
||||
ext->dir = LV_DDLIST_DIR_LEFT;
|
||||
ext->max_height = LV_DPI * 2;
|
||||
ext->anim_time = LV_DDLIST_DEF_ANIM_TIME;
|
||||
lv_style_list_init(&ext->style_page);
|
||||
lv_style_list_init(&ext->style_scrlbar);
|
||||
lv_style_list_init(&ext->style_selected);
|
||||
@ -401,12 +411,16 @@ void lv_ddlist_open(lv_obj_t * ddlist, lv_anim_enable_t anim)
|
||||
lv_obj_t * label = lv_label_create(ext->page, NULL);
|
||||
lv_label_set_static_text(label, ext->options);
|
||||
|
||||
if(lv_obj_get_height(label) > ext->max_height) {
|
||||
lv_cont_set_fit2(ext->page, LV_FIT_TIGHT, LV_FIT_NONE);
|
||||
lv_obj_set_height(ext->page, ext->max_height);
|
||||
} else {
|
||||
lv_cont_set_fit(ext->page, LV_FIT_TIGHT);
|
||||
}
|
||||
lv_cont_set_fit2(ext->page, LV_FIT_TIGHT, LV_FIT_NONE);
|
||||
lv_coord_t label_h = lv_obj_get_height(label);
|
||||
lv_style_int_t top = lv_obj_get_style_int(ddlist, LV_DDLIST_PART_LIST, LV_STYLE_PAD_TOP);
|
||||
lv_style_int_t bottom = lv_obj_get_style_int(ddlist, LV_DDLIST_PART_LIST, LV_STYLE_PAD_BOTTOM);
|
||||
|
||||
lv_coord_t list_h = label_h + top + bottom;
|
||||
|
||||
if(list_h > ext->max_height) list_h = ext->max_height;
|
||||
|
||||
lv_obj_set_height(ext->page, list_h);
|
||||
|
||||
pos_selected(ddlist);
|
||||
|
||||
@ -431,6 +445,15 @@ void lv_ddlist_open(lv_obj_t * ddlist, lv_anim_enable_t anim)
|
||||
else if(dir == LV_DDLIST_DIR_LEFT) lv_obj_align(ext->page, ddlist, LV_ALIGN_OUT_LEFT_TOP, 0, 0);
|
||||
else if(dir == LV_DDLIST_DIR_RIGHT)lv_obj_align(ext->page, ddlist, LV_ALIGN_OUT_RIGHT_TOP, 0, 0);
|
||||
}
|
||||
|
||||
if(dir != LV_DDLIST_DIR_UP) {
|
||||
lv_anim_t a;
|
||||
lv_anim_init(&a);
|
||||
lv_anim_set_exec_cb(&a, ddlist, list_anim);
|
||||
lv_anim_set_values(&a, 0, list_h);
|
||||
lv_anim_set_time(&a, ext->anim_time, 0);
|
||||
lv_anim_create(&a);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -445,8 +468,25 @@ void lv_ddlist_close(lv_obj_t * ddlist, lv_anim_enable_t anim)
|
||||
#endif
|
||||
lv_ddlist_ext_t * ext = lv_obj_get_ext_attr(ddlist);
|
||||
if(ext->page == NULL) return;
|
||||
lv_obj_del(ext->page);
|
||||
ext->page = NULL;
|
||||
|
||||
ext->pr_opt_id = LV_DDLIST_PR_NONE;
|
||||
|
||||
if(ext->anim_time == 0 || anim == LV_ANIM_OFF) {
|
||||
lv_obj_del(ext->page);
|
||||
ext->page = NULL;
|
||||
} else {
|
||||
// if(dir != LV_DDLIST_DIR_UP) {
|
||||
lv_anim_t a;
|
||||
lv_anim_init(&a);
|
||||
lv_anim_set_exec_cb(&a, ddlist, list_anim);
|
||||
lv_anim_set_values(&a, lv_obj_get_height(ext->page), 0);
|
||||
lv_anim_set_time(&a, ext->anim_time, 0);
|
||||
lv_anim_set_ready_cb(&a, close_anim_ready);
|
||||
lv_anim_create(&a);
|
||||
|
||||
// }
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**********************
|
||||
@ -553,28 +593,17 @@ static lv_design_res_t lv_ddlist_page_design(lv_obj_t * page, const lv_area_t *
|
||||
lv_ddlist_page_ext_t * page_ext = lv_obj_get_ext_attr(page);
|
||||
lv_obj_t * ddlist = page_ext->ddlist;
|
||||
lv_ddlist_ext_t * ext = lv_obj_get_ext_attr(ddlist);
|
||||
if(!ext->show_selected) return LV_DESIGN_RES_OK;
|
||||
|
||||
/*Draw a rectangle under the selected item*/
|
||||
const lv_font_t * font = lv_obj_get_style_ptr(ddlist, LV_DDLIST_PART_LIST, LV_STYLE_FONT);
|
||||
lv_style_int_t line_space = lv_obj_get_style_int(ddlist, LV_DDLIST_PART_LIST, LV_STYLE_LINE_SPACE);
|
||||
lv_coord_t font_h = lv_font_get_line_height(font);
|
||||
/*Draw the boxes if the page is not being deleted*/
|
||||
if(ext->page) {
|
||||
if(ext->pr_opt_id != LV_DDLIST_PR_NONE) {
|
||||
draw_box(ddlist, clip_area, ext->pr_opt_id, LV_OBJ_STATE_PRESSED);
|
||||
}
|
||||
|
||||
/*Draw the selected*/
|
||||
lv_obj_t * label = get_label(ddlist);
|
||||
lv_area_t rect_area;
|
||||
rect_area.y1 = label->coords.y1;
|
||||
rect_area.y1 += ext->sel_opt_id * (font_h + line_space);
|
||||
rect_area.y1 -= line_space / 2;
|
||||
|
||||
rect_area.y2 = rect_area.y1 + font_h + line_space - 1;
|
||||
rect_area.x1 = page->coords.x1;
|
||||
rect_area.x2 = page->coords.x2;
|
||||
|
||||
lv_draw_rect_dsc_t sel_rect;
|
||||
lv_draw_rect_dsc_init(&sel_rect);
|
||||
lv_obj_init_draw_rect_dsc(ddlist, LV_DDLIST_PART_SELECTED, &sel_rect);
|
||||
lv_draw_rect(&rect_area, clip_area, &sel_rect);
|
||||
if(ext->show_selected) {
|
||||
draw_box(ddlist, clip_area, ext->sel_opt_id, LV_OBJ_STATE_NORMAL);
|
||||
}
|
||||
}
|
||||
}
|
||||
/*Post draw when the children are drawn*/
|
||||
else if(mode == LV_DESIGN_DRAW_POST) {
|
||||
@ -586,27 +615,15 @@ static lv_design_res_t lv_ddlist_page_design(lv_obj_t * page, const lv_area_t *
|
||||
lv_obj_t * ddlist = page_ext->ddlist;
|
||||
lv_ddlist_ext_t * ext = lv_obj_get_ext_attr(ddlist);
|
||||
|
||||
if(!ext->show_selected) return LV_DESIGN_RES_OK;
|
||||
/*Draw the box labels if the page is not being deleted*/
|
||||
if(ext->page) {
|
||||
if(ext->pr_opt_id != LV_DDLIST_PR_NONE) {
|
||||
draw_box_label(ddlist, clip_area, ext->pr_opt_id, LV_OBJ_STATE_PRESSED);
|
||||
}
|
||||
|
||||
lv_draw_label_dsc_t label_dsc;
|
||||
lv_draw_label_dsc_init(&label_dsc);
|
||||
lv_obj_init_draw_label_dsc(ddlist, LV_DDLIST_PART_SELECTED, &label_dsc);
|
||||
lv_coord_t font_h = lv_font_get_line_height(label_dsc.font);
|
||||
|
||||
lv_obj_t * label = get_label(ddlist);
|
||||
lv_area_t area_sel;
|
||||
area_sel.y1 = label->coords.y1;
|
||||
area_sel.y1 += ext->sel_opt_id * (font_h + label_dsc.line_space);
|
||||
area_sel.y1 -= label_dsc.line_space / 2;
|
||||
|
||||
area_sel.y2 = area_sel.y1 + font_h + label_dsc.line_space - 1;
|
||||
area_sel.x1 = page->coords.x1;
|
||||
area_sel.x2 = page->coords.x2;
|
||||
lv_area_t mask_sel;
|
||||
bool area_ok;
|
||||
area_ok = lv_area_intersect(&mask_sel, clip_area, &area_sel);
|
||||
if(area_ok) {
|
||||
lv_draw_label(&label->coords, &mask_sel, &label_dsc, lv_label_get_text(label), NULL);
|
||||
if(ext->show_selected) {
|
||||
draw_box_label(ddlist, clip_area, ext->sel_opt_id, LV_OBJ_STATE_NORMAL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -623,12 +640,6 @@ static lv_design_res_t lv_ddlist_page_design(lv_obj_t * page, const lv_area_t *
|
||||
static lv_res_t lv_ddlist_signal(lv_obj_t * ddlist, lv_signal_t sign, void * param)
|
||||
{
|
||||
lv_res_t res;
|
||||
if(sign == LV_SIGNAL_GET_STYLE) {
|
||||
lv_get_style_info_t * info = param;
|
||||
info->result = lv_ddlist_get_style(ddlist, info->part);
|
||||
if(info->result != NULL) return LV_RES_OK;
|
||||
return LV_RES_OK;
|
||||
}
|
||||
|
||||
/* Include the ancient signal function */
|
||||
res = ancestor_signal(ddlist, sign, param);
|
||||
@ -637,7 +648,22 @@ static lv_res_t lv_ddlist_signal(lv_obj_t * ddlist, lv_signal_t sign, void * par
|
||||
|
||||
lv_ddlist_ext_t * ext = lv_obj_get_ext_attr(ddlist);
|
||||
|
||||
if(sign == LV_SIGNAL_CLEANUP) {
|
||||
if(sign == LV_SIGNAL_GET_STYLE) {
|
||||
lv_get_style_info_t * info = param;
|
||||
info->result = lv_ddlist_get_style(ddlist, info->part);
|
||||
if(info->result != NULL) return LV_RES_OK;
|
||||
return LV_RES_OK;
|
||||
}
|
||||
else if(sign == LV_SIGNAL_GET_STATE_DSC) {
|
||||
lv_ddlist_ext_t * ext = lv_obj_get_ext_attr(ddlist);
|
||||
lv_get_state_info_t * info = param;
|
||||
if(info->part == LV_DDLIST_PART_LIST ||
|
||||
info->part == LV_DDLIST_PART_SCRLBAR ||
|
||||
info->part == LV_DDLIST_PART_SELECTED) {
|
||||
info->result = lv_obj_get_state_dsc(ext->page, LV_PAGE_PART_BG);
|
||||
}
|
||||
}
|
||||
else if(sign == LV_SIGNAL_CLEANUP) {
|
||||
lv_ddlist_close(ddlist, LV_ANIM_OFF);
|
||||
}
|
||||
else if(sign == LV_SIGNAL_FOCUS) {
|
||||
@ -655,9 +681,10 @@ static lv_res_t lv_ddlist_signal(lv_obj_t * ddlist, lv_signal_t sign, void * par
|
||||
lv_ddlist_close(ddlist, LV_ANIM_ON);
|
||||
}
|
||||
#endif
|
||||
} else if(sign == LV_SIGNAL_DEFOCUS || sign == LV_SIGNAL_LEAVE) {
|
||||
lv_ddlist_close(ddlist, LV_ANIM_ON);
|
||||
}
|
||||
else if(sign == LV_SIGNAL_RELEASED) {
|
||||
|
||||
if(lv_indev_is_dragging(lv_indev_get_act()) == false) {
|
||||
if(ext->page) {
|
||||
lv_ddlist_close(ddlist, LV_ANIM_ON);
|
||||
@ -673,8 +700,6 @@ static lv_res_t lv_ddlist_signal(lv_obj_t * ddlist, lv_signal_t sign, void * par
|
||||
ext->sel_opt_id = ext->sel_opt_id_orig;
|
||||
lv_obj_invalidate(ddlist);
|
||||
}
|
||||
} else if(sign == LV_SIGNAL_DEFOCUS) {
|
||||
lv_ddlist_close(ddlist, LV_ANIM_ON);
|
||||
}
|
||||
else if(sign == LV_SIGNAL_COORD_CHG) {
|
||||
if(ext->page) lv_ddlist_close(ddlist, LV_ANIM_OFF);
|
||||
@ -748,6 +773,8 @@ static lv_res_t lv_ddlist_page_signal(lv_obj_t * page, lv_signal_t sign, void *
|
||||
if(lv_indev_is_dragging(lv_indev_get_act()) == false) {
|
||||
page_release_handler(page);
|
||||
}
|
||||
} else if(sign == LV_SIGNAL_PRESSED) {
|
||||
page_press_handler(page);
|
||||
} else if(sign == LV_SIGNAL_CLEANUP) {
|
||||
lv_ddlist_ext_t * ext = lv_obj_get_ext_attr(ddlist);
|
||||
ext->page = NULL; /*The page is just being deleted*/
|
||||
@ -775,19 +802,26 @@ static lv_res_t lv_ddlist_page_scrl_signal(lv_obj_t * scrl, lv_signal_t sign, vo
|
||||
lv_obj_t * page = lv_obj_get_parent(scrl);
|
||||
lv_ddlist_page_ext_t * page_ext = lv_obj_get_ext_attr(page);
|
||||
lv_obj_t * ddlist = page_ext->ddlist;
|
||||
lv_ddlist_ext_t * ext = lv_obj_get_ext_attr(ddlist);
|
||||
|
||||
if(sign == LV_SIGNAL_RELEASED) {
|
||||
if(lv_indev_is_dragging(lv_indev_get_act()) == false) {
|
||||
page_release_handler(page);
|
||||
}
|
||||
} else if(sign == LV_SIGNAL_REFR_EXT_DRAW_PAD) {
|
||||
/* Make possible to draw on the full width of the background to redraw the selected rectangle
|
||||
* when the ddlist is scrolled in fix height mode.
|
||||
* (The scrollabel is scrolled the "select rectangle" is drawn on the bg too)*/
|
||||
lv_style_int_t left = lv_obj_get_style_int(ddlist, LV_DDLIST_PART_LIST, LV_STYLE_PAD_LEFT);
|
||||
lv_style_int_t right = lv_obj_get_style_int(ddlist, LV_DDLIST_PART_LIST, LV_STYLE_PAD_RIGHT);
|
||||
scrl->ext_draw_pad = LV_MATH_MAX(scrl->ext_draw_pad, LV_MATH_MAX(left, right));
|
||||
}
|
||||
} else if(sign == LV_SIGNAL_PRESSED) {
|
||||
page_press_handler(page);
|
||||
} else if(sign == LV_SIGNAL_DRAG_BEGIN) {
|
||||
ext->pr_opt_id = LV_DDLIST_PR_NONE;
|
||||
lv_obj_invalidate(page);
|
||||
}
|
||||
else if(sign == LV_SIGNAL_REFR_EXT_DRAW_PAD) {
|
||||
/* Make possible to draw on the full width of the background to redraw the selected rectangle
|
||||
* when the ddlist is scrolled in fix height mode.
|
||||
* (The scrollabel is scrolled the "select rectangle" is drawn on the bg too)*/
|
||||
lv_style_int_t left = lv_obj_get_style_int(ddlist, LV_DDLIST_PART_LIST, LV_STYLE_PAD_LEFT);
|
||||
lv_style_int_t right = lv_obj_get_style_int(ddlist, LV_DDLIST_PART_LIST, LV_STYLE_PAD_RIGHT);
|
||||
scrl->ext_draw_pad = LV_MATH_MAX(scrl->ext_draw_pad, LV_MATH_MAX(left, right));
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
@ -826,6 +860,75 @@ static lv_style_list_t * lv_ddlist_get_style(lv_obj_t * ddlist, uint8_t part)
|
||||
return style_dsc_p;
|
||||
}
|
||||
|
||||
void draw_box(lv_obj_t * ddlist, const lv_area_t * clip_area, uint16_t id, lv_obj_state_t state)
|
||||
{
|
||||
lv_ddlist_ext_t * ext = lv_obj_get_ext_attr(ddlist);
|
||||
lv_obj_t * page = ext->page;
|
||||
lv_obj_state_dsc_t state_orig = page->state_dsc;
|
||||
|
||||
page->state_dsc.act = LV_OBJ_STATE_NORMAL;
|
||||
page->state_dsc.act |= state;
|
||||
page->state_dsc.prev = page->state_dsc.act;
|
||||
|
||||
/*Draw a rectangle under the selected item*/
|
||||
const lv_font_t * font = lv_obj_get_style_ptr(ddlist, LV_DDLIST_PART_LIST, LV_STYLE_FONT);
|
||||
lv_style_int_t line_space = lv_obj_get_style_int(ddlist, LV_DDLIST_PART_LIST, LV_STYLE_LINE_SPACE);
|
||||
lv_coord_t font_h = lv_font_get_line_height(font);
|
||||
|
||||
/*Draw the selected*/
|
||||
lv_obj_t * label = get_label(ddlist);
|
||||
lv_area_t rect_area;
|
||||
rect_area.y1 = label->coords.y1;
|
||||
rect_area.y1 += id * (font_h + line_space);
|
||||
rect_area.y1 -= line_space / 2;
|
||||
|
||||
rect_area.y2 = rect_area.y1 + font_h + line_space - 1;
|
||||
rect_area.x1 = ext->page->coords.x1;
|
||||
rect_area.x2 = ext->page->coords.x2;
|
||||
|
||||
lv_draw_rect_dsc_t sel_rect;
|
||||
lv_draw_rect_dsc_init(&sel_rect);
|
||||
lv_obj_init_draw_rect_dsc(ddlist, LV_DDLIST_PART_SELECTED, &sel_rect);
|
||||
lv_draw_rect(&rect_area, clip_area, &sel_rect);
|
||||
|
||||
page->state_dsc = state_orig;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void draw_box_label(lv_obj_t * ddlist, const lv_area_t * clip_area, uint16_t id, lv_obj_state_t state)
|
||||
{
|
||||
lv_ddlist_ext_t * ext = lv_obj_get_ext_attr(ddlist);
|
||||
lv_obj_t * page = ext->page;
|
||||
lv_obj_state_dsc_t state_orig = page->state_dsc;
|
||||
|
||||
page->state_dsc.act = LV_OBJ_STATE_NORMAL;
|
||||
page->state_dsc.act |= state;
|
||||
page->state_dsc.prev = page->state_dsc.act;
|
||||
|
||||
lv_draw_label_dsc_t label_dsc;
|
||||
lv_draw_label_dsc_init(&label_dsc);
|
||||
lv_obj_init_draw_label_dsc(ddlist, LV_DDLIST_PART_SELECTED, &label_dsc);
|
||||
lv_coord_t font_h = lv_font_get_line_height(label_dsc.font);
|
||||
|
||||
lv_obj_t * label = get_label(ddlist);
|
||||
lv_area_t area_sel;
|
||||
area_sel.y1 = label->coords.y1;
|
||||
area_sel.y1 += id * (font_h + label_dsc.line_space);
|
||||
area_sel.y1 -= label_dsc.line_space / 2;
|
||||
|
||||
area_sel.y2 = area_sel.y1 + font_h + label_dsc.line_space - 1;
|
||||
area_sel.x1 = page->coords.x1;
|
||||
area_sel.x2 = page->coords.x2;
|
||||
lv_area_t mask_sel;
|
||||
bool area_ok;
|
||||
area_ok = lv_area_intersect(&mask_sel, clip_area, &area_sel);
|
||||
if(area_ok) {
|
||||
lv_draw_label(&label->coords, &mask_sel, &label_dsc, lv_label_get_text(label), NULL);
|
||||
}
|
||||
page->state_dsc = state_orig;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a drop down list is released to open it or set new option
|
||||
* @param page pointer to the drop down list's page
|
||||
@ -838,7 +941,6 @@ static lv_res_t page_release_handler(lv_obj_t * page)
|
||||
|
||||
lv_ddlist_ext_t * ext = lv_obj_get_ext_attr(ddlist);
|
||||
|
||||
|
||||
lv_indev_t * indev = lv_indev_get_act();
|
||||
#if LV_USE_GROUP
|
||||
/*Leave edit mode once a new item is selected*/
|
||||
@ -851,34 +953,11 @@ static lv_res_t page_release_handler(lv_obj_t * page)
|
||||
}
|
||||
#endif
|
||||
|
||||
lv_obj_t * label = get_label(ddlist);
|
||||
|
||||
|
||||
/*Search the clicked option (For KEYPAD and ENCODER the new value should be already set)*/
|
||||
if(lv_indev_get_type(indev) == LV_INDEV_TYPE_POINTER || lv_indev_get_type(indev) == LV_INDEV_TYPE_BUTTON) {
|
||||
lv_point_t p;
|
||||
lv_indev_get_point(indev, &p);
|
||||
p.y -= label->coords.y1;
|
||||
p.x -= label->coords.x1;
|
||||
uint16_t letter_i;
|
||||
letter_i = lv_label_get_letter_on(label, &p);
|
||||
|
||||
uint16_t new_opt = 0;
|
||||
const char * txt = lv_label_get_text(label);
|
||||
uint32_t i = 0;
|
||||
uint32_t i_prev = 0;
|
||||
|
||||
uint32_t letter_cnt = 0;
|
||||
uint32_t letter;
|
||||
for(letter_cnt = 0; letter_cnt < letter_i; letter_cnt++) {
|
||||
letter = lv_txt_encoded_next(txt, &i);
|
||||
/*Count he lines to reach the clicked letter. But ignore the last '\n' because it
|
||||
* still belongs to the clicked line*/
|
||||
if(letter == '\n' && i_prev != letter_i) new_opt++;
|
||||
i_prev = i;
|
||||
}
|
||||
|
||||
ext->sel_opt_id = new_opt;
|
||||
ext->sel_opt_id = get_id_on_point(ddlist, p.x, p.y);
|
||||
ext->sel_opt_id_orig = ext->sel_opt_id;
|
||||
}
|
||||
|
||||
@ -895,6 +974,49 @@ static lv_res_t page_release_handler(lv_obj_t * page)
|
||||
return LV_RES_OK;
|
||||
}
|
||||
|
||||
static void page_press_handler(lv_obj_t * page)
|
||||
{
|
||||
lv_ddlist_page_ext_t * page_ext = lv_obj_get_ext_attr(page);
|
||||
lv_obj_t * ddlist = page_ext->ddlist;
|
||||
|
||||
lv_ddlist_ext_t * ext = lv_obj_get_ext_attr(ddlist);
|
||||
|
||||
lv_indev_t * indev = lv_indev_get_act();
|
||||
if(indev && (lv_indev_get_type(indev) == LV_INDEV_TYPE_POINTER || lv_indev_get_type(indev) == LV_INDEV_TYPE_BUTTON)) {
|
||||
lv_point_t p;
|
||||
lv_indev_get_point(indev, &p);
|
||||
ext->pr_opt_id = get_id_on_point(ddlist, p.x, p.y);
|
||||
lv_obj_invalidate(page);
|
||||
}
|
||||
}
|
||||
|
||||
static uint16_t get_id_on_point(lv_obj_t * ddlist, lv_coord_t x, lv_coord_t y)
|
||||
{
|
||||
lv_obj_t * label = get_label(ddlist);
|
||||
x -= label->coords.x1;
|
||||
y -= label->coords.y1;
|
||||
uint16_t letter_i;
|
||||
|
||||
lv_point_t p = {x, y};
|
||||
letter_i = lv_label_get_letter_on(label, &p);
|
||||
uint16_t opt = 0;
|
||||
const char * txt = lv_label_get_text(label);
|
||||
uint32_t i = 0;
|
||||
uint32_t i_prev = 0;
|
||||
|
||||
uint32_t letter_cnt = 0;
|
||||
uint32_t letter;
|
||||
for(letter_cnt = 0; letter_cnt < letter_i; letter_cnt++) {
|
||||
letter = lv_txt_encoded_next(txt, &i);
|
||||
/*Count he lines to reach the clicked letter. But ignore the last '\n' because it
|
||||
* still belongs to the clicked line*/
|
||||
if(letter == '\n' && i_prev != letter_i) opt++;
|
||||
i_prev = i;
|
||||
}
|
||||
|
||||
return opt;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the position of list when it is closed to show the selected item
|
||||
* @param ddlist pointer to a drop down list
|
||||
@ -927,5 +1049,19 @@ static lv_obj_t * get_label(const lv_obj_t * ddlist)
|
||||
return lv_obj_get_child(lv_page_get_scrl(ext->page), NULL);
|
||||
}
|
||||
|
||||
static void list_anim(void * p, lv_anim_value_t v)
|
||||
{
|
||||
lv_obj_t * ddlist = p;
|
||||
lv_ddlist_ext_t * ext = lv_obj_get_ext_attr(ddlist);
|
||||
lv_obj_set_height(ext->page, v);
|
||||
}
|
||||
|
||||
static void close_anim_ready(lv_anim_t * a)
|
||||
{
|
||||
lv_obj_t * ddlist = a->var;
|
||||
lv_ddlist_ext_t * ext = lv_obj_get_ext_attr(ddlist);
|
||||
lv_obj_del(ext->page);
|
||||
ext->page = NULL;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -61,15 +61,17 @@ typedef struct
|
||||
lv_style_list_t style_scrlbar; /*Style of the scroll bar*/
|
||||
lv_coord_t max_height; /*Height of the ddlist when opened. (0: auto-size)*/
|
||||
uint16_t option_cnt; /*Number of options*/
|
||||
int16_t sel_opt_id; /*Index of the currently selected option*/
|
||||
int16_t sel_opt_id_orig; /*Store the original index on focus*/
|
||||
uint16_t sel_opt_id; /*Index of the currently selected option*/
|
||||
uint16_t sel_opt_id_orig; /*Store the original index on focus*/
|
||||
uint16_t pr_opt_id; /*Index of the currently pressed option*/
|
||||
uint16_t anim_time;
|
||||
lv_ddlist_dir_t dir :2;
|
||||
uint8_t show_selected :1;
|
||||
} lv_ddlist_ext_t;
|
||||
|
||||
enum {
|
||||
LV_DDLIST_PART_BTN,
|
||||
LV_DDLIST_PART_LIST,
|
||||
LV_DDLIST_PART_BTN = LV_BTN_PART_MAIN,
|
||||
LV_DDLIST_PART_LIST = _LV_BTN_PART_REAL_LAST,
|
||||
LV_DDLIST_PART_SCRLBAR,
|
||||
LV_DDLIST_PART_SELECTED,
|
||||
};
|
||||
|
@ -628,7 +628,6 @@ void lv_label_get_letter_pos(const lv_obj_t * label, uint16_t char_id, lv_point_
|
||||
|
||||
/*Calculate the x coordinate*/
|
||||
lv_coord_t x = lv_txt_get_width(bidi_txt, visual_byte_pos, font, letter_space, flag);
|
||||
|
||||
if(char_id != line_start) x += letter_space;
|
||||
|
||||
if(align == LV_LABEL_ALIGN_CENTER) {
|
||||
@ -709,7 +708,7 @@ uint16_t lv_label_get_letter_on(const lv_obj_t * label, lv_point_t * pos)
|
||||
#if LV_USE_BIDI
|
||||
bidi_txt = lv_mem_buf_get(new_line_start - line_start + 1);
|
||||
uint16_t txt_len = new_line_start - line_start;
|
||||
if(bidi_txt[new_line_start] == '\0' && txt_len > 0) txt_len--;
|
||||
if(new_line_start > 0 && txt[new_line_start - 1] == '\0' && txt_len > 0) txt_len--;
|
||||
lv_bidi_process_paragraph(txt + line_start, bidi_txt, txt_len, lv_obj_get_base_dir(label), NULL, 0);
|
||||
#else
|
||||
bidi_txt = (char*)txt + line_start;
|
||||
@ -753,7 +752,7 @@ uint16_t lv_label_get_letter_on(const lv_obj_t * label, lv_point_t * pos)
|
||||
x += lv_font_get_glyph_width(font, letter, letter_next);
|
||||
|
||||
/*Finish if the x position or the last char of the line is reached*/
|
||||
if(pos->x < x || i + line_start == new_line_start) {
|
||||
if(pos->x < x || i + line_start == new_line_start || txt[i + line_start] == '\0') {
|
||||
i = i_act;
|
||||
break;
|
||||
}
|
||||
@ -763,11 +762,11 @@ uint16_t lv_label_get_letter_on(const lv_obj_t * label, lv_point_t * pos)
|
||||
}
|
||||
|
||||
#if LV_USE_BIDI
|
||||
lv_mem_buf_release(bidi_txt);
|
||||
/*Handle Bidi*/
|
||||
bool is_rtl;
|
||||
logical_pos = lv_bidi_get_logical_pos(&txt[line_start], NULL, txt_len, lv_obj_get_base_dir(label), lv_txt_encoded_get_char_id(bidi_txt, i), &is_rtl);
|
||||
if (is_rtl) logical_pos++;
|
||||
lv_mem_buf_release(bidi_txt);
|
||||
#else
|
||||
logical_pos = lv_txt_encoded_get_char_id(bidi_txt, i);
|
||||
#endif
|
||||
|
@ -281,7 +281,7 @@ static lv_res_t lv_line_signal(lv_obj_t * line, lv_signal_t sign, void * param)
|
||||
|
||||
if(sign == LV_SIGNAL_REFR_EXT_DRAW_PAD) {
|
||||
/*The corner of the skew lines is out of the intended area*/
|
||||
lv_style_int_t * line_width = lv_obj_get_style_int(line, LV_LINE_PART_MAIN, LV_STYLE_LINE_WIDTH);
|
||||
lv_style_int_t line_width = lv_obj_get_style_int(line, LV_LINE_PART_MAIN, LV_STYLE_LINE_WIDTH);
|
||||
if(line->ext_draw_pad < line_width) line->ext_draw_pad = line_width;
|
||||
}
|
||||
|
||||
|
@ -738,10 +738,10 @@ static lv_res_t lv_page_signal(lv_obj_t * page, lv_signal_t sign, void * param)
|
||||
info->result = lv_page_get_style(page, info->part);
|
||||
if(info->result != NULL) return LV_RES_OK;
|
||||
else return ancestor_signal(page, sign, param);
|
||||
} else if(sign == LV_SIGNAL_GET_STATE) {
|
||||
} else if(sign == LV_SIGNAL_GET_STATE_DSC) {
|
||||
lv_get_state_info_t * info = param;
|
||||
if(info->part == LV_PAGE_PART_SCRL) info->result = lv_obj_get_state(lv_page_get_scrl(page), LV_CONT_PART_MAIN);
|
||||
else info->result = lv_obj_get_state(page, info->part);
|
||||
if(info->part == LV_PAGE_PART_SCRL) info->result = lv_obj_get_state_dsc(lv_page_get_scrl(page), LV_CONT_PART_MAIN);
|
||||
else info->result = lv_obj_get_state_dsc(page, info->part);
|
||||
return LV_RES_OK;
|
||||
}
|
||||
|
||||
|
@ -1362,11 +1362,15 @@ static lv_res_t lv_ta_signal(lv_obj_t * ta, lv_signal_t sign, void * param)
|
||||
info->result = lv_ta_get_style(ta, info->part);
|
||||
if(info->result != NULL) return LV_RES_OK;
|
||||
else return ancestor_signal(ta, sign, param);
|
||||
}else if(sign == LV_SIGNAL_GET_STATE) {
|
||||
}else if(sign == LV_SIGNAL_GET_STATE_DSC) {
|
||||
lv_ta_ext_t * ext = ta->ext_attr;
|
||||
lv_get_state_info_t * info = param;
|
||||
if(info->part == LV_TA_PART_PLACEHOLDER) {
|
||||
info->result = ext->placeholder ? lv_obj_get_state(ext->placeholder, LV_LABEL_PART_MAIN) : 0;
|
||||
if(ext->placeholder) {
|
||||
info->result = lv_obj_get_state_dsc(ext->placeholder, LV_LABEL_PART_MAIN);
|
||||
} else {
|
||||
info->result = NULL;
|
||||
}
|
||||
return LV_RES_OK;
|
||||
}
|
||||
else return ancestor_signal(ta, sign, param);
|
||||
|
@ -585,6 +585,14 @@ static lv_res_t lv_tabview_signal(lv_obj_t * tabview, lv_signal_t sign, void * p
|
||||
info->result = lv_tabview_get_style(tabview, info->part);
|
||||
if(info->result != NULL) return LV_RES_OK;
|
||||
else return ancestor_signal(tabview, sign, param);
|
||||
} else if(sign == LV_SIGNAL_GET_STATE_DSC) {
|
||||
lv_tabview_ext_t * ext = lv_obj_get_ext_attr(tabview);
|
||||
lv_get_state_info_t * info = param;
|
||||
if(info->part == LV_TABVIEW_PART_TAB_BG) info->result = lv_obj_get_state_dsc(ext->btns, LV_BTNM_PART_BG);
|
||||
else if(info->part == LV_TABVIEW_PART_TAB) info->result = lv_obj_get_state_dsc(ext->btns, LV_BTNM_PART_BTN);
|
||||
else if(info->part == LV_TABVIEW_PART_INDIC) info->result = lv_obj_get_state_dsc(ext->indic, LV_OBJ_PART_MAIN);
|
||||
else if(info->part == LV_TABVIEW_PART_BG_SCRL) info->result = lv_obj_get_state_dsc(ext->content, LV_PAGE_PART_SCRL);
|
||||
return LV_RES_OK;
|
||||
}
|
||||
|
||||
/* Include the ancient signal function */
|
||||
|
@ -38,7 +38,7 @@ typedef enum {
|
||||
LV_THEME_SCR,
|
||||
LV_THEME_OBJ,
|
||||
|
||||
LV_THEME_PANEL,
|
||||
LV_THEME_CONT,
|
||||
|
||||
LV_THEME_BTN,
|
||||
|
||||
|
@ -6,8 +6,10 @@
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
#include <stdint.h>
|
||||
#include "lv_theme.h"
|
||||
#include "../lv_objx/lv_img.h"
|
||||
#include "../lv_misc/lv_types.h"
|
||||
|
||||
#if LV_USE_THEME_ALIEN
|
||||
|
||||
@ -41,6 +43,7 @@ void lv_theme_alien_apply(lv_obj_t * obj, lv_theme_style_t name);
|
||||
|
||||
static lv_theme_t theme;
|
||||
|
||||
|
||||
static lv_style_t scr;
|
||||
static lv_style_t panel; /*General fancy background (e.g. to chart or ta)*/
|
||||
static lv_style_t btn;
|
||||
@ -116,6 +119,7 @@ static lv_style_t chart_series_bg, chart_series;
|
||||
* STATIC FUNCTIONS
|
||||
**********************/
|
||||
|
||||
|
||||
static void basic_init(void)
|
||||
{
|
||||
lv_style_init(&scr);
|
||||
|
Loading…
x
Reference in New Issue
Block a user