BigW Consortium Gitlab

Commit 151b7cbb by Gabor

Rectangle padding added

parent c4763559
......@@ -15,8 +15,6 @@
/*********************
* DEFINES
*********************/
#define LV_OBJ_DEF_LENGTH 80
#define LV_OBJ_DEF_HEIGHT 60
/**********************
* TYPEDEFS
......@@ -111,6 +109,7 @@ void lv_obj_inv(lv_obj_t* obj_dp)
*/
void lv_obj_refr_style(lv_obj_t* obj_dp)
{
lv_obj_inv(obj_dp);
obj_dp->signal_f(obj_dp, LV_SIGNAL_STYLE_CHG, NULL);
lv_obj_inv(obj_dp);
......@@ -186,9 +185,9 @@ lv_obj_t* lv_obj_create(lv_obj_t* parent_dp, lv_obj_t * copy_dp)
new_obj_dp->cords.x1 = parent_dp->cords.x1;
new_obj_dp->cords.y1 = parent_dp->cords.y1;
new_obj_dp->cords.x2 = parent_dp->cords.x1 +
LV_OBJ_DEF_LENGTH * LV_DOWNSCALE;
LV_OBJ_DEF_WIDTH;
new_obj_dp->cords.y2 = parent_dp->cords.y1 +
LV_OBJ_DEF_HEIGHT * LV_DOWNSCALE;
LV_OBJ_DEF_HEIGHT;
/*Set appearance*/
new_obj_dp->style_p = lv_objs_get(LV_OBJS_DEF, NULL);
......@@ -750,6 +749,7 @@ void lv_obj_set_style(lv_obj_t* obj_dp, void * style_p)
obj_dp->style_p = style_p;
obj_dp->signal_f(obj_dp, LV_SIGNAL_STYLE_CHG, NULL);
//obj_dp->signal_f(lv_obj_get_parent(obj_dp, )
lv_obj_inv(obj_dp);
}
......
......@@ -39,6 +39,9 @@
#define LV_STYLE_MULT 1
#endif
#define LV_OBJ_DEF_WIDTH (80 * LV_DOWNSCALE)
#define LV_OBJ_DEF_HEIGHT (60 * LV_DOWNSCALE)
/**********************
* TYPEDEFS
**********************/
......
......@@ -25,20 +25,26 @@
typedef enum
{
LV_BTN_PR,
LV_BTN_REL,
LV_BTN_TGL_PR,
LV_BTN_TGL_REL,
LV_BTN_INA,
LV_BTN_STATE_PR,
LV_BTN_STATE_REL,
LV_BTN_STATE_TGL_PR,
LV_BTN_STATE_TGL_REL,
LV_BTN_STATE_INA,
LV_BTN_STATE_NUM,
}lv_btn_state_t;
typedef struct
{
lv_rects_t rel;
lv_rects_t pr;
lv_rects_t tgl_rel;
lv_rects_t tgl_pr;
lv_rects_t ina;
lv_rects_t rects; /*To be compatible with the ancestor*/
color_t mcolor[LV_BTN_STATE_NUM];
color_t gcolor[LV_BTN_STATE_NUM];
color_t bcolor[LV_BTN_STATE_NUM];
cord_t bwidth;
cord_t round;
opa_t bopa;
uint8_t empty;
cord_t hpad;
cord_t vpad;
}lv_btns_t;
typedef enum
......@@ -50,6 +56,7 @@ typedef enum
typedef struct
{
lv_rect_ext_t rect_ext;
bool (*pr_action)(lv_obj_t*, lv_dispi_t *);
bool (*rel_action)(lv_obj_t*, lv_dispi_t *);
bool (*lpr_action)(lv_obj_t*, lv_dispi_t *);
......
......@@ -207,6 +207,9 @@ void lv_label_set_text(lv_obj_t * obj_dp, const char * text)
lv_obj_set_width(obj_dp, longest_line);
}
lv_obj_t * parent_dp = lv_obj_get_parent(obj_dp);
parent_dp->signal_f(parent_dp, LV_SIGNAL_CHILD_CHG, obj_dp);
lv_obj_inv(obj_dp);
}
......
......@@ -39,6 +39,8 @@ static lv_pages_t lv_pages_def =
.bg_rects.bwidth = 0 * LV_STYLE_MULT,
.bg_rects.round = 2 * LV_STYLE_MULT,
.bg_rects.empty = 0,
.bg_rects.hpad = 10,
.bg_rects.vpad = 10,
.sb_rects.mcolor = COLOR_BLACK,
.sb_rects.gcolor = COLOR_BLACK,
......@@ -68,6 +70,8 @@ static lv_pages_t lv_pages_paper =
.bg_rects.bwidth = 2 * LV_STYLE_MULT,
.bg_rects.round = 0 * LV_STYLE_MULT,
.bg_rects.empty = 0,
.bg_rects.hpad = 20 * LV_STYLE_MULT,
.bg_rects.vpad = 20 * LV_STYLE_MULT,
.sb_rects.mcolor = COLOR_BLACK,
.sb_rects.gcolor = COLOR_BLACK,
......@@ -85,12 +89,13 @@ static lv_pages_t lv_pages_paper =
.margin_ver = 15 * LV_STYLE_MULT,
.padding_hor = 10 * LV_STYLE_MULT,
.padding_ver = 10 * LV_STYLE_MULT,
};
static lv_pages_t lv_pages_transp =
{
.bg_rects.empty = 1,
.bg_rects.hpad = 1,
.bg_rects.vpad = 1,
.sb_rects.mcolor = COLOR_BLACK,
.sb_rects.gcolor = COLOR_BLACK,
......@@ -133,14 +138,14 @@ lv_obj_t* lv_page_create(lv_obj_t * par_dp, lv_obj_t * ori_dp)
new_dp = lv_rect_create(par_dp, ori_dp);
/*Init the new object*/
lv_page_t * page_p = lv_obj_alloc_ext(new_dp, sizeof(lv_page_t));
lv_page_ext_t * page_p = lv_obj_alloc_ext(new_dp, sizeof(lv_page_ext_t));
/*Init the main rectangle if it is not copied*/
if(ori_dp == NULL) {
lv_obj_set_size(new_dp, 100,200);
lv_obj_set_drag(new_dp, true);
lv_obj_set_drag_throw(new_dp, true);
lv_obj_set_style(new_dp, &lv_pages_def);
lv_rect_set_pad_en(new_dp, true, true);
} else {
lv_obj_set_style(new_dp, lv_obj_get_style(ori_dp));
}
......@@ -198,10 +203,9 @@ bool lv_page_signal(lv_obj_t* obj_dp, lv_signal_t sign, void* param)
bool refr_y = false;
area_t page_cords;
area_t par_cords;
lv_obj_t * i;
lv_obj_t * par_dp = lv_obj_get_parent(obj_dp);
lv_page_t * page_ext_p = lv_obj_get_ext(obj_dp);
lv_page_ext_t * page_ext_p = lv_obj_get_ext(obj_dp);
lv_pages_t * pages_p = lv_obj_get_style(obj_dp);
switch(sign) {
......@@ -268,36 +272,6 @@ bool lv_page_signal(lv_obj_t* obj_dp, lv_signal_t sign, void* param)
}
break;
case LV_SIGNAL_CHILD_CHG:
page_cords.x1 = LV_CORD_MAX;
page_cords.y1 = LV_CORD_MAX;
page_cords.x2 = LV_CORD_MIN;
page_cords.y2 = LV_CORD_MIN;
LL_READ(obj_dp->child_ll, i) {
page_cords.x1 = min(page_cords.x1, i->cords.x1);
page_cords.y1 = min(page_cords.y1, i->cords.y1);
page_cords.x2 = max(page_cords.x2, i->cords.x2);
page_cords.y2 = max(page_cords.y2, i->cords.y2);
}
/*If the value is not the init value then the page has >=1 child.*/
if(page_cords.x1 != LV_CORD_MAX) {
page_cords.x1 -= pages_p->padding_hor;
page_cords.x2 += pages_p->padding_hor;
page_cords.y1 -= pages_p->padding_ver;
page_cords.y2 += pages_p->padding_ver;
area_cpy(&obj_dp->cords, &page_cords);
lv_obj_set_pos(obj_dp, lv_obj_get_x(obj_dp),
lv_obj_get_y(obj_dp));
} else {
lv_obj_set_size(obj_dp, 10, 10);
}
lv_obj_inv(par_dp);
break;
case LV_SIGNAL_STYLE_CHG:
/* Set the styles only if they are different else infinite loop
......@@ -397,7 +371,7 @@ lv_pages_t * lv_pages_get(lv_pages_builtin_t style, lv_pages_t * to_copy)
*/
static void lv_page_sb_refresh(lv_obj_t* page_dp)
{
lv_page_t * page_p = lv_obj_get_ext(page_dp);
lv_page_ext_t * page_p = lv_obj_get_ext(page_dp);
lv_pages_t * pages_p = lv_obj_get_style(page_dp);
lv_obj_t* par_dp = lv_obj_get_parent(page_dp);
cord_t size_tmp;
......
......@@ -45,9 +45,10 @@ typedef struct
typedef struct
{
lv_rect_ext_t rect_exp;
lv_obj_t* sbh_dp; /*Horizontal scrollbar*/
lv_obj_t* sbv_dp; /*Vertical scrollbar*/
}lv_page_t;
}lv_page_ext_t;
typedef enum
{
......
......@@ -12,6 +12,7 @@
#include "lv_rect.h"
#include "../lv_draw/lv_draw.h"
#include "../lv_draw/lv_draw_vbasic.h"
#include "misc/math/math_base.h"
/*********************
* DEFINES
......@@ -32,14 +33,17 @@ static bool lv_rect_design(lv_obj_t* obj_dp, const area_t * mask_p, lv_design_mo
static lv_rects_t lv_rects_def =
{ .mcolor = COLOR_MAKE(0x50, 0x70, 0x90), .gcolor = COLOR_MAKE(0x20, 0x40, 0x60),
.bcolor = COLOR_WHITE, .bwidth = 2 * LV_STYLE_MULT, .bopa = 50,
.round = 4 * LV_STYLE_MULT, .empty = 0 };
.round = 4 * LV_STYLE_MULT, .empty = 0,
.hpad = 0, .vpad = 0 };
static lv_rects_t lv_rects_transp =
{ .bwidth = 0, .empty = 0 };
{ .bwidth = 0, .empty = 0,
.hpad = 0, .vpad = 0 };
static lv_rects_t lv_rects_border =
{ .bcolor = COLOR_BLACK, .bwidth = 2 * LV_STYLE_MULT, .bopa = 100,
.round = 4 * LV_STYLE_MULT, .empty = 1 };
.round = 4 * LV_STYLE_MULT, .empty = 1,
.hpad = 0, .vpad = 0};
/**********************
* MACROS
......@@ -64,13 +68,20 @@ lv_obj_t* lv_rect_create(lv_obj_t* par_dp, lv_obj_t * copy_dp)
/*Create a basic object*/
lv_obj_t* new_obj_dp = lv_obj_create(par_dp, copy_dp);
dm_assert(new_obj_dp);
lv_obj_alloc_ext(new_obj_dp, sizeof(lv_rect_ext_t));
lv_rect_ext_t * rect_ext_dp = lv_obj_get_ext(new_obj_dp);
lv_obj_set_design_f(new_obj_dp, lv_rect_design);
lv_obj_set_signal_f(new_obj_dp, lv_rect_signal);
/*Init the new rectangle*/
if(copy_dp == NULL) {
lv_obj_set_style(new_obj_dp, &lv_rects_def);
rect_ext_dp->hpad_en = 0;
rect_ext_dp->vpad_en = 0;
} else {
lv_rect_ext_t * ori_rect_ext = lv_obj_get_ext(copy_dp);
rect_ext_dp->hpad_en = ori_rect_ext->hpad_en;
rect_ext_dp->vpad_en = ori_rect_ext->vpad_en;
}
return new_obj_dp;
......@@ -88,11 +99,61 @@ bool lv_rect_signal(lv_obj_t* obj_dp, lv_signal_t sign, void * param)
/* Include the ancient signal function */
valid = lv_obj_signal(obj_dp, sign, param);
area_t rect_cords;
lv_rects_t * rests_p = lv_obj_get_style(obj_dp);
lv_rect_ext_t * ext_p = lv_obj_get_ext(obj_dp);
lv_obj_t * i;
/* 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_STYLE_CHG: /*Recalculate the padding if the style changed*/
case LV_SIGNAL_CHILD_CHG:
if(ext_p->hpad_en == 0 &&
ext_p->vpad_en == 0) {
break;
}
/*Search the side coordinates of the children*/
lv_obj_get_cords(obj_dp, &rect_cords);
rect_cords.x1 = LV_CORD_MAX;
rect_cords.y1 = LV_CORD_MAX;
rect_cords.x2 = LV_CORD_MIN;
rect_cords.y2 = LV_CORD_MIN;
LL_READ(obj_dp->child_ll, i) {
rect_cords.x1 = min(rect_cords.x1, i->cords.x1);
rect_cords.y1 = min(rect_cords.y1, i->cords.y1);
rect_cords.x2 = max(rect_cords.x2, i->cords.x2);
rect_cords.y2 = max(rect_cords.y2, i->cords.y2);
}
/*If the value is not the init value then the page has >=1 child.*/
if(rect_cords.x1 != LV_CORD_MAX) {
if(rests_p->hpad != 0) {
rect_cords.x1 -= rests_p->hpad;
rect_cords.x2 += rests_p->hpad;
} else {
rect_cords.x1 = obj_dp->cords.x1;
rect_cords.x2 = obj_dp->cords.x2;
}
if(rests_p->vpad != 0) {
rect_cords.y1 -= rests_p->vpad;
rect_cords.y2 += rests_p->vpad;
} else {
rect_cords.y1 = obj_dp->cords.y1;
rect_cords.y2 = obj_dp->cords.y2;
}
area_cpy(&obj_dp->cords, &rect_cords);
lv_obj_set_pos(obj_dp, lv_obj_get_x(obj_dp),
lv_obj_get_y(obj_dp));
} else {
lv_obj_set_size(obj_dp, LV_OBJ_DEF_WIDTH, LV_OBJ_DEF_HEIGHT);
}
break;
default:
break;
}
......@@ -101,6 +162,52 @@ bool lv_rect_signal(lv_obj_t* obj_dp, lv_signal_t sign, void * param)
return valid;
}
/*=====================
* Setter functions
*====================*/
/**
* Enable the horizontal or vertical padding
* @param obj_dp pointer to a rectangle object
* @param hor_en true: enable the horizontal padding
* @param ver_en true: enable the vertical padding
*/
void lv_rect_set_pad_en(lv_obj_t * obj_dp, bool hor_en, bool ver_en)
{
lv_rect_ext_t * ext_p = lv_obj_get_ext(obj_dp);
ext_p->hpad_en = hor_en == false ? 0 : 1;
ext_p->vpad_en = ver_en == false ? 0 : 1;
obj_dp->signal_f(obj_dp, LV_SIGNAL_STYLE_CHG, obj_dp);
}
/*=====================
* Getter functions
*====================*/
/**
* Get horizontal padding enable attribute of a rectangle
* @param obj_dp pointer to a rectangle object
* @return true: horizontal padding is enabled
*/
bool lv_rect_get_hpad_en(lv_obj_t * obj_dp)
{
lv_rect_ext_t * ext_p = lv_obj_get_ext(obj_dp);
return ext_p->hpad_en == 0 ? false : true;
}
/**
* Get vertical padding enable attribute of a rectangle
* @param obj_dp pointer to a rectangle object
* @return true: vertical padding is enabled
*/
bool lv_rect_get_vpad_en(lv_obj_t * obj_dp)
{
lv_rect_ext_t * ext_p = lv_obj_get_ext(obj_dp);
return ext_p->vpad_en == 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_rects_builtin_t enum
......@@ -109,7 +216,7 @@ bool lv_rect_signal(lv_obj_t* obj_dp, lv_signal_t sign, void * param)
*/
lv_rects_t * lv_rects_get(lv_rects_builtin_t style, lv_rects_t * copy_p)
{
lv_rects_t *style_p;
lv_rects_t * style_p;
switch(style) {
case LV_RECTS_DEF:
......
......@@ -29,6 +29,8 @@ typedef struct
color_t gcolor;
color_t bcolor;
uint16_t bwidth;
cord_t hpad;
cord_t vpad;
uint8_t bopa;
uint8_t empty :1;
uint16_t round;
......@@ -37,7 +39,8 @@ typedef struct
typedef struct
{
uint8_t hpad_en:1;
uint8_t vpad_en:1;
}lv_rect_ext_t;
typedef enum
......@@ -53,6 +56,13 @@ typedef enum
/*Create function*/
lv_obj_t* lv_rect_create(lv_obj_t* par_dp, lv_obj_t * copy_dp);
bool lv_rect_signal(lv_obj_t* obj_dp, lv_signal_t sign, void * param);
void lv_rect_set_pad_en(lv_obj_t * obj_dp, bool hor_en, bool ver_en);
bool lv_rect_get_hpad_en(lv_obj_t * obj_dp);
bool lv_rect_get_vpad_en(lv_obj_t * obj_dp);
lv_rects_t * lv_rects_get(lv_rects_builtin_t style, lv_rects_t * copy_p);
/**********************
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment