mirror of
https://github.com/lvgl/lvgl.git
synced 2025-01-14 06:42:58 +08:00
add LV_BORDER_INTERNAL
This commit is contained in:
parent
9531f04abf
commit
d19792289d
@ -37,6 +37,7 @@ enum
|
||||
LV_BORDER_LEFT = 0x04,
|
||||
LV_BORDER_RIGHT = 0x08,
|
||||
LV_BORDER_FULL = 0x0F,
|
||||
LV_BORDER_INTERNAL = 0x10, /*FOR matrix-like objects (e.g. Button matrix)*/
|
||||
};
|
||||
typedef uint8_t lv_border_part_t;
|
||||
|
||||
|
@ -35,7 +35,7 @@ static bool button_is_inactive(const char * btn_str);
|
||||
const char * cut_ctrl_byte(const char * btn_str);
|
||||
static uint16_t get_button_from_point(lv_obj_t * btnm, lv_point_t * p);
|
||||
static uint16_t get_button_text(lv_obj_t * btnm, uint16_t btn_id);
|
||||
static void create_buttons(lv_obj_t * btnm, const char ** map);
|
||||
static void allocate_btn_areas(lv_obj_t * btnm, const char ** map);
|
||||
|
||||
/**********************
|
||||
* STATIC VARIABLES
|
||||
@ -154,7 +154,7 @@ void lv_btnm_set_map(lv_obj_t * btnm, const char ** map)
|
||||
ext->map_p = map;
|
||||
|
||||
/*Analyze the map and create the required number of buttons*/
|
||||
create_buttons(btnm, map);
|
||||
allocate_btn_areas(btnm, map);
|
||||
|
||||
/*Set size and positions of the buttons*/
|
||||
lv_style_t * style_bg = lv_btnm_get_style(btnm, LV_BTNM_STYLE_BG);
|
||||
@ -231,10 +231,9 @@ void lv_btnm_set_map(lv_obj_t * btnm, const char ** map)
|
||||
}
|
||||
act_y += btn_h + style_bg->body.padding.inner;
|
||||
|
||||
/*If no vertical padding then make sure the last row is at the bottom of 'btnm'*/
|
||||
if(style_bg->body.padding.ver == 0 &&
|
||||
act_y + btn_h * 2 > max_h) { /*Last row?*/
|
||||
btn_h = max_h - act_y - 1;
|
||||
/*Make sure the last row is at the bottom of 'btnm'*/
|
||||
if(act_y + btn_h * 2 > max_h) { /*Last row?*/
|
||||
btn_h = max_h - act_y + style_bg->body.padding.ver - 1;
|
||||
}
|
||||
|
||||
if(strlen(map_p_tmp[btn_cnt]) == 0) break; /*Break on end of map*/
|
||||
@ -456,15 +455,16 @@ static bool lv_btnm_design(lv_obj_t * btnm, const lv_area_t * mask, lv_design_mo
|
||||
|
||||
uint16_t btn_i = 0;
|
||||
uint16_t txt_i = 0;
|
||||
|
||||
lv_style_t style_tmp;
|
||||
lv_txt_flag_t txt_flag = LV_TXT_FLAG_NONE;
|
||||
|
||||
if(ext->recolor)
|
||||
txt_flag = LV_TXT_FLAG_RECOLOR;
|
||||
if(ext->recolor) txt_flag = LV_TXT_FLAG_RECOLOR;
|
||||
|
||||
for(btn_i = 0; btn_i < ext->btn_cnt; btn_i ++, txt_i ++) {
|
||||
/*Search the next valid text in the map*/
|
||||
while(strcmp(ext->map_p[txt_i], "\n") == 0) txt_i ++;
|
||||
while(strcmp(ext->map_p[txt_i], "\n") == 0) {
|
||||
txt_i ++;
|
||||
}
|
||||
|
||||
/*Skip hidden buttons*/
|
||||
if(button_is_hidden(ext->map_p[txt_i])) continue;
|
||||
@ -486,7 +486,29 @@ static bool lv_btnm_design(lv_obj_t * btnm, const lv_area_t * mask, lv_design_mo
|
||||
else if(btn_i == ext->btn_id_pr && btn_i == ext->btn_id_tgl) btn_style = lv_btnm_get_style(btnm, LV_BTNM_STYLE_BTN_TGL_PR);
|
||||
else btn_style = lv_btnm_get_style(btnm, LV_BTNM_STYLE_BTN_REL); /*Not possible option, just to be sure*/
|
||||
|
||||
lv_draw_rect(&area_tmp, mask, btn_style, opa_scale);
|
||||
lv_style_copy(&style_tmp, btn_style);
|
||||
|
||||
/*Remove borders on the edges if `LV_BORDER_INTERNAL`*/
|
||||
if(style_tmp.body.border.part & LV_BORDER_INTERNAL) {
|
||||
if(area_tmp.y1 == btnm->coords.y1 + bg_style->body.padding.ver) {
|
||||
style_tmp.body.border.part &= ~LV_BORDER_TOP;
|
||||
}
|
||||
if(area_tmp.y2 == btnm->coords.y2 - bg_style->body.padding.ver) {
|
||||
style_tmp.body.border.part &= ~LV_BORDER_BOTTOM;
|
||||
}
|
||||
|
||||
if(txt_i == 0) {
|
||||
style_tmp.body.border.part &= ~LV_BORDER_LEFT;
|
||||
}
|
||||
else if(strcmp(ext->map_p[txt_i - 1],"\n") == 0) {
|
||||
style_tmp.body.border.part &= ~LV_BORDER_LEFT;
|
||||
}
|
||||
|
||||
if(ext->map_p[txt_i + 1][0] == '\0' || strcmp(ext->map_p[txt_i + 1], "\n") == 0) {
|
||||
style_tmp.body.border.part &= ~LV_BORDER_RIGHT;
|
||||
}
|
||||
}
|
||||
lv_draw_rect(&area_tmp, mask, &style_tmp, opa_scale);
|
||||
|
||||
/*Calculate the size of the text*/
|
||||
if(btn_style->glass) btn_style = bg_style;
|
||||
@ -715,7 +737,7 @@ static lv_res_t lv_btnm_signal(lv_obj_t * btnm, lv_signal_t sign, void * param)
|
||||
* @param btnm pointer to button matrix object
|
||||
* @param map_p pointer to a string array
|
||||
*/
|
||||
static void create_buttons(lv_obj_t * btnm, const char ** map)
|
||||
static void allocate_btn_areas(lv_obj_t * btnm, const char ** map)
|
||||
{
|
||||
/*Count the buttons in the map*/
|
||||
uint16_t btn_cnt = 0;
|
||||
|
@ -8,7 +8,6 @@
|
||||
*********************/
|
||||
#include "lv_theme.h"
|
||||
|
||||
|
||||
#if USE_LV_THEME_MATERIAL
|
||||
|
||||
/*********************
|
||||
@ -434,7 +433,7 @@ static void btnm_init(void)
|
||||
bg.text.color = LV_COLOR_HEX3(0x555);
|
||||
|
||||
lv_style_copy(&rel, theme.panel);
|
||||
rel.body.border.part = LV_BORDER_RIGHT;
|
||||
rel.body.border.part = LV_BORDER_FULL | LV_BORDER_INTERNAL;
|
||||
rel.body.border.width = 1;
|
||||
rel.body.border.color = LV_COLOR_HEX3(0xbbb);
|
||||
rel.body.empty = 1;
|
||||
|
@ -426,6 +426,9 @@ static void win_init(void)
|
||||
*/
|
||||
lv_theme_t * lv_theme_mono_init(uint16_t hue, lv_font_t * font)
|
||||
{
|
||||
|
||||
(void)hue; /*Unused*/
|
||||
|
||||
if(font == NULL) font = LV_FONT_DEFAULT;
|
||||
|
||||
_font = font;
|
||||
|
@ -429,29 +429,29 @@ static void btnm_init(void)
|
||||
btnm_bg.body.border.width = 1;
|
||||
|
||||
lv_style_copy(&rel, &btn_rel);
|
||||
rel.body.border.part = LV_BORDER_RIGHT;
|
||||
rel.body.border.width = 2;
|
||||
rel.body.radius = 0;
|
||||
rel.body.border.part = LV_BORDER_FULL | LV_BORDER_INTERNAL;
|
||||
rel.body.border.width = 1;
|
||||
rel.body.radius = 2;
|
||||
|
||||
lv_style_copy(&pr, &btn_pr);
|
||||
pr.body.border.part = LV_BORDER_RIGHT;
|
||||
pr.body.border.width = 2;
|
||||
pr.body.radius = 0;
|
||||
pr.body.border.part = rel.body.border.part;
|
||||
pr.body.border.width = rel.body.border.width;
|
||||
pr.body.radius = rel.body.radius;
|
||||
|
||||
lv_style_copy(&tgl_rel, &btn_tgl_rel);
|
||||
tgl_rel.body.border.part = LV_BORDER_RIGHT;
|
||||
tgl_rel.body.border.width = 2;
|
||||
tgl_rel.body.radius = 0;
|
||||
tgl_rel.body.border.part = rel.body.border.part;
|
||||
tgl_rel.body.border.width = rel.body.border.width;
|
||||
tgl_rel.body.radius = rel.body.radius;
|
||||
|
||||
lv_style_copy(&tgl_pr, &btn_tgl_pr);
|
||||
tgl_pr.body.border.part = LV_BORDER_RIGHT;
|
||||
tgl_pr.body.border.width = 2;
|
||||
tgl_pr.body.radius = 0;
|
||||
tgl_pr.body.border.part = rel.body.border.part;
|
||||
tgl_pr.body.border.width = rel.body.border.width;
|
||||
tgl_pr.body.radius = rel.body.radius;
|
||||
|
||||
lv_style_copy(&ina, &btn_ina);
|
||||
ina.body.border.part = LV_BORDER_RIGHT;
|
||||
ina.body.border.width = 2;
|
||||
ina.body.radius = 0;
|
||||
ina.body.border.part = rel.body.border.part;
|
||||
ina.body.border.width = rel.body.border.width;
|
||||
ina.body.radius = rel.body.radius;
|
||||
|
||||
theme.btnm.bg = &btnm_bg;
|
||||
theme.btnm.btn.rel = &rel;
|
||||
|
Loading…
x
Reference in New Issue
Block a user