BigW Consortium Gitlab

Commit 6d85a9c0 by Kiss-Vamosi Gabor

App style added + minor mods

parent 6cb16b4d
......@@ -68,6 +68,33 @@ typedef struct __LV_APP_DSC_T
uint16_t win_data_size;
}lv_app_dsc_t;
typedef struct {
lv_rects_t menu_style;
lv_btns_t menu_btn_style;
lv_labels_t menu_btn_label_style;
lv_imgs_t menu_btn_img_style;
lv_lists_t app_list_style;
lv_pages_t sc_page_style;
lv_btns_t sc_area_style;
lv_wins_t win_style;
lv_btns_t sc_style;
lv_labels_t sc_title_style;
opa_t menu_opa;
opa_t menu_btn_opa;
opa_t sc_opa;
cord_t menu_h;
cord_t app_list_w;
cord_t app_list_h;
cord_t sc_w;
cord_t sc_h;
font_types_t font_small;
font_types_t font_medium;
font_types_t font_large;
}lv_app_style_t;
/**********************
* GLOBAL PROTOTYPES
......@@ -80,7 +107,11 @@ lv_obj_t * lv_app_sc_open(lv_app_inst_t * app);
void lv_app_sc_close(lv_app_inst_t * app);
lv_obj_t * lv_app_win_open(lv_app_inst_t * app);
void lv_app_win_close(lv_app_inst_t * app);
const lv_app_dsc_t * lv_app_dsc_get(const char * name);
const lv_app_dsc_t * lv_app_get_dsc(const char * name);
lv_app_style_t * lv_app_get_style(void);
void lv_app_refr_style(void);
const lv_app_dsc_t * lv_app_example_init(void);
......
......@@ -342,12 +342,15 @@ static lv_obj_t * dispi_search_obj(const lv_dispi_t * dispi_p, lv_obj_t * obj)
*/
static void dispi_drag(lv_dispi_t * dispi_p)
{
lv_obj_t * par = lv_obj_get_parent(dispi_p->act_obj);
lv_obj_t * drag_obj = dispi_p->act_obj;
if(lv_obj_get_drag_parent(dispi_p->act_obj) != false) {
drag_obj = par;
}
/*If drag parent is active check recursively the drag_parent attribute*/
while(lv_obj_get_drag_parent(drag_obj) != false &&
drag_obj != NULL) {
drag_obj = lv_obj_get_parent(drag_obj);
}
if(drag_obj == NULL) return;
if(lv_obj_get_drag(drag_obj) == false) return;
......@@ -388,12 +391,16 @@ static void dispi_drag_throw(lv_dispi_t * dispi_p)
if(dispi_p->drag_in_prog == 0) return;
/*Set new position if the vector is not zero*/
lv_obj_t * par = lv_obj_get_parent(dispi_p->last_obj);
lv_obj_t * drag_obj = dispi_p->last_obj;
if(lv_obj_get_drag_parent(dispi_p->last_obj) != false) {
drag_obj = par;
}
/*If drag parent is active check recursively the drag_parent attribute*/
while(lv_obj_get_drag_parent(drag_obj) != false &&
drag_obj != NULL) {
drag_obj = lv_obj_get_parent(drag_obj);
}
if(drag_obj == NULL) return;
/*Return if the drag throw is not enabled*/
if(lv_obj_get_drag_throw(drag_obj) == false ){
......
......@@ -225,7 +225,7 @@ void lv_btn_set_state(lv_obj_t * btn, lv_btn_state_t state)
* @param btn pointer to a button object
* @param pr_action pointer to function
*/
void lv_btn_set_pr_action(lv_obj_t * btn, bool (*pr_action)(lv_obj_t *, lv_dispi_t *))
void lv_btn_set_pr_action(lv_obj_t * btn, lv_action_res_t (*pr_action)(lv_obj_t *, lv_dispi_t *))
{
lv_btn_ext_t * ext = lv_obj_get_ext(btn);
......@@ -237,7 +237,7 @@ void lv_btn_set_pr_action(lv_obj_t * btn, bool (*pr_action)(lv_obj_t *, lv_dispi
* @param btn pointer to a button object
* @param pr_action pointer to function
*/
void lv_btn_set_rel_action(lv_obj_t * btn, bool (*rel_action)(lv_obj_t *, lv_dispi_t *))
void lv_btn_set_rel_action(lv_obj_t * btn, lv_action_res_t (*rel_action)(lv_obj_t *, lv_dispi_t *))
{
lv_btn_ext_t * btn_p = lv_obj_get_ext(btn);
......@@ -249,7 +249,7 @@ void lv_btn_set_rel_action(lv_obj_t * btn, bool (*rel_action)(lv_obj_t *, lv_dis
* @param btn pointer to a button object
* @param pr_action pointer to function
*/
void lv_btn_set_lpr_action(lv_obj_t * btn, bool (*lpr_action)(lv_obj_t *, lv_dispi_t *))
void lv_btn_set_lpr_action(lv_obj_t * btn, lv_action_res_t (*lpr_action)(lv_obj_t *, lv_dispi_t *))
{
lv_btn_ext_t * ext = lv_obj_get_ext(btn);
......@@ -352,9 +352,11 @@ static bool lv_btn_design(lv_obj_t * btn, const area_t * mask, lv_design_mode_t
lv_rects_t rects_tmp;
lv_btns_t * btns_tmp = lv_obj_get_style(btn);
lv_btn_style_load(btn, &rects_tmp);
btn->style_p = &rects_tmp;
ancestor_design_f(btn, mask, mode); /*Draw the rectangle*/
btn->style_p = btns_tmp; /*Reload the original button style*/
if(rects_tmp.objs.transp == 0) {
btn->style_p = &rects_tmp;
ancestor_design_f(btn, mask, mode); /*Draw the rectangle*/
btn->style_p = btns_tmp; /*Reload the original button style*/
}
}
return true;
}
......@@ -375,11 +377,12 @@ static void lv_btn_style_load(lv_obj_t * btn, lv_rects_t * new_rects)
new_rects->gcolor = style->gcolor[state];
new_rects->bcolor = style->bcolor[state];
new_rects->lcolor = style->lcolor[state];
if(style->light_en[state] != 0) {
new_rects->light = style->rects.light;
} else {
new_rects->light = 0;
}
new_rects->empty = style->flags[state].empty;
new_rects->objs.transp = style->flags[state].transp;
if(style->flags[state].light_en != 0) new_rects->light = style->rects.light;
else new_rects->light = 0;
}
/**
......@@ -392,31 +395,41 @@ static void lv_btns_init(void)
lv_btns_def.gcolor[LV_BTN_STATE_REL] = COLOR_BLACK;
lv_btns_def.bcolor[LV_BTN_STATE_REL] = COLOR_WHITE;
lv_btns_def.lcolor[LV_BTN_STATE_REL] = COLOR_MAKE(0x30, 0x40, 0x50);
lv_btns_def.light_en[LV_BTN_STATE_REL] = 0;
lv_btns_def.flags[LV_BTN_STATE_REL].light_en = 0;
lv_btns_def.flags[LV_BTN_STATE_REL].transp = 0;
lv_btns_def.flags[LV_BTN_STATE_REL].empty = 0;
lv_btns_def.mcolor[LV_BTN_STATE_PR] = COLOR_MAKE(0x60, 0x80, 0xa0);
lv_btns_def.gcolor[LV_BTN_STATE_PR] = COLOR_MAKE(0x20, 0x30, 0x40);
lv_btns_def.bcolor[LV_BTN_STATE_PR] = COLOR_WHITE;
lv_btns_def.lcolor[LV_BTN_STATE_PR] = COLOR_MAKE(0x30, 0x40, 0x50);
lv_btns_def.light_en[LV_BTN_STATE_PR] = 1;
lv_btns_def.flags[LV_BTN_STATE_PR].light_en = 1;
lv_btns_def.flags[LV_BTN_STATE_PR].transp = 0;
lv_btns_def.flags[LV_BTN_STATE_PR].empty = 0;
lv_btns_def.mcolor[LV_BTN_STATE_TGL_REL] = COLOR_MAKE(0x80, 0x00, 0x00);
lv_btns_def.gcolor[LV_BTN_STATE_TGL_REL] = COLOR_MAKE(0x20, 0x20, 0x20);
lv_btns_def.bcolor[LV_BTN_STATE_TGL_REL] = COLOR_WHITE;
lv_btns_def.lcolor[LV_BTN_STATE_TGL_REL] = COLOR_MAKE(0x30, 0x40, 0x50);
lv_btns_def.light_en[LV_BTN_STATE_TGL_REL] = 0;
lv_btns_def.flags[LV_BTN_STATE_TGL_REL].light_en = 0;
lv_btns_def.flags[LV_BTN_STATE_TGL_REL].transp = 0;
lv_btns_def.flags[LV_BTN_STATE_TGL_REL].empty = 0;
lv_btns_def.mcolor[LV_BTN_STATE_TGL_PR] = COLOR_MAKE(0xf0, 0x26, 0x26);
lv_btns_def.gcolor[LV_BTN_STATE_TGL_PR] = COLOR_MAKE(0x40, 0x40, 0x40);
lv_btns_def.bcolor[LV_BTN_STATE_TGL_PR] = COLOR_WHITE;
lv_btns_def.lcolor[LV_BTN_STATE_TGL_PR] = COLOR_MAKE(0x30, 0x40, 0x50);
lv_btns_def.light_en[LV_BTN_STATE_TGL_PR] = 1;
lv_btns_def.flags[LV_BTN_STATE_TGL_PR].light_en = 1;
lv_btns_def.flags[LV_BTN_STATE_TGL_PR].transp = 0;
lv_btns_def.flags[LV_BTN_STATE_TGL_PR].empty = 0;
lv_btns_def.mcolor[LV_BTN_STATE_INA] = COLOR_SILVER;
lv_btns_def.gcolor[LV_BTN_STATE_INA] = COLOR_GRAY;
lv_btns_def.bcolor[LV_BTN_STATE_INA] = COLOR_WHITE;
lv_btns_def.lcolor[LV_BTN_STATE_INA] = COLOR_MAKE(0x30, 0x40, 0x50);
lv_btns_def.light_en[LV_BTN_STATE_INA] = 0;
lv_btns_def.flags[LV_BTN_STATE_INA].light_en = 0;
lv_btns_def.flags[LV_BTN_STATE_INA].transp= 0;
lv_btns_def.flags[LV_BTN_STATE_INA].empty = 0;
lv_btns_def.rects.bwidth = 2 * LV_STYLE_MULT;
lv_btns_def.rects.bopa = 50;
......@@ -429,9 +442,17 @@ static void lv_btns_init(void)
/*Transparent style*/
memcpy(&lv_btns_transp, &lv_btns_def, sizeof(lv_btns_t));
lv_btns_transp.rects.objs.transp = 1;
lv_btns_transp.rects.bwidth = 0;
lv_btns_transp.rects.empty = 1;
lv_btns_transp.flags[LV_BTN_STATE_REL].transp = 1;
lv_btns_transp.flags[LV_BTN_STATE_REL].empty = 1;
lv_btns_transp.flags[LV_BTN_STATE_PR].transp = 1;
lv_btns_transp.flags[LV_BTN_STATE_PR].empty = 1;
lv_btns_transp.flags[LV_BTN_STATE_TGL_REL].transp = 1;
lv_btns_transp.flags[LV_BTN_STATE_TGL_REL].empty = 1;
lv_btns_transp.flags[LV_BTN_STATE_TGL_PR].transp = 1;
lv_btns_transp.flags[LV_BTN_STATE_TGL_PR].empty = 1;
lv_btns_transp.flags[LV_BTN_STATE_INA].transp = 1;
lv_btns_transp.flags[LV_BTN_STATE_INA].empty = 1;
/*Border style*/
......@@ -441,8 +462,12 @@ static void lv_btns_init(void)
lv_btns_border.bcolor[LV_BTN_STATE_TGL_REL] = COLOR_BLACK;
lv_btns_border.bcolor[LV_BTN_STATE_TGL_PR] = COLOR_BLACK;
lv_btns_border.bcolor[LV_BTN_STATE_INA] = COLOR_GRAY;
lv_btns_border.flags[LV_BTN_STATE_REL].empty = 1;
lv_btns_border.flags[LV_BTN_STATE_PR].empty = 1;
lv_btns_border.flags[LV_BTN_STATE_TGL_REL].empty = 1;
lv_btns_border.flags[LV_BTN_STATE_TGL_PR].empty = 1;
lv_btns_border.flags[LV_BTN_STATE_INA].empty = 1;
lv_btns_border.rects.bwidth = 2 * LV_STYLE_MULT;
lv_btns_border.rects.empty = 1;
lv_btns_border.rects.bopa = 50;
lv_btns_border.rects.round = 4 * LV_STYLE_MULT;
lv_btns_border.rects.hpad = 10 * LV_STYLE_MULT;
......
......@@ -33,6 +33,21 @@ typedef enum
LV_BTN_STATE_NUM,
}lv_btn_state_t;
typedef enum
{
LV_ACTION_RES_OK = 0,
LV_ACTION_RES_INV = 0,
}lv_action_res_t;
typedef lv_action_res_t (lv_btn_action_t) (lv_obj_t*, lv_dispi_t *);
typedef struct
{
uint8_t light_en :1;
uint8_t transp :1;
uint8_t empty :1;
}lv_btns_bits_t;
/*Style of button*/
typedef struct
{
......@@ -42,7 +57,7 @@ typedef struct
color_t gcolor[LV_BTN_STATE_NUM];
color_t bcolor[LV_BTN_STATE_NUM];
color_t lcolor[LV_BTN_STATE_NUM];
uint8_t light_en[LV_BTN_STATE_NUM];
lv_btns_bits_t flags[LV_BTN_STATE_NUM];
}lv_btns_t;
/*Built-in styles of button*/
......@@ -58,9 +73,9 @@ typedef struct
{
lv_rect_ext_t rect_ext; /*Ext. of ancestor*/
/*New data for this type */
bool (*pr_action)(lv_obj_t *, lv_dispi_t *);
bool (*rel_action)(lv_obj_t *, lv_dispi_t *);
bool (*lpr_action)(lv_obj_t *, lv_dispi_t *);
lv_action_res_t (*pr_action)(lv_obj_t *, lv_dispi_t *);
lv_action_res_t (*rel_action)(lv_obj_t *, lv_dispi_t *);
lv_action_res_t (*lpr_action)(lv_obj_t *, lv_dispi_t *);
lv_btn_state_t state;
uint8_t tgl :1; /*1: Toggle enabled*/
......@@ -78,9 +93,9 @@ lv_btns_t * lv_btns_get(lv_btns_builtin_t style, lv_btns_t * copy);
void lv_btn_set_tgl(lv_obj_t * btn, bool tgl);
void lv_btn_set_state(lv_obj_t * btn, lv_btn_state_t state);
void lv_btn_set_pr_action(lv_obj_t * btn, bool (*pr_action)(lv_obj_t *, lv_dispi_t *));
void lv_btn_set_rel_action(lv_obj_t * btn, bool (*rel_action)(lv_obj_t *, lv_dispi_t *));
void lv_btn_set_lpr_action(lv_obj_t * btn, bool (*lpr_action)(lv_obj_t *, lv_dispi_t *));
void lv_btn_set_pr_action(lv_obj_t * btn, lv_action_res_t (*pr_action)(lv_obj_t *, lv_dispi_t *));
void lv_btn_set_rel_action(lv_obj_t * btn, lv_action_res_t (*rel_action)(lv_obj_t *, lv_dispi_t *));
void lv_btn_set_lpr_action(lv_obj_t * btn, lv_action_res_t (*lpr_action)(lv_obj_t *, lv_dispi_t *));
bool lv_btn_get_tgl(lv_obj_t * btn);
lv_btn_state_t lv_btn_get_state(lv_obj_t * btn);
......
......@@ -110,7 +110,7 @@ bool lv_list_signal(lv_obj_t * list, lv_signal_t sign, void * param)
* @param rel_action pointer to release action function (like with lv_btn)
* @return pointer to the new list element which can be customized (a button)
*/
lv_obj_t * lv_list_add(lv_obj_t * list, const char * img_fn, const char * txt, bool (*rel_action)(lv_obj_t *, lv_dispi_t *))
lv_obj_t * lv_list_add(lv_obj_t * list, const char * img_fn, const char * txt, lv_btn_action_t rel_action)
{
lv_lists_t * lists = lv_obj_get_style(list);
lv_list_ext_t * ext = lv_obj_get_ext(list);
......
......@@ -65,7 +65,7 @@ typedef struct
**********************/
lv_obj_t * lv_list_create(lv_obj_t * par, lv_obj_t * copy);
bool lv_list_signal(lv_obj_t * list, lv_signal_t sign, void * param);
lv_obj_t * lv_list_add(lv_obj_t * list, const char * img_fn, const char * txt, bool (*rel_action)(lv_obj_t *, lv_dispi_t *));
lv_obj_t * lv_list_add(lv_obj_t * list, const char * img_fn, const char * txt, lv_btn_action_t rel_action);
lv_lists_t * lv_lists_get(lv_lists_builtin_t style, lv_lists_t * copy);
void lv_list_down(lv_obj_t * list);
......
......@@ -82,7 +82,7 @@ lv_obj_t * lv_mbox_create(lv_obj_t * par, lv_obj_t * copy)
ext->btnh = lv_rect_create(new_mbox, NULL);
lv_rect_set_fit(ext->btnh, false, true);
lv_rect_set_layout(ext->btnh, LV_RECT_LAYOUT_GRID);
lv_rect_set_layout(ext->btnh, LV_RECT_LAYOUT_PRETTY);
lv_obj_set_style(new_mbox, lv_mboxs_get(LV_MBOXS_DEF, NULL));
......@@ -173,7 +173,7 @@ bool lv_mbox_signal(lv_obj_t * mbox, lv_signal_t sign, void * param)
* @param rel_action a function which will be called when the button is relesed
* @return pointer to the created button (lv_btn)
*/
lv_obj_t * lv_mbox_add_btn(lv_obj_t * mbox, const char * btn_txt, bool (*rel_action)(lv_obj_t *, lv_dispi_t *))
lv_obj_t * lv_mbox_add_btn(lv_obj_t * mbox, const char * btn_txt, lv_btn_action_t rel_action)
{
lv_mbox_ext_t * ext = lv_obj_get_ext(mbox);
lv_mboxs_t * style = lv_obj_get_style(mbox);
......@@ -194,7 +194,7 @@ lv_obj_t * lv_mbox_add_btn(lv_obj_t * mbox, const char * btn_txt, bool (*rel_act
if(child_num == 1) {
lv_rect_set_layout(ext->btnh, LV_RECT_LAYOUT_CENTER);
} else if (child_num == 2) {
lv_rect_set_layout(ext->btnh, LV_RECT_LAYOUT_GRID);
lv_rect_set_layout(ext->btnh, LV_RECT_LAYOUT_PRETTY);
}
return btn;
......@@ -374,8 +374,8 @@ static void lv_temps_init(void)
lv_mboxs_def.bg.light = 10 * LV_STYLE_MULT;
lv_btns_get(LV_BTNS_DEF, &lv_mboxs_def.btn);
lv_mboxs_def.btn.light_en[LV_BTN_STATE_PR] = 0;
lv_mboxs_def.btn.light_en[LV_BTN_STATE_REL] = 0;
lv_mboxs_def.btn.flags[LV_BTN_STATE_PR].light_en = 0;
lv_mboxs_def.btn.flags[LV_BTN_STATE_REL].light_en = 0;
lv_labels_get(LV_LABELS_TITLE, &lv_mboxs_def.title);
lv_labels_get(LV_LABELS_TXT, &lv_mboxs_def.txt);
lv_labels_get(LV_LABELS_BTN, &lv_mboxs_def.btn_label);
......
......@@ -68,7 +68,7 @@ lv_obj_t * lv_mbox_create(lv_obj_t * par, lv_obj_t * copy);
bool lv_mbox_signal(lv_obj_t * mbox, lv_signal_t sign, void * param);
lv_mboxs_t * lv_mboxs_get(lv_mboxs_builtin_t style, lv_mboxs_t * copy);
lv_obj_t * lv_mbox_add_btn(lv_obj_t * mbox, const char * btn_txt, bool (*rel_action)(lv_obj_t *, lv_dispi_t *));
lv_obj_t * lv_mbox_add_btn(lv_obj_t * mbox, const char * btn_txt, lv_btn_action_t rel_action);
bool lv_mbox_close_action (lv_obj_t * mbox, lv_dispi_t *dispi);
void lv_mbox_auto_close(lv_obj_t * mbox, uint16_t tout);
void lv_mbox_set_title(lv_obj_t * mbox, const char * title);
......
......@@ -278,13 +278,13 @@ static bool lv_scrolling_signal(lv_obj_t * scrolling, lv_signal_t sign, void* pa
/**
* Glue the object to the page. After it the page can be moved (dragged) with this object too.
* @param page pointer to an object on a page
* @param obj pointer to an object on a page
* @param glue true: enable glue, false: disable glue
*/
void lv_page_glue_obj(lv_obj_t * page, bool glue)
void lv_page_glue_obj(lv_obj_t * obj, bool glue)
{
lv_obj_set_drag_parent(page, glue);
lv_obj_set_drag(page, glue);
lv_obj_set_drag_parent(obj, glue);
lv_obj_set_drag(obj, glue);
}
......@@ -293,6 +293,18 @@ void lv_page_glue_obj(lv_obj_t * page, bool glue)
*====================*/
/**
* Get the scrollable object of a page-
* @param page pointer to page object
* @return pointer to rectangle which is the scrollable part of the page
*/
lv_obj_t * lv_page_get_scrable(lv_obj_t * page)
{
lv_page_ext_t * ext = lv_obj_get_ext(page);
return ext->scrolling;
}
/**
* Return with a pointer to a built-in style and/or copy it to a variable
* @param style a style name from lv_pages_builtin_t enum
* @param copy copy the style to this variable. (NULL if unused)
......
......@@ -71,6 +71,8 @@ void lv_page_glue_obj(lv_obj_t * page, bool glue);
lv_pages_t * lv_pages_get(lv_pages_builtin_t style, lv_pages_t * copy);
bool lv_page_signal(lv_obj_t * page, lv_signal_t sign, void * param);
lv_obj_t * lv_page_get_scrable(lv_obj_t * page);
/**********************
* MACROS
**********************/
......
......@@ -41,6 +41,7 @@ static void lv_rect_refr_layout(lv_obj_t * rect);
static void lv_rect_layout_col(lv_obj_t * rect);
static void lv_rect_layout_row(lv_obj_t * rect);
static void lv_rect_layout_center(lv_obj_t * rect);
static void lv_rect_layout_pretty(lv_obj_t * rect);
static void lv_rect_layout_grid(lv_obj_t * rect);
static void lv_rect_refr_autofit(lv_obj_t * rect);
static void lv_rects_init(void);
......@@ -364,6 +365,9 @@ static void lv_rect_refr_layout(lv_obj_t * rect)
{
lv_rect_layout_t type = lv_rect_get_layout(rect);
/*'rect' has to be at least 1 child*/
if(lv_obj_get_child(rect, NULL) == NULL) return;
if(type == LV_RECT_LAYOUT_OFF) return;
if(type == LV_RECT_LAYOUT_CENTER) {
......@@ -372,7 +376,9 @@ static void lv_rect_refr_layout(lv_obj_t * rect)
lv_rect_layout_col(rect);
} else if(type == LV_RECT_LAYOUT_ROW_T || type == LV_RECT_LAYOUT_ROW_M || type == LV_RECT_LAYOUT_ROW_B) {
lv_rect_layout_row(rect);
} else if(type == LV_RECT_LAYOUT_GRID) {
} else if(type == LV_RECT_LAYOUT_PRETTY) {
lv_rect_layout_pretty(rect);
} else if(type == LV_RECT_LAYOUT_GRID) {
lv_rect_layout_grid(rect);
}
}
......@@ -510,11 +516,11 @@ static void lv_rect_layout_center(lv_obj_t * rect)
}
/**
* Handle the grid layout. Put as many object as possible in row
* Handle the pretty layout. Put as many object as possible in row
* then begin a new row
* @param rect pointer to an object which layout should be handled
*/
static void lv_rect_layout_grid(lv_obj_t * rect)
static void lv_rect_layout_pretty(lv_obj_t * rect)
{
lv_obj_t * child_rs; /* Row starter child */
lv_obj_t * child_rc; /* Row closer child */
......@@ -586,6 +592,47 @@ static void lv_rect_layout_grid(lv_obj_t * rect)
}
/**
* Handle the grid layout. Align same-sized objects in a grid
* @param rect pointer to an object which layout should be handled
*/
static void lv_rect_layout_grid(lv_obj_t * rect)
{
lv_obj_t * child;
lv_rects_t * style = lv_obj_get_style(rect);
cord_t w_tot = lv_obj_get_width(rect);
cord_t w_obj = lv_obj_get_width(lv_obj_get_child(rect, NULL));
cord_t h_obj = lv_obj_get_height(lv_obj_get_child(rect, NULL));
uint16_t obj_row = (w_tot - (2 * style->hpad)) / (w_obj + style->opad); /*Obj. num. in a row*/
cord_t x_ofs = w_obj + (w_tot - (2 * style->hpad) - (obj_row * w_obj)) / (obj_row - 1);
cord_t y_ofs = h_obj + style->opad;
/* Disable child change action because the children will be moved a lot
* an unnecessary child change signals could be sent*/
rect->child_chg_off = 1;
/* Align the children */
cord_t act_x = style->hpad;
cord_t act_y = style->vpad;
uint16_t obj_cnt = 0;
LL_READ_BACK(rect->child_ll, child) {
if(lv_obj_get_hidden(child) != false) continue;
lv_obj_set_pos(child, act_x, act_y);
act_x += x_ofs;
obj_cnt ++;
if(obj_cnt >= obj_row) {
obj_cnt = 0;
act_x = style->hpad;
act_y += y_ofs;
}
}
rect->child_chg_off = 0;
}
/**
* Handle auto fit. Set the size of the object to involve all children.
* @param rect pointer to an object which size will be modified
*/
......
......@@ -34,7 +34,8 @@ typedef enum
LV_RECT_LAYOUT_ROW_T, /*Row left align*/
LV_RECT_LAYOUT_ROW_M, /*Row middle align*/
LV_RECT_LAYOUT_ROW_B, /*Row right align*/
LV_RECT_LAYOUT_GRID, /*Put as many object as possible in row and begin a new row*/
LV_RECT_LAYOUT_PRETTY, /*Put as many object as possible in row and begin a new row*/
LV_RECT_LAYOUT_GRID, /*Align same-sized object into a grid*/
}lv_rect_layout_t;
/*Style of rectangle*/
......
......@@ -72,6 +72,9 @@ lv_obj_t * lv_win_create(lv_obj_t * par, lv_obj_t * copy)
/*Init the new window object*/
if(copy == NULL) {
/*Create a page for the content*/
ext->content = lv_page_create(new_win, NULL);
/*Create a holder for the header*/
ext->header = lv_rect_create(new_win, NULL);
lv_rect_set_fit(ext->header, false, true);
......@@ -85,8 +88,7 @@ lv_obj_t * lv_win_create(lv_obj_t * par, lv_obj_t * copy)
lv_rect_set_fit(ext->ctrl_holder, true, false);
lv_rect_set_layout(ext->ctrl_holder, LV_RECT_LAYOUT_ROW_M);
/*Create a page for the content*/
ext->content = lv_page_create(new_win, NULL);
lv_obj_set_style(new_win, lv_wins_get(LV_WINS_DEF, NULL));
......@@ -149,15 +151,20 @@ bool lv_win_signal(lv_obj_t * win, lv_signal_t sign, void * param)
lv_obj_set_style(ext->ctrl_holder, &style->ctrl_holder);
lv_obj_set_style(ext->title, &style->title);
lv_obj_set_style(ext->header, &style->header);
lv_obj_set_opa(ext->header, style->header_opa);
/*Refresh the style of all control buttons*/
child = lv_obj_get_child(ext->ctrl_holder, NULL);
while(child != NULL) {
lv_obj_set_style(child, &style->ctrl_btn);
lv_obj_set_opa(child, style->ctrl_btn_opa);
/*Refresh the image style too*/
lv_obj_set_style(lv_obj_get_child(child, NULL), &style->ctrl_img);
child = lv_obj_get_child(ext->ctrl_holder, child);
}
lv_win_realign(win);
break;
case LV_SIGNAL_CHILD_CHG:
/*If a child added move it to the 'content' object*/
......@@ -195,13 +202,14 @@ bool lv_win_signal(lv_obj_t * win, lv_signal_t sign, void * param)
* @param rel_action a function pointer to call when the button is released
* @return pointer to the created button object
*/
lv_obj_t * lv_win_add_ctrl_btn(lv_obj_t * win, const char * img_path, bool (*rel_action)(lv_obj_t *, lv_dispi_t *))
lv_obj_t * lv_win_add_ctrl_btn(lv_obj_t * win, const char * img_path, lv_btn_action_t rel_action)
{
lv_win_ext_t * ext = lv_obj_get_ext(win);
lv_wins_t * style = lv_obj_get_style(win);
lv_obj_t * btn = lv_btn_create(ext->ctrl_holder, NULL);
lv_obj_set_style(btn, &style->ctrl_btn);
lv_obj_set_opa(btn, style->ctrl_btn_opa);
lv_obj_set_size(btn, style->ctrl_btn_w, style->ctrl_btn_h);
lv_btn_set_rel_action(btn, rel_action);
lv_obj_t * img = lv_img_create(btn, NULL);
......@@ -254,7 +262,7 @@ const char * lv_win_get_title(lv_obj_t * win)
{
lv_win_ext_t * ext = lv_obj_get_ext(win);
return ext->title;
return lv_label_get_text(ext->title);
}
/**
......@@ -348,6 +356,7 @@ static void lv_wins_init(void)
/*Transparent background. It will be always covered*/
lv_objs_get(LV_OBJS_TRANSP, &lv_wins_def.bg);
/*Style for the content*/
lv_pages_get(LV_PAGES_DEF, &lv_wins_def.content);
lv_wins_def.content.bg_rects.objs.color = COLOR_WHITE;
lv_wins_def.content.bg_rects.gcolor = COLOR_WHITE;
......@@ -356,6 +365,7 @@ static void lv_wins_init(void)
lv_wins_def.content.bg_rects.round = 0;
lv_wins_def.content.bg_rects.hpad = 0;
lv_wins_def.content.bg_rects.vpad = 0;
lv_wins_def.header_on_content = 0;
/*Styles for the header*/
lv_rects_get(LV_RECTS_DEF, &lv_wins_def.header);
......@@ -390,6 +400,9 @@ static void lv_wins_init(void)
lv_wins_def.ctrl_btn_w = LV_WIN_CTRL_BTN_DEF_W;
lv_wins_def.ctrl_btn_h = LV_WIN_CTRL_BTN_DEF_H;
lv_wins_def.header_opa = OPA_COVER;
lv_wins_def.ctrl_btn_opa = OPA_COVER;
}
/**
......@@ -413,7 +426,13 @@ static void lv_win_realign(lv_obj_t * win)
lv_obj_set_height(ext->ctrl_holder, style->ctrl_btn_h + 2 * style->ctrl_holder.vpad * 2);
lv_obj_set_width(ext->header, lv_obj_get_width(win));
lv_obj_set_size(ext->content, lv_obj_get_width(win), lv_obj_get_height(win) - lv_obj_get_height(ext->header));
if(style->header_on_content == 0) {
lv_obj_set_size(ext->content, lv_obj_get_width(win), lv_obj_get_height(win) - lv_obj_get_height(ext->header));
}
else {
lv_obj_set_size(ext->content, lv_obj_get_width(win), lv_obj_get_height(win));
}
/*Align the higher object first to make the correct header size first*/
if(lv_obj_get_height(ext->title) > lv_obj_get_height(ext->ctrl_holder)) {
......@@ -425,7 +444,12 @@ static void lv_win_realign(lv_obj_t * win)
}
lv_obj_set_pos_us(ext->header, 0, 0);
lv_obj_align_us(ext->content, ext->header, LV_ALIGN_OUT_BOTTOM_RIGHT, 0, 0);
if(style->header_on_content == 0) {
lv_obj_align_us(ext->content, ext->header, LV_ALIGN_OUT_BOTTOM_RIGHT, 0, 0);
} else {
lv_obj_set_pos(ext->content, 0, 0);
}
}
#endif
......@@ -40,8 +40,11 @@ typedef struct
lv_imgs_t ctrl_img;
cord_t ctrl_btn_w;
cord_t ctrl_btn_h;
opa_t ctrl_btn_opa;
opa_t header_opa;
/*Content settings*/
lv_pages_t content;
uint8_t header_on_content:1;
}lv_wins_t;
/*Built-in styles of window*/
......@@ -68,7 +71,7 @@ lv_obj_t * lv_win_create(lv_obj_t * par, lv_obj_t * copy);
bool lv_win_signal(lv_obj_t * win, lv_signal_t sign, void * param);
lv_wins_t * lv_wins_get(lv_wins_builtin_t style, lv_wins_t * copy);
lv_obj_t * lv_win_add_ctrl_btn(lv_obj_t * win, const char * img, bool (*rel_action)(lv_obj_t *, lv_dispi_t *));
lv_obj_t * lv_win_add_ctrl_btn(lv_obj_t * win, const char * img, lv_btn_action_t rel_action);
bool lv_win_close_action(lv_obj_t * btn, lv_dispi_t * dispi);
void lv_win_set_title(lv_obj_t * win, const char * title);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment