New style system introduced! Still not applied to apps

This commit is contained in:
Gabor
2017-04-13 10:20:35 +02:00
parent 09967f66f2
commit 6116e83815
43 changed files with 2080 additions and 2362 deletions

View File

@@ -811,7 +811,7 @@ static lv_action_res_t lv_app_win_close_action(lv_obj_t * close_btn, lv_dispi_t
lv_obj_set_style(app->win, &wins_anim);
/*Hide some elements to speed up the animation*/
lv_obj_set_hidden(((lv_win_ext_t *)app->win->ext)->ctrl_holder, true);
lv_obj_set_hidden(((lv_win_ext_t *)app->win->ext)->btnh, true);
lv_obj_set_hidden(((lv_win_ext_t *)app->win->ext)->title, true);
lv_obj_set_hidden(((lv_win_ext_t *)app->win->ext)->page.scrl, true);
@@ -920,7 +920,7 @@ static lv_action_res_t lv_app_win_open_anim_create(lv_app_inst_t * app)
lv_obj_set_style(app->win, &wins_anim);
/*Hide some elements to speed up the animation*/
lv_obj_set_hidden(((lv_win_ext_t *)app->win->ext)->ctrl_holder, true);
lv_obj_set_hidden(((lv_win_ext_t *)app->win->ext)->btnh, true);
lv_obj_set_hidden(((lv_win_ext_t *)app->win->ext)->title, true);
lv_obj_set_hidden(((lv_win_ext_t *)app->win->ext)->page.scrl, true);
@@ -1000,7 +1000,7 @@ static lv_action_res_t lv_app_win_minim_anim_create(lv_app_inst_t * app)
lv_obj_set_style(app->win, &wins_anim);
/*Hide some elements to speed up the animation*/
lv_obj_set_hidden(((lv_win_ext_t *)app->win->ext)->ctrl_holder, true);
lv_obj_set_hidden(((lv_win_ext_t *)app->win->ext)->btnh, true);
lv_obj_set_hidden(((lv_win_ext_t *)app->win->ext)->title, true);
lv_obj_set_hidden(((lv_win_ext_t *)app->win->ext)->page.scrl, true);
@@ -1052,7 +1052,7 @@ static lv_action_res_t lv_app_win_minim_anim_create(lv_app_inst_t * app)
static void lv_app_win_open_anim_cb(lv_obj_t * app_win)
{
/*Unhide the the elements*/
lv_obj_set_hidden(((lv_win_ext_t *)app_win->ext)->ctrl_holder, false);
lv_obj_set_hidden(((lv_win_ext_t *)app_win->ext)->btnh, false);
lv_obj_set_hidden(((lv_win_ext_t *)app_win->ext)->title, false);
lv_obj_set_hidden(((lv_win_ext_t *)app_win->ext)->page.scrl, false);

View File

@@ -18,6 +18,7 @@
#include "lv_draw_rbasic.h"
#include "lv_draw_vbasic.h"
#include "misc/fs/ufs/ufs.h"
#include "../lv_objx/lv_img.h"
/*********************
* DEFINES
@@ -42,10 +43,10 @@ typedef enum
* STATIC PROTOTYPES
**********************/
#if USE_LV_RECT != 0
static void lv_draw_rect_main_mid(const area_t * cords_p, const area_t * mask_p, const lv_rects_t * rects_p);
static void lv_draw_rect_main_corner(const area_t * cords_p, const area_t * mask_p, const lv_rects_t * rects_p);
static void lv_draw_rect_border_straight(const area_t * cords_p, const area_t * mask_p, const lv_rects_t * rects_p);
static void lv_draw_rect_border_corner(const area_t * cords_p, const area_t * mask_p, const lv_rects_t * rects_p);
static void lv_draw_rect_main_mid(const area_t * cords_p, const area_t * mask_p, const lv_style_t * style);
static void lv_draw_rect_main_corner(const area_t * cords_p, const area_t * mask_p, const lv_style_t * style_p);
static void lv_draw_rect_border_straight(const area_t * cords_p, const area_t * mask_p, const lv_style_t * style_p);
static void lv_draw_rect_border_corner(const area_t * cords_p, const area_t * mask_p, const lv_style_t * style);
static uint16_t lv_draw_rect_radius_corr(uint16_t r, cord_t w, cord_t h);
#endif /*USE_LV_RECT != 0*/
@@ -68,20 +69,6 @@ static void (*map_fp)(const area_t * cords_p, const area_t * mask_p, const color
#endif
#if USE_LV_IMG != 0 && USE_FSINT != 0 && USE_UFS != 0
static lv_rects_t lv_img_no_pic_rects = {
.base.color = COLOR_BLACK, .gcolor = COLOR_BLACK,
.bcolor = COLOR_RED, .bwidth = 2 * LV_DOWNSCALE, .bopa = 100,
.radius = 0, .empty = 0
};
static lv_labels_t lv_img_no_pic_labels = {
.base.color = COLOR_WHITE,
.letter_space = 1 * LV_DOWNSCALE, .line_space = 1 * LV_DOWNSCALE,
.mid = 1,
};
#endif
/**********************
* MACROS
**********************/
@@ -95,25 +82,25 @@ static lv_labels_t lv_img_no_pic_labels = {
* Draw a rectangle
* @param cords_p the coordinates of the rectangle
* @param mask_p the rectangle will be drawn only in this mask
* @param rects_p pointer to a rectangle style
* @param style_p pointer to a style
*/
void lv_draw_rect(const area_t * cords_p, const area_t * mask_p, const lv_rects_t * rects_p)
void lv_draw_rect(const area_t * cords_p, const area_t * mask_p, const lv_style_t * style_p)
{
if(area_get_height(cords_p) < 1 || area_get_width(cords_p) < 1) return;
if(rects_p->empty == 0){
lv_draw_rect_main_mid(cords_p, mask_p, rects_p);
if(style_p->empty == 0){
lv_draw_rect_main_mid(cords_p, mask_p, style_p);
if(rects_p->radius != 0) {
lv_draw_rect_main_corner(cords_p, mask_p, rects_p);
if(style_p->radius != 0) {
lv_draw_rect_main_corner(cords_p, mask_p, style_p);
}
}
if(rects_p->bwidth != 0) {
lv_draw_rect_border_straight(cords_p, mask_p, rects_p);
if(style_p->bwidth != 0) {
lv_draw_rect_border_straight(cords_p, mask_p, style_p);
if(rects_p->radius != 0) {
lv_draw_rect_border_corner(cords_p, mask_p, rects_p);
if(style_p->radius != 0) {
lv_draw_rect_border_corner(cords_p, mask_p, style_p);
}
}
}
@@ -233,11 +220,11 @@ void lv_draw_triangle(const point_t * points, const area_t * mask_p, color_t col
* Write a text
* @param cords_p coordinates of the label
* @param mask_p the label will be drawn only in this area
* @param labels_p pointer to a label style
* @param style pointer to a style
* @param txt 0 terminated text to write
* @param flag settings for the text from 'txt_flag_t' enum
*/
void lv_draw_label(const area_t * cords_p,const area_t * mask_p, const lv_labels_t * style,
void lv_draw_label(const area_t * cords_p,const area_t * mask_p, const lv_style_t * style,
const char * txt, txt_flag_t flag)
{
const font_t * font = style->font;
@@ -254,7 +241,7 @@ void lv_draw_label(const area_t * cords_p,const area_t * mask_p, const lv_labels
pos.y = cords_p->y1;
/*Align the line to middle if enabled*/
if(style->mid != 0) {
if(style->txt_align != 0) {
line_length = txt_get_width(&txt[line_start], line_end - line_start,
font, style->letter_space, flag);
pos.x += (w - line_length) / 2;
@@ -298,7 +285,7 @@ void lv_draw_label(const area_t * cords_p,const area_t * mask_p, const lv_labels
sscanf(buf, "%02x%02x%02x", &r, &g, &b);
recolor = COLOR_MAKE(r, g, b);
} else {
recolor.full = style->base.color.full;
recolor.full = style->ccolor.full;
}
cmd_state = CMD_STATE_IN; /*After the parameter the text is in the command*/
}
@@ -306,8 +293,8 @@ void lv_draw_label(const area_t * cords_p,const area_t * mask_p, const lv_labels
}
}
if(cmd_state == CMD_STATE_IN) letter_fp(&pos, mask_p, font, txt[i], recolor, style->base.opa);
else letter_fp(&pos, mask_p, font, txt[i], style->base.color, style->base.opa);
if(cmd_state == CMD_STATE_IN) letter_fp(&pos, mask_p, font, txt[i], recolor, style->opa);
else letter_fp(&pos, mask_p, font, txt[i], style->ccolor, style->opa);
pos.x += (font_get_width(font, txt[i]) >> LV_FONT_ANTIALIAS) + style->letter_space;
}
/*Go to next line*/
@@ -316,7 +303,7 @@ void lv_draw_label(const area_t * cords_p,const area_t * mask_p, const lv_labels
pos.x = cords_p->x1;
/*Align to middle*/
if(style->mid != 0) {
if(style->txt_align != 0) {
line_length = txt_get_width(&txt[line_start], line_end - line_start,
font, style->letter_space, flag);
pos.x += (w - line_length) / 2;
@@ -338,12 +325,11 @@ void lv_draw_label(const area_t * cords_p,const area_t * mask_p, const lv_labels
* @param opa opacity of the image (0..255)
*/
void lv_draw_img(const area_t * cords_p, const area_t * mask_p,
const lv_imgs_t * style, const char * fn)
const lv_style_t * style, const char * fn)
{
if(fn == NULL) {
lv_draw_rect(cords_p, mask_p, &lv_img_no_pic_rects);
if(lv_img_no_pic_labels.font == NULL) lv_img_no_pic_labels.font = font_get(LV_FONT_DEFAULT);
lv_draw_label(cords_p, mask_p,&lv_img_no_pic_labels, "No data", TXT_FLAG_NONE);
lv_draw_rect(cords_p, mask_p, lv_style_get(LV_STYLE_PLAIN, NULL));
lv_draw_label(cords_p, mask_p, lv_style_get(LV_STYLE_PLAIN, NULL), "No data", TXT_FLAG_NONE);
} else {
fs_file_t file;
fs_res_t res = fs_open(&file, fn, FS_MODE_RD);
@@ -412,15 +398,15 @@ void lv_draw_img(const area_t * cords_p, const area_t * mask_p,
uint8_t * f_data = ((ufs_file_t*)file.file_d)->ent->data_d;
f_data += ((ufs_file_t*)file.file_d)->rwp;
((ufs_file_t*)file.file_d)->rwp += useful_data;
map_fp(&act_area, &mask_sub, (void*)f_data , style->base.opa, header.transp, upscale,
style->base.color, style->recolor_opa);
map_fp(&act_area, &mask_sub, (void*)f_data , style->opa, header.transp, upscale,
style->ccolor, style->img_recolor);
}
/*Or read the NOT const files normally*/
else {
color_t buf[LV_HOR_RES];
res = fs_read(&file, buf, useful_data, &br);
map_fp(&act_area, &mask_sub, buf, style->base.opa, header.transp, upscale,
style->base.color, style->recolor_opa);
map_fp(&act_area, &mask_sub, buf, style->opa, header.transp, upscale,
style->ccolor, style->img_recolor);
}
fs_tell(&file, &act_pos);
@@ -433,9 +419,8 @@ void lv_draw_img(const area_t * cords_p, const area_t * mask_p,
fs_close(&file);
if(res != FS_RES_OK) {
lv_draw_rect(cords_p, mask_p, &lv_img_no_pic_rects);
if(lv_img_no_pic_labels.font == NULL) lv_img_no_pic_labels.font = font_get(LV_FONT_DEFAULT);
lv_draw_label(cords_p, mask_p,&lv_img_no_pic_labels, fn, TXT_FLAG_NONE);
lv_draw_rect(cords_p, mask_p, lv_style_get(LV_STYLE_PLAIN, NULL));
lv_draw_label(cords_p, mask_p, lv_style_get(LV_STYLE_PLAIN, NULL), "No data", TXT_FLAG_NONE);
}
}
}
@@ -452,9 +437,9 @@ void lv_draw_img(const area_t * cords_p, const area_t * mask_p,
* @param lines_p pointer to a line style
*/
void lv_draw_line(const point_t * p1, const point_t * p2, const area_t * mask_p,
const lv_lines_t * style)
const lv_style_t * style)
{
if(style->width == 0) return;
if(style->line_width == 0) return;
if(p1->x == p2->x && p1->y == p2->y) return;
@@ -490,7 +475,7 @@ void lv_draw_line(const point_t * p1, const point_t * p2, const area_t * mask_p,
}
/*Make the correction on lie width*/
width = ((style->width - 1) * width_corr_array[wcor]) >> LINE_WIDTH_CORR_SHIFT;
width = ((style->line_width - 1) * width_corr_array[wcor]) >> LINE_WIDTH_CORR_SHIFT;
width_half = width >> 1;
width_1 = width & 0x1 ? 1 : 0;
@@ -509,7 +494,7 @@ void lv_draw_line(const point_t * p1, const point_t * p2, const area_t * mask_p,
draw_area.x2 = MATH_MAX(act_area.x1, act_area.x2);
draw_area.y1 = MATH_MIN(act_area.y1, act_area.y2);
draw_area.y2 = MATH_MAX(act_area.y1, act_area.y2);
fill_fp(&draw_area, mask_p, style->base.color, style->base.opa);
fill_fp(&draw_area, mask_p, style->ccolor, style->opa);
}
if (hor == false && last_x != act_point.x) {
area_t act_area;
@@ -525,7 +510,7 @@ void lv_draw_line(const point_t * p1, const point_t * p2, const area_t * mask_p,
draw_area.x2 = MATH_MAX(act_area.x1, act_area.x2);
draw_area.y1 = MATH_MIN(act_area.y1, act_area.y2);
draw_area.y2 = MATH_MAX(act_area.y1, act_area.y2);
fill_fp(&draw_area, mask_p, style->base.color, style->base.opa);
fill_fp(&draw_area, mask_p, style->ccolor, style->opa);
}
/*Calc. the next point of the line*/
@@ -553,7 +538,7 @@ void lv_draw_line(const point_t * p1, const point_t * p2, const area_t * mask_p,
draw_area.x2 = MATH_MAX(act_area.x1, act_area.x2);
draw_area.y1 = MATH_MIN(act_area.y1, act_area.y2);
draw_area.y2 = MATH_MAX(act_area.y1, act_area.y2);
fill_fp(&draw_area, mask_p, style->base.color, style->base.opa);
fill_fp(&draw_area, mask_p, style->ccolor, style->opa);
}
if (hor == false) {
area_t act_area;
@@ -567,7 +552,7 @@ void lv_draw_line(const point_t * p1, const point_t * p2, const area_t * mask_p,
draw_area.x2 = MATH_MAX(act_area.x1, act_area.x2);
draw_area.y1 = MATH_MIN(act_area.y1, act_area.y2);
draw_area.y2 = MATH_MAX(act_area.y1, act_area.y2);
fill_fp(&draw_area, mask_p, style->base.color, style->base.opa);
fill_fp(&draw_area, mask_p, style->ccolor, style->opa);
}
}
#endif /*USE_LV_LINE != 0*/
@@ -583,14 +568,14 @@ void lv_draw_line(const point_t * p1, const point_t * p2, const area_t * mask_p,
* @param mask_p the rectangle will be drawn only on this area
* @param rects_p pointer to a rectangle style
*/
static void lv_draw_rect_main_mid(const area_t * cords_p, const area_t * mask_p, const lv_rects_t * rects_p)
static void lv_draw_rect_main_mid(const area_t * cords_p, const area_t * mask_p, const lv_style_t * style)
{
uint16_t radius = rects_p->radius;
uint16_t radius = style->radius;
color_t mcolor = rects_p->base.color;
color_t gcolor = rects_p->gcolor;
color_t mcolor = style->mcolor;
color_t gcolor = style->gcolor;
uint8_t mix;
opa_t opa = rects_p->base.opa;
opa_t opa = style->opa;
cord_t height = area_get_height(cords_p);
cord_t width = area_get_width(cords_p);
@@ -633,14 +618,14 @@ static void lv_draw_rect_main_mid(const area_t * cords_p, const area_t * mask_p,
* @param mask_p the rectangle will be drawn only on this area
* @param rects_p pointer to a rectangle style
*/
static void lv_draw_rect_main_corner(const area_t * cords_p, const area_t * mask_p, const lv_rects_t * rects_p)
static void lv_draw_rect_main_corner(const area_t * cords_p, const area_t * mask_p, const lv_style_t * style_p)
{
uint16_t radius = rects_p->radius;
uint16_t radius = style_p->radius;
color_t mcolor = rects_p->base.color;
color_t gcolor = rects_p->gcolor;
color_t mcolor = style_p->mcolor;
color_t gcolor = style_p->gcolor;
color_t act_color;
opa_t opa = rects_p->base.opa;
opa_t opa = style_p->opa;
uint8_t mix;
cord_t height = area_get_height(cords_p);
cord_t width = area_get_width(cords_p);
@@ -804,14 +789,14 @@ if(edge_top_area.y1 != mid_top_area.y1) {
* @param mask_p the rectangle will be drawn only on this area
* @param rects_p pointer to a rectangle style
*/
static void lv_draw_rect_border_straight(const area_t * cords_p, const area_t * mask_p, const lv_rects_t * rects_p)
static void lv_draw_rect_border_straight(const area_t * cords_p, const area_t * mask_p, const lv_style_t * style_p)
{
uint16_t radius = rects_p->radius;
uint16_t radius = style_p->radius;
cord_t width = area_get_width(cords_p);
cord_t height = area_get_height(cords_p);
uint16_t bwidth = rects_p->bwidth;
opa_t bopa = (uint16_t)((uint16_t) rects_p->base.opa * rects_p->bopa) >> 8;
uint16_t bwidth = style_p->bwidth;
opa_t bopa = (uint16_t)((uint16_t) style_p->opa * style_p->bopa) >> 8;
area_t work_area;
cord_t length_corr = 0;
cord_t corner_size = 0;
@@ -831,7 +816,7 @@ static void lv_draw_rect_border_straight(const area_t * cords_p, const area_t *
/* Modify the corner_size if corner is drawn */
corner_size ++;
color_t b_color = rects_p->bcolor;
color_t b_color = style_p->bcolor;
/*Left border*/
work_area.x1 = cords_p->x1;
@@ -920,12 +905,12 @@ static void lv_draw_rect_border_straight(const area_t * cords_p, const area_t *
* @param rects_p pointer to a rectangle style
* @param opa opacity of the rectangle (0..255)
*/
static void lv_draw_rect_border_corner(const area_t * cords_p, const area_t * mask_p, const lv_rects_t * rects_p)
static void lv_draw_rect_border_corner(const area_t * cords_p, const area_t * mask_p, const lv_style_t * style)
{
uint16_t radius = rects_p->radius;
uint16_t bwidth = rects_p->bwidth;
color_t bcolor = rects_p->bcolor;
opa_t bopa = (uint16_t)((uint16_t) rects_p->base.opa * rects_p->bopa ) >> 8;
uint16_t radius = style->radius;
uint16_t bwidth = style->bwidth;
color_t bcolor = style->bcolor;
opa_t bopa = (uint16_t)((uint16_t) style->opa * style->bopa ) >> 8;
/*0 px border width drawn as 1 px, so decrement the bwidth*/
bwidth--;

View File

@@ -9,14 +9,9 @@
/*********************
* INCLUDES
*********************/
#include "../lv_objx/lv_btn.h"
#include "../lv_objx/lv_rect.h"
#include "../lv_objx/lv_line.h"
#include "../lv_objx/lv_img.h"
#include "../lv_objx/lv_label.h"
#include "misc_conf.h"
#include "../lv_misc/text.h"
#include "../lv_obj/lv_style.h"
/*********************
* DEFINES
@@ -34,10 +29,10 @@
* Draw a rectangle
* @param cords_p the coordinates of the rectangle
* @param mask_p the rectangle will be drawn only in this mask
* @param rects_p pointer to a rectangle style
* @param style_p pointer to a style
*/
#if USE_LV_RECT != 0
void lv_draw_rect(const area_t * cords_p, const area_t * mask_p, const lv_rects_t * rects_p);
void lv_draw_rect(const area_t * cords_p, const area_t * mask_p, const lv_style_t * style_p);
#endif
@@ -57,12 +52,12 @@ void lv_draw_triangle(const point_t * points, const area_t * mask_p, color_t col
* Write a text
* @param cords_p coordinates of the label
* @param mask_p the label will be drawn only in this area
* @param labels_p pointer to a label style
* @param style_p pointer to a style
* @param txt 0 terminated text to write
* @param flags settings for the text from 'txt_flag_t' enum
*/
#if USE_LV_LABEL != 0
void lv_draw_label(const area_t * cords_p,const area_t * mask_p, const lv_labels_t * style,
void lv_draw_label(const area_t * cords_p,const area_t * mask_p, const lv_style_t * style_p,
const char * txt, txt_flag_t flag);
#endif
@@ -74,7 +69,7 @@ void lv_draw_label(const area_t * cords_p,const area_t * mask_p, const lv_labels
*/
#if USE_LV_IMG != 0 && USE_FSINT != 0 && USE_UFS != 0
void lv_draw_img(const area_t * cords_p, const area_t * mask_p,
const lv_imgs_t * imgs_p, const char * fn);
const lv_style_t * style_p, const char * fn);
#endif
/**
@@ -82,11 +77,11 @@ void lv_draw_img(const area_t * cords_p, const area_t * mask_p,
* @param p1 first point of the line
* @param p2 second point of the line
* @param mask_pthe line will be drawn only on this area
* @param lines_p pointer to a line style
* @param style_p pointer to a style
*/
#if USE_LV_LINE != 0
void lv_draw_line(const point_t * p1, const point_t * p2, const area_t * mask_p,
const lv_lines_t * lines_p);
const lv_style_t * style_p);
#endif
/**********************

View File

@@ -429,7 +429,7 @@ static void dispi_drag(lv_dispi_t * dispi_p)
/*Set the drag in progress flag if the object is really moved*/
if(lv_obj_get_x(drag_obj) != act_x || lv_obj_get_y(drag_obj) != act_y) {
if(dispi_p->drag_range_out == 0) { /*Send the drag begin signal on first move*/
if(dispi_p->drag_range_out != 0) { /*Send the drag begin signal on first move*/
drag_obj->signal_f(drag_obj, LV_SIGNAL_DRAG_BEGIN, dispi_p);
}
dispi_p->drag_in_prog = 1;

View File

@@ -35,8 +35,8 @@
**********************/
static void lv_obj_pos_child_refr(lv_obj_t * obj, cord_t x_diff, cord_t y_diff);
static void lv_style_refr_core(void * style_p, lv_obj_t * obj);
static void lv_child_refr_style(lv_obj_t * obj);
static void lv_obj_del_child(lv_obj_t * obj);
static void lv_objs_init(void);
static bool lv_obj_design(lv_obj_t * obj, const area_t * mask_p, lv_design_mode_t mode);
/**********************
@@ -46,11 +46,6 @@ static lv_obj_t * def_scr = NULL;
static lv_obj_t * act_scr = NULL;
static ll_dsc_t scr_ll;
static lv_objs_t lv_objs_scr;
static lv_objs_t lv_objs_plain;
static lv_objs_t lv_objs_transp;
#ifdef LV_IMG_DEF_WALLPAPER
LV_IMG_DECLARE(LV_IMG_DEF_WALLPAPER);
#endif
@@ -72,6 +67,9 @@ void lv_init(void)
area_t scr_area;
area_set(&scr_area, 0, 0, LV_HOR_RES, LV_VER_RES);
lv_rfill(&scr_area, NULL, COLOR_BLACK, OPA_COVER);
/*Init. the sstyles*/
lv_style_init();
/*Init. the screen refresh system*/
lv_refr_init();
@@ -136,7 +134,7 @@ lv_obj_t * lv_obj_create(lv_obj_t * parent, lv_obj_t * copy)
new_obj->ext_size = 0;
/*Set appearance*/
new_obj->style_p = lv_objs_get(LV_OBJS_SCR, NULL);
new_obj->style_p = lv_style_get(LV_STYLE_PLAIN, NULL);
/*Set virtual functions*/
lv_obj_set_signal_f(new_obj, lv_obj_signal);
@@ -178,7 +176,7 @@ lv_obj_t * lv_obj_create(lv_obj_t * parent, lv_obj_t * copy)
new_obj->ext_size = 0;
/*Set appearance*/
new_obj->style_p = lv_objs_get(LV_OBJS_PLAIN, NULL);
new_obj->style_p = lv_style_get(LV_STYLE_PLAIN, NULL);
/*Set virtual functions*/
lv_obj_set_signal_f(new_obj, lv_obj_signal);
@@ -319,43 +317,6 @@ bool lv_obj_signal(lv_obj_t * obj, lv_signal_t sign, void * param)
return valid;
}
/**
* Return with a pointer to built-in style and/or copy it to a variable
* @param style a style name from lv_objs_builtin_t enum
* @param copy_p copy the style to this variable. (NULL if unused)
* @return pointer to an lv_objs_t style
*/
lv_objs_t * lv_objs_get(lv_objs_builtin_t style, lv_objs_t * copy_p)
{
static bool style_inited = false;
/*Make the style initialization if it is not done yet*/
if(style_inited == false) {
lv_objs_init();
style_inited = true;
}
lv_objs_t * style_p;
switch(style) {
case LV_OBJS_SCR:
style_p = &lv_objs_scr;
break;
case LV_OBJS_PLAIN:
style_p = &lv_objs_plain;
break;
case LV_OBJS_TRANSP:
style_p = &lv_objs_transp;
break;
default:
style_p = NULL;
}
if(copy_p != NULL) memcpy(copy_p, style_p, sizeof(lv_objs_t));
return style_p;
}
/**
* Mark the object as invalid therefore its current position will be redrawn by 'lv_refr_task'
@@ -807,20 +768,17 @@ void lv_obj_set_ext_size(lv_obj_t * obj, cord_t ext_size)
* @param obj pointer to an object
* @param style_p pointer to the new style
*/
void lv_obj_set_style(lv_obj_t * obj, void * style)
void lv_obj_set_style(lv_obj_t * obj, lv_style_t * style)
{
lv_obj_inv(obj);
if(obj->style_iso != 0) {
dm_free(obj->style_p);
obj->style_iso = 0;
}
obj->style_p = style;
/*Send a style change signal to the object*/
lv_obj_refr_style(obj);
/*Send a signal about style change to every children with NULL style*/
lv_child_refr_style(obj);
lv_obj_inv(obj);
}
/**
@@ -1277,13 +1235,24 @@ cord_t lv_obj_getext_size(lv_obj_t * obj)
*---------------*/
/**
* Get the style pointer of an object
* Get the style pointer of an object (if NULL get style of the parent)
* @param obj pointer to an object
* @return pointer to a style
*/
void * lv_obj_get_style(lv_obj_t * obj)
lv_style_t * lv_obj_get_style(lv_obj_t * obj)
{
return obj->style_p;
if(obj->style_p != NULL) return obj->style_p;
else {
lv_obj_t * par = obj->par;
while(par != NULL) {
if(par->style_p != NULL) return par->style_p;
par = par->par;
}
}
/*Never reach this, at least the screen has to be a style*/
return NULL;
}
/*-----------------
@@ -1460,13 +1429,13 @@ static bool lv_obj_design(lv_obj_t * obj, const area_t * mask_p, lv_design_mode
cover = area_is_in(mask_p, &obj->cords);
return cover;
} else if(mode == LV_DESIGN_DRAW_MAIN) {
lv_objs_t * style = lv_obj_get_style(obj);
lv_style_t * style = lv_obj_get_style(obj);
/*Simply draw a rectangle*/
#if LV_VDB_SIZE == 0
lv_rfill(&obj->cords, mask_p, style->color, style->opa);
#else
lv_vfill(&obj->cords, mask_p, style->color, style->opa);
lv_vfill(&obj->cords, mask_p, style->mcolor, style->opa);
#endif
}
return true;
@@ -1509,6 +1478,26 @@ static void lv_style_refr_core(void * style_p, lv_obj_t * obj)
}
}
/**
* Recursively refresh the style of the children. Go deeper until a not NULL style is found
* because the NULL styles are inherited from the parent
* @param obj pointer to an object
*/
static void lv_child_refr_style(lv_obj_t * obj)
{
lv_obj_t * child = lv_obj_get_child(obj, NULL);
while(child != NULL) {
if(child->style_p == NULL) {
lv_child_refr_style(child);
}
child = lv_obj_get_child(obj, child);
}
/*Send a style change signal to the object*/
lv_obj_refr_style(obj);
}
/**
* Called by 'lv_obj_del' to delete the children objects
* @param obj pointer to an object (all of its children will be deleted)
@@ -1547,15 +1536,3 @@ static void lv_obj_del_child(lv_obj_t * obj)
dm_free(obj); /*Free the object itself*/
}
static void lv_objs_init(void)
{
lv_objs_scr.color = LV_OBJ_DEF_SCR_COLOR;
lv_objs_scr.opa = OPA_COVER;
lv_objs_plain.color =COLOR_MAKE(0x88, 0xaf, 0xcb);
lv_objs_plain.opa = OPA_COVER;
lv_objs_transp.color = lv_objs_plain.color;
lv_objs_transp.opa = OPA_TRANSP;
}

View File

@@ -15,6 +15,7 @@
#include "misc/mem/dyn_mem.h"
#include "misc/mem/linked_list.h"
#include "misc/others/color.h"
#include "lv_style.h"
/*********************
* DEFINES
@@ -85,7 +86,7 @@ typedef struct __LV_OBJ_T
lv_design_f_t design_f;
void * ext; /*The object attributes can be extended here*/
void * style_p; /*Object specific style*/
lv_style_t * style_p; /*Object specific style*/
#if LV_OBJ_FREE_P != 0
void * free_p; /*Application specific pointer (set it freely)*/
@@ -151,13 +152,6 @@ typedef struct
opa_t opa;
}lv_objs_t;
typedef enum
{
LV_OBJS_SCR,
LV_OBJS_PLAIN,
LV_OBJS_TRANSP,
}lv_objs_builtin_t;
typedef enum
{
LV_ANIM_NONE = 0,
@@ -221,14 +215,6 @@ void lv_obj_del(lv_obj_t * obj);
*/
bool lv_obj_signal(lv_obj_t * obj, lv_signal_t sign, void * param);
/**
* Return with a pointer to built-in style and/or copy it to a variable
* @param style a style name from lv_objs_builtin_t enum
* @param copy_p copy the style to this variable. (NULL if unused)
* @return pointer to an lv_objs_t style
*/
lv_objs_t * lv_objs_get(lv_objs_builtin_t style, lv_objs_t * copy_p);
/**
* Load a new screen
* @param scr pointer to a screen
@@ -365,7 +351,7 @@ void lv_obj_set_ext_size(lv_obj_t * obj, cord_t ext_size);
* @param obj pointer to an object
* @param style_p pointer to the new style
*/
void lv_obj_set_style(lv_obj_t * obj, void * style);
void lv_obj_set_style(lv_obj_t * obj, lv_style_t * style);
/**
* Isolate the style of an object. In other words a unique style will be created
@@ -570,7 +556,7 @@ cord_t lv_obj_getext_size(lv_obj_t * obj);
* @param obj pointer to an object
* @return pointer to a style
*/
void * lv_obj_get_style(lv_obj_t * obj);
lv_style_t * lv_obj_get_style(lv_obj_t * obj);
/**
* Get the hidden attribute of an object
@@ -676,7 +662,4 @@ void * lv_obj_get_free_p(lv_obj_t * obj);
* MACROS
**********************/
#define LV_SA(obj, style_type) ((style_type *) obj->style_p)
#define LV_EA(obj, ext_type) ((ext_type *) obj->ext)
#endif

View File

@@ -316,7 +316,8 @@ static lv_obj_t * lv_refr_get_top_obj(const area_t * area_p, lv_obj_t * obj)
/*If no better children check this object*/
if(found_p == NULL) {
if(((lv_objs_t *)obj->style_p)->opa == OPA_COVER &&
lv_style_t * style = lv_obj_get_style(obj);
if(style->opa == OPA_COVER &&
obj->design_f(obj, area_p, LV_DESIGN_COVER_CHK) != false) {
found_p = obj;
}
@@ -401,8 +402,9 @@ static void lv_refr_obj(lv_obj_t * obj, const area_t * mask_ori_p)
/*Draw the parent and its children only if they ore on 'mask_parent'*/
if(union_ok != false) {
/* Redraw the object */
if(((lv_objs_t *)obj->style_p)->opa != OPA_TRANSP) {
/* Redraw the object */
lv_style_t * style = lv_obj_get_style(obj);
if(style->opa != OPA_TRANSP) {
obj->design_f(obj, &obj_ext_mask, LV_DESIGN_DRAW_MAIN);
/* tick_wait_ms(100); */ /*DEBUG: Wait after every object draw to see the order of drawing*/
}
@@ -435,7 +437,7 @@ static void lv_refr_obj(lv_obj_t * obj, const area_t * mask_ori_p)
}
/* If all the children are redrawn make 'post draw' design */
if(((lv_objs_t *)obj->style_p)->opa != OPA_TRANSP) {
if(style->opa != OPA_TRANSP) {
obj->design_f(obj, &obj_ext_mask, LV_DESIGN_DRAW_POST);
}
}

643
lv_obj/lv_style.c Normal file
View File

@@ -0,0 +1,643 @@
/**
* @file lv_style.c
*
*/
/*********************
* INCLUDES
*********************/
#include "lv_conf.h"
#include "lv_style.h"
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
/**********************
* STATIC VARIABLES
**********************/
static lv_style_t lv_style_scr;
static lv_style_t lv_style_transp;
static lv_style_t lv_style_transp_tight;
static lv_style_t lv_style_plain;
static lv_style_t lv_style_plain_color;
static lv_style_t lv_style_pretty;
static lv_style_t lv_style_pretty_color;
static lv_style_t lv_style_focus;
static lv_style_t lv_style_focus_color;
static lv_style_t lv_style_btn_rel;
static lv_style_t lv_style_btn_pr;
static lv_style_t lv_style_btn_trel;
static lv_style_t lv_style_btn_tpr;
static lv_style_t lv_style_btn_ina;
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
/**
* Init the basic styles
*/
void lv_style_init (void)
{
/*Screen style*/
lv_style_set_ccolor(&lv_style_scr, COLOR_MAKE(0x20, 0x20, 0x20));
lv_style_set_opa(&lv_style_scr, OPA_COVER);
lv_style_set_opa_prop(&lv_style_scr, true);
lv_style_set_mcolor(&lv_style_scr, COLOR_WHITE);
lv_style_set_gcolor(&lv_style_scr, COLOR_WHITE);
lv_style_set_bcolor(&lv_style_scr, COLOR_MAKE(0x20, 0x20 ,0x20));
lv_style_set_scolor(&lv_style_scr, COLOR_GRAY);
lv_style_set_radius(&lv_style_scr, 0);
lv_style_set_bwidth(&lv_style_scr, LV_DPI / 30 >= 1 ? LV_DPI / 30 >= 1 : 1);
lv_style_set_swidth(&lv_style_scr, 0);
lv_style_set_vpad(&lv_style_scr, LV_DPI / 6);
lv_style_set_hpad(&lv_style_scr, LV_DPI / 6);
lv_style_set_opad(&lv_style_scr, LV_DPI / 6);
lv_style_set_bopa(&lv_style_scr, OPA_COVER);
lv_style_set_empty(&lv_style_scr, false);
lv_style_set_font(&lv_style_scr, font_get(LV_FONT_DEFAULT));
lv_style_set_letter_space(&lv_style_scr, 1 * LV_DOWNSCALE);
lv_style_set_line_space(&lv_style_scr, 5 * LV_DOWNSCALE);
lv_style_set_txt_align(&lv_style_scr, 0);
lv_style_set_img_recolor(&lv_style_scr, OPA_TRANSP);
lv_style_set_line_width(&lv_style_scr, 1 * LV_DOWNSCALE);
/*Plain style (by default the same as the screen style)*/
memcpy(&lv_style_plain, &lv_style_scr, sizeof(lv_style_t));
/*Plain color style*/
memcpy(&lv_style_plain_color, &lv_style_plain, sizeof(lv_style_t));
lv_style_set_ccolor(&lv_style_plain_color, COLOR_SILVER);
lv_style_set_mcolor(&lv_style_plain_color, COLOR_CYAN);
lv_style_set_gcolor(&lv_style_plain_color, COLOR_CYAN);
/*Pretty style */
memcpy(&lv_style_pretty, &lv_style_plain, sizeof(lv_style_t));
lv_style_set_mcolor(&lv_style_pretty, COLOR_WHITE);
lv_style_set_mcolor(&lv_style_pretty, COLOR_SILVER);
lv_style_set_radius(&lv_style_pretty, LV_DPI / 10);
/*Pretty color style*/
memcpy(&lv_style_pretty_color, &lv_style_pretty, sizeof(lv_style_t));
lv_style_set_mcolor(&lv_style_pretty_color, COLOR_WHITE);
lv_style_set_mcolor(&lv_style_pretty_color, COLOR_CYAN);
/*Transparent style*/
memcpy(&lv_style_transp, &lv_style_plain, sizeof(lv_style_t));
lv_style_set_empty(&lv_style_transp, true);
lv_style_set_bwidth(&lv_style_transp, 0);
/*Transparent tight style*/
memcpy(&lv_style_transp_tight, &lv_style_transp, sizeof(lv_style_t));
lv_style_set_hpad(&lv_style_transp_tight, 0);
lv_style_set_vpad(&lv_style_transp_tight, 0);
/*Button released style*/
memcpy(&lv_style_btn_rel, &lv_style_plain, sizeof(lv_style_t));
lv_style_set_mcolor(&lv_style_btn_rel, COLOR_WHITE);
lv_style_set_gcolor(&lv_style_btn_rel, COLOR_GRAY);
/*Button pressed style*/
memcpy(&lv_style_btn_pr, &lv_style_btn_rel, sizeof(lv_style_t));
lv_style_set_mcolor(&lv_style_btn_pr, COLOR_BLACK);
lv_style_set_ccolor(&lv_style_btn_pr, COLOR_SILVER);
lv_style_set_scolor(&lv_style_btn_pr, COLOR_GRAY);
lv_style_set_swidth(&lv_style_btn_pr, 10);
/*Button toggle released style*/
memcpy(&lv_style_btn_trel, &lv_style_btn_rel, sizeof(lv_style_t));
lv_style_set_mcolor(&lv_style_btn_trel, COLOR_LIME);
/*Button toggle pressed style*/
memcpy(&lv_style_btn_tpr, &lv_style_btn_rel, sizeof(lv_style_t));
lv_style_set_mcolor(&lv_style_btn_tpr, COLOR_GREEN);
/*Button inactive style*/
memcpy(&lv_style_btn_ina, &lv_style_btn_rel, sizeof(lv_style_t));
lv_style_set_mcolor(&lv_style_btn_ina, COLOR_YELLOW);
}
/**
* Get style from its name
* @param style_name an element of the 'lv_style_name_t' enum
* @return pointer to the requested style (lv_style_def by default)
*/
lv_style_t * lv_style_get(lv_style_name_t style_name, lv_style_t * copy)
{
lv_style_t * style = &lv_style_plain;
switch(style_name) {
case LV_STYLE_SCR:
style = &lv_style_scr;
break;
case LV_STYLE_PLAIN:
style = &lv_style_plain;
break;
case LV_STYLE_PLAIN_COLOR:
style = &lv_style_plain_color;
break;
case LV_STYLE_PRETTY:
style = &lv_style_pretty;
break;
case LV_STYLE_PRETTY_COLOR:
style = &lv_style_pretty_color;
break;
case LV_STYLE_TRANSP:
style = &lv_style_transp;
break;
case LV_STYLE_TRANSP_TIGHT:
style = &lv_style_transp_tight;
break;
case LV_STYLE_BTN_REL:
style = &lv_style_btn_rel;
break;
case LV_STYLE_BTN_PR:
style = &lv_style_btn_pr;
break;
case LV_STYLE_BTN_TREL:
style = &lv_style_btn_trel;
break;
case LV_STYLE_BTN_TPR:
style = &lv_style_btn_tpr;
break;
case LV_STYLE_BTN_INA:
style = &lv_style_btn_ina;
break;
default:
style = &lv_style_plain;
}
if(copy != NULL) memcpy(copy, style, sizeof(lv_style_t));
return style;
}
/**
* Set the content color of a style
* @param style pointer to style
* @param ccolor content color
*/
void lv_style_set_ccolor(lv_style_t * style, color_t ccolor)
{
style->ccolor = ccolor;
}
/**
* Set the opacity of a style
* @param style pointer to style
* @param opa opacity (OPA_COVER, OPA_TRANSP, OPA_10, OPA_20 ... OPA_90)
*/
void lv_style_set_opa(lv_style_t * style, opa_t opa)
{
style->opa = opa;
}
/**
* Set the proportional opacity attribute of a style (make the opacity relative to the parent)
* @param style pointer to style
* @param opa_prop true: enabled, false: disabled
*/
void lv_style_set_opa_prop(lv_style_t * style, bool opa_prop)
{
style->opa_prop = opa_prop == false ? 0 : 1;
}
/**
* Set the container main color of a style
* @param style pointer to style
* @param mcolor main color of the background
*/
void lv_style_set_mcolor(lv_style_t * style, color_t mcolor)
{
style->mcolor = mcolor;
}
/**
* Set the container gradient color of a style
* @param style pointer to style
* @param gcolor gradient color of the background
*/
void lv_style_set_gcolor(lv_style_t * style, color_t gcolor)
{
style->gcolor = gcolor;
}
/**
* Set the container border color of a style
* @param style pointer to style
* @param bcolor border color of the background
*/
void lv_style_set_bcolor(lv_style_t * style, color_t bcolor)
{
style->bcolor = bcolor;
}
/**
* Set the container shadow color of a style
* @param style pointer to style
* @param scolor shadow color of the background
*/
void lv_style_set_scolor(lv_style_t * style, color_t scolor)
{
style->scolor = scolor;
}
/**
* Set the container corner radius of a style
* @param style pointer to style
* @param radius corner radius of the background (>= 0)
*/
void lv_style_set_radius(lv_style_t * style, cord_t radius)
{
style->radius = radius;
}
/**
* Set the container border width of a style
* @param style pointer to style
* @param bwidth border width of the background (>= 0, 0 means no border)
*/
void lv_style_set_bwidth(lv_style_t * style, cord_t bwidth)
{
style->bwidth = bwidth;
}
/**
* Set the container shadow width of a style
* @param style pointer to style
* @param swidth shadow width of the background (>= 0, 0 means no shadow)
*/
void lv_style_set_swidth(lv_style_t * style, cord_t swidth)
{
style->swidth = swidth;
}
/**
* Set the container vertical padding of a style
* @param style pointer to style
* @param vpad vertical padding on the background
*/
void lv_style_set_vpad(lv_style_t * style, cord_t vpad)
{
style->vpad = vpad;
}
/**
* Set the container horizontal padding of a style
* @param style pointer to style
* @param hpad horizontal padding on the background
*/
void lv_style_set_hpad(lv_style_t * style, cord_t hpad)
{
style->hpad = hpad;
}
/**
* Set the container object padding of a style
* @param style pointer to style
* @param opad padding between objects on the background
*/
void lv_style_set_opad(lv_style_t * style, cord_t opad)
{
style->opad = opad;
}
/**
* Set the container border opacity of a style (relative to the object opacity)
* @param style pointer to style
* @param bopa border opacity of the background (OPA_COVER, OPA_TRANSP, OPA_10, OPA_20 ... OPA_90)
*/
void lv_style_set_bopa(lv_style_t * style, opa_t bopa)
{
style->bopa = bopa;
}
/**
* Set container empty attribute of a style (transparent background but border drawn)
* @param style pointer to style
* @param empty true: empty enable, false: empty disable
*/
void lv_style_set_empty(lv_style_t * style, bool empty)
{
style->empty = empty == false ? 0 : 1;
}
/**
* Set the font of a style
* @param style pointer to style
* @param font pointer to a fint
*/
void lv_style_set_font(lv_style_t * style, const font_t * font)
{
style->font = font;
}
/**
* Set the letter space of a style
* @param style pointer to style
* @param letter_space new letter space
*/
void lv_style_set_letter_space(lv_style_t * style, cord_t letter_space)
{
style->letter_space = letter_space;
}
/**
* Set the line space of a style
* @param style pointer to style
* @param line_space new letter space
*/
void lv_style_set_line_space(lv_style_t * style, cord_t line_space)
{
style->line_space = line_space;
}
/**
* Set the text align of a style
* @param style pointer to style
* @param align TODO
*/
void lv_style_set_txt_align(lv_style_t * style, uint8_t align)
{
style->txt_align = align;
}
/**
* Set the image re-color intensity of a style
* @param style pointer to style
* @param recolor re-coloring intensity (OPA_TRANSP: do nothing, OPA_COVER: fully re-color, OPA_10: little re-color)
*/
void lv_style_set_img_recolor(lv_style_t * style, opa_t recolor)
{
style->img_recolor = recolor;
}
/**
* Set the line width of a style
* @param style pointer to style
* @param width new line width (>=0)
*/
void lv_style_set_line_width(lv_style_t * style, cord_t width)
{
style->line_width = width;
}
/*************************
* GET FUNTIONS
*************************/
/**
* Get the content color of a style
* @param style pointer to style
* @return content color
*/
color_t lv_style_get_ccolor(lv_style_t * style)
{
return style->ccolor;
}
/**
* Get the opacity of a style
* @param style pointer to style
* @return opacity (OPA_COVER, OPA_TRANSP, OPA_10, OPA_20 ... OPA_90)
*/
opa_t lv_style_get_opa(lv_style_t * style)
{
return style->opa;
}
/**
* Get the proportional opacity attribute of a style (make the opacity relative to the parent)
* @param style pointer to style
* @return true: enabled, false: disabled
*/
bool lv_style_get_opa_prop(lv_style_t * style)
{
return style->opa_prop == 0 ? false : true;
}
/**
* Get the container main color of a style
* @param style pointer to style
* @return main color of the background
*/
color_t lv_style_get_mcolor(lv_style_t * style)
{
return style->mcolor;
}
/**
* Get the container gradient color of a style
* @param style pointer to style
* @return gradient color of the background
*/
color_t lv_style_get_gcolor(lv_style_t * style)
{
return style->gcolor;
}
/**
* Get the container border color of a style
* @param style pointer to style
* @return border color of the background
*/
color_t lv_style_get_bcolor(lv_style_t * style)
{
return style->bcolor;
}
/**
* Get the container shadow color of a style
* @param style pointer to style
* @return shadow color of the background
*/
color_t lv_style_get_Scolor(lv_style_t * style)
{
return style->scolor;
}
/**
* Get the container corner radius of a style
* @param style pointer to style
* @return corner radius of the background (>= 0)
*/
cord_t lv_style_get_radius(lv_style_t * style)
{
return style->radius;
}
/**
* Get the container border width of a style
* @param style pointer to style
* @return border width of the background (>= 0, 0 means no border)
*/
cord_t lv_style_get_bwidth(lv_style_t * style)
{
return style->bwidth;
}
/**
* Get the container shadow width of a style
* @param style pointer to style
* @return shadow width of the background (>= 0, 0 means no shadow)
*/
cord_t lv_style_get_swidth(lv_style_t * style)
{
return style->swidth;
}
/**
* Get the container vertical padding of a style
* @param style pointer to style
* @return vertical padding on the background
*/
cord_t lv_style_get_vpad(lv_style_t * style)
{
return style->vpad;
}
/**
* Get the container horizontal padding of a style
* @param style pointer to style
* @return horizontal padding on the background
*/
cord_t lv_style_get_hpad(lv_style_t * style)
{
return style->hpad;
}
/**
* Get the container object padding of a style
* @param style pointer to style
* @return padding between objects on the background
*/
cord_t lv_style_get_opad(lv_style_t * style)
{
return style->opad;
}
/**
* Get the container border opacity of a style (relative to the object opacity)
* @param style pointer to style
* @return border opacity of the background (OPA_COVER, OPA_TRANSP, OPA_10, OPA_20 ... OPA_90)
*/
opa_t lv_style_get_bopa(lv_style_t * style)
{
return style->bopa;
}
/**
* Get container empty attribute of a style (transparent background but border drawn)
* @param style pointer to style
* @return true: empty enable, false: empty disable
*/
bool lv_style_get_empty(lv_style_t * style, bool empty)
{
return style->empty == false ? 0 : 1;
}
/**
* Get the font of a style
* @param style pointer to style
* @return pointer to a fint
*/
const font_t * lv_style_get_font(lv_style_t * style)
{
return style->font;
}
/**
* Get the letter space of a style
* @param style pointer to style
* @return new letter space
*/
cord_t lv_style_get_letter_space(lv_style_t * style)
{
return style->letter_space;
}
/**
* Get the line space of a style
* @param style pointer to style
* @return new letter space
*/
cord_t lv_style_get_line_space(lv_style_t * style)
{
return style->line_space;
}
/**
* Get the text align of a style
* @param style pointer to style
* @return TODO
*/
uint8_t lv_style_get_txt_align(lv_style_t * style)
{
return style->txt_align;
}
/**
* Get the image re-color intensity of a style
* @param style pointer to style
* @return re-coloring intensity (OPA_TRANSP: do nothing, OPA_COVER: fully re-color, OPA_10: little re-color)
*/
opa_t lv_style_get_img_recolor(lv_style_t * style)
{
return style->img_recolor;
}
/**
* Get the line width of a style
* @param style pointer to style
* @return new line width (>=0)
*/
cord_t lv_style_get_line_width(lv_style_t * style)
{
return style->line_width;
}
/**********************
* STATIC FUNCTIONS
**********************/

361
lv_obj/lv_style.h Normal file
View File

@@ -0,0 +1,361 @@
/**
* @file lv_style.h
*
*/
#ifndef LV_STYLE_H
#define LV_STYLE_H
/*********************
* INCLUDES
*********************/
#include <stdbool.h>
#include "misc/others/color.h"
#include "../lv_misc/area.h"
#include "../lv_misc/font.h"
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
typedef struct
{
/*Object level styles*/
color_t ccolor; /*Content color (e.g. text or image re-color )*/
opa_t opa; /*Opacity of the object*/
uint8_t opa_prop:1; /*Opacity is proportional to the parent*/
uint8_t empty :1; /*Transparent background (border drawn)*/
color_t mcolor; /*Main color of background*/
color_t gcolor; /*Gradient color of background*/
color_t bcolor; /*Border color of background*/
color_t scolor; /*Shadow color of background*/
cord_t radius; /*Corner radius of background*/
cord_t bwidth; /*Width of the background border*/
cord_t swidth; /*Width of the background shadow effect*/
cord_t vpad; /*Vertical padding*/
cord_t hpad; /*Horizontal padding*/
cord_t opad; /*Object padding on the background*/
opa_t bopa; /*Opacity of background border*/
const font_t * font;
cord_t letter_space;
cord_t line_space;
uint8_t txt_align;
opa_t img_recolor;
cord_t line_width;
}lv_style_t;
typedef enum {
LV_STYLE_SCR,
LV_STYLE_TRANSP,
LV_STYLE_TRANSP_TIGHT,
LV_STYLE_PLAIN,
LV_STYLE_PLAIN_COLOR,
LV_STYLE_PRETTY,
LV_STYLE_PRETTY_COLOR,
LV_STYLE_BTN_REL,
LV_STYLE_BTN_PR,
LV_STYLE_BTN_TREL,
LV_STYLE_BTN_TPR,
LV_STYLE_BTN_INA,
}lv_style_name_t;
/**********************
* GLOBAL PROTOTYPES
**********************/
/**
* Init the basic styles
*/
void lv_style_init (void);
/**
* Get style from its name
* @param style_name an element of the 'lv_style_name_t' enum
* @return pointer to the requested style (lv_style_def by default)
*/
lv_style_t * lv_style_get(lv_style_name_t style_name, lv_style_t * copy);
/**
* Inherit all not set attributes of child style from a parent style
* @param result pointer to a 'lv_style_t' variable to store the result style
* @param child pointer to a child style. (if NULL 'lv_style_def' will be used)
* @param parent pointer to a parent style (if NULL 'lv_style_def' will be used)
*/
lv_style_t * lv_style_inherit(lv_style_t * result, const lv_style_t * child, const lv_style_t * parent );
/**
* Set the content color of a style
* @param style pointer to style
* @param ccolor content color
*/
void lv_style_set_ccolor(lv_style_t * style, color_t ccolor);
/**
* Clear the content color of a style (it will be inherited from the parent style)
* @param style pointer to a style
*/
void lv_style_clear_ccolor(lv_style_t * style);
/**
* Set the opacity of a style
* @param style pointer to style
* @param opa opacity (OPA_COVER, OPA_TRANSP, OPA_10, OPA_20 ... OPA_90)
*/
void lv_style_set_opa(lv_style_t * style, opa_t opa);
/**
* Clear the opacity of a style (it will be inherited from the parent style)
* @param style pointer to a style
*/
void lv_style_clear_opa(lv_style_t * style);
/**
* Set the proportional opacity attribute of a style (make the opacity relative to the parent)
* @param style pointer to style
* @param opa_prop true: enabled, false: disabled
*/
void lv_style_set_opa_prop(lv_style_t * style, bool opa_prop);
/**
* Clear the proportional opacity attribute of a style (it will be inherited from the parent style)
* @param style pointer to a style
*/
void lv_style_clear_opa_prop(lv_style_t * style);
/**
* Set the container main color of a style
* @param style pointer to style
* @param mcolor main color of the background
*/
void lv_style_set_mcolor(lv_style_t * style, color_t mcolor);
/**
* Clear the container main color of a style (it will be inherited from the parent style)
* @param style pointer to a style
*/
void lv_style_clear_mcolor(lv_style_t * style);
/**
* Set the container gradient color of a style
* @param style pointer to style
* @param gcolor gradient color of the background
*/
void lv_style_set_gcolor(lv_style_t * style, color_t gcolor);
/**
* Clear the container gradient color of a style (it will be inherited from the parent style)
* @param style pointer to a style
*/
void lv_style_clear_gcolor(lv_style_t * style);
/**
* Set the container border color of a style
* @param style pointer to style
* @param bcolor border color of the background
*/
void lv_style_set_bcolor(lv_style_t * style, color_t bcolor);
/**
* Clear the container border color of a style (it will be inherited from the parent style)
* @param style pointer to a style
*/
void lv_style_clear_bcolor(lv_style_t * style);
/**
* Set the container light (shadow effect) color of a style
* @param style pointer to style
* @param lcolor light (shadow) color of the background
*/
void lv_style_set_scolor(lv_style_t * style, color_t lcolor);
/**
* Set the container corner radius of a style
* @param style pointer to style
* @param radius corner radius of the background (>= 0)
*/
void lv_style_set_radius(lv_style_t * style, cord_t radius);
/**
* Clear the container radius of a style (it will be inherited from the parent style)
* @param style pointer to a style
*/
void lv_style_clear_radius(lv_style_t * style);
/**
* Set the container border width of a style
* @param style pointer to style
* @param bwidth border width of the background (>= 0, 0 means no border)
*/
void lv_style_set_bwidth(lv_style_t * style, cord_t bwidth);
/**
* Clear the container border width of a style (it will be inherited from the parent style)
* @param style pointer to a style
*/
void lv_style_clear_bwidth(lv_style_t * style);
/**
* Set the container shadow width of a style
* @param style pointer to style
* @param swidth shadow width of the background (>= 0, 0 means no shadow)
*/
void lv_style_set_swidth(lv_style_t * style, cord_t swidth);
/**
* Clear the container light (shadow) width of a style (it will be inherited from the parent style)
* @param style pointer to a style
*/
void lv_style_clear_lwidth(lv_style_t * style);
/**
* Set the container vertical padding of a style
* @param style pointer to style
* @param vpad vertical padding on the background
*/
void lv_style_set_vpad(lv_style_t * style, cord_t vpad);
/**
* Clear the container vertical padding of a style (it will be inherited from the parent style)
* @param style pointer to a style
*/
void lv_style_clear_vpad(lv_style_t * style);
/**
* Set the container horizontal padding of a style
* @param style pointer to style
* @param hpad horizontal padding on the background
*/
void lv_style_set_hpad(lv_style_t * style, cord_t hpad);
/**
* Clear the container horizontal padding of a style (it will be inherited from the parent style)
* @param style pointer to a style
*/
void lv_style_clear_hpad(lv_style_t * style);
/**
* Set the container object padding of a style
* @param style pointer to style
* @param opad padding between objects on the background
*/
void lv_style_set_opad(lv_style_t * style, cord_t opad);
/**
* Clear the container object padding of a style (it will be inherited from the parent style)
* @param style pointer to a style
*/
void lv_style_clear_opad(lv_style_t * style);
/**
* Set the container border opacity of a style (relative to the object opacity)
* @param style pointer to style
* @param bopa border opacity of the background (OPA_COVER, OPA_TRANSP, OPA_10, OPA_20 ... OPA_90)
*/
void lv_style_set_bopa(lv_style_t * style, opa_t bopa);
/**
* Clear the container border opacity of a style (it will be inherited from the parent style)
* @param style pointer to a style
*/
void lv_style_clear_bopa(lv_style_t * style);
/**
* Set container empty attribute of a style (transparent background but border drawn)
* @param style pointer to style
* @param empty true: empty enable, false: empty disable
*/
void lv_style_set_empty(lv_style_t * style, bool empty);
/**
* Clear the container empty attribute of a style (it will be inherited from the parent style)
* @param style pointer to a style
*/
void lv_style_clear_empty(lv_style_t * style);
/**
* Set the font of a style
* @param style pointer to style
* @param font pointer to a font
*/
void lv_style_set_font(lv_style_t * style, const font_t * font);
/**
* Clear the font of a style (it will be inherited from the parent style)
* @param style pointer to a style
*/
void lv_style_clear_font(lv_style_t * style);
/**
* Set the letter space of a style
* @param style pointer to style
* @param letter_space new letter space
*/
void lv_style_set_letter_space(lv_style_t * style, cord_t letter_space);
/**
* Clear the letter space of a style (it will be inherited from the parent style)
* @param style pointer to a style
*/
void lv_style_clear_letter_space(lv_style_t * style);
/**
* Set the line space of a style
* @param style pointer to style
* @param line_space new letter space
*/
void lv_style_set_line_space(lv_style_t * style, cord_t line_space);
/**
* Clear the line space of a style (it will be inherited from the parent style)
* @param style pointer to a style
*/
void lv_style_clear_line_space(lv_style_t * style);
/**
* Set the text align of a style
* @param style pointer to style
* @param align TODO
*/
void lv_style_set_txt_align(lv_style_t * style, uint8_t align);
/**
* Clear the text align of a style (it will be inherited from the parent style)
* @param style pointer to a style
*/
void lv_style_clear_txt_align(lv_style_t * style);
/**
* Set the image re-color intensity of a style
* @param style pointer to style
* @param recolor re-coloring intensity (OPA_TRANSP: do nothing, OPA_COVER: fully re-color, OPA_10: little re-color)
*/
void lv_style_set_img_recolor(lv_style_t * style, opa_t recolor);
/**
* Clear the image recolor of a style (it will be inherited from the parent style)
* @param style pointer to a style
*/
void lv_style_clear_img_recolor(lv_style_t * style);
/**
* Set the line width of a style
* @param style pointer to style
* @param width new line width (>=0)
*/
void lv_style_set_line_width(lv_style_t * style, cord_t width);
/**
* Clear the line width of a style (it will be inherited from the parent style)
* @param style pointer to a style
*/
void lv_style_clear_line_width(lv_style_t * style);
/**********************
* MACROS
**********************/
#endif

View File

@@ -31,12 +31,10 @@
* STATIC PROTOTYPES
**********************/
static bool lv_bar_design(lv_obj_t * bar, const area_t * mask, lv_design_mode_t mode);
static void lv_bars_init(void);
/**********************
* STATIC VARIABLES
**********************/
static lv_bars_t lv_bars_def;
static lv_design_f_t ancestor_design_f;
/**********************
@@ -71,6 +69,7 @@ lv_obj_t * lv_bar_create(lv_obj_t * par, lv_obj_t * copy)
ext->act_value = 0;
ext->format_str = NULL;
ext->label = NULL;
ext->style_indic = lv_style_get(LV_STYLE_PRETTY_COLOR, NULL);
/* Save the rectangle design function.
* It will be used in the bar design function*/
@@ -81,6 +80,8 @@ lv_obj_t * lv_bar_create(lv_obj_t * par, lv_obj_t * copy)
/*Init the new bar object*/
if(copy == NULL) {
ext->format_str = dm_alloc(strlen(LV_BAR_DEF_FORMAT) + 1);
strcpy(ext->format_str, LV_BAR_DEF_FORMAT);
@@ -89,7 +90,7 @@ lv_obj_t * lv_bar_create(lv_obj_t * par, lv_obj_t * copy)
lv_rect_set_layout(new_bar, LV_RECT_LAYOUT_CENTER);
lv_obj_set_click(new_bar, false);
lv_obj_set_size(new_bar, LV_BAR_DEF_WIDTH, LV_BAR_DEF_HEIGHT);
lv_obj_set_style(new_bar, lv_bars_get(LV_BARS_DEF, NULL));
lv_obj_set_style(new_bar, lv_style_get(LV_STYLE_PRETTY, NULL));
lv_bar_set_value(new_bar, ext->act_value);
} else {
@@ -99,13 +100,12 @@ lv_obj_t * lv_bar_create(lv_obj_t * par, lv_obj_t * copy)
ext->min_value = ext_copy->min_value;
ext->max_value = ext_copy->max_value;
ext->act_value = ext_copy->act_value;
ext->style_indic = ext_copy->style_indic;
ext->label = lv_label_create(new_bar, ext_copy->label);
/*Refresh the style with new signal function*/
lv_obj_refr_style(new_bar);
lv_bar_set_value(new_bar, ext->act_value);
}
return new_bar;
}
@@ -127,7 +127,7 @@ bool lv_bar_signal(lv_obj_t * bar, lv_signal_t sign, void * param)
* make the object specific signal handling */
if(valid != false) {
lv_bar_ext_t * ext = lv_obj_get_ext(bar);
lv_bars_t * style = lv_obj_get_style(bar);
lv_style_t * style = lv_obj_get_style(bar);
point_t p;
char buf[LV_BAR_TXT_MAX_LENGTH];
@@ -137,8 +137,7 @@ bool lv_bar_signal(lv_obj_t * bar, lv_signal_t sign, void * param)
ext->format_str = NULL;
break;
case LV_SIGNAL_STYLE_CHG:
lv_obj_set_style(ext->label, &style->label);
lv_bar_set_value(bar, lv_bar_get_value(bar));
lv_obj_set_style(ext->label, style);
break;
default:
break;
@@ -202,6 +201,20 @@ void lv_bar_set_format_str(lv_obj_t * bar, const char * format)
lv_bar_set_value(bar, ext->act_value);
}
/**
* Set the style of bar indicator
* @param bar pointer to a bar obeject
* @param style pointer to a style
*/
void lv_bar_set_style_indic(lv_obj_t * bar, lv_style_t * style)
{
lv_bar_ext_t * ext = lv_obj_get_ext(bar);
ext->style_indic = style;
lv_obj_inv(bar);
}
/*=====================
* Getter functions
*====================*/
@@ -218,34 +231,17 @@ int16_t lv_bar_get_value(lv_obj_t * bar)
}
/**
* Return with a pointer to a built-in style and/or copy it to a variable
* @param style a style name from lv_bars_builtin_t enum
* @param copy copy the style to this variable. (NULL if unused)
* @return pointer to an lv_bars_t style
* Get the style of bar indicator
* @param bar pointer to a bar object
* @return pointer to the bar indicator style
*/
lv_bars_t * lv_bars_get(lv_bars_builtin_t style, lv_bars_t * copy)
lv_style_t * lv_bar_get_style_indic(lv_obj_t * bar)
{
static bool style_inited = false;
lv_bar_ext_t * ext = lv_obj_get_ext(bar);
/*Make the style initialization if it is not done yet*/
if(style_inited == false) {
lv_bars_init();
style_inited = true;
}
if(ext->style_indic == NULL) return lv_obj_get_style(bar);
lv_bars_t *style_p;
switch(style) {
case LV_BARS_DEF:
style_p = &lv_bars_def;
break;
default:
style_p = &lv_bars_def;
}
if(copy != NULL) memcpy(copy, style_p, sizeof(lv_bars_t));
return style_p;
return ext->style_indic;
}
/**********************
@@ -274,9 +270,7 @@ static bool lv_bar_design(lv_obj_t * bar, const area_t * mask, lv_design_mode_t
ancestor_design_f(bar, mask, mode);
lv_bar_ext_t * ext = lv_obj_get_ext(bar);
lv_bars_t * style = lv_obj_get_style(bar);
area_t bar_area;
uint32_t tmp;
area_cpy(&bar_area, &bar->cords);
cord_t w = lv_obj_get_width(bar);
@@ -291,30 +285,10 @@ static bool lv_bar_design(lv_obj_t * bar, const area_t * mask, lv_design_mode_t
}
/*Draw the main bar*/
lv_draw_rect(&bar_area, mask, &style->indic);
lv_style_t * style_indic = lv_bar_get_style_indic(bar);
lv_draw_rect(&bar_area, mask, style_indic);
}
return true;
}
/**
* Initialize the bar styles
*/
static void lv_bars_init(void)
{
/*Default style*/
lv_rects_get(LV_RECTS_FANCY, &lv_bars_def.bg); /*Background*/
lv_bars_def.bg.base.color = COLOR_WHITE;
lv_bars_def.bg.gcolor = COLOR_SILVER,
lv_bars_def.bg.bcolor = COLOR_BLACK;
lv_rects_get(LV_RECTS_FANCY, &lv_bars_def.indic); /*Bar*/
lv_bars_def.indic.base.color = COLOR_LIME;
lv_bars_def.indic.gcolor = COLOR_GREEN;
lv_bars_def.indic.bcolor = COLOR_BLACK;
lv_bars_def.indic.swidth = 0;
lv_labels_get(LV_LABELS_TXT, &lv_bars_def.label); /*Label*/
lv_bars_def.label.line_space = 0;
}
#endif

View File

@@ -37,30 +37,16 @@
/*Data of bar*/
typedef struct
{
lv_rect_ext_t rect_ext; /*Ext. of ancestor*/
lv_rect_ext_t rect_ext; /*Ext. of ancestor*/
/*New data for this type */
lv_obj_t * label; /*Pointer to the label on the bar*/
int16_t act_value; /*Current value of the bar*/
int16_t min_value; /*Minimum value of the bar*/
int16_t max_value; /*Maximum value of the bar*/
char * format_str; /*Format string of the label. E.g. "Progress: %d"*/
lv_obj_t * label; /*Pointer to the label on the bar*/
int16_t act_value; /*Current value of the bar*/
int16_t min_value; /*Minimum value of the bar*/
int16_t max_value; /*Maximum value of the bar*/
char * format_str; /*Format string of the label. E.g. "Progress: %d"*/
lv_style_t * style_indic; /*Style of the indicator*/
}lv_bar_ext_t;
/*Style of bar*/
typedef struct
{
lv_rects_t bg; /*Style of the background (inherited)*/
lv_rects_t indic; /*Style of the indicator*/
lv_labels_t label; /*Style of the label*/
}lv_bars_t;
/*Built-in styles of bar*/
typedef enum
{
LV_BARS_DEF,
}lv_bars_builtin_t;
/**********************
* GLOBAL PROTOTYPES
**********************/
@@ -110,14 +96,8 @@ void lv_bar_set_format_str(lv_obj_t * bar, const char * format);
*/
int16_t lv_bar_get_value(lv_obj_t * bar);
/**
* Return with a pointer to a built-in style and/or copy it to a variable
* @param style a style name from lv_bars_builtin_t enum
* @param copy copy the style to this variable. (NULL if unused)
* @return pointer to an lv_bars_t style
*/
lv_bars_t * lv_bars_get(lv_bars_builtin_t style, lv_bars_t * copy);
lv_style_t * lv_bar_get_style_indic(lv_obj_t * bar);
void lv_bar_set_style_indic(lv_obj_t * bar, lv_style_t * style);
/**********************
* MACROS
**********************/

View File

@@ -31,14 +31,10 @@
**********************/
static bool lv_btn_design(lv_obj_t * btn, const area_t * mask, lv_design_mode_t mode);
static void lv_btns_init(void);
/**********************
* STATIC VARIABLES
**********************/
static lv_btns_t lv_btns_def;
static lv_btns_t lv_btns_border;
static lv_btns_t lv_btns_transp;
static lv_design_f_t ancestor_design_f;
@@ -70,6 +66,11 @@ lv_obj_t * lv_btn_create(lv_obj_t * par, lv_obj_t * copy)
ext->rel_action = NULL;
ext->lpr_action = NULL;
ext->lpr_rep_action = NULL;
ext->styles[LV_BTN_STATE_REL] = lv_style_get(LV_STYLE_BTN_REL, NULL);
ext->styles[LV_BTN_STATE_PR] = lv_style_get(LV_STYLE_BTN_PR, NULL);
ext->styles[LV_BTN_STATE_TREL] = lv_style_get(LV_STYLE_BTN_TREL, NULL);
ext->styles[LV_BTN_STATE_TPR] = lv_style_get(LV_STYLE_BTN_TPR, NULL);
ext->styles[LV_BTN_STATE_INA] = lv_style_get(LV_STYLE_BTN_INA, NULL);
ext->lpr_exec = 0;
ext->tgl = 0;
@@ -81,7 +82,7 @@ lv_obj_t * lv_btn_create(lv_obj_t * par, lv_obj_t * copy)
/*If no copy do the basic initialization*/
if(copy == NULL) {
lv_rect_set_layout(new_btn, LV_RECT_LAYOUT_CENTER);
lv_obj_set_style(new_btn, lv_btns_get(LV_BTNS_DEF, NULL));
lv_obj_set_style(new_btn, ext->styles[LV_BTN_STATE_REL]);
}
/*Copy 'copy'*/
else {
@@ -91,6 +92,11 @@ lv_obj_t * lv_btn_create(lv_obj_t * par, lv_obj_t * copy)
ext->rel_action = copy_ext->rel_action;
ext->lpr_action = copy_ext->lpr_action;
ext->lpr_rep_action = copy_ext->lpr_action;
ext->styles[LV_BTN_STATE_REL] = copy_ext->styles[LV_BTN_STATE_REL];
ext->styles[LV_BTN_STATE_PR] = copy_ext->styles[LV_BTN_STATE_PR];
ext->styles[LV_BTN_STATE_TREL] = copy_ext->styles[LV_BTN_STATE_TREL];
ext->styles[LV_BTN_STATE_TPR] = copy_ext->styles[LV_BTN_STATE_TPR];
ext->styles[LV_BTN_STATE_INA] = copy_ext->styles[LV_BTN_STATE_INA];
ext->tgl = copy_ext->tgl;
/*Refresh the style with new signal function*/
@@ -110,19 +116,14 @@ bool lv_btn_signal(lv_obj_t * btn, lv_signal_t sign, void * param)
{
bool valid;
/*On style change preload the style for the rectangle signal*/
lv_btn_ext_t * ext = lv_obj_get_ext(btn);
lv_btns_t * style = lv_obj_get_style(btn);
if(sign == LV_SIGNAL_STYLE_CHG) {
memcpy(&style->current, &style->state_style[ext->state], sizeof(lv_rects_t));
}
/* Include the ancient signal function */
valid = lv_rect_signal(btn, sign, param);
/* The object can be deleted so check its validity and then
* make the object specific signal handling */
if(valid != false) {
lv_btn_ext_t * ext = lv_obj_get_ext(btn);
lv_style_t * style = lv_obj_get_style(btn);
lv_btn_state_t state = lv_btn_get_state(btn);
bool tgl = lv_btn_get_tgl(btn);
@@ -185,7 +186,7 @@ bool lv_btn_signal(lv_obj_t * btn, lv_signal_t sign, void * param)
case LV_SIGNAL_LONG_PRESS:
/*Call the long press action, here 'param' is the caller dispi*/
if(ext->lpr_action != NULL && state != LV_BTN_STATE_INA) {
ext->lpr_exec = 1;
ext->lpr_exec = 1;
valid = ext->lpr_action(btn, param);
}
break;
@@ -230,9 +231,7 @@ void lv_btn_set_state(lv_obj_t * btn, lv_btn_state_t state)
lv_btn_ext_t * ext = lv_obj_get_ext(btn);
if(ext->state != state) {
ext->state = state;
lv_btns_t * style = lv_obj_get_style(btn);
memcpy(&style->current, &style->state_style[ext->state], sizeof(lv_rects_t));
lv_obj_refr_style(btn);
lv_obj_set_style(btn, ext->styles[state]);
}
}
@@ -284,6 +283,28 @@ void lv_btn_set_lpr_rep_action(lv_obj_t * btn, lv_action_t lpr_rep_action)
ext->lpr_rep_action = lpr_rep_action;
}
/**
* Set styles of a button is each state
* @param btn pointer to button object
* @param rel pointer to a style for releases state
* @param pr pointer to a style for pressed state
* @param trel pointer to a style for toggled releases state
* @param tpr pointer to a style for toggled pressed state
* @param ina pointer to a style for inactive state
*/
void lv_btn_set_styles(lv_obj_t * btn, lv_style_t * rel, lv_style_t * pr, lv_style_t * trel, lv_style_t * tpr, lv_style_t * ina)
{
lv_btn_ext_t * ext = lv_obj_get_ext(btn);
ext->styles[LV_BTN_STATE_REL] = rel;
ext->styles[LV_BTN_STATE_PR] = pr;
ext->styles[LV_BTN_STATE_TREL] = trel;
ext->styles[LV_BTN_STATE_TPR] = tpr;
ext->styles[LV_BTN_STATE_INA] = ina;
lv_obj_set_style(btn, ext->styles[ext->state]);
}
/*=====================
* Getter functions
*====================*/
@@ -313,42 +334,21 @@ bool lv_btn_get_tgl(lv_obj_t * btn)
}
/**
* Return with a pointer to a built-in style and/or copy it to a variable
* @param style a style name from lv_btns_builtin_t enum
* @param copy copy the style to this variable. (NULL if unused)
* @return pointer to an lv_btns_t style
* Get the style of a button in a given state
* @param btn pointer to a button object
* @param state a state from 'lv_btn_state_t' in which style should be get
* @return pointer to the style in the given state
*/
lv_btns_t * lv_btns_get(lv_btns_builtin_t style, lv_btns_t * copy)
lv_style_t * lv_btn_get_style(lv_obj_t * btn, lv_btn_state_t state)
{
static bool style_inited = false;
lv_btn_ext_t * ext = lv_obj_get_ext(btn);
/*Make the style initialization if it is not done yet*/
if(style_inited == false) {
lv_btns_init();
style_inited = true;
}
if(ext->styles[state] == NULL) return lv_obj_get_style(btn->par);
lv_btns_t * style_p;
switch(style) {
case LV_BTNS_DEF:
style_p = &lv_btns_def;
break;
case LV_BTNS_BORDER:
style_p = &lv_btns_border;
break;
case LV_BTNS_TRANSP:
style_p = &lv_btns_transp;
break;
default:
style_p = &lv_btns_def;
}
if(copy != NULL) memcpy(copy, style_p, sizeof(lv_btns_t));
return style_p;
return ext->styles[state];
}
/**********************
* STATIC FUNCTIONS
**********************/
@@ -367,85 +367,12 @@ static bool lv_btn_design(lv_obj_t * btn, const area_t * mask, lv_design_mode_t
/* Because of the radius it is not sure the area is covered*/
if(mode == LV_DESIGN_COVER_CHK) {
/*Temporally set a rectangle style for the button to look like as rectangle*/
lv_rects_t rects_tmp;
lv_btns_t * btns_tmp = lv_obj_get_style(btn);
lv_btn_ext_t * ext = lv_obj_get_ext(btn);
bool ret = false;
memcpy(&rects_tmp, &btns_tmp->state_style[ext->state], sizeof(lv_rects_t));
btn->style_p = &rects_tmp;
ret = ancestor_design_f(btn, mask, mode); /*Draw the rectangle*/
btn->style_p = btns_tmp; /*Reload the original button style*/
return ancestor_design_f(btn, mask, mode); /*Draw the rectangle*/
return ret;
} else if(mode == LV_DESIGN_DRAW_MAIN || mode == LV_DESIGN_DRAW_POST) {
area_t area;
lv_obj_get_cords(btn, &area);
/*Temporally set a rectangle style for the button to draw it as rectangle*/
lv_rects_t rects_tmp;
lv_btns_t * btns_tmp = lv_obj_get_style(btn);
lv_btn_ext_t * ext = lv_obj_get_ext(btn);
memcpy(&rects_tmp, &btns_tmp->state_style[ext->state], sizeof(lv_rects_t));
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;
}
/**
* Initialize the button styles
*/
static void lv_btns_init(void)
{
/*Default style*/
lv_rects_get(LV_RECTS_FANCY, &lv_btns_def.state_style[LV_BTN_STATE_REL]);
lv_btns_def.state_style[LV_BTN_STATE_REL].base.color = COLOR_MAKE(0xcc, 0xe0, 0xf5);
lv_btns_def.state_style[LV_BTN_STATE_REL].gcolor = COLOR_MAKE(0xa6, 0xc9, 0xed);
lv_btns_def.state_style[LV_BTN_STATE_REL].bcolor = COLOR_MAKE(0x33, 0x99, 0xff);
lv_rects_get(LV_RECTS_FANCY, &lv_btns_def.state_style[LV_BTN_STATE_PR]);
lv_btns_def.state_style[LV_BTN_STATE_PR].base.color = COLOR_MAKE(0xa6, 0xc9, 0xed);
lv_btns_def.state_style[LV_BTN_STATE_PR].gcolor = COLOR_MAKE(0x60, 0x88, 0xb0);
lv_btns_def.state_style[LV_BTN_STATE_PR].bcolor = COLOR_MAKE(0x33, 0x99, 0xff);
lv_btns_def.state_style[LV_BTN_STATE_PR].swidth = 3 * lv_btns_def.state_style[LV_BTN_STATE_REL].swidth / 4;
lv_rects_get(LV_RECTS_FANCY, &lv_btns_def.state_style[LV_BTN_STATE_TREL]);
lv_btns_def.state_style[LV_BTN_STATE_TREL].base.color = COLOR_MAKE(0xff, 0xed, 0xd3);
lv_btns_def.state_style[LV_BTN_STATE_TREL].gcolor = COLOR_MAKE(0xfc, 0xc7, 0x7a);
lv_btns_def.state_style[LV_BTN_STATE_TREL].bcolor = COLOR_MAKE(0xff, 0x90, 0x00);
lv_rects_get(LV_RECTS_FANCY, &lv_btns_def.state_style[LV_BTN_STATE_TPR]);
lv_btns_def.state_style[LV_BTN_STATE_TPR].base.color = COLOR_MAKE(0xfc, 0xc7, 0x7a);
lv_btns_def.state_style[LV_BTN_STATE_TPR].gcolor = COLOR_MAKE(0xdd, 0x8a, 0x4e);
lv_btns_def.state_style[LV_BTN_STATE_TPR].bcolor = COLOR_MAKE(0xff, 0x90, 0x00);
lv_btns_def.state_style[LV_BTN_STATE_TPR].swidth = 3 * lv_btns_def.state_style[LV_BTN_STATE_TREL].swidth / 4;
lv_rects_get(LV_RECTS_FANCY, &lv_btns_def.state_style[LV_BTN_STATE_INA]);
lv_btns_def.state_style[LV_BTN_STATE_INA].base.color = COLOR_MAKE(0xe0, 0xe0, 0xe0);
lv_btns_def.state_style[LV_BTN_STATE_INA].gcolor = lv_btns_def.state_style[LV_BTN_STATE_INA].base.color;
lv_btns_def.state_style[LV_BTN_STATE_INA].bcolor = COLOR_MAKE(0x80, 0x80, 0x80);
/*Border style*/
lv_rects_get(LV_RECTS_BORDER, &lv_btns_border.state_style[LV_BTN_STATE_REL]);
lv_btns_border.state_style[LV_BTN_STATE_REL].bcolor = COLOR_MAKE(0x20, 0x20, 0x20);
lv_rects_get(LV_RECTS_BORDER, &lv_btns_border.state_style[LV_BTN_STATE_PR]);
lv_btns_border.state_style[LV_BTN_STATE_PR].bcolor = COLOR_MAKE(0x60, 0x60, 0x60);
lv_rects_get(LV_RECTS_BORDER, &lv_btns_border.state_style[LV_BTN_STATE_TREL]);
lv_btns_border.state_style[LV_BTN_STATE_TREL].bcolor = COLOR_MAKE(0x00, 0x33, 0xff);
lv_rects_get(LV_RECTS_BORDER, &lv_btns_border.state_style[LV_BTN_STATE_TPR]);
lv_btns_border.state_style[LV_BTN_STATE_TPR].bcolor = COLOR_MAKE(0x00, 0x33, 0x99);
lv_rects_get(LV_RECTS_BORDER, &lv_btns_border.state_style[LV_BTN_STATE_INA]);
lv_btns_border.state_style[LV_BTN_STATE_INA].bcolor = COLOR_MAKE(0xa0, 0xa0, 0xa0);
/*Transparent style*/
lv_rects_get(LV_RECTS_TRANSP, &lv_btns_transp.state_style[LV_BTN_STATE_REL]);
lv_rects_get(LV_RECTS_TRANSP, &lv_btns_transp.state_style[LV_BTN_STATE_PR]);
lv_rects_get(LV_RECTS_TRANSP, &lv_btns_transp.state_style[LV_BTN_STATE_TREL]);
lv_rects_get(LV_RECTS_TRANSP, &lv_btns_transp.state_style[LV_BTN_STATE_TPR]);
lv_rects_get(LV_RECTS_TRANSP, &lv_btns_transp.state_style[LV_BTN_STATE_INA]);
}
#endif

View File

@@ -31,10 +31,10 @@
/*Button states*/
typedef enum
{
LV_BTN_STATE_PR,
LV_BTN_STATE_REL,
LV_BTN_STATE_TPR,
LV_BTN_STATE_PR,
LV_BTN_STATE_TREL,
LV_BTN_STATE_TPR,
LV_BTN_STATE_INA,
LV_BTN_STATE_NUM,
}lv_btn_state_t;
@@ -49,27 +49,13 @@ typedef struct
lv_action_t lpr_action; /*A function to call when the button is long pressed (NULL if unused)*/
lv_action_t lpr_rep_action; /*A function to call periodically after long press (NULL if unused)*/
lv_style_t * styles[LV_BTN_STATE_NUM]; /*Styles in each state*/
lv_btn_state_t state; /*Current state of the button from 'lv_btn_state_t' enum*/
uint8_t tgl :1; /*1: Toggle enabled*/
uint8_t lpr_exec :1; /*1: Long press action executed (Handled by the library)*/
}lv_btn_ext_t;
/*Style of button*/
typedef struct
{
lv_rects_t current; /*Current style according to the state. Library use this. Style of ancestor*/
/*New style element for this type */
lv_rects_t state_style[LV_BTN_STATE_NUM]; /*Rectangle styles for each state*/
}lv_btns_t;
/*Built-in styles of button*/
typedef enum
{
LV_BTNS_DEF,
LV_BTNS_BORDER,
LV_BTNS_TRANSP,
}lv_btns_builtin_t;
/**********************
* GLOBAL PROTOTYPES
@@ -133,6 +119,8 @@ void lv_btn_set_lpr_action(lv_obj_t * btn, lv_action_t lpr_action);
*/
void lv_btn_set_lpr_rep_action(lv_obj_t * btn, lv_action_t lpr_rep_action);
void lv_btn_set_styles(lv_obj_t * btn, lv_style_t * rel, lv_style_t * pr, lv_style_t * trel, lv_style_t * tpr, lv_style_t * ina);
/**
* Get the current state of the button
* @param btn pointer to a button object
@@ -147,14 +135,7 @@ lv_btn_state_t lv_btn_get_state(lv_obj_t * btn);
*/
bool lv_btn_get_tgl(lv_obj_t * btn);
/**
* Return with a pointer to a built-in style and/or copy it to a variable
* @param style a style name from lv_btns_builtin_t enum
* @param copy copy the style to this variable. (NULL if unused)
* @return pointer to an lv_btns_t style
*/
lv_btns_t * lv_btns_get(lv_btns_builtin_t style, lv_btns_t * copy);
lv_style_t * lv_btn_get_style(lv_obj_t * btn, lv_btn_state_t state);
/**********************
* MACROS
**********************/

View File

@@ -31,13 +31,10 @@ static bool lv_btnm_design(lv_obj_t * btnm, const area_t * mask, lv_design_mode_
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 void lv_btnm_create_btns(lv_obj_t * btnm, const char ** map);
static void lv_btnms_init(void);
/**********************
* STATIC VARIABLES
**********************/
static lv_btnms_t lv_btnms_def;
static const char * lv_btnm_def_map[] = {"Btn1","Btn2", "Btn3","\n",
"\002Btn4","Btn5", ""};
@@ -75,17 +72,18 @@ lv_obj_t * lv_btnm_create(lv_obj_t * par, lv_obj_t * copy)
ext->btn_areas = NULL;
ext->cb = NULL;
ext->map_p = NULL;
ext->style_btn_rel = lv_style_get(LV_STYLE_BTN_REL, NULL);
ext->style_btn_pr = lv_style_get(LV_STYLE_BTN_PR, NULL);
if(ancestor_design_f == NULL) ancestor_design_f = lv_obj_get_design_f(new_btnm);
lv_obj_set_signal_f(new_btnm, lv_btnm_signal);
lv_obj_set_design_f(new_btnm, lv_btnm_design);
/*Init the new button matrix object*/
if(copy == NULL) {
lv_obj_set_size(new_btnm, LV_HOR_RES / 2, LV_VER_RES / 2);
lv_obj_set_style(new_btnm, lv_btnms_get(LV_BTNMS_DEF, NULL));
lv_obj_set_size(new_btnm, LV_HOR_RES, LV_VER_RES / 2);
lv_obj_set_style(new_btnm, lv_style_get(LV_STYLE_PLAIN, NULL));
lv_btnm_set_map(new_btnm, lv_btnm_def_map);
}
/*Copy an existing object*/
@@ -114,77 +112,72 @@ bool lv_btnm_signal(lv_obj_t * btnm, lv_signal_t sign, void * param)
* make the object specific signal handling */
if(valid != false) {
lv_btnm_ext_t * ext = lv_obj_get_ext(btnm);
uint16_t new_btn;
area_t btnm_area;
area_t btn_area;
point_t p;
switch(sign) {
case LV_SIGNAL_CLEANUP:
dm_free(ext->btn_areas);
break;
case LV_SIGNAL_STYLE_CHG:
case LV_SIGNAL_CORD_CHG:
lv_btnm_set_map(btnm, LV_EA(btnm, lv_btnm_ext_t)->map_p);
break;
case LV_SIGNAL_PRESSING:
/*Search the pressed area*/
lv_dispi_get_point(param, &p);
new_btn = lv_btnm_get_btn_from_point(btnm, &p);
/*Invalidate to old and the new areas*/;
lv_obj_get_cords(btnm, &btnm_area);
if(new_btn != ext->btn_pr) {
lv_dispi_reset_lpr(param);
if(ext->btn_pr != LV_BTNM_PR_NONE) {
area_cpy(&btn_area, &ext->btn_areas[ext->btn_pr]);
btn_area.x1 += btnm_area.x1;
btn_area.y1 += btnm_area.y1;
btn_area.x2 += btnm_area.x1;
btn_area.y2 += btnm_area.y1;
lv_inv_area(&btn_area);
}
if(new_btn != LV_BTNM_PR_NONE) {
area_cpy(&btn_area, &ext->btn_areas[new_btn]);
btn_area.x1 += btnm_area.x1;
btn_area.y1 += btnm_area.y1;
btn_area.x2 += btnm_area.x1;
btn_area.y2 += btnm_area.y1;
lv_inv_area(&btn_area);
}
}
ext->btn_pr = new_btn;
break;
case LV_SIGNAL_RELEASED:
case LV_SIGNAL_LONG_PRESS_REP:
if(ext->cb != NULL &&
ext->btn_pr != LV_BTNM_PR_NONE) {
uint16_t txt_i = 0;
uint16_t btn_i = 0;
/*Search the next valid text in the map*/
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) {
/*Invalidate to old area*/;
lv_obj_get_cords(btnm, &btnm_area);
if(sign == LV_SIGNAL_CLEANUP) {
dm_free(ext->btn_areas);
}
else if(sign == LV_SIGNAL_STYLE_CHG || sign == LV_SIGNAL_CORD_CHG) {
lv_btnm_set_map(btnm, ext->map_p);
}
else if(sign == LV_SIGNAL_PRESSING) {
uint16_t btn_pr;
/*Search the pressed area*/
lv_dispi_get_point(param, &p);
btn_pr = lv_btnm_get_btn_from_point(btnm, &p);
/*Invalidate to old and the new areas*/;
lv_obj_get_cords(btnm, &btnm_area);
if(btn_pr != ext->btn_pr) {
lv_dispi_reset_lpr(param);
if(ext->btn_pr != LV_BTNM_PR_NONE) {
area_cpy(&btn_area, &ext->btn_areas[ext->btn_pr]);
btn_area.x1 += btnm_area.x1;
btn_area.y1 += btnm_area.y1;
btn_area.x2 += btnm_area.x1;
btn_area.y2 += btnm_area.y1;
lv_inv_area(&btn_area);
}
if(btn_pr != LV_BTNM_PR_NONE) {
area_cpy(&btn_area, &ext->btn_areas[btn_pr]);
btn_area.x1 += btnm_area.x1;
btn_area.y1 += btnm_area.y1;
btn_area.x2 += btnm_area.x1;
btn_area.y2 += btnm_area.y1;
lv_inv_area(&btn_area);
}
}
ext->btn_pr = LV_BTNM_PR_NONE;
}
break;
default:
break;
ext->btn_pr = btn_pr;
}
else if(sign == LV_SIGNAL_RELEASED || sign == LV_SIGNAL_LONG_PRESS_REP) {
if(ext->cb != NULL &&
ext->btn_pr != LV_BTNM_PR_NONE) {
uint16_t txt_i = 0;
uint16_t btn_i = 0;
/*Search the next valid text in the map*/
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) {
/*Invalidate to old area*/;
lv_obj_get_cords(btnm, &btnm_area);
area_cpy(&btn_area, &ext->btn_areas[ext->btn_pr]);
btn_area.x1 += btnm_area.x1;
btn_area.y1 += btnm_area.y1;
btn_area.x2 += btnm_area.x1;
btn_area.y2 += btnm_area.y1;
lv_inv_area(&btn_area);
ext->btn_pr = LV_BTNM_PR_NONE;
}
}
}
return valid;
@@ -208,16 +201,17 @@ void lv_btnm_set_map(lv_obj_t * btnm, const char ** map)
{
if(map == NULL) return;
LV_EA(btnm, lv_btnm_ext_t)->map_p = map;
lv_btnm_ext_t * ext = lv_obj_get_ext(btnm);
ext->map_p = map;
/*Analyze the map and create the required number of buttons*/
lv_btnm_create_btns(btnm, map);
/*Set size and positions of the buttons*/
lv_btnms_t * btnms = lv_obj_get_style(btnm);
cord_t max_w = lv_obj_get_width(btnm) - 2 * btnms->bg.hpad;
cord_t max_h = lv_obj_get_height(btnm) - 2 * btnms->bg.vpad;
cord_t act_y = btnms->bg.vpad;
lv_style_t * btnms = lv_obj_get_style(btnm);
cord_t max_w = lv_obj_get_width(btnm) - 2 * btnms->hpad;
cord_t max_h = lv_obj_get_height(btnm) - 2 * btnms->vpad;
cord_t act_y = btnms->vpad;
/*Count the lines to calculate button height*/
uint8_t line_cnt = 1;
@@ -226,7 +220,7 @@ void lv_btnm_set_map(lv_obj_t * btnm, const char ** map)
if(strcmp(map[li], "\n") == 0) line_cnt ++;
}
cord_t btn_h = max_h - ((line_cnt - 1) * btnms->bg.opad);
cord_t btn_h = max_h - ((line_cnt - 1) * btnms->opad);
btn_h = btn_h / line_cnt;
/* Count the units and the buttons in a line
@@ -237,7 +231,6 @@ void lv_btnm_set_map(lv_obj_t * btnm, const char ** map)
uint16_t i_tot = 0; /*Act. index in the str map*/
uint16_t btn_i = 0; /*Act. index of button areas*/
const char ** map_p_tmp = map;
lv_btnm_ext_t * ext = lv_obj_get_ext(btnm);
/*Count the units and the buttons in a line*/
while(1) {
@@ -253,11 +246,11 @@ void lv_btnm_set_map(lv_obj_t * btnm, const char ** map)
/*Only deal with the non empty lines*/
if(btn_cnt != 0) {
/*Calculate the width of all units*/
cord_t all_unit_w = max_w - ((btn_cnt-1) * btnms->bg.opad);
cord_t all_unit_w = max_w - ((btn_cnt-1) * btnms->opad);
/*Set the button size and positions and set the texts*/
uint16_t i;
cord_t act_x = btnms->bg.hpad;
cord_t act_x = btnms->hpad;
cord_t act_unit_w;
unit_act_cnt = 0;
for(i = 0; i < btn_cnt; i++) {
@@ -267,7 +260,7 @@ void lv_btnm_set_map(lv_obj_t * btnm, const char ** map)
act_unit_w = (all_unit_w * lv_btnm_get_width_unit(map_p_tmp[i])) / unit_cnt;
/*Always recalculate act_x because of rounding errors */
act_x = (unit_act_cnt * all_unit_w) / unit_cnt + i * btnms->bg.opad + btnms->bg.hpad;
act_x = (unit_act_cnt * all_unit_w) / unit_cnt + i * btnms->opad + btnms->hpad;
area_set(&ext->btn_areas[btn_i], act_x,
act_y,
@@ -280,7 +273,7 @@ void lv_btnm_set_map(lv_obj_t * btnm, const char ** map)
btn_i ++;
}
}
act_y += btn_h + btnms->bg.opad;
act_y += btn_h + btnms->opad;
if(strlen(map_p_tmp[btn_cnt]) == 0) break; /*Break on end of map*/
map_p_tmp = &map_p_tmp[btn_cnt + 1]; /*Set the map to the next line*/
i_tot ++; /*Skip the '\n'*/
@@ -296,7 +289,22 @@ void lv_btnm_set_map(lv_obj_t * btnm, const char ** map)
*/
void lv_btnm_set_action(lv_obj_t * btnm, lv_btnm_callback_t cb)
{
LV_EA(btnm, lv_btnm_ext_t)->cb = cb;
lv_btnm_ext_t * ext = lv_obj_get_ext(btnm);
ext->cb = cb;
}
/**
* Set the style of the buttons in a given state
* @param btnm pointer to a button matrix object
* @param state style in this state (LV_BTN_STATE_PR or LV_BTN_STATE_REL)
* @param style pointer to style
*/
void lv_btnm_set_styles_btn(lv_obj_t * btnm, lv_btn_state_t state, lv_style_t * style)
{
lv_btnm_ext_t * ext = lv_obj_get_ext(btnm);
if(state == LV_BTN_STATE_REL) ext->style_btn_rel = style;
if(state == LV_BTN_STATE_PR) ext->style_btn_pr = style;
}
/*=====================
@@ -310,7 +318,8 @@ void lv_btnm_set_action(lv_obj_t * btnm, lv_btnm_callback_t cb)
*/
const char ** lv_btnm_get_map(lv_obj_t * btnm)
{
return LV_EA(btnm, lv_btnm_ext_t)->map_p;
lv_btnm_ext_t * ext = lv_obj_get_ext(btnm);
return ext->map_p;
}
/**
@@ -318,41 +327,37 @@ const char ** lv_btnm_get_map(lv_obj_t * btnm)
* @param btnm: pointer to button matrix object
* @return pointer to the callback function
*/
lv_btnm_callback_t lv_btnm_get_cb(lv_obj_t * btnm)
lv_btnm_callback_t lv_btnm_get_action(lv_obj_t * btnm)
{
return LV_EA(btnm, lv_btnm_ext_t)->cb;
lv_btnm_ext_t * ext = lv_obj_get_ext(btnm);
return ext->cb;
}
/**
* Return with a pointer to a built-in style and/or copy it to a variable
* @param style a style name from lv_btnms_builtin_t enum
* @param copy copy the style to this variable. (NULL if unused)
* @return pointer to an lv_btnms_t style
* Get the style of buttons in button matrix
* @param btnm pointer to a button matrix object
* @param state style in this state (LV_BTN_STATE_PR or LV_BTN_STATE_REL)
* @return pointer the button style in the given state
*/
lv_btnms_t * lv_btnms_get(lv_btnms_builtin_t style, lv_btnms_t * copy)
lv_style_t * lv_btnm_get_style_btn(lv_obj_t * btnm, lv_btn_state_t state)
{
static bool style_inited = false;
lv_style_t * style;
lv_btnm_ext_t * ext = lv_obj_get_ext(btnm);
/*Make the style initialization if it is not done yet*/
if(style_inited == false) {
lv_btnms_init();
style_inited = true;
}
switch(state) {
case LV_BTN_STATE_PR:
style = ext->style_btn_pr;
break;
case LV_BTN_STATE_REL:
style = ext->style_btn_rel;
break;
default:
style = NULL;
}
lv_btnms_t *style_p;
if(style == NULL) style = lv_obj_get_style(btnm);
switch(style) {
case LV_BTNMS_DEF:
style_p = &lv_btnms_def;
break;
default:
style_p = &lv_btnms_def;
}
if(copy != NULL) memcpy(copy, style_p, sizeof(lv_btnms_t));
return style_p;
return style;
}
/**********************
@@ -380,7 +385,8 @@ static bool lv_btnm_design(lv_obj_t * btnm, const area_t * mask, lv_design_mode_
ancestor_design_f(btnm, mask, mode);
lv_btnm_ext_t * ext = lv_obj_get_ext(btnm);
lv_btnms_t * style = lv_obj_get_style(btnm);
lv_style_t * style = lv_obj_get_style(btnm);
lv_style_t * btn_style;
area_t area_btnm;
area_t area_tmp;
@@ -402,19 +408,18 @@ static bool lv_btnm_design(lv_obj_t * btnm, const area_t * mask, lv_design_mode_
btn_h = area_get_height(&area_tmp);
/*Load the style*/
lv_btn_state_t state;
state = ext->btn_pr == btn_i ? LV_BTN_STATE_PR : LV_BTN_STATE_REL;
btn_style = lv_btnm_get_style_btn(btnm, ext->btn_pr == btn_i ? LV_BTN_STATE_PR : LV_BTN_STATE_REL);
lv_draw_rect(&area_tmp, mask, &style->btn.state_style[state]);
lv_draw_rect(&area_tmp, mask, btn_style);
/*Search the next valid text in the map*/
while(strcmp(ext->map_p[txt_i], "\n") == 0) txt_i ++;
/*Calculate the size of the text*/
const font_t * font = style->label.font;
const font_t * font = style->font;
point_t txt_size;
txt_get_size(&txt_size, ext->map_p[txt_i], font,
style->label.letter_space, style->label.line_space,
style->letter_space, style->line_space,
area_get_width(&area_btnm), TXT_FLAG_NONE);
area_tmp.x1 += (btn_w - txt_size.x) / 2;
@@ -422,7 +427,7 @@ static bool lv_btnm_design(lv_obj_t * btnm, const area_t * mask, lv_design_mode_
area_tmp.x2 = area_tmp.x1 + txt_size.x;
area_tmp.y2 = area_tmp.y1 + txt_size.y;
lv_draw_label(&area_tmp, mask, &style->label, ext->map_p[txt_i], TXT_FLAG_NONE);
lv_draw_label(&area_tmp, mask, style, ext->map_p[txt_i], TXT_FLAG_NONE);
txt_i ++;
}
}
@@ -431,25 +436,6 @@ static bool lv_btnm_design(lv_obj_t * btnm, const area_t * mask, lv_design_mode_
return true;
}
/**
* Initialize the button matrix styles
*/
static void lv_btnms_init(void)
{
/*Default style*/
lv_rects_get(LV_RECTS_PLAIN, &lv_btnms_def.bg); /*Background rectangle style*/
lv_btnms_def.bg.vpad = LV_DPI / 30;
lv_btnms_def.bg.hpad = LV_DPI / 30;
lv_btnms_def.bg.opad = LV_DPI / 30;
lv_btnms_def.bg.radius = 0;
lv_btnms_def.bg.bwidth = 0;
lv_btns_get(LV_BTNS_DEF, &lv_btnms_def.btn); /*Button style*/
lv_btnms_def.btn.state_style[LV_BTN_STATE_REL].swidth = 0;
lv_btnms_def.btn.state_style[LV_BTN_STATE_PR].swidth = 0;
lv_labels_get(LV_LABELS_BTN, &lv_btnms_def.label); /*BUtton label style*/
}
/**
* Create the required number of buttons according to a map
* @param btnm pointer to button matrix object
@@ -487,7 +473,6 @@ static uint8_t lv_btnm_get_width_unit(const char * btn_str)
if(btn_str[0] <= '\011') return btn_str[0];
return 1;
}
static uint16_t lv_btnm_get_btn_from_point(lv_obj_t * btnm, point_t * p)

View File

@@ -50,24 +50,10 @@ typedef struct
uint16_t btn_cnt; /*Number of button in 'map_p'(Handled by the library)*/
uint16_t btn_pr; /*Index of the currently pressed button or LV_BTNM_PR_NONE (Handled by the library)*/
lv_btnm_callback_t cb; /*A function to call when a button is releases*/
lv_style_t * style_btn_rel; /*Style of the released buttons*/
lv_style_t * style_btn_pr; /*Style of the pressed buttons*/
}lv_btnm_ext_t;
/*Style of button matrix*/
typedef struct
{
lv_rects_t bg; /*Style of ancestor*/
/*New style element for this type */
lv_btns_t btn; /*Style of the buttons*/
lv_labels_t label; /*Style of the labels on the buttons*/
}lv_btnms_t;
/*Built-in styles of button matrix*/
typedef enum
{
LV_BTNMS_DEF,
}lv_btnms_builtin_t;
/**********************
* GLOBAL PROTOTYPES
**********************/
@@ -108,6 +94,7 @@ void lv_btnm_set_map(lv_obj_t * btnm, const char ** map);
*/
void lv_btnm_set_action(lv_obj_t * btnm, lv_btnm_callback_t cb);
void lv_btnm_set_styles_btn(lv_obj_t * btnm, lv_btn_state_t state, lv_style_t * style);
/**
* Get the current map of a button matrix
* @param btnm pointer to a button matrix object
@@ -120,16 +107,9 @@ const char ** lv_btnm_get_map(lv_obj_t * btnm);
* @param btnm: pointer to button matrix object
* @return pointer to the callback function
*/
lv_btnm_callback_t lv_btnm_get_cb(lv_obj_t * btnm);
/**
* Return with a pointer to a built-in style and/or copy it to a variable
* @param style a style name from lv_btnms_builtin_t enum
* @param copy copy the style to this variable. (NULL if unused)
* @return pointer to an lv_btnms_t style
*/
lv_btnms_t * lv_btnms_get(lv_btnms_builtin_t style, lv_btnms_t * copy);
lv_btnm_callback_t lv_btnm_get_action(lv_obj_t * btnm);
lv_style_t * lv_btnm_get_style_btn(lv_obj_t * btnm, lv_btn_state_t state);
/**********************
* MACROS
**********************/

View File

@@ -23,12 +23,10 @@
* STATIC PROTOTYPES
**********************/
static bool lv_cb_design(lv_obj_t * cb, const area_t * mask, lv_design_mode_t mode);
static void lv_cbs_init(void);
/**********************
* STATIC VARIABLES
**********************/
static lv_cbs_t lv_cbs_def;
static lv_design_f_t ancestor_design_f;
/**********************
* MACROS
@@ -66,17 +64,22 @@ lv_obj_t * lv_cb_create(lv_obj_t * par, lv_obj_t * copy)
/*Init the new checkbox object*/
if(copy == NULL) {
ext->bullet = lv_btn_create(new_cb, 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_rect_set_layout(new_cb, LV_RECT_LAYOUT_ROW_M);
lv_rect_set_fit(new_cb, true, true);
lv_btn_set_tgl(new_cb, true);
ext->bullet = lv_btn_create(new_cb, NULL);
lv_obj_set_click(ext->bullet, false);
lv_btn_set_styles(ext->bullet, lv_style_get(LV_STYLE_BTN_REL, NULL), lv_style_get(LV_STYLE_BTN_PR, NULL),
lv_style_get(LV_STYLE_BTN_TREL, NULL), lv_style_get(LV_STYLE_BTN_TPR, NULL),
lv_style_get(LV_STYLE_BTN_INA, NULL));
ext->label = lv_label_create(new_cb, NULL);
lv_obj_set_style(ext->label, NULL); /*Inherit the style of the parent*/
lv_label_set_text(ext->label, "Check box");
lv_obj_set_style(new_cb, lv_cbs_get(LV_CBS_DEF, NULL));
} else {
lv_cb_ext_t * copy_ext = lv_obj_get_ext(copy);
ext->bullet = lv_btn_create(new_cb, copy_ext->bullet);
@@ -106,29 +109,19 @@ bool lv_cb_signal(lv_obj_t * cb, lv_signal_t sign, void * param)
valid = lv_btn_signal(cb, sign, param);
lv_cb_ext_t * ext = lv_obj_get_ext(cb);
lv_cbs_t * cbs = lv_obj_get_style(cb);
lv_style_t * style = lv_obj_get_style(cb);
/* 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_PRESSED:
case LV_SIGNAL_RELEASED:
case LV_SIGNAL_LONG_PRESS:
case LV_SIGNAL_PRESS_LOST:
lv_btn_set_state(ext->bullet, lv_btn_get_state(cb));
break;
case LV_SIGNAL_STYLE_CHG:
lv_obj_set_size(ext->bullet, cbs->bullet_size, cbs->bullet_size);
lv_obj_set_style(ext->bullet, &cbs->bullet);
lv_obj_set_style(ext->label, &cbs->label);
break;
case LV_SIGNAL_CLEANUP:
/*Nothing to cleanup. (No dynamically allocated memory in 'ext')*/
break;
default:
break;
if(sign == LV_SIGNAL_STYLE_CHG) {
lv_obj_set_size(ext->bullet, font_get_height(style->font), font_get_height(style->font));
}
if(sign == LV_SIGNAL_PRESSED ||
sign == LV_SIGNAL_RELEASED ||
sign == LV_SIGNAL_PRESS_LOST) {
lv_btn_set_state(lv_cb_get_bullet(cb), lv_btn_get_state(cb));
}
}
return valid;
@@ -167,35 +160,16 @@ const char * lv_cb_get_text(lv_obj_t * cb)
}
/**
* Return with a pointer to a built-in style and/or copy it to a variable
* @param style a style name from lv_cbs_builtin_t enum
* @param copy copy the style to this variable. (NULL if unused)
* @return pointer to an lv_cbs_t style
* Get the bullet (lv_btn) of a check box
* @param cb pointer to check box object
* @return pointer to the bullet of the check box (lv_btn)
*/
lv_cbs_t * lv_cbs_get(lv_cbs_builtin_t style, lv_cbs_t * copy)
lv_obj_t * lv_cb_get_bullet(lv_obj_t * cb)
{
static bool style_inited = false;
/*Make the style initialization if it is not done yet*/
if(style_inited == false) {
lv_cbs_init();
style_inited = true;
}
lv_cbs_t *style_p;
switch(style) {
case LV_CBS_DEF:
style_p = &lv_cbs_def;
break;
default:
style_p = &lv_cbs_def;
}
if(copy != NULL) memcpy(copy, style_p, sizeof(lv_cbs_t));
return style_p;
lv_cb_ext_t * ext = lv_obj_get_ext(cb);
return ext->bullet;
}
/**********************
* STATIC FUNCTIONS
**********************/
@@ -231,33 +205,4 @@ static bool lv_cb_design(lv_obj_t * cb, const area_t * mask, lv_design_mode_t mo
return true;
}
/**
* Initialize the rectangle styles
*/
static void lv_cbs_init(void)
{
/*Default style*/
/*Bg style*/
lv_btns_get(LV_BTNS_TRANSP, &lv_cbs_def.bg);
lv_cbs_def.bg.state_style[LV_BTN_STATE_REL].hpad = LV_DPI / 10;
lv_cbs_def.bg.state_style[LV_BTN_STATE_REL].vpad = LV_DPI / 10;
lv_cbs_def.bg.state_style[LV_BTN_STATE_PR].hpad = LV_DPI / 10;
lv_cbs_def.bg.state_style[LV_BTN_STATE_PR].vpad = LV_DPI / 10;
lv_cbs_def.bg.state_style[LV_BTN_STATE_TREL].hpad = LV_DPI / 10;
lv_cbs_def.bg.state_style[LV_BTN_STATE_TREL].vpad = LV_DPI / 10;
lv_cbs_def.bg.state_style[LV_BTN_STATE_TPR].hpad = LV_DPI / 10;
lv_cbs_def.bg.state_style[LV_BTN_STATE_TPR].vpad = LV_DPI / 10;
lv_cbs_def.bg.state_style[LV_BTN_STATE_INA].hpad = LV_DPI / 10;
lv_cbs_def.bg.state_style[LV_BTN_STATE_INA].vpad = LV_DPI / 10;
/*Bullet style*/
lv_btns_get(LV_BTNS_DEF, &lv_cbs_def.bullet);
/*Label*/
lv_labels_get(LV_LABELS_TXT, &lv_cbs_def.label);
/*Others*/
lv_cbs_def.bullet_size = LV_OBJ_DEF_WIDTH / 3;
}
#endif

View File

@@ -41,22 +41,6 @@ typedef struct
lv_obj_t * label; /*Pointer to label*/
}lv_cb_ext_t;
/*Style of check box*/
typedef struct
{
lv_btns_t bg; /*Style of the background button*/
/*New style element for this type */
lv_btns_t bullet; /*Style of the bullet*/
lv_labels_t label; /*Style of the label*/
cord_t bullet_size; /*Size of bullet (square)*/
}lv_cbs_t;
/*Built-in styles of check box*/
typedef enum
{
LV_CBS_DEF, /*Default style with transparent background*/
}lv_cbs_builtin_t;
/**********************
* GLOBAL PROTOTYPES
**********************/
@@ -91,14 +75,7 @@ void lv_cb_set_text(lv_obj_t * cb, const char * txt);
*/
const char * lv_cb_get_text(lv_obj_t * cb);
/**
* Return with a pointer to a built-in style and/or copy it to a variable
* @param style a style name from lv_cbs_builtin_t enum
* @param copy copy the style to this variable. (NULL if unused)
* @return pointer to an lv_cbs_t style
*/
lv_cbs_t * lv_cbs_get(lv_cbs_builtin_t style, lv_cbs_t * copy);
lv_obj_t * lv_cb_get_bullet(lv_obj_t * cb);
/**********************
* MACROS
**********************/

View File

@@ -29,7 +29,6 @@
* STATIC PROTOTYPES
**********************/
static bool lv_chart_design(lv_obj_t * chart, const area_t * mask, lv_design_mode_t mode);
static void lv_charts_init(void);
static void lv_chart_draw_div(lv_obj_t * chart, const area_t * mask);
static void lv_chart_draw_lines(lv_obj_t * chart, const area_t * mask);
static void lv_chart_draw_points(lv_obj_t * chart, const area_t * mask);
@@ -39,7 +38,6 @@ static void lv_chart_draw_cols(lv_obj_t * chart, const area_t * mask);
/**********************
* STATIC VARIABLES
**********************/
static lv_charts_t lv_charts_def;
static lv_design_f_t ancestor_design_f;
/**********************
@@ -77,6 +75,8 @@ lv_obj_t * lv_chart_create(lv_obj_t * par, lv_obj_t * copy)
ext->vdiv_num = LV_CHART_VDIV_DEF;
ext->pnum = LV_CHART_PNUM_DEF;
ext->type = LV_CHART_LINE;
ext->data_opa = OPA_COVER;
ext->dark_eff = OPA_50;
if(ancestor_design_f == NULL) ancestor_design_f = lv_obj_get_design_f(new_chart);
@@ -85,7 +85,7 @@ lv_obj_t * lv_chart_create(lv_obj_t * par, lv_obj_t * copy)
/*Init the new chart background object*/
if(copy == NULL) {
lv_obj_set_style(new_chart, lv_charts_get(LV_CHARTS_DEF, NULL));
lv_obj_set_style(new_chart, lv_style_get(LV_STYLE_PRETTY, NULL));
} else {
lv_chart_ext_t * ext_copy = lv_obj_get_ext(copy);
ext->type = ext_copy->type;
@@ -94,6 +94,7 @@ lv_obj_t * lv_chart_create(lv_obj_t * par, lv_obj_t * copy)
ext->hdiv_num = ext_copy->hdiv_num;
ext->vdiv_num = ext_copy->vdiv_num;
ext->pnum = ext_copy->pnum;
ext->data_opa = ext_copy->data_opa;
/*Refresh the style with new signal function*/
lv_obj_refr_style(new_chart);
@@ -120,17 +121,11 @@ bool lv_chart_signal(lv_obj_t * chart, lv_signal_t sign, void * param)
if(valid != false) {
cord_t ** datal;
lv_chart_ext_t * ext = lv_obj_get_ext(chart);
switch(sign) {
case LV_SIGNAL_CLEANUP:
LL_READ(ext->dl_ll, datal) {
dm_free(*datal);
}
ll_clear(&ext->dl_ll);
break;
default:
break;
if(sign == LV_SIGNAL_CLEANUP) {
LL_READ(ext->dl_ll, datal) {
dm_free(*datal);
}
ll_clear(&ext->dl_ll);
}
}
@@ -140,20 +135,22 @@ bool lv_chart_signal(lv_obj_t * chart, lv_signal_t sign, void * param)
/**
* Allocate and add a data line to the chart
* @param chart pointer to a chart object
* @return pointer to the allocated data lie (an array for the data points)
* @param color color of the data line
* @param width line width/point radius/column width
* @return pointer to the allocated data line (an array for the data points)
*/
cord_t * lv_chart_add_dataline(lv_obj_t * chart)
cord_t * lv_chart_add_dataline(lv_obj_t * chart, color_t color, cord_t width)
{
lv_chart_ext_t * ext = lv_obj_get_ext(chart);
cord_t ** dl = ll_ins_head(&ext->dl_ll);
lv_chart_dl_t * dl = ll_ins_head(&ext->dl_ll);
cord_t def = (ext->ymax - ext->ymin) >> 2; /*1/4 range as default value*/
if(dl == NULL) return NULL;
*dl = dm_alloc(sizeof(cord_t) * ext->pnum);
dl->points = dm_alloc(sizeof(cord_t) * ext->pnum);
uint16_t i;
cord_t * p_tmp = *dl;
cord_t * p_tmp = dl->points;
for(i = 0; i < ext->pnum; i++) {
*p_tmp = def;
p_tmp++;
@@ -161,7 +158,7 @@ cord_t * lv_chart_add_dataline(lv_obj_t * chart)
ext->dl_num++;
return *dl;
return dl->points;
}
/**
@@ -231,18 +228,39 @@ void lv_chart_set_type(lv_obj_t * chart, lv_chart_type_t type)
void lv_chart_set_pnum(lv_obj_t * chart, uint16_t pnum)
{
lv_chart_ext_t * ext = lv_obj_get_ext(chart);
cord_t ** y_data;
lv_chart_dl_t * dl;
if(pnum < 1) pnum = 1;
LL_READ_BACK(ext->dl_ll, y_data) {
*y_data = dm_realloc(*y_data, sizeof(cord_t) * pnum);
LL_READ_BACK(ext->dl_ll, dl) {
dl->points = dm_realloc(dl->points, sizeof(cord_t) * pnum);
}
ext->pnum = pnum;
lv_chart_refr(chart);
}
/**
* Set the opacity of the data lines
* @param chart pointer to chart object
* @param opa opacity of the data lines
*/
void lv_chart_set_data_opa(lv_obj_t * chart, opa_t opa)
{
lv_chart_ext_t * ext = lv_obj_get_ext(chart);
ext->data_opa = opa;
}
/**
* Set the dark effect on the bottom of the points or columns
* @param chart pointer to chart object
* @param dark_eff dark effect level (OPA_TRANSP to turn off)
*/
void lv_chart_set_drak_effect(lv_obj_t * chart, opa_t dark_eff)
{
lv_chart_ext_t * ext = lv_obj_get_ext(chart);
ext->dark_eff = dark_eff;
}
/**
* Shift all data right and set the most right data on a data line
* @param chart pointer to chart object
@@ -263,6 +281,7 @@ void lv_chart_set_next(lv_obj_t * chart, cord_t * dl, cord_t y)
}
/*=====================
* Getter functions
*====================*/
@@ -292,36 +311,26 @@ uint16_t lv_chart_get_pnum(lv_obj_t * chart)
}
/**
* Return with a pointer to a built-in style and/or copy it to a variable
* @param style a style name from lv_charts_builtin_t enum
* @param copy copy the style to this variable. (NULL if unused)
* @return pointer to an lv_charts_t style
* Get the opacity of the data lines
* @param chart pointer to chart object
* @return the opacity of the data lines
*/
lv_charts_t * lv_charts_get(lv_charts_builtin_t style, lv_charts_t * copy)
opa_t lv_chart_get_data_opa(lv_obj_t * chart)
{
static bool style_inited = false;
/*Make the style initialization if it is not done yet*/
if(style_inited == false) {
lv_charts_init();
style_inited = true;
}
lv_charts_t * style_p;
switch(style) {
case LV_CHARTS_DEF:
style_p = &lv_charts_def;
break;
default:
style_p = &lv_charts_def;
}
if(copy != NULL) memcpy(copy, style_p, sizeof(lv_charts_t));
return style_p;
lv_chart_ext_t * ext = lv_obj_get_ext(chart);
return ext->data_opa;
}
/**
* Get the dark effect level on the bottom of the points or columns
* @param chart pointer to chart object
* @return dark effect level (OPA_TRANSP to turn off)
*/
opa_t lv_chart_get_dark_effect(lv_obj_t * chart, opa_t dark_eff)
{
lv_chart_ext_t * ext = lv_obj_get_ext(chart);
return ext->dark_eff;
}
/**********************
* STATIC FUNCTIONS
**********************/
@@ -377,7 +386,7 @@ static bool lv_chart_design(lv_obj_t * chart, const area_t * mask, lv_design_mod
static void lv_chart_draw_div(lv_obj_t * chart, const area_t * mask)
{
lv_chart_ext_t * ext = lv_obj_get_ext(chart);
lv_charts_t * style = lv_obj_get_style(chart);
lv_style_t * style = lv_obj_get_style(chart);
uint8_t div_i;
point_t p1;
@@ -392,7 +401,7 @@ static void lv_chart_draw_div(lv_obj_t * chart, const area_t * mask)
p1.y = (int32_t)((int32_t)h * div_i) / (ext->hdiv_num + 1);
p1.y += y_ofs;
p2.y = p1.y;
lv_draw_line(&p1, &p2, mask, &style->div_line);
lv_draw_line(&p1, &p2, mask, style);
}
p1.y = 0 + y_ofs;
@@ -401,7 +410,7 @@ static void lv_chart_draw_div(lv_obj_t * chart, const area_t * mask)
p1.x = (int32_t)((int32_t)w * div_i) / (ext->vdiv_num + 1);
p1.x += x_ofs;
p2.x = p1.x;
lv_draw_line(&p1, &p2, mask, &style->div_line);
lv_draw_line(&p1, &p2, mask, style);
}
}
@@ -412,7 +421,7 @@ static void lv_chart_draw_div(lv_obj_t * chart, const area_t * mask)
static void lv_chart_draw_lines(lv_obj_t * chart, const area_t * mask)
{
lv_chart_ext_t * ext = lv_obj_get_ext(chart);
lv_charts_t * style = lv_obj_get_style(chart);
lv_style_t * style = lv_obj_get_style(chart);
uint8_t i;
point_t p1;
@@ -422,20 +431,20 @@ static void lv_chart_draw_lines(lv_obj_t * chart, const area_t * mask)
cord_t x_ofs = chart->cords.x1;
cord_t y_ofs = chart->cords.y1;
int32_t y_tmp;
cord_t ** y_data;
lv_chart_dl_t * dl;
uint8_t dl_cnt = 0;
lv_lines_t lines;
lv_lines_get(LV_LINES_DEF, &lines);
lines.width = style->width;
lines.base.opa = (uint16_t)((uint16_t)style->bg_rect.base.opa * style->data_opa) >> 8;
lv_style_t lines;
lv_style_get(LV_STYLE_PLAIN, &lines);
lines.opa = (uint16_t)((uint16_t)style->opa * ext->data_opa) >> 8;
/*Go through all data lines*/
LL_READ_BACK(ext->dl_ll, y_data) {
lines.base.color = style->color[dl_cnt];
LL_READ_BACK(ext->dl_ll, dl) {
lines.line_width = dl->width;
lines.ccolor = dl->color;
p1.x = 0 + x_ofs;
p2.x = 0 + x_ofs;
y_tmp = (int32_t)((int32_t) (*y_data)[0] - ext->ymin) * h;
y_tmp = (int32_t)((int32_t) dl->points[0] - ext->ymin) * h;
y_tmp = y_tmp / (ext->ymax - ext->ymin);
p2.y = h - y_tmp + y_ofs;
@@ -445,7 +454,7 @@ static void lv_chart_draw_lines(lv_obj_t * chart, const area_t * mask)
p2.x = ((w * i) / (ext->pnum - 1)) + x_ofs;
y_tmp = (int32_t)((int32_t) (*y_data)[i] - ext->ymin) * h;
y_tmp = (int32_t)((int32_t) dl->points[i] - ext->ymin) * h;
y_tmp = y_tmp / (ext->ymax - ext->ymin);
p2.y = h - y_tmp + y_ofs;
@@ -463,7 +472,7 @@ static void lv_chart_draw_lines(lv_obj_t * chart, const area_t * mask)
static void lv_chart_draw_points(lv_obj_t * chart, const area_t * mask)
{
lv_chart_ext_t * ext = lv_obj_get_ext(chart);
lv_charts_t * style = lv_obj_get_style(chart);
lv_style_t * style = lv_obj_get_style(chart);
uint8_t i;
area_t cir_a;
@@ -472,32 +481,32 @@ static void lv_chart_draw_points(lv_obj_t * chart, const area_t * mask)
cord_t x_ofs = chart->cords.x1;
cord_t y_ofs = chart->cords.y1;
int32_t y_tmp;
cord_t ** y_data;
uint8_t dl_cnt = 0;
lv_rects_t rects;
cord_t rad = style->width;
lv_chart_dl_t * dl;
uint8_t dl_cnt = 0;
lv_style_t rects;
lv_style_get(LV_STYLE_PLAIN, &rects);
lv_rects_get(LV_RECTS_PLAIN, &rects);
rects.bwidth = 0;
rects.empty = 0;
rects.radius = LV_RECT_CIRCLE;
rects.base.opa = (uint16_t)((uint16_t)style->bg_rect.base.opa * style->data_opa) >> 8;
rects.opa = (uint16_t)((uint16_t)style->opa * ext->data_opa) >> 8;
/*Go through all data lines*/
LL_READ_BACK(ext->dl_ll, y_data) {
rects.base.color = style->color[dl_cnt];
rects.gcolor = color_mix(COLOR_BLACK, style->color[dl_cnt], style->dark_eff);
LL_READ_BACK(ext->dl_ll, dl) {
rects.radius = dl->width;
rects.mcolor = dl->color;
rects.gcolor = color_mix(COLOR_BLACK, dl->color, ext->dark_eff);
for(i = 0; i < ext->pnum; i ++) {
cir_a.x1 = ((w * i) / (ext->pnum - 1)) + x_ofs;
cir_a.x2 = cir_a.x1 + rad;
cir_a.x1 -= rad;
cir_a.x2 = cir_a.x1 + rects.radius;
cir_a.x1 -= rects.radius;
y_tmp = (int32_t)((int32_t) (*y_data)[i] - ext->ymin) * h;
y_tmp = (int32_t)((int32_t) dl->points[i] - ext->ymin) * h;
y_tmp = y_tmp / (ext->ymax - ext->ymin);
cir_a.y1 = h - y_tmp + y_ofs;
cir_a.y2 = cir_a.y1 + rad;
cir_a.y1 -= rad;
cir_a.y2 = cir_a.y1 + rects.radius;
cir_a.y1 -= rects.radius;
lv_draw_rect(&cir_a, mask, &rects);
}
@@ -513,7 +522,7 @@ static void lv_chart_draw_points(lv_obj_t * chart, const area_t * mask)
static void lv_chart_draw_cols(lv_obj_t * chart, const area_t * mask)
{
lv_chart_ext_t * ext = lv_obj_get_ext(chart);
lv_charts_t * style = lv_obj_get_style(chart);
lv_style_t * style = lv_obj_get_style(chart);
uint8_t i;
area_t col_a;
@@ -522,23 +531,24 @@ static void lv_chart_draw_cols(lv_obj_t * chart, const area_t * mask)
cord_t w = lv_obj_get_width(chart);
cord_t h = lv_obj_get_height(chart);
int32_t y_tmp;
cord_t ** y_data;
uint8_t dl_cnt = 0;
lv_rects_t rects;
lv_chart_dl_t * dl;
uint8_t dl_cnt = 0;
lv_style_t rects;
cord_t col_w = w / (2 * ext->dl_num * ext->pnum); /* Suppose (2 * dl_num) * pnum columns*/
cord_t x_ofs = col_w / 2; /*Shift with a half col.*/
lv_rects_get(LV_RECTS_PLAIN, &rects);
lv_style_get(LV_STYLE_PLAIN, &rects);
rects.bwidth = 0;
rects.empty = 0;
rects.radius = 0;
rects.base.opa = (uint16_t)((uint16_t)style->bg_rect.base.opa * style->data_opa) >> 8;
rects.opa = (uint16_t)((uint16_t)style->opa * ext->data_opa) >> 8;
col_a.y2 = chart->cords.y2;
/*Go through all data lines*/
LL_READ_BACK(ext->dl_ll, y_data) {
rects.base.color = style->color[dl_cnt];
rects.gcolor = color_mix(COLOR_BLACK, style->color[dl_cnt], style->dark_eff);
LL_READ_BACK(ext->dl_ll, dl) {
rects.mcolor = dl->color;
rects.gcolor = color_mix(COLOR_BLACK, dl->color, ext->dark_eff);
for(i = 0; i < ext->pnum; i ++) {
/* Calculate the x coordinates. Suppose (2 * dl_num) * pnum columns and draw to every second
@@ -554,7 +564,7 @@ static void lv_chart_draw_cols(lv_obj_t * chart, const area_t * mask)
col_a.x1 += x_ofs;
col_a.x2 += x_ofs;
y_tmp = (int32_t)((int32_t) (*y_data)[i] - ext->ymin) * h;
y_tmp = (int32_t)((int32_t) dl->points[i] - ext->ymin) * h;
y_tmp = y_tmp / (ext->ymax - ext->ymin);
col_a.y1 = h - y_tmp + chart->cords.y1;
@@ -566,35 +576,4 @@ static void lv_chart_draw_cols(lv_obj_t * chart, const area_t * mask)
dl_cnt++;
}
}
/**
* Initialize the chart styles
*/
static void lv_charts_init(void)
{
/*Default style*/
/* Background */
lv_rects_get(LV_RECTS_FANCY, &lv_charts_def.bg_rect);
/* Div. line */
lv_lines_get(LV_LINES_DEF, &lv_charts_def.div_line);
lv_charts_def.div_line.width = 1 * LV_DOWNSCALE;
lv_charts_def.div_line.base.color = COLOR_GRAY;
lv_charts_def.div_line.base.opa = OPA_50;
/*Data lines*/
lv_charts_def.width = 2 * LV_DOWNSCALE;
lv_charts_def.data_opa = OPA_COVER;
lv_charts_def.dark_eff = OPA_70;
lv_charts_def.color[0] = COLOR_RED;
lv_charts_def.color[1] = COLOR_GREEN;
lv_charts_def.color[2] = COLOR_BLUE;
lv_charts_def.color[3] = COLOR_MAGENTA;
lv_charts_def.color[4] = COLOR_CYAN;
lv_charts_def.color[5] = COLOR_YELLOW;
lv_charts_def.color[6] = COLOR_WHITE;
lv_charts_def.color[7] = COLOR_GRAY;
}
#endif

View File

@@ -33,6 +33,13 @@
/**********************
* TYPEDEFS
**********************/
typedef struct
{
cord_t * points;
color_t color;
cord_t width;
}lv_chart_dl_t;
/*Data of chart */
typedef struct
{
@@ -42,37 +49,23 @@ typedef struct
cord_t ymax; /*y max value (used to scale the data)*/
uint8_t hdiv_num; /*Number of horizontal division lines*/
uint8_t vdiv_num; /*Number of vertical division lines*/
ll_dsc_t dl_ll; /*Linked list for the data line pointers (stores cord_t * )*/
ll_dsc_t dl_ll; /*Linked list for the data line pointers (stores lv_chart_dl_t)*/
uint16_t pnum; /*Point number in a data line*/
uint8_t type :2; /*Line, column or point chart (from 'lv_chart_type_t')*/
uint8_t dl_num; /*Data line number in dl_ll*/
uint8_t type :3; /*Line, column or point chart (from 'lv_chart_type_t')*/
uint8_t dl_num; /*Number of data lines in dl_ll*/
opa_t data_opa; /*Opacity of data lines*/
opa_t dark_eff; /*Dark level of the point/column bottoms*/
}lv_chart_ext_t;
/*Chart types*/
typedef enum
{
LV_CHART_NONE = 0,
LV_CHART_LINE,
LV_CHART_COL,
LV_CHART_POINT,
}lv_chart_type_t;
/*Style of chart*/
typedef struct
{
lv_rects_t bg_rect; /*Style of the ancestor*/
/*New style element for this type */
lv_lines_t div_line;
color_t color[LV_CHART_DL_NUM]; /*Line/Point/Col colors */
cord_t width; /*Data line width or point radius*/
opa_t data_opa; /*Line/Point/Col opacity*/
opa_t dark_eff; /*Dark effect on the bottom of points and columns*/
}lv_charts_t;
/*Built-in styles of chart*/
typedef enum
{
LV_CHARTS_DEF,
}lv_charts_builtin_t;
/**********************
* GLOBAL PROTOTYPES
@@ -99,7 +92,7 @@ bool lv_chart_signal(lv_obj_t * chart, lv_signal_t sign, void * param);
* @param chart pointer to a chart object
* @return pointer to the allocated data lie (an array for the data points)
*/
cord_t * lv_chart_add_dataline(lv_obj_t * chart);
cord_t * lv_chart_add_dataline(lv_obj_t * chart, color_t color, cord_t width);
/**
* Refresh a chart if its data line has changed
@@ -139,6 +132,10 @@ void lv_chart_set_type(lv_obj_t * chart, lv_chart_type_t type);
*/
void lv_chart_set_pnum(lv_obj_t * chart, uint16_t pnum);
void lv_chart_set_data_opa(lv_obj_t * chart, opa_t opa);
void lv_chart_set_drak_effect(lv_obj_t * chart, opa_t dark_eff);
/**
* Shift all data right and set the most right data on a data line
* @param chart pointer to chart object
@@ -161,14 +158,8 @@ lv_chart_type_t lv_chart_get_type(lv_obj_t * chart);
*/
uint16_t lv_chart_get_pnum(lv_obj_t * chart);
/**
* Return with a pointer to a built-in style and/or copy it to a variable
* @param style a style name from lv_charts_builtin_t enum
* @param copy copy the style to this variable. (NULL if unused)
* @return pointer to an lv_charts_t style
*/
lv_charts_t * lv_charts_get(lv_charts_builtin_t style, lv_charts_t * copy);
opa_t lv_chart_get_data_opa(lv_obj_t * chart);
opa_t lv_chart_get_dark_effect(lv_obj_t * chart, opa_t dark_eff);
/**********************
* MACROS
**********************/

View File

@@ -29,14 +29,13 @@ static bool lv_ddlist_design(lv_obj_t * ddlist, const area_t * mask, lv_design_m
static lv_action_res_t lv_ddlist_rel_action(lv_obj_t * ddlist, lv_dispi_t * dispi);
static void lv_ddlist_refr_size(lv_obj_t * ddlist, bool anim_en);
static void lv_ddlist_pos_act_option(lv_obj_t * ddlist);
static void lv_ddlists_init(void);
/**********************
* STATIC VARIABLES
**********************/
static lv_ddlists_t lv_ddlists_def;
static lv_design_f_t ancestor_design_f;
static const char * def_options[] = {"Option 1", "Option 2", "Option 3", ""};
static const char * def_options[] = {"Option 1", "Option 2", "Option 3","Option 4", "Option 5", "Option 6",
"Option 7", "Option 8", "Option 9","Option 10", "Option 11", "Option 12",""};
/**********************
* MACROS
**********************/
@@ -71,6 +70,7 @@ lv_obj_t * lv_ddlist_create(lv_obj_t * par, lv_obj_t * copy)
ext->opened = 0;
ext->auto_size = 0;
ext->sel_opt = 0;
ext->style_sel = lv_style_get(LV_STYLE_PLAIN_COLOR, NULL);
/*The signal and design functions are not copied so set them here*/
if(ancestor_design_f == NULL) ancestor_design_f = lv_obj_get_design_f(new_ddlist);
@@ -80,12 +80,16 @@ lv_obj_t * lv_ddlist_create(lv_obj_t * par, lv_obj_t * copy)
/*Init the new drop down list drop down list*/
if(copy == NULL) {
lv_obj_set_drag(lv_page_get_scrl(new_ddlist), false);
lv_obj_t * scrl = lv_page_get_scrl(new_ddlist);
lv_obj_set_drag(scrl, false);
lv_obj_set_style(scrl, lv_style_get(LV_STYLE_TRANSP, NULL));
ext->opt_label = lv_label_create(new_ddlist, NULL);
lv_obj_set_style(ext->opt_label, NULL); /*Inherit the style*/
lv_rect_set_fit(new_ddlist, true, false);
lv_page_set_rel_action(new_ddlist, lv_ddlist_rel_action);
lv_obj_set_style(new_ddlist, lv_ddlists_get(LV_DDLISTS_DEF, NULL));
lv_page_set_sb_mode(new_ddlist, LV_PAGE_SB_MODE_DRAG);
lv_obj_set_style(new_ddlist, lv_style_get(LV_STYLE_PRETTY, NULL));
lv_ddlist_set_options(new_ddlist, def_options);
}
/*Copy an existing drop down list*/
@@ -121,19 +125,8 @@ bool lv_ddlist_signal(lv_obj_t * ddlist, lv_signal_t sign, void * param)
/* The object can be deleted so check its validity and then
* make the object specific signal handling */
if(valid != false) {
lv_ddlist_ext_t * ext = lv_obj_get_ext(ddlist);
lv_ddlists_t * style = lv_obj_get_style(ddlist);
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->opt_label, &style->label);
lv_ddlist_refr_size(ddlist, false);
break;
default:
break;
if(sign == LV_SIGNAL_STYLE_CHG) {
lv_ddlist_refr_size(ddlist, false);
}
}
@@ -209,6 +202,18 @@ void lv_ddlist_set_auto_size(lv_obj_t * ddlist, bool auto_size)
ext->auto_size = auto_size == false ? 0 : 1;
}
/**
* Set the style of the rectangle on the selected option
* @param ddlist pointer to a drop down list object
* @param style pointer the new style of the select rectangle
*/
void lv_dlist_set_style_select(lv_obj_t * ddlist, lv_style_t * style)
{
lv_ddlist_ext_t * ext = lv_obj_get_ext(ddlist);
ext->style_sel = style;
}
/*=====================
* Getter functions
*====================*/
@@ -238,7 +243,7 @@ uint16_t lv_ddlist_get_selected(lv_obj_t * ddlist)
/**
* Get the auto size attribute.
* @param ddlist pointer to a drop down list
* @param ddlist pointer to a drop down list object
* @return true: the auto_size is enabled, false: disabled
*/
bool lv_ddlist_get_auto_size(lv_obj_t * ddlist, bool auto_size)
@@ -248,34 +253,17 @@ bool lv_ddlist_get_auto_size(lv_obj_t * ddlist, bool auto_size)
}
/**
* Return with a pointer to a built-in style and/or copy it to a variable
* @param style a style name from lv_ddlists_builtin_t enum
* @param copy copy the style to this variable. (NULL if unused)
* @return pointer to an lv_ddlists_t style
* Get the style of the rectangle on the selected option
* @param ddlist pointer to a drop down list object
* @return pointer the style of the select rectangle
*/
lv_ddlists_t * lv_ddlists_get(lv_ddlists_builtin_t style, lv_ddlists_t * copy)
lv_style_t * lv_dlist_get_style_select(lv_obj_t * ddlist)
{
static bool style_inited = false;
lv_ddlist_ext_t * ext = lv_obj_get_ext(ddlist);
if(ext->style_sel == NULL) return lv_obj_get_style(ddlist);
/*Make the style initialization if it is not done yet*/
if(style_inited == false) {
lv_ddlists_init();
style_inited = true;
}
return ext->style_sel;
lv_ddlists_t *style_p;
switch(style) {
case LV_DDLISTS_DEF:
style_p = &lv_ddlists_def;
break;
default:
style_p = &lv_ddlists_def;
}
if(copy != NULL) memcpy(copy, style_p, sizeof(lv_ddlists_t));
return style_p;
}
/**********************
@@ -306,25 +294,25 @@ static bool lv_ddlist_design(lv_obj_t * ddlist, const area_t * mask, lv_design_m
/*If the list is opened draw a rectangle below the selected item*/
lv_ddlist_ext_t * ext = lv_obj_get_ext(ddlist);
if(ext->opened != 0) {
lv_ddlists_t * style = lv_obj_get_style(ddlist);
const font_t * font = style->label.font;
lv_style_t * style = lv_obj_get_style(ddlist);
const font_t * font = style->font;
cord_t font_h = font_get_height(font) >> LV_FONT_ANTIALIAS;
area_t rect_area;
lv_style_t * style_page_scrl = lv_obj_get_style(lv_page_get_scrl(ddlist));
rect_area.y1 = ext->opt_label->cords.y1;
rect_area.y1 += ext->sel_opt * (font_h + style->label.line_space);
rect_area.y1 -= style->sel.vpad;
rect_area.y1 += ext->sel_opt * (font_h + style->line_space);
rect_area.y1 -= style->line_space / 2;
rect_area.y2 = rect_area.y1 + font_h + 2 * style->sel.vpad;
rect_area.x1 = ext->opt_label->cords.x1 - style->page.scrl.hpad;
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.x2 = rect_area.x1 + lv_obj_get_width(lv_page_get_scrl(ddlist));
lv_draw_rect(&rect_area, mask, &style->sel);
lv_draw_rect(&rect_area, mask, ext->style_sel);
}
}
/*Post draw when the children are drawn*/
else if(mode == LV_DESIGN_DRAW_POST) {
ancestor_design_f(ddlist, mask, mode);
}
return true;
@@ -386,19 +374,20 @@ static lv_action_res_t lv_ddlist_rel_action(lv_obj_t * ddlist, lv_dispi_t * disp
static void lv_ddlist_refr_size(lv_obj_t * ddlist, bool anim_en)
{
lv_ddlist_ext_t * ext = lv_obj_get_ext(ddlist);
lv_ddlists_t * style = lv_obj_get_style(ddlist);
lv_style_t * style = lv_obj_get_style(ddlist);
cord_t new_height;
if(ext->opened != 0) { /*Open the list*/
new_height = lv_obj_get_height(lv_page_get_scrl(ddlist)) + 2 * style->page.bg.vpad;
new_height = lv_obj_get_height(lv_page_get_scrl(ddlist)) + 2 * style->vpad;
lv_obj_t * parent = lv_obj_get_parent(ddlist);
/*Reduce the height if enabled and required*/
if(ext->auto_size != 0 && new_height + ddlist->cords.y1 > parent->cords.y2) {
new_height = parent->cords.y2 - ddlist->cords.y1;
}
} else { /*Close the list*/
const font_t * font = style->label.font;
const font_t * font = style->font;
lv_style_t * label_style = lv_obj_get_style(ext->opt_label);
cord_t font_h = font_get_height(font) >> LV_FONT_ANTIALIAS;
new_height = font_h + 2 * style->sel.vpad;
new_height = font_h + 2 * label_style->line_space;
}
if(anim_en == false) {
lv_obj_set_height(ddlist, new_height);
@@ -429,42 +418,14 @@ static void lv_ddlist_refr_size(lv_obj_t * ddlist, bool anim_en)
static void lv_ddlist_pos_act_option(lv_obj_t * ddlist)
{
lv_ddlist_ext_t * ext = lv_obj_get_ext(ddlist);
lv_ddlists_t * style = lv_obj_get_style(ddlist);
const font_t * font = style->label.font;
lv_style_t * style = lv_obj_get_style(ddlist);
const font_t * font = style->font;
cord_t font_h = font_get_height(font) >> LV_FONT_ANTIALIAS;
lv_style_t * label_style = lv_obj_get_style(ext->opt_label);
lv_obj_t * scrl = lv_page_get_scrl(ddlist);
lv_style_t * style_scrl = lv_obj_get_style(scrl);
lv_obj_set_y(lv_page_get_scrl(ddlist),
-(ext->sel_opt * (font_h + style->label.line_space) +
style->page.scrl.vpad) + style->sel.vpad);
}
/**
* Initialize the built-in drop down list styles
*/
static void lv_ddlists_init(void)
{
/*Plain style*/
lv_pages_get(LV_PAGES_PAPER, &lv_ddlists_def.page);
lv_ddlists_def.page.bg.base.color = COLOR_WHITE;
lv_ddlists_def.page.bg.gcolor = COLOR_SILVER;
lv_ddlists_def.page.bg.bopa = OPA_50;
lv_ddlists_def.page.bg.swidth = LV_DPI / 8;
lv_ddlists_def.page.scrl.hpad = LV_DPI / 10;
lv_ddlists_def.page.scrl.vpad = LV_DPI / 4;
lv_ddlists_def.page.scrl.opad = 0;
lv_ddlists_def.page.sb_mode = LV_PAGE_SB_MODE_OFF;
lv_labels_get(LV_LABELS_TXT, &lv_ddlists_def.label);
lv_ddlists_def.label.line_space = LV_DPI / 4;
lv_rects_get(LV_RECTS_PLAIN, &lv_ddlists_def.sel);
lv_ddlists_def.sel.bwidth = 0;
lv_ddlists_def.sel.radius = 0;
lv_ddlists_def.sel.vpad = LV_DPI / 8;
lv_obj_set_y(scrl, -(ext->sel_opt * (font_h + label_style->line_space) - label_style->line_space) - style_scrl->hpad);
}

View File

@@ -28,26 +28,13 @@ typedef struct
lv_page_ext_t page; /*Ext. of ancestor*/
/*New data for this type */
lv_obj_t * opt_label; /*Label for the options*/
lv_style_t * style_sel; /*Style of the selected option*/
lv_action_res_t (*cb)(lv_obj_t *, uint16_t); /*Pointer to function to call when an option is slected*/
uint16_t sel_opt; /*Index of the current option*/
uint8_t opened :1; /*1: The list is opened*/
uint8_t auto_size :1; /*1: Set height to show all options. 0: Set height maximum to the parent bottom*/
}lv_ddlist_ext_t;
/*Style of drop down list*/
typedef struct
{
lv_pages_t page; /*Style of ancestor*/
/*New style element for this type */
lv_rects_t sel; /*Select the 'selected' rectangle*/
lv_labels_t label; /*Style of labels*/
}lv_ddlists_t;
/*Built-in styles of drop down list*/
typedef enum
{
LV_DDLISTS_DEF, /*Default drop down list*/
}lv_ddlists_builtin_t;
/**********************
* GLOBAL PROTOTYPES
@@ -105,6 +92,8 @@ void lv_ddlist_set_action(lv_obj_t * ddlist, lv_action_res_t (*cb)(lv_obj_t *, u
*/
void lv_ddlist_set_auto_size(lv_obj_t * ddlist, bool auto_size);
void lv_dlist_set_style_select(lv_obj_t * ddlist, lv_style_t * style);
/**
* Get the options of a drop down list
* @param ddlist pointer to drop down list object
@@ -126,13 +115,7 @@ uint16_t lv_ddlist_get_selected(lv_obj_t * ddlist);
*/
bool lv_ddlist_get_auto_size(lv_obj_t * ddlist, bool auto_size);
/**
* Return with a pointer to a built-in style and/or copy it to a variable
* @param style a style name from lv_ddlists_builtin_t enum
* @param copy copy the style to this variable. (NULL if unused)
* @return pointer to an lv_ddlists_t style
*/
lv_ddlists_t * lv_ddlists_get(lv_ddlists_builtin_t style, lv_ddlists_t * copy);
lv_style_t * lv_dlist_get_style_select(lv_obj_t * ddlist);
/**********************
* MACROS

View File

@@ -31,16 +31,12 @@
* STATIC PROTOTYPES
**********************/
static bool lv_img_design(lv_obj_t * img, const area_t * mask, lv_design_mode_t mode);
static void lv_imgs_init(void);
static bool lv_img_is_symbol(const char * txt);
/**********************
* STATIC VARIABLES
**********************/
static lv_imgs_t lv_imgs_def;
static lv_imgs_t lv_imgs_light;
static lv_imgs_t lv_imgs_dark;
/**********************
* MACROS
@@ -83,10 +79,10 @@ lv_obj_t * lv_img_create(lv_obj_t * par, lv_obj_t * copy)
* and must be screen sized*/
if(par != NULL) ext->auto_size = 1;
else ext->auto_size = 0;
lv_obj_set_style(new_img, lv_imgs_get(LV_IMGS_DEF, NULL));
lv_obj_set_style(new_img, lv_style_get(LV_STYLE_PLAIN, NULL));
} else {
ext->auto_size = lv_img_get_auto_size(copy);
lv_img_set_file(new_img, LV_EA(copy, lv_img_ext_t)->fn);
lv_img_set_file(new_img, ext->fn);
/*Refresh the style with new signal function*/
lv_obj_refr_style(new_img);
@@ -113,6 +109,7 @@ bool lv_img_signal(lv_obj_t * img, lv_signal_t sign, void * param)
if(valid != false) {
lv_img_ext_t * img_p = lv_obj_get_ext(img);
switch(sign) {
/*TODO set file again if style changed with symbols*/
case LV_SIGNAL_CLEANUP:
dm_free(img_p->fn);
break;
@@ -124,46 +121,6 @@ bool lv_img_signal(lv_obj_t * img, lv_signal_t sign, void * param)
return valid;
}
/**
* Return with a pointer to built-in style and/or copy it to a variable
* @param style a style name from lv_imgs_builtin_t enum
* @param copy copy the style to this variable. (NULL if unused)
* @return pointer to an lv_imgs_t style
*/
lv_imgs_t * lv_imgs_get(lv_imgs_builtin_t style, lv_imgs_t * copy)
{
static bool style_inited = false;
/*Make the style initialization if it is not done yet*/
if(style_inited == false) {
lv_imgs_init();
style_inited = true;
}
lv_imgs_t * style_p;
switch(style) {
case LV_IMGS_DEF:
style_p = &lv_imgs_def;
break;
case LV_IMGS_LIGHT:
style_p = &lv_imgs_light;
break;
case LV_IMGS_DARK:
style_p = &lv_imgs_dark;
break;
default:
style_p = &lv_imgs_def;
}
if(copy != NULL) {
if(style_p != NULL) memcpy(copy, style_p, sizeof(lv_imgs_t));
else memcpy(copy, &lv_imgs_def, sizeof(lv_imgs_t));
}
return style_p;
}
/**
* Create a file to the RAMFS from a picture data
* @param fn file name of the new file (e.g. "pic1", will be available at "U:/pic1")
@@ -227,9 +184,9 @@ void lv_img_set_file(lv_obj_t * img, const char * fn)
/*Handle symbol texts*/
else {
#if LV_IMG_ENABLE_SYMBOLS
lv_imgs_t * imgs = lv_obj_get_style(img);
lv_style_t * style = lv_obj_get_style(img);
point_t size;
txt_get_size(&size, fn, imgs->sym_font, 0, 0, LV_CORD_MAX, TXT_FLAG_NONE);
txt_get_size(&size, fn, style->font, 0, 0, LV_CORD_MAX, TXT_FLAG_NONE);
ext->w = size.x;
ext->h = size.y;
ext->transp = 0;
@@ -334,7 +291,7 @@ bool lv_img_get_upscale(lv_obj_t * img)
*/
static bool lv_img_design(lv_obj_t * img, const area_t * mask, lv_design_mode_t mode)
{
lv_imgs_t * imgs_p = lv_obj_get_style(img);
lv_style_t * style = lv_obj_get_style(img);
lv_img_ext_t * ext = lv_obj_get_ext(img);
if(mode == LV_DESIGN_COVER_CHK) {
@@ -350,13 +307,6 @@ static bool lv_img_design(lv_obj_t * img, const area_t * mask, lv_design_mode_t
/*Create a default style for symbol texts*/
#if LV_IMG_ENABLE_SYMBOLS != 0
bool sym = lv_img_is_symbol(ext->fn);
lv_labels_t sym_style;
lv_labels_get(LV_LABELS_TXT, &sym_style);
sym_style.font = imgs_p->sym_font;
sym_style.letter_space = 0;
sym_style.line_space = 0;
sym_style.mid = 0;
sym_style.base.color = imgs_p->base.color;
#endif
lv_obj_get_cords(img, &cords);
@@ -371,10 +321,10 @@ static bool lv_img_design(lv_obj_t * img, const area_t * mask, lv_design_mode_t
for(; cords_tmp.x1 < cords.x2; cords_tmp.x1 += ext->w, cords_tmp.x2 += ext->w) {
#if LV_IMG_ENABLE_SYMBOLS == 0
lv_draw_img(&cords_tmp, mask, imgs_p, opa, ext->fn);
lv_draw_img(&cords_tmp, mask, style, opa, ext->fn);
#else
if(sym == false) lv_draw_img(&cords_tmp, mask, imgs_p, ext->fn);
else lv_draw_label(&cords_tmp, mask, &sym_style, ext->fn, TXT_FLAG_NONE);
if(sym == false) lv_draw_img(&cords_tmp, mask, style, ext->fn);
else lv_draw_label(&cords_tmp, mask, style, ext->fn, TXT_FLAG_NONE);
#endif
}
}
@@ -405,26 +355,5 @@ static bool lv_img_is_symbol(const char * txt)
return true;
}
/**
* Initialize the image styles
*/
static void lv_imgs_init(void)
{
/*Default style*/
lv_imgs_def.base.color = COLOR_BLACK;
lv_imgs_def.base.opa = OPA_COVER;
lv_imgs_def.recolor_opa = OPA_TRANSP;
#if LV_IMG_ENABLE_SYMBOLS != 0
lv_imgs_def.sym_font = font_get(LV_IMG_DEF_SYMBOL_FONT);
#endif
/*Dark style*/
memcpy(&lv_imgs_dark, &lv_imgs_def, sizeof(lv_imgs_t));
lv_imgs_dark.base.color = COLOR_BLACK; lv_imgs_dark.recolor_opa = OPA_50;
/*Light style*/
memcpy(&lv_imgs_light, &lv_imgs_dark, sizeof(lv_imgs_t));
lv_imgs_light.base.color = COLOR_WHITE; lv_imgs_light.recolor_opa = OPA_50;
}
#endif

View File

@@ -49,26 +49,6 @@ typedef struct
uint8_t transp :1; /*Transp. bit in the image header (Handled by the library)*/
}lv_img_ext_t;
/*Style of image*/
typedef struct
{
lv_objs_t base; /*Style of ancestor*/
/*New style element for this type */
opa_t recolor_opa; /*Intensity of recoloring with base.color (OPA_TRANSP, OPA_10 ... OPA_COVER)*/
#if LV_IMG_ENABLE_SYMBOLS != 0
const font_t * sym_font; /*Symbol font is the image is used as icon*/
#endif
}lv_imgs_t;
/*Built-in styles of image*/
typedef enum
{
LV_IMGS_DEF,
LV_IMGS_LIGHT,
LV_IMGS_DARK,
}lv_imgs_builtin_t;
/* Image header it is compatible with
* the result image converter utility*/
typedef struct
@@ -79,7 +59,6 @@ typedef struct
uint16_t transp :1; /*1: Do not draw LV_IMG_TRANSP_COLOR pixels*/
}lv_img_raw_header_t;
/**********************
* GLOBAL PROTOTYPES
**********************/
@@ -101,14 +80,6 @@ lv_obj_t * lv_img_create(lv_obj_t * par, lv_obj_t * copy);
*/
bool lv_img_signal(lv_obj_t * img, lv_signal_t sign, void * param);
/**
* Return with a pointer to built-in style and/or copy it to a variable
* @param style a style name from lv_imgs_builtin_t enum
* @param copy copy the style to this variable. (NULL if unused)
* @return pointer to an lv_imgs_t style
*/
lv_imgs_t * lv_imgs_get(lv_imgs_builtin_t style, lv_imgs_t * copy);
/**
* Create a file to the RAMFS from a picture data
* @param fn file name of the new file (e.g. "pic1", will be available at "U:/pic1")
@@ -154,10 +125,6 @@ bool lv_img_get_auto_size(lv_obj_t * img);
*/
bool lv_img_get_upscale(lv_obj_t * img);
lv_imgs_t * lv_imgs_get(lv_imgs_builtin_t style, lv_imgs_t * copy);
/**********************
* MACROS
**********************/

View File

@@ -49,15 +49,10 @@
**********************/
static bool lv_label_design(lv_obj_t * label, const area_t * mask, lv_design_mode_t mode);
static void lv_label_refr_text(lv_obj_t * label);
static void lv_labels_init(void);
/**********************
* STATIC VARIABLES
**********************/
static lv_labels_t lv_labels_title;
static lv_labels_t lv_labels_txt;
static lv_labels_t lv_labels_btn;
/**********************
* MACROS
**********************/
@@ -95,7 +90,7 @@ lv_obj_t * lv_label_create(lv_obj_t * par, lv_obj_t * copy)
/*Init the new label*/
if(copy == NULL) {
lv_obj_set_click(new_label, false);
lv_obj_set_style(new_label, lv_labels_get(LV_LABELS_TXT, NULL));
lv_obj_set_style(new_label, NULL);
lv_label_set_long_mode(new_label, LV_LABEL_LONG_EXPAND);
lv_label_set_text(new_label, "Text");
}
@@ -354,7 +349,7 @@ void lv_label_get_letter_pos(lv_obj_t * label, uint16_t index, point_t * pos)
uint32_t line_start = 0;
uint32_t new_line_start = 0;
cord_t max_w = lv_obj_get_width(label);
lv_labels_t * style = lv_obj_get_style(label);
lv_style_t * style = lv_obj_get_style(label);
const font_t * font = style->font;
uint8_t letter_height = font_get_height(font) >> LV_FONT_ANTIALIAS;
cord_t y = 0;
@@ -396,7 +391,7 @@ void lv_label_get_letter_pos(lv_obj_t * label, uint16_t index, point_t * pos)
x += (font_get_width(font, text[i]) >> LV_FONT_ANTIALIAS) + style->letter_space;
}
if(style->mid != 0) {
if(style->txt_align != 0) {
cord_t line_w;
line_w = txt_get_width(&text[line_start], new_line_start - line_start,
font, style->letter_space, flag);
@@ -421,7 +416,7 @@ uint16_t lv_label_get_letter_on(lv_obj_t * label, point_t * pos)
uint32_t line_start = 0;
uint32_t new_line_start = 0;
cord_t max_w = lv_obj_get_width(label);
lv_labels_t * style = lv_obj_get_style(label);
lv_style_t * style = lv_obj_get_style(label);
const font_t * font = style->font;
uint8_t letter_height = font_get_height(font) >> LV_FONT_ANTIALIAS;
cord_t y = 0;
@@ -444,7 +439,7 @@ uint16_t lv_label_get_letter_on(lv_obj_t * label, point_t * pos)
/*Calculate the x coordinate*/
cord_t x = 0;
if(style->mid != 0) {
if(style->txt_align != 0) {
cord_t line_w;
line_w = txt_get_width(&text[line_start], new_line_start - line_start,
font, style->letter_space, flag);
@@ -469,43 +464,6 @@ uint16_t lv_label_get_letter_on(lv_obj_t * label, point_t * pos)
return i;
}
/**
* Return with a pointer to a built-in style and/or copy it to a variable
* @param style a style name from lv_labels_builtin_t enum
* @param copy copy the style to this variable. (NULL if unused)
* @return pointer to an lv_labels_t style
*/
lv_labels_t * lv_labels_get(lv_labels_builtin_t style, lv_labels_t * copy)
{
static bool style_inited = false;
/*Make the style initialization if it is not done yet*/
if(style_inited == false) {
lv_labels_init();
style_inited = true;
}
lv_labels_t * style_p;
switch(style) {
case LV_LABELS_TXT:
style_p = &lv_labels_txt;
break;
case LV_LABELS_TITLE:
style_p = &lv_labels_title;
break;
case LV_LABELS_BTN:
style_p = &lv_labels_btn;
break;
default:
style_p = &lv_labels_txt;
}
if(copy != NULL) memcpy(copy, style_p, sizeof(lv_labels_t));
return style_p;
}
/**********************
* STATIC FUNCTIONS
@@ -554,7 +512,7 @@ static void lv_label_refr_text(lv_obj_t * label)
if(ext->txt == NULL) return;
cord_t max_w = lv_obj_get_width(label);
lv_labels_t * style = lv_obj_get_style(label);
lv_style_t * style = lv_obj_get_style(label);
const font_t * font = style->font;
ext->dot_end = LV_LABEL_DOT_END_INV; /*Initialize the dot end index*/
@@ -661,26 +619,4 @@ static void lv_label_refr_text(lv_obj_t * label)
lv_obj_inv(label);
}
/**
* Initialize the label styles
*/
static void lv_labels_init(void)
{
/*Text style*/
lv_objs_get(LV_OBJS_PLAIN, &lv_labels_txt.base);
lv_labels_txt.base.color = COLOR_MAKE(0x20, 0x20, 0x20);
lv_labels_txt.font = font_get(LV_FONT_DEFAULT);
lv_labels_txt.letter_space = 1 * LV_DOWNSCALE;
lv_labels_txt.line_space = 2 * LV_DOWNSCALE;
lv_labels_txt.mid = 0;
memcpy(&lv_labels_btn, &lv_labels_txt, sizeof(lv_labels_t));
lv_labels_btn.base.color = COLOR_MAKE(0x20, 0x20, 0x20);
lv_labels_btn.mid = 1;
memcpy(&lv_labels_title, &lv_labels_txt, sizeof(lv_labels_t));
lv_labels_title.letter_space = 4 * LV_DOWNSCALE;
lv_labels_title.line_space = 4 * LV_DOWNSCALE;
lv_labels_title.mid = 0;
}
#endif

View File

@@ -47,25 +47,6 @@ typedef struct
uint8_t recolor :1; /*Enable in-line letter re-coloring*/
}lv_label_ext_t;
/*Style of label*/
typedef struct
{
lv_objs_t base; /*Style of ancestor*/
/*New style element for this type */
const font_t * font; /*Pointer to a font*/
cord_t letter_space; /*Letter space in px*/
cord_t line_space; /*Line space in px*/
uint8_t mid:1; /*1: Align the lines into the middle*/
}lv_labels_t;
/*Built-in styles of label*/
typedef enum
{
LV_LABELS_TXT, /*General text style*/
LV_LABELS_TITLE, /*Like text style but greater spaces*/
LV_LABELS_BTN, /*Mid. aligned style for buttons*/
}lv_labels_builtin_t;
/**********************
* GLOBAL PROTOTYPES
**********************/
@@ -168,14 +149,6 @@ void lv_label_get_letter_pos(lv_obj_t * label, uint16_t index, point_t * pos);
*/
uint16_t lv_label_get_letter_on(lv_obj_t * label, point_t * pos);
/**
* Return with a pointer to a built-in style and/or copy it to a variable
* @param style a style name from lv_labels_builtin_t enum
* @param copy copy the style to this variable. (NULL if unused)
* @return pointer to an lv_labels_t style
*/
lv_labels_t * lv_labels_get(lv_labels_builtin_t style, lv_labels_t * copy);
/**********************
* MACROS
**********************/

View File

@@ -29,14 +29,10 @@
* STATIC PROTOTYPES
**********************/
static bool lv_led_design(lv_obj_t * led, const area_t * mask, lv_design_mode_t mode);
static void lv_leds_init(void);
/**********************
* STATIC VARIABLES
**********************/
static lv_leds_t lv_leds_red;
static lv_leds_t lv_leds_green;
static lv_design_f_t ancestor_design_f;
/**********************
@@ -75,7 +71,7 @@ lv_obj_t * lv_led_create(lv_obj_t * par, lv_obj_t * copy)
/*Init the new led object*/
if(copy == NULL) {
lv_obj_set_style(new_led, lv_leds_get(LV_LEDS_RED, NULL));
lv_obj_set_style(new_led, lv_style_get(LV_STYLE_PRETTY_COLOR, NULL));
lv_obj_set_size(new_led, LV_LED_WIDTH_DEF, LV_LED_HEIGHT_DEF);
}
/*Copy an existing object*/
@@ -183,40 +179,6 @@ uint8_t lv_led_get_bright(lv_obj_t * led)
return ext->bright;
}
/**
* Return with a pointer to a built-in style and/or copy it to a variable
* @param style a style name from lv_leds_builtin_t enum
* @param copy copy the style to this variable. (NULL if unused)
* @return pointer to an lv_leds_t style
*/
lv_leds_t * lv_leds_get(lv_leds_builtin_t style, lv_leds_t * copy)
{
static bool style_inited = false;
/*Make the style initialization if it is not done yet*/
if(style_inited == false) {
lv_leds_init();
style_inited = true;
}
lv_leds_t *style_p;
switch(style) {
case LV_LEDS_RED:
style_p = &lv_leds_red;
break;
case LV_LEDS_GREEN:
style_p = &lv_leds_green;
break;
default:
style_p = &lv_leds_red;
}
if(copy != NULL) memcpy(copy, style_p, sizeof(lv_leds_t));
return style_p;
}
/**********************
* STATIC FUNCTIONS
**********************/
@@ -239,18 +201,18 @@ static bool lv_led_design(lv_obj_t * led, const area_t * mask, lv_design_mode_t
} else if(mode == LV_DESIGN_DRAW_MAIN) {
/*Make darker colors in a temporary style according to the brightness*/
lv_led_ext_t * ext = lv_obj_get_ext(led);
lv_leds_t * style = lv_obj_get_style(led);
lv_style_t * style = lv_obj_get_style(led);
/*Create a temporal style*/
lv_leds_t leds_tmp;
lv_style_t leds_tmp;
memcpy(&leds_tmp, style, sizeof(leds_tmp));
/*Mix. the color with black proportionally with brightness*/
leds_tmp.bg_rect.base.color = color_mix(leds_tmp.bg_rect.base.color, COLOR_BLACK, ext->bright);
leds_tmp.bg_rect.gcolor = color_mix(leds_tmp.bg_rect.gcolor, COLOR_BLACK, ext->bright);
leds_tmp.mcolor = color_mix(leds_tmp.mcolor, COLOR_BLACK, ext->bright);
leds_tmp.gcolor = color_mix(leds_tmp.gcolor, COLOR_BLACK, ext->bright);
/*Set the current swidth according to brightness proportionally between LV_LED_BRIGHT_OFF and LV_LED_BRIGHT_ON*/
leds_tmp.bg_rect.swidth = (uint16_t)(uint16_t)(ext->bright * style->bg_rect.swidth) >> 8;
leds_tmp.swidth = (uint16_t)(uint16_t)(ext->bright * style->swidth) >> 8;
led->style_p = &leds_tmp;
ancestor_design_f(led, mask, mode);
@@ -259,29 +221,4 @@ static bool lv_led_design(lv_obj_t * led, const area_t * mask, lv_design_mode_t
return true;
}
/**
* Initialize the led styles
*/
static void lv_leds_init(void)
{
/*Default style (red)*/
lv_rects_get(LV_RECTS_PLAIN, &lv_leds_red.bg_rect);
lv_leds_red.bg_rect.base.color = COLOR_RED;
lv_leds_red.bg_rect.gcolor = COLOR_MARRON,
lv_leds_red.bg_rect.bcolor = COLOR_MAKE(0x40, 0x00, 0x00);
lv_leds_red.bg_rect.scolor = COLOR_RED;
lv_leds_red.bg_rect.bwidth = 3 * LV_DOWNSCALE;
lv_leds_red.bg_rect.bopa = OPA_50;
lv_leds_red.bg_rect.swidth = LV_DPI / 4;
lv_leds_red.bg_rect.radius = LV_RECT_CIRCLE;
/* Green style */
memcpy(&lv_leds_green, &lv_leds_red, sizeof(lv_leds_t));
lv_leds_green.bg_rect.base.color = COLOR_LIME;
lv_leds_green.bg_rect.gcolor = COLOR_GREEN;
lv_leds_green.bg_rect.bcolor = COLOR_MAKE(0x00, 0x40, 0x00);
lv_leds_green.bg_rect.scolor = COLOR_LIME;
}
#endif

View File

@@ -35,20 +35,6 @@ typedef struct
uint8_t bright; /*Current brightness of the LED (0..255)*/
}lv_led_ext_t;
/*Style of led*/
typedef struct
{
lv_rects_t bg_rect; /*Style of ancestor*/
/*New style element for this type */
}lv_leds_t;
/*Built-in styles of led*/
typedef enum
{
LV_LEDS_RED, /*Red LED style*/
LV_LEDS_GREEN, /*Green LED style*/
}lv_leds_builtin_t;
/**********************
* GLOBAL PROTOTYPES
**********************/
@@ -102,15 +88,6 @@ void lv_led_tgl(lv_obj_t * led);
*/
uint8_t lv_led_get_bright(lv_obj_t * led);
/**
* Return with a pointer to a built-in style and/or copy it to a variable
* @param style a style name from lv_leds_builtin_t enum
* @param copy copy the style to this variable. (NULL if unused)
* @return pointer to an lv_leds_t style
*/
lv_leds_t * lv_leds_get(lv_leds_builtin_t style, lv_leds_t * copy);
/**********************
* MACROS
**********************/

View File

@@ -34,12 +34,10 @@
* STATIC PROTOTYPES
**********************/
static bool lv_line_design(lv_obj_t * line, const area_t * mask, lv_design_mode_t mode);
static void lv_lines_init(void);
/**********************
* STATIC VARIABLES
**********************/
static lv_lines_t lv_lines_def;
/**********************
* MACROS
@@ -74,7 +72,7 @@ lv_obj_t * lv_line_create(lv_obj_t * par, lv_obj_t * copy)
/*Init the new rectangle*/
if(copy == NULL) {
lv_obj_set_style(new_line, lv_lines_get(LV_LINES_DEF, NULL));
lv_obj_set_style(new_line, lv_style_get(LV_STYLE_PLAIN, NULL));
}
/*Copy an existing object*/
else {
@@ -82,8 +80,7 @@ lv_obj_t * lv_line_create(lv_obj_t * par, lv_obj_t * copy)
lv_line_set_y_inv(new_line,lv_line_get_y_inv(copy));
lv_line_set_auto_size(new_line,lv_line_get_auto_size(copy));
lv_line_set_upscale(new_line,lv_line_get_upscale(copy));
lv_line_set_points(new_line, LV_EA(copy, lv_line_ext_t)->point_array,
LV_EA(copy, lv_line_ext_t)->point_num);
lv_line_set_points(new_line, ext->point_array, ext->point_num);
/*Refresh the style with new signal function*/
lv_obj_refr_style(new_line);
}
@@ -147,8 +144,8 @@ void lv_line_set_points(lv_obj_t * line, const point_t * point_a, uint16_t point
ymax = MATH_MAX(point_a[i].y * us, ymax);
}
lv_lines_t * lines = lv_obj_get_style(line);
lv_obj_set_size(line, xmax + lines->width, ymax + lines->width);
lv_style_t * lines = lv_obj_get_style(line);
lv_obj_set_size(line, xmax + lines->line_width, ymax + lines->line_width);
}
}
@@ -241,36 +238,6 @@ bool lv_line_get_upscale(lv_obj_t * line)
return ext->upscale == 0 ? false : true;
}
/**
* Return with a pointer to a built-in style and/or copy it to a variable
* @param style a style name from lv_lines_builtin_t enum
* @param copy copy the style to this variable. (NULL if unused)
* @return pointer to an lv_lines_t style
*/
lv_lines_t * lv_lines_get(lv_lines_builtin_t style, lv_lines_t * copy)
{
static bool style_inited = false;
/*Make the style initialization if it is not done yet*/
if(style_inited == false) {
lv_lines_init();
style_inited = true;
}
lv_lines_t *style_p;
switch(style) {
case LV_LINES_DEF:
style_p = &lv_lines_def;
break;
default:
style_p = &lv_lines_def;
}
if(copy != NULL) memcpy(copy, style_p, sizeof(lv_lines_t));
return style_p;
}
/**********************
* STATIC FUNCTIONS
**********************/
@@ -294,7 +261,7 @@ static bool lv_line_design(lv_obj_t * line, const area_t * mask, lv_design_mode_
if(ext->point_num == 0 || ext->point_array == NULL) return false;
lv_lines_t * style = lv_obj_get_style(line);
lv_style_t * style = lv_obj_get_style(line);
area_t area;
lv_obj_get_cords(line, &area);
cord_t x_ofs = area.x1;
@@ -327,14 +294,4 @@ static bool lv_line_design(lv_obj_t * line, const area_t * mask, lv_design_mode_
return true;
}
/**
* Initialize the line styles
*/
static void lv_lines_init(void)
{
/*Default style*/
lv_lines_def.width = LV_DPI / 25;
lv_lines_def.base.color = COLOR_RED;
lv_lines_def.base.opa = OPA_COVER;
}
#endif

View File

@@ -33,20 +33,6 @@ typedef struct
uint8_t upscale :1; /*1: upscale coordinates with LV_DOWNSCALE*/
}lv_line_ext_t;
/*Style of line*/
typedef struct
{
lv_objs_t base; /*Style of ancestor*/
/*New style element for this type */
cord_t width; /*Line width*/
}lv_lines_t;
/*Built-in styles of line*/
typedef enum
{
LV_LINES_DEF,
}lv_lines_builtin_t;
/**********************
* GLOBAL PROTOTYPES
**********************/
@@ -121,14 +107,6 @@ bool lv_line_get_y_inv(lv_obj_t * line);
*/
bool lv_line_get_upscale(lv_obj_t * line);
/**
* Return with a pointer to a built-in style and/or copy it to a variable
* @param style a style name from lv_lines_builtin_t enum
* @param copy copy the style to this variable. (NULL if unused)
* @return pointer to an lv_lines_t style
*/
lv_lines_t * lv_lines_get(lv_lines_builtin_t style, lv_lines_t * copy);
/**********************
* MACROS
**********************/

View File

@@ -28,13 +28,10 @@
#if 0
static bool lv_list_design(lv_obj_t * list, const area_t * mask, lv_design_mode_t mode);
#endif
static void lv_lists_init(void);
/**********************
* STATIC VARIABLES
**********************/
static lv_lists_t lv_lists_def;
static lv_lists_t lv_lists_transp;
/**********************
* MACROS
@@ -62,13 +59,22 @@ lv_obj_t * lv_list_create(lv_obj_t * par, lv_obj_t * copy)
lv_list_ext_t * ext = lv_obj_alloc_ext(new_list, sizeof(lv_list_ext_t));
dm_assert(ext);
ext->width_sb = 0;
ext->styles_liste[LV_BTN_STATE_REL] = lv_style_get(LV_STYLE_BTN_REL, NULL);
ext->styles_liste[LV_BTN_STATE_PR] = lv_style_get(LV_STYLE_BTN_PR, NULL);
ext->styles_liste[LV_BTN_STATE_TREL] = lv_style_get(LV_STYLE_BTN_TREL, NULL);
ext->styles_liste[LV_BTN_STATE_PR] = lv_style_get(LV_STYLE_BTN_TPR, NULL);
ext->styles_liste[LV_BTN_STATE_INA] = lv_style_get(LV_STYLE_BTN_INA, NULL);
lv_obj_set_signal_f(new_list, lv_list_signal);
/*Init the new list object*/
if(copy == NULL) {
lv_obj_set_size_us(new_list, 120, 150);
lv_obj_set_style(new_list, lv_lists_get(LV_LISTS_DEF, NULL));
lv_rect_set_layout(LV_EA(new_list, lv_list_ext_t)->page.scrl, LV_LIST_LAYOUT_DEF);
lv_obj_set_size_us(new_list, 2 * LV_DPI, 3 * LV_DPI);
lv_rect_set_layout(ext->page.scrl, LV_LIST_LAYOUT_DEF);
lv_obj_set_style(new_list, lv_style_get(LV_STYLE_TRANSP_TIGHT, NULL));
lv_obj_set_style(lv_page_get_scrl(new_list), lv_style_get(LV_STYLE_PRETTY, NULL));
lv_page_set_sb_mode(new_list, LV_PAGE_SB_MODE_AUTO);
} else {
/*Refresh the style with new signal function*/
lv_obj_refr_style(new_list);
@@ -89,15 +95,6 @@ bool lv_list_signal(lv_obj_t * list, lv_signal_t sign, void * param)
/* Include the ancient signal function */
valid = lv_page_signal(list, sign, param);
/* The object can be deleted so check its validity and then
* make the object specific signal handling */
if(valid != false) {
switch(sign) {
default:
break;
}
}
return valid;
}
@@ -112,12 +109,16 @@ 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, lv_action_t rel_action)
{
lv_lists_t * lists = lv_obj_get_style(list);
lv_style_t * style = lv_obj_get_style(list);
lv_list_ext_t * ext = lv_obj_get_ext(list);
/*Create a list element with the image an the text*/
lv_obj_t * liste;
liste = lv_btn_create(list, NULL);
lv_obj_set_style(liste, &lists->liste_btn);
lv_btn_set_styles(liste, ext->styles_liste[LV_BTN_STATE_REL], ext->styles_liste[LV_BTN_STATE_PR],
ext->styles_liste[LV_BTN_STATE_TREL], ext->styles_liste[LV_BTN_STATE_TPR],
ext->styles_liste[LV_BTN_STATE_INA]);
lv_btn_set_rel_action(liste, rel_action);
lv_page_glue_obj(liste, true);
lv_rect_set_layout(liste, LV_RECT_LAYOUT_ROW_M);
@@ -126,28 +127,26 @@ lv_obj_t * lv_list_add(lv_obj_t * list, const char * img_fn, const char * txt, l
if(img_fn != NULL && img_fn[0] != '\0') {
lv_obj_t * img = lv_img_create(liste, NULL);
lv_img_set_file(img, img_fn);
lv_obj_set_style(img, &lists->liste_img);
lv_obj_set_style(img, ext->styles_liste[LV_BTN_STATE_REL]);
lv_obj_set_click(img, false);
}
if(txt != NULL) {
lv_obj_t * label = lv_label_create(liste, NULL);
lv_label_set_text(label, txt);
lv_obj_set_style(label,&lists->liste_label);
lv_obj_set_style(label, ext->styles_liste[LV_BTN_STATE_REL]);
lv_obj_set_click(label, false);
}
lv_lists_t * style = lv_obj_get_style(list);
/*Make the size adjustment*/
cord_t w = lv_obj_get_width(list);
cord_t hpad_tot = lists->page.bg.hpad + lists->page.scrl.hpad;
lv_style_t * style_scrl = lv_obj_get_style(lv_page_get_scrl(list));
cord_t hpad_tot = style->hpad + style_scrl->hpad;
w -= hpad_tot * 2;
/*Make place for the scrollbar if hpad_tot is too small*/
if(style->width_sb != 0) {
if(hpad_tot < lists->page.sb_width) w -= lists->page.sb_width - hpad_tot;
if(ext->width_sb != 0) {
if(hpad_tot < ext->page.sb_width) w -= ext->page.sb_width - hpad_tot;
}
lv_obj_set_width(liste, w);
@@ -203,6 +202,33 @@ void lv_list_down(lv_obj_t * list)
* Setter functions
*====================*/
/**
* Set styles of the list elements of a list in each state
* @param list pointer to list object
* @param rel pointer to a style for releases state
* @param pr pointer to a style for pressed state
* @param trel pointer to a style for toggled releases state
* @param tpr pointer to a style for toggled pressed state
* @param ina pointer to a style for inactive state
*/
void lv_list_set_styles_liste(lv_obj_t * list, lv_style_t * rel, lv_style_t * pr, lv_style_t * trel, lv_style_t * tpr, lv_style_t * ina)
{
lv_list_ext_t * ext = lv_obj_get_ext(list);
ext->styles_liste[LV_BTN_STATE_REL] = rel;
ext->styles_liste[LV_BTN_STATE_PR] = pr;
ext->styles_liste[LV_BTN_STATE_TREL] = trel;
ext->styles_liste[LV_BTN_STATE_TPR] = tpr;
ext->styles_liste[LV_BTN_STATE_INA] = ina;
lv_obj_t * liste = lv_obj_get_child(list, NULL);
while(liste != NULL) {
lv_btn_set_styles(liste, rel, pr, trel, tpr, ina);
liste = lv_obj_get_child(list, liste);
}
}
/*=====================
* Getter functions
@@ -220,38 +246,20 @@ const char * lv_list_element_get_txt(lv_obj_t * liste)
return lv_label_get_text(label);
}
/**
* Return with a pointer to a built-in style and/or copy it to a variable
* @param style a style name from lv_lists_builtin_t enum
* @param copy_p copy the style to this variable. (NULL if unused)
* @return pointer to an lv_lists_t style
* Get the style of the list elements in a given state
* @param list pointer to a button object
* @param state a state from 'lv_btn_state_t' in which style should be get
* @return pointer to the style in the given state
*/
lv_lists_t * lv_lists_get(lv_lists_builtin_t style, lv_lists_t * list)
lv_style_t * lv_list_get_style_liste(lv_obj_t * list, lv_btn_state_t state)
{
static bool style_inited = false;
lv_list_ext_t * ext = lv_obj_get_ext(list);
/*Make the style initialization if it is not done yet*/
if(style_inited == false) {
lv_lists_init();
style_inited = true;
}
if(ext->styles_liste[state] == NULL) return lv_obj_get_style(list);
lv_lists_t *style_p;
switch(style) {
case LV_LISTS_DEF:
style_p = &lv_lists_def;
break;
case LV_LISTS_TRANSP:
style_p = &lv_lists_transp;
break;
default:
style_p = &lv_lists_def;
}
if(list != NULL) memcpy(list, style_p, sizeof(lv_lists_t));
return style_p;
return ext->styles_liste[state];
}
@@ -283,41 +291,4 @@ static bool lv_list_design(lv_obj_t * list, const area_t * mask, lv_design_mode_
}
#endif
/**
* Initialize the list styles
*/
static void lv_lists_init(void)
{
/*Default style*/
lv_pages_get(LV_PAGES_MENU, &lv_lists_def.page);
lv_rects_get(LV_RECTS_TRANSP, &lv_lists_def.liste_btn.state_style[LV_BTN_STATE_REL]);
lv_rects_get(LV_RECTS_PLAIN, &lv_lists_def.liste_btn.state_style[LV_BTN_STATE_PR]);
lv_rects_get(LV_RECTS_TRANSP, &lv_lists_def.liste_btn.state_style[LV_BTN_STATE_TREL]);
lv_rects_get(LV_RECTS_PLAIN, &lv_lists_def.liste_btn.state_style[LV_BTN_STATE_TPR]);
lv_rects_get(LV_RECTS_PLAIN, &lv_lists_def.liste_btn.state_style[LV_BTN_STATE_INA]);
lv_lists_def.liste_btn.state_style[LV_BTN_STATE_REL].hpad = LV_DPI / 4;
lv_lists_def.liste_btn.state_style[LV_BTN_STATE_REL].vpad = LV_DPI / 4;
lv_lists_def.liste_btn.state_style[LV_BTN_STATE_REL].opad = LV_DPI / 6;
lv_lists_def.liste_btn.state_style[LV_BTN_STATE_PR].hpad = LV_DPI / 4;
lv_lists_def.liste_btn.state_style[LV_BTN_STATE_PR].vpad = LV_DPI / 4;
lv_lists_def.liste_btn.state_style[LV_BTN_STATE_PR].opad = LV_DPI / 6;
lv_lists_def.liste_btn.state_style[LV_BTN_STATE_PR].radius = 0;
lv_lists_def.liste_btn.state_style[LV_BTN_STATE_TREL].hpad = LV_DPI / 4;
lv_lists_def.liste_btn.state_style[LV_BTN_STATE_TREL].vpad = LV_DPI / 4;
lv_lists_def.liste_btn.state_style[LV_BTN_STATE_TREL].opad = LV_DPI / 6;
lv_lists_def.liste_btn.state_style[LV_BTN_STATE_TPR].hpad = LV_DPI / 4;
lv_lists_def.liste_btn.state_style[LV_BTN_STATE_TPR].vpad = LV_DPI / 4;
lv_lists_def.liste_btn.state_style[LV_BTN_STATE_TPR].opad = LV_DPI / 6;
lv_lists_def.liste_btn.state_style[LV_BTN_STATE_TPR].radius = 0;
lv_lists_def.liste_btn.state_style[LV_BTN_STATE_INA].hpad = LV_DPI / 4;
lv_lists_def.liste_btn.state_style[LV_BTN_STATE_INA].vpad = LV_DPI / 4;
lv_lists_def.liste_btn.state_style[LV_BTN_STATE_INA].opad = LV_DPI / 6;
lv_lists_def.liste_btn.state_style[LV_BTN_STATE_INA].radius = 0;
lv_labels_get(LV_LABELS_BTN, &lv_lists_def.liste_label); /*List element label style*/
lv_imgs_get(LV_IMGS_DEF, &lv_lists_def.liste_img); /*List element image style*/
memcpy(&lv_lists_transp, &lv_lists_def, sizeof(lv_lists_t));
lv_pages_get(LV_PAGES_TRANSP, &lv_lists_transp.page);
}
#endif

View File

@@ -43,27 +43,10 @@ typedef struct
{
lv_page_ext_t page; /*Ext. of ancestor*/
/*New data for this type */
/*No new data*/
lv_style_t * styles_liste[LV_BTN_STATE_NUM]; /*Styles of the list element buttons*/
uint8_t width_sb :1; /*1: Keep space for the scrollbar*/
}lv_list_ext_t;
/*Style of list*/
typedef struct
{
lv_pages_t page; /*Style of ancestor*/
/*New style element for this type */
lv_btns_t liste_btn; /*List element button style*/
lv_labels_t liste_label; /*List element label style*/
lv_imgs_t liste_img; /*List element image style*/
uint8_t width_sb :1; /*1: Keep space for the scrollbar*/
}lv_lists_t;
/*Built-in styles of list*/
typedef enum
{
LV_LISTS_DEF, /*Default list style. Transparent background, visible scrlollable object*/
LV_LISTS_TRANSP, /*Transparent list style. Transparent background and scrollable object*/
}lv_lists_builtin_t;
/**********************
* GLOBAL PROTOTYPES
**********************/
@@ -106,6 +89,7 @@ void lv_list_up(lv_obj_t * list);
*/
void lv_list_down(lv_obj_t * list);
void lv_list_set_styles_liste(lv_obj_t * list, lv_style_t * rel, lv_style_t * pr, lv_style_t * trel, lv_style_t * tpr, lv_style_t * ina);
/**
* Get the text of a list element
* @param liste pointer to list element
@@ -113,14 +97,7 @@ void lv_list_down(lv_obj_t * list);
*/
const char * lv_list_element_get_txt(lv_obj_t * liste);
/**
* Return with a pointer to a built-in style and/or copy it to a variable
* @param style a style name from lv_lists_builtin_t enum
* @param copy_p copy the style to this variable. (NULL if unused)
* @return pointer to an lv_lists_t style
*/
lv_lists_t * lv_lists_get(lv_lists_builtin_t style, lv_lists_t * list);
lv_style_t * lv_list_get_style_liste(lv_obj_t * list, lv_btn_state_t state);
/**********************
* MACROS
**********************/

View File

@@ -32,18 +32,12 @@
#if 0 /*Unused*/
static bool lv_mbox_design(lv_obj_t * mbox, const area_t * mask, lv_design_mode_t mode);
#endif
static void lv_mboxs_init(void);
static void lv_mbox_realign(lv_obj_t * mbox);
static void lv_mbox_disable_fit(lv_obj_t * mbox);
/**********************
* STATIC VARIABLES
**********************/
static lv_mboxs_t lv_mboxs_def; /*Default message box style*/
static lv_mboxs_t lv_mboxs_info;
static lv_mboxs_t lv_mboxs_warn;
static lv_mboxs_t lv_mboxs_err;
/**********************
* MACROS
**********************/
@@ -72,8 +66,12 @@ lv_obj_t * lv_mbox_create(lv_obj_t * par, lv_obj_t * copy)
lv_mbox_ext_t * ext = lv_obj_alloc_ext(new_mbox, sizeof(lv_mbox_ext_t));
dm_assert(ext);
ext->txt = NULL;
ext->title = NULL;
ext->btnh = NULL;
ext->styles_btn[LV_BTN_STATE_REL] = lv_style_get(LV_STYLE_BTN_REL, NULL);
ext->styles_btn[LV_STYLE_BTN_PR] = lv_style_get(LV_STYLE_BTN_PR, NULL);
ext->styles_btn[LV_STYLE_BTN_TREL] = lv_style_get(LV_STYLE_BTN_TREL, NULL);
ext->styles_btn[LV_STYLE_BTN_TPR] = lv_style_get(LV_STYLE_BTN_TPR, NULL);
ext->styles_btn[LV_STYLE_BTN_INA] = lv_style_get(LV_STYLE_BTN_INA, NULL);
/*The signal and design functions are not copied so set them here*/
lv_obj_set_signal_f(new_mbox, lv_mbox_signal);
@@ -86,24 +84,25 @@ lv_obj_t * lv_mbox_create(lv_obj_t * par, lv_obj_t * copy)
ext->txt = lv_label_create(new_mbox, NULL);
lv_label_set_text(ext->txt, "Text of the message box");
lv_obj_set_style(new_mbox, lv_mboxs_get(LV_MBOXS_DEF, NULL));
lv_obj_set_style(new_mbox, lv_style_get(LV_STYLE_PRETTY, NULL));
}
/*Copy an existing message box*/
else {
lv_mbox_ext_t * copy_ext = lv_obj_get_ext(copy);
ext->txt = lv_label_create(new_mbox, copy_ext->txt);
lv_mbox_set_title(new_mbox, lv_mbox_get_title(copy));
/*Copy the buttons and the label on them*/
if(copy_ext->btnh != NULL) {
lv_obj_t * btn;
const char * btn_txt;
btn = lv_obj_get_child(copy_ext->btnh, NULL);
while(btn != NULL) {
btn_txt = lv_label_get_text(lv_obj_get_child(btn, NULL));
lv_mbox_add_btn(new_mbox, btn_txt, LV_EA(btn, lv_btn_ext_t)->rel_action);
btn = lv_obj_get_child(copy_ext->btnh, btn);
lv_obj_t * btn_copy;
const char * btn_txt_copy;
lv_btn_ext_t * btn_ext_copy;
btn_copy = lv_obj_get_child(copy_ext->btnh, NULL);
while(btn_copy != NULL) {
btn_txt_copy = lv_label_get_text(lv_obj_get_child(btn_copy, NULL));
btn_ext_copy = lv_obj_get_ext(btn_copy);
lv_mbox_add_btn(new_mbox, btn_txt_copy, btn_ext_copy->rel_action);
btn_copy = lv_obj_get_child(copy_ext->btnh, btn_copy);
}
}
/*Refresh the style with new signal function*/
@@ -133,86 +132,104 @@ bool lv_mbox_signal(lv_obj_t * mbox, lv_signal_t sign, void * param)
* make the object specific signal handling */
if(valid != false) {
lv_mbox_ext_t * ext = lv_obj_get_ext(mbox);
lv_mboxs_t * style = lv_obj_get_style(mbox);
lv_obj_t * btn;
switch(sign) {
case LV_SIGNAL_CLEANUP:
/*Nothing to cleanup. (No dynamically allocated memory in 'ext')*/
break;
case LV_SIGNAL_CORD_CHG:
/*If the size is changed refresh the message box*/
if(area_get_width(param) != lv_obj_get_width(mbox) ||
area_get_height(param) != lv_obj_get_height(mbox)) {
lv_mbox_realign(mbox);
}
break;
case LV_SIGNAL_LONG_PRESS:
if(sign == LV_SIGNAL_CORD_CHG) {
/*If the size is changed refresh the message box*/
if(area_get_width(param) != lv_obj_get_width(mbox) ||
area_get_height(param) != lv_obj_get_height(mbox)) {
lv_mbox_realign(mbox);
}
}
else if(sign == LV_SIGNAL_LONG_PRESS) {
#if LV_MBOX_ANIM_TIME != 0
lv_mbox_start_auto_close(mbox, 0);
lv_mbox_start_auto_close(mbox, 0);
#else
lv_obj_del(mbox);
valid = false;
lv_obj_del(mbox);
valid = false;
#endif
lv_dispi_wait_release(param);
break;
case LV_SIGNAL_STYLE_CHG:
if(ext->title != NULL) lv_obj_set_style(ext->title, &style->title);
lv_obj_set_style(ext->txt, &style->txt);
if(ext->btnh != NULL) lv_obj_set_style(ext->btnh, &style->btnh);
lv_dispi_wait_release(param);
}
else if(sign == LV_SIGNAL_STYLE_CHG) {
lv_obj_set_style(ext->txt, ext->styles_btn[LV_BTN_STATE_REL]);
/*Refresh all the buttons*/
if(ext->btnh != NULL) {
btn = lv_obj_get_child(ext->btnh, NULL);
while(btn != NULL) {
/*Refresh the next button's style*/
lv_obj_set_style(btn, &style->btn);
/*Refresh all the buttons*/
if(ext->btnh != NULL) {
lv_obj_t * btn;
btn = lv_obj_get_child(ext->btnh, NULL);
while(btn != NULL) {
/*Refresh the next button's style*/
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]);
/*Refresh the button label too*/
lv_obj_set_style(lv_obj_get_child(btn, NULL), &style->btn_label);
btn = lv_obj_get_child(ext->btnh, btn);
}
}
break;
default:
break;
}
/*Refresh the button label too*/
lv_obj_set_style(lv_obj_get_child(btn, NULL), ext->styles_btn[LV_BTN_STATE_REL]);
btn = lv_obj_get_child(ext->btnh, btn);
}
}
}
}
return valid;
}
/**
* A release action which can be assigned to a message box button to close it
* @param btn pointer to the released button
* @param dispi pointer to the caller display input
* @return always lv_action_res_t because the button is deleted with the mesage box
*/
lv_action_res_t lv_mbox_close_action(lv_obj_t * btn, lv_dispi_t * dispi)
{
lv_obj_t * mbox = lv_mbox_get_from_btn(btn);
lv_obj_del(mbox);
return LV_ACTION_RES_INV;
}
/**
* Add a button to the message box
* @param mbox pointer to message box object
* @param btn_txt the text of the button
* @param rel_action a function which will be called when the button is released
* @return pointer to the created button (lv_btn)
*/
lv_obj_t * lv_mbox_add_btn(lv_obj_t * mbox, const char * btn_txt, lv_action_t rel_action)
{
lv_mbox_ext_t * ext = lv_obj_get_ext(mbox);
/*Create a button if it is not existed yet*/
if(ext->btnh == NULL) {
ext->btnh = lv_rect_create(mbox, NULL);
lv_obj_set_style(ext->btnh, lv_style_get(LV_STYLE_TRANSP, NULL));
lv_obj_set_click(ext->btnh, false);
lv_rect_set_fit(ext->btnh, false, true);
lv_rect_set_layout(ext->btnh, LV_RECT_LAYOUT_PRETTY);
}
lv_obj_t * btn;
btn = lv_btn_create(ext->btnh, NULL);
lv_btn_set_rel_action(btn, rel_action);
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_rect_set_fit(btn, true, true);
lv_obj_t * label;
label = lv_label_create(btn, NULL);
lv_obj_set_style(label, ext->styles_btn[LV_BTN_STATE_REL]);
lv_label_set_text(label, btn_txt);
lv_mbox_realign(mbox);
return btn;
}
/*=====================
* Setter functions
*====================*/
/**
* Set the title of the message box
* @param mbox pointer to a message box
* @param title a '\0' terminated character string which will be the message box title
*/
void lv_mbox_set_title(lv_obj_t * mbox, const char * title)
{
lv_mbox_ext_t * ext = lv_obj_get_ext(mbox);
lv_mboxs_t * style = lv_obj_get_style(mbox);
if(title[0] != '\0') {
if(ext->title == NULL) {
ext->title = lv_label_create(mbox, NULL);
lv_obj_set_style(ext->title, &style->title);
/*Set the other parents again. It will look like they were created later */
lv_obj_set_parent(ext->txt, mbox);
if(ext->btnh != NULL) lv_obj_set_parent(ext->btnh, mbox);
}
lv_label_set_text(ext->title, title);
} else if(ext->title != NULL) {
lv_obj_del(ext->title);
ext->title = NULL;
}
lv_mbox_realign(mbox);
}
/**
* Set the text of the message box
* @param mbox pointer to a message box
@@ -227,55 +244,30 @@ void lv_mbox_set_text(lv_obj_t * mbox, const char * txt)
}
/**
* Add a button to the message box
* @param mbox pointer to message box object
* @param btn_txt the text of the button
* @param rel_action a function which will be called when the button is relesed
* @return pointer to the created button (lv_btn)
* Set styles of the buttons of a message box in each state
* @param mbox pointer to a message box object
* @param rel pointer to a style for releases state
* @param pr pointer to a style for pressed state
* @param trel pointer to a style for toggled releases state
* @param tpr pointer to a style for toggled pressed state
* @param ina pointer to a style for inactive state
*/
lv_obj_t * lv_mbox_add_btn(lv_obj_t * mbox, const char * btn_txt, lv_action_t rel_action)
void lv_mbox_set_styles_btn(lv_obj_t * mbox, lv_style_t * rel, lv_style_t * pr, lv_style_t * trel, lv_style_t * tpr, lv_style_t * ina)
{
lv_mbox_ext_t * ext = lv_obj_get_ext(mbox);
lv_mboxs_t * style = lv_obj_get_style(mbox);
lv_mbox_ext_t * ext = lv_obj_get_ext(mbox);
/*Create a button if it is not existed yet*/
if(ext->btnh == NULL) {
ext->btnh = lv_rect_create(mbox, NULL);
lv_obj_set_style(ext->btnh, &style->btnh);
lv_obj_set_click(ext->btnh, false);
lv_rect_set_fit(ext->btnh, false, true);
lv_rect_set_layout(ext->btnh, LV_RECT_LAYOUT_PRETTY);
}
ext->styles_btn[LV_BTN_STATE_REL] = rel;
ext->styles_btn[LV_BTN_STATE_PR] = pr;
ext->styles_btn[LV_BTN_STATE_TREL] = trel;
ext->styles_btn[LV_BTN_STATE_TPR] = tpr;
ext->styles_btn[LV_BTN_STATE_INA] = ina;
lv_obj_t * btn;
btn = lv_btn_create(ext->btnh, NULL);
lv_btn_set_rel_action(btn, rel_action);
lv_obj_set_style(btn, &style->btn);
lv_rect_set_fit(btn, true, true);
lv_obj_t * btn = lv_obj_get_child(ext->btnh, NULL);
lv_obj_t * label;
label = lv_label_create(btn, NULL);
lv_obj_set_style(label, &style->btn_label);
lv_label_set_text(label, btn_txt);
lv_mbox_realign(mbox);
return btn;
}
/**
* A release action which can be assigned to a message box button to close it
* @param btn pointer to the released button
* @param dispi pointer to the caller display input
* @return always lv_action_res_t because the button is deleted with the mesage box
*/
lv_action_res_t lv_mbox_close_action(lv_obj_t * btn, lv_dispi_t * dispi)
{
lv_obj_t * mbox = lv_mbox_get_from_btn(btn);
lv_obj_del(mbox);
return LV_ACTION_RES_INV;
while(btn != NULL) {
lv_btn_set_styles(btn, rel, pr, trel, tpr, ina);
btn = lv_obj_get_child(mbox, btn);
}
}
/**
@@ -311,18 +303,6 @@ void lv_mbox_stop_auto_close(lv_obj_t * mbox)
* Getter functions
*====================*/
/**
* get the title of the message box
* @param mbox pointer to a message box object
* @return pointer to the title of the message box
*/
const char * lv_mbox_get_title(lv_obj_t * mbox)
{
lv_mbox_ext_t * ext = lv_obj_get_ext(mbox);
return ext->title == NULL ? "" : lv_label_get_text(ext->title);
}
/**
* Get the text of the message box
* @param mbox pointer to a message box object
@@ -349,52 +329,21 @@ lv_obj_t * lv_mbox_get_from_btn(lv_obj_t * btn)
return mbox;
}
/**
* Return with a pointer to a built-in style and/or copy it to a variable
* @param style a style name from lv_mboxs_builtin_t enum
* @param copy copy the style to this variable. (NULL if unused)
* @return pointer to an lv_mboxs_t style
* Get the style of the buttons on a message box
* @param mbox pointer to a message box object
* @param state a state from 'lv_btn_state_t' in which style should be get
* @return pointer to the style in the given state
*/
lv_mboxs_t * lv_mboxs_get(lv_mboxs_builtin_t style, lv_mboxs_t * copy)
lv_style_t * lv_mbox_get_style_btn(lv_obj_t * mbox, lv_btn_state_t state)
{
static bool style_inited = false;
lv_btn_ext_t * ext = lv_obj_get_ext(mbox);
/*Make the style initialization if it is not done yet*/
if(style_inited == false) {
lv_mboxs_init();
style_inited = true;
}
if(ext->styles[state] == NULL) return lv_obj_get_style(mbox);
lv_mboxs_t *style_p;
switch(style) {
case LV_MBOXS_DEF:
style_p = &lv_mboxs_def;
break;
case LV_MBOXS_INFO:
style_p = &lv_mboxs_info;
break;
case LV_MBOXS_WARN:
style_p = &lv_mboxs_warn;
break;
case LV_MBOXS_ERR:
style_p = &lv_mboxs_err;
break;
default:
style_p = &lv_mboxs_def;
}
if(copy != NULL) {
if(style_p != NULL) memcpy(copy, style_p, sizeof(lv_mboxs_t));
else memcpy(copy, &lv_mboxs_def, sizeof(lv_mboxs_t));
}
return style_p;
return ext->styles[state];
}
/**********************
* STATIC FUNCTIONS
**********************/
@@ -436,7 +385,6 @@ static void lv_mbox_realign(lv_obj_t * mbox)
/*Set the button holder width to the width of the text and title*/
if(ext->btnh != NULL) {
cord_t title_w = ext->title == NULL ? 0 :lv_obj_get_width(ext->title);
cord_t txt_w = lv_obj_get_width(ext->txt);
cord_t btn_w = 0;
lv_obj_t * btn;
@@ -446,8 +394,7 @@ static void lv_mbox_realign(lv_obj_t * mbox)
btn = lv_obj_get_child(ext->btnh, btn);
}
cord_t w = MATH_MAX(title_w, txt_w);
w = MATH_MAX(w, btn_w);
cord_t w = MATH_MAX(txt_w, btn_w);
lv_obj_set_width(ext->btnh, w );
}
}
@@ -461,60 +408,4 @@ static void lv_mbox_disable_fit(lv_obj_t * mbox)
lv_rect_set_fit(mbox, false, false);
}
/**
* Initialize the message box styles
*/
static void lv_mboxs_init(void)
{
/*Default style*/
lv_rects_get(LV_RECTS_FANCY, &lv_mboxs_def.bg);
lv_btns_get(LV_BTNS_DEF, &lv_mboxs_def.btn);
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);
lv_rects_get(LV_RECTS_TRANSP, &lv_mboxs_def.btnh);
lv_mboxs_def.btnh.hpad = 0;
lv_mboxs_def.btnh.vpad = 0;
memcpy(&lv_mboxs_info, &lv_mboxs_def, sizeof(lv_mboxs_t));
lv_mboxs_info.bg.base.color = COLOR_BLACK;
lv_mboxs_info.bg.gcolor = COLOR_BLACK;
lv_mboxs_info.bg.bcolor = COLOR_WHITE;
lv_mboxs_info.title.base.color = COLOR_WHITE;
lv_mboxs_info.txt.base.color = COLOR_WHITE;
lv_mboxs_info.txt.letter_space = 2 * LV_DOWNSCALE;
lv_btns_get(LV_BTNS_BORDER, &lv_mboxs_info.btn);
lv_mboxs_info.btn.state_style[LV_BTN_STATE_PR].bcolor = COLOR_SILVER;
lv_mboxs_info.btn.state_style[LV_BTN_STATE_REL].bcolor = COLOR_WHITE;
lv_mboxs_info.btn.state_style[LV_BTN_STATE_PR].base.color = COLOR_GRAY;
lv_mboxs_info.btn.state_style[LV_BTN_STATE_PR].gcolor = COLOR_GRAY;
lv_mboxs_info.btn.state_style[LV_BTN_STATE_REL].bopa = OPA_COVER;
lv_mboxs_info.btn.state_style[LV_BTN_STATE_PR].bopa = OPA_COVER;
lv_mboxs_info.btn_label.base.color = COLOR_WHITE;
memcpy(&lv_mboxs_warn, &lv_mboxs_info, sizeof(lv_mboxs_t));
lv_mboxs_warn.bg.base.color = COLOR_MAKE(0xff, 0xb2, 0x66);
lv_mboxs_warn.bg.gcolor = COLOR_MAKE(0xff, 0xad, 0x29);
lv_mboxs_warn.btn.state_style[LV_BTN_STATE_REL].bcolor = COLOR_MAKE(0x10, 0x10, 0x10);
lv_mboxs_warn.btn.state_style[LV_BTN_STATE_PR].bcolor = COLOR_MAKE(0x10, 0x10, 0x10);
lv_mboxs_warn.btn.state_style[LV_BTN_STATE_PR].base.color = COLOR_MAKE(0xa8, 0x6e, 0x33);
lv_mboxs_warn.btn.state_style[LV_BTN_STATE_PR].gcolor = COLOR_MAKE(0xa8, 0x6e, 0x33);
lv_mboxs_warn.title.base.color = COLOR_MAKE(0x10, 0x10, 0x10);
lv_mboxs_warn.txt.base.color = COLOR_MAKE(0x10, 0x10, 0x10);;
lv_mboxs_warn.btn_label.base.color = COLOR_MAKE(0x10, 0x10, 0x10);
memcpy(&lv_mboxs_err, &lv_mboxs_warn, sizeof(lv_mboxs_t));
lv_mboxs_err.bg.base.color = COLOR_MAKE(0xff, 0x66, 0x66);
lv_mboxs_err.bg.gcolor = COLOR_MAKE(0x99, 0x22, 0x22);
lv_mboxs_err.btn.state_style[LV_BTN_STATE_REL].bcolor = COLOR_BLACK;
lv_mboxs_err.btn.state_style[LV_BTN_STATE_PR].bcolor = COLOR_BLACK;
lv_mboxs_err.btn.state_style[LV_BTN_STATE_PR].base.color = COLOR_MAKE(0x70, 0x00, 0x00);
lv_mboxs_err.btn.state_style[LV_BTN_STATE_PR].gcolor = COLOR_MAKE(0x70, 0x00, 0x00);
lv_mboxs_err.title.base.color = COLOR_BLACK;
lv_mboxs_err.txt.base.color = COLOR_BLACK;
lv_mboxs_err.btn_label.base.color = COLOR_BLACK;
}
#endif

View File

@@ -44,33 +44,11 @@ typedef struct
{
lv_rect_ext_t bg; /*Ext. of ancestor*/
/*New data for this type */
lv_obj_t * title; /*Title of the message box*/
lv_obj_t * txt; /*Text of the message box*/
lv_obj_t * btnh; /*Holder of the buttons*/
lv_style_t * styles_btn[LV_BTN_STATE_NUM]; /*Style of the buttons*/
}lv_mbox_ext_t;
/*Style of message box*/
typedef struct
{
lv_rects_t bg; /*Style of ancestor*/
/*New style element for this type */
lv_labels_t title; /*Style of the title*/
lv_labels_t txt; /*Style of the text*/
lv_rects_t btnh; /*Style of the button holder*/
lv_btns_t btn; /*Style of the buttons*/
lv_labels_t btn_label; /*Style of the label on the buttons*/
}lv_mboxs_t;
/*Built-in styles of message box*/
typedef enum
{
LV_MBOXS_DEF,
LV_MBOXS_INFO,
LV_MBOXS_WARN,
LV_MBOXS_ERR,
}lv_mboxs_builtin_t;
/**********************
* GLOBAL PROTOTYPES
**********************/
@@ -92,20 +70,13 @@ 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);
/**
* Set the title of the message box
* @param mbox pointer to a message box
* @param title a '\0' terminated character string which will be the message box title
*/
void lv_mbox_set_title(lv_obj_t * mbox, const char * title);
/**
* Set the text of the message box
* @param mbox pointer to a message box
* @param txt a '\0' terminated character string which will be the message box text
*/
void lv_mbox_set_text(lv_obj_t * mbox, const char * txt);
void lv_mbox_set_styles_btn(lv_obj_t * mbox, lv_style_t * rel, lv_style_t * pr, lv_style_t * trel, lv_style_t * tpr, lv_style_t * ina);
/**
* Add a button to the message box
* @param mbox pointer to message box object
@@ -136,13 +107,6 @@ void lv_mbox_start_auto_close(lv_obj_t * mbox, uint16_t tout);
*/
void lv_mbox_stop_auto_close(lv_obj_t * mbox);
/**
* get the title of the message box
* @param mbox pointer to a message box object
* @return pointer to the title of the message box
*/
const char * lv_mbox_get_title(lv_obj_t * mbox);
/**
* Get the text of the message box
* @param mbox pointer to a message box object
@@ -158,14 +122,6 @@ const char * lv_mbox_get_txt(lv_obj_t * mbox);
*/
lv_obj_t * lv_mbox_get_from_btn(lv_obj_t * btn);
/**
* Return with a pointer to a built-in style and/or copy it to a variable
* @param style a style name from lv_mboxs_builtin_t enum
* @param copy copy the style to this variable. (NULL if unused)
* @return pointer to an lv_mboxs_t style
*/
lv_mboxs_t * lv_mboxs_get(lv_mboxs_builtin_t style, lv_mboxs_t * copy);
/**********************
* MACROS
**********************/

View File

@@ -34,15 +34,10 @@
static void lv_page_sb_refresh(lv_obj_t * main);
static bool lv_page_design(lv_obj_t * page, const area_t * mask, lv_design_mode_t mode);
static bool lv_scrl_signal(lv_obj_t * scrl, lv_signal_t sign, void* param);
static void lv_pages_init(void);
/**********************
* STATIC VARIABLES
**********************/
static lv_pages_t lv_pages_def;
static lv_pages_t lv_pages_paper;
static lv_pages_t lv_pages_menu;
static lv_pages_t lv_pages_transp;
static lv_design_f_t ancestor_design_f;
/**********************
@@ -77,19 +72,22 @@ lv_obj_t * lv_page_create(lv_obj_t * par, lv_obj_t * copy)
ext->rel_action = NULL;
ext->sbh_draw = 0;
ext->sbv_draw = 0;
ext->style_sb = lv_style_get(LV_STYLE_PRETTY, NULL);
ext->sb_width = LV_DPI / 8;
ext->sb_mode = LV_PAGE_SB_MODE_ON;
if(ancestor_design_f == NULL) ancestor_design_f = lv_obj_get_design_f(new_page);
/*Init the new page object*/
if(copy == NULL) {
lv_pages_t * style = lv_pages_get(LV_PAGES_DEF, NULL);
lv_style_t * style = lv_style_get(LV_STYLE_PRETTY_COLOR, NULL);
ext->scrl = lv_rect_create(new_page, NULL);
lv_obj_set_signal_f(ext->scrl, lv_scrl_signal);
lv_obj_set_drag(ext->scrl, true);
lv_obj_set_drag_throw(ext->scrl, true);
lv_obj_set_protect(ext->scrl, LV_PROTECT_PARENT);
lv_rect_set_fit(ext->scrl, true, true);
lv_obj_set_style(ext->scrl, &style->scrl);
lv_obj_set_style(ext->scrl, lv_style_get(LV_STYLE_PRETTY, NULL));
/* Add the signal function only if 'scrolling' is created
* because everything has to be ready before any signal is received*/
@@ -136,7 +134,7 @@ bool lv_page_signal(lv_obj_t * page, lv_signal_t sign, void * param)
* make the object specific signal handling */
if(obj_valid != false) {
lv_page_ext_t * ext = lv_obj_get_ext(page);
lv_pages_t * style = lv_obj_get_style(page);
lv_style_t * style = lv_obj_get_style(page);
lv_obj_t * child;
switch(sign) {
case LV_SIGNAL_CHILD_CHG: /*Move children to the scrollable object*/
@@ -153,11 +151,10 @@ bool lv_page_signal(lv_obj_t * page, lv_signal_t sign, void * param)
break;
case LV_SIGNAL_STYLE_CHG:
area_set_height(&ext->sbh, style->sb_width);
area_set_width(&ext->sbv, style->sb_width);
lv_obj_set_style(ext->scrl, &style->scrl);
area_set_height(&ext->sbh, ext->sb_width);
area_set_width(&ext->sbv, ext->sb_width);
if(style->sb_mode == LV_PAGE_SB_MODE_ON) {
if(ext->sb_mode == LV_PAGE_SB_MODE_ON) {
ext->sbh_draw = 1;
ext->sbv_draw = 1;
} else {
@@ -226,10 +223,10 @@ static bool lv_scrl_signal(lv_obj_t * scrl, lv_signal_t sign, void* param)
area_t page_cords;
area_t obj_cords;
lv_obj_t * page = lv_obj_get_parent(scrl);
lv_pages_t * style = lv_obj_get_style(page);
lv_style_t * page_style = lv_obj_get_style(page);
lv_page_ext_t * page_ext = lv_obj_get_ext(page);
cord_t hpad = style->bg.hpad;
cord_t vpad = style->bg.vpad;
cord_t hpad = page_style->hpad;
cord_t vpad = page_style->vpad;
switch(sign) {
case LV_SIGNAL_CORD_CHG:
@@ -281,9 +278,9 @@ static bool lv_scrl_signal(lv_obj_t * scrl, lv_signal_t sign, void* param)
break;
case LV_SIGNAL_DRAG_BEGIN:
if(style->sb_mode == LV_PAGE_SB_MODE_DRAG ) {
cord_t sbh_pad = MATH_MAX(style->sb_width, style->bg.hpad);
cord_t sbv_pad = MATH_MAX(style->sb_width, style->bg.vpad);
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 sbv_pad = MATH_MAX(page_ext->sb_width, page_style->vpad);
if(area_get_height(&page_ext->sbv) < lv_obj_get_height(scrl) - 2 * sbv_pad) {
page_ext->sbv_draw = 1;
}
@@ -294,7 +291,7 @@ static bool lv_scrl_signal(lv_obj_t * scrl, lv_signal_t sign, void* param)
break;
case LV_SIGNAL_DRAG_END:
if(style->sb_mode == LV_PAGE_SB_MODE_DRAG) {
if(page_ext->sb_mode == LV_PAGE_SB_MODE_DRAG) {
area_t sb_area_tmp;
if(page_ext->sbh_draw != 0) {
area_cpy(&sb_area_tmp, &page_ext->sbh);
@@ -363,6 +360,41 @@ void lv_page_set_pr_action(lv_obj_t * page, lv_action_t pr_action)
ext->pr_action = pr_action;
}
/**
* Set the scroll bar width on a page
* @param page pointer to a page object
* @param sb_width the new scroll bar width in pixels
*/
void lv_page_set_sb_width(lv_obj_t * page, cord_t sb_width)
{
lv_page_ext_t * ext = lv_obj_get_ext(page);
ext->sb_width = sb_width;
lv_obj_inv(page);
}
/**
* Set the scroll bar mode on a page
* @param page pointer to a page object
* @param sb_mode the new mode from 'lv_page_sb_mode_t' enum
*/
void lv_page_set_sb_mode(lv_obj_t * page, lv_page_sb_mode_t sb_mode)
{
lv_page_ext_t * ext = lv_obj_get_ext(page);
ext->sb_mode = sb_mode;
lv_obj_inv(page);
}
/**
* Set a new style for the scroll bars object on the page
* @param page pointer to a page object
* @param style pointer to a style for the scroll bars
*/
void lv_page_set_style_sb(lv_obj_t * page, lv_style_t * style)
{
lv_page_ext_t * ext = lv_obj_get_ext(page);
ext->style_sb = style;
lv_obj_inv(page);
}
/**
* Glue the object to the page. After it the page can be moved (dragged) with this object too.
@@ -384,7 +416,9 @@ void lv_page_glue_obj(lv_obj_t * obj, bool glue)
void lv_page_focus(lv_obj_t * page, lv_obj_t * obj, bool anim_en)
{
lv_page_ext_t * ext = lv_obj_get_ext(page);
lv_pages_t * style = lv_obj_get_style(page);
lv_style_t * style = lv_obj_get_style(page);
lv_obj_t * scrl = lv_page_get_scrl(page);
lv_style_t * style_scrl = lv_obj_get_style(scrl);
cord_t obj_y = obj->cords.y1 - ext->scrl->cords.y1;
cord_t obj_h = lv_obj_get_height(obj);
@@ -401,8 +435,8 @@ void lv_page_focus(lv_obj_t * page, lv_obj_t * obj, bool anim_en)
if((obj_h <= page_h && top_err > 0) ||
(obj_h > page_h && top_err < bot_err)) {
/*Calculate a new position and to let scrable_rects.vpad space above*/
scrlable_y = -(obj_y - style->scrl.vpad - style->bg.vpad);
scrlable_y += style->scrl.vpad;
scrlable_y = -(obj_y - style_scrl->vpad - style->vpad);
scrlable_y += style_scrl->vpad;
refr = true;
}
/*Out of the page on the bottom*/
@@ -411,7 +445,7 @@ void lv_page_focus(lv_obj_t * page, lv_obj_t * obj, bool anim_en)
/*Calculate a new position and to let scrable_rects.vpad space below*/
scrlable_y = -obj_y;
scrlable_y += page_h - obj_h;
scrlable_y -= style->scrl.vpad;
scrlable_y -= style_scrl->vpad;
refr = true;
}
@@ -455,45 +489,39 @@ lv_obj_t * lv_page_get_scrl(lv_obj_t * page)
return ext->scrl;
}
/**
* Get the scroll bar width on a page
* @param page pointer to a page object
* @return the scroll bar width in pixels
*/
cord_t lv_page_get_sb_width(lv_obj_t * page)
{
lv_page_ext_t * ext = lv_obj_get_ext(page);
return ext->sb_width;
}
/**
* 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)
* @return pointer to an lv_pages_t style
* Set the scroll bar mode on a page
* @param page pointer to a page object
* @return the mode from 'lv_page_sb_mode_t' enum
*/
lv_pages_t * lv_pages_get(lv_pages_builtin_t style, lv_pages_t * copy)
lv_page_sb_mode_t lv_page_get_sb_mode(lv_obj_t * page)
{
static bool style_inited = false;
lv_page_ext_t * ext = lv_obj_get_ext(page);
return ext->sb_mode;
}
/*Make the style initialization if it is not done yet*/
if(style_inited == false) {
lv_pages_init();
style_inited = true;
}
/**
* Set a new style for the scroll bars object on the page
* @param page pointer to a page object
* @return pointer to a style for the scroll bars
*/
lv_style_t * lv_page_get_style_sb(lv_obj_t * page)
{
lv_page_ext_t * ext = lv_obj_get_ext(page);
if(ext->style_sb == NULL) return lv_obj_get_style(page);
lv_pages_t * style_p;
switch(style) {
case LV_PAGES_DEF:
style_p = &lv_pages_def;
break;
case LV_PAGES_PAPER:
style_p = &lv_pages_paper;
break;
case LV_PAGES_MENU:
style_p = &lv_pages_menu;
break;
case LV_PAGES_TRANSP:
style_p = &lv_pages_transp;
break;
default:
style_p = &lv_pages_def;
}
if(copy != NULL) memcpy(copy, style_p, sizeof(lv_pages_t));
return style_p;
else return ext->style_sb;
}
/**********************
@@ -519,7 +547,6 @@ static bool lv_page_design(lv_obj_t * page, const area_t * mask, lv_design_mode_
} else if(mode == LV_DESIGN_DRAW_POST) { /*Draw the scroll bars finally*/
ancestor_design_f(page, mask, mode);
lv_page_ext_t * ext = lv_obj_get_ext(page);
lv_pages_t * style = lv_obj_get_style(page);
/*Draw the scrollbars*/
area_t sb_area;
@@ -530,7 +557,7 @@ static bool lv_page_design(lv_obj_t * page, const area_t * mask, lv_design_mode_
sb_area.y1 += page->cords.y1;
sb_area.x2 += page->cords.x1;
sb_area.y2 += page->cords.y1;
lv_draw_rect(&sb_area, mask, &style->sb);
lv_draw_rect(&sb_area, mask, ext->style_sb);
}
if(ext->sbv_draw != 0) {
@@ -540,7 +567,7 @@ static bool lv_page_design(lv_obj_t * page, const area_t * mask, lv_design_mode_
sb_area.y1 += page->cords.y1;
sb_area.x2 += page->cords.x1;
sb_area.y2 += page->cords.y1;
lv_draw_rect(&sb_area, mask, &style->sb);
lv_draw_rect(&sb_area, mask, ext->style_sb);
}
}
@@ -559,38 +586,38 @@ static void lv_page_sb_refresh(lv_obj_t * page)
* - horizontal and vertical scrollbars can overlap on the corners
* - if the page has radius the scrollbar can be out of the radius */
lv_page_ext_t * page_ext = lv_obj_get_ext(page);
lv_pages_t * style = lv_obj_get_style(page);
lv_obj_t * scrl = page_ext->scrl;
lv_page_ext_t * ext = lv_obj_get_ext(page);
lv_style_t * style = lv_obj_get_style(page);
lv_obj_t * scrl = ext->scrl;
cord_t size_tmp;
cord_t scrl_w = lv_obj_get_width(scrl);
cord_t scrl_h = lv_obj_get_height(scrl);
cord_t hpad = style->bg.hpad;
cord_t vpad = style->bg.vpad;
cord_t hpad = style->hpad;
cord_t vpad = style->vpad;
cord_t obj_w = lv_obj_get_width(page);
cord_t obj_h = lv_obj_get_height(page);
cord_t sbh_pad = MATH_MAX(style->sb_width, style->bg.hpad);
cord_t sbv_pad = MATH_MAX(style->sb_width, style->bg.vpad);
cord_t sbh_pad = MATH_MAX(ext->sb_width, style->hpad);
cord_t sbv_pad = MATH_MAX(ext->sb_width, style->vpad);
if(style->sb_mode == LV_PAGE_SB_MODE_OFF) return;
if(ext->sb_mode == LV_PAGE_SB_MODE_OFF) return;
if(style->sb_mode == LV_PAGE_SB_MODE_ON) {
page_ext->sbh_draw = 1;
page_ext->sbv_draw = 1;
if(ext->sb_mode == LV_PAGE_SB_MODE_ON) {
ext->sbh_draw = 1;
ext->sbv_draw = 1;
}
/*Invalidate the current (old) scrollbar areas*/
area_t sb_area_tmp;
if(page_ext->sbh_draw != 0) {
area_cpy(&sb_area_tmp, &page_ext->sbh);
if(ext->sbh_draw != 0) {
area_cpy(&sb_area_tmp, &ext->sbh);
sb_area_tmp.x1 += page->cords.x1;
sb_area_tmp.y1 += page->cords.y1;
sb_area_tmp.x2 += page->cords.x2;
sb_area_tmp.y2 += page->cords.y2;
lv_inv_area(&sb_area_tmp);
}
if(page_ext->sbv_draw != 0) {
area_cpy(&sb_area_tmp, &page_ext->sbv);
if(ext->sbv_draw != 0) {
area_cpy(&sb_area_tmp, &ext->sbv);
sb_area_tmp.x1 += page->cords.x1;
sb_area_tmp.y1 += page->cords.y1;
sb_area_tmp.x2 += page->cords.x2;
@@ -600,48 +627,48 @@ static void lv_page_sb_refresh(lv_obj_t * page)
/*Horizontal scrollbar*/
if(scrl_w <= obj_w - 2 * hpad) { /*Full sized scroll bar*/
area_set_width(&page_ext->sbh, obj_w - 2 * sbh_pad);
area_set_pos(&page_ext->sbh, sbh_pad, obj_h - style->sb_width);
if(style->sb_mode == LV_PAGE_SB_MODE_AUTO) page_ext->sbh_draw = 0;
area_set_width(&ext->sbh, obj_w - 2 * sbh_pad);
area_set_pos(&ext->sbh, sbh_pad, obj_h - ext->sb_width);
if(ext->sb_mode == LV_PAGE_SB_MODE_AUTO) ext->sbh_draw = 0;
} else {
size_tmp = (obj_w * (obj_w - (2 * sbh_pad))) / (scrl_w + 2 * hpad);
area_set_width(&page_ext->sbh, size_tmp);
area_set_width(&ext->sbh, size_tmp);
area_set_pos(&page_ext->sbh, sbh_pad +
area_set_pos(&ext->sbh, sbh_pad +
(-(lv_obj_get_x(scrl) - hpad) * (obj_w - size_tmp - 2 * sbh_pad)) /
(scrl_w + 2 * hpad - obj_w ), obj_h - style->sb_width);
(scrl_w + 2 * hpad - obj_w ), obj_h - ext->sb_width);
if(style->sb_mode == LV_PAGE_SB_MODE_AUTO) page_ext->sbh_draw = 1;
if(ext->sb_mode == LV_PAGE_SB_MODE_AUTO) ext->sbh_draw = 1;
}
/*Vertical scrollbar*/
if(scrl_h <= obj_h - 2 * vpad) { /*Full sized scroll bar*/
area_set_height(&page_ext->sbv, obj_h - 2 * sbv_pad);
area_set_pos(&page_ext->sbv, obj_w - style->sb_width, sbv_pad);
if(style->sb_mode == LV_PAGE_SB_MODE_AUTO) page_ext->sbv_draw = 0;
area_set_height(&ext->sbv, obj_h - 2 * sbv_pad);
area_set_pos(&ext->sbv, obj_w - ext->sb_width, sbv_pad);
if(ext->sb_mode == LV_PAGE_SB_MODE_AUTO) ext->sbv_draw = 0;
} else {
size_tmp = (obj_h * (obj_h - (2 * sbv_pad))) / (scrl_h + 2 * vpad);
area_set_height(&page_ext->sbv, size_tmp);
area_set_height(&ext->sbv, size_tmp);
area_set_pos(&page_ext->sbv, obj_w - style->sb_width,
area_set_pos(&ext->sbv, obj_w - ext->sb_width,
sbv_pad +
(-(lv_obj_get_y(scrl) - vpad) * (obj_h - size_tmp - 2 * sbv_pad)) /
(scrl_h + 2 * vpad - obj_h ));
if(style->sb_mode == LV_PAGE_SB_MODE_AUTO) page_ext->sbv_draw = 1;
if(ext->sb_mode == LV_PAGE_SB_MODE_AUTO) ext->sbv_draw = 1;
}
/*Invalidate the new scrollbar areas*/
if(page_ext->sbh_draw != 0) {
area_cpy(&sb_area_tmp, &page_ext->sbh);
if(ext->sbh_draw != 0) {
area_cpy(&sb_area_tmp, &ext->sbh);
sb_area_tmp.x1 += page->cords.x1;
sb_area_tmp.y1 += page->cords.y1;
sb_area_tmp.x2 += page->cords.x2;
sb_area_tmp.y2 += page->cords.y2;
lv_inv_area(&sb_area_tmp);
}
if(page_ext->sbv_draw != 0) {
area_cpy(&sb_area_tmp, &page_ext->sbv);
if(ext->sbv_draw != 0) {
area_cpy(&sb_area_tmp, &ext->sbv);
sb_area_tmp.x1 += page->cords.x1;
sb_area_tmp.y1 += page->cords.y1;
sb_area_tmp.x2 += page->cords.x2;
@@ -650,61 +677,4 @@ static void lv_page_sb_refresh(lv_obj_t * page)
}
}
/**
* Initialize the page styles
*/
static void lv_pages_init(void)
{
/*Deafult style*/
lv_rects_get(LV_RECTS_FANCY, &lv_pages_def.bg);
lv_pages_def.bg.swidth = 0;
lv_rects_get(LV_RECTS_PLAIN, &lv_pages_def.scrl);
lv_rects_get(LV_RECTS_PLAIN, &lv_pages_def.sb);
lv_pages_def.sb.base.opa = OPA_70;
lv_pages_def.sb.base.color = COLOR_SILVER;
lv_pages_def.sb.gcolor = COLOR_GRAY;
lv_pages_def.sb.bcolor = COLOR_GRAY;
lv_pages_def.sb.bopa = OPA_COVER;
lv_pages_def.sb.bwidth = LV_DPI / 50 == 0 ? 1 * LV_DOWNSCALE : LV_DPI / 50;
lv_pages_def.sb.radius = LV_RECT_CIRCLE;
lv_pages_def.sb_width = LV_DPI / 6;
lv_pages_def.sb_mode = LV_PAGE_SB_MODE_ON;
/*Paper style*/
lv_rects_get(LV_RECTS_FANCY, &lv_pages_paper.bg);
lv_rects_get(LV_RECTS_TRANSP, &lv_pages_paper.scrl);
lv_pages_paper.scrl.hpad = LV_DPI / 4;
lv_pages_paper.scrl.vpad = LV_DPI / 4;
lv_pages_paper.scrl.opad = LV_DPI / 3;
lv_pages_paper.bg.hpad = 0;
lv_pages_paper.bg.vpad = 0;
lv_pages_paper.bg.opad = 0;
lv_pages_paper.bg.base.color = COLOR_WHITE;
lv_pages_paper.bg.gcolor = COLOR_SILVER;
memcpy(&lv_pages_paper.sb, &lv_pages_def.sb, sizeof(lv_rects_t));
lv_pages_paper.sb_width = LV_DPI / 6;
lv_pages_paper.sb_mode = LV_PAGE_SB_MODE_AUTO;
/*Menu style*/
lv_rects_get(LV_RECTS_TRANSP, &lv_pages_menu.bg);
lv_rects_get(LV_RECTS_PLAIN, &lv_pages_menu.scrl);
lv_pages_menu.scrl.hpad = 0;
lv_pages_menu.scrl.vpad = 0;
lv_pages_menu.scrl.opad = LV_DPI / 6;
lv_pages_menu.bg.hpad = 0;
lv_pages_menu.bg.vpad = 0;
lv_pages_menu.bg.opad = 0;
lv_pages_menu.scrl.base.color = COLOR_SILVER;
lv_pages_menu.scrl.gcolor = COLOR_SILVER;
memcpy(&lv_pages_menu.sb, &lv_pages_def.sb, sizeof(lv_rects_t));
lv_pages_menu.sb_width = LV_DPI / 6;
lv_pages_menu.sb_mode = LV_PAGE_SB_MODE_AUTO;
/*Transparent style*/
lv_rects_get(LV_RECTS_TRANSP, &lv_pages_transp.bg);
lv_rects_get(LV_RECTS_TRANSP, &lv_pages_transp.scrl);
memcpy(&lv_pages_transp.sb, &lv_pages_def.sb, sizeof(lv_rects_t));
lv_pages_transp.sb_width = LV_DPI / 6;
lv_pages_transp.sb_mode = LV_PAGE_SB_MODE_AUTO;
}
#endif

View File

@@ -28,6 +28,15 @@
* TYPEDEFS
**********************/
/*Scrollbar modes: shows when should the scrollbars be visible*/
typedef enum
{
LV_PAGE_SB_MODE_OFF, /*Never show scrollbars*/
LV_PAGE_SB_MODE_ON, /*Always show scrollbars*/
LV_PAGE_SB_MODE_DRAG, /*Show scrollbars when page is being dragged*/
LV_PAGE_SB_MODE_AUTO, /*Show scrollbars when the scrollable rect. is large enough to be scrolled*/
}lv_page_sb_mode_t;
/*Data of page*/
typedef struct
{
@@ -36,40 +45,15 @@ typedef struct
lv_obj_t * scrl; /*The scrollable object on the background*/
lv_action_t rel_action; /*Function to call when the page is released*/
lv_action_t pr_action; /*Function to call when the page is pressed*/
lv_style_t * style_sb; /*Style of scrollbars*/
cord_t sb_width; /*Width of the scrollbars*/
lv_page_sb_mode_t sb_mode; /*Scrollbar visibility from 'lv_page_sb_mode_t'*/
area_t sbh; /*Horizontal scrollbar area relative to the page. (Handled by the library) */
area_t sbv; /*Vertical scrollbar area relative to the page (Handled by the library)*/
uint8_t sbh_draw :1; /*1: horizontal scrollbar is visible now (Handled by the library)*/
uint8_t sbv_draw :1; /*1: vertical scrollbar is visible now (Handled by the library)*/
}lv_page_ext_t;
/*Scrollbar modes: shows when should the scrollbars be visible*/
typedef enum
{
LV_PAGE_SB_MODE_OFF, /*Never show scrollbars*/
LV_PAGE_SB_MODE_ON, /*Always show scrollbars*/
LV_PAGE_SB_MODE_DRAG, /*Show scrollbars when page is being dragged*/
LV_PAGE_SB_MODE_AUTO, /*Show scrollbars when the scrollable rect. is large enough to be scrolled*/
}lv_page_sb_mode_t;
/*Style of page*/
typedef struct
{
lv_rects_t bg; /*Style of ancestor*/
/*New style element for this type */
lv_rects_t scrl; /*Style of the scrollable rectangle*/
lv_rects_t sb; /*Style of scrollbars*/
cord_t sb_width; /*Width of the scrollbars*/
lv_page_sb_mode_t sb_mode; /*Scrollbar visibility from 'lv_page_sb_mode_t'*/
}lv_pages_t;
/*Built-in styles of page*/
typedef enum
{
LV_PAGES_DEF,
LV_PAGES_PAPER, /*White background, transparent scrollable*/
LV_PAGES_MENU, /*Transparent background, gray scrollable*/
LV_PAGES_TRANSP,
}lv_pages_builtin_t;
/**********************
* GLOBAL PROTOTYPES
@@ -112,6 +96,9 @@ void lv_page_set_pr_action(lv_obj_t * page, lv_action_t pr_action);
*/
void lv_page_glue_obj(lv_obj_t * obj, bool glue);
void lv_page_set_sb_width(lv_obj_t * page, cord_t sb_width);
void lv_page_set_sb_mode(lv_obj_t * page, lv_page_sb_mode_t sb_mode);
void lv_page_set_style_sb(lv_obj_t * page, lv_style_t * style);
/**
* Focus on an object. It ensures that the object will be visible on the page.
* @param page pointer to a page object
@@ -127,13 +114,16 @@ void lv_page_focus(lv_obj_t * page, lv_obj_t * obj, bool anim_en);
*/
lv_obj_t * lv_page_get_scrl(lv_obj_t * page);
cord_t lv_page_get_sb_width(lv_obj_t * page);
/**
* 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)
* @return pointer to an lv_pages_t style
* Set the scroll bar mode on a page
* @param page pointer to a page object
* @return the mode from 'lv_page_sb_mode_t' enum
*/
lv_pages_t * lv_pages_get(lv_pages_builtin_t style, lv_pages_t * copy);
lv_page_sb_mode_t lv_page_get_sb_mode(lv_obj_t * page);
lv_style_t * lv_page_get_style_sb(lv_obj_t * page);
/**********************
* MACROS

View File

@@ -44,15 +44,10 @@ 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);
/**********************
* STATIC VARIABLES
**********************/
static lv_rects_t lv_rects_plain;
static lv_rects_t lv_rects_fancy;
static lv_rects_t lv_rects_border;
static lv_rects_t lv_rects_transp;
/**********************
* MACROS
@@ -89,7 +84,7 @@ lv_obj_t * lv_rect_create(lv_obj_t * par, lv_obj_t * copy)
/*Init the new rectangle*/
if(copy == NULL) {
lv_obj_set_style(new_rect, lv_rects_get(LV_RECTS_PLAIN, NULL));
lv_obj_set_style(new_rect, lv_style_get(LV_STYLE_PLAIN, NULL));
}
/*Copy an existing object*/
else {
@@ -123,7 +118,7 @@ bool lv_rect_signal(lv_obj_t * rect, lv_signal_t sign, void * param)
* make the object specific signal handling */
if(valid != false) {
lv_rects_t * style = lv_obj_get_style(rect);
lv_style_t * style = lv_obj_get_style(rect);
switch(sign) {
case LV_SIGNAL_STYLE_CHG: /*Recalculate the padding if the style changed*/
@@ -228,47 +223,6 @@ bool lv_rect_get_vfit(lv_obj_t * rect)
}
/**
* Return with a pointer to a built-in style and/or copy it to a variable
* @param style a style name from lv_rects_builtin_t enum
* @param copy copy the style to this variable. (NULL if unused)
* @return pointer to an lv_rects_t style
*/
lv_rects_t * lv_rects_get(lv_rects_builtin_t style, lv_rects_t * copy)
{
static bool style_inited = false;
/*Make the style initialization if it is not done yet*/
if(style_inited == false) {
lv_rects_init();
style_inited = true;
}
lv_rects_t * style_p;
switch(style) {
case LV_RECTS_PLAIN:
style_p = &lv_rects_plain;
break;
case LV_RECTS_FANCY:
style_p = &lv_rects_fancy;
break;
case LV_RECTS_BORDER:
style_p = &lv_rects_border;
break;
case LV_RECTS_TRANSP:
style_p = &lv_rects_transp;
break;
default:
style_p = &lv_rects_plain;
}
if(copy != NULL) {
memcpy(copy, style_p, sizeof(lv_rects_t));
}
return style_p;
}
/**********************
@@ -290,9 +244,9 @@ static bool lv_rect_design(lv_obj_t * rect, const area_t * mask, lv_design_mode_
if(mode == LV_DESIGN_COVER_CHK) {
/* Because of the radius it is not sure the area is covered
* Check the areas where there is no radius*/
if(LV_SA(rect, lv_rects_t)->empty != 0) return false;
if(rect->style_p->empty != 0) return false;
uint16_t r = LV_SA(rect, lv_rects_t)->radius;
uint16_t r = rect->style_p->radius;
if(r == LV_RECT_CIRCLE) return false;
@@ -312,7 +266,7 @@ static bool lv_rect_design(lv_obj_t * rect, const area_t * mask, lv_design_mode_
return false;
} else if(mode == LV_DESIGN_DRAW_MAIN) {
lv_rects_t * style = lv_obj_get_style(rect);
lv_style_t * style = lv_obj_get_style(rect);
area_t area;
lv_obj_get_cords(rect, &area);
@@ -333,17 +287,17 @@ static bool lv_rect_design(lv_obj_t * rect, const area_t * mask, lv_design_mode_
*/
static void lv_rect_draw_shadow(lv_obj_t * rect, const area_t * mask)
{
lv_rects_t * style = lv_obj_get_style(rect);
lv_style_t * style = lv_obj_get_style(rect);
cord_t swidth = style->swidth;
if(swidth == 0) return;
uint8_t res = LV_DOWNSCALE * 2;
if(swidth < res) return;
area_t shadow_area;
lv_rects_t shadow_style;
lv_style_t shadow_style;
lv_obj_get_cords(rect, &shadow_area);
memcpy(&shadow_style, style, sizeof(lv_rects_t));
memcpy(&shadow_style, style, sizeof(lv_style_t));
shadow_style.empty = 1;
shadow_style.bwidth = swidth;
@@ -361,7 +315,7 @@ static void lv_rect_draw_shadow(lv_obj_t * rect, const area_t * mask)
shadow_area.y2 += swidth;
cord_t i;
shadow_style.base.opa = style->base.opa / (swidth / res);
shadow_style.opa = style->opa / (swidth / res);
for(i = 1; i < swidth; i += res) {
lv_draw_rect(&shadow_area, mask, &shadow_style);
@@ -411,7 +365,7 @@ static void lv_rect_layout_col(lv_obj_t * rect)
/*Adjust margin and get the alignment type*/
lv_align_t align;
lv_rects_t * style = lv_obj_get_style(rect);
lv_style_t * style = lv_obj_get_style(rect);
cord_t hpad_corr;
switch(type) {
@@ -460,7 +414,7 @@ static void lv_rect_layout_row(lv_obj_t * rect)
/*Adjust margin and get the alignment type*/
lv_align_t align;
lv_rects_t * style = lv_obj_get_style(rect);
lv_style_t * style = lv_obj_get_style(rect);
cord_t vpad_corr = style->vpad;
switch(type) {
@@ -506,7 +460,7 @@ static void lv_rect_layout_row(lv_obj_t * rect)
static void lv_rect_layout_center(lv_obj_t * rect)
{
lv_obj_t * child;
lv_rects_t * style = lv_obj_get_style(rect);
lv_style_t * style = lv_obj_get_style(rect);
uint32_t obj_num = 0;
cord_t h_tot = 0;
@@ -546,7 +500,7 @@ 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 */
lv_obj_t * child_tmp; /* Temporary child */
lv_rects_t * style = lv_obj_get_style(rect);
lv_style_t * style = lv_obj_get_style(rect);
cord_t w_obj = lv_obj_get_width(rect);
cord_t act_y = style->vpad;
/* Disable child change action because the children will be moved a lot
@@ -622,7 +576,7 @@ static void lv_rect_layout_pretty(lv_obj_t * rect)
static void lv_rect_layout_grid(lv_obj_t * rect)
{
lv_obj_t * child;
lv_rects_t * style = lv_obj_get_style(rect);
lv_style_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));
@@ -680,7 +634,7 @@ static void lv_rect_refr_autofit(lv_obj_t * rect)
area_t new_cords;
area_t ori;
lv_rects_t * style = lv_obj_get_style(rect);
lv_style_t * style = lv_obj_get_style(rect);
lv_obj_t * i;
cord_t hpad = style->hpad;
cord_t vpad = style->vpad;
@@ -739,55 +693,4 @@ static void lv_rect_refr_autofit(lv_obj_t * rect)
}
}
/**
* Initialize the rectangle styles
*/
static void lv_rects_init(void)
{
/*Plain style*/
lv_objs_get(LV_OBJS_PLAIN, &lv_rects_plain.base);
lv_rects_plain.base.color = COLOR_MAKE(0x80, 0xb3, 0xe6); //6BA3BF
lv_rects_plain.gcolor = lv_rects_plain.base.color;
lv_rects_plain.bcolor = COLOR_WHITE;
lv_rects_plain.scolor = COLOR_GRAY;
lv_rects_plain.bwidth = (LV_DPI / 30) == 0 ? 1 * LV_DOWNSCALE : LV_DPI / 30;
lv_rects_plain.swidth = 0;
lv_rects_plain.bopa = OPA_COVER;
lv_rects_plain.radius = LV_DPI / 10;
lv_rects_plain.empty = 0;
lv_rects_plain.hpad = LV_DPI / 2;
lv_rects_plain.vpad = LV_DPI / 2;
lv_rects_plain.opad = LV_DPI / 4;
/*Fancy style*/
lv_objs_get(LV_OBJS_PLAIN, &lv_rects_fancy.base);
lv_rects_fancy.gcolor = COLOR_MAKE(0xd3, 0xe1, 0xea);
lv_rects_fancy.bcolor = COLOR_WHITE;
lv_rects_fancy.scolor = COLOR_BLACK;
lv_rects_fancy.bwidth = (LV_DPI / 30) == 0 ? 1 * LV_DOWNSCALE : LV_DPI / 30;
lv_rects_fancy.swidth = LV_DPI / 6;
lv_rects_fancy.bopa = OPA_50;
lv_rects_fancy.radius = LV_DPI / 10;
lv_rects_fancy.empty = 0;
lv_rects_fancy.hpad = LV_DPI / 4;
lv_rects_fancy.vpad = LV_DPI / 4;
lv_rects_fancy.opad = LV_DPI / 6;
/*Transparent style*/
memcpy(&lv_rects_transp, &lv_rects_plain, sizeof(lv_rects_t));
/* Do not use opa=OPA_TRANSP because design function will not be called
* but it might draw something on transparent background*/
lv_rects_transp.empty = 1;
lv_rects_transp.bwidth = 0;
lv_rects_transp.swidth = 0;
lv_rects_transp.hpad = 0;
lv_rects_transp.vpad = 0;
/*Border style*/
memcpy(&lv_rects_border, &lv_rects_plain, sizeof(lv_rects_t));
lv_rects_border.bcolor = COLOR_MAKE(0x30, 0x30, 0x30);
lv_rects_border.bwidth = LV_DPI / 30;
lv_rects_border.swidth = 0;
lv_rects_border.empty = 1;
}
#endif

View File

@@ -48,34 +48,6 @@ typedef struct
uint8_t vpad_en :1; /*Enable horizontal padding according to the children*/
}lv_rect_ext_t;
/*Style of rectangle*/
typedef struct
{
lv_objs_t base; /*Style of ancestor*/
/*New style element for this type */
color_t gcolor; /*Gradient color*/
color_t bcolor; /*Border color*/
color_t scolor; /*Shadow color*/
cord_t bwidth; /*Border width*/
cord_t swidth; /*Shadow width*/
cord_t radius; /*Radius on the corners*/
cord_t hpad; /*Horizontal padding. Used by fit and layout.*/
cord_t vpad; /*Vertical padding. Used by fit and layout.*/
cord_t opad; /*Object padding. Used by fit */
opa_t bopa; /*Border opacity relative to the object*/
uint8_t empty :1; /*1: Do not draw the body of the rectangle*/
}lv_rects_t;
/*Built-in styles of rectangle*/
typedef enum
{
LV_RECTS_PLAIN,
LV_RECTS_FANCY,
LV_RECTS_BORDER,
LV_RECTS_TRANSP,
}lv_rects_builtin_t;
/**********************
* GLOBAL PROTOTYPES
**********************/
@@ -133,13 +105,6 @@ bool lv_rect_get_hfit(lv_obj_t * rect);
*/
bool lv_rect_get_vfit(lv_obj_t * rect);
/**
* Return with a pointer to a built-in style and/or copy it to a variable
* @param style a style name from lv_rects_builtin_t enum
* @param copy copy the style to this variable. (NULL if unused)
* @return pointer to an lv_rects_t style
*/
lv_rects_t * lv_rects_get(lv_rects_builtin_t style, lv_rects_t * copy);
/**********************
* MACROS

View File

@@ -25,13 +25,10 @@
* STATIC PROTOTYPES
**********************/
static bool lv_slider_design(lv_obj_t * slider, const area_t * mask, lv_design_mode_t mode);
static void lv_sliders_init(void);
/**********************
* STATIC VARIABLES
**********************/
static lv_sliders_t lv_sliders_def; /*Default slider style*/
static lv_design_f_t ancestor_design_f;
/**********************
@@ -66,6 +63,7 @@ lv_obj_t * lv_slider_create(lv_obj_t * par, lv_obj_t * copy)
/*Initialize the allocated 'ext' */
ext->cb = NULL;
ext->tmp_value = ext->bar.min_value;
ext->style_knob = lv_style_get(LV_STYLE_PRETTY_COLOR, NULL);
/* Save the bar design function.
* It will be used in the sllider design function*/
@@ -77,7 +75,6 @@ lv_obj_t * lv_slider_create(lv_obj_t * par, lv_obj_t * copy)
/*Init the new slider slider*/
if(copy == NULL) {
lv_obj_set_style(new_slider, lv_sliders_get(LV_SLIDERS_DEF, NULL));
lv_obj_set_click(new_slider, true);
}
/*Copy an existing slider*/
@@ -165,45 +162,42 @@ void lv_slider_set_action(lv_obj_t * slider, lv_action_t cb)
ext->cb = cb;
}
/**
* Set the style of knob on a slider
* @param slider pointer to slider object
* @param style pointer the new knob style
*/
void lv_slider_set_sytle_knob(lv_obj_t * slider, lv_style_t * style)
{
lv_slider_ext_t * ext = lv_obj_get_ext(slider);
ext->style_knob = style;
lv_obj_inv(slider);
}
/*=====================
* Getter functions
*====================*/
/*
* New object specific "get" function comes here
*/
/**
* Return with a pointer to a built-in style and/or copy it to a variable
* @param style a style name from lv_sliders_builtin_t enum
* @param copy copy the style to this variable. (NULL if unused)
* @return pointer to an lv_sliders_t style
* Get the slider callback function
* @param slider pointer to slider object
* @return the callback function
*/
lv_sliders_t * lv_sliders_get(lv_sliders_builtin_t style, lv_sliders_t * copy)
lv_action_t lv_slider_get_action(lv_obj_t * slider)
{
static bool style_inited = false;
/*Make the style initialization if it is not done yet*/
if(style_inited == false) {
lv_sliders_init();
style_inited = true;
}
lv_sliders_t *style_p;
switch(style) {
case LV_SLIDERS_DEF:
style_p = &lv_sliders_def;
break;
default:
style_p = &lv_sliders_def;
}
if(copy != NULL) memcpy(copy, style_p, sizeof(lv_sliders_t));
return style_p;
lv_slider_ext_t * ext = lv_obj_get_ext(slider);
return ext->cb;
}
/**
* Get the style of knob on a slider
* @param slider pointer to slider object
* @return pointer the new knob style
*/
lv_style_t * lv_slider_get_sytle_knob(lv_obj_t * slider)
{
lv_slider_ext_t * ext = lv_obj_get_ext(slider);
return ext->style_knob;
}
/**********************
@@ -252,7 +246,6 @@ static bool lv_slider_design(lv_obj_t * slider, const area_t * mask, lv_design_m
ancestor_design_f(slider, mask, mode);
ext->bar.act_value -=tmp;
lv_sliders_t * style = lv_obj_get_style(slider);
area_t knob_area;
area_cpy(&knob_area, &slider->cords);
@@ -269,7 +262,7 @@ static bool lv_slider_design(lv_obj_t * slider, const area_t * mask, lv_design_m
knob_area.y2 = knob_area.y1 + w;
}
lv_draw_rect(&knob_area, mask, &style->knob);
lv_draw_rect(&knob_area, mask, ext->style_knob);
}
/*Post draw when the children are drawn*/
@@ -280,22 +273,4 @@ static bool lv_slider_design(lv_obj_t * slider, const area_t * mask, lv_design_m
return true;
}
/**
* Initialize the built-in slider styles
*/
static void lv_sliders_init(void)
{
/*Default style*/
lv_bars_get(LV_BARS_DEF, &lv_sliders_def.bar);
lv_sliders_def.bar.indic.radius = LV_RECT_CIRCLE;
lv_sliders_def.bar.bg.radius = LV_RECT_CIRCLE;
lv_rects_get(LV_RECTS_PLAIN, &lv_sliders_def.knob);
lv_sliders_def.knob.base.color = COLOR_SILVER;
lv_sliders_def.knob.gcolor = COLOR_GRAY;
lv_sliders_def.knob.base.opa = OPA_70;
lv_sliders_def.knob.radius = lv_sliders_def.bar.indic.radius;
}
#endif

View File

@@ -29,16 +29,9 @@ typedef struct
/*New data for this type */
lv_action_t cb; /*Function to call when a new value is set*/
int16_t tmp_value; /*Store temporal value during press until release (Handled by the library)*/
lv_style_t * style_knob; /*Styée of the knob*/
}lv_slider_ext_t;
/*Style of slider*/
typedef struct
{
lv_bars_t bar; /*Style of ancestor*/
/*New style element for this type */
lv_rects_t knob; /*Style of the knob*/
}lv_sliders_t;
/*Built-in styles of slider*/
typedef enum
{
@@ -66,13 +59,6 @@ lv_obj_t * lv_slider_create(lv_obj_t * par, lv_obj_t * copy);
*/
bool lv_slider_signal(lv_obj_t * slider, lv_signal_t sign, void * param);
/**
* Return with a pointer to a built-in style and/or copy it to a variable
* @param style a style name from lv_sliders_builtin_t enum
* @param copy copy the style to this variable. (NULL if unused)
* @return pointer to an lv_sliders_t style
*/
lv_sliders_t * lv_sliders_get(lv_sliders_builtin_t style, lv_sliders_t * copy);
/**********************
* MACROS

View File

@@ -40,13 +40,10 @@ static bool lv_ta_design(lv_obj_t * ta, const area_t * mask, lv_design_mode_t mo
static bool lv_ta_scrling_design(lv_obj_t * scrling, const area_t * mask, lv_design_mode_t mode);
static void lv_ta_hide_cursor(lv_obj_t * ta, uint8_t hide);
static void lv_ta_save_valid_cursor_x(lv_obj_t * ta);
static void lv_tas_init(void);
/**********************
* STATIC VARIABLES
**********************/
static lv_tas_t lv_tas_def;
lv_design_f_t ancestor_design_f;
lv_design_f_t scrl_design_f;
@@ -97,7 +94,7 @@ lv_obj_t * lv_ta_create(lv_obj_t * par, lv_obj_t * copy)
lv_label_set_text(ext->label, "Text area");
lv_page_glue_obj(ext->label, true);
lv_obj_set_click(ext->label, false);
lv_obj_set_style(new_ta, lv_tas_get(LV_TAS_DEF, NULL));
lv_obj_set_style(new_ta, lv_obj_get_style(ext->page.scrl));
lv_obj_set_size(new_ta, LV_TA_DEF_WIDTH, LV_TA_DEF_HEIGHT);
}
/*Copy an existing object*/
@@ -148,7 +145,7 @@ bool lv_ta_signal(lv_obj_t * ta, lv_signal_t sign, void * param)
* make the object specific signal handling */
if(valid != false) {
lv_ta_ext_t * ext = lv_obj_get_ext(ta);
lv_tas_t * style = lv_obj_get_style(ta);
lv_style_t * style = lv_obj_get_style(ta);
switch(sign) {
case LV_SIGNAL_CLEANUP:
/* Nothing to clean up.
@@ -156,9 +153,9 @@ bool lv_ta_signal(lv_obj_t * ta, lv_signal_t sign, void * param)
break;
case LV_SIGNAL_STYLE_CHG:
if(ext->label) {
lv_obj_set_style(ext->label, &style->label);
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 *
(style->page.bg.hpad + style->page.scrl.hpad));
(style->hpad + style->hpad));
lv_label_set_text(ext->label, NULL);
}
break;
@@ -166,7 +163,7 @@ bool lv_ta_signal(lv_obj_t * ta, lv_signal_t sign, void * param)
case LV_SIGNAL_CORD_CHG:
if(ext->label != NULL) {
lv_obj_set_width(ext->label, lv_obj_get_width(ta) - 2 *
(style->page.bg.hpad + style->page.scrl.hpad));
(style->hpad + style->hpad));
lv_label_set_text(ext->label, NULL);
}
break;
@@ -299,6 +296,8 @@ void lv_ta_del(lv_obj_t * ta)
void lv_ta_set_cursor_pos(lv_obj_t * ta, int16_t pos)
{
lv_ta_ext_t * ext = lv_obj_get_ext(ta);
lv_obj_t * scrl = lv_page_get_scrl(ta);
lv_style_t * style_scrl = lv_obj_get_style(scrl);
uint16_t txt_len = strlen(lv_label_get_text(ext->label));
if(pos < 0) pos = txt_len + pos;
@@ -310,8 +309,8 @@ void lv_ta_set_cursor_pos(lv_obj_t * ta, int16_t pos)
/*Position the label to make the cursor visible*/
lv_obj_t * label_par = lv_obj_get_parent(ext->label);
point_t cur_pos;
lv_tas_t * style = lv_obj_get_style(ta);
const font_t * font_p = style->label.font;
lv_style_t * style = lv_obj_get_style(ta);
const font_t * font_p = style->font;
area_t label_cords;
area_t ta_cords;
lv_label_get_letter_pos(ext->label, pos, &cur_pos);
@@ -325,9 +324,9 @@ void lv_ta_set_cursor_pos(lv_obj_t * ta, int16_t pos)
/*Check the bottom*/
cord_t font_h = font_get_height(font_p) >> LV_FONT_ANTIALIAS;
if(label_cords.y1 + cur_pos.y + font_h + style->page.scrl.vpad > ta_cords.y2) {
if(label_cords.y1 + cur_pos.y + font_h + style_scrl->vpad > ta_cords.y2) {
lv_obj_set_y(label_par, -(cur_pos.y - lv_obj_get_height(ta) +
font_h + 2 * style->page.scrl.vpad));
font_h + 2 * style_scrl->vpad));
}
lv_obj_inv(ta);
@@ -377,7 +376,7 @@ void lv_ta_cursor_down(lv_obj_t * ta)
lv_label_get_letter_pos(ext->label, lv_ta_get_cursor_pos(ta), &pos);
/*Increment the y with one line and keep the valid x*/
lv_labels_t * label_style = lv_obj_get_style(ext->label);
lv_style_t * label_style = lv_obj_get_style(ext->label);
const font_t * font_p = label_style->font;
cord_t font_h = font_get_height(font_p) >> LV_FONT_ANTIALIAS;
pos.y += font_h + label_style->line_space + 1;
@@ -404,7 +403,7 @@ void lv_ta_cursor_up(lv_obj_t * ta)
lv_label_get_letter_pos(ext->label, lv_ta_get_cursor_pos(ta), &pos);
/*Decrement the y with one line and keep the valid x*/
lv_labels_t * label_style = lv_obj_get_style(ext->label);
lv_style_t * label_style = lv_obj_get_style(ext->label);
const font_t * font = label_style->font;
cord_t font_h = font_get_height(font) >> LV_FONT_ANTIALIAS;
pos.y -= font_h + label_style->line_space - 1;
@@ -414,6 +413,7 @@ void lv_ta_cursor_up(lv_obj_t * ta)
uint16_t new_cur_pos = lv_label_get_letter_on(ext->label, &pos);
lv_ta_set_cursor_pos(ta, new_cur_pos);
}
/*=====================
* Getter functions
*====================*/
@@ -440,36 +440,6 @@ uint16_t lv_ta_get_cursor_pos(lv_obj_t * ta)
return ext->cursor_pos;
}
/**
* Return with a pointer to a built-in style and/or copy it to a variable
* @param style a style name from lv_tas_builtin_t enum
* @param copy copy the style to this variable. (NULL if unused)
* @return pointer to an lv_tas_t style
*/
lv_tas_t * lv_tas_get(lv_tas_builtin_t style, lv_tas_t * copy)
{
static bool style_inited = false;
/*Make the style initialization if it is not done yet*/
if(style_inited == false) {
lv_tas_init();
style_inited = true;
}
lv_tas_t *style_p;
switch(style) {
case LV_TAS_DEF:
style_p = &lv_tas_def;
break;
default:
style_p = &lv_tas_def;
}
if(copy != NULL) memcpy(copy, style_p, sizeof(lv_tas_t));
return style_p;
}
/**********************
* STATIC FUNCTIONS
**********************/
@@ -523,26 +493,26 @@ static bool lv_ta_scrling_design(lv_obj_t * scrling, const area_t * mask, lv_des
/*Draw the cursor too*/
lv_obj_t * ta = lv_obj_get_parent(scrling);
lv_ta_ext_t * ta_ext = lv_obj_get_ext(ta);
lv_tas_t * ta_style = lv_obj_get_style(ta);
lv_style_t * ta_style = lv_obj_get_style(ta);
if(ta_style->cursor_show != 0 && ta_ext->cur_hide == 0) {
if(ta_ext->cursor_show != 0 && ta_ext->cur_hide == 0) {
uint16_t cur_pos = lv_ta_get_cursor_pos(ta);
point_t letter_pos;
lv_label_get_letter_pos(ta_ext->label, cur_pos, &letter_pos);
area_t cur_area;
lv_labels_t * labels_p = lv_obj_get_style(ta_ext->label);
lv_style_t * labels_p = lv_obj_get_style(ta_ext->label);
cur_area.x1 = letter_pos.x + ta_ext->label->cords.x1;
cur_area.y1 = letter_pos.y + ta_ext->label->cords.y1;
cur_area.x2 = letter_pos.x + ta_ext->label->cords.x1 + LV_DOWNSCALE ;
cur_area.y2 = letter_pos.y + ta_ext->label->cords.y1 + (font_get_height(labels_p->font) >> LV_FONT_ANTIALIAS);
lv_rects_t cur_rects;
lv_rects_get(LV_RECTS_PLAIN, &cur_rects);
lv_style_t cur_rects;
lv_style_get(LV_STYLE_PLAIN, &cur_rects);
cur_rects.radius = 0;
cur_rects.bwidth = 0;
cur_rects.base.color = ta_style->label.base.color;
cur_rects.gcolor = ta_style->label.base.color;
cur_rects.mcolor = ta_style->ccolor;
cur_rects.gcolor = ta_style->ccolor;
lv_draw_rect(&cur_area, mask, &cur_rects);
}
}
@@ -577,19 +547,4 @@ static void lv_ta_save_valid_cursor_x(lv_obj_t * ta)
ext->cursor_valid_x = cur_pos.x;
}
/**
* Initialize the text area styles
*/
static void lv_tas_init(void)
{
/*Default style*/
lv_pages_get(LV_PAGES_PAPER, &lv_tas_def.page);
lv_tas_def.page.sb_mode = LV_PAGE_SB_MODE_DRAG;
lv_labels_get(LV_LABELS_TXT, &lv_tas_def.label);
lv_tas_def.label.base.color = COLOR_MAKE(0x10, 0x10, 0x10);
lv_tas_def.cursor_show = 1;
}
#endif

View File

@@ -43,23 +43,9 @@ typedef struct
cord_t cursor_valid_x; /*Used when stepping up/down in text area. Handled by the library*/
uint16_t cursor_pos; /*The current cursor position (0: before 1. letter, 1: before 2. letter etc.)*/
uint8_t cur_hide :1; /*Indicates that the cursor is visible now or not*/
uint8_t cursor_show :1; /*Flag to indicate the cursor is now being shown or not (Handled by the library)*/
}lv_ta_ext_t;
/*Style of text area*/
typedef struct
{
lv_pages_t page; /*Style of ancestor*/
/*New style element for this type */
lv_labels_t label; /*Style of the label*/
uint8_t cursor_show :1; /*Flag to indicate the cursor is now being shown or not (Handled by the library)*/
}lv_tas_t;
/*Built-in styles of text area*/
typedef enum
{
LV_TAS_DEF,
}lv_tas_builtin_t;
/**********************
* GLOBAL PROTOTYPES
**********************/
@@ -155,13 +141,6 @@ const char * lv_ta_get_txt(lv_obj_t * ta);
*/
uint16_t lv_ta_get_cursor_pos(lv_obj_t * ta);
/**
* Return with a pointer to a built-in style and/or copy it to a variable
* @param style a style name from lv_tas_builtin_t enum
* @param copy copy the style to this variable. (NULL if unused)
* @return pointer to an lv_tas_t style
*/
lv_tas_t * lv_tas_get(lv_tas_builtin_t style, lv_tas_t * copy);
/**********************
* MACROS

View File

@@ -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

View File

@@ -55,34 +55,17 @@
/*Data of window*/
typedef struct
{
lv_page_ext_t page; /*Ext. of ancestor*/
/*Ext. of ancestor*/
/*New data for this type */
lv_obj_t * page;
lv_obj_t * header; /*Pointer to the header rectangle of the window*/
lv_obj_t * title; /*Pointer to the title label of the window*/
lv_obj_t * ctrl_holder; /*Pointer to the control button holder rectangle of the window*/
lv_obj_t * btnh; /*Pointer to the control button holder rectangle of the window*/
lv_style_t * style_header; /*Style of the header rectangle*/
lv_style_t * styles_btn[LV_BTN_STATE_NUM]; /*Style of the control buttons*/
cord_t btn_size; /*Size of the control buttons (square)*/
}lv_win_ext_t;
/*Style of window*/
typedef struct
{
lv_pages_t page; /*Style of ancestor*/
/*New style element for this type */
/*Header settings*/
lv_rects_t header; /*Style of the header rectangle*/
lv_labels_t title; /*Style of the window title*/
lv_rects_t ctrl_holder; /*Style of holder of the control buttons*/
lv_btns_t ctrl_btn; /*Style of the control buttons*/
lv_imgs_t ctrl_img; /*Style of the image on the control buttons*/
cord_t ctrl_btn_w; /*Width of the control buttons*/
cord_t ctrl_btn_h; /*Height of the control buttons*/
}lv_wins_t;
/*Built-in styles of window*/
typedef enum
{
LV_WINS_DEF,
}lv_wins_builtin_t;
/**********************
* GLOBAL PROTOTYPES
**********************/
@@ -135,6 +118,8 @@ void lv_win_set_title(lv_obj_t * win, const char * title);
*/
const char * lv_win_get_title(lv_obj_t * win);
lv_obj_t * lv_win_get_page(lv_obj_t * win);
/**
* 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.
@@ -143,14 +128,6 @@ const char * lv_win_get_title(lv_obj_t * win);
*/
lv_obj_t * lv_win_get_from_ctrl_btn(lv_obj_t * ctrl_btn);
/**
* 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);
/**********************
* MACROS
**********************/