lv_group: group signals are added to releated object types

This commit is contained in:
Gabor
2017-07-20 12:26:34 +02:00
parent 8dba219f42
commit faf33212e7
14 changed files with 659 additions and 231 deletions

View File

@@ -47,6 +47,7 @@
/*lv_obj (base object) settings*/ /*lv_obj (base object) settings*/
#define LV_OBJ_FREE_NUM 1 /*Enable the free number attribute*/ #define LV_OBJ_FREE_NUM 1 /*Enable the free number attribute*/
#define LV_OBJ_FREE_P 1 /*Enable the free pointer attribute*/ #define LV_OBJ_FREE_P 1 /*Enable the free pointer attribute*/
#define LV_OBJ_GROUP 1 /*Enable object groups*/
/*Others*/ /*Others*/
#define LV_COLOR_TRANSP COLOR_LIME #define LV_COLOR_TRANSP COLOR_LIME
@@ -145,6 +146,9 @@
/*List (dependencies: lv_page, lv_btn, lv_label, lv_img)*/ /*List (dependencies: lv_page, lv_btn, lv_label, lv_img)*/
#define USE_LV_LIST 1 #define USE_LV_LIST 1
#if USE_LV_LIST != 0
#define LV_LIST_FOCUS_TIME 100 /*Animation time of focusing to the a list element [ms] (0: no animation) */
#endif
/*Drop down list (dependencies: lv_page, lv_label)*/ /*Drop down list (dependencies: lv_page, lv_label)*/
#define USE_LV_DDLIST 1 #define USE_LV_DDLIST 1

View File

