lv_group: works with obj. copy + bug fixes

This commit is contained in:
Gabor
2017-07-20 13:29:22 +02:00
parent faf33212e7
commit 455676e982
5 changed files with 135 additions and 37 deletions

View File

@@ -40,6 +40,9 @@ void lv_group_activate_next(lv_group_t * group);
void lv_group_activate_prev(lv_group_t * group); void lv_group_activate_prev(lv_group_t * group);
lv_style_t * lv_group_activate_style(lv_group_t * group, lv_style_t * style); lv_style_t * lv_group_activate_style(lv_group_t * group, lv_style_t * style);
lv_obj_t * lv_group_get_active(lv_group_t * group); lv_obj_t * lv_group_get_active(lv_group_t * group);
void lv_group_inc_active(lv_group_t * group);
void lv_group_dec_active(lv_group_t * group);
void lv_group_sel_active(lv_group_t * group);
/********************** /**********************
* MACROS * MACROS

View File

@@ -15,6 +15,7 @@
#include "lvgl/lv_obj/lv_group.h" #include "lvgl/lv_obj/lv_group.h"
#include "lvgl/lv_app/lv_app.h" #include "lvgl/lv_app/lv_app.h"
#include "lvgl/lv_draw/lv_draw_rbasic.h" #include "lvgl/lv_draw/lv_draw_rbasic.h"
#include "lv_group.h"
#include "misc/gfx/anim.h" #include "misc/gfx/anim.h"
#include "hal/indev/indev.h" #include "hal/indev/indev.h"
#include <stdint.h> #include <stdint.h>
@@ -142,10 +143,14 @@ lv_obj_t * lv_obj_create(lv_obj_t * parent, lv_obj_t * copy)
#if LV_OBJ_FREE_NUM != 0 #if LV_OBJ_FREE_NUM != 0
new_obj->free_num = 0; new_obj->free_num = 0;
#endif #endif
#if LV_OBJ_FREE_P != 0 #if LV_OBJ_FREE_P != 0
new_obj->free_p = NULL; new_obj->free_p = NULL;
#endif #endif
#if LV_OBJ_GROUP != 0
new_obj->group_p = NULL;
#endif
/*Set attributes*/ /*Set attributes*/
new_obj->click_en = 0; new_obj->click_en = 0;
new_obj->drag_en = 0; new_obj->drag_en = 0;
@@ -188,6 +193,9 @@ lv_obj_t * lv_obj_create(lv_obj_t * parent, lv_obj_t * copy)
#if LV_OBJ_FREE_P != 0 #if LV_OBJ_FREE_P != 0
new_obj->free_p = NULL; new_obj->free_p = NULL;
#endif #endif
#if LV_OBJ_GROUP != 0
new_obj->group_p = NULL;
#endif
/*Set attributes*/ /*Set attributes*/
new_obj->click_en = 1; new_obj->click_en = 1;
@@ -199,7 +207,6 @@ lv_obj_t * lv_obj_create(lv_obj_t * parent, lv_obj_t * copy)
new_obj->protect = LV_PROTECT_NONE; new_obj->protect = LV_PROTECT_NONE;
new_obj->ext = NULL; new_obj->ext = NULL;
} }
if(copy != NULL) { if(copy != NULL) {
@@ -224,6 +231,13 @@ lv_obj_t * lv_obj_create(lv_obj_t * parent, lv_obj_t * copy)
new_obj->style_p = copy->style_p; new_obj->style_p = copy->style_p;
#if LV_OBJ_GROUP != 0
/*Add to the same group*/
if(copy->group_p != NULL) {
lv_group_add(copy->group_p, new_obj);
}
#endif
lv_obj_set_pos(new_obj, lv_obj_get_x(copy), lv_obj_get_y(copy)); lv_obj_set_pos(new_obj, lv_obj_get_x(copy), lv_obj_get_y(copy));
} }

View File

