mirror of
https://github.com/lvgl/lvgl.git
synced 2025-01-28 07:03:00 +08:00
all widgets work in a basic way
This commit is contained in:
parent
ea6ee3d198
commit
8d3f43cf5c
@ -41,6 +41,7 @@ typedef struct
|
||||
lv_draw_line_dsc_t * line_dsc;
|
||||
lv_draw_img_dsc_t * img_dsc;
|
||||
lv_draw_arc_dsc_t * arc_dsc;
|
||||
char text[16];
|
||||
const lv_area_t * draw_area;
|
||||
const lv_point_t * p1;
|
||||
const lv_point_t * p2;
|
||||
|
@ -88,10 +88,15 @@ void lv_draw_arc(lv_coord_t center_x, lv_coord_t center_y, uint16_t radius, uin
|
||||
|
||||
lv_draw_rect_dsc_t cir_dsc;
|
||||
lv_draw_rect_dsc_init(&cir_dsc);
|
||||
cir_dsc.bg_opa = dsc->opa;
|
||||
cir_dsc.bg_color = dsc->color;
|
||||
cir_dsc.blend_mode = dsc->blend_mode;
|
||||
cir_dsc.bg_img_src = dsc->bg_img_src;
|
||||
if(dsc->bg_img_src) {
|
||||
cir_dsc.bg_opa = LV_OPA_TRANSP;
|
||||
cir_dsc.bg_img_src = dsc->bg_img_src;
|
||||
cir_dsc.bg_img_opa = dsc->opa;
|
||||
} else {
|
||||
cir_dsc.bg_opa = dsc->opa;
|
||||
cir_dsc.bg_color = dsc->color;
|
||||
}
|
||||
|
||||
lv_area_t area_out;
|
||||
area_out.x1 = center_x - radius;
|
||||
|
@ -211,7 +211,6 @@ static void basic_init(void)
|
||||
lv_style_set_bg_opa(&styles->scr, LV_OPA_COVER);
|
||||
lv_style_set_bg_color(&styles->scr, COLOR_SCR);
|
||||
lv_style_set_text_color(&styles->scr, COLOR_SCR_TEXT);
|
||||
lv_style_set_pad_all(&styles->scr, PAD_DEF);
|
||||
lv_style_set_pad_row(&styles->scr, PAD_DEF);
|
||||
lv_style_set_pad_column(&styles->scr, PAD_DEF);
|
||||
|
||||
@ -352,15 +351,14 @@ static void basic_init(void)
|
||||
style_init_reset(&styles->chart_series);
|
||||
lv_style_set_line_width(&styles->chart_series, LV_DPX(3));
|
||||
lv_style_set_radius(&styles->chart_series, LV_DPX(1));
|
||||
lv_style_set_size(&styles->chart_series, LV_DPX(5));
|
||||
|
||||
style_init_reset(&styles->chart_ticks);
|
||||
lv_style_set_line_width(&styles->chart_ticks, LV_DPX(1));
|
||||
lv_style_set_line_color(&styles->chart_ticks, COLOR_GRAY);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#if LV_USE_METER
|
||||
style_init_reset(&styles->meter_marker);
|
||||
lv_style_set_line_width(&styles->meter_marker, LV_DPX(5));
|
||||
@ -381,41 +379,20 @@ static void basic_init(void)
|
||||
lv_style_set_border_width(&styles->table_cell, LV_DPX(1));
|
||||
lv_style_set_border_color(&styles->table_cell, CARD_BORDER_COLOR);
|
||||
#endif
|
||||
}
|
||||
//
|
||||
//static void linemeter_init(void)
|
||||
//{
|
||||
//#if LV_USE_LINEMETER != 0
|
||||
// style_init_reset(&styles->lmeter);
|
||||
// lv_style_set_radius(&styles->lmeter, LV_STATE_DEFAULT, LV_RADIUS_CIRCLE);
|
||||
// lv_style_set_pad_left(&styles->lmeter, LV_STATE_DEFAULT, LV_DPX(20));
|
||||
// lv_style_set_pad_right(&styles->lmeter, LV_STATE_DEFAULT, LV_DPX(20));
|
||||
// lv_style_set_pad_top(&styles->lmeter, LV_STATE_DEFAULT, LV_DPX(20));
|
||||
// lv_style_set_scale_width(&styles->lmeter, LV_STATE_DEFAULT, LV_DPX(25));
|
||||
//
|
||||
// lv_style_set_line_color(&styles->lmeter, LV_STATE_DEFAULT, theme.color_primary);
|
||||
// lv_style_set_scale_grad_color(&styles->lmeter, LV_STATE_DEFAULT, theme.color_primary);
|
||||
// lv_style_set_scale_end_color(&styles->lmeter, LV_STATE_DEFAULT, lv_color_hex3(0x888));
|
||||
// lv_style_set_line_width(&styles->lmeter, LV_STATE_DEFAULT, LV_DPX(10));
|
||||
// lv_style_set_scale_end_line_width(&styles->lmeter, LV_STATE_DEFAULT, LV_DPX(7));
|
||||
//#endif
|
||||
//}
|
||||
//
|
||||
|
||||
static void textarea_init(void)
|
||||
{
|
||||
#if LV_USE_TEXTAREA
|
||||
style_init_reset(&styles->ta_cursor);
|
||||
lv_style_set_border_color(&styles->ta_cursor, LV_STATE_DEFAULT, COLOR_BG_SEC_TEXT);
|
||||
lv_style_set_border_width(&styles->ta_cursor, LV_STATE_DEFAULT, LV_DPX(2));
|
||||
lv_style_set_pad_left(&styles->ta_cursor, LV_STATE_DEFAULT, LV_DPX(1));
|
||||
lv_style_set_border_side(&styles->ta_cursor, LV_STATE_DEFAULT, LV_BORDER_SIDE_LEFT);
|
||||
lv_style_set_border_color(&styles->ta_cursor, COLOR_BG_SEC_TEXT);
|
||||
lv_style_set_border_width(&styles->ta_cursor, LV_DPX(2));
|
||||
lv_style_set_pad_left(&styles->ta_cursor, LV_DPX(1));
|
||||
lv_style_set_border_side(&styles->ta_cursor, LV_BORDER_SIDE_LEFT);
|
||||
lv_style_set_anim_time(&styles->ta_cursor, 400);
|
||||
|
||||
style_init_reset(&styles->ta_placeholder);
|
||||
lv_style_set_text_color(&styles->ta_placeholder, LV_STATE_DEFAULT,
|
||||
IS_LIGHT ? COLOR_BG_TEXT_DIS : lv_color_hex(0xa1adbd));
|
||||
lv_style_set_text_color(&styles->ta_placeholder, IS_LIGHT ? COLOR_BG_TEXT_DIS : lv_color_hex(0xa1adbd));
|
||||
#endif
|
||||
}
|
||||
|
||||
//
|
||||
//static void ddlist_init(void)
|
||||
//{
|
||||
@ -486,7 +463,6 @@ lv_theme_t * lv_theme_default_init(lv_color_t color_primary, lv_color_t color_se
|
||||
theme.flags = flags;
|
||||
|
||||
basic_init();
|
||||
textarea_init();
|
||||
|
||||
theme.apply_cb = theme_apply;
|
||||
|
||||
@ -646,25 +622,16 @@ static void theme_apply(lv_theme_t * th, lv_obj_t * obj)
|
||||
else if(lv_obj_check_type(obj, &lv_meter)) {
|
||||
lv_obj_add_style_no_refresh(obj, LV_PART_MAIN, LV_STATE_DEFAULT, &styles->card);
|
||||
lv_obj_add_style_no_refresh(obj, LV_PART_MARKER, LV_STATE_DEFAULT, &styles->meter_marker);
|
||||
lv_obj_add_style_no_refresh(obj, LV_PART_INDICATOR, LV_STATE_DEFAULT, &styles->meter_indic);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#if LV_USE_TEXTAREA
|
||||
case LV_THEME_TEXTAREA:
|
||||
list = _lv_obj_get_style_list(obj, LV_TEXTAREA_PART_MAIN);
|
||||
_lv_style_list_add_style(list, &styles->card);
|
||||
_lv_style_list_add_style(list, &styles->pad_small);
|
||||
_lv_style_list_add_style(list, &styles->sb);
|
||||
|
||||
list = _lv_obj_get_style_list(obj, LV_TEXTAREA_PART_PLACEHOLDER);
|
||||
_lv_style_list_add_style(list, &styles->ta_placeholder);
|
||||
|
||||
list = _lv_obj_get_style_list(obj, LV_TEXTAREA_PART_CURSOR);
|
||||
_lv_style_list_add_style(list, &styles->ta_cursor);
|
||||
break;
|
||||
|
||||
else if(lv_obj_check_type(obj, &lv_textarea)) {
|
||||
lv_obj_add_style_no_refresh(obj, LV_PART_MAIN, LV_STATE_DEFAULT, &styles->card);
|
||||
lv_obj_add_style_no_refresh(obj, LV_PART_SCROLLBAR, LV_STATE_DEFAULT, &styles->scrollbar);
|
||||
lv_obj_add_style_no_refresh(obj, LV_PART_SCROLLBAR, LV_STATE_SCROLLED, &styles->scrollbar_scrolled);
|
||||
lv_obj_add_style_no_refresh(obj, LV_PART_MARKER, LV_STATE_DEFAULT, &styles->ta_cursor);
|
||||
}
|
||||
#endif
|
||||
|
||||
//#if LV_USE_LINEMETER
|
||||
|
@ -13,6 +13,7 @@
|
||||
#include "../lv_core/lv_refr.h"
|
||||
#include "../lv_draw/lv_draw.h"
|
||||
#include "../lv_core/lv_disp.h"
|
||||
#include "../lv_core/lv_indev.h"
|
||||
#include "../lv_misc/lv_math.h"
|
||||
#include "../lv_themes/lv_theme.h"
|
||||
|
||||
@ -1203,7 +1204,7 @@ static void draw_cursors(lv_obj_t * obj, const lv_area_t * clip_area)
|
||||
|
||||
}
|
||||
|
||||
static void draw_y_ticks(lv_obj_t * obj, const lv_area_t * mask, lv_chart_axis_t axis)
|
||||
static void draw_y_ticks(lv_obj_t * obj, const lv_area_t * clip_area, lv_chart_axis_t axis)
|
||||
{
|
||||
lv_chart_t * chart = (lv_chart_t *)obj;
|
||||
|
||||
@ -1216,7 +1217,6 @@ static void draw_y_ticks(lv_obj_t * obj, const lv_area_t * mask, lv_chart_axis_t
|
||||
lv_coord_t x_ofs;
|
||||
lv_coord_t y_ofs = obj->coords.y1;
|
||||
lv_coord_t h = (lv_obj_get_height(obj) * chart->y_zoom) >> 8;
|
||||
char buf[LV_CHART_AXIS_TICK_LABEL_MAX_LEN + 1]; /* up to N symbols per label + null terminator */
|
||||
|
||||
/* chose correct side of the chart */
|
||||
lv_coord_t major_tick_len;
|
||||
@ -1237,6 +1237,11 @@ static void draw_y_ticks(lv_obj_t * obj, const lv_area_t * mask, lv_chart_axis_t
|
||||
minor_tick_len *= -1;
|
||||
}
|
||||
|
||||
lv_obj_draw_hook_dsc_t hook_dsc;
|
||||
lv_obj_draw_hook_dsc_init(&hook_dsc, clip_area);
|
||||
hook_dsc.id = axis;
|
||||
hook_dsc.part = LV_PART_MARKER;
|
||||
|
||||
lv_draw_line_dsc_t line_dsc;
|
||||
lv_draw_line_dsc_init(&line_dsc);
|
||||
lv_obj_init_draw_line_dsc(obj, LV_PART_MARKER, &line_dsc);
|
||||
@ -1252,8 +1257,8 @@ static void draw_y_ticks(lv_obj_t * obj, const lv_area_t * mask, lv_chart_axis_t
|
||||
/* draw a line at moving y position */
|
||||
p2.y = p1.y = y_ofs + (int32_t)((int32_t)(h - line_dsc.width) * i) / total_tick_num;
|
||||
|
||||
if(p2.y - label_dsc.font->line_height > mask->y2) return;
|
||||
if(p2.y + label_dsc.font->line_height < mask->y1) continue;
|
||||
if(p2.y - label_dsc.font->line_height > clip_area->y2) return;
|
||||
if(p2.y + label_dsc.font->line_height < clip_area->y1) continue;
|
||||
|
||||
/* first point of the tick */
|
||||
p1.x = x_ofs;
|
||||
@ -1269,15 +1274,18 @@ static void draw_y_ticks(lv_obj_t * obj, const lv_area_t * mask, lv_chart_axis_t
|
||||
if(major) p2.x = p1.x - major_tick_len; /* major tick */
|
||||
else p2.x = p1.x - minor_tick_len; /* minor tick */
|
||||
|
||||
lv_draw_line(&p1, &p2, mask, &line_dsc);
|
||||
lv_draw_line(&p1, &p2, clip_area, &line_dsc);
|
||||
|
||||
/* add text only to major tick */
|
||||
if(!major) continue;
|
||||
chart->tick_label_cb(obj, axis, i / sub_tick_cnt, buf, sizeof(buf));
|
||||
|
||||
int32_t tick_value = chart->ymax[axis] - lv_map(i, 0, total_tick_num, chart->ymin[axis], chart->ymax[axis]);
|
||||
lv_snprintf(hook_dsc.text, sizeof(hook_dsc.text), "%d", tick_value);
|
||||
lv_event_send(obj, LV_EVENT_DRAW_PART_BEGIN, &hook_dsc);
|
||||
|
||||
/* reserve appropriate area */
|
||||
lv_point_t size;
|
||||
_lv_txt_get_size(&size, buf, label_dsc.font, label_dsc.letter_space, label_dsc.line_space,
|
||||
_lv_txt_get_size(&size, hook_dsc.text, label_dsc.font, label_dsc.letter_space, label_dsc.line_space,
|
||||
LV_COORD_MAX, LV_TEXT_FLAG_CENTER);
|
||||
|
||||
/* set the area at some distance of the major tick len left of the tick */
|
||||
@ -1294,16 +1302,16 @@ static void draw_y_ticks(lv_obj_t * obj, const lv_area_t * mask, lv_chart_axis_t
|
||||
a.x2 = p2.x + size.x + label_gap;
|
||||
}
|
||||
|
||||
lv_draw_label(&a, mask, &label_dsc, buf, NULL);
|
||||
lv_draw_label(&a, clip_area, &label_dsc, hook_dsc.text, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
static void draw_x_ticks(lv_obj_t * obj, const lv_area_t * mask)
|
||||
static void draw_x_ticks(lv_obj_t * obj, const lv_area_t * clip_area)
|
||||
{
|
||||
lv_chart_t * chart = (lv_chart_t *)obj;
|
||||
|
||||
lv_area_t series_mask;
|
||||
bool mask_ret = _lv_area_intersect(&series_mask, &obj->coords, mask);
|
||||
bool mask_ret = _lv_area_intersect(&series_mask, &obj->coords, clip_area);
|
||||
if(mask_ret == false) return;
|
||||
|
||||
uint32_t i;
|
||||
@ -1324,8 +1332,8 @@ static void draw_x_ticks(lv_obj_t * obj, const lv_area_t * mask)
|
||||
lv_coord_t minor_tick_len = major_tick_len / 2;
|
||||
lv_coord_t label_gap = TICK_LABEL_GAP;
|
||||
|
||||
if(h + y_ofs > mask->y2) return;
|
||||
if(h + y_ofs + label_gap + label_dsc.font->line_height + major_tick_len < mask->y1) return;
|
||||
if(h + y_ofs > clip_area->y2) return;
|
||||
if(h + y_ofs + label_gap + label_dsc.font->line_height + major_tick_len < clip_area->y1) return;
|
||||
|
||||
lv_draw_line_dsc_t line_dsc;
|
||||
lv_draw_line_dsc_init(&line_dsc);
|
||||
@ -1333,6 +1341,12 @@ static void draw_x_ticks(lv_obj_t * obj, const lv_area_t * mask)
|
||||
line_dsc.dash_gap = 0;
|
||||
line_dsc.dash_width = 0;
|
||||
|
||||
lv_obj_draw_hook_dsc_t hook_dsc;
|
||||
lv_obj_draw_hook_dsc_init(&hook_dsc, clip_area);
|
||||
hook_dsc.id = LV_CHART_AXIS_X;
|
||||
hook_dsc.part = LV_PART_MARKER;
|
||||
|
||||
|
||||
/* The columns don't start at the most right position
|
||||
* so change the width and offset accordingly. */
|
||||
if(chart->type == LV_CHART_TYPE_COLUMN) {
|
||||
@ -1343,7 +1357,6 @@ static void draw_x_ticks(lv_obj_t * obj, const lv_area_t * mask)
|
||||
}
|
||||
|
||||
p1.y = h + y_ofs;
|
||||
char buf[LV_CHART_AXIS_TICK_LABEL_MAX_LEN + 1]; /* up to N symbols per label + null terminator */
|
||||
uint32_t total_tick_num = major_tick_cnt * sub_tick_cnt;
|
||||
for(i = 0; i <= total_tick_num; i++) { /* one extra loop - it may not exist in the list, empty label */
|
||||
bool major = false;
|
||||
@ -1354,15 +1367,17 @@ static void draw_x_ticks(lv_obj_t * obj, const lv_area_t * mask)
|
||||
if(p1.x > series_mask.x2) return;
|
||||
|
||||
p2.y = p1.y + (major ? major_tick_len : minor_tick_len);
|
||||
lv_draw_line(&p1, &p2, mask, &line_dsc);
|
||||
lv_draw_line(&p1, &p2, clip_area, &line_dsc);
|
||||
|
||||
/* add text only to major tick */
|
||||
if(!major) continue;
|
||||
chart->tick_label_cb(obj, LV_CHART_AXIS_X, i / sub_tick_cnt, buf, sizeof(buf));
|
||||
|
||||
lv_snprintf(hook_dsc.text, sizeof(hook_dsc.text), "%d", i / sub_tick_cnt);
|
||||
lv_event_send(obj, LV_EVENT_DRAW_PART_BEGIN, &hook_dsc.text);
|
||||
|
||||
/* reserve appropriate area */
|
||||
lv_point_t size;
|
||||
_lv_txt_get_size(&size, buf, label_dsc.font, label_dsc.letter_space, label_dsc.line_space,
|
||||
_lv_txt_get_size(&size, hook_dsc.text, label_dsc.font, label_dsc.letter_space, label_dsc.line_space,
|
||||
LV_COORD_MAX, LV_TEXT_FLAG_CENTER);
|
||||
|
||||
/* set the area at some distance of the major tick len under of the tick */
|
||||
@ -1371,7 +1386,7 @@ static void draw_x_ticks(lv_obj_t * obj, const lv_area_t * mask)
|
||||
a.x2 = (p2.x + size.x / 2),
|
||||
a.y1 = p2.y + label_gap;
|
||||
a.y2 = (a.y1 + size.y);
|
||||
lv_draw_label(&a, mask, &label_dsc, buf, NULL);
|
||||
lv_draw_label(&a, clip_area, &label_dsc, hook_dsc.text, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -503,10 +503,11 @@ void lv_dropdown_open(lv_obj_t * dropdown_obj)
|
||||
{
|
||||
lv_dropdown_t * dropdown = (lv_dropdown_t *) dropdown_obj;
|
||||
|
||||
lv_obj_add_state(dropdown_obj, LV_STATE_CHECKED);
|
||||
|
||||
lv_obj_clear_flag(dropdown->list, LV_OBJ_FLAG_HIDDEN);
|
||||
lv_obj_clear_flag(dropdown->list, LV_OBJ_FLAG_CLICK_FOCUSABLE);
|
||||
lv_obj_set_parent(dropdown->list, lv_obj_get_screen(dropdown_obj));
|
||||
|
||||
/*Set smaller width to the width of the button*/
|
||||
if(lv_obj_get_width(dropdown->list) <= lv_obj_get_width(dropdown_obj) &&
|
||||
(dropdown->dir == LV_DIR_TOP || dropdown->dir == LV_DIR_BOTTOM)) {
|
||||
@ -594,6 +595,7 @@ void lv_dropdown_open(lv_obj_t * dropdown_obj)
|
||||
*/
|
||||
void lv_dropdown_close(lv_obj_t * obj)
|
||||
{
|
||||
lv_obj_clear_state(obj, LV_STATE_CHECKED);
|
||||
lv_dropdown_t * dropdown = (lv_dropdown_t *) obj;
|
||||
|
||||
dropdown->pr_opt_id = LV_DROPDOWN_PR_NONE;
|
||||
@ -641,7 +643,6 @@ static void lv_dropdown_constructor(lv_obj_t * obj, lv_obj_t * parent, const lv_
|
||||
((lv_dropdown_list_t*)list_obj)->dropdown = (lv_obj_t *) dropdown;
|
||||
dropdown->list = list_obj;
|
||||
lv_obj_add_flag(dropdown->list, LV_OBJ_FLAG_HIDDEN);
|
||||
lv_obj_add_flag(obj, LV_OBJ_FLAG_CHECKABLE);
|
||||
|
||||
if(copy == NULL) {
|
||||
lv_obj_set_width(obj, LV_DPX(150));
|
||||
@ -751,6 +752,7 @@ static lv_draw_res_t lv_dropdown_draw(lv_obj_t * obj, const lv_area_t * clip_are
|
||||
symbol_area.x1 = obj->coords.x2 - right - symbol_w;
|
||||
symbol_area.x2 = symbol_area.x1 + symbol_w - 1;
|
||||
}
|
||||
|
||||
if(symbol_type == LV_IMG_SRC_SYMBOL) {
|
||||
lv_draw_label(&symbol_area, clip_area, &label_dsc, dropdown->symbol, NULL);
|
||||
} else {
|
||||
@ -762,47 +764,31 @@ static lv_draw_res_t lv_dropdown_draw(lv_obj_t * obj, const lv_area_t * clip_are
|
||||
img_dsc.angle = lv_obj_get_style_transform_angle(obj, LV_PART_MAIN);
|
||||
lv_draw_img(&symbol_area, clip_area, dropdown->symbol, &img_dsc);
|
||||
}
|
||||
}
|
||||
|
||||
// txt = rev ? dropdown->symbol : opt_txt;
|
||||
// if(txt) {
|
||||
// _lv_txt_get_size(&txt_size, txt, label_dsc.font, label_dsc.letter_space, label_dsc.line_space, LV_COORD_MAX,
|
||||
// label_dsc.flag);
|
||||
//
|
||||
// txt_area.y1 = obj->coords.y1 + top;
|
||||
// txt_area.y2 = txt_area.y1 + txt_size.y;
|
||||
//
|
||||
// /*Center align the text if no symbol*/
|
||||
// if(dropdown->symbol == NULL && txt == opt_txt) {
|
||||
// txt_area.x1 = obj->coords.x1 + (lv_obj_get_width(obj) - txt_size.x) / 2;
|
||||
// txt_area.x2 = txt_area.x1 + txt_size.x;
|
||||
// }
|
||||
// else {
|
||||
// txt_area.x1 = obj->coords.x1 + left;
|
||||
// txt_area.x2 = txt_area.x1 + txt_size.x;
|
||||
// }
|
||||
// lv_draw_label(&txt_area, clip_area, &label_dsc, txt, NULL);
|
||||
// }
|
||||
//
|
||||
// txt = rev ? opt_txt : dropdown->symbol;
|
||||
// if(txt) {
|
||||
// _lv_txt_get_size(&txt_size, txt, label_dsc.font, label_dsc.letter_space, label_dsc.line_space, LV_COORD_MAX,
|
||||
// label_dsc.flag);
|
||||
// txt_area.y1 = obj->coords.y1 + top;
|
||||
// txt_area.y2 = txt_area.y1 + txt_size.y;
|
||||
//
|
||||
// /*Center align the text if no symbol*/
|
||||
// if(dropdown->symbol == NULL && txt == opt_txt) {
|
||||
// txt_area.x1 = obj->coords.x1 + (lv_obj_get_width(obj) - txt_size.x) / 2;
|
||||
// txt_area.x2 = txt_area.x1 + txt_size.x;
|
||||
// }
|
||||
// else {
|
||||
// txt_area.x1 = obj->coords.x2 - right - txt_size.x;
|
||||
// txt_area.x2 = txt_area.x1 + txt_size.x;
|
||||
// }
|
||||
//
|
||||
// lv_draw_label(&txt_area, clip_area, &label_dsc, txt, NULL);
|
||||
// }
|
||||
lv_point_t size;
|
||||
_lv_txt_get_size(&size, opt_txt, label_dsc.font, label_dsc.letter_space, label_dsc.line_space, LV_COORD_MAX,
|
||||
label_dsc.flag);
|
||||
|
||||
lv_area_t txt_area;
|
||||
txt_area.y1 = obj->coords.y1 + top;
|
||||
txt_area.y2 = txt_area.y1 + size.y;
|
||||
/*Center align the text if no symbol*/
|
||||
if(dropdown->symbol == NULL) {
|
||||
txt_area.x1 = obj->coords.x1 + (lv_obj_get_width(obj) - size.x) / 2;
|
||||
txt_area.x2 = txt_area.x1 + size.x;
|
||||
}
|
||||
else {
|
||||
/*Text to the right*/
|
||||
if(symbol_to_left) {
|
||||
txt_area.x1 = obj->coords.x2 - right - size.x;
|
||||
txt_area.x2 = txt_area.x1 + size.x;
|
||||
} else {
|
||||
txt_area.x1 = obj->coords.x1 + left;
|
||||
txt_area.x2 = txt_area.x1 + size.x;
|
||||
}
|
||||
}
|
||||
lv_draw_label(&txt_area, clip_area, &label_dsc, opt_txt, NULL);
|
||||
}
|
||||
|
||||
if(dropdown->text == NULL) {
|
||||
lv_mem_buf_release((char *)opt_txt);
|
||||
|
@ -164,13 +164,6 @@ char * lv_label_get_text(const lv_obj_t * label);
|
||||
*/
|
||||
lv_label_long_mode_t lv_label_get_long_mode(const lv_obj_t * label);
|
||||
|
||||
/**
|
||||
* Get the align attribute
|
||||
* @param label pointer to a label object
|
||||
* @return LV_TEXT_ALIGN_LEFT or LV_TEXT_ALIGN_CENTER
|
||||
*/
|
||||
lv_text_align_t lv_label_get_align(const lv_obj_t * label);
|
||||
|
||||
/**
|
||||
* Get the recoloring attribute
|
||||
* @param label pointer to a label object
|
||||
|
@ -476,6 +476,10 @@ static void draw_lines_and_labels(lv_obj_t * obj, const lv_area_t * clip_area, c
|
||||
lv_draw_label_dsc_init(&label_dsc);
|
||||
lv_obj_init_draw_label_dsc(obj, LV_PART_MARKER, &label_dsc);
|
||||
|
||||
lv_obj_draw_hook_dsc_t hook_dsc;
|
||||
lv_obj_draw_hook_dsc_init(&hook_dsc, clip_area);
|
||||
hook_dsc.part = LV_PART_MARKER;
|
||||
|
||||
uint32_t sub_cnt = meter->marker_nth - 1;
|
||||
lv_opa_t opa_main = lv_obj_get_style_opa(obj, LV_PART_MAIN);
|
||||
bool marker;
|
||||
@ -564,11 +568,11 @@ static void draw_lines_and_labels(lv_obj_t * obj, const lv_area_t * clip_area, c
|
||||
p.x = (int32_t)(((int32_t)cos_mid * r_text + 127) >> (LV_TRIGO_SHIFT)) + scale_center.y;
|
||||
p.y = (int32_t)(((int32_t)sin_mid * r_text + 127) >> (LV_TRIGO_SHIFT)) + scale_center.x;
|
||||
|
||||
char buf[32];
|
||||
lv_snprintf(buf, sizeof(buf), "%d", value_of_line);
|
||||
lv_snprintf(hook_dsc.text, sizeof(hook_dsc.text), "%d", value_of_line);
|
||||
lv_event_send(obj, LV_EVENT_DRAW_PART_BEGIN, &hook_dsc);
|
||||
|
||||
lv_point_t label_size;
|
||||
_lv_txt_get_size(&label_size, buf, label_dsc.font, label_dsc.letter_space, label_dsc.line_space,
|
||||
_lv_txt_get_size(&label_size, hook_dsc.text, label_dsc.font, label_dsc.letter_space, label_dsc.line_space,
|
||||
LV_COORD_MAX, LV_TEXT_FLAG_NONE);
|
||||
|
||||
lv_area_t label_cord;
|
||||
@ -577,7 +581,7 @@ static void draw_lines_and_labels(lv_obj_t * obj, const lv_area_t * clip_area, c
|
||||
label_cord.x2 = label_cord.x1 + label_size.x;
|
||||
label_cord.y2 = label_cord.y1 + label_size.y;
|
||||
|
||||
lv_draw_label(&label_cord, clip_area, &label_dsc, buf, NULL);
|
||||
lv_draw_label(&label_cord, clip_area, &label_dsc, hook_dsc.text, NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -35,14 +35,21 @@
|
||||
* STATIC PROTOTYPES
|
||||
**********************/
|
||||
static void lv_switch_constructor(lv_obj_t * obj, lv_obj_t * parent, const lv_obj_t * copy);
|
||||
static void lv_switch_destructor(void * obj);
|
||||
static void lv_switch_destructor(lv_obj_t * obj);
|
||||
static lv_res_t lv_switch_signal(lv_obj_t * obj, lv_signal_t sign, void * param);
|
||||
static lv_draw_res_t lv_switch_draw(lv_obj_t * sw, const lv_area_t * clip_area, lv_draw_mode_t mode);
|
||||
|
||||
/**********************
|
||||
* STATIC VARIABLES
|
||||
**********************/
|
||||
lv_switch_class_t lv_switch;
|
||||
const lv_obj_class_t lv_switch = {
|
||||
.constructor = lv_switch_constructor,
|
||||
.destructor = lv_switch_destructor,
|
||||
.signal_cb = lv_switch_signal,
|
||||
.draw_cb = lv_switch_draw,
|
||||
.instance_size = sizeof(lv_switch_t),
|
||||
.base_class = &lv_obj
|
||||
};
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
@ -61,23 +68,9 @@ lv_switch_class_t lv_switch;
|
||||
*/
|
||||
lv_obj_t * lv_switch_create(lv_obj_t * parent, const lv_obj_t * copy)
|
||||
{
|
||||
if(!lv_switch._inited) {
|
||||
LV_CLASS_INIT(lv_switch, lv_obj);
|
||||
lv_switch.constructor = lv_switch_constructor;
|
||||
lv_switch.destructor = lv_switch_destructor;
|
||||
lv_switch.draw_cb = lv_switch_draw;
|
||||
lv_switch.signal_cb = lv_switch_signal;
|
||||
}
|
||||
|
||||
lv_obj_t * obj = lv_class_new(&lv_switch);
|
||||
lv_switch.constructor(obj, parent, copy);
|
||||
|
||||
lv_obj_create_finish(obj, parent, copy);
|
||||
|
||||
return obj;
|
||||
return lv_obj_create_from_class(&lv_switch, parent, copy);
|
||||
}
|
||||
|
||||
|
||||
/**********************
|
||||
* STATIC FUNCTIONS
|
||||
**********************/
|
||||
@ -86,10 +79,7 @@ static void lv_switch_constructor(lv_obj_t * obj, lv_obj_t * parent, const lv_ob
|
||||
{
|
||||
LV_LOG_TRACE("switch create started");
|
||||
|
||||
LV_CLASS_CONSTRUCTOR_BEGIN(obj, lv_switch)
|
||||
lv_switch.base_p->constructor(obj, parent, copy);
|
||||
|
||||
lv_switch_t * sw = (lv_switch_t *) obj;
|
||||
lv_obj_construct_base(obj, parent, copy);
|
||||
|
||||
if(copy == NULL) {
|
||||
lv_obj_clear_flag(obj, LV_OBJ_FLAG_SCROLLABLE);
|
||||
@ -97,11 +87,10 @@ static void lv_switch_constructor(lv_obj_t * obj, lv_obj_t * parent, const lv_ob
|
||||
lv_obj_set_size(obj, LV_DPX(60), LV_DPX(35));
|
||||
}
|
||||
|
||||
LV_CLASS_CONSTRUCTOR_END(obj, lv_switch)
|
||||
LV_LOG_INFO("switch created");
|
||||
}
|
||||
|
||||
static void lv_switch_destructor(void * obj)
|
||||
static void lv_switch_destructor(lv_obj_t * obj)
|
||||
{
|
||||
// lv_bar_t * bar = obj;
|
||||
//
|
||||
@ -124,19 +113,16 @@ static void lv_switch_destructor(void * obj)
|
||||
static lv_draw_res_t lv_switch_draw(lv_obj_t * obj, const lv_area_t * clip_area, lv_draw_mode_t mode)
|
||||
{
|
||||
/*Return false if the object is not covers the mask_p area*/
|
||||
if(mode == LV_DRAW_COVER_CHK) {
|
||||
if(mode == LV_DRAW_MODE_COVER_CHECK) {
|
||||
return LV_DRAW_RES_NOT_COVER;
|
||||
}
|
||||
/*Draw the object*/
|
||||
else if(mode == LV_DRAW_DRAW_MAIN) {
|
||||
|
||||
else if(mode == LV_DRAW_MODE_MAIN_DRAW) {
|
||||
/*The ancestor draw function will draw the background.*/
|
||||
lv_switch.base_p->draw_cb(obj, clip_area, mode);
|
||||
lv_obj.draw_cb(obj, clip_area, mode);
|
||||
|
||||
lv_bidi_dir_t base_dir = lv_obj_get_base_dir(obj);
|
||||
|
||||
lv_switch_t * sw = (lv_switch_t *)obj;
|
||||
|
||||
/*Calculate the indicator area*/
|
||||
lv_coord_t bg_left = lv_obj_get_style_pad_left(obj, LV_PART_MAIN);
|
||||
lv_coord_t bg_right = lv_obj_get_style_pad_right(obj, LV_PART_MAIN);
|
||||
@ -148,7 +134,7 @@ static lv_draw_res_t lv_switch_draw(lv_obj_t * obj, const lv_area_t * clip_area,
|
||||
if(chk) {
|
||||
/*Respect the background's padding*/
|
||||
lv_area_t indic_area;
|
||||
lv_area_copy(&indic_area, &sw->coords);
|
||||
lv_area_copy(&indic_area, &obj->coords);
|
||||
indic_area.x1 += bg_left;
|
||||
indic_area.x2 -= bg_right;
|
||||
indic_area.y1 += bg_top;
|
||||
@ -167,16 +153,16 @@ static lv_draw_res_t lv_switch_draw(lv_obj_t * obj, const lv_area_t * clip_area,
|
||||
|
||||
/*Left*/
|
||||
if((base_dir != LV_BIDI_DIR_RTL && !chk) || (base_dir == LV_BIDI_DIR_RTL && chk)) {
|
||||
knob_area.x1 = sw->coords.x1 + bg_left;
|
||||
knob_area.x1 = obj->coords.x1 + bg_left;
|
||||
knob_area.x2 = knob_area.x1 + knob_size;
|
||||
}
|
||||
else {
|
||||
knob_area.x2 = sw->coords.x2 - bg_right;
|
||||
knob_area.x2 = obj->coords.x2 - bg_right;
|
||||
knob_area.x1 = knob_area.x2 - knob_size;
|
||||
}
|
||||
|
||||
knob_area.y1 = sw->coords.y1 + bg_top;
|
||||
knob_area.y2 = sw->coords.y2 - bg_bottom;
|
||||
knob_area.y1 = obj->coords.y1 + bg_top;
|
||||
knob_area.y2 = obj->coords.y2 - bg_bottom;
|
||||
|
||||
lv_coord_t knob_left = lv_obj_get_style_pad_left(obj, LV_PART_KNOB);
|
||||
lv_coord_t knob_right = lv_obj_get_style_pad_right(obj, LV_PART_KNOB);
|
||||
@ -197,8 +183,8 @@ static lv_draw_res_t lv_switch_draw(lv_obj_t * obj, const lv_area_t * clip_area,
|
||||
|
||||
}
|
||||
/*Post draw when the children are drawn*/
|
||||
else if(mode == LV_DRAW_DRAW_POST) {
|
||||
return lv_switch.base_p->draw_cb(obj, clip_area, mode);
|
||||
else if(mode == LV_DRAW_MODE_POST_DRAW) {
|
||||
return lv_obj.draw_cb(obj, clip_area, mode);
|
||||
}
|
||||
|
||||
return LV_DRAW_RES_OK;
|
||||
@ -217,7 +203,7 @@ static lv_res_t lv_switch_signal(lv_obj_t * obj, lv_signal_t sign, void * param)
|
||||
lv_res_t res;
|
||||
|
||||
/* Include the ancient signal function */
|
||||
res = lv_switch.base_p->signal_cb(obj, sign, param);
|
||||
res = lv_obj.signal_cb(obj, sign, param);
|
||||
if(res != LV_RES_OK) return res;
|
||||
|
||||
|
||||
|
@ -32,19 +32,12 @@ extern "C" {
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
|
||||
LV_CLASS_DECLARE_START(lv_switch, lv_obj);
|
||||
typedef struct {
|
||||
lv_obj_t obj;
|
||||
}lv_switch_t;
|
||||
|
||||
#define _lv_switch_constructor void (*constructor)(struct _lv_obj_t * obj, struct _lv_obj_t * parent, const struct _lv_obj_t * copy)
|
||||
|
||||
#define _lv_switch_data \
|
||||
_lv_obj_data
|
||||
|
||||
#define _lv_switch_class_dsc \
|
||||
_lv_obj_class_dsc \
|
||||
|
||||
LV_CLASS_DECLARE_END(lv_switch, lv_obj);
|
||||
|
||||
extern lv_switch_class_t lv_switch;
|
||||
extern const lv_obj_class_t lv_switch;
|
||||
|
||||
/**********************
|
||||
* GLOBAL PROTOTYPES
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -38,25 +38,21 @@ LV_EXPORT_CONST_INT(LV_TEXTAREA_CURSOR_LAST);
|
||||
|
||||
/*Data of text area*/
|
||||
typedef struct {
|
||||
/*New data for this type */
|
||||
lv_obj_t obj;
|
||||
lv_obj_t * label; /*Label of the text area*/
|
||||
char * placeholder_txt; /*Place holder label. only visible if text is an empty string*/
|
||||
lv_style_list_t style_placeholder;
|
||||
char * pwd_tmp; /*Used to store the original text in password mode*/
|
||||
const char * accepted_chars; /*Only these characters will be accepted. NULL: accept all*/
|
||||
uint32_t max_length; /*The max. number of characters. 0: no limit*/
|
||||
uint16_t pwd_show_time; /*Time to show characters in password mode before change them to '*' */
|
||||
struct {
|
||||
lv_style_list_t style; /* Style of the cursor (NULL to use label's style)*/
|
||||
lv_coord_t valid_x; /* Used when stepping up/down to a shorter line.
|
||||
* (Used by the library)*/
|
||||
uint32_t pos; /* The current cursor position
|
||||
* (0: before 1st letter; 1: before 2nd letter ...)*/
|
||||
uint16_t blink_time; /*Blink period*/
|
||||
lv_area_t area; /* Cursor area relative to the Text Area*/
|
||||
uint32_t txt_byte_pos; /* Byte index of the letter after (on) the cursor*/
|
||||
uint8_t state : 1; /*Cursor is visible now or not (Handled by the library)*/
|
||||
uint8_t hidden : 1; /*Cursor is hidden by he user */
|
||||
uint8_t show : 1; /*Cursor is visible now or not (Handled by the library)*/
|
||||
uint8_t click_pos : 1; /*1: Enable positioning the cursor by clicking the text area*/
|
||||
} cursor;
|
||||
#if LV_LABEL_TEXT_SEL
|
||||
@ -67,17 +63,9 @@ typedef struct {
|
||||
#endif
|
||||
uint8_t pwd_mode : 1; /*Replace characters with '*' */
|
||||
uint8_t one_line : 1; /*One line mode (ignore line breaks)*/
|
||||
} lv_textarea_ext_t;
|
||||
} lv_textarea_t;
|
||||
|
||||
/** Possible text areas styles. */
|
||||
enum {
|
||||
LV_TEXTAREA_PART_MAIN, /**< Text area background style */
|
||||
LV_TEXTAREA_PART_CURSOR, /**< Cursor style */
|
||||
LV_TEXTAREA_PART_PLACEHOLDER, /**< Placeholder style */
|
||||
_LV_TEXTAREA_PART_VIRTUAL_LAST,
|
||||
};
|
||||
|
||||
typedef uint8_t lv_textarea_style_t;
|
||||
extern const lv_obj_class_t lv_textarea;
|
||||
|
||||
/**********************
|
||||
* GLOBAL PROTOTYPES
|
||||
@ -177,15 +165,6 @@ void lv_textarea_set_pwd_mode(lv_obj_t * ta, bool en);
|
||||
*/
|
||||
void lv_textarea_set_one_line(lv_obj_t * ta, bool en);
|
||||
|
||||
/**
|
||||
* Set the alignment of the text area.
|
||||
* In one line mode the text can be scrolled only with `LV_TEXT_ALIGN_LEFT`.
|
||||
* This function should be called if the size of text area changes.
|
||||
* @param ta pointer to a text are object
|
||||
* @param align the desired alignment from `lv_text_align_t`. (LV_TEXT_ALIGN_LEFT/CENTER/RIGHT)
|
||||
*/
|
||||
void lv_textarea_set_text_align(lv_obj_t * ta, lv_text_align_t align);
|
||||
|
||||
/**
|
||||
* Set a list of characters. Only these characters will be accepted by the text area
|
||||
* @param ta pointer to Text Area
|
||||
@ -224,13 +203,6 @@ void lv_textarea_set_text_sel(lv_obj_t * ta, bool en);
|
||||
*/
|
||||
void lv_textarea_set_pwd_show_time(lv_obj_t * ta, uint16_t time);
|
||||
|
||||
/**
|
||||
* Set cursor blink animation time
|
||||
* @param ta pointer to Text area
|
||||
* @param time blink period. 0: disable blinking
|
||||
*/
|
||||
void lv_textarea_set_cursor_blink_time(lv_obj_t * ta, uint16_t time);
|
||||
|
||||
/*=====================
|
||||
* Getter functions
|
||||
*====================*/
|
||||
@ -326,13 +298,6 @@ bool lv_textarea_get_text_sel_en(lv_obj_t * ta);
|
||||
*/
|
||||
uint16_t lv_textarea_get_pwd_show_time(lv_obj_t * ta);
|
||||
|
||||
/**
|
||||
* Set cursor blink animation time
|
||||
* @param ta pointer to Text area
|
||||
* @return time blink period. 0: disable blinking
|
||||
*/
|
||||
uint16_t lv_textarea_get_cursor_blink_time(lv_obj_t * ta);
|
||||
|
||||
/*=====================
|
||||
* Other functions
|
||||
*====================*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user