@@ -50,6 +50,12 @@ void lv_group_add(lv_group_t * group, lv_obj_t * obj)
obj->group_p = group; obj->group_p = group;
lv_obj_t ** next = ll_ins_tail(&group->obj_ll); lv_obj_t ** next = ll_ins_tail(&group->obj_ll);
*next = obj; *next = obj;
/* If the head and the tail is equal then there is only one object in the linked list.
* In this case automatically activate it*/
if(ll_get_head(&group->obj_ll) == next) {
lv_group_activate_next(group);
}
} }
void lv_group_activate_obj(lv_group_t * group, lv_obj_t * obj) void lv_group_activate_obj(lv_group_t * group, lv_obj_t * obj)
@@ -107,6 +113,31 @@ lv_style_t * lv_group_activate_style(lv_group_t * group, lv_style_t * style)
return &group->style_tmp; return &group->style_tmp;
} }
void lv_group_inc_active(lv_group_t * group)
{
lv_obj_t * act = lv_group_get_active(group);
if(act == NULL) return;
act->signal_f(act, LV_SIGNAL_INCREASE, NULL);
}
void lv_group_dec_active(lv_group_t * group)
{
lv_obj_t * act = lv_group_get_active(group);
if(act == NULL) return;
act->signal_f(act, LV_SIGNAL_DECREASE, NULL);
}
void lv_group_sel_active(lv_group_t * group)
{
lv_obj_t * act = lv_group_get_active(group);
if(act == NULL) return;
act->signal_f(act, LV_SIGNAL_SELECT, NULL);
}
lv_obj_t * lv_group_get_active(lv_group_t * group) lv_obj_t * lv_group_get_active(lv_group_t * group)
{ {
if(group == NULL) return NULL; if(group == NULL) return NULL;
@@ -123,7 +154,8 @@ static void style_activate_def(lv_style_t * style)
{ {
style->bcolor = COLOR_ORANGE; style->bcolor = COLOR_ORANGE;
style->bopa = OPA_COVER; style->bopa = OPA_COVER;
style->bwidth = style->bwidth * 2; if(style->bwidth == 0 && style->empty == 0) style->bwidth = 2 * LV_DOWNSCALE; /*Add border to not transparent styles*/
else style->bwidth = style->bwidth * 2; /*Make the border thicker*/
style->mcolor = color_mix(style->mcolor, COLOR_ORANGE, OPA_80); style->mcolor = color_mix(style->mcolor, COLOR_ORANGE, OPA_80);
style->gcolor = color_mix(style->gcolor, COLOR_ORANGE, OPA_80); style->gcolor = color_mix(style->gcolor, COLOR_ORANGE, OPA_80);
} }

View File

@@ -72,7 +72,14 @@ typedef bool (* lv_design_f_t) (struct __LV_OBJ_T * obj, const area_t * mask_p,
typedef enum typedef enum
{ {
/*General signals*/
LV_SIGNAL_CLEANUP, LV_SIGNAL_CLEANUP,
LV_SIGNAL_CHILD_CHG,
LV_SIGNAL_CORD_CHG,
LV_SIGNAL_STYLE_CHG,
LV_SIGNAL_REFR_EXT_SIZE,
/*Display input related*/
LV_SIGNAL_PRESSED, LV_SIGNAL_PRESSED,
LV_SIGNAL_PRESSING, LV_SIGNAL_PRESSING,
LV_SIGNAL_PRESS_LOST, LV_SIGNAL_PRESS_LOST,
@@ -81,12 +88,13 @@ typedef enum
LV_SIGNAL_LONG_PRESS_REP, LV_SIGNAL_LONG_PRESS_REP,
LV_SIGNAL_DRAG_BEGIN, LV_SIGNAL_DRAG_BEGIN,
LV_SIGNAL_DRAG_END, LV_SIGNAL_DRAG_END,
LV_SIGNAL_CHILD_CHG,
LV_SIGNAL_CORD_CHG, /*Group related*/
LV_SIGNAL_STYLE_CHG,
LV_SIGNAL_REFR_EXT_SIZE,
LV_SIGNAL_ACTIVATE, LV_SIGNAL_ACTIVATE,
LV_SIGNAL_DEACTIVATE, LV_SIGNAL_DEACTIVATE,
LV_SIGNAL_INCREASE,
LV_SIGNAL_DECREASE,
LV_SIGNAL_SELECT,
}lv_signal_t; }lv_signal_t;
typedef bool (* lv_signal_f_t) (struct __LV_OBJ_T * obj, lv_signal_t sign, void * param); typedef bool (* lv_signal_f_t) (struct __LV_OBJ_T * obj, lv_signal_t sign, void * param);

View File

@@ -185,6 +185,22 @@ bool lv_btn_signal(lv_obj_t * btn, lv_signal_t sign, void * param)
if(ext->lpr_rep_action != NULL && state != LV_BTN_STATE_INA) { if(ext->lpr_rep_action != NULL && state != LV_BTN_STATE_INA) {
valid = ext->lpr_rep_action(btn, param); valid = ext->lpr_rep_action(btn, param);
} }
} else if(sign == LV_SIGNAL_INCREASE) {
if(lv_btn_get_tgl(btn) != false) {
lv_btn_set_state(btn, LV_BTN_STATE_TREL);
}
} else if(sign == LV_SIGNAL_DECREASE) {
if(lv_btn_get_tgl(btn) != false) {
lv_btn_set_state(btn, LV_BTN_STATE_REL);
}
} else if(sign == LV_SIGNAL_SELECT) {
if(lv_btn_get_tgl(btn) != false) {
lv_btn_state_t state = lv_btn_get_state(btn);
if(state == LV_BTN_STATE_REL) lv_btn_set_state(btn, LV_BTN_STATE_TREL);
else if(state == LV_BTN_STATE_PR) lv_btn_set_state(btn, LV_BTN_STATE_TPR);
else if(state == LV_BTN_STATE_TREL) lv_btn_set_state(btn, LV_BTN_STATE_REL);
else if(state == LV_BTN_STATE_TPR) lv_btn_set_state(btn, LV_BTN_STATE_PR);
}
} }
} }
@@ -321,6 +337,50 @@ bool lv_btn_get_tgl(lv_obj_t * btn)
return ext->tgl != 0 ? true : false; return ext->tgl != 0 ? true : false;
} }
/**
* Get the release action of a button
* @param btn pointer to a button object
* @return pointer to the release action function
*/
lv_action_t lv_btn_get_rel_action(lv_obj_t * btn)
{
lv_btn_ext_t * ext = lv_obj_get_ext(btn);
return ext->rel_action;
}
/**
* Get the press action of a button
* @param btn pointer to a button object
* @return pointer to the press action function
*/
lv_action_t lv_btn_get_pr_action(lv_obj_t * btn)
{
lv_btn_ext_t * ext = lv_obj_get_ext(btn);
return ext->pr_action;
}
/**
* Get the long press action of a button
* @param btn pointer to a button object
* @return pointer to the release action function
*/
lv_action_t lv_btn_get_lpr_action(lv_obj_t * btn)
{
lv_btn_ext_t * ext = lv_obj_get_ext(btn);
return ext->lpr_action;
}
/**
* Get the long press repeat action of a button
* @param btn pointer to a button object
* @return pointer to the long press repeat action function
*/
lv_action_t lv_btn_get_lpr_rep_action(lv_obj_t * btn)
{
lv_btn_ext_t * ext = lv_obj_get_ext(btn);
return ext->lpr_rep_action;
}
/** /**
* Get the style of a button in a given state * Get the style of a button in a given state
* @param btn pointer to a button object * @param btn pointer to a button object

View File

@@ -148,6 +148,32 @@ lv_btn_state_t lv_btn_get_state(lv_obj_t * btn);
*/ */
bool lv_btn_get_tgl(lv_obj_t * btn); bool lv_btn_get_tgl(lv_obj_t * btn);
/**
* Get the release action of a button
* @param btn pointer to a button object
* @return pointer to the release action function
*/
lv_action_t lv_btn_get_rel_action(lv_obj_t * btn);
/**
* Get the press action of a button
* @param btn pointer to a button object
* @return pointer to the press action function
*/
lv_action_t lv_btn_get_pr_action(lv_obj_t * btn);
/**
* Get the long press action of a button
* @param btn pointer to a button object
* @return pointer to the release action function
*/
lv_action_t lv_btn_get_lpr_action(lv_obj_t * btn);
/**
* Get the long press repeat action of a button
* @param btn pointer to a button object
* @return pointer to the long press repeat action function
*/
lv_action_t lv_btn_get_lpr_rep_action(lv_obj_t * btn);
/** /**
* Get the style of a button in a given state * Get the style of a button in a given state
* @param btn pointer to a button object * @param btn pointer to a button object

View File

@@ -29,6 +29,7 @@
static bool lv_btnm_design(lv_obj_t * btnm, const area_t * mask, lv_design_mode_t mode); static bool lv_btnm_design(lv_obj_t * btnm, const area_t * mask, lv_design_mode_t mode);
static uint8_t lv_btnm_get_width_unit(const char * btn_str); static uint8_t lv_btnm_get_width_unit(const char * btn_str);
static uint16_t lv_btnm_get_btn_from_point(lv_obj_t * btnm, point_t * p); static uint16_t lv_btnm_get_btn_from_point(lv_obj_t * btnm, point_t * p);
static uint16_t lv_btnm_get_btn_txt(lv_obj_t * btnm, uint16_t btn_id);
static void lv_btnm_create_btns(lv_obj_t * btnm, const char ** map); static void lv_btnm_create_btns(lv_obj_t * btnm, const char ** map);
/********************** /**********************
@@ -155,18 +156,8 @@ bool lv_btnm_signal(lv_obj_t * btnm, lv_signal_t sign, void * param)
} }
else if(sign == LV_SIGNAL_RELEASED || sign == LV_SIGNAL_LONG_PRESS_REP) { else if(sign == LV_SIGNAL_RELEASED || sign == LV_SIGNAL_LONG_PRESS_REP) {
if(ext->cb != NULL && ext->btn_pr != LV_BTNM_PR_NONE) { if(ext->cb != NULL && ext->btn_pr != LV_BTNM_PR_NONE) {
uint16_t txt_i = 0; uint16_t txt_i = lv_btnm_get_btn_txt(btnm, ext->btn_pr);
uint16_t btn_i = 0; if(txt_i != LV_BTNM_PR_NONE) ext->cb(btnm, txt_i);
/* Search the text of ext->btn_pr the buttons text in the map
* Skip "\n"-s*/
while(btn_i != ext->btn_pr) {
btn_i ++;
txt_i ++;
if(strcmp(ext->map_p[txt_i], "\n") == 0) txt_i ++;
}
ext->cb(btnm, txt_i);
} }
if(sign == LV_SIGNAL_RELEASED && ext->btn_pr != LV_BTNM_PR_NONE) { if(sign == LV_SIGNAL_RELEASED && ext->btn_pr != LV_BTNM_PR_NONE) {
@@ -181,11 +172,26 @@ bool lv_btnm_signal(lv_obj_t * btnm, lv_signal_t sign, void * param)
ext->btn_pr = LV_BTNM_PR_NONE; ext->btn_pr = LV_BTNM_PR_NONE;
} }
} } else if(sign == LV_SIGNAL_PRESS_LOST || sign == LV_SIGNAL_DEACTIVATE) {
else if(sign == LV_SIGNAL_PRESS_LOST) {
ext->btn_pr = LV_BTNM_PR_NONE; ext->btn_pr = LV_BTNM_PR_NONE;
lv_obj_inv(btnm); lv_obj_inv(btnm);
} else if(sign == LV_SIGNAL_ACTIVATE) {
ext->btn_pr = 0;
lv_obj_inv(btnm);
} else if(sign == LV_SIGNAL_INCREASE) {
if(ext->btn_pr == LV_BTNM_PR_NONE) ext->btn_pr = 0;
else ext->btn_pr++;
if(ext->btn_pr >= ext->btn_cnt - 1) ext->btn_pr = ext->btn_cnt - 1;
lv_obj_inv(btnm);
} else if(sign == LV_SIGNAL_DECREASE) {
if(ext->btn_pr == LV_BTNM_PR_NONE) ext->btn_pr = 0;
if(ext->btn_pr > 0) ext->btn_pr--;
lv_obj_inv(btnm);
} else if(sign == LV_SIGNAL_SELECT) {
if(ext->cb != NULL) {
uint16_t txt_i = lv_btnm_get_btn_txt(btnm, ext->btn_pr);
if(txt_i != LV_BTNM_PR_NONE) ext->cb(btnm, txt_i);
}
} }
} }
@@ -441,8 +447,6 @@ static bool lv_btnm_design(lv_obj_t * btnm, const area_t * mask, lv_design_mode_
txt_i ++; txt_i ++;
} }
} }
return true; return true;
} }
@@ -486,6 +490,12 @@ static uint8_t lv_btnm_get_width_unit(const char * btn_str)
return 1; return 1;
} }
/**
* Gives the button id of a button under a given point
* @param btnm pointer to a button matrix object
* @param p a point with absolute coordinates
* @return the id of the button or LV_BTNM_PR_NONE.
*/
static uint16_t lv_btnm_get_btn_from_point(lv_obj_t * btnm, point_t * p) static uint16_t lv_btnm_get_btn_from_point(lv_obj_t * btnm, point_t * p)
{ {
area_t btnm_cords; area_t btnm_cords;
@@ -510,5 +520,33 @@ static uint16_t lv_btnm_get_btn_from_point(lv_obj_t * btnm, point_t * p)
return i; return i;
} }
/**
* Get the text of a button
* @param btnm pointer to a button matrix object
* @param btn_id button id
* @return text id in ext->map_p or LV_BTNM_PR_NONE if 'btn_id' was invalid
*/
static uint16_t lv_btnm_get_btn_txt(lv_obj_t * btnm, uint16_t btn_id)
{
lv_btnm_ext_t * ext = lv_obj_get_ext(btnm);
if(btn_id > ext->btn_cnt) return LV_BTNM_PR_NONE;
uint16_t txt_i = 0;
uint16_t btn_i = 0;
/* Search the text of ext->btn_pr the buttons text in the map
* Skip "\n"-s*/
while(btn_i != btn_id) {
btn_i ++;
txt_i ++;
if(strcmp(ext->map_p[txt_i], "\n") == 0) txt_i ++;
}
if(btn_i == ext->btn_cnt) return LV_BTNM_PR_NONE;
return txt_i;
}
#endif #endif

View File

@@ -10,6 +10,7 @@
#if USE_LV_CB != 0 #if USE_LV_CB != 0
#include "lv_cb.h" #include "lv_cb.h"
#include "../lv_obj/lv_group.h"
/********************* /*********************
* DEFINES * DEFINES
@@ -23,11 +24,14 @@
* STATIC PROTOTYPES * STATIC PROTOTYPES
**********************/ **********************/
static bool lv_cb_design(lv_obj_t * cb, const area_t * mask, lv_design_mode_t mode); static bool lv_cb_design(lv_obj_t * cb, const area_t * mask, lv_design_mode_t mode);
static bool lv_bullet_design(lv_obj_t * bullet, const area_t * mask, lv_design_mode_t mode);
/********************** /**********************
* STATIC VARIABLES * STATIC VARIABLES
**********************/ **********************/
static lv_design_f_t ancestor_design_f; static lv_design_f_t ancestor_bg_design_f;
static lv_design_f_t ancestor_bullet_design_f;
/********************** /**********************
* MACROS * MACROS
**********************/ **********************/
@@ -57,7 +61,7 @@ lv_obj_t * lv_cb_create(lv_obj_t * par, lv_obj_t * copy)
ext->bullet = NULL; ext->bullet = NULL;
ext->label = NULL; ext->label = NULL;
if(ancestor_design_f == NULL) ancestor_design_f = lv_obj_get_design_f(new_cb); if(ancestor_bg_design_f == NULL) ancestor_bg_design_f = lv_obj_get_design_f(new_cb);
lv_obj_set_signal_f(new_cb, lv_cb_signal); lv_obj_set_signal_f(new_cb, lv_cb_signal);
lv_obj_set_design_f(new_cb, lv_cb_design); lv_obj_set_design_f(new_cb, lv_cb_design);
@@ -65,6 +69,7 @@ lv_obj_t * lv_cb_create(lv_obj_t * par, lv_obj_t * copy)
/*Init the new checkbox object*/ /*Init the new checkbox object*/
if(copy == NULL) { if(copy == NULL) {
ext->bullet = lv_btn_create(new_cb, NULL); ext->bullet = lv_btn_create(new_cb, NULL);
if(ancestor_bullet_design_f == NULL) ancestor_bullet_design_f = lv_obj_get_design_f(ext->bullet);
lv_btn_set_styles(new_cb, lv_style_get(LV_STYLE_TRANSP, NULL), lv_style_get(LV_STYLE_TRANSP, NULL), lv_btn_set_styles(new_cb, lv_style_get(LV_STYLE_TRANSP, NULL), lv_style_get(LV_STYLE_TRANSP, NULL),
lv_style_get(LV_STYLE_TRANSP, NULL), lv_style_get(LV_STYLE_TRANSP, NULL), lv_style_get(LV_STYLE_TRANSP, NULL), lv_style_get(LV_STYLE_TRANSP, NULL),
lv_style_get(LV_STYLE_TRANSP, NULL)); lv_style_get(LV_STYLE_TRANSP, NULL));
@@ -72,6 +77,7 @@ lv_obj_t * lv_cb_create(lv_obj_t * par, lv_obj_t * copy)
lv_cont_set_fit(new_cb, true, true); lv_cont_set_fit(new_cb, true, true);
lv_btn_set_tgl(new_cb, true); lv_btn_set_tgl(new_cb, true);
lv_obj_set_design_f(ext->bullet, lv_bullet_design);
lv_obj_set_click(ext->bullet, false); lv_obj_set_click(ext->bullet, false);
lv_btn_set_styles(ext->bullet, lv_style_get(LV_STYLE_PRETTY, NULL), lv_style_get(LV_STYLE_PRETTY_COLOR, NULL), lv_btn_set_styles(ext->bullet, lv_style_get(LV_STYLE_PRETTY, NULL), lv_style_get(LV_STYLE_PRETTY_COLOR, NULL),
lv_style_get(LV_STYLE_BTN_TREL, NULL), lv_style_get(LV_STYLE_BTN_TPR, NULL), lv_style_get(LV_STYLE_BTN_TREL, NULL), lv_style_get(LV_STYLE_BTN_TPR, NULL),
@@ -114,10 +120,12 @@ bool lv_cb_signal(lv_obj_t * cb, lv_signal_t sign, void * param)
if(valid != false) { if(valid != false) {
if(sign == LV_SIGNAL_STYLE_CHG) { if(sign == LV_SIGNAL_STYLE_CHG) {
lv_obj_set_size(ext->bullet, font_get_height(style->font), font_get_height(style->font)); lv_obj_set_size(ext->bullet, font_get_height(style->font), font_get_height(style->font));
} } else if(sign == LV_SIGNAL_PRESSED ||
if(sign == LV_SIGNAL_PRESSED ||
sign == LV_SIGNAL_RELEASED || sign == LV_SIGNAL_RELEASED ||
sign == LV_SIGNAL_PRESS_LOST) { sign == LV_SIGNAL_PRESS_LOST ||
sign == LV_SIGNAL_INCREASE ||
sign == LV_SIGNAL_DECREASE ||
sign == LV_SIGNAL_SELECT) {
lv_btn_set_state(lv_cb_get_bullet(cb), lv_btn_get_state(cb)); lv_btn_set_state(lv_cb_get_bullet(cb), lv_btn_get_state(cb));
} }
} }
@@ -186,19 +194,62 @@ static bool lv_cb_design(lv_obj_t * cb, const area_t * mask, lv_design_mode_t mo
{ {
if(mode == LV_DESIGN_COVER_CHK) { if(mode == LV_DESIGN_COVER_CHK) {
/*Return false if the object is not covers the mask_p area*/ /*Return false if the object is not covers the mask_p area*/
return ancestor_design_f(cb, mask, mode); return ancestor_bg_design_f(cb, mask, mode);
} else if(mode == LV_DESIGN_DRAW_MAIN || mode == LV_DESIGN_DRAW_POST) { } else if(mode == LV_DESIGN_DRAW_MAIN || mode == LV_DESIGN_DRAW_POST) {
lv_cb_ext_t * cb_ext = lv_obj_get_ext(cb); lv_cb_ext_t * cb_ext = lv_obj_get_ext(cb);
lv_btn_ext_t * bullet_ext = lv_obj_get_ext(cb_ext->bullet); lv_btn_ext_t * bullet_ext = lv_obj_get_ext(cb_ext->bullet);
/*Be sure he state of the bullet is the same as the parent button*/ /*Be sure the state of the bullet is the same as the parent button*/
bullet_ext->state = cb_ext->bg_btn.state; bullet_ext->state = cb_ext->bg_btn.state;
return ancestor_design_f(cb, mask, mode); return ancestor_bg_design_f(cb, mask, mode);
} else {
return ancestor_bg_design_f(cb, mask, mode);
} }
/*Draw the object*/ return true;
}
/**
* Handle the drawing related tasks of the check boxes
* @param bullet pointer to an object
* @param mask the object will be drawn only in this area
* @param mode LV_DESIGN_COVER_CHK: only check if the object fully covers the 'mask_p' area
* (return 'true' if yes)
* LV_DESIGN_DRAW: draw the object (always return 'true')
* LV_DESIGN_DRAW_POST: drawing after every children are drawn
* @param return true/false, depends on 'mode'
*/
static bool lv_bullet_design(lv_obj_t * bullet, const area_t * mask, lv_design_mode_t mode)
{
if(mode == LV_DESIGN_COVER_CHK) {
return ancestor_bullet_design_f(bullet, mask, mode);
} else if(mode == LV_DESIGN_DRAW_MAIN) {
#if LV_OBJ_GROUP != 0
/* If the check box is the active in a group and
* the background is not visible (transparent or empty)
* then activate the style of the bullet*/
lv_style_t * style_ori = lv_obj_get_style(bullet);
lv_obj_t * bg = lv_obj_get_parent(bullet);
lv_style_t * style_page = lv_obj_get_style(bg);
lv_group_t * g = lv_obj_get_group(bg);
if(style_page->empty != 0 || style_page->opa == OPA_TRANSP) { /*Background is visible?*/
if(lv_group_get_active(g) == bg) {
lv_style_t * style_mod;
style_mod = lv_group_activate_style(g, style_ori);
bullet->style_p = style_mod; /*Temporally change the style to the activated */
}
}
#endif
ancestor_bullet_design_f(bullet, mask, mode);
#if LV_OBJ_GROUP != 0
bullet->style_p = style_ori; /*Revert the style*/
#endif
} else if(mode == LV_DESIGN_DRAW_POST) {
ancestor_bullet_design_f(bullet, mask, mode);
}
return true; return true;
} }

View File

@@ -70,6 +70,7 @@ lv_obj_t * lv_ddlist_create(lv_obj_t * par, lv_obj_t * copy)
ext->opened = 0; ext->opened = 0;
ext->auto_size = 0; ext->auto_size = 0;
ext->sel_opt = 0; ext->sel_opt = 0;
ext->num_opt = 0;
ext->anim_time = LV_DDLIST_DEF_ANIM_TIME; ext->anim_time = LV_DDLIST_DEF_ANIM_TIME;
ext->style_sel = lv_style_get(LV_STYLE_PLAIN_COLOR, NULL); ext->style_sel = lv_style_get(LV_STYLE_PLAIN_COLOR, NULL);
@@ -83,7 +84,8 @@ lv_obj_t * lv_ddlist_create(lv_obj_t * par, lv_obj_t * copy)
if(copy == NULL) { if(copy == NULL) {
lv_obj_t * scrl = lv_page_get_scrl(new_ddlist); lv_obj_t * scrl = lv_page_get_scrl(new_ddlist);
lv_obj_set_drag(scrl, false); lv_obj_set_drag(scrl, false);
lv_obj_set_style(scrl, lv_style_get(LV_STYLE_TRANSP, NULL)); lv_obj_set_style(scrl, lv_style_get(LV_STYLE_TRANSP, NULL));;
lv_cont_set_fit(scrl, true, true);
ext->opt_label = lv_label_create(new_ddlist, NULL); ext->opt_label = lv_label_create(new_ddlist, NULL);
lv_cont_set_fit(new_ddlist, true, false); lv_cont_set_fit(new_ddlist, true, false);
@@ -129,20 +131,36 @@ bool lv_ddlist_signal(lv_obj_t * ddlist, lv_signal_t sign, void * param)
lv_ddlist_ext_t * ext = lv_obj_get_ext(ddlist); lv_ddlist_ext_t * ext = lv_obj_get_ext(ddlist);
lv_obj_set_style(ext->opt_label, lv_obj_get_style(ddlist)); lv_obj_set_style(ext->opt_label, lv_obj_get_style(ddlist));
lv_ddlist_refr_size(ddlist, 0); lv_ddlist_refr_size(ddlist, 0);
} } else if(sign == LV_SIGNAL_ACTIVATE) {
else if(sign == LV_SIGNAL_ACTIVATE) {
lv_ddlist_ext_t * ext = lv_obj_get_ext(ddlist); lv_ddlist_ext_t * ext = lv_obj_get_ext(ddlist);
if(ext->opened == false) { if(ext->opened == false) {
ext->opened = true; ext->opened = true;
lv_ddlist_refr_size(ddlist, true); lv_ddlist_refr_size(ddlist, true);
} }
} } else if(sign == LV_SIGNAL_DEACTIVATE) {
else if(sign == LV_SIGNAL_DEACTIVATE) {
lv_ddlist_ext_t * ext = lv_obj_get_ext(ddlist); lv_ddlist_ext_t * ext = lv_obj_get_ext(ddlist);
if(ext->opened != false) { if(ext->opened != false) {
ext->opened = false; ext->opened = false;
lv_ddlist_refr_size(ddlist, true); lv_ddlist_refr_size(ddlist, true);
} }
} else if(sign == LV_SIGNAL_INCREASE) {
lv_ddlist_ext_t * ext = lv_obj_get_ext(ddlist);
if(ext->sel_opt < ext->num_opt - 1) {
ext->sel_opt ++;
lv_obj_inv(ddlist);
if(ext->cb != NULL) {
ext->cb(ddlist, NULL);
}
}
} else if(sign == LV_SIGNAL_DECREASE) {
lv_ddlist_ext_t * ext = lv_obj_get_ext(ddlist);
if(ext->sel_opt > 0) {
ext->sel_opt --;
lv_obj_inv(ddlist);
if(ext->cb != NULL) {
ext->cb(ddlist, NULL);
}
}
} }
} }
@@ -172,6 +190,8 @@ void lv_ddlist_set_options(lv_obj_t * ddlist, const char ** options)
i++; i++;
} }
ext->num_opt = i;
lv_ddlist_refr_size(ddlist, 0); lv_ddlist_refr_size(ddlist, 0);
} }
@@ -183,6 +203,15 @@ void lv_ddlist_set_options(lv_obj_t * ddlist, const char ** options)
void lv_ddlist_set_options_str(lv_obj_t * ddlist, const char * options) void lv_ddlist_set_options_str(lv_obj_t * ddlist, const char * options)
{ {
lv_ddlist_ext_t * ext = lv_obj_get_ext(ddlist); lv_ddlist_ext_t * ext = lv_obj_get_ext(ddlist);
/*Count the '\n'-s to determine the number of options*/
ext->num_opt = 0;
uint16_t i;
for(i = 0; options[i] != '\0'; i++) {
if(options[i] == '\n') ext->num_opt++;
}
ext->num_opt++; /*Last option in the at row*/
lv_label_set_text(ext->opt_label, options); lv_label_set_text(ext->opt_label, options);
lv_ddlist_refr_size(ddlist, 0); lv_ddlist_refr_size(ddlist, 0);
} }
@@ -372,7 +401,7 @@ static bool lv_ddlist_design(lv_obj_t * ddlist, const area_t * mask, lv_design_m
rect_area.y1 -= style->line_space / 2; rect_area.y1 -= style->line_space / 2;
rect_area.y2 = rect_area.y1 + font_h + style->line_space; rect_area.y2 = rect_area.y1 + font_h + style->line_space;
rect_area.x1 = ext->opt_label->cords.x1 - style_page_scrl->hpad; rect_area.x1 = ext->opt_label->cords.x1 - style->hpad;
rect_area.x2 = rect_area.x1 + lv_obj_get_width(lv_page_get_scrl(ddlist)); rect_area.x2 = rect_area.x1 + lv_obj_get_width(lv_page_get_scrl(ddlist));
lv_draw_rect(&rect_area, mask, ext->style_sel); lv_draw_rect(&rect_area, mask, ext->style_sel);

View File

@@ -43,7 +43,8 @@ typedef struct
/*New data for this type */ /*New data for this type */
lv_obj_t * opt_label; /*Label for the options*/ lv_obj_t * opt_label; /*Label for the options*/
lv_style_t * style_sel; /*Style of the selected option*/ lv_style_t * style_sel; /*Style of the selected option*/
lv_action_t cb; /*Pointer to function to call when an option is slected*/ lv_action_t cb; /*Pointer to function to call when an option is selected*/
uint16_t num_opt; /*Number of options*/
uint16_t sel_opt; /*Index of the current option*/ uint16_t sel_opt; /*Index of the current option*/
uint16_t anim_time; /*Open/Close animation time [ms]*/ uint16_t anim_time; /*Open/Close animation time [ms]*/
uint8_t opened :1; /*1: The list is opened*/ uint8_t opened :1; /*1: The list is opened*/

View File

@@ -10,13 +10,17 @@
#if USE_LV_LIST != 0 #if USE_LV_LIST != 0
#include "lv_list.h" #include "lv_list.h"
#include <lvgl/lv_objx/lv_cont.h> #include "lvgl/lv_objx/lv_cont.h"
#include "misc/gfx/anim.h"
#include "misc/math/math_base.h" #include "misc/math/math_base.h"
/********************* /*********************
* DEFINES * DEFINES
*********************/ *********************/
#define LV_LIST_LAYOUT_DEF LV_CONT_LAYOUT_COL_M #define LV_LIST_LAYOUT_DEF LV_CONT_LAYOUT_COL_M
#ifndef LV_LIST_FOCUS_TIME
#define LV_LIST_FOCUS_TIME 100 /*Animation time of focusing to the a list element [ms] (0: no animation) */
#endif
/********************** /**********************
* TYPEDEFS * TYPEDEFS
@@ -111,7 +115,78 @@ bool lv_list_signal(lv_obj_t * list, lv_signal_t sign, void * param)
/* The object can be deleted so check its validity and then /* The object can be deleted so check its validity and then
* make the object specific signal handling */ * make the object specific signal handling */
if(valid != false) { if(valid != false) {
if(sign == LV_SIGNAL_ACTIVATE) {
/*Get the first button*/
lv_obj_t * btn = NULL;
lv_obj_t * btn_prev = NULL;
btn = lv_obj_get_child(lv_page_get_scrl(list), btn);
while(btn != NULL) {
btn_prev = btn;
btn = lv_obj_get_child(lv_page_get_scrl(list), btn);
}
if(btn_prev != NULL) {
lv_btn_set_state(btn_prev, LV_BTN_STATE_PR);
}
} else if(sign == LV_SIGNAL_DEACTIVATE) {
/*Get the 'pressed' button*/
lv_obj_t * btn = NULL;
btn = lv_obj_get_child(lv_page_get_scrl(list), btn);
while(btn != NULL) {
if(lv_btn_get_state(btn) == LV_BTN_STATE_PR) break;
btn = lv_obj_get_child(lv_page_get_scrl(list), btn);
}
if(btn != NULL) {
lv_btn_set_state(btn, LV_BTN_STATE_REL);
}
} else if(sign == LV_SIGNAL_INCREASE) {
/*Get the last pressed button*/
lv_obj_t * btn = NULL;
lv_obj_t * btn_prev = NULL;
btn = lv_obj_get_child(lv_page_get_scrl(list), btn);
while(btn != NULL) {
if(lv_btn_get_state(btn) == LV_BTN_STATE_PR) break;
btn_prev = btn;
btn = lv_obj_get_child(lv_page_get_scrl(list), btn);
}
if(btn_prev != NULL && btn != NULL) {
lv_btn_set_state(btn, LV_BTN_STATE_REL);
lv_btn_set_state(btn_prev, LV_BTN_STATE_PR);
lv_page_focus(list, btn_prev, LV_LIST_FOCUS_TIME);
}
} else if(sign == LV_SIGNAL_DECREASE) {
/*Get the last pressed button*/
lv_obj_t * btn = NULL;
btn = lv_obj_get_child(lv_page_get_scrl(list), btn);
while(btn != NULL) {
if(lv_btn_get_state(btn) == LV_BTN_STATE_PR) break;
btn = lv_obj_get_child(lv_page_get_scrl(list), btn);
}
if(btn != NULL) {
lv_obj_t * btn_prev = lv_obj_get_child(lv_page_get_scrl(list), btn);
if(btn_prev != NULL) {
lv_btn_set_state(btn, LV_BTN_STATE_REL);
lv_btn_set_state(btn_prev, LV_BTN_STATE_PR);
lv_page_focus(list, btn_prev, LV_LIST_FOCUS_TIME);
}
}
} else if(sign == LV_SIGNAL_SELECT) {
/*Get the 'pressed' button*/
lv_obj_t * btn = NULL;
btn = lv_obj_get_child(lv_page_get_scrl(list), btn);
while(btn != NULL) {
if(lv_btn_get_state(btn) == LV_BTN_STATE_PR) break;
btn = lv_obj_get_child(lv_page_get_scrl(list), btn);
}
if(btn != NULL) {
lv_action_t rel_action;
rel_action = lv_btn_get_rel_action(btn);
if(rel_action != NULL) rel_action(btn, NULL);
}
}
} }
return valid; return valid;
} }
@@ -180,19 +255,37 @@ void lv_list_up(lv_obj_t * list)
{ {
/*Search the first list element which 'y' coordinate is below the parent /*Search the first list element which 'y' coordinate is below the parent
* and position the list to show this element on the bottom*/ * and position the list to show this element on the bottom*/
lv_obj_t * h = lv_obj_get_parent(list); lv_obj_t * scrl = lv_page_get_scrl(list);
lv_obj_t * e; lv_obj_t * e;
lv_obj_t * e_prev = NULL; lv_obj_t * e_prev = NULL;
e = lv_obj_get_child(list, NULL); e = lv_obj_get_child(scrl, NULL);
while(e != NULL) { while(e != NULL) {
if(e->cords.y2 <= h->cords.y2) { if(e->cords.y2 <= list->cords.y2) {
if(e_prev != NULL) if(e_prev != NULL) {
lv_obj_set_y(list, lv_obj_get_height(h) - cord_t new_y = lv_obj_get_height(list) - (lv_obj_get_y(e_prev) + lv_obj_get_height(e_prev));
(lv_obj_get_y(e_prev) + lv_obj_get_height(e_prev))); #if LV_LIST_FOCUS_TIME == 0
lv_obj_set_y(scrl, new_y);
#else
anim_t a;
a.var = scrl;
a.start = lv_obj_get_y(scrl);
a.end = new_y;
a.fp = (anim_fp_t)lv_obj_set_y;
a.path = anim_get_path(ANIM_PATH_LIN);
a.end_cb = NULL;
a.act_time = 0;
a.time = LV_LIST_FOCUS_TIME;
a.playback = 0;
a.playback_pause = 0;
a.repeat = 0;
a.repeat_pause = 0;
anim_create(&a);
#endif
}
break; break;
} }
e_prev = e; e_prev = e;
e = lv_obj_get_child(list, e); e = lv_obj_get_child(scrl, e);
} }
} }
@@ -204,15 +297,33 @@ void lv_list_down(lv_obj_t * list)
{ {
/*Search the first list element which 'y' coordinate is above the parent /*Search the first list element which 'y' coordinate is above the parent
* and position the list to show this element on the top*/ * and position the list to show this element on the top*/
lv_obj_t * h = lv_obj_get_parent(list); lv_obj_t * scrl = lv_page_get_scrl(list);
lv_obj_t * e; lv_obj_t * e;
e = lv_obj_get_child(list, NULL); e = lv_obj_get_child(scrl, NULL);
while(e != NULL) { while(e != NULL) {
if(e->cords.y1 < h->cords.y1) { if(e->cords.y1 < list->cords.y1) {
lv_obj_set_y(list, -lv_obj_get_y(e)); cord_t new_y = -lv_obj_get_y(e);
#if LV_LIST_FOCUS_TIME == 0
lv_obj_set_y(scrl, new_y);
#else
anim_t a;
a.var = scrl;
a.start = lv_obj_get_y(scrl);
a.end = new_y;
a.fp = (anim_fp_t)lv_obj_set_y;
a.path = anim_get_path(ANIM_PATH_LIN);
a.end_cb = NULL;
a.act_time = 0;
a.time = LV_LIST_FOCUS_TIME;
a.playback = 0;
a.playback_pause = 0;
a.repeat = 0;
a.repeat_pause = 0;
anim_create(&a);
#endif
break; break;
} }
e = lv_obj_get_child(list, e); e = lv_obj_get_child(scrl, e);
} }
} }