@@ -33,6 +33,8 @@
static bool lv_list_design(lv_obj_t * list, const area_t * mask, lv_design_mode_t mode); static bool lv_list_design(lv_obj_t * list, const area_t * mask, lv_design_mode_t mode);
#endif #endif
static lv_obj_t * lv_list_get_next_btn(lv_obj_t * list, lv_obj_t * prev_btn);
/********************** /**********************
* STATIC VARIABLES * STATIC VARIABLES
**********************/ **********************/
@@ -119,10 +121,10 @@ bool lv_list_signal(lv_obj_t * list, lv_signal_t sign, void * param)
/*Get the first button*/ /*Get the first button*/
lv_obj_t * btn = NULL; lv_obj_t * btn = NULL;
lv_obj_t * btn_prev = NULL; lv_obj_t * btn_prev = NULL;
btn = lv_obj_get_child(lv_page_get_scrl(list), btn); btn = lv_list_get_next_btn(list, btn);
while(btn != NULL) { while(btn != NULL) {
btn_prev = btn; btn_prev = btn;
btn = lv_obj_get_child(lv_page_get_scrl(list), btn); btn = lv_list_get_next_btn(list, btn);
} }
if(btn_prev != NULL) { if(btn_prev != NULL) {
lv_btn_set_state(btn_prev, LV_BTN_STATE_PR); lv_btn_set_state(btn_prev, LV_BTN_STATE_PR);
@@ -130,10 +132,10 @@ bool lv_list_signal(lv_obj_t * list, lv_signal_t sign, void * param)
} else if(sign == LV_SIGNAL_DEACTIVATE) { } else if(sign == LV_SIGNAL_DEACTIVATE) {
/*Get the 'pressed' button*/ /*Get the 'pressed' button*/
lv_obj_t * btn = NULL; lv_obj_t * btn = NULL;
btn = lv_obj_get_child(lv_page_get_scrl(list), btn); btn = lv_list_get_next_btn(list, btn);
while(btn != NULL) { while(btn != NULL) {
if(lv_btn_get_state(btn) == LV_BTN_STATE_PR) break; if(lv_btn_get_state(btn) == LV_BTN_STATE_PR) break;
btn = lv_obj_get_child(lv_page_get_scrl(list), btn); btn = lv_list_get_next_btn(list, btn);
} }
if(btn != NULL) { if(btn != NULL) {
@@ -143,11 +145,11 @@ bool lv_list_signal(lv_obj_t * list, lv_signal_t sign, void * param)
/*Get the last pressed button*/ /*Get the last pressed button*/
lv_obj_t * btn = NULL; lv_obj_t * btn = NULL;
lv_obj_t * btn_prev = NULL; lv_obj_t * btn_prev = NULL;
btn = lv_obj_get_child(lv_page_get_scrl(list), btn); btn = lv_list_get_next_btn(list, btn);
while(btn != NULL) { while(btn != NULL) {
if(lv_btn_get_state(btn) == LV_BTN_STATE_PR) break; if(lv_btn_get_state(btn) == LV_BTN_STATE_PR) break;
btn_prev = btn; btn_prev = btn;
btn = lv_obj_get_child(lv_page_get_scrl(list), btn); btn = lv_list_get_next_btn(list, btn);
} }
if(btn_prev != NULL && btn != NULL) { if(btn_prev != NULL && btn != NULL) {
@@ -158,14 +160,14 @@ bool lv_list_signal(lv_obj_t * list, lv_signal_t sign, void * param)
} else if(sign == LV_SIGNAL_DECREASE) { } else if(sign == LV_SIGNAL_DECREASE) {
/*Get the last pressed button*/ /*Get the last pressed button*/
lv_obj_t * btn = NULL; lv_obj_t * btn = NULL;
btn = lv_obj_get_child(lv_page_get_scrl(list), btn); btn = lv_list_get_next_btn(list, btn);
while(btn != NULL) { while(btn != NULL) {
if(lv_btn_get_state(btn) == LV_BTN_STATE_PR) break; if(lv_btn_get_state(btn) == LV_BTN_STATE_PR) break;
btn = lv_obj_get_child(lv_page_get_scrl(list), btn); btn = lv_list_get_next_btn(list, btn);
} }
if(btn != NULL) { if(btn != NULL) {
lv_obj_t * btn_prev = lv_obj_get_child(lv_page_get_scrl(list), btn); lv_obj_t * btn_prev = lv_list_get_next_btn(list, btn);
if(btn_prev != NULL) { if(btn_prev != NULL) {
lv_btn_set_state(btn, LV_BTN_STATE_REL); lv_btn_set_state(btn, LV_BTN_STATE_REL);
lv_btn_set_state(btn_prev, LV_BTN_STATE_PR); lv_btn_set_state(btn_prev, LV_BTN_STATE_PR);
@@ -175,10 +177,10 @@ bool lv_list_signal(lv_obj_t * list, lv_signal_t sign, void * param)
} else if(sign == LV_SIGNAL_SELECT) { } else if(sign == LV_SIGNAL_SELECT) {
/*Get the 'pressed' button*/ /*Get the 'pressed' button*/
lv_obj_t * btn = NULL; lv_obj_t * btn = NULL;
btn = lv_obj_get_child(lv_page_get_scrl(list), btn); btn = lv_list_get_next_btn(list, btn);
while(btn != NULL) { while(btn != NULL) {
if(lv_btn_get_state(btn) == LV_BTN_STATE_PR) break; if(lv_btn_get_state(btn) == LV_BTN_STATE_PR) break;
btn = lv_obj_get_child(lv_page_get_scrl(list), btn); btn = lv_list_get_next_btn(list, btn);
} }
if(btn != NULL) { if(btn != NULL) {
@@ -258,7 +260,7 @@ void lv_list_up(lv_obj_t * list)
lv_obj_t * scrl = lv_page_get_scrl(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(scrl, NULL); e = lv_list_get_next_btn(list, NULL);
while(e != NULL) { while(e != NULL) {
if(e->cords.y2 <= list->cords.y2) { if(e->cords.y2 <= list->cords.y2) {
if(e_prev != NULL) { if(e_prev != NULL) {
@@ -285,7 +287,7 @@ void lv_list_up(lv_obj_t * list)
break; break;
} }
e_prev = e; e_prev = e;
e = lv_obj_get_child(scrl, e); e = lv_list_get_next_btn(list, e);
} }
} }
@@ -299,7 +301,7 @@ void lv_list_down(lv_obj_t * list)
* 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 * scrl = lv_page_get_scrl(list); lv_obj_t * scrl = lv_page_get_scrl(list);
lv_obj_t * e; lv_obj_t * e;
e = lv_obj_get_child(scrl, NULL); e = lv_list_get_next_btn(list, NULL);
while(e != NULL) { while(e != NULL) {
if(e->cords.y1 < list->cords.y1) { if(e->cords.y1 < list->cords.y1) {
cord_t new_y = -lv_obj_get_y(e); cord_t new_y = -lv_obj_get_y(e);
@@ -323,7 +325,7 @@ void lv_list_down(lv_obj_t * list)
#endif #endif
break; break;
} }
e = lv_obj_get_child(scrl, e); e = lv_list_get_next_btn(list, e);
} }
} }
@@ -351,8 +353,9 @@ void lv_list_set_sb_out(lv_obj_t * list, bool out)
*/ */
void lv_list_set_element_text_roll(lv_obj_t * liste, bool en) void lv_list_set_element_text_roll(lv_obj_t * liste, bool en)
{ {
/*The last child is the label*/ lv_obj_t * label = lv_list_get_element_label(liste);
lv_obj_t * label = lv_obj_get_child(liste, NULL); if(label == NULL) return;
if(en == false) { if(en == false) {
lv_label_set_long_mode(label, LV_LABEL_LONG_DOTS); lv_label_set_long_mode(label, LV_LABEL_LONG_DOTS);
} else { } else {
@@ -384,12 +387,11 @@ void lv_list_set_styles_btn(lv_obj_t * list, lv_style_t * rel, lv_style_t * pr,
ext->styles_btn[LV_BTN_STATE_TPR] = tpr; ext->styles_btn[LV_BTN_STATE_TPR] = tpr;
ext->styles_btn[LV_BTN_STATE_INA] = ina; ext->styles_btn[LV_BTN_STATE_INA] = ina;
lv_obj_t * scrl = lv_page_get_scrl(list); lv_obj_t * liste = lv_list_get_next_btn(list, NULL);
lv_obj_t * liste = lv_obj_get_child(scrl, NULL);
while(liste != NULL) while(liste != NULL)
{ {
lv_btn_set_styles(liste, rel, pr, trel, tpr, ina); lv_btn_set_styles(liste, rel, pr, trel, tpr, ina);
liste = lv_obj_get_child(scrl, liste); liste = lv_list_get_next_btn(list, liste);
} }
} }
@@ -405,16 +407,14 @@ void lv_list_set_style_img(lv_obj_t * list, lv_style_t * style)
ext->style_img = style; ext->style_img = style;
lv_obj_t * scrl = lv_page_get_scrl(list); lv_obj_t * liste = lv_list_get_next_btn(list, NULL);
lv_obj_t * liste = lv_obj_get_child(scrl, NULL);
lv_obj_t * img; lv_obj_t * img;
while(liste != NULL) while(liste != NULL)
{ {
img = lv_obj_get_child(liste, NULL); /*Now img = the label*/ img = lv_list_get_element_img(liste);
img = lv_obj_get_child(liste, img); /*Now img = the image (if ULL then no image) */
if(img != NULL) lv_obj_set_style(img, style); if(img != NULL) lv_obj_set_style(img, style);
liste = lv_obj_get_child(scrl, liste); liste = lv_list_get_next_btn(list, liste);
} }
} }
@@ -429,11 +429,47 @@ void lv_list_set_style_img(lv_obj_t * list, lv_style_t * style)
*/ */
const char * lv_list_get_element_text(lv_obj_t * liste) const char * lv_list_get_element_text(lv_obj_t * liste)
{ {
/*The last child is the label*/ lv_obj_t * label = lv_list_get_element_label(liste);
lv_obj_t * label = lv_obj_get_child(liste, NULL); if(label == NULL) return "";
return lv_label_get_text(label); return lv_label_get_text(label);
} }
/**
* Get the label object from a list element
* @param liste pointer to a list element (button)
* @return pointer to the label from the list element or NULL if not found
*/
lv_obj_t * lv_list_get_element_label(lv_obj_t * liste)
{
lv_obj_t * label = lv_obj_get_child(liste, NULL);
if(label == NULL) return NULL;
while(label->signal_f != lv_label_signal) {
label = lv_obj_get_child(liste, NULL);
if(label == NULL) break;
}
return label;
}
/**
* Get the image object from a list element
* @param liste pointer to a list element (button)
* @return pointer to the image from the list element or NULL if not found
*/
lv_obj_t * lv_list_get_element_img(lv_obj_t * liste)
{
lv_obj_t * img = lv_obj_get_child(liste, NULL);
if(img == NULL) return NULL;
while(img->signal_f != lv_img_signal) {
img = lv_obj_get_child(liste, NULL);
if(img == NULL) break;
}
return img;
}
/** /**
* Get the scroll bar outside attribute * Get the scroll bar outside attribute
* @param list pointer to list object * @param list pointer to list object
@@ -503,4 +539,29 @@ static bool lv_list_design(lv_obj_t * list, const area_t * mask, lv_design_mode_
} }
#endif #endif
/**
* Get the next button from list
* @param list pointer to a list object
* @param prev_btn pointer to button. Search the next after it.
* @return pointer to the next button or NULL
*/
static lv_obj_t * lv_list_get_next_btn(lv_obj_t * list, lv_obj_t * prev_btn)
{
/* Not a good practice but user can add/create objects to the lists manually.
* When getting the next button try to be sure that it is at least a button */
lv_obj_t * btn ;
lv_obj_t * scrl = lv_page_get_scrl(list);
btn = lv_obj_get_child(scrl, prev_btn);
if(btn == NULL) return NULL;
while(btn->signal_f != lv_btn_signal) {
btn = lv_obj_get_child(scrl, prev_btn);
if(btn == NULL) break;
}
return btn;
}
#endif #endif

View File

@@ -141,6 +141,20 @@ void lv_list_set_style_img(lv_obj_t * list, lv_style_t * style);
*/ */
const char * lv_list_get_element_text(lv_obj_t * liste); const char * lv_list_get_element_text(lv_obj_t * liste);
/**
* Get the label object from a list element
* @param liste pointer to a list element (button)
* @return pointer to the label from the list element or NULL if not found
*/
lv_obj_t * lv_list_get_element_label(lv_obj_t * liste);
/**
* Get the image object from a list element
* @param liste pointer to a list element (button)
* @return pointer to the image from the list element or NULL if not found
*/
lv_obj_t * lv_list_get_element_img(lv_obj_t * liste);
/** /**
* Get the scroll bar outside attribute * Get the scroll bar outside attribute
* @param list pointer to list object * @param list pointer to list object

View File

@@ -170,10 +170,16 @@ bool lv_page_signal(lv_obj_t * page, lv_signal_t sign, void * param)
lv_page_sb_refresh(page); lv_page_sb_refresh(page);
} else if(sign == LV_SIGNAL_CORD_CHG) { } else if(sign == LV_SIGNAL_CORD_CHG) {
lv_style_t * style = lv_obj_get_style(page);
/*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))) {
if(lv_cont_get_hfit(ext->scrl) == false) {
lv_obj_set_width(ext->scrl, lv_obj_get_width(page) - 2 * style->hpad);
}
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 scrollbars are important olny if they are visible now*/ /*The scrollbars are important olny if they are visible now*/
@@ -309,15 +315,15 @@ 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) { }
if(page_ext->pr_action != NULL) { }else if(sign == LV_SIGNAL_PRESSED) {
page_ext->pr_action(page, param); if(page_ext->pr_action != NULL) {
} page_ext->pr_action(page, param);
} else if(sign == LV_SIGNAL_RELEASED) { }
if(lv_dispi_is_dragging(param) == false) { } else if(sign == LV_SIGNAL_RELEASED) {
if(page_ext->rel_action != NULL) { if(lv_dispi_is_dragging(param) == false) {
page_ext->rel_action(page, param); if(page_ext->rel_action != NULL) {
} page_ext->rel_action(page, param);
} }
} }
} }