New style system introduced! Still not applied to apps
This commit is contained in:
250
lv_objx/lv_win.c
250
lv_objx/lv_win.c
@@ -25,13 +25,11 @@
|
||||
#if 0 /*Not used*/
|
||||
static bool lv_win_design(lv_obj_t * win, const area_t * mask, lv_design_mode_t mode);
|
||||
#endif
|
||||
static void lv_wins_init(void);
|
||||
static void lv_win_realign(lv_obj_t * win);
|
||||
|
||||
/**********************
|
||||
* STATIC VARIABLES
|
||||
**********************/
|
||||
static lv_wins_t lv_wins_def;
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
@@ -54,25 +52,38 @@ static lv_wins_t lv_wins_def;
|
||||
lv_obj_t * lv_win_create(lv_obj_t * par, lv_obj_t * copy)
|
||||
{
|
||||
/*Create the ancestor object*/
|
||||
lv_obj_t * new_win = lv_page_create(par, copy);
|
||||
lv_obj_t * new_win = lv_obj_create(par, copy);
|
||||
dm_assert(new_win);
|
||||
|
||||
/*Allocate the object type specific extended data*/
|
||||
lv_win_ext_t * ext = lv_obj_alloc_ext(new_win, sizeof(lv_win_ext_t));
|
||||
dm_assert(ext);
|
||||
ext->ctrl_holder = NULL;
|
||||
ext->page = NULL;
|
||||
ext->btnh = NULL;
|
||||
ext->header = NULL;
|
||||
ext->title = NULL;
|
||||
|
||||
lv_obj_set_signal_f(new_win, lv_win_signal);
|
||||
ext->style_header = lv_style_get(LV_STYLE_PLAIN_COLOR, NULL);
|
||||
ext->styles_btn[LV_BTN_STATE_REL] = lv_style_get(LV_STYLE_BTN_REL, NULL);
|
||||
ext->styles_btn[LV_BTN_STATE_PR] = lv_style_get(LV_STYLE_BTN_PR, NULL);
|
||||
ext->styles_btn[LV_BTN_STATE_TREL] = lv_style_get(LV_STYLE_BTN_TREL, NULL);
|
||||
ext->styles_btn[LV_BTN_STATE_TPR] = lv_style_get(LV_STYLE_BTN_TPR, NULL);
|
||||
ext->styles_btn[LV_BTN_STATE_INA] = lv_style_get(LV_STYLE_BTN_INA, NULL);
|
||||
ext->btn_size = LV_DPI;
|
||||
|
||||
/*Init the new window object*/
|
||||
if(copy == NULL) {
|
||||
|
||||
lv_obj_set_size(new_win, LV_HOR_RES, LV_VER_RES);
|
||||
lv_obj_set_pos(new_win, 0, 0);
|
||||
lv_obj_t * scrl = lv_page_get_scrl(new_win);
|
||||
lv_obj_set_style(new_win, lv_style_get(LV_STYLE_PLAIN, NULL));
|
||||
|
||||
ext->page = lv_page_create(new_win, NULL);
|
||||
lv_obj_set_protect(ext->page, LV_PROTECT_PARENT);
|
||||
lv_obj_set_style(ext->page, lv_style_get(LV_STYLE_TRANSP, NULL));
|
||||
lv_page_set_sb_mode(ext->page, LV_PAGE_SB_MODE_AUTO);
|
||||
|
||||
lv_obj_t * scrl = lv_page_get_scrl(ext->page);
|
||||
lv_rect_set_fit(scrl, false, true);
|
||||
lv_obj_set_style(scrl, lv_style_get(LV_STYLE_TRANSP, NULL));
|
||||
|
||||
/*Create a holder for the header*/
|
||||
ext->header = lv_rect_create(new_win, NULL);
|
||||
@@ -80,18 +91,19 @@ lv_obj_t * lv_win_create(lv_obj_t * par, lv_obj_t * copy)
|
||||
/*Move back the header because it is automatically moved to the scrollable */
|
||||
lv_obj_set_protect(ext->header, LV_PROTECT_PARENT);
|
||||
lv_obj_set_parent(ext->header, new_win);
|
||||
lv_obj_set_style(ext->header, lv_style_get(LV_STYLE_PLAIN_COLOR, NULL));
|
||||
|
||||
/*Create a title on the header*/
|
||||
ext->title = lv_label_create(ext->header, NULL);
|
||||
lv_label_set_text(ext->title,"My title");
|
||||
|
||||
/*Create a holder for the control buttons*/
|
||||
ext->ctrl_holder = lv_rect_create(ext->header, NULL);
|
||||
lv_rect_set_fit(ext->ctrl_holder, true, false);
|
||||
lv_rect_set_layout(ext->ctrl_holder, LV_RECT_LAYOUT_ROW_M);
|
||||
|
||||
lv_obj_set_style(new_win, lv_wins_get(LV_WINS_DEF, NULL));
|
||||
ext->btnh = lv_rect_create(ext->header, NULL);
|
||||
lv_rect_set_fit(ext->btnh, true, false);
|
||||
lv_obj_set_style(ext->btnh, lv_style_get(LV_STYLE_TRANSP_TIGHT, NULL));
|
||||
lv_rect_set_layout(ext->btnh, LV_RECT_LAYOUT_ROW_M);
|
||||
|
||||
lv_obj_set_signal_f(new_win, lv_win_signal);
|
||||
lv_obj_set_size(new_win, LV_HOR_RES, LV_VER_RES);
|
||||
}
|
||||
/*Copy an existing object*/
|
||||
@@ -104,18 +116,19 @@ lv_obj_t * lv_win_create(lv_obj_t * par, lv_obj_t * copy)
|
||||
lv_obj_set_parent(ext->header, new_win);
|
||||
|
||||
ext->title = lv_label_create(ext->header, copy_ext->title);
|
||||
ext->ctrl_holder = lv_rect_create(ext->header, copy_ext->ctrl_holder);
|
||||
ext->btnh = lv_rect_create(ext->header, copy_ext->btnh);
|
||||
|
||||
/*Copy the control buttons*/
|
||||
lv_obj_t * child;
|
||||
lv_obj_t * cbtn;
|
||||
child = lv_obj_get_child(copy_ext->ctrl_holder, NULL);
|
||||
child = lv_obj_get_child(copy_ext->btnh, NULL);
|
||||
while(child != NULL) {
|
||||
cbtn = lv_btn_create(ext->ctrl_holder, child);
|
||||
cbtn = lv_btn_create(ext->btnh, child);
|
||||
lv_img_create(cbtn, lv_obj_get_child(child, NULL));
|
||||
child = lv_obj_get_child(copy_ext->ctrl_holder, child);
|
||||
child = lv_obj_get_child(copy_ext->btnh, child);
|
||||
}
|
||||
|
||||
lv_obj_set_signal_f(new_win, lv_win_signal);
|
||||
/*Refresh the style with new signal function*/
|
||||
lv_obj_refr_style(new_win);
|
||||
}
|
||||
@@ -137,47 +150,51 @@ bool lv_win_signal(lv_obj_t * win, lv_signal_t sign, void * param)
|
||||
bool valid;
|
||||
|
||||
/* Include the ancient signal function */
|
||||
valid = lv_page_signal(win, sign, param);
|
||||
lv_win_ext_t * ext = lv_obj_get_ext(win);
|
||||
lv_wins_t * style = lv_obj_get_style(win);
|
||||
lv_obj_t * child;
|
||||
valid = lv_obj_signal(win, sign, param);
|
||||
|
||||
/* The object can be deleted so check its validity and then
|
||||
* make the object specific signal handling */
|
||||
if(valid != false) {
|
||||
switch(sign) {
|
||||
case LV_SIGNAL_CLEANUP:
|
||||
/*Nothing to cleanup. (No dynamically allocated memory in 'ext')*/
|
||||
break;
|
||||
case LV_SIGNAL_STYLE_CHG:
|
||||
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);
|
||||
|
||||
if(sign == LV_SIGNAL_CHILD_CHG) { /*Move children to the page*/
|
||||
lv_obj_t * page = lv_win_get_page(win);
|
||||
if(page != NULL) {
|
||||
lv_obj_t * child;
|
||||
child = lv_obj_get_child(win, NULL);
|
||||
while(child != NULL) {
|
||||
if(lv_obj_is_protected(child, LV_PROTECT_PARENT) == false) {
|
||||
lv_obj_t * tmp = child;
|
||||
child = lv_obj_get_child(win, child); /*Get the next child before move this*/
|
||||
lv_obj_set_parent(tmp, page);
|
||||
} else {
|
||||
child = lv_obj_get_child(win, child);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(sign == LV_SIGNAL_STYLE_CHG) {
|
||||
/*Refresh the style of all control buttons*/
|
||||
// lv_win_ext_t * ext = lv_obj_get_ext(win);
|
||||
// lv_style_t * style = lv_obj_get_style(win);
|
||||
// lv_obj_t * child;
|
||||
// child = lv_obj_get_child(ext->ctrl_holder, NULL);
|
||||
// while(child != NULL) {
|
||||
// lv_obj_set_style(child, &style->ctrl_btn);
|
||||
//
|
||||
// /*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);
|
||||
// }
|
||||
|
||||
/*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);
|
||||
|
||||
/*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_CORD_CHG:
|
||||
/*If the size is changed refresh the window*/
|
||||
if(area_get_width(param) != lv_obj_get_width(win) ||
|
||||
area_get_height(param) != lv_obj_get_height(win)) {
|
||||
lv_win_realign(win);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
lv_win_realign(win);
|
||||
}
|
||||
else if(sign == LV_SIGNAL_CORD_CHG) {
|
||||
/*If the size is changed refresh the window*/
|
||||
if(area_get_width(param) != lv_obj_get_width(win) ||
|
||||
area_get_height(param) != lv_obj_get_height(win)) {
|
||||
lv_win_realign(win);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return valid;
|
||||
@@ -197,16 +214,16 @@ bool lv_win_signal(lv_obj_t * win, lv_signal_t sign, void * param)
|
||||
lv_obj_t * lv_win_add_ctrl_btn(lv_obj_t * win, const char * img_path, lv_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_size(btn, style->ctrl_btn_w, style->ctrl_btn_h);
|
||||
lv_obj_t * btn = lv_btn_create(ext->btnh, NULL);
|
||||
lv_btn_set_styles(btn, ext->styles_btn[LV_BTN_STATE_REL], ext->styles_btn[LV_BTN_STATE_PR],
|
||||
ext->styles_btn[LV_BTN_STATE_TREL], ext->styles_btn[LV_BTN_STATE_TPR],
|
||||
ext->styles_btn[LV_BTN_STATE_INA]);
|
||||
lv_obj_set_size(btn, ext->btn_size, ext->btn_size);
|
||||
lv_btn_set_rel_action(btn, rel_action);
|
||||
|
||||
lv_obj_t * img = lv_img_create(btn, NULL);
|
||||
lv_obj_set_click(img, false);
|
||||
lv_obj_set_style(img, &style->ctrl_img);
|
||||
lv_img_set_file(img, img_path);
|
||||
|
||||
lv_win_realign(win);
|
||||
@@ -245,6 +262,7 @@ void lv_win_set_title(lv_obj_t * win, const char * title)
|
||||
/*=====================
|
||||
* Getter functions
|
||||
*====================*/
|
||||
|
||||
/**
|
||||
* Get the title of a window
|
||||
* @param win pointer to a window object
|
||||
@@ -253,10 +271,20 @@ void lv_win_set_title(lv_obj_t * win, const char * title)
|
||||
const char * lv_win_get_title(lv_obj_t * win)
|
||||
{
|
||||
lv_win_ext_t * ext = lv_obj_get_ext(win);
|
||||
|
||||
return lv_label_get_text(ext->title);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the page of a window
|
||||
* @param win pointer to a window object
|
||||
* @return page pointer to the page object of the window
|
||||
*/
|
||||
lv_obj_t * lv_win_get_page(lv_obj_t * win)
|
||||
{
|
||||
lv_win_ext_t * ext = lv_obj_get_ext(win);
|
||||
return ext->page;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the pointer of a widow from one of its control button.
|
||||
* It is useful in the action of the control buttons where only button is known.
|
||||
@@ -272,37 +300,6 @@ lv_obj_t * lv_win_get_from_ctrl_btn(lv_obj_t * ctrl_btn)
|
||||
return win;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return with a pointer to a built-in style and/or copy it to a variable
|
||||
* @param style a style name from lv_wins_builtin_t enum
|
||||
* @param copy_p copy the style to this variable. (NULL if unused)
|
||||
* @return pointer to an lv_wins_t style
|
||||
*/
|
||||
lv_wins_t * lv_wins_get(lv_wins_builtin_t style, lv_wins_t * copy)
|
||||
{
|
||||
static bool style_inited = false;
|
||||
|
||||
/*Make the style initialization if it is not done yet*/
|
||||
if(style_inited == false) {
|
||||
lv_wins_init();
|
||||
style_inited = true;
|
||||
}
|
||||
|
||||
lv_wins_t *style_p;
|
||||
|
||||
switch(style) {
|
||||
case LV_WINS_DEF:
|
||||
style_p = &lv_wins_def;
|
||||
break;
|
||||
default:
|
||||
style_p = &lv_wins_def;
|
||||
}
|
||||
|
||||
if(copy != NULL) memcpy(copy, style_p, sizeof(lv_wins_t));
|
||||
|
||||
return style_p;
|
||||
}
|
||||
|
||||
/**********************
|
||||
* STATIC FUNCTIONS
|
||||
**********************/
|
||||
@@ -337,50 +334,6 @@ static bool lv_win_design(lv_obj_t * win, const area_t * mask, lv_design_mode_t
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Initialize the window styles
|
||||
*/
|
||||
static void lv_wins_init(void)
|
||||
{
|
||||
/*Style for the content*/
|
||||
lv_pages_get(LV_PAGES_PAPER, &lv_wins_def.page); /*LV_PAGES_PAPER: White bg, transparent scrl*/
|
||||
lv_wins_def.page.bg.base.color = COLOR_WHITE;
|
||||
lv_wins_def.page.bg.gcolor = COLOR_WHITE;
|
||||
lv_wins_def.page.bg.bwidth = 1 * LV_DOWNSCALE;
|
||||
lv_wins_def.page.bg.bcolor = COLOR_GRAY;
|
||||
lv_wins_def.page.bg.radius = 0;
|
||||
lv_wins_def.page.bg.vpad = LV_DPI; /*Great vpad on the background to move the content below the header*/
|
||||
lv_wins_def.page.bg.hpad = LV_DPI / 4;
|
||||
|
||||
/*Styles for the header*/
|
||||
lv_rects_get(LV_RECTS_PLAIN, &lv_wins_def.header);
|
||||
lv_wins_def.header.bwidth = 0;
|
||||
lv_wins_def.header.radius = 0;
|
||||
lv_wins_def.header.hpad = LV_DPI / 10;
|
||||
lv_wins_def.header.vpad = LV_DPI / 10;
|
||||
lv_wins_def.header.bwidth = 0;
|
||||
lv_wins_def.header.radius = 0;
|
||||
|
||||
lv_rects_get(LV_RECTS_TRANSP, &lv_wins_def.ctrl_holder);
|
||||
lv_wins_def.ctrl_holder.hpad = 0;
|
||||
lv_wins_def.ctrl_holder.vpad = 0;
|
||||
lv_wins_def.ctrl_holder.opad = LV_DPI / 10;
|
||||
|
||||
lv_btns_get(LV_BTNS_DEF, &lv_wins_def.ctrl_btn);
|
||||
lv_wins_def.ctrl_btn.state_style[LV_BTN_STATE_REL].swidth = 0;
|
||||
lv_wins_def.ctrl_btn.state_style[LV_BTN_STATE_PR].swidth = 0;
|
||||
lv_wins_def.ctrl_btn.state_style[LV_BTN_STATE_TREL].swidth = 0;
|
||||
lv_wins_def.ctrl_btn.state_style[LV_BTN_STATE_TPR].swidth = 0;
|
||||
lv_wins_def.ctrl_btn.state_style[LV_BTN_STATE_INA].swidth = 0;
|
||||
|
||||
lv_imgs_get(LV_IMGS_DEF, &lv_wins_def.ctrl_img);
|
||||
|
||||
lv_labels_get(LV_LABELS_TITLE, &lv_wins_def.title);
|
||||
|
||||
lv_wins_def.ctrl_btn_w = 2 * LV_DPI / 3;
|
||||
lv_wins_def.ctrl_btn_h = 2 * LV_DPI / 3;
|
||||
}
|
||||
|
||||
/**
|
||||
* Realign the building elements of a window
|
||||
* @param win pointer to window objectker
|
||||
@@ -388,34 +341,41 @@ static void lv_wins_init(void)
|
||||
static void lv_win_realign(lv_obj_t * win)
|
||||
{
|
||||
lv_win_ext_t * ext = lv_obj_get_ext(win);
|
||||
lv_wins_t * style = lv_obj_get_style(win);
|
||||
lv_style_t * style = lv_obj_get_style(win);
|
||||
|
||||
if(ext->ctrl_holder == NULL || ext->header == NULL || ext->title == NULL) return;
|
||||
if(ext->page == NULL || ext->btnh == NULL || ext->header == NULL || ext->title == NULL) return;
|
||||
|
||||
lv_obj_t * cbtn;
|
||||
/*Refresh the style of all control buttons*/
|
||||
cbtn = lv_obj_get_child(ext->ctrl_holder, NULL);
|
||||
cbtn = lv_obj_get_child(ext->btnh, NULL);
|
||||
while(cbtn != NULL) {
|
||||
lv_obj_set_size(cbtn, style->ctrl_btn_w, style->ctrl_btn_h);
|
||||
cbtn = lv_obj_get_child(ext->ctrl_holder, cbtn);
|
||||
lv_obj_set_size(cbtn, ext->btn_size, ext->btn_size);
|
||||
cbtn = lv_obj_get_child(ext->btnh, cbtn);
|
||||
}
|
||||
|
||||
lv_obj_set_height(ext->ctrl_holder, style->ctrl_btn_h + 2 * style->ctrl_holder.vpad * 2);
|
||||
lv_style_t * btnh_style = lv_obj_get_style(ext->btnh);
|
||||
lv_obj_set_height(ext->btnh, ext->btn_size + 2 * btnh_style->vpad * 2);
|
||||
lv_obj_set_width(ext->header, lv_obj_get_width(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)) {
|
||||
lv_obj_align(ext->title, NULL, LV_ALIGN_IN_LEFT_MID, style->header.hpad, 0);
|
||||
lv_obj_align(ext->ctrl_holder, NULL, LV_ALIGN_IN_RIGHT_MID, -style->header.hpad, 0);
|
||||
if(lv_obj_get_height(ext->title) > lv_obj_get_height(ext->btnh)) {
|
||||
lv_obj_align(ext->title, NULL, LV_ALIGN_IN_LEFT_MID, ext->style_header->hpad, 0);
|
||||
lv_obj_align(ext->btnh, NULL, LV_ALIGN_IN_RIGHT_MID, - ext->style_header->hpad, 0);
|
||||
} else {
|
||||
lv_obj_align(ext->ctrl_holder, NULL, LV_ALIGN_IN_RIGHT_MID, -style->header.hpad, 0);
|
||||
lv_obj_align(ext->title, NULL, LV_ALIGN_IN_LEFT_MID, style->header.hpad, 0);
|
||||
lv_obj_align(ext->btnh, NULL, LV_ALIGN_IN_RIGHT_MID, - ext->style_header->hpad, 0);
|
||||
lv_obj_align(ext->title, NULL, LV_ALIGN_IN_LEFT_MID, ext->style_header->hpad, 0);
|
||||
}
|
||||
|
||||
lv_obj_set_pos_us(ext->header, 0, 0);
|
||||
|
||||
lv_obj_t * scrl = lv_page_get_scrl(win);
|
||||
lv_obj_set_width(scrl, LV_HOR_RES - 2 * style->page.bg.hpad);
|
||||
lv_obj_t * page = lv_win_get_page(win);
|
||||
lv_obj_set_size(page, lv_obj_get_width(win), lv_obj_get_height(win) - lv_obj_get_height(ext->header));
|
||||
lv_obj_align(page, ext->header, LV_ALIGN_OUT_BOTTOM_LEFT, 0, 0);
|
||||
|
||||
lv_style_t * style_page = lv_obj_get_style(page);
|
||||
lv_obj_t * scrl = lv_page_get_scrl(page);
|
||||
|
||||
lv_obj_set_width(scrl, lv_obj_get_width(page) - 2 * style_page->hpad);
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user