View File

@@ -132,13 +132,11 @@ bool lv_mbox_signal(lv_obj_t * mbox, lv_signal_t sign, void * param)
area_get_height(param) != lv_obj_get_height(mbox)) { area_get_height(param) != lv_obj_get_height(mbox)) {
lv_mbox_realign(mbox); lv_mbox_realign(mbox);
} }
} } else if(sign == LV_SIGNAL_LONG_PRESS) {
else if(sign == LV_SIGNAL_LONG_PRESS) {
lv_mbox_start_auto_close(mbox, 0); lv_mbox_start_auto_close(mbox, 0);
lv_dispi_wait_release(param); lv_dispi_wait_release(param);
valid = false; valid = false;
} } else if(sign == LV_SIGNAL_STYLE_CHG) {
else if(sign == LV_SIGNAL_STYLE_CHG) {
/*Refresh all the buttons*/ /*Refresh all the buttons*/
if(ext->btnh != NULL) { if(ext->btnh != NULL) {
lv_obj_t * btn; lv_obj_t * btn;
@@ -150,6 +148,85 @@ bool lv_mbox_signal(lv_obj_t * mbox, lv_signal_t sign, void * param)
btn = lv_obj_get_child(ext->btnh, btn); btn = lv_obj_get_child(ext->btnh, btn);
} }
} }
} else if(sign == LV_SIGNAL_ACTIVATE) {
/*Get the first button*/
if(ext->btnh != NULL) {
lv_obj_t * btn = NULL;
lv_obj_t * btn_prev = NULL;
btn = lv_obj_get_child(ext->btnh, btn);
while(btn != NULL) {
btn_prev = btn;
btn = lv_obj_get_child(ext->btnh, btn);
}
if(btn_prev != NULL) {
lv_btn_set_state(btn_prev, LV_BTN_STATE_PR);
}
}
} else if(sign == LV_SIGNAL_DEACTIVATE) {
/*Get the 'pressed' button*/
if(ext->btnh != NULL) {
lv_obj_t * btn = NULL;
btn = lv_obj_get_child(ext->btnh, btn);
while(btn != NULL) {
if(lv_btn_get_state(btn) == LV_BTN_STATE_PR) break;
btn = lv_obj_get_child(ext->btnh, btn);
}
if(btn != NULL) {
lv_btn_set_state(btn, LV_BTN_STATE_REL);
}
}
} else if(sign == LV_SIGNAL_INCREASE) {
/*Get the last pressed button*/
if(ext->btnh != NULL) {
lv_obj_t * btn = NULL;
lv_obj_t * btn_prev = NULL;
btn = lv_obj_get_child(ext->btnh, btn);
while(btn != NULL) {
if(lv_btn_get_state(btn) == LV_BTN_STATE_PR) break;
btn_prev = btn;
btn = lv_obj_get_child(ext->btnh, btn);
}
if(btn_prev != NULL && btn != NULL) {
lv_btn_set_state(btn, LV_BTN_STATE_REL);
lv_btn_set_state(btn_prev, LV_BTN_STATE_PR);
}
}
} else if(sign == LV_SIGNAL_DECREASE) {
/*Get the last pressed button*/
if(ext->btnh != NULL) {
lv_obj_t * btn = NULL;
btn = lv_obj_get_child(ext->btnh, btn);
while(btn != NULL) {
if(lv_btn_get_state(btn) == LV_BTN_STATE_PR) break;
btn = lv_obj_get_child(ext->btnh, btn);
}
if(btn != NULL) {
lv_obj_t * btn_prev = lv_obj_get_child(ext->btnh, btn);
if(btn_prev != NULL) {
lv_btn_set_state(btn, LV_BTN_STATE_REL);
lv_btn_set_state(btn_prev, LV_BTN_STATE_PR);
}
}
}
} else if(sign == LV_SIGNAL_SELECT) {
/*Get the 'pressed' button*/
if(ext->btnh != NULL) {
lv_obj_t * btn = NULL;
btn = lv_obj_get_child(ext->btnh, btn);
while(btn != NULL) {
if(lv_btn_get_state(btn) == LV_BTN_STATE_PR) break;
btn = lv_obj_get_child(ext->btnh, btn);
}
if(btn != NULL) {
lv_action_t rel_action;
rel_action = lv_btn_get_rel_action(btn);
if(rel_action != NULL) rel_action(btn, NULL);
}
}
} }
} }

View File

@@ -86,7 +86,7 @@ lv_obj_t * lv_page_create(lv_obj_t * par, lv_obj_t * copy)
lv_obj_set_drag(ext->scrl, true); lv_obj_set_drag(ext->scrl, true);
lv_obj_set_drag_throw(ext->scrl, true); lv_obj_set_drag_throw(ext->scrl, true);
lv_obj_set_protect(ext->scrl, LV_PROTECT_PARENT); lv_obj_set_protect(ext->scrl, LV_PROTECT_PARENT);
lv_cont_set_fit(ext->scrl, true, true); lv_cont_set_fit(ext->scrl, false, true);
lv_obj_set_style(ext->scrl, lv_style_get(LV_STYLE_PRETTY, NULL)); lv_obj_set_style(ext->scrl, lv_style_get(LV_STYLE_PRETTY, NULL));
lv_obj_set_design_f(ext->scrl, lv_scrl_design); lv_obj_set_design_f(ext->scrl, lv_scrl_design);
@@ -143,8 +143,7 @@ bool lv_page_signal(lv_obj_t * page, lv_signal_t sign, void * param)
if(obj_valid != false) { if(obj_valid != false) {
lv_page_ext_t * ext = lv_obj_get_ext(page); lv_page_ext_t * ext = lv_obj_get_ext(page);
lv_obj_t * child; lv_obj_t * child;
switch(sign) { if(sign == LV_SIGNAL_CHILD_CHG) { /*Move children to the scrollable object*/
case LV_SIGNAL_CHILD_CHG: /*Move children to the scrollable object*/
child = lv_obj_get_child(page, NULL); child = lv_obj_get_child(page, NULL);
while(child != NULL) { while(child != NULL) {
if(lv_obj_is_protected(child, LV_PROTECT_PARENT) == false) { if(lv_obj_is_protected(child, LV_PROTECT_PARENT) == false) {
@@ -155,9 +154,12 @@ bool lv_page_signal(lv_obj_t * page, lv_signal_t sign, void * param)
child = lv_obj_get_child(page, child); child = lv_obj_get_child(page, child);
} }
} }
break; } else if(sign == LV_SIGNAL_STYLE_CHG) {
lv_style_t * style = lv_obj_get_style(page);
if(lv_cont_get_hfit(ext->scrl) == false) {
lv_obj_set_width(ext->scrl, lv_obj_get_width(page) - 2 * style->hpad);
}
case LV_SIGNAL_STYLE_CHG:
if(ext->sb_mode == LV_PAGE_SB_MODE_ON) { if(ext->sb_mode == LV_PAGE_SB_MODE_ON) {
ext->sbh_draw = 1; ext->sbh_draw = 1;
ext->sbv_draw = 1; ext->sbv_draw = 1;
@@ -167,36 +169,28 @@ bool lv_page_signal(lv_obj_t * page, lv_signal_t sign, void * param)
} }
lv_page_sb_refresh(page); lv_page_sb_refresh(page);
break; } else if(sign == LV_SIGNAL_CORD_CHG) {
case LV_SIGNAL_CORD_CHG:
/*Refresh the scrollbar and notify the scrl if the size is changed*/ /*Refresh the scrollbar and notify the scrl if the size is changed*/
if(ext->scrl != NULL && if(ext->scrl != NULL &&
(lv_obj_get_width(page) != area_get_width(param) || (lv_obj_get_width(page) != area_get_width(param) ||
lv_obj_get_height(page) != area_get_height(param))) { lv_obj_get_height(page) != area_get_height(param))) {
ext->scrl->signal_f(ext->scrl, LV_SIGNAL_CORD_CHG, &ext->scrl->cords); ext->scrl->signal_f(ext->scrl, LV_SIGNAL_CORD_CHG, &ext->scrl->cords);
/*The scrolbars are important olny if they are visible now*/ /*The scrollbars are important olny if they are visible now*/
if(ext->sbh_draw != 0 || ext->sbv_draw != 0) if(ext->sbh_draw != 0 || ext->sbv_draw != 0)
lv_page_sb_refresh(page); lv_page_sb_refresh(page);
} }
break; } else if(sign == LV_SIGNAL_PRESSED) {
case LV_SIGNAL_PRESSED:
if(ext->pr_action != NULL) { if(ext->pr_action != NULL) {
ext->pr_action(page, param); ext->pr_action(page, param);
} }
break; } else if(sign == LV_SIGNAL_RELEASED) {
case LV_SIGNAL_RELEASED:
if(lv_dispi_is_dragging(param) == false) { if(lv_dispi_is_dragging(param) == false) {
if(ext->rel_action != NULL) { if(ext->rel_action != NULL) {
ext->rel_action(page, param); ext->rel_action(page, param);
} }
} }
break;
default:
break;
} }
} }
@@ -220,56 +214,56 @@ static bool lv_scrl_signal(lv_obj_t * scrl, lv_signal_t sign, void* param)
* make the object specific signal handling */ * make the object specific signal handling */
if(obj_valid != false) { if(obj_valid != false) {
lv_obj_t * page = lv_obj_get_parent(scrl);
lv_style_t * page_style = lv_obj_get_style(page);
lv_page_ext_t * page_ext = lv_obj_get_ext(page);
if(sign == LV_SIGNAL_CORD_CHG) {
cord_t new_x; cord_t new_x;
cord_t new_y; cord_t new_y;
bool refr_x = false; bool refr_x = false;
bool refr_y = false; bool refr_y = false;
area_t page_cords; area_t page_cords;
area_t obj_cords; area_t scrl_cords;
lv_obj_t * page = lv_obj_get_parent(scrl);
lv_style_t * page_style = lv_obj_get_style(page);
lv_page_ext_t * page_ext = lv_obj_get_ext(page);
cord_t hpad = page_style->hpad; cord_t hpad = page_style->hpad;
cord_t vpad = page_style->vpad; cord_t vpad = page_style->vpad;
switch(sign) {
case LV_SIGNAL_CORD_CHG:
new_x = lv_obj_get_x(scrl); new_x = lv_obj_get_x(scrl);
new_y = lv_obj_get_y(scrl); new_y = lv_obj_get_y(scrl);
lv_obj_get_cords(scrl, &obj_cords); lv_obj_get_cords(scrl, &scrl_cords);
lv_obj_get_cords(page, &page_cords); lv_obj_get_cords(page, &page_cords);
/*scrollable width smaller then page width? -> align to left*/ /*scrollable width smaller then page width? -> align to left*/
if(area_get_width(&obj_cords) + 2 * hpad < area_get_width(&page_cords)) { if(area_get_width(&scrl_cords) + 2 * hpad < area_get_width(&page_cords)) {
if(obj_cords.x1 != page_cords.x1 + hpad) { if(scrl_cords.x1 != page_cords.x1 + hpad) {
new_x = hpad; new_x = hpad;
refr_x = true; refr_x = true;
} }
} else { } else {
/*The edges of the scrollable can not be in the page (minus hpad) */ /*The edges of the scrollable can not be in the page (minus hpad) */
if(obj_cords.x2 < page_cords.x2 - hpad) { if(scrl_cords.x2 < page_cords.x2 - hpad) {
new_x = area_get_width(&page_cords) - area_get_width(&obj_cords) - hpad; /* Right align */ new_x = area_get_width(&page_cords) - area_get_width(&scrl_cords) - hpad; /* Right align */
refr_x = true; refr_x = true;
} }
if (obj_cords.x1 > page_cords.x1 + hpad) { if (scrl_cords.x1 > page_cords.x1 + hpad) {
new_x = hpad; /*Left align*/ new_x = hpad; /*Left align*/
refr_x = true; refr_x = true;
} }
} }
/*scrollable height smaller then page height? -> align to left*/ /*scrollable height smaller then page height? -> align to left*/
if(area_get_height(&obj_cords) + 2 * vpad < area_get_height(&page_cords)) { if(area_get_height(&scrl_cords) + 2 * vpad < area_get_height(&page_cords)) {
if(obj_cords.y1 != page_cords.y1 + vpad) { if(scrl_cords.y1 != page_cords.y1 + vpad) {
new_y = vpad; new_y = vpad;
refr_y = true; refr_y = true;
} }
} else { } else {
/*The edges of the scrollable can not be in the page (minus vpad) */ /*The edges of the scrollable can not be in the page (minus vpad) */
if(obj_cords.y2 < page_cords.y2 - vpad) { if(scrl_cords.y2 < page_cords.y2 - vpad) {
new_y = area_get_height(&page_cords) - area_get_height(&obj_cords) - vpad; /* Bottom align */ new_y = area_get_height(&page_cords) - area_get_height(&scrl_cords) - vpad; /* Bottom align */
refr_y = true; refr_y = true;
} }
if (obj_cords.y1 > page_cords.y1 + vpad) { if (scrl_cords.y1 > page_cords.y1 + vpad) {
new_y = vpad; /*Top align*/ new_y = vpad; /*Top align*/
refr_y = true; refr_y = true;
} }
@@ -279,9 +273,11 @@ static bool lv_scrl_signal(lv_obj_t * scrl, lv_signal_t sign, void* param)
} }
lv_page_sb_refresh(page); lv_page_sb_refresh(page);
break; } else if(sign == LV_SIGNAL_CORD_CHG) {
if(lv_cont_get_hfit(scrl) == false) {
case LV_SIGNAL_DRAG_BEGIN: lv_obj_set_width(scrl, lv_obj_get_width(page) - 2 * page_style->hpad);
}
} else if(sign == LV_SIGNAL_DRAG_BEGIN) {
if(page_ext->sb_mode == LV_PAGE_SB_MODE_DRAG ) { if(page_ext->sb_mode == LV_PAGE_SB_MODE_DRAG ) {
cord_t sbh_pad = MATH_MAX(page_ext->sb_width, page_style->hpad); cord_t sbh_pad = MATH_MAX(page_ext->sb_width, page_style->hpad);
cord_t sbv_pad = MATH_MAX(page_ext->sb_width, page_style->vpad); cord_t sbv_pad = MATH_MAX(page_ext->sb_width, page_style->vpad);
@@ -292,9 +288,7 @@ static bool lv_scrl_signal(lv_obj_t * scrl, lv_signal_t sign, void* param)
page_ext->sbh_draw = 1; page_ext->sbh_draw = 1;
} }
} }
break; } else if(sign == LV_SIGNAL_DRAG_END) {
case LV_SIGNAL_DRAG_END:
if(page_ext->sb_mode == LV_PAGE_SB_MODE_DRAG) { if(page_ext->sb_mode == LV_PAGE_SB_MODE_DRAG) {
area_t sb_area_tmp; area_t sb_area_tmp;
if(page_ext->sbh_draw != 0) { if(page_ext->sbh_draw != 0) {
@@ -315,23 +309,17 @@ static bool lv_scrl_signal(lv_obj_t * scrl, lv_signal_t sign, void* param)
lv_inv_area(&sb_area_tmp); lv_inv_area(&sb_area_tmp);
page_ext->sbv_draw = 0; page_ext->sbv_draw = 0;
} }
} } else if(sign == LV_SIGNAL_PRESSED) {
break;
case LV_SIGNAL_PRESSED:
if(page_ext->pr_action != NULL) { if(page_ext->pr_action != NULL) {
page_ext->pr_action(page, param); page_ext->pr_action(page, param);
} }
break; } else if(sign == LV_SIGNAL_RELEASED) {
case LV_SIGNAL_RELEASED:
if(lv_dispi_is_dragging(param) == false) { if(lv_dispi_is_dragging(param) == false) {
if(page_ext->rel_action != NULL) { if(page_ext->rel_action != NULL) {
page_ext->rel_action(page, param); page_ext->rel_action(page, param);
} }
} }
break; }
default:
break;
} }
} }

View File

@@ -145,10 +145,15 @@ bool lv_slider_signal(lv_obj_t * slider, lv_signal_t sign, void * param)
lv_obj_get_height(slider) != area_get_height(param)) { lv_obj_get_height(slider) != area_get_height(param)) {
slider->signal_f(slider, LV_SIGNAL_REFR_EXT_SIZE, NULL); slider->signal_f(slider, LV_SIGNAL_REFR_EXT_SIZE, NULL);
} }
} } else if(sign == LV_SIGNAL_REFR_EXT_SIZE) {
else if(sign == LV_SIGNAL_REFR_EXT_SIZE) {
cord_t x = MATH_MIN(w, h); cord_t x = MATH_MIN(w, h);
if(slider->ext_size < x) slider->ext_size = x; if(slider->ext_size < x) slider->ext_size = x;
} else if(sign == LV_SIGNAL_INCREASE) {
lv_bar_set_value(slider, lv_bar_get_value(slider) + 1);
if(ext->cb != NULL) ext->cb(slider, NULL);
} else if(sign == LV_SIGNAL_DECREASE) {
lv_bar_set_value(slider, lv_bar_get_value(slider) - 1);
if(ext->cb != NULL) ext->cb(slider, NULL);
} }
} }

View File

@@ -158,32 +158,30 @@ bool lv_ta_signal(lv_obj_t * ta, lv_signal_t sign, void * param)
if(valid != false) { if(valid != false) {
lv_ta_ext_t * ext = lv_obj_get_ext(ta); lv_ta_ext_t * ext = lv_obj_get_ext(ta);
lv_style_t * style = lv_obj_get_style(ta); lv_style_t * style = lv_obj_get_style(ta);
switch(sign) { if(sign == LV_SIGNAL_CLEANUP) {
case LV_SIGNAL_CLEANUP:
/* Nothing to clean up. /* Nothing to clean up.
* (The created label will be deleted automatically) */ * (The created label will be deleted automatically) */
break; } else if(sign == LV_SIGNAL_STYLE_CHG) {
case LV_SIGNAL_STYLE_CHG:
if(ext->label) { if(ext->label) {
lv_obj_set_style(ext->label, lv_obj_get_style(ext->page.scrl)); lv_obj_set_style(ext->label, lv_obj_get_style(ext->page.scrl));
lv_obj_set_width(ext->label, lv_obj_get_width(ta) - 2 * lv_obj_set_width(ext->label, lv_obj_get_width(ta) - 2 *
(style->hpad + style->hpad)); (style->hpad + style->hpad));
lv_label_set_text(ext->label, NULL); lv_label_set_text(ext->label, NULL);
} }
break; } else if(sign == LV_SIGNAL_CORD_CHG) {
/*Set the label width according to the text area width*/ /*Set the label width according to the text area width*/
case LV_SIGNAL_CORD_CHG:
if(ext->label != NULL) { if(ext->label != NULL) {
lv_obj_set_width(ext->label, lv_obj_get_width(ta) - 2 * lv_obj_set_width(ext->label, lv_obj_get_width(ta) - 2 *
(style->hpad + style->hpad)); (style->hpad + style->hpad));
lv_label_set_text(ext->label, NULL); lv_label_set_text(ext->label, NULL);
} }
break; } else if(sign == LV_SIGNAL_INCREASE) {
default: lv_ta_set_cursor_pos(ta, lv_ta_get_cursor_pos(ta) + 1);
break; } else if(sign == LV_SIGNAL_DECREASE) {
uint16_t cur_pos = lv_ta_get_cursor_pos(ta);
if(cur_pos > 0) lv_ta_set_cursor_pos(ta, cur_pos - 1);
} }
} }
return valid; return valid;
} }