1
0
mirror of https://github.com/lvgl/lvgl.git synced 2025-01-14 06:42:58 +08:00

rwork and update widgets

This commit is contained in:
Gabor Kiss-Vamosi 2021-01-12 19:22:38 +01:00
parent 04aa8de0f3
commit 09ffbb80e7
31 changed files with 2555 additions and 3297 deletions

1
lvgl.h
View File

@ -61,6 +61,7 @@ extern "C" {
#include "src/lv_widgets/lv_canvas.h"
#include "src/lv_widgets/lv_objmask.h"
#include "src/lv_widgets/lv_gauge.h"
#include "src/lv_widgets/lv_linemeter.h"
#include "src/lv_widgets/lv_switch.h"
#include "src/lv_widgets/lv_arc.h"

View File

@ -236,6 +236,20 @@ lv_obj_t * lv_obj_create_from_class(const lv_obj_class_t * class, lv_obj_t * par
return obj;
}
void lv_obj_construct_base(lv_obj_t * obj, lv_obj_t * parent, const lv_obj_t * copy)
{
const lv_obj_class_t * original_class_p = obj->class_p;
/*Don't let the descendant methods to run during constructing the ancestor type*/
obj->class_p = obj->class_p->base_class;
obj->class_p->constructor(obj, parent, copy);
/*Restore the original class*/
obj->class_p = original_class_p;
}
/**
* Delete 'obj' and all of its children
* @param obj pointer to an object to delete
@ -1404,8 +1418,6 @@ static void obj_del_core(lv_obj_t * obj)
static void lv_obj_constructor(lv_obj_t * obj, lv_obj_t * parent, const lv_obj_t * copy)
{
LV_CLASS_CONSTRUCTOR_BEGIN(obj, lv_obj)
/*Create a screen*/
if(parent == NULL) {
LV_LOG_TRACE("Screen create started");
@ -1514,8 +1526,6 @@ static void lv_obj_constructor(lv_obj_t * obj, lv_obj_t * parent, const lv_obj_t
lv_obj_invalidate(obj);
}
LV_CLASS_CONSTRUCTOR_END(obj, lv_obj)
LV_LOG_INFO("Object create ready");
}

View File

@ -266,11 +266,11 @@ enum {
LV_PART_CONTENT,
LV_PART_INDICATOR,
LV_PART_KNOB,
LV_PART_HIGHLIGHT,
LV_PART_HIGHLIGHT, //selected?
LV_PART_PLACEHOLDER,
LV_PART_CURSOR,
LV_PART_ITEMS,
LV_PART_MARKER,
LV_PART_CURSOR, //combine with marker?
LV_PART_CUSTOM_1,
LV_PART_CUSTOM_2,
@ -330,10 +330,9 @@ void lv_deinit(void);
*/
lv_obj_t * lv_obj_create(lv_obj_t * parent, const lv_obj_t * copy);
void lv_obj_create_finish(lv_obj_t * obj, lv_obj_t * parent, const lv_obj_t * copy);
lv_obj_t * lv_obj_create_from_class(const lv_obj_class_t * class, lv_obj_t * parent, const lv_obj_t * copy);
void lv_obj_construct_base(lv_obj_t * obj, lv_obj_t * parent, const lv_obj_t * copy);
/**
* Delete 'obj' and all of its children
* @param obj pointer to an object to delete

View File

@ -215,9 +215,24 @@ void lv_obj_init_draw_label_dsc(lv_obj_t * obj, uint8_t part, lv_draw_label_dsc_
draw_dsc->font = lv_obj_get_style_text_font(obj, part);
#if LV_USE_BIDI
#if LV_USE_BIDI == 0
draw_dsc->bidi_dir = lv_obj_get_base_dir(obj);
#endif
lv_text_align_t align = lv_obj_get_style_text_align(obj, part);
switch (align) {
case LV_TEXT_ALIGN_CENTER:
draw_dsc->flag |= LV_TEXT_FLAG_CENTER;
break;
case LV_TEXT_ALIGN_RIGHT:
draw_dsc->flag |= LV_TEXT_FLAG_RIGHT;
break;
case LV_TEXT_ALIGN_AUTO:
draw_dsc->flag |= draw_dsc->bidi_dir == LV_BIDI_DIR_RTL ? LV_TEXT_FLAG_RIGHT : LV_TEXT_FLAG_CENTER;
break;
}
}
/**

View File

@ -602,58 +602,59 @@ void _lv_obj_create_style_transition(lv_obj_t * obj, lv_style_prop_t prop, uint8
*/
_lv_style_state_cmp_t _lv_obj_style_state_compare(lv_obj_t * obj, lv_state_t state1, lv_state_t state2)
{
return _LV_STYLE_STATE_CMP_DIFF_LAYOUT;
lv_obj_style_list_t * list = &obj->style_list;
_lv_style_state_cmp_t res = _LV_STYLE_STATE_CMP_SAME;
/*Are there any new styles for the new state?*/
uint32_t i;
// for(i = 0; i < list->style_cnt; i++) {
// if(list->styles[i].is_trans) continue;
//
// /*The style is valid for a stat but not the other*/
// bool valid1 = list->styles[i].state & (~state1) ? false : true;
// bool valid2 = list->styles[i].state & (~state2) ? false : true;
// if(valid1 != valid2) {
// lv_style_t * style = list->styles[i].style;
//
// /*If there is layout difference on the main part, return immediately. There is no more serious difference*/
// _lv_style_state_cmp_t res_tmp = res;
// if(style->pad_bottom || (style->ext && style->ext->has.pad_bottom)) res_tmp = _LV_STYLE_STATE_CMP_DIFF_LAYOUT;
// else if(style->pad_top || (style->ext && style->ext->has.pad_bottom)) res_tmp = _LV_STYLE_STATE_CMP_DIFF_LAYOUT;
// else if(style->pad_left || (style->ext && style->ext->has.pad_bottom)) res_tmp = _LV_STYLE_STATE_CMP_DIFF_LAYOUT;
// else if(style->pad_right || (style->ext && style->ext->has.pad_bottom)) res_tmp = _LV_STYLE_STATE_CMP_DIFF_LAYOUT;
//
// if(res_tmp == _LV_STYLE_STATE_CMP_DIFF_LAYOUT) {
// if(list->styles[i].part == LV_PART_MAIN) return _LV_STYLE_STATE_CMP_DIFF_LAYOUT;
// else {
// res = _LV_STYLE_STATE_CMP_DIFF_DRAW_PAD;
// continue;
// }
// }
//
// /*Check for draw pad changes*/
// if(style->ext && style->ext->has.transform_width) res = _LV_STYLE_STATE_CMP_DIFF_DRAW_PAD;
// else if(style->transform_width || (style->ext && style->ext->has.transform_height)) res = _LV_STYLE_STATE_CMP_DIFF_DRAW_PAD;
// else if(style->ext && style->ext->has.transform_angle) res = _LV_STYLE_STATE_CMP_DIFF_DRAW_PAD;
// else if(style->ext && style->ext->has.transform_zoom) res = _LV_STYLE_STATE_CMP_DIFF_DRAW_PAD;
// else if(style->outline_opa || (style->ext && style->ext->has.outline_opa)) res = _LV_STYLE_STATE_CMP_DIFF_DRAW_PAD;
// else if(style->outline_pad || (style->ext && style->ext->has.outline_pad)) res = _LV_STYLE_STATE_CMP_DIFF_DRAW_PAD;
// else if(style->shadow_width|| (style->ext && style->ext->has.shadow_width)) res = _LV_STYLE_STATE_CMP_DIFF_DRAW_PAD;
// else if(style->shadow_opa|| (style->ext && style->ext->has.shadow_opa)) res = _LV_STYLE_STATE_CMP_DIFF_DRAW_PAD;
// else if(style->ext && style->ext->has.shadow_ofs_x) res = _LV_STYLE_STATE_CMP_DIFF_DRAW_PAD;
// else if(style->ext && style->ext->has.shadow_ofs_y) res = _LV_STYLE_STATE_CMP_DIFF_DRAW_PAD;
// else if(style->ext && style->ext->has.shadow_spread) res = _LV_STYLE_STATE_CMP_DIFF_DRAW_PAD;
// else if(style->line_width || (style->ext && style->ext->has.line_width)) res = _LV_STYLE_STATE_CMP_DIFF_DRAW_PAD;
// else if(style->ext && style->ext->has.content_src) res = _LV_STYLE_STATE_CMP_DIFF_DRAW_PAD;
// else if(style->ext && style->ext->has.content_ofs_x) res = _LV_STYLE_STATE_CMP_DIFF_DRAW_PAD;
// else if(style->ext && style->ext->has.content_ofs_y) res = _LV_STYLE_STATE_CMP_DIFF_DRAW_PAD;
// else if(style->ext && style->ext->has.content_align) res = _LV_STYLE_STATE_CMP_DIFF_DRAW_PAD;
// else {
// if(res != _LV_STYLE_STATE_CMP_DIFF_DRAW_PAD) res = _LV_STYLE_STATE_CMP_DIFF_REDRAW;
// }
// }
// }
for(i = 0; i < list->style_cnt; i++) {
if(list->styles[i].is_trans) continue;
/*The style is valid for a stat but not the other*/
bool valid1 = list->styles[i].state & (~state1) ? false : true;
bool valid2 = list->styles[i].state & (~state2) ? false : true;
if(valid1 != valid2) {
lv_style_t * style = list->styles[i].style;
lv_style_value_t v;
/*If there is layout difference on the main part, return immediately. There is no more serious difference*/
_lv_style_state_cmp_t res_tmp = res;
if(lv_style_get_prop(style, LV_STYLE_PAD_TOP, &v)) res_tmp = _LV_STYLE_STATE_CMP_DIFF_LAYOUT;
else if(lv_style_get_prop(style, LV_STYLE_PAD_BOTTOM, &v)) res_tmp = _LV_STYLE_STATE_CMP_DIFF_LAYOUT;
else if(lv_style_get_prop(style, LV_STYLE_PAD_LEFT, &v)) res_tmp = _LV_STYLE_STATE_CMP_DIFF_LAYOUT;
else if(lv_style_get_prop(style, LV_STYLE_PAD_RIGHT, &v)) res_tmp = _LV_STYLE_STATE_CMP_DIFF_LAYOUT;
else if(lv_style_get_prop(style, LV_STYLE_PAD_COLUMN, &v)) res_tmp = _LV_STYLE_STATE_CMP_DIFF_LAYOUT;
else if(lv_style_get_prop(style, LV_STYLE_PAD_ROW, &v)) res_tmp = _LV_STYLE_STATE_CMP_DIFF_LAYOUT;
if(res_tmp == _LV_STYLE_STATE_CMP_DIFF_LAYOUT) {
if(list->styles[i].part == LV_PART_MAIN) return _LV_STYLE_STATE_CMP_DIFF_LAYOUT;
else {
res = _LV_STYLE_STATE_CMP_DIFF_DRAW_PAD;
continue;
}
}
/*Check for draw pad changes*/
if(lv_style_get_prop(style, LV_STYLE_TRANSFORM_WIDTH, &v)) res = _LV_STYLE_STATE_CMP_DIFF_DRAW_PAD;
else if(lv_style_get_prop(style, LV_STYLE_TRANSFORM_HEIGHT, &v)) res = _LV_STYLE_STATE_CMP_DIFF_DRAW_PAD;
else if(lv_style_get_prop(style, LV_STYLE_TRANSFORM_ANGLE, &v)) res = _LV_STYLE_STATE_CMP_DIFF_DRAW_PAD;
else if(lv_style_get_prop(style, LV_STYLE_TRANSFORM_ZOOM, &v)) res = _LV_STYLE_STATE_CMP_DIFF_DRAW_PAD;
else if(lv_style_get_prop(style, LV_STYLE_OUTLINE_OPA, &v)) res = _LV_STYLE_STATE_CMP_DIFF_DRAW_PAD;
else if(lv_style_get_prop(style, LV_STYLE_OUTLINE_PAD, &v)) res = _LV_STYLE_STATE_CMP_DIFF_DRAW_PAD;
else if(lv_style_get_prop(style, LV_STYLE_SHADOW_WIDTH, &v)) res = _LV_STYLE_STATE_CMP_DIFF_DRAW_PAD;
else if(lv_style_get_prop(style, LV_STYLE_SHADOW_OPA, &v)) res = _LV_STYLE_STATE_CMP_DIFF_DRAW_PAD;
else if(lv_style_get_prop(style, LV_STYLE_SHADOW_OFS_X, &v)) res = _LV_STYLE_STATE_CMP_DIFF_DRAW_PAD;
else if(lv_style_get_prop(style, LV_STYLE_SHADOW_OFS_Y, &v)) res = _LV_STYLE_STATE_CMP_DIFF_DRAW_PAD;
else if(lv_style_get_prop(style, LV_STYLE_SHADOW_SPREAD, &v)) res = _LV_STYLE_STATE_CMP_DIFF_DRAW_PAD;
else if(lv_style_get_prop(style, LV_STYLE_LINE_WIDTH, &v)) res = _LV_STYLE_STATE_CMP_DIFF_DRAW_PAD;
else if(lv_style_get_prop(style, LV_STYLE_CONTENT_SRC, &v)) res = _LV_STYLE_STATE_CMP_DIFF_DRAW_PAD;
else if(lv_style_get_prop(style, LV_STYLE_CONTENT_OFS_X, &v)) res = _LV_STYLE_STATE_CMP_DIFF_DRAW_PAD;
else if(lv_style_get_prop(style, LV_STYLE_CONTENT_OFS_Y, &v)) res = _LV_STYLE_STATE_CMP_DIFF_DRAW_PAD;
else if(lv_style_get_prop(style, LV_STYLE_CONTENT_ALIGN, &v)) res = _LV_STYLE_STATE_CMP_DIFF_DRAW_PAD;
else {
if(res != _LV_STYLE_STATE_CMP_DIFF_DRAW_PAD) res = _LV_STYLE_STATE_CMP_DIFF_REDRAW;
}
}
}
return res;
}
@ -1106,9 +1107,6 @@ static void trans_anim_cb(lv_style_trans_t * tr, lv_anim_value_t v)
refr = false;
}
}
if(tr->prop == LV_STYLE_TRANSFORM_HEIGHT) {
printf("set\n");
}
lv_style_set_prop(list->styles[i].style, tr->prop, value_final);
if (refr) _lv_obj_refresh_style(tr->obj, tr->prop);
break;
@ -1135,9 +1133,6 @@ static void trans_anim_start_cb(lv_anim_t * a)
lv_obj_style_t * style_trans = _get_trans_style(tr->obj, tr->part);
lv_style_set_prop(style_trans->style, tr->prop, tr->start_value); /*Be sure `trans_style` has a valid value */
if(tr->prop == LV_STYLE_TRANSFORM_HEIGHT) {
printf("start\n");
}
}
static void trans_anim_ready_cb(lv_anim_t * a)

View File

@ -77,6 +77,7 @@ enum {
LV_TEXT_ALIGN_LEFT, /**< Align text to left */
LV_TEXT_ALIGN_CENTER, /**< Align text to center */
LV_TEXT_ALIGN_RIGHT, /**< Align text to right */
LV_TEXT_ALIGN_AUTO, /**< */
};
typedef uint8_t lv_text_align_t;
@ -260,6 +261,9 @@ bool lv_style_remove_prop(lv_style_t * style, lv_style_prop_t prop);
static inline void lv_style_set_radius(lv_style_t * style, lv_coord_t value) {
lv_style_value_t v = {.num = value}; lv_style_set_prop(style, LV_STYLE_RADIUS, v); }
static inline void lv_style_set_anim_time(lv_style_t * style, lv_coord_t value) {
lv_style_value_t v = {.num = value}; lv_style_set_prop(style, LV_STYLE_ANIM_TIME, v); }
static inline void lv_style_set_clip_corner(lv_style_t * style, bool value) {
lv_style_value_t v = {.num = value}; lv_style_set_prop(style, LV_STYLE_CLIP_CORNER, v); }

View File

@ -475,8 +475,7 @@ static void anim_task(lv_timer_t * param)
if(a->path.cb) new_value = a->path.cb(&a->path, a);
else new_value = lv_anim_path_linear(&a->path, a);
if(new_value != a->current)
{
if(new_value != a->current) {
a->current = new_value;
/*Apply the calculated value*/
if(a->exec_cb) a->exec_cb(a->var, new_value);

View File

@ -1,17 +0,0 @@
/**
* Start the constructor
* Makes the instance look like to instance of the class where the constructor is called.
* It's important because the virtual functions should be called from the level of the constructor.
*/
#define LV_CLASS_CONSTRUCTOR_BEGIN(inst, classname) \
const void * _original_class_p = inst->class_p; \
obj->class_p = (void*)&classname;
/**
* Finish the constructor.
* It reverts the original base class (changed by LV_CLASS_CONSTRUCTOR_BEGIN).
*/
#define LV_CLASS_CONSTRUCTOR_END(inst, classname) \
inst->class_p = _original_class_p;

View File

@ -47,6 +47,12 @@ typedef struct {
*/
LV_ATTRIBUTE_FAST_MEM int16_t _lv_trigo_sin(int16_t angle);
static inline LV_ATTRIBUTE_FAST_MEM int16_t _lv_trigo_cos(int16_t angle)
{
return _lv_trigo_sin(angle + 90);
}
//! @endcond
/**

View File

@ -104,12 +104,13 @@ typedef struct {
lv_style_t grow;
lv_style_t transition_delayed;
lv_style_t transition_normal;
lv_style_t anim;
lv_style_t line_dashed;
/*Parts*/
lv_style_t knob;
lv_style_t indic;
#if LV_USE_ARC
lv_style_t arc_indic;
lv_style_t arc_indic_primary;
@ -121,7 +122,7 @@ typedef struct {
#endif
#if LV_USE_CHART
lv_style_t chart_bg, chart_series;
lv_style_t chart_series, chart_ticks;
#endif
#if LV_USE_CHECKBOX
@ -184,10 +185,10 @@ static bool inited;
static void basic_init(void)
{
const static lv_style_prop_t trans_props[] = {
// LV_STYLE_BG_OPA, LV_STYLE_BG_COLOR,
LV_STYLE_BG_OPA, LV_STYLE_BG_COLOR,
LV_STYLE_TRANSFORM_WIDTH,
LV_STYLE_TRANSFORM_HEIGHT,
// LV_STYLE_COLOR_FILTER_OPA, LV_STYLE_COLOR_FILTER_CB,
LV_STYLE_COLOR_FILTER_OPA, LV_STYLE_COLOR_FILTER_CB,
0
};
@ -234,6 +235,8 @@ static void basic_init(void)
lv_style_set_border_post(&styles->card, true);
lv_style_set_text_color(&styles->card, CARD_TEXT_COLOR);
lv_style_set_pad_all(&styles->card, PAD_DEF);
lv_style_set_line_color(&styles->card, COLOR_GRAY);
lv_style_set_line_width(&styles->card, LV_DPX(1));
style_init_reset(&styles->focus_border);
lv_style_set_border_color(&styles->focus_border, theme.color_primary);
@ -315,6 +318,13 @@ static void basic_init(void)
lv_style_set_pad_all(&styles->knob, LV_DPX(5));
lv_style_set_radius(&styles->knob, LV_RADIUS_CIRCLE);
style_init_reset(&styles->anim);
lv_style_set_anim_time(&styles->anim, 200);
style_init_reset(&styles->line_dashed);
lv_style_set_line_dash_width(&styles->line_dashed, LV_DPX(10));
lv_style_set_line_dash_gap(&styles->line_dashed, LV_DPX(10));
#if LV_USE_ARC
style_init_reset(&styles->arc_indic);
lv_style_set_line_color(&styles->arc_indic, COLOR_GRAY);
@ -341,18 +351,14 @@ static void basic_init(void)
#endif
#if LV_USE_CHART
style_init_reset(&styles->chart_bg);
lv_style_set_line_width(&styles->chart_bg, LV_DPX(1));
lv_style_set_line_dash_width(&styles->chart_bg, LV_DPX(10));
lv_style_set_line_dash_gap(&styles->chart_bg, LV_DPX(10));
lv_style_set_line_color(&styles->chart_bg, LV_COLOR_RED);//CARD_BORDER_COLOR);
lv_style_set_text_color(&styles->chart_bg, LV_COLOR_RED);//CARD_BORDER_COLOR);
style_init_reset(&styles->chart_series);
lv_style_set_line_width(&styles->chart_series, LV_DPX(3));
// lv_style_set_size(&styles->chart_series, LV_DPX(4));
lv_style_set_pad_all(&styles->chart_series, LV_DPX(2)); /*Space between columns*/
lv_style_set_radius(&styles->chart_series, LV_DPX(1));
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
@ -364,78 +370,60 @@ static void basic_init(void)
lv_style_set_border_side(&styles->table_cell, LV_BORDER_SIDE_TOP | LV_BORDER_SIDE_BOTTOM);
#endif
}
static void line_init(void)
{
#if LV_USE_LINE != 0
#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 gauge_init(void)
{
#if LV_USE_GAUGE != 0
style_init_reset(&styles->gauge_main);
lv_style_set_line_color(&styles->gauge_main, LV_STATE_DEFAULT, lv_color_hex3(0x888));
lv_style_set_scale_grad_color(&styles->gauge_main, LV_STATE_DEFAULT, lv_color_hex3(0x888));
lv_style_set_scale_end_color(&styles->gauge_main, LV_STATE_DEFAULT, theme.color_primary);
lv_style_set_line_width(&styles->gauge_main, LV_STATE_DEFAULT, LV_DPX(5));
lv_style_set_scale_end_line_width(&styles->gauge_main, LV_STATE_DEFAULT, LV_DPX(4));
lv_style_set_scale_end_border_width(&styles->gauge_main, LV_STATE_DEFAULT, LV_DPX(8));
lv_style_set_pad_left(&styles->gauge_main, LV_STATE_DEFAULT, LV_DPX(20));
lv_style_set_pad_right(&styles->gauge_main, LV_STATE_DEFAULT, LV_DPX(20));
lv_style_set_pad_top(&styles->gauge_main, LV_STATE_DEFAULT, LV_DPX(20));
lv_style_set_pad_all(&styles->gauge_main, LV_STATE_DEFAULT, LV_DPX(20));
lv_style_set_scale_width(&styles->gauge_main, LV_STATE_DEFAULT, LV_DPX(15));
lv_style_set_radius(&styles->gauge_main, LV_STATE_DEFAULT, LV_RADIUS_CIRCLE);
style_init_reset(&styles->gauge_strong);
lv_style_set_line_color(&styles->gauge_strong, LV_STATE_DEFAULT, lv_color_hex3(0x888));
lv_style_set_scale_grad_color(&styles->gauge_strong, LV_STATE_DEFAULT, lv_color_hex3(0x888));
lv_style_set_scale_end_color(&styles->gauge_strong, LV_STATE_DEFAULT, theme.color_primary);
lv_style_set_line_width(&styles->gauge_strong, LV_STATE_DEFAULT, LV_DPX(8));
lv_style_set_scale_end_line_width(&styles->gauge_strong, LV_STATE_DEFAULT, LV_DPX(8));
lv_style_set_scale_width(&styles->gauge_strong, LV_STATE_DEFAULT, LV_DPX(25));
style_init_reset(&styles->gauge_needle);
lv_style_set_line_color(&styles->gauge_needle, LV_STATE_DEFAULT, IS_LIGHT ? lv_color_hex(0x464b5b) : LV_COLOR_WHITE);
lv_style_set_line_width(&styles->gauge_needle, LV_STATE_DEFAULT, LV_DPX(8));
lv_style_set_bg_opa(&styles->gauge_needle, LV_STATE_DEFAULT, LV_OPA_COVER);
lv_style_set_bg_color(&styles->gauge_needle, LV_STATE_DEFAULT, IS_LIGHT ? lv_color_hex(0x464b5b) : LV_COLOR_WHITE);
lv_style_set_radius(&styles->gauge_needle, LV_STATE_DEFAULT, LV_RADIUS_CIRCLE);
lv_style_set_size(&styles->gauge_needle, LV_STATE_DEFAULT, LV_DPX(30));
lv_style_set_pad_all(&styles->gauge_needle, LV_STATE_DEFAULT, LV_DPX(10));
#endif
}
static void spinner_init(void)
{
#if LV_USE_SPINNER != 0
#endif
}
static void chart_init(void)
{
}
//
//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 gauge_init(void)
//{
//#if LV_USE_GAUGE != 0
// style_init_reset(&styles->gauge_main);
// lv_style_set_line_color(&styles->gauge_main, LV_STATE_DEFAULT, lv_color_hex3(0x888));
// lv_style_set_scale_grad_color(&styles->gauge_main, LV_STATE_DEFAULT, lv_color_hex3(0x888));
// lv_style_set_scale_end_color(&styles->gauge_main, LV_STATE_DEFAULT, theme.color_primary);
// lv_style_set_line_width(&styles->gauge_main, LV_STATE_DEFAULT, LV_DPX(5));
// lv_style_set_scale_end_line_width(&styles->gauge_main, LV_STATE_DEFAULT, LV_DPX(4));
// lv_style_set_scale_end_border_width(&styles->gauge_main, LV_STATE_DEFAULT, LV_DPX(8));
// lv_style_set_pad_left(&styles->gauge_main, LV_STATE_DEFAULT, LV_DPX(20));
// lv_style_set_pad_right(&styles->gauge_main, LV_STATE_DEFAULT, LV_DPX(20));
// lv_style_set_pad_top(&styles->gauge_main, LV_STATE_DEFAULT, LV_DPX(20));
// lv_style_set_pad_all(&styles->gauge_main, LV_STATE_DEFAULT, LV_DPX(20));
// lv_style_set_scale_width(&styles->gauge_main, LV_STATE_DEFAULT, LV_DPX(15));
// lv_style_set_radius(&styles->gauge_main, LV_STATE_DEFAULT, LV_RADIUS_CIRCLE);
//
// style_init_reset(&styles->gauge_strong);
// lv_style_set_line_color(&styles->gauge_strong, LV_STATE_DEFAULT, lv_color_hex3(0x888));
// lv_style_set_scale_grad_color(&styles->gauge_strong, LV_STATE_DEFAULT, lv_color_hex3(0x888));
// lv_style_set_scale_end_color(&styles->gauge_strong, LV_STATE_DEFAULT, theme.color_primary);
// lv_style_set_line_width(&styles->gauge_strong, LV_STATE_DEFAULT, LV_DPX(8));
// lv_style_set_scale_end_line_width(&styles->gauge_strong, LV_STATE_DEFAULT, LV_DPX(8));
// lv_style_set_scale_width(&styles->gauge_strong, LV_STATE_DEFAULT, LV_DPX(25));
//
// style_init_reset(&styles->gauge_needle);
// lv_style_set_line_color(&styles->gauge_needle, LV_STATE_DEFAULT, IS_LIGHT ? lv_color_hex(0x464b5b) : LV_COLOR_WHITE);
// lv_style_set_line_width(&styles->gauge_needle, LV_STATE_DEFAULT, LV_DPX(8));
// lv_style_set_bg_opa(&styles->gauge_needle, LV_STATE_DEFAULT, LV_OPA_COVER);
// lv_style_set_bg_color(&styles->gauge_needle, LV_STATE_DEFAULT, IS_LIGHT ? lv_color_hex(0x464b5b) : LV_COLOR_WHITE);
// lv_style_set_radius(&styles->gauge_needle, LV_STATE_DEFAULT, LV_RADIUS_CIRCLE);
// lv_style_set_size(&styles->gauge_needle, LV_STATE_DEFAULT, LV_DPX(30));
// lv_style_set_pad_all(&styles->gauge_needle, LV_STATE_DEFAULT, LV_DPX(10));
//#endif
//}
static void textarea_init(void)
{
@ -536,11 +524,6 @@ lv_theme_t * lv_theme_default_init(lv_color_t color_primary, lv_color_t color_se
theme.flags = flags;
basic_init();
line_init();
linemeter_init();
gauge_init();
spinner_init();
chart_init();
textarea_init();
theme.apply_cb = theme_apply;
@ -656,17 +639,20 @@ static void theme_apply(lv_theme_t * th, lv_obj_t * obj)
#if LV_USE_CHART
else if(lv_obj_check_type(obj, &lv_chart)) {
lv_obj_add_style_no_refresh(obj, LV_PART_MAIN, LV_STATE_DEFAULT, &styles->card);
lv_obj_add_style_no_refresh(obj, LV_PART_MAIN, LV_STATE_DEFAULT, &styles->chart_bg);
lv_obj_add_style_no_refresh(obj, LV_PART_MAIN, LV_STATE_DEFAULT, &styles->line_dashed);
lv_obj_add_style_no_refresh(obj, LV_PART_MAIN, LV_STATE_DEFAULT, &styles->pad_zero);
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_SERIES, LV_STATE_DEFAULT, &styles->chart_series);
lv_obj_add_style_no_refresh(obj, LV_PART_ITEMS, LV_STATE_DEFAULT, &styles->chart_series);
lv_obj_add_style_no_refresh(obj, LV_PART_MARKER, LV_STATE_DEFAULT, &styles->pad_small);
lv_obj_add_style_no_refresh(obj, LV_PART_MARKER, LV_STATE_DEFAULT, &styles->chart_ticks);
}
#endif
#if LV_USE_ROLLER
else if(lv_obj_check_type(obj, &lv_roller)) {
lv_obj_add_style_no_refresh(obj, LV_PART_MAIN, LV_STATE_DEFAULT, &styles->card);
lv_obj_add_style_no_refresh(obj, LV_PART_MAIN, LV_STATE_DEFAULT, &styles->anim);
lv_obj_add_style_no_refresh(obj, LV_PART_HIGHLIGHT, LV_STATE_DEFAULT, &styles->bg_color_primary);
}
#endif
@ -691,38 +677,10 @@ static void theme_apply(lv_theme_t * th, lv_obj_t * obj)
lv_obj_add_style_no_refresh(obj, LV_PART_KNOB, LV_STATE_DEFAULT, &styles->knob);
}
#endif
//#if LV_USE_BTNMATRIX
//case LV_THEME_BTNMATRIX:
// list = _lv_obj_get_style_list(obj, LV_BTNMATRIX_PART_MAIN);
// _lv_style_list_add_style(list, &styles->card);
// _lv_style_list_add_style(list, &styles->pad_small);
//
// list = _lv_obj_get_style_list(obj, LV_BTNMATRIX_PART_BTN);
// _lv_style_list_add_style(list, &styles->card);
// _lv_style_list_add_style(list, &styles->bg_click);
// _lv_style_list_add_style(list, &styles->btnmatrix_btn);
//
// list = _lv_obj_get_style_list(obj, LV_BTNMATRIX_PART_BTN_2);
// _lv_style_list_add_style(list, &styles->card);
// _lv_style_list_add_style(list, &styles->bg_click);
// _lv_style_list_add_style(list, &styles->btnmatrix_btn);
// break;
//#endif
#if LV_USE_IMG
case LV_THEME_IMAGE:
break;
#endif
#if LV_USE_IMGBTN
case LV_THEME_IMGBTN:
break;
#endif
#if LV_USE_LINE
case LV_THEME_LINE:
break;
#endif
else if(lv_obj_check_type(obj, &lv_img)) {
lv_obj_add_style_no_refresh(obj, LV_PART_MAIN, LV_STATE_DEFAULT, &styles->card);
}
#if LV_USE_OBJMASK
case LV_THEME_OBJMASK:
@ -730,41 +688,6 @@ case LV_THEME_OBJMASK:
break;
#endif
//#if LV_USE_DROPDOWN
//case LV_THEME_DROPDOWN:
// list = _lv_obj_get_style_list(obj, LV_DROPDOWN_PART_MAIN);
// _lv_style_list_add_style(list, &styles->card);
// _lv_style_list_add_style(list, &styles->bg_click);
// _lv_style_list_add_style(list, &styles->pad_small);
//
// list = _lv_obj_get_style_list(obj, LV_DROPDOWN_PART_LIST);
// _lv_style_list_add_style(list, &styles->card);
// _lv_style_list_add_style(list, &styles->ddlist_page);
// _lv_style_list_add_style(list, &styles->sb);
//
// list = _lv_obj_get_style_list(obj, LV_DROPDOWN_PART_SELECTED);
// _lv_style_list_add_style(list, &styles->ddlist_sel);
// break;
//#endif
//#if LV_USE_CHART
//case LV_THEME_CHART:
// list = _lv_obj_get_style_list(obj, LV_CHART_PART_BG);
// _lv_style_list_add_style(list, &styles->card);
// _lv_style_list_add_style(list, &styles->chart_bg);
// _lv_style_list_add_style(list, &styles->pad_small);
//
// list = _lv_obj_get_style_list(obj, LV_CHART_PART_SERIES_BG);
// _lv_style_list_add_style(list, &styles->pad_small);
// _lv_style_list_add_style(list, &styles->chart_series_bg);
//
// list = _lv_obj_get_style_list(obj, LV_CHART_PART_CURSOR);
// _lv_style_list_add_style(list, &styles->chart_series_bg);
//
// list = _lv_obj_get_style_list(obj, LV_CHART_PART_SERIES);
// _lv_style_list_add_style(list, &styles->chart_series);
// break;
//#endif
#if LV_USE_TEXTAREA
case LV_THEME_TEXTAREA:
@ -782,26 +705,27 @@ case LV_THEME_TEXTAREA:
#endif
#if LV_USE_LINEMETER
case LV_THEME_LINEMETER:
list = _lv_obj_get_style_list(obj, LV_LINEMETER_PART_MAIN);
_lv_style_list_add_style(list, &styles->card);
_lv_style_list_add_style(list, &styles->lmeter);
break;
#endif
#if LV_USE_GAUGE
case LV_THEME_GAUGE:
list = _lv_obj_get_style_list(obj, LV_GAUGE_PART_MAIN);
_lv_style_list_add_style(list, &styles->card);
_lv_style_list_add_style(list, &styles->gauge_main);
list = _lv_obj_get_style_list(obj, LV_GAUGE_PART_MAJOR);
_lv_style_list_add_style(list, &styles->gauge_strong);
list = _lv_obj_get_style_list(obj, LV_GAUGE_PART_NEEDLE);
_lv_style_list_add_style(list, &styles->gauge_needle);
break;
#endif
//#if LV_USE_LINEMETER
//case LV_THEME_LINEMETER:
// list = _lv_obj_get_style_list(obj, LV_LINEMETER_PART_MAIN);
// _lv_style_list_add_style(list, &styles->card);
// _lv_style_list_add_style(list, &styles->lmeter);
// break;
//#endif
//
//#if LV_USE_GAUGE
//case LV_THEME_GAUGE:
// list = _lv_obj_get_style_list(obj, LV_GAUGE_PART_MAIN);
// _lv_style_list_add_style(list, &styles->card);
// _lv_style_list_add_style(list, &styles->gauge_main);
//
// list = _lv_obj_get_style_list(obj, LV_GAUGE_PART_MAJOR);
// _lv_style_list_add_style(list, &styles->gauge_strong);
//
// list = _lv_obj_get_style_list(obj, LV_GAUGE_PART_NEEDLE);
// _lv_style_list_add_style(list, &styles->gauge_needle);
// break;
//#endif
}
/**********************

View File

@ -418,8 +418,7 @@ static void lv_arc_constructor(lv_obj_t * obj, lv_obj_t * parent, const lv_obj_t
{
LV_LOG_TRACE("lv_arc create started");
LV_CLASS_CONSTRUCTOR_BEGIN(obj, lv_arc)
lv_obj.constructor(obj, parent, copy);
lv_obj_construct_base(obj, parent, copy);
lv_arc_t * arc = (lv_arc_t *)obj;
LV_LOG_TRACE("arc create started");
@ -469,11 +468,6 @@ static void lv_arc_constructor(lv_obj_t * obj, lv_obj_t * parent, const lv_obj_t
arc->last_angle = copy_arc->last_angle;
}
LV_LOG_INFO("arc created");
LV_CLASS_CONSTRUCTOR_END(obj, lv_arc)
LV_LOG_INFO("arc created");
}
static void lv_arc_destructor(lv_obj_t * obj)

View File

@ -53,7 +53,7 @@ static void lv_bar_anim_ready(lv_anim_t * a);
/**********************
* STATIC VARIABLES
**********************/
const lv_obj_class_t lv_bar = {
const lv_obj_class_t lv_bar = {
.constructor = lv_bar_constructor,
.destructor = lv_bar_destructor,
.signal_cb = lv_bar_signal,
@ -265,8 +265,7 @@ static void lv_bar_constructor(lv_obj_t * obj, lv_obj_t * parent, const lv_obj_t
{
LV_LOG_TRACE("lv_bar create started");
LV_CLASS_CONSTRUCTOR_BEGIN(obj, lv_bar)
lv_obj.constructor(obj, parent, copy);
lv_obj_construct_base(obj, parent, copy);
lv_bar_t * bar = (lv_bar_t *)obj;
bar->min_value = 0;
@ -295,7 +294,6 @@ static void lv_bar_constructor(lv_obj_t * obj, lv_obj_t * parent, const lv_obj_t
lv_bar_set_value(obj, bar->cur_value, LV_ANIM_OFF);
}
LV_CLASS_CONSTRUCTOR_END(obj, lv_bar)
LV_LOG_INFO("bar created");
}

View File

@ -86,14 +86,11 @@ static void lv_btn_constructor(lv_obj_t * obj, lv_obj_t * parent, const lv_obj_t
{
LV_LOG_TRACE("lv_btn create started");
LV_CLASS_CONSTRUCTOR_BEGIN(obj, lv_btn)
lv_obj.constructor(obj, parent, copy);
lv_obj_construct_base(obj, parent, copy);
lv_obj_set_size(obj, LV_DPI, LV_DPI / 3);
lv_obj_clear_flag(obj, LV_OBJ_FLAG_SCROLLABLE);
LV_CLASS_CONSTRUCTOR_END(obj, lv_btn)
LV_LOG_INFO("btn created");
}

View File

@ -498,12 +498,7 @@ bool lv_btnmatrix_get_one_checked(const lv_obj_t * obj)
static void lv_btnmatrix_constructor(lv_obj_t * obj, lv_obj_t * parent, const lv_obj_t * copy)
{
LV_LOG_TRACE("lv_bar create started");
LV_CLASS_CONSTRUCTOR_BEGIN(obj, lv_btnmatrix)
lv_obj.constructor(obj, parent, copy);
LV_LOG_TRACE("button matrix create started");
lv_obj_construct_base(obj, parent, copy);
lv_btnmatrix_t * btnm = (lv_btnmatrix_t *)obj;
btnm->btn_cnt = 0;
@ -529,7 +524,6 @@ static void lv_btnmatrix_constructor(lv_obj_t * obj, lv_obj_t * parent, const lv
}
LV_CLASS_CONSTRUCTOR_END(obj, lv_bar)
LV_LOG_INFO("button matrix created");
}

View File

@ -28,23 +28,17 @@
#define LV_CHART_PNUM_DEF 10
#define LV_CHART_LABEL_ITERATOR_FORWARD 1
#define LV_CHART_LABEL_ITERATOR_REVERSE 0
#define TICK_LABEL_GAP LV_DPX(2)
/**********************
* TYPEDEFS
**********************/
typedef struct {
const char * list_start;
const char * current_pos;
uint8_t items_left;
uint8_t is_reverse_iter;
} lv_chart_label_iterator_t;
/**********************
* STATIC PROTOTYPES
**********************/
static void lv_chart_constructor(lv_obj_t * obj, lv_obj_t * parent, const lv_obj_t * copy);
static void lv_chart_destructor(void * obj);
static void lv_chart_destructor(lv_obj_t * obj);
static lv_design_res_t lv_chart_design(lv_obj_t * obj, const lv_area_t * clip_area, lv_design_mode_t mode);
static lv_res_t lv_chart_signal(lv_obj_t * obj, lv_signal_t sign, void * param);
@ -55,14 +49,18 @@ static void draw_cursors(lv_obj_t * obj, const lv_area_t * clip_area);
static void draw_axes(lv_obj_t * obj, const lv_area_t * mask);
static void invalidate_lines(lv_obj_t * obj, uint16_t i);
static void invalidate_columns(lv_obj_t * obj, uint16_t i);
static void get_next_axis_label(lv_chart_label_iterator_t * iterator, char * buf);
static inline bool is_tick_with_label(uint8_t tick_num, lv_chart_axis_cfg_t * axis);
static lv_chart_label_iterator_t create_axis_label_iter(const char * list, uint8_t iterator_dir);
/**********************
* STATIC VARIABLES
**********************/
lv_chart_class_t lv_chart;
const lv_obj_class_t lv_chart = {
.constructor = lv_chart_constructor,
.destructor = lv_chart_destructor,
.signal_cb = lv_chart_signal,
.design_cb = lv_chart_design,
.instance_size = sizeof(lv_chart_t),
.base_class = &lv_obj
};
/**********************
* MACROS
@ -81,27 +79,7 @@ lv_chart_class_t lv_chart;
*/
lv_obj_t * lv_chart_create(lv_obj_t * parent, const lv_obj_t * copy)
{
LV_LOG_TRACE("chart create started");
if(!lv_chart._inited) {
LV_CLASS_INIT(lv_chart, lv_obj);
lv_chart.constructor = lv_chart_constructor;
lv_chart.destructor = lv_chart_destructor;
lv_chart.design_cb = lv_chart_design;
lv_chart.signal_cb = lv_chart_signal;
}
lv_obj_t * obj = lv_class_new(&lv_chart);
lv_chart.constructor(obj, parent, copy);
lv_obj_create_finish(obj, parent, copy);
LV_LOG_INFO("chart created");
return obj;
return lv_obj_create_from_class(&lv_chart, parent, copy);
}
/*======================
@ -172,10 +150,10 @@ void lv_chart_remove_series(lv_obj_t * obj, lv_chart_series_t * series)
* Add a cursor with a given color
* @param chart pointer to chart object
* @param color color of the cursor
* @param dir direction of the cursor. `LV_CHART_CURSOR_RIGHT/LEFT/TOP/DOWN`. OR-ed values are possible
* @param dir direction of the cursor. `LV_DIR_RIGHT/LEFT/TOP/DOWN`. OR-ed values are possible
* @return pointer to the created cursor
*/
lv_chart_cursor_t * lv_chart_add_cursor(lv_obj_t * obj, lv_color_t color, lv_cursor_direction_t axes)
lv_chart_cursor_t * lv_chart_add_cursor(lv_obj_t * obj, lv_color_t color, lv_dir_t axes)
{
LV_ASSERT_OBJ(obj, LV_OBJX_NAME);
@ -262,17 +240,14 @@ void lv_chart_set_y_range(lv_obj_t * obj, lv_chart_axis_t axis, lv_coord_t ymin,
{
LV_ASSERT_OBJ(obj, LV_OBJX_NAME);
if(axis >= _LV_CHART_AXIS_LAST) {
if(axis != LV_CHART_AXIS_PRIMARY_Y && axis != LV_CHART_AXIS_SECONDARY_Y) {
LV_LOG_WARN("Invalid axis: %d", axis);
return;
}
lv_chart_t * chart = (lv_chart_t *)obj;
if(chart->ymin[axis] == ymin && chart->ymax[axis] == ymax) return;
chart->ymin[axis] = ymin;
chart->ymax[axis] = (ymax == ymin ? ymax + 1 : ymax);;
chart->ymax[axis] = (ymax == ymin ? ymax + 1 : ymax);
lv_chart_refresh(obj);
}
@ -440,97 +415,6 @@ void lv_chart_set_update_mode(lv_obj_t * obj, lv_chart_update_mode_t update_mode
lv_obj_invalidate(obj);
}
/**
* Set the length of the tick marks on the x axis
* @param chart pointer to the chart
* @param major_tick_len the length of the major tick or `LV_CHART_TICK_LENGTH_AUTO` to set automatically
* (where labels are added)
* @param minor_tick_len the length of the minor tick, `LV_CHART_TICK_LENGTH_AUTO` to set automatically
* (where no labels are added)
*/
void lv_chart_set_x_tick_length(lv_obj_t * obj, uint8_t major_tick_len, uint8_t minor_tick_len)
{
LV_ASSERT_OBJ(obj, LV_OBJX_NAME);
lv_chart_t * chart = (lv_chart_t *)obj;
chart->x_axis.major_tick_len = major_tick_len;
chart->x_axis.minor_tick_len = minor_tick_len;
}
/**
* Set the length of the tick marks on the y axis
* @param chart pointer to the chart
* @param major_tick_len the length of the major tick or `LV_CHART_TICK_LENGTH_AUTO` to set automatically
* (where labels are added)
* @param minor_tick_len the length of the minor tick, `LV_CHART_TICK_LENGTH_AUTO` to set automatically
* (where no labels are added)
*/
void lv_chart_set_y_tick_length(lv_obj_t * obj, uint8_t major_tick_len, uint8_t minor_tick_len)
{
LV_ASSERT_OBJ(obj, LV_OBJX_NAME);
lv_chart_t * chart = (lv_chart_t *)obj;
chart->y_axis.major_tick_len = major_tick_len;
chart->y_axis.minor_tick_len = minor_tick_len;
}
/**
* Set the length of the tick marks on the secondary y axis
* @param chart pointer to the chart
* @param major_tick_len the length of the major tick or `LV_CHART_TICK_LENGTH_AUTO` to set automatically
* (where labels are added)
* @param minor_tick_len the length of the minor tick, `LV_CHART_TICK_LENGTH_AUTO` to set automatically
* (where no labels are added)
*/
void lv_chart_set_secondary_y_tick_length(lv_obj_t * obj, uint8_t major_tick_len, uint8_t minor_tick_len)
{
LV_ASSERT_OBJ(obj, LV_OBJX_NAME);
lv_chart_t * chart = (lv_chart_t *)obj;
chart->secondary_y_axis.major_tick_len = major_tick_len;
chart->secondary_y_axis.minor_tick_len = minor_tick_len;
}
/**
* Set the x-axis tick count and labels of a chart
* @param chart pointer to a chart object
* @param list_of_values list of string values, terminated with \n, except the last
* @param num_tick_marks if list_of_values is NULL: total number of ticks per axis
* else number of ticks between two value labels
* @param options extra options
*/
void lv_chart_set_x_tick_texts(lv_obj_t * obj, const char * list_of_values, uint8_t num_tick_marks,
lv_chart_axis_options_t options)
{
LV_ASSERT_OBJ(obj, LV_OBJX_NAME);
LV_ASSERT_NULL(list_of_values);
lv_chart_t * chart = (lv_chart_t *)obj;
chart->x_axis.num_tick_marks = num_tick_marks;
chart->x_axis.list_of_values = list_of_values;
chart->x_axis.options = options;
}
/**
* Set the y-axis tick count and labels of a chart
* @param chart pointer to a chart object
* @param list_of_values list of string values, terminated with \n, except the last
* @param num_tick_marks if list_of_values is NULL: total number of ticks per axis
* else number of ticks between two value labels
* @param options extra options
*/
void lv_chart_set_y_tick_texts(lv_obj_t * obj, const char * list_of_values, uint8_t num_tick_marks,
lv_chart_axis_options_t options)
{
LV_ASSERT_OBJ(obj, LV_OBJX_NAME);
LV_ASSERT_NULL(list_of_values);
lv_chart_t * chart = (lv_chart_t *)obj;
chart->y_axis.num_tick_marks = num_tick_marks;
chart->y_axis.list_of_values = list_of_values;
chart->y_axis.options = options;
}
/**
* Set the secondary y-axis tick count and labels of a chart
* @param chart pointer to a chart object
@ -539,16 +423,24 @@ void lv_chart_set_y_tick_texts(lv_obj_t * obj, const char * list_of_values, uint
* else number of ticks between two value labels
* @param options extra options
*/
void lv_chart_set_secondary_y_tick_texts(lv_obj_t * obj, const char * list_of_values, uint8_t num_tick_marks,
lv_chart_axis_options_t options)
void lv_chart_set_tick_label_cb(lv_obj_t * obj, lv_chart_tick_label_cb_t tick_label_cb, lv_coord_t ext_size)
{
LV_ASSERT_OBJ(obj, LV_OBJX_NAME);
LV_ASSERT_NULL(list_of_values);
lv_chart_t * chart = (lv_chart_t *)obj;
chart->secondary_y_axis.num_tick_marks = num_tick_marks;
chart->secondary_y_axis.list_of_values = list_of_values;
chart->secondary_y_axis.options = options;
chart->tick_label_cb = tick_label_cb;
chart->ext_size = ext_size;
_lv_obj_refresh_ext_draw_pad(obj);
lv_obj_invalidate(obj);
}
void lv_chart_set_sub_tick_conut(lv_obj_t * obj, lv_chart_axis_t axis, uint32_t cnt)
{
LV_ASSERT_OBJ(obj, LV_OBJX_NAME);
lv_chart_t * chart = (lv_chart_t *)obj;
chart->sub_tick_cnt[axis] = cnt;
lv_obj_invalidate(obj);
}
/**
@ -782,7 +674,7 @@ lv_coord_t lv_chart_get_x_from_index(lv_obj_t * obj, lv_chart_series_t * ser, ui
else if(chart->type & LV_CHART_TYPE_COLUMN) {
lv_coord_t col_w = w / ((_lv_ll_get_len(&chart->series_ll) + 1) * chart->point_cnt); /* Suppose + 1 series as separator*/
lv_chart_series_t * itr_ser = NULL;
lv_coord_t col_space = lv_obj_get_style_pad_left(obj, LV_PART_SERIES);
lv_coord_t col_space = lv_obj_get_style_pad_left(obj, LV_PART_ITEMS);
x = (int32_t)((int32_t)w * id) / chart->point_cnt;
x += col_w / 2; /*Start offset*/
@ -851,37 +743,28 @@ static void lv_chart_constructor(lv_obj_t * obj, lv_obj_t * parent, const lv_obj
{
LV_LOG_TRACE("chart create started");
LV_CLASS_CONSTRUCTOR_BEGIN(obj, lv_chart)
lv_chart.base_p->constructor(obj, parent, copy);
lv_obj_construct_base(obj, parent, copy);
lv_chart_t * chart = (lv_chart_t *) obj;
_lv_ll_init(&chart->series_ll, sizeof(lv_chart_series_t));
_lv_ll_init(&chart->cursors_ll, sizeof(lv_chart_cursor_t));
uint8_t i;
for(i = 0; i < _LV_CHART_AXIS_LAST; i++) {
chart->ymin[i] = LV_CHART_YMIN_DEF;
chart->ymax[i] = LV_CHART_YMAX_DEF;
}
chart->ymin[LV_CHART_AXIS_PRIMARY_Y] = LV_CHART_YMIN_DEF;
chart->ymax[LV_CHART_AXIS_PRIMARY_Y] = LV_CHART_YMAX_DEF;
chart->ymin[LV_CHART_AXIS_SECONDARY_Y] = LV_CHART_YMIN_DEF;
chart->ymax[LV_CHART_AXIS_SECONDARY_Y] = LV_CHART_YMAX_DEF;
chart->hdiv_cnt = LV_CHART_HDIV_DEF;
chart->vdiv_cnt = LV_CHART_VDIV_DEF;
chart->point_cnt = LV_CHART_PNUM_DEF;
chart->sub_tick_cnt[0] = 5;
chart->sub_tick_cnt[1] = 5;
chart->sub_tick_cnt[2] = 5;
chart->type = LV_CHART_TYPE_LINE;
chart->update_mode = LV_CHART_UPDATE_MODE_SHIFT;
chart->x_zoom = 512;
chart->y_zoom = 256;
_lv_memset_00(&chart->x_axis, sizeof(chart->x_axis));
_lv_memset_00(&chart->y_axis, sizeof(chart->y_axis));
_lv_memset_00(&chart->secondary_y_axis, sizeof(chart->secondary_y_axis));
chart->x_axis.major_tick_len = LV_DPX(8);
chart->x_axis.minor_tick_len = LV_DPX(4);
chart->y_axis.major_tick_len = LV_DPX(8);
chart->y_axis.minor_tick_len = LV_DPX(4);
chart->secondary_y_axis.major_tick_len = LV_DPX(8);
chart->secondary_y_axis.minor_tick_len = LV_DPX(4);
/*Init the new chart background object*/
if(copy == NULL) {
@ -896,15 +779,11 @@ static void lv_chart_constructor(lv_obj_t * obj, lv_obj_t * parent, const lv_obj
chart->point_cnt = chart_copy->point_cnt;
_lv_memcpy_small(chart->ymin, chart_copy->ymin, sizeof(chart->ymin));
_lv_memcpy_small(chart->ymax, chart_copy->ymax, sizeof(chart->ymax));
_lv_memcpy(&chart->x_axis, &chart_copy->x_axis, sizeof(lv_chart_axis_cfg_t));
_lv_memcpy(&chart->y_axis, &chart_copy->y_axis, sizeof(lv_chart_axis_cfg_t));
_lv_memcpy(&chart->secondary_y_axis, &chart_copy->secondary_y_axis, sizeof(lv_chart_axis_cfg_t));
}
LV_CLASS_CONSTRUCTOR_END(obj, lv_chart)
LV_LOG_INFO("chart created");
}
static void lv_chart_destructor(void * obj)
static void lv_chart_destructor(lv_obj_t * obj)
{
// lv_chart_series_t * ser;
@ -918,7 +797,7 @@ static void lv_chart_destructor(void * obj)
// }
// _lv_ll_clear(&chart->series_ll);
//
// _lv_obj_reset_style_list_no_refr(chart, LV_PART_SERIES);
// _lv_obj_reset_style_list_no_refr(chart, LV_PART_ITEMS);
// _lv_obj_reset_style_list_no_refr(chart, LV_PART_CURSOR);
// _lv_obj_reset_style_list_no_refr(chart, LV_PART_MAIN);
//}
@ -943,10 +822,10 @@ static void lv_chart_destructor(void * obj)
static lv_design_res_t lv_chart_design(lv_obj_t * obj, const lv_area_t * clip_area, lv_design_mode_t mode)
{
if(mode == LV_DESIGN_COVER_CHK) {
return lv_chart.base_p->design_cb(obj, clip_area, mode);
return lv_obj.design_cb(obj, clip_area, mode);
}
else if(mode == LV_DESIGN_DRAW_MAIN) {
lv_chart.base_p->design_cb(obj, clip_area, mode);
lv_obj.design_cb(obj, clip_area, mode);
draw_div_lines(obj, clip_area);
draw_axes(obj, clip_area);
@ -957,7 +836,7 @@ static lv_design_res_t lv_chart_design(lv_obj_t * obj, const lv_area_t * clip_ar
draw_cursors(obj, clip_area);
}
else if(mode == LV_DESIGN_DRAW_POST) {
lv_chart.base_p->design_cb(obj, clip_area, mode);
lv_obj.design_cb(obj, clip_area, mode);
}
return LV_DESIGN_RES_OK;
}
@ -973,7 +852,7 @@ static lv_res_t lv_chart_signal(lv_obj_t * obj, lv_signal_t sign, void * param)
/* Include the ancient signal function */
lv_res_t res;
res = lv_chart.base_p->signal_cb(obj, sign, param);
res = lv_obj.signal_cb(obj, sign, param);
lv_chart_t * chart = (lv_chart_t *)obj;
if(sign == LV_SIGNAL_GET_SELF_SIZE) {
@ -982,7 +861,7 @@ static lv_res_t lv_chart_signal(lv_obj_t * obj, lv_signal_t sign, void * param)
p->y = (lv_obj_get_height(obj) * chart->y_zoom) >> 8;
} else if(sign == LV_SIGNAL_REFR_EXT_DRAW_PAD) {
lv_coord_t * s = param;
*s = LV_MATH_MAX(*s, 100);
*s = LV_MATH_MAX(*s, chart->ext_size);
}
return res;
@ -1001,37 +880,23 @@ static void draw_div_lines(lv_obj_t * obj, const lv_area_t * clip_area)
bool mask_ret = _lv_area_intersect(&series_mask, &obj->coords, clip_area);
if(mask_ret == false) return;
uint8_t div_i;
uint8_t div_i_end;
uint8_t div_i_start;
uint32_t i;
lv_point_t p1;
lv_point_t p2;
lv_coord_t h = (lv_obj_get_height(obj) * chart->y_zoom) >> 8;
lv_coord_t w = (lv_obj_get_width(obj) * chart->x_zoom) >> 8;
lv_coord_t x_ofs = obj->coords.x1;
lv_coord_t y_ofs = obj->coords.y1;
lv_coord_t x_ofs = obj->coords.x1 - lv_obj_get_scroll_left(obj);
lv_coord_t y_ofs = obj->coords.y1 - lv_obj_get_scroll_top(obj);
lv_draw_line_dsc_t line_dsc;
lv_draw_line_dsc_init(&line_dsc);
lv_obj_init_draw_line_dsc(obj, LV_PART_MAIN, &line_dsc);
bool has_border = lv_obj_get_style_border_width(obj, LV_PART_MAIN) ? true : false;
if(chart->hdiv_cnt != 0) {
/*Draw side lines if no border*/
if(has_border != 0) {
div_i_start = 1;
div_i_end = chart->hdiv_cnt;
}
else {
div_i_start = 0;
div_i_end = chart->hdiv_cnt + 1;
}
p1.x = 0 + x_ofs;
p2.x = w - 1 + x_ofs;
for(div_i = div_i_start; div_i <= div_i_end; div_i++) {
p1.y = (int32_t)((int32_t)(h - line_dsc.width) * div_i) / (chart->hdiv_cnt + 1);
p1.x = obj->coords.x1;
p2.x = obj->coords.x2;
for(i = 0; i <= chart->hdiv_cnt + 1; i++) {
p1.y = (int32_t)((int32_t)(h - line_dsc.width) * i) / (chart->hdiv_cnt + 1);
p1.y += y_ofs;
p2.y = p1.y;
lv_draw_line(&p1, &p2, &series_mask, &line_dsc);
@ -1039,20 +904,10 @@ static void draw_div_lines(lv_obj_t * obj, const lv_area_t * clip_area)
}
if(chart->vdiv_cnt != 0) {
/*Draw side lines if no border*/
if(has_border != 0) {
div_i_start = 1;
div_i_end = chart->vdiv_cnt;
}
else {
div_i_start = 0;
div_i_end = chart->vdiv_cnt + 1;
}
p1.y = 0 + y_ofs;
p2.y = h + y_ofs - 1;
for(div_i = div_i_start; div_i <= div_i_end; div_i++) {
p1.x = (int32_t)((int32_t)(w - line_dsc.width) * div_i) / (chart->vdiv_cnt + 1);
p1.y = obj->coords.y1;
p2.y = obj->coords.y2;
for(i = 0; i <= chart->vdiv_cnt + 1; i++) {
p1.x = (int32_t)((int32_t)(w - line_dsc.width) * i) / (chart->vdiv_cnt + 1);
p1.x += x_ofs;
p2.x = p1.x;
lv_draw_line(&p1, &p2, &series_mask, &line_dsc);
@ -1086,16 +941,16 @@ static void draw_series_line(lv_obj_t * obj, const lv_area_t * clip_area)
lv_draw_line_dsc_t line_dsc;
lv_draw_line_dsc_init(&line_dsc);
lv_obj_init_draw_line_dsc(obj, LV_PART_SERIES, &line_dsc);
lv_obj_init_draw_line_dsc(obj, LV_PART_ITEMS, &line_dsc);
lv_draw_mask_fade_param_t mask_fade_p;
int16_t mask_fade_id = LV_MASK_ID_INV;
lv_draw_rect_dsc_t area_dsc;
bool has_area = lv_obj_get_style_bg_opa(obj, LV_PART_SERIES) > LV_OPA_MIN ? true : false;
bool has_area = lv_obj_get_style_bg_opa(obj, LV_PART_ITEMS) > LV_OPA_MIN ? true : false;
bool has_fade = false;
if(has_area) {
lv_draw_rect_dsc_init(&area_dsc);
lv_obj_init_draw_rect_dsc(obj, LV_PART_SERIES, &area_dsc);
lv_obj_init_draw_rect_dsc(obj, LV_PART_ITEMS, &area_dsc);
area_dsc.border_width = 0;
has_fade = area_dsc.bg_grad_dir == LV_GRAD_DIR_VER ? true : false;
@ -1111,7 +966,7 @@ static void draw_series_line(lv_obj_t * obj, const lv_area_t * clip_area)
point_dsc.radius = LV_RADIUS_CIRCLE;
lv_coord_t point_radius = 5;//lv_obj_get_style_size(obj, LV_PART_SERIES);
lv_coord_t point_radius = 5;//lv_obj_get_style_size(obj, LV_PART_ITEMS);
/*Do not bother with line ending is the point will over it*/
if(point_radius > line_dsc.width / 2) line_dsc.raw_end = 1;
@ -1234,13 +1089,13 @@ static void draw_series_column(lv_obj_t * obj, const lv_area_t * clip_area)
lv_chart_series_t * ser;
lv_coord_t col_w = w / ((_lv_ll_get_len(&chart->series_ll) + 1) * chart->point_cnt); /* Suppose + 1 series as separator*/
lv_coord_t x_ofs = col_w / 2 - lv_obj_get_scroll_left(obj);; /*Shift with a half col.*/
lv_coord_t col_space = lv_obj_get_style_pad_left(obj, LV_PART_SERIES);
lv_coord_t col_space = lv_obj_get_style_pad_left(obj, LV_PART_ITEMS);
lv_coord_t y_ofs = -lv_obj_get_scroll_top(obj);
lv_draw_rect_dsc_t col_dsc;
lv_draw_rect_dsc_init(&col_dsc);
lv_obj_init_draw_rect_dsc(obj, LV_PART_SERIES, &col_dsc);
lv_obj_init_draw_rect_dsc(obj, LV_PART_ITEMS, &col_dsc);
col_dsc.bg_grad_dir = LV_GRAD_DIR_NONE;
col_dsc.bg_opa = LV_OPA_COVER;
@ -1319,7 +1174,7 @@ static void draw_cursors(lv_obj_t * obj, const lv_area_t * clip_area)
line_dsc.color = cursor->color;
point_dsc.bg_color = cursor->color;
if(cursor->axes & LV_CHART_CURSOR_RIGHT) {
if(cursor->axes & LV_DIR_RIGHT) {
p1.x = obj->coords.x1 + cursor->point.x;
p1.y = obj->coords.y1 + cursor->point.y;
p2.x = obj->coords.x2;
@ -1327,7 +1182,7 @@ static void draw_cursors(lv_obj_t * obj, const lv_area_t * clip_area)
lv_draw_line(&p1, &p2, &series_mask, &line_dsc);
}
if(cursor->axes & LV_CHART_CURSOR_UP) {
if(cursor->axes & LV_DIR_TOP) {
p1.x = obj->coords.x1 + cursor->point.x;
p1.y = obj->coords.y1;
@ -1336,7 +1191,7 @@ static void draw_cursors(lv_obj_t * obj, const lv_area_t * clip_area)
lv_draw_line(&p1, &p2, &series_mask, &line_dsc);
}
if(cursor->axes & LV_CHART_CURSOR_LEFT) {
if(cursor->axes & LV_DIR_LEFT) {
p1.x = obj->coords.x1;
p1.y = obj->coords.y1 + cursor->point.y;
p2.x = p1.x + cursor->point.x;
@ -1344,7 +1199,7 @@ static void draw_cursors(lv_obj_t * obj, const lv_area_t * clip_area)
lv_draw_line(&p1, &p2, &series_mask, &line_dsc);
}
if(cursor->axes & LV_CHART_CURSOR_DOWN) {
if(cursor->axes & LV_DIR_BOTTOM) {
p1.x = obj->coords.x1 + cursor->point.x;
p1.y = obj->coords.y1 + cursor->point.y;
@ -1370,252 +1225,98 @@ static void draw_cursors(lv_obj_t * obj, const lv_area_t * clip_area)
}
/**
* Create iterator for newline-separated list
* @param list pointer to newline-separated labels list
* @param iterator_dir LV_CHART_ITERATOR_FORWARD or LV_CHART_LABEL_ITERATOR_REVERSE
* @return lv_chart_label_iterator_t
*/
static lv_chart_label_iterator_t create_axis_label_iter(const char * list, uint8_t iterator_dir)
{
lv_chart_label_iterator_t iterator = {0};
uint8_t j;
iterator.list_start = list;
/* count number of list items */
for(j = 0; list[j] != '\0'; j++) {
if(list[j] == '\n')
iterator.items_left++;
}
if(iterator_dir == LV_CHART_LABEL_ITERATOR_FORWARD) {
iterator.is_reverse_iter = 0;
iterator.current_pos = list;
}
else {
iterator.is_reverse_iter = 1;
// -1 to skip '\0' at the end of the string
iterator.current_pos = list + j - 1;
}
iterator.items_left++;
return iterator;
}
/**
* Get next label from iterator created by lv_chart_create_label_iter()
* @param iterator iterator to get label from
* @param[out] buf buffer to point next label to
*/
static void get_next_axis_label(lv_chart_label_iterator_t * iterator, char * buf)
{
uint32_t label_len = 0;
if(iterator->is_reverse_iter) {
const char * label_start;
/* count the length of the current label*/
while((*iterator->current_pos != '\n') &&
(iterator->current_pos != iterator->list_start)) {
iterator->current_pos--;
label_len++;
}
label_start = iterator->current_pos;
if(*iterator->current_pos == '\n') {
/* do not copy \n symbol, +1 to skip it*/
label_start++;
/* skip newline*/
iterator->current_pos--;
}
else {
/* it is last label in list (first one from the beginning )*/
label_len++;
}
/* do not allow output buffer overflow */
if(label_len > LV_CHART_AXIS_TICK_LABEL_MAX_LEN) {
label_len = LV_CHART_AXIS_TICK_LABEL_MAX_LEN;
}
strncpy(buf, label_start, label_len);
}
else {
/* search for tick string */
while(iterator->current_pos[label_len] != '\n' &&
iterator->current_pos[label_len] != '\0') {
/* do not overflow the buffer, but move to the end of the current label */
if(label_len < LV_CHART_AXIS_TICK_LABEL_MAX_LEN) {
buf[label_len] = iterator->current_pos[label_len];
label_len++;
}
else {
label_len++;
}
}
iterator->current_pos += label_len;
/* do not allow output buffer overflow */
if(label_len > LV_CHART_AXIS_TICK_LABEL_MAX_LEN) {
label_len = LV_CHART_AXIS_TICK_LABEL_MAX_LEN;
}
if(*iterator->current_pos == '\n') iterator->current_pos++;
}
/* terminate the string */
buf[label_len] = '\0';
}
/**
* Check whether there should be a label next to tick with given
* number
* @param tick_num number of the tick to check
* @param axis pointer to struct containing info on the axis
* @return true if label should be located next to current tick
*/
static inline bool is_tick_with_label(uint8_t tick_num, lv_chart_axis_cfg_t * axis)
{
return ((tick_num == 0) || ((tick_num % axis->num_tick_marks) == 0));
}
static void draw_y_ticks(lv_obj_t * obj, const lv_area_t * mask, uint8_t which_axis)
static void draw_y_ticks(lv_obj_t * obj, const lv_area_t * mask, lv_chart_axis_t axis)
{
lv_chart_t * chart = (lv_chart_t *)obj;
lv_chart_axis_cfg_t * y_axis = (which_axis == LV_CHART_AXIS_PRIMARY_Y) ?
&chart->y_axis : &chart->secondary_y_axis;
if(y_axis->list_of_values == NULL && y_axis->num_tick_marks == 0) return;
uint8_t i;
uint8_t num_of_labels;
uint8_t num_scale_ticks;
int8_t major_tick_len, minor_tick_len;
uint8_t iter_dir;
uint32_t i;
uint32_t major_tick_cnt = chart->hdiv_cnt + 1;
uint32_t sub_tick_cnt = chart->sub_tick_cnt[LV_CHART_AXIS_X] + 1;
lv_point_t p1;
lv_point_t p2;
lv_coord_t x_ofs;
lv_chart_label_iterator_t iter;
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 */
if(which_axis == LV_CHART_AXIS_PRIMARY_Y) x_ofs = obj->coords.x1;
else x_ofs = obj->coords.x2;
lv_coord_t major_tick_len;
if(axis == LV_CHART_AXIS_PRIMARY_Y) {
x_ofs = obj->coords.x1;
major_tick_len = lv_obj_get_style_pad_left(obj, LV_PART_MARKER);
} else {
x_ofs = obj->coords.x2;
major_tick_len = lv_obj_get_style_pad_right(obj, LV_PART_MARKER);
}
major_tick_len = y_axis->major_tick_len;
minor_tick_len = y_axis->minor_tick_len;
lv_coord_t minor_tick_len = major_tick_len / 2;
lv_coord_t label_gap = TICK_LABEL_GAP;
/* tick lines on secondary y axis are drawn in other direction*/
if(which_axis == LV_CHART_AXIS_SECONDARY_Y) {
if(axis == LV_CHART_AXIS_SECONDARY_Y) {
major_tick_len *= -1;
minor_tick_len *= -1;
}
iter_dir = (y_axis->options & LV_CHART_AXIS_INVERSE_LABELS_ORDER) ? LV_CHART_LABEL_ITERATOR_REVERSE :
LV_CHART_LABEL_ITERATOR_FORWARD;
iter = create_axis_label_iter(y_axis->list_of_values, iter_dir);
/*determine the number of options */
num_of_labels = iter.items_left;
/* we can't have string labels without ticks step, set to 1 if not specified */
if(y_axis->num_tick_marks == 0) y_axis->num_tick_marks = 1;
/* calculate total number of ticks */
if(num_of_labels < 2)
num_scale_ticks = y_axis->num_tick_marks;
else
num_scale_ticks = (y_axis->num_tick_marks * (num_of_labels - 1));
lv_coord_t label_dist = which_axis == LV_CHART_AXIS_PRIMARY_Y ?
lv_obj_get_style_pad_left(obj, LV_PART_MAIN) : lv_obj_get_style_pad_right(obj, LV_PART_MAIN);
lv_draw_line_dsc_t line_dsc;
lv_draw_line_dsc_init(&line_dsc);
lv_obj_init_draw_line_dsc(obj, LV_PART_MAIN, &line_dsc);
lv_obj_init_draw_line_dsc(obj, LV_PART_MARKER, &line_dsc);
line_dsc.dash_gap = 0;
line_dsc.dash_width = 0;
lv_draw_label_dsc_t label_dsc;
lv_draw_label_dsc_init(&label_dsc);
lv_obj_init_draw_label_dsc(obj, LV_PART_MAIN, &label_dsc);
for(i = 0; i < (num_scale_ticks + 1); i++) { /* one extra loop - it may not exist in the list, empty label */
lv_obj_init_draw_label_dsc(obj, LV_PART_MARKER, &label_dsc);
uint32_t total_tick_num = major_tick_cnt * sub_tick_cnt;
for(i = 0; i <= total_tick_num; i++) {
/* draw a line at moving y position */
p2.y = p1.y =
y_ofs + (int32_t)((int32_t)(h - line_dsc.width) * i) / num_scale_ticks;
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) {
if(is_tick_with_label(i, y_axis)) {
get_next_axis_label(&iter, buf);
}
continue;
}
if(p2.y + label_dsc.font->line_height < mask->y1) continue;
/* first point of the tick */
p1.x = x_ofs;
/* move extra pixel out of chart boundary */
if(which_axis == LV_CHART_AXIS_PRIMARY_Y)
p1.x--;
else
p1.x++;
if(axis == LV_CHART_AXIS_PRIMARY_Y) p1.x--;
else p1.x++;
/* second point of the tick */
if((num_of_labels != 0) && (i == 0 || i % y_axis->num_tick_marks == 0))
p2.x = p1.x - major_tick_len; /* major tick */
else
p2.x = p1.x - minor_tick_len; /* minor tick */
bool major = false;
if(i % sub_tick_cnt == 0) major = true;
if(y_axis->options & LV_CHART_AXIS_INVERSE_LABELS_ORDER) {
/*if label order is inversed last tick have number 0*/
if(i != 0)
lv_draw_line(&p1, &p2, mask, &line_dsc);
else if((y_axis->options & LV_CHART_AXIS_DRAW_LAST_TICK) != 0)
lv_draw_line(&p1, &p2, mask, &line_dsc);
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);
/* add text only to major tick */
if(!major) continue;
chart->tick_label_cb(obj, axis, i / sub_tick_cnt, buf, sizeof(buf));
/* 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_COORD_MAX, LV_TEXT_FLAG_CENTER);
/* set the area at some distance of the major tick len left of the tick */
lv_area_t a;
a.y1 = p2.y - size.y / 2;
a.y2 = p2.y + size.y / 2;
if(axis == LV_CHART_AXIS_PRIMARY_Y) {
a.x1 = p2.x - size.x - label_gap;
a.x2 = p2.x - label_gap;
}
else {
if(i != num_scale_ticks)
lv_draw_line(&p1, &p2, mask, &line_dsc);
else if((y_axis->options & LV_CHART_AXIS_DRAW_LAST_TICK) != 0)
lv_draw_line(&p1, &p2, mask, &line_dsc);
a.x1 = p2.x + label_gap;
a.x2 = p2.x + size.x + label_gap;
}
/* draw values if available */
if(num_of_labels != 0) {
/* add text only to major tick */
if(is_tick_with_label(i, y_axis)) {
get_next_axis_label(&iter, buf);
/* 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_COORD_MAX, LV_TEXT_FLAG_CENTER);
/* set the area at some distance of the major tick len left of the tick */
/* changed to explicit member initialization to allow compilation as c++ */
lv_area_t a;
a.y1 = p2.y - size.y / 2;
a.y2 = p2.y + size.y / 2;
if(which_axis == LV_CHART_AXIS_PRIMARY_Y) {
a.x1 = p2.x - size.x - label_dist;
a.x2 = p2.x - label_dist;
}
else {
a.x1 = p2.x + label_dist;
a.x2 = p2.x + size.x + label_dist;
}
lv_draw_label(&a, mask, &label_dsc, buf, NULL);
}
}
lv_draw_label(&a, mask, &label_dsc, buf, NULL);
}
}
@ -1623,38 +1324,34 @@ static void draw_x_ticks(lv_obj_t * obj, const lv_area_t * mask)
{
lv_chart_t * chart = (lv_chart_t *)obj;
if(chart->x_axis.list_of_values == NULL && chart->x_axis.num_tick_marks == 0) return;
lv_area_t series_mask;
bool mask_ret = _lv_area_intersect(&series_mask, &obj->coords, mask);
if(mask_ret == false) return;
uint8_t i;
uint8_t num_of_labels;
uint8_t num_scale_ticks;
uint8_t major_tick_len, minor_tick_len;
lv_chart_label_iterator_t iter;
uint32_t i;
uint32_t major_tick_cnt = chart->vdiv_cnt + 1;
uint32_t sub_tick_cnt = chart->sub_tick_cnt[LV_CHART_AXIS_X] + 1;
lv_point_t p1;
lv_point_t p2;
lv_coord_t x_ofs = obj->coords.x1;
lv_coord_t x_ofs = obj->coords.x1 - lv_obj_get_scroll_left(obj);
lv_coord_t y_ofs = obj->coords.y1;
lv_coord_t h = lv_obj_get_height(obj);
lv_coord_t w = (lv_obj_get_width(obj) * chart->x_zoom) >> 8;
lv_coord_t label_dist = lv_obj_get_style_pad_bottom(obj, LV_PART_MAIN);
lv_draw_label_dsc_t label_dsc;
lv_draw_label_dsc_init(&label_dsc);
lv_obj_init_draw_label_dsc(obj, LV_PART_MAIN, &label_dsc);
lv_obj_init_draw_label_dsc(obj, LV_PART_MARKER, &label_dsc);
major_tick_len = chart->x_axis.major_tick_len;
minor_tick_len = chart->x_axis.minor_tick_len;
lv_coord_t major_tick_len = lv_obj_get_style_pad_bottom(obj, LV_PART_MARKER);
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_dist + label_dsc.font->line_height + major_tick_len < mask->y1) return;
if(h + y_ofs + label_gap + label_dsc.font->line_height + major_tick_len < mask->y1) return;
lv_draw_line_dsc_t line_dsc;
lv_draw_line_dsc_init(&line_dsc);
lv_obj_init_draw_line_dsc(obj, LV_PART_MAIN, &line_dsc);
lv_obj_init_draw_line_dsc(obj, LV_PART_MARKER, &line_dsc);
line_dsc.dash_gap = 0;
line_dsc.dash_width = 0;
@ -1667,58 +1364,36 @@ static void draw_x_ticks(lv_obj_t * obj, const lv_area_t * mask)
w -= col_w * ser_num + col_w;
}
p1.y = h + y_ofs;
char buf[LV_CHART_AXIS_TICK_LABEL_MAX_LEN + 1]; /* up to N symbols per label + null terminator */
/*determine the number of options */
iter = create_axis_label_iter(chart->x_axis.list_of_values, LV_CHART_LABEL_ITERATOR_FORWARD);
num_of_labels = iter.items_left;
/* we can't have string labels without ticks step, set to 1 if not specified */
if(chart->x_axis.num_tick_marks == 0) chart->x_axis.num_tick_marks = 1;
/* calculate total number of marks */
if(num_of_labels < 2)
num_scale_ticks = chart->x_axis.num_tick_marks;
else
num_scale_ticks = (chart->x_axis.num_tick_marks * (num_of_labels - 1));
for(i = 0; i < (num_scale_ticks + 1); i++) { /* one extra loop - it may not exist in the list, empty label */
/* first point of the tick */
p1.y = h + y_ofs;
/* second point of the tick */
if((num_of_labels != 0) && (i == 0 || i % chart->x_axis.num_tick_marks == 0))
p2.y = p1.y + major_tick_len; /* major tick */
else
p2.y = p1.y + minor_tick_len; /* minor tick */
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;
if(i % sub_tick_cnt == 0) major = true;
/* draw a line at moving x position */
p2.x = p1.x = x_ofs + (int32_t)((int32_t)(w - line_dsc.width) * i) / num_scale_ticks;
p2.x = p1.x = x_ofs + (int32_t)((int32_t)(w - line_dsc.width) * i) / total_tick_num;
if(p1.x > series_mask.x2) return;
if(i != num_scale_ticks)
lv_draw_line(&p1, &p2, mask, &line_dsc);
else if((chart->x_axis.options & LV_CHART_AXIS_DRAW_LAST_TICK) != 0)
lv_draw_line(&p1, &p2, mask, &line_dsc);
p2.y = p1.y + (major ? major_tick_len : minor_tick_len);
lv_draw_line(&p1, &p2, mask, &line_dsc);
/* draw values if available */
if(num_of_labels != 0) {
/* add text only to major tick */
if(is_tick_with_label(i, &(chart->x_axis))) {
get_next_axis_label(&iter, buf);
if(!major) continue;
chart->tick_label_cb(obj, LV_CHART_AXIS_X, i / sub_tick_cnt, buf, sizeof(buf));
/* 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_COORD_MAX, LV_TEXT_FLAG_CENTER);
/* 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_COORD_MAX, LV_TEXT_FLAG_CENTER);
/* set the area at some distance of the major tick len under of the tick */
lv_area_t a = {(p2.x - size.x / 2), (p2.y + label_dist), (p2.x + size.x / 2),
(p2.y + size.y + label_dist)
};
lv_draw_label(&a, mask, &label_dsc, buf, NULL);
}
}
/* set the area at some distance of the major tick len under of the tick */
lv_area_t a;
a.x1 = (p2.x - size.x / 2);
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);
}
}
@ -1741,8 +1416,8 @@ static void invalidate_lines(lv_obj_t * obj, uint16_t i)
lv_coord_t w = lv_obj_get_width(obj);
lv_coord_t x_ofs = obj->coords.x1;
lv_coord_t line_width = lv_obj_get_style_line_width(obj, LV_PART_SERIES);
lv_coord_t point_radius = 5;//lv_obj_get_style_size(chart, LV_PART_SERIES);
lv_coord_t line_width = lv_obj_get_style_line_width(obj, LV_PART_ITEMS);
lv_coord_t point_radius = 5;//lv_obj_get_style_size(chart, LV_PART_ITEMS);
lv_area_t coords;
lv_area_copy(&coords, &obj->coords);

View File

@ -51,21 +51,13 @@ typedef uint8_t lv_chart_update_mode_t;
enum {
LV_CHART_AXIS_PRIMARY_Y,
LV_CHART_AXIS_PRIMARY_Y, /*Y axis should be the first to allow indexing arrays with the values*/
LV_CHART_AXIS_SECONDARY_Y,
LV_CHART_AXIS_X,
_LV_CHART_AXIS_LAST,
};
typedef uint8_t lv_chart_axis_t;
enum {
LV_CHART_CURSOR_NONE = 0x00,
LV_CHART_CURSOR_RIGHT = 0x01,
LV_CHART_CURSOR_UP = 0x02,
LV_CHART_CURSOR_LEFT = 0x04,
LV_CHART_CURSOR_DOWN = 0x08
};
typedef uint8_t lv_cursor_direction_t;
typedef struct {
lv_coord_t * points;
lv_color_t color;
@ -78,55 +70,30 @@ typedef struct {
typedef struct {
lv_point_t point;
lv_color_t color;
lv_cursor_direction_t axes : 4;
lv_dir_t axes : 4;
} lv_chart_cursor_t;
/** Data of axis */
enum {
LV_CHART_AXIS_SKIP_LAST_TICK = 0x00, /**< don't draw the last tick */
LV_CHART_AXIS_DRAW_LAST_TICK = 0x01, /**< draw the last tick */
LV_CHART_AXIS_INVERSE_LABELS_ORDER = 0x02 /**< draw tick labels in an inverted order*/
};
typedef uint8_t lv_chart_axis_options_t;
typedef void (*lv_chart_tick_label_cb_t)(const lv_obj_t * obj, lv_chart_axis_t axis, uint32_t tick_id, char buf[], size_t buf_len);
typedef struct {
const char * list_of_values;
lv_chart_axis_options_t options;
uint8_t num_tick_marks;
uint8_t major_tick_len;
uint8_t minor_tick_len;
} lv_chart_axis_cfg_t;
LV_CLASS_DECLARE_START(lv_chart, lv_obj);
#define _lv_chart_constructor void (*constructor)(struct _lv_obj_t * obj, struct _lv_obj_t * parent, const struct _lv_obj_t * copy)
#define _lv_chart_data \
_lv_obj_data \
lv_ll_t series_ll; /*Linked list for the data line pointers (stores lv_chart_series_t)*/ \
lv_ll_t cursors_ll; /*Linked list for the cursor pointers (stores lv_chart_cursor_t)*/ \
lv_coord_t ymin[_LV_CHART_AXIS_LAST]; /*y min values for both axis (used to scale the data)*/ \
lv_coord_t ymax[_LV_CHART_AXIS_LAST]; /*y max values for both axis (used to scale the data)*/ \
uint8_t hdiv_cnt; /*Number of horizontal division lines*/ \
uint8_t vdiv_cnt; /*Number of vertical division lines*/ \
uint16_t point_cnt; /*Point number in a data line*/ \
lv_chart_type_t type; /*Line, column or point chart (from 'lv_chart_type_t')*/ \
lv_chart_axis_cfg_t y_axis; \
lv_chart_axis_cfg_t x_axis; \
lv_chart_axis_cfg_t secondary_y_axis; \
uint16_t x_zoom; \
uint16_t y_zoom; \
lv_obj_t obj;
lv_ll_t series_ll; /*Linked list for the data line pointers (stores lv_chart_series_t)*/
lv_ll_t cursors_ll; /*Linked list for the cursor pointers (stores lv_chart_cursor_t)*/
lv_chart_tick_label_cb_t tick_label_cb;
lv_coord_t ymin[2];
lv_coord_t ymax[2];
lv_coord_t ext_size;
uint8_t hdiv_cnt; /*Number of horizontal division lines*/
uint8_t vdiv_cnt; /*Number of vertical division lines*/
uint8_t sub_tick_cnt[_LV_CHART_AXIS_LAST];
uint16_t point_cnt; /*Point number in a data line*/
lv_chart_type_t type; /*Line, column or point chart (from 'lv_chart_type_t')*/
uint16_t x_zoom;
uint16_t y_zoom;
uint8_t update_mode : 1;
}lv_chart_t;
#define _lv_chart_class_dsc \
_lv_obj_class_dsc
LV_CLASS_DECLARE_END(lv_chart, lv_obj);
extern lv_chart_class_t lv_chart;
#define LV_PART_SERIES 20
extern const lv_obj_class_t lv_chart;
/**********************
* GLOBAL PROTOTYPES
@ -164,10 +131,10 @@ void lv_chart_remove_series(lv_obj_t * chart, lv_chart_series_t * series);
* Add a cursor with a given color
* @param chart pointer to chart object
* @param color color of the cursor
* @param dir direction of the cursor. `LV_CHART_CURSOR_RIGHT/LEFT/TOP/DOWN`. OR-ed values are possible
* @param dir direction of the cursor. `LV_DIR_RIGHT/LEFT/TOP/BOTTOM/HOR/VER/ALL`
* @return pointer to the created cursor
*/
lv_chart_cursor_t * lv_chart_add_cursor(lv_obj_t * chart, lv_color_t color, lv_cursor_direction_t dir);
lv_chart_cursor_t * lv_chart_add_cursor(lv_obj_t * chart, lv_color_t color, lv_dir_t dir);
/**
* Clear the point of a series
@ -290,30 +257,7 @@ void lv_chart_set_secondary_y_tick_length(lv_obj_t * chart, uint8_t major_tick_l
* else number of ticks between two value labels
* @param options extra options
*/
void lv_chart_set_x_tick_texts(lv_obj_t * chart, const char * list_of_values, uint8_t num_tick_marks,
lv_chart_axis_options_t options);
/**
* Set the secondary y-axis tick count and labels of a chart
* @param chart pointer to a chart object
* @param list_of_values list of string values, terminated with \n, except the last
* @param num_tick_marks if list_of_values is NULL: total number of ticks per axis
* else number of ticks between two value labels
* @param options extra options
*/
void lv_chart_set_secondary_y_tick_texts(lv_obj_t * chart, const char * list_of_values, uint8_t num_tick_marks,
lv_chart_axis_options_t options);
/**
* Set the y-axis tick count and labels of a chart
* @param chart pointer to a chart object
* @param list_of_values list of string values, terminated with \n, except the last
* @param num_tick_marks if list_of_values is NULL: total number of ticks per axis
* else number of ticks between two value labels
* @param options extra options
*/
void lv_chart_set_y_tick_texts(lv_obj_t * chart, const char * list_of_values, uint8_t num_tick_marks,
lv_chart_axis_options_t options);
void lv_chart_set_tick_label_cb(lv_obj_t * chart, lv_chart_tick_label_cb_t tick_label_cb, lv_coord_t ext_size);
/**
* Set the index of the x-axis start point in the data array

View File

@ -135,8 +135,7 @@ static void lv_checkbox_constructor(lv_obj_t * obj, lv_obj_t * parent, const lv_
{
LV_LOG_TRACE("lv_checkbox create started");
LV_CLASS_CONSTRUCTOR_BEGIN(obj, lv_checkbox)
lv_obj.constructor(obj, parent, copy);
lv_obj_construct_base(obj, parent, copy);
lv_checkbox_t * cb = (lv_checkbox_t *) obj;
/*Create the ancestor basic object*/
@ -153,8 +152,6 @@ static void lv_checkbox_constructor(lv_obj_t * obj, lv_obj_t * parent, const lv_
// const lv_checkbox_t * copy_ext = (const lv_checkbox_t *)copy;
}
LV_CLASS_CONSTRUCTOR_END(obj, lv_checkbox)
LV_LOG_INFO("lv_checkbox created");
}
@ -170,7 +167,7 @@ static void lv_checkbox_destructor(lv_obj_t * obj)
// bar->class_p->base_p->destructor(obj);
}
int cnt = 0;
/**
* Handle the drawing related tasks of the check box
* @param cb pointer to a check box object
@ -204,16 +201,8 @@ static lv_design_res_t lv_checkbox_design(lv_obj_t * obj, const lv_area_t * clip
lv_coord_t marker_topp = lv_obj_get_style_pad_top(obj, LV_PART_MARKER);
lv_coord_t marker_bottomp = lv_obj_get_style_pad_bottom(obj, LV_PART_MARKER);
lv_coord_t tranf_w = lv_obj_get_style_transform_width(obj, LV_PART_MARKER);
lv_coord_t tranf_h = lv_obj_get_style_transform_height(obj, LV_PART_MARKER);
if(tranf_h == 2) {
lv_coord_t tranf_h2 = lv_obj_get_style_transform_height(obj, LV_PART_MARKER);
}
cnt++;
if(cnt == 2) {
cnt = 100;
}
lv_coord_t transf_w = lv_obj_get_style_transform_width(obj, LV_PART_MARKER);
lv_coord_t transf_h = lv_obj_get_style_transform_height(obj, LV_PART_MARKER);
lv_draw_rect_dsc_t marker_dsc;
lv_draw_rect_dsc_init(&marker_dsc);
@ -224,13 +213,12 @@ static lv_design_res_t lv_checkbox_design(lv_obj_t * obj, const lv_area_t * clip
marker_area.y1 = obj->coords.y1 + bg_topp;
marker_area.y2 = marker_area.y1 + font_h + marker_topp + marker_bottomp - 1;
printf("%d, %d\n", tranf_h, 0);
lv_area_t marker_area_transf;
lv_area_copy(&marker_area_transf, &marker_area);
marker_area_transf.x1 -= tranf_w;
marker_area_transf.x2 += tranf_w;
marker_area_transf.y1 -= tranf_h;
marker_area_transf.y2 += tranf_h;
marker_area_transf.x1 -= transf_w;
marker_area_transf.x2 += transf_w;
marker_area_transf.y1 -= transf_h;
marker_area_transf.y2 += transf_h;
lv_draw_rect(&marker_area_transf, clip_area, &marker_dsc);
lv_coord_t line_space = lv_obj_get_style_text_line_space(obj, LV_PART_MAIN);

File diff suppressed because it is too large Load Diff

View File

@ -1,274 +1,264 @@
/**
* @file lv_gauge.h
*
*/
#ifndef LV_GAUGE_H
#define LV_GAUGE_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#include "../lv_conf_internal.h"
#if LV_USE_GAUGE != 0
/*Testing of dependencies*/
#if LV_USE_LINEMETER == 0
#error "lv_gauge: lv_linemeter is required. Enable it in lv_conf.h (LV_USE_LINEMETER 1) "
#endif
#include "../lv_core/lv_obj.h"
#include "lv_linemeter.h"
#include "lv_label.h"
#include "lv_line.h"
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
typedef void (*lv_gauge_format_cb_t)(lv_obj_t * gauge, char * buf, int bufsize, int32_t value);
/*Data of gauge*/
typedef struct {
lv_linemeter_ext_t lmeter; /*Ext. of ancestor*/
/*New data for this type */
int32_t * values; /*Array of the set values (for needles) */
const lv_color_t * needle_colors; /*Color of the needles (lv_color_t my_colors[needle_num])*/
const void * needle_img;
lv_point_t needle_img_pivot;
lv_style_list_t style_needle;
lv_style_list_t style_strong;
uint8_t needle_count; /*Number of needles*/
uint8_t label_count; /*Number of labels on the scale*/
lv_gauge_format_cb_t format_cb;
} lv_gauge_ext_t;
/*Styles*/
enum {
LV_GAUGE_PART_MAIN = LV_LINEMETER_PART_MAIN,
LV_GAUGE_PART_MAJOR = _LV_LINEMETER_PART_VIRTUAL_LAST,
LV_GAUGE_PART_NEEDLE,
_LV_GAUGE_PART_VIRTUAL_LAST = _LV_LINEMETER_PART_VIRTUAL_LAST,
};
typedef uint8_t lv_gauge_style_t;
/**********************
* GLOBAL PROTOTYPES
**********************/
/**
* Create a gauge objects
* @param par pointer to an object, it will be the parent of the new gauge
* @param copy pointer to a gauge object, if not NULL then the new object will be copied from it
* @return pointer to the created gauge
*/
lv_obj_t * lv_gauge_create(lv_obj_t * par, const lv_obj_t * copy);
/*=====================
* Setter functions
*====================*/
/**
* Set the number of needles
* @param gauge pointer to gauge object
* @param needle_cnt new count of needles
* @param colors an array of colors for needles (with 'num' elements)
*/
void lv_gauge_set_needle_count(lv_obj_t * gauge, uint8_t needle_cnt, const lv_color_t colors[]);
/**
* Set the value of a needle
* @param gauge pointer to a gauge
* @param needle_id the id of the needle
* @param value the new value
*/
void lv_gauge_set_value(lv_obj_t * gauge, uint8_t needle_id, int32_t value);
/**
* Set minimum and the maximum values of a gauge
* @param gauge pointer to he gauge object
* @param min minimum value
* @param max maximum value
*/
static inline void lv_gauge_set_range(lv_obj_t * gauge, int32_t min, int32_t max)
{
lv_linemeter_set_range(gauge, min, max);
}
/**
* Set a critical value on the scale. After this value 'line.color' scale lines will be drawn
* @param gauge pointer to a gauge object
* @param value the critical value
*/
static inline void lv_gauge_set_critical_value(lv_obj_t * gauge, int32_t value)
{
lv_linemeter_set_value(gauge, value);
}
/**
* Set the scale settings of a gauge
* @param gauge pointer to a gauge object
* @param angle angle of the scale (0..360)
* @param line_cnt count of scale lines.
* To get a given "subdivision" lines between labels:
* `line_cnt = (sub_div + 1) * (label_cnt - 1) + 1 `
* @param label_cnt count of scale labels.
*/
void lv_gauge_set_scale(lv_obj_t * gauge, uint16_t angle, uint8_t line_cnt, uint8_t label_cnt);
/**
* Set the set an offset for the gauge's angles to rotate it.
* @param gauge pointer to a line meter object
* @param angle angle offset (0..360), rotates clockwise
*/
static inline void lv_gauge_set_angle_offset(lv_obj_t * gauge, uint16_t angle)
{
lv_linemeter_set_angle_offset(gauge, angle);
}
/**
* Set an image to display as needle(s).
* The needle image should be horizontal and pointing to the right (`--->`).
* @param gauge pointer to a gauge object
* @param img_src pointer to an `lv_img_dsc_t` variable or a path to an image
* (not an `lv_img` object)
* @param pivot_x the X coordinate of rotation center of the image
* @param pivot_y the Y coordinate of rotation center of the image
*/
void lv_gauge_set_needle_img(lv_obj_t * gauge, const void * img, lv_coord_t pivot_x, lv_coord_t pivot_y);
/**
* Assign a function to format gauge values
* @param gauge pointer to a gauge object
* @param format_cb pointer to function of lv_gauge_format_cb_t
*/
void lv_gauge_set_formatter_cb(lv_obj_t * gauge, lv_gauge_format_cb_t format_cb);
/*=====================
* Getter functions
*====================*/
/**
* Get the value of a needle
* @param gauge pointer to gauge object
* @param needle the id of the needle
* @return the value of the needle [min,max]
*/
int32_t lv_gauge_get_value(const lv_obj_t * gauge, uint8_t needle);
/**
* Get the count of needles on a gauge
* @param gauge pointer to gauge
* @return count of needles
*/
uint8_t lv_gauge_get_needle_count(const lv_obj_t * gauge);
/**
* Get the minimum value of a gauge
* @param gauge pointer to a gauge object
* @return the minimum value of the gauge
*/
static inline int32_t lv_gauge_get_min_value(const lv_obj_t * lmeter)
{
return lv_linemeter_get_min_value(lmeter);
}
/**
* Get the maximum value of a gauge
* @param gauge pointer to a gauge object
* @return the maximum value of the gauge
*/
static inline int32_t lv_gauge_get_max_value(const lv_obj_t * lmeter)
{
return lv_linemeter_get_max_value(lmeter);
}
/**
* Get a critical value on the scale.
* @param gauge pointer to a gauge object
* @return the critical value
*/
static inline int32_t lv_gauge_get_critical_value(const lv_obj_t * gauge)
{
return lv_linemeter_get_value(gauge);
}
/**
* Set the number of labels (and the thicker lines too)
* @param gauge pointer to a gauge object
* @return count of labels
*/
uint8_t lv_gauge_get_label_count(const lv_obj_t * gauge);
/**
* Get the scale number of a gauge
* @param gauge pointer to a gauge object
* @return number of the scale units
*/
static inline uint16_t lv_gauge_get_line_count(const lv_obj_t * gauge)
{
return lv_linemeter_get_line_count(gauge);
}
/**
* Get the scale angle of a gauge
* @param gauge pointer to a gauge object
* @return angle of the scale
*/
static inline uint16_t lv_gauge_get_scale_angle(const lv_obj_t * gauge)
{
return lv_linemeter_get_scale_angle(gauge);
}
/**
* Get the offset for the gauge.
* @param gauge pointer to a gauge object
* @return angle offset (0..360)
*/
static inline uint16_t lv_gauge_get_angle_offset(lv_obj_t * gauge)
{
return lv_linemeter_get_angle_offset(gauge);
}
/**
* Get an image to display as needle(s).
* @param gauge pointer to a gauge object
* @return pointer to an `lv_img_dsc_t` variable or a path to an image
* (not an `lv_img` object). `NULL` if not used.
*/
const void * lv_gauge_get_needle_img(lv_obj_t * gauge);
/**
* Get the X coordinate of the rotation center of the needle image
* @param gauge pointer to a gauge object
* @return the X coordinate of rotation center of the image
*/
lv_coord_t lv_gauge_get_needle_img_pivot_x(lv_obj_t * gauge);
/**
* Get the Y coordinate of the rotation center of the needle image
* @param gauge pointer to a gauge object
* @return the X coordinate of rotation center of the image
*/
lv_coord_t lv_gauge_get_needle_img_pivot_y(lv_obj_t * gauge);
/**********************
* MACROS
**********************/
#endif /*LV_USE_GAUGE*/
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /*LV_GAUGE_H*/
///**
// * @file lv_gauge.h
// *
// */
//
//#ifndef LV_GAUGE_H
//#define LV_GAUGE_H
//
//#ifdef __cplusplus
//extern "C" {
//#endif
//
///*********************
// * INCLUDES
// *********************/
//#include "../lv_conf_internal.h"
//
//#if LV_USE_GAUGE != 0
//
///*Testing of dependencies*/
//#if LV_USE_LINEMETER == 0
//#error "lv_gauge: lv_linemeter is required. Enable it in lv_conf.h (LV_USE_LINEMETER 1) "
//#endif
//
//#include "../lv_core/lv_obj.h"
//#include "lv_linemeter.h"
//#include "lv_label.h"
//#include "lv_line.h"
//
///*********************
// * DEFINES
// *********************/
//
///**********************
// * TYPEDEFS
// **********************/
//
//typedef void (*lv_gauge_format_cb_t)(lv_obj_t * gauge, char * buf, int bufsize, int32_t value);
//
///*Data of gauge*/
//typedef struct {
// lv_linemeter_ext_t lmeter; /*Ext. of ancestor*/
// /*New data for this type */
// int32_t * values; /*Array of the set values (for needles) */
// const lv_color_t * needle_colors; /*Color of the needles (lv_color_t my_colors[needle_num])*/
// const void * needle_img;
// lv_point_t needle_img_pivot;
// uint8_t needle_count; /*Number of needles*/
// uint8_t label_count; /*Number of labels on the scale*/
// lv_gauge_format_cb_t format_cb;
//} lv_gauge_ext_t;
//
//
///**********************
// * GLOBAL PROTOTYPES
// **********************/
//
///**
// * Create a gauge objects
// * @param par pointer to an object, it will be the parent of the new gauge
// * @param copy pointer to a gauge object, if not NULL then the new object will be copied from it
// * @return pointer to the created gauge
// */
//lv_obj_t * lv_gauge_create(lv_obj_t * par, const lv_obj_t * copy);
//
///*=====================
// * Setter functions
// *====================*/
//
///**
// * Set the number of needles
// * @param gauge pointer to gauge object
// * @param needle_cnt new count of needles
// * @param colors an array of colors for needles (with 'num' elements)
// */
//void lv_gauge_set_needle_count(lv_obj_t * gauge, uint8_t needle_cnt, const lv_color_t colors[]);
//
///**
// * Set the value of a needle
// * @param gauge pointer to a gauge
// * @param needle_id the id of the needle
// * @param value the new value
// */
//void lv_gauge_set_value(lv_obj_t * gauge, uint8_t needle_id, int32_t value);
//
///**
// * Set minimum and the maximum values of a gauge
// * @param gauge pointer to he gauge object
// * @param min minimum value
// * @param max maximum value
// */
//static inline void lv_gauge_set_range(lv_obj_t * gauge, int32_t min, int32_t max)
//{
// lv_linemeter_set_range(gauge, min, max);
//}
//
///**
// * Set a critical value on the scale. After this value 'line.color' scale lines will be drawn
// * @param gauge pointer to a gauge object
// * @param value the critical value
// */
//static inline void lv_gauge_set_critical_value(lv_obj_t * gauge, int32_t value)
//{
// lv_linemeter_set_value(gauge, value);
//}
//
///**
// * Set the scale settings of a gauge
// * @param gauge pointer to a gauge object
// * @param angle angle of the scale (0..360)
// * @param line_cnt count of scale lines.
// * To get a given "subdivision" lines between labels:
// * `line_cnt = (sub_div + 1) * (label_cnt - 1) + 1 `
// * @param label_cnt count of scale labels.
// */
//void lv_gauge_set_scale(lv_obj_t * gauge, uint16_t angle, uint8_t line_cnt, uint8_t label_cnt);
//
///**
// * Set the set an offset for the gauge's angles to rotate it.
// * @param gauge pointer to a line meter object
// * @param angle angle offset (0..360), rotates clockwise
// */
//static inline void lv_gauge_set_angle_offset(lv_obj_t * gauge, uint16_t angle)
//{
// lv_linemeter_set_angle_offset(gauge, angle);
//}
//
///**
// * Set an image to display as needle(s).
// * The needle image should be horizontal and pointing to the right (`--->`).
// * @param gauge pointer to a gauge object
// * @param img_src pointer to an `lv_img_dsc_t` variable or a path to an image
// * (not an `lv_img` object)
// * @param pivot_x the X coordinate of rotation center of the image
// * @param pivot_y the Y coordinate of rotation center of the image
// */
//void lv_gauge_set_needle_img(lv_obj_t * gauge, const void * img, lv_coord_t pivot_x, lv_coord_t pivot_y);
//
///**
// * Assign a function to format gauge values
// * @param gauge pointer to a gauge object
// * @param format_cb pointer to function of lv_gauge_format_cb_t
// */
//void lv_gauge_set_formatter_cb(lv_obj_t * gauge, lv_gauge_format_cb_t format_cb);
//
///*=====================
// * Getter functions
// *====================*/
//
///**
// * Get the value of a needle
// * @param gauge pointer to gauge object
// * @param needle the id of the needle
// * @return the value of the needle [min,max]
// */
//int32_t lv_gauge_get_value(const lv_obj_t * gauge, uint8_t needle);
//
///**
// * Get the count of needles on a gauge
// * @param gauge pointer to gauge
// * @return count of needles
// */
//uint8_t lv_gauge_get_needle_count(const lv_obj_t * gauge);
//
///**
// * Get the minimum value of a gauge
// * @param gauge pointer to a gauge object
// * @return the minimum value of the gauge
// */
//static inline int32_t lv_gauge_get_min_value(const lv_obj_t * lmeter)
//{
// return lv_linemeter_get_min_value(lmeter);
//}
//
///**
// * Get the maximum value of a gauge
// * @param gauge pointer to a gauge object
// * @return the maximum value of the gauge
// */
//static inline int32_t lv_gauge_get_max_value(const lv_obj_t * lmeter)
//{
// return lv_linemeter_get_max_value(lmeter);
//}
//
///**
// * Get a critical value on the scale.
// * @param gauge pointer to a gauge object
// * @return the critical value
// */
//static inline int32_t lv_gauge_get_critical_value(const lv_obj_t * gauge)
//{
// return lv_linemeter_get_value(gauge);
//}
//
///**
// * Set the number of labels (and the thicker lines too)
// * @param gauge pointer to a gauge object
// * @return count of labels
// */
//uint8_t lv_gauge_get_label_count(const lv_obj_t * gauge);
//
///**
// * Get the scale number of a gauge
// * @param gauge pointer to a gauge object
// * @return number of the scale units
// */
//static inline uint16_t lv_gauge_get_line_count(const lv_obj_t * gauge)
//{
// return lv_linemeter_get_line_count(gauge);
//}
//
///**
// * Get the scale angle of a gauge
// * @param gauge pointer to a gauge object
// * @return angle of the scale
// */
//static inline uint16_t lv_gauge_get_scale_angle(const lv_obj_t * gauge)
//{
// return lv_linemeter_get_scale_angle(gauge);
//}
//
///**
// * Get the offset for the gauge.
// * @param gauge pointer to a gauge object
// * @return angle offset (0..360)
// */
//static inline uint16_t lv_gauge_get_angle_offset(lv_obj_t * gauge)
//{
// return lv_linemeter_get_angle_offset(gauge);
//}
//
///**
// * Get an image to display as needle(s).
// * @param gauge pointer to a gauge object
// * @return pointer to an `lv_img_dsc_t` variable or a path to an image
// * (not an `lv_img` object). `NULL` if not used.
// */
//const void * lv_gauge_get_needle_img(lv_obj_t * gauge);
//
///**
// * Get the X coordinate of the rotation center of the needle image
// * @param gauge pointer to a gauge object
// * @return the X coordinate of rotation center of the image
// */
//lv_coord_t lv_gauge_get_needle_img_pivot_x(lv_obj_t * gauge);
//
///**
// * Get the Y coordinate of the rotation center of the needle image
// * @param gauge pointer to a gauge object
// * @return the X coordinate of rotation center of the image
// */
//lv_coord_t lv_gauge_get_needle_img_pivot_y(lv_obj_t * gauge);
//
///**********************
// * MACROS
// **********************/
//
//#endif /*LV_USE_GAUGE*/
//
//#ifdef __cplusplus
//} /* extern "C" */
//#endif
//
//#endif /*LV_GAUGE_H*/

File diff suppressed because it is too large Load Diff

View File

@ -31,8 +31,7 @@ extern "C" {
**********************/
/*Data of image*/
typedef struct {
/*No inherited ext. because inherited from the base object*/ /*Ext. of ancestor*/
/*New data for this type */
lv_obj_t obj;
const void * src; /*Image source: Pointer to an array or a file or a symbol*/
lv_point_t offset;
lv_coord_t w; /*Width of the image (Handled by the library)*/
@ -43,13 +42,9 @@ typedef struct {
uint8_t src_type : 2; /*See: lv_img_src_t*/
uint8_t cf : 5; /*Color format from `lv_img_color_format_t`*/
uint8_t antialias : 1; /*Apply anti-aliasing in transformations (rotate, zoom)*/
} lv_img_ext_t;
} lv_img_t;
/*Image parts*/
enum {
LV_IMG_PART_MAIN,
};
typedef uint8_t lv_img_part_t;
extern const lv_obj_class_t lv_img;
/**********************
* GLOBAL PROTOTYPES

View File

@ -400,7 +400,7 @@ void lv_label_get_letter_pos(const lv_obj_t * obj, uint32_t char_id, lv_point_t
line_start = new_line_start;
}
/*If the last character is line break then go to the nlabel line*/
/*If the last character is line break then go to the next line*/
if(byte_id > 0) {
if((txt[byte_id - 1] == '\n' || txt[byte_id - 1] == '\r') && txt[byte_id] == '\0') {
y += letter_height + line_space;
@ -548,8 +548,8 @@ uint32_t lv_label_get_letter_on(const lv_obj_t * obj, lv_point_t * pos_in)
/* Get the current letter.*/
uint32_t letter = _lv_txt_encoded_next(bidi_txt, &i);
/*Get the nlabel letter too for kerning*/
uint32_t letter_nlabel = _lv_txt_encoded_next(&bidi_txt[i], NULL);
/*Get the next letter too for kerning*/
uint32_t letter_next = _lv_txt_encoded_next(&bidi_txt[i], NULL);
/*Handle the recolor command*/
if((flag & LV_TEXT_FLAG_RECOLOR) != 0) {
@ -558,9 +558,9 @@ uint32_t lv_label_get_letter_on(const lv_obj_t * obj, lv_point_t * pos_in)
}
}
lv_coord_t gw = lv_font_get_glyph_width(font, letter, letter_nlabel);
lv_coord_t gw = lv_font_get_glyph_width(font, letter, letter_next);
/*Finish if the x position or the last char of the nlabel line is reached*/
/*Finish if the x position or the last char of the next line is reached*/
if(pos.x < x + gw || i + line_start == new_line_start || txt[i_act + line_start] == '\0') {
i = i_act;
break;
@ -634,91 +634,91 @@ uint32_t lv_label_get_text_sel_end(const lv_obj_t * obj)
* @param pos Point to check for character under
* @return whether a character is drawn under the point
*/
//bool lv_label_is_char_under_pos(const lv_obj_t * label, lv_point_t * pos)
//{
// LV_ASSERT_OBJ(label, LV_OBJX_NAME);
// LV_ASSERT_NULL(pos);
//
// lv_area_t txt_coords;
// get_txt_coords(label, &txt_coords);
// const char * txt = lv_label_get_text(obj);
// lv_label_label_t * label = lv_obj_get_label_attr(label);
// uint32_t line_start = 0;
// uint32_t new_line_start = 0;
// lv_coord_t max_w = lv_area_get_width(&txt_coords);
// const lv_font_t * font = lv_obj_get_style_text_font(obj, LV_PART_MAIN);
// lv_coord_t line_space = lv_obj_get_style_text_line_space(obj, LV_PART_MAIN);
// lv_coord_t letter_space = lv_obj_get_style_text_letter_space(obj, LV_PART_MAIN);
// lv_coord_t letter_height = lv_font_get_line_height(font);
// lv_coord_t y = 0;
// lv_text_flag_t flag = LV_TEXT_FLAG_NONE;
// lv_text_align_t align = lv_label_get_align(label);
//
// if(label->recolor != 0) flag |= LV_TEXT_FLAG_RECOLOR;
// if(label->expand != 0) flag |= LV_TEXT_FLAG_EXPAND;
// if(label->long_mode == LV_LABEL_LONG_EXPAND) flag |= LV_TEXT_FLAG_FIT;
// if(align == LV_TEXT_ALIGN_CENTER) flag |= LV_TEXT_FLAG_CENTER;
//
// /*Search the line of the index letter */;
// while(txt[line_start] != '\0') {
// new_line_start += _lv_txt_get_next_line(&txt[line_start], font, letter_space, max_w, flag);
//
// if(pos->y <= y + letter_height) break; /*The line is found (stored in 'line_start')*/
// y += letter_height + line_space;
//
// line_start = new_line_start;
// }
//
// /*Calculate the x coordinate*/
// lv_coord_t x = 0;
// lv_coord_t last_x = 0;
// if(align == LV_TEXT_ALIGN_CENTER) {
// lv_coord_t line_w;
// line_w = _lv_txt_get_width(&txt[line_start], new_line_start - line_start, font, letter_space, flag);
// x += lv_area_get_width(&txt_coords) / 2 - line_w / 2;
// }
// else if(align == LV_TEXT_ALIGN_RIGHT) {
// lv_coord_t line_w;
// line_w = _lv_txt_get_width(&txt[line_start], new_line_start - line_start, font, letter_space, flag);
// x += lv_area_get_width(&txt_coords) - line_w;
// }
//
// lv_text_cmd_state_t cmd_state = LV_TEXT_CMD_STATE_WAIT;
//
// uint32_t i = line_start;
// uint32_t i_current = i;
// uint32_t letter = '\0';
// uint32_t letter_nlabel = '\0';
//
// if(new_line_start > 0) {
// while(i <= new_line_start - 1) {
// /* Get the current letter
// * Be careful 'i' already points to the nlabel character */
// letter = _lv_txt_encoded_next(txt, &i);
//
// /*Get the nlabel letter for kerning*/
// letter_nlabel = _lv_txt_encoded_next(&txt[i], NULL);
//
// /*Handle the recolor command*/
// if((flag & LV_TEXT_FLAG_RECOLOR) != 0) {
// if(_lv_txt_is_cmd(&cmd_state, txt[i]) != false) {
// continue; /*Skip the letter is it is part of a command*/
// }
// }
// last_x = x;
// x += lv_font_get_glyph_width(font, letter, letter_nlabel);
// if(pos->x < x) {
// i = i_current;
// break;
// }
// x += letter_space;
// i_current = i;
// }
// }
//
// int32_t max_diff = lv_font_get_glyph_width(font, letter, letter_nlabel) + letter_space + 1;
// return (pos->x >= (last_x - letter_space) && pos->x <= (last_x + max_diff));
//}
bool lv_label_is_char_under_pos(const lv_obj_t * obj, lv_point_t * pos)
{
LV_ASSERT_OBJ(obj, LV_OBJX_NAME);
LV_ASSERT_NULL(pos);
lv_area_t txt_coords;
get_txt_coords(obj, &txt_coords);
const char * txt = lv_label_get_text(obj);
lv_label_t * label = (lv_label_t*)obj;
uint32_t line_start = 0;
uint32_t new_line_start = 0;
lv_coord_t max_w = lv_area_get_width(&txt_coords);
const lv_font_t * font = lv_obj_get_style_text_font(obj, LV_PART_MAIN);
lv_coord_t line_space = lv_obj_get_style_text_line_space(obj, LV_PART_MAIN);
lv_coord_t letter_space = lv_obj_get_style_text_letter_space(obj, LV_PART_MAIN);
lv_coord_t letter_height = lv_font_get_line_height(font);
lv_text_align_t align = lv_obj_get_style_text_align(obj, LV_PART_MAIN);
lv_coord_t y = 0;
lv_text_flag_t flag = LV_TEXT_FLAG_NONE;
if(label->recolor != 0) flag |= LV_TEXT_FLAG_RECOLOR;
if(label->expand != 0) flag |= LV_TEXT_FLAG_EXPAND;
if(label->long_mode == LV_LABEL_LONG_EXPAND) flag |= LV_TEXT_FLAG_FIT;
if(align == LV_TEXT_ALIGN_CENTER) flag |= LV_TEXT_FLAG_CENTER;
/*Search the line of the index letter */;
while(txt[line_start] != '\0') {
new_line_start += _lv_txt_get_next_line(&txt[line_start], font, letter_space, max_w, flag);
if(pos->y <= y + letter_height) break; /*The line is found (stored in 'line_start')*/
y += letter_height + line_space;
line_start = new_line_start;
}
/*Calculate the x coordinate*/
lv_coord_t x = 0;
lv_coord_t last_x = 0;
if(align == LV_TEXT_ALIGN_CENTER) {
lv_coord_t line_w;
line_w = _lv_txt_get_width(&txt[line_start], new_line_start - line_start, font, letter_space, flag);
x += lv_area_get_width(&txt_coords) / 2 - line_w / 2;
}
else if(align == LV_TEXT_ALIGN_RIGHT) {
lv_coord_t line_w;
line_w = _lv_txt_get_width(&txt[line_start], new_line_start - line_start, font, letter_space, flag);
x += lv_area_get_width(&txt_coords) - line_w;
}
lv_text_cmd_state_t cmd_state = LV_TEXT_CMD_STATE_WAIT;
uint32_t i = line_start;
uint32_t i_current = i;
uint32_t letter = '\0';
uint32_t letter_next = '\0';
if(new_line_start > 0) {
while(i <= new_line_start - 1) {
/* Get the current letter
* Be careful 'i' already points to the next character */
letter = _lv_txt_encoded_next(txt, &i);
/*Get the next letter for kerning*/
letter_next = _lv_txt_encoded_next(&txt[i], NULL);
/*Handle the recolor command*/
if((flag & LV_TEXT_FLAG_RECOLOR) != 0) {
if(_lv_txt_is_cmd(&cmd_state, txt[i]) != false) {
continue; /*Skip the letter is it is part of a command*/
}
}
last_x = x;
x += lv_font_get_glyph_width(font, letter, letter_next);
if(pos->x < x) {
i = i_current;
break;
}
x += letter_space;
i_current = i;
}
}
int32_t max_diff = lv_font_get_glyph_width(font, letter, letter_next) + letter_space + 1;
return (pos->x >= (last_x - letter_space) && pos->x <= (last_x + max_diff));
}
/*=====================
* Other functions
@ -1040,8 +1040,7 @@ static void lv_label_constructor(lv_obj_t * obj, lv_obj_t * parent, const lv_obj
{
LV_LOG_TRACE("label create started");
LV_CLASS_CONSTRUCTOR_BEGIN(obj, lv_label)
lv_obj.constructor(obj, parent, copy);
lv_obj_construct_base(obj, parent, copy);
lv_label_t * label = (lv_label_t *)obj;
@ -1070,8 +1069,6 @@ static void lv_label_constructor(lv_obj_t * obj, lv_obj_t * parent, const lv_obj
lv_label_set_long_mode(obj, LV_LABEL_LONG_EXPAND);
lv_label_set_text(obj, "Text");
LV_CLASS_CONSTRUCTOR_END(obj, lv_label)
LV_LOG_INFO("label created");
}

View File

@ -29,13 +29,22 @@
/**********************
* STATIC PROTOTYPES
**********************/
static lv_design_res_t lv_line_design(lv_obj_t * line, const lv_area_t * clip_area, lv_design_mode_t mode);
static lv_res_t lv_line_signal(lv_obj_t * line, lv_signal_t sign, void * param);
static void lv_line_constructor(lv_obj_t * obj, lv_obj_t * parent, const lv_obj_t * copy);
static void lv_line_destructor(lv_obj_t * obj);
static lv_design_res_t lv_line_design(lv_obj_t * obj, const lv_area_t * clip_area, lv_design_mode_t mode);
static lv_res_t lv_line_signal(lv_obj_t * obj, lv_signal_t sign, void * param);
/**********************
* STATIC VARIABLES
**********************/
static lv_signal_cb_t ancestor_signal;
const lv_obj_class_t lv_line = {
.constructor = lv_line_constructor,
.destructor = lv_line_destructor,
.signal_cb = lv_line_signal,
.design_cb = lv_line_design,
.instance_size = sizeof(lv_line_t),
.base_class = &lv_obj
};
/**********************
* MACROS
@ -50,52 +59,9 @@ static lv_signal_cb_t ancestor_signal;
* @param par pointer to an object, it will be the parent of the new line
* @return pointer to the created line
*/
lv_obj_t * lv_line_create(lv_obj_t * par, const lv_obj_t * copy)
lv_obj_t * lv_line_create(lv_obj_t * parent, const lv_obj_t * copy)
{
LV_LOG_TRACE("line create started");
/*Create a basic object*/
lv_obj_t * line = lv_obj_create(par, copy);
LV_ASSERT_MEM(line);
if(line == NULL) return NULL;
if(ancestor_signal == NULL) ancestor_signal = lv_obj_get_signal_cb(line);
/*Extend the basic object to line object*/
lv_line_ext_t * ext = lv_obj_allocate_ext_attr(line, sizeof(lv_line_ext_t));
LV_ASSERT_MEM(ext);
if(ext == NULL) {
lv_obj_del(line);
return NULL;
}
ext->point_num = 0;
ext->point_array = NULL;
ext->y_inv = 0;
lv_obj_set_design_cb(line, lv_line_design);
lv_obj_set_signal_cb(line, lv_line_signal);
/*Init the new line*/
if(copy == NULL) {
lv_obj_set_size(line, LV_SIZE_AUTO, LV_SIZE_AUTO);
lv_obj_clear_flag(line, LV_OBJ_FLAG_CLICKABLE);
lv_theme_apply(line, LV_THEME_LINE);
}
/*Copy an existing object*/
else {
lv_line_ext_t * copy_ext = lv_obj_get_ext_attr(copy);
lv_line_set_y_invert(line, lv_line_get_y_invert(copy));
lv_line_set_points(line, copy_ext->point_array, copy_ext->point_num);
/*Refresh the style with new signal function*/
_lv_obj_refresh_style(line, LV_OBJ_PART_ALL, LV_STYLE_PROP_ALL);
}
LV_LOG_INFO("line created");
return line;
return lv_obj_create_from_class(&lv_line, parent, copy);
}
/*=====================
@ -109,17 +75,17 @@ lv_obj_t * lv_line_create(lv_obj_t * par, const lv_obj_t * copy)
* so the array can NOT be a local variable which will be destroyed
* @param point_num number of points in 'point_a'
*/
void lv_line_set_points(lv_obj_t * line, const lv_point_t point_a[], uint16_t point_num)
void lv_line_set_points(lv_obj_t * obj, const lv_point_t point_a[], uint16_t point_num)
{
LV_ASSERT_OBJ(line, LV_OBJX_NAME);
LV_ASSERT_OBJ(obj, LV_OBJX_NAME);
lv_line_ext_t * ext = lv_obj_get_ext_attr(line);
ext->point_array = point_a;
ext->point_num = point_num;
lv_line_t * line = (lv_line_t *) obj;
line->point_array = point_a;
line->point_num = point_num;
_lv_obj_handle_self_size_chg(line);
_lv_obj_handle_self_size_chg(obj);
lv_obj_invalidate(line);
lv_obj_invalidate(obj);
}
/**
@ -129,16 +95,16 @@ void lv_line_set_points(lv_obj_t * line, const lv_point_t point_a[], uint16_t po
* @param line pointer to a line object
* @param en true: enable the y inversion, false:disable the y inversion
*/
void lv_line_set_y_invert(lv_obj_t * line, bool en)
void lv_line_set_y_invert(lv_obj_t * obj, bool en)
{
LV_ASSERT_OBJ(line, LV_OBJX_NAME);
LV_ASSERT_OBJ(obj, LV_OBJX_NAME);
lv_line_ext_t * ext = lv_obj_get_ext_attr(line);
if(ext->y_inv == en) return;
lv_line_t * line = (lv_line_t *) obj;
if(line->y_inv == en) return;
ext->y_inv = en == false ? 0 : 1;
line->y_inv = en == false ? 0 : 1;
lv_obj_invalidate(line);
lv_obj_invalidate(obj);
}
/*=====================
@ -150,19 +116,52 @@ void lv_line_set_y_invert(lv_obj_t * line, bool en)
* @param line pointer to a line object
* @return true: y inversion is enabled, false: disabled
*/
bool lv_line_get_y_invert(const lv_obj_t * line)
bool lv_line_get_y_invert(const lv_obj_t * obj)
{
LV_ASSERT_OBJ(line, LV_OBJX_NAME);
LV_ASSERT_OBJ(obj, LV_OBJX_NAME);
lv_line_ext_t * ext = lv_obj_get_ext_attr(line);
lv_line_t * line = (lv_line_t *) obj;
return ext->y_inv == 0 ? false : true;
return line->y_inv == 0 ? false : true;
}
/**********************
* STATIC FUNCTIONS
**********************/
static void lv_line_constructor(lv_obj_t * obj, lv_obj_t * parent, const lv_obj_t * copy)
{
LV_LOG_TRACE("line create started");
lv_obj_construct_base(obj, parent, copy);
/*Create a basic object*/
lv_line_t * line = (lv_line_t *) obj;
line->point_num = 0;
line->point_array = NULL;
line->y_inv = 0;
/*Init the new line*/
if(copy == NULL) {
lv_obj_set_size(obj, LV_SIZE_AUTO, LV_SIZE_AUTO);
lv_obj_clear_flag(obj, LV_OBJ_FLAG_CLICKABLE);
}
/*Copy an existing object*/
else {
lv_line_t * copy_line = (lv_line_t *) copy;
lv_line_set_y_invert(obj, lv_line_get_y_invert(copy));
lv_line_set_points(obj, copy_line->point_array, copy_line->point_num);
}
LV_LOG_INFO("line created");
}
static void lv_line_destructor(lv_obj_t * obj)
{
}
/**
* Handle the drawing related tasks of the lines
* @param line pointer to an object
@ -173,47 +172,49 @@ bool lv_line_get_y_invert(const lv_obj_t * line)
* LV_DESIGN_DRAW_POST: drawing after every children are drawn
* @param return an element of `lv_design_res_t`
*/
static lv_design_res_t lv_line_design(lv_obj_t * line, const lv_area_t * clip_area, lv_design_mode_t mode)
static lv_design_res_t lv_line_design(lv_obj_t * obj, const lv_area_t * clip_area, lv_design_mode_t mode)
{
/*A line never covers an area*/
if(mode == LV_DESIGN_COVER_CHK)
return LV_DESIGN_RES_NOT_COVER;
else if(mode == LV_DESIGN_DRAW_MAIN) {
lv_line_ext_t * ext = lv_obj_get_ext_attr(line);
lv_obj.design_cb(obj, clip_area, mode);
lv_line_t * line = (lv_line_t *) obj;
if(ext->point_num == 0 || ext->point_array == NULL) return false;
if(line->point_num == 0 || line->point_array == NULL) return false;
lv_area_t area;
lv_obj_get_coords(line, &area);
lv_coord_t x_ofs = area.x1 - lv_obj_get_scroll_x(line);
lv_coord_t y_ofs = area.y1 - lv_obj_get_scroll_y(line);
lv_obj_get_coords(obj, &area);
lv_coord_t x_ofs = area.x1 - lv_obj_get_scroll_x(obj);
lv_coord_t y_ofs = area.y1 - lv_obj_get_scroll_y(obj);
lv_point_t p1;
lv_point_t p2;
lv_coord_t h = lv_obj_get_height(line);
lv_coord_t h = lv_obj_get_height(obj);
uint16_t i;
lv_draw_line_dsc_t line_dsc;
lv_draw_line_dsc_init(&line_dsc);
lv_obj_init_draw_line_dsc(line, LV_LINE_PART_MAIN, &line_dsc);
lv_obj_init_draw_line_dsc(obj, LV_PART_MAIN, &line_dsc);
/*Read all points and draw the lines*/
for(i = 0; i < ext->point_num - 1; i++) {
for(i = 0; i < line->point_num - 1; i++) {
p1.x = ext->point_array[i].x + x_ofs;
p2.x = ext->point_array[i + 1].x + x_ofs;
p1.x = line->point_array[i].x + x_ofs;
p2.x = line->point_array[i + 1].x + x_ofs;
if(ext->y_inv == 0) {
p1.y = ext->point_array[i].y + y_ofs;
p2.y = ext->point_array[i + 1].y + y_ofs;
if(line->y_inv == 0) {
p1.y = line->point_array[i].y + y_ofs;
p2.y = line->point_array[i + 1].y + y_ofs;
}
else {
p1.y = h - ext->point_array[i].y + y_ofs;
p2.y = h - ext->point_array[i + 1].y + y_ofs;
p1.y = h - line->point_array[i].y + y_ofs;
p2.y = h - line->point_array[i + 1].y + y_ofs;
}
lv_draw_line(&p1, &p2, clip_area, &line_dsc);
line_dsc.round_start = 0; /*Draw the rounding only on the end points after the first line*/
}
} else if (mode == LV_DESIGN_DRAW_POST) {
lv_obj.design_cb(obj, clip_area, mode);
}
return LV_DESIGN_RES_OK;
}
@ -224,36 +225,34 @@ static lv_design_res_t lv_line_design(lv_obj_t * line, const lv_area_t * clip_ar
* @param sign a signal type from lv_signal_t enum
* @return LV_RES_OK: the object is not deleted in the function; LV_RES_INV: the object is deleted
*/
static lv_res_t lv_line_signal(lv_obj_t * line, lv_signal_t sign, void * param)
static lv_res_t lv_line_signal(lv_obj_t * obj, lv_signal_t sign, void * param)
{
lv_res_t res;
/* Include the ancient signal function */
res = ancestor_signal(line, sign, param);
res = lv_obj.signal_cb(obj, sign, param);
if(res != LV_RES_OK) return res;
if(sign == LV_SIGNAL_GET_TYPE) {
return _lv_obj_handle_get_type_signal(param, LV_OBJX_NAME);
}
else if(sign == LV_SIGNAL_REFR_EXT_DRAW_PAD) {
if(sign == LV_SIGNAL_REFR_EXT_DRAW_PAD) {
/*The corner of the skew lines is out of the intended area*/
lv_coord_t line_width = lv_obj_get_style_line_width(line, LV_LINE_PART_MAIN);
lv_coord_t line_width = lv_obj_get_style_line_width(obj, LV_PART_MAIN);
lv_coord_t * s = param;
if(*s < line_width) *s = line_width;
}
else if(sign == LV_SIGNAL_GET_SELF_SIZE) {
lv_line_ext_t * ext = lv_obj_get_ext_attr(line);
lv_line_t * line = (lv_line_t *) obj;
lv_point_t * p = param;
lv_coord_t w = 0;
lv_coord_t h = 0;
if(ext->point_num > 0) {
if(line->point_num > 0) {
uint16_t i;
for(i = 0; i < ext->point_num; i++) {
w = LV_MATH_MAX(ext->point_array[i].x, w);
h = LV_MATH_MAX(ext->point_array[i].y, h);
for(i = 0; i < line->point_num; i++) {
w = LV_MATH_MAX(line->point_array[i].x, w);
h = LV_MATH_MAX(line->point_array[i].y, h);
}
lv_coord_t line_width = lv_obj_get_style_line_width(line, LV_LINE_PART_MAIN);
lv_coord_t line_width = lv_obj_get_style_line_width(obj, LV_PART_MAIN);
w += line_width;
h += line_width;
p->x = w;

View File

@ -29,17 +29,13 @@ extern "C" {
/*Data of line*/
typedef struct {
/*Inherited from 'base_obj' so no inherited ext.*/ /*Ext. of ancestor*/
lv_obj_t obj;
const lv_point_t * point_array; /*Pointer to an array with the points of the line*/
uint16_t point_num; /*Number of points in 'point_array' */
uint8_t y_inv : 1; /*1: y == 0 will be on the bottom*/
} lv_line_ext_t;
} lv_line_t;
/*Styles*/
enum {
LV_LINE_PART_MAIN,
};
typedef uint8_t lv_line_style_t;
extern const lv_obj_class_t lv_line;
/**********************
* GLOBAL PROTOTYPES

View File

@ -7,7 +7,7 @@
* INCLUDES
*********************/
#include "lv_linemeter.h"
#if LV_USE_LINEMETER != 0
#if LV_USE_METER != 0
#include "../lv_misc/lv_debug.h"
#include "../lv_draw/lv_draw.h"
@ -27,13 +27,25 @@
/**********************
* STATIC PROTOTYPES
**********************/
static lv_design_res_t lv_linemeter_design(lv_obj_t * lmeter, const lv_area_t * clip_area, lv_design_mode_t mode);
static lv_res_t lv_linemeter_signal(lv_obj_t * lmeter, lv_signal_t sign, void * param);
static void lv_meter_constructor(lv_obj_t * obj, lv_obj_t * parent, const lv_obj_t * copy);
static void lv_meter_destructor(lv_obj_t * obj);
static lv_design_res_t lv_meter_design(lv_obj_t * lmeter, const lv_area_t * clip_area, lv_design_mode_t mode);
static lv_res_t lv_meter_signal(lv_obj_t * lmeter, lv_signal_t sign, void * param);
static void draw_arcs(lv_obj_t * obj, const lv_area_t * clip_area, const lv_area_t * scale_area);
static void draw_lines_and_labels(lv_obj_t * obj, const lv_area_t * clip_area, const lv_area_t * scale_area);
static void draw_needles(lv_obj_t * obj, const lv_area_t * clip_area, const lv_area_t * scale_area);
/**********************
* STATIC VARIABLES
**********************/
static lv_signal_cb_t ancestor_signal;
const lv_obj_class_t lv_meter = {
.constructor = lv_meter_constructor,
.destructor = lv_meter_destructor,
.signal_cb = lv_meter_signal,
.design_cb = lv_meter_design,
.instance_size = sizeof(lv_meter_t),
.base_class = &lv_obj
};
/**********************
* MACROS
@ -50,59 +62,9 @@ static lv_signal_cb_t ancestor_signal;
* it
* @return pointer to the created line meter
*/
lv_obj_t * lv_linemeter_create(lv_obj_t * par, const lv_obj_t * copy)
lv_obj_t * lv_meter_create(lv_obj_t * parent, const lv_obj_t * copy)
{
LV_LOG_TRACE("line meter create started");
/*Create the ancestor of line meter*/
lv_obj_t * linemeter = lv_obj_create(par, copy);
LV_ASSERT_MEM(linemeter);
if(linemeter == NULL) return NULL;
if(ancestor_signal == NULL) ancestor_signal = lv_obj_get_signal_cb(linemeter);
/*Allocate the line meter type specific extended data*/
lv_linemeter_ext_t * ext = lv_obj_allocate_ext_attr(linemeter, sizeof(lv_linemeter_ext_t));
LV_ASSERT_MEM(ext);
if(ext == NULL) {
lv_obj_del(linemeter);
return NULL;
}
/*Initialize the allocated 'ext' */
ext->min_value = 0;
ext->max_value = 100;
ext->cur_value = 0;
ext->line_cnt = 18;
ext->scale_angle = 240;
ext->angle_ofs = 0;
ext->mirrored = 0;
/*The signal and design functions are not copied so set them here*/
lv_obj_set_signal_cb(linemeter, lv_linemeter_signal);
lv_obj_set_design_cb(linemeter, lv_linemeter_design);
/*Init the new line meter line meter*/
if(copy == NULL) {
lv_obj_set_size(linemeter, 3 * LV_DPI / 2, 3 * LV_DPI / 2);
lv_theme_apply(linemeter, LV_THEME_LINEMETER);
}
/*Copy an existing line meter*/
else {
lv_linemeter_ext_t * copy_ext = lv_obj_get_ext_attr(copy);
ext->scale_angle = copy_ext->scale_angle;
ext->line_cnt = copy_ext->line_cnt;
ext->min_value = copy_ext->min_value;
ext->max_value = copy_ext->max_value;
ext->cur_value = copy_ext->cur_value;
/*Refresh the style with new signal function*/
_lv_obj_refresh_style(linemeter, LV_OBJ_PART_ALL, LV_STYLE_PROP_ALL);
}
LV_LOG_INFO("line meter created");
return linemeter;
return lv_obj_create_from_class(&lv_meter, parent, copy);
}
/*=====================
@ -114,26 +76,44 @@ lv_obj_t * lv_linemeter_create(lv_obj_t * par, const lv_obj_t * copy)
* @param lmeter pointer to a line meter object
* @param value new value
*/
void lv_linemeter_set_value(lv_obj_t * lmeter, int32_t value)
lv_meter_indicator_t * lv_meter_add_indicator(lv_obj_t * obj)
{
LV_ASSERT_OBJ(lmeter, LV_OBJX_NAME);
LV_ASSERT_OBJ(obj, LV_OBJX_NAME);
lv_linemeter_ext_t * ext = lv_obj_get_ext_attr(lmeter);
if(ext->cur_value == value) return;
lv_meter_t * meter = (lv_meter_t *) obj;
lv_meter_indicator_t * indic = _lv_ll_ins_head(&meter->indic_ll);
int32_t old_value = ext->cur_value;
indic->color = LV_COLOR_RED;
indic->img_src = NULL;
indic->value = 40;
indic->type = LV_METER_INDICATOR_TYPE_NEEDLE | LV_METER_INDICATOR_TYPE_ARC | LV_METER_INDICATOR_TYPE_SCALE;
ext->cur_value = value > ext->max_value ? ext->max_value : value;
ext->cur_value = ext->cur_value < ext->min_value ? ext->min_value : ext->cur_value;
return indic;
int16_t level_old =
(int32_t)((int32_t)(old_value - ext->min_value) * (ext->line_cnt - 1)) / (ext->max_value - ext->min_value);
int16_t level_new =
(int32_t)((int32_t)(ext->cur_value - ext->min_value) * (ext->line_cnt - 1)) / (ext->max_value - ext->min_value);
}
if(level_new == level_old) return;
lv_meter_segment_t * lv_meter_add_segment(lv_obj_t * obj)
{
LV_ASSERT_OBJ(obj, LV_OBJX_NAME);
lv_obj_invalidate(lmeter);
lv_meter_t * meter = (lv_meter_t *) obj;
lv_meter_segment_t * seg = _lv_ll_ins_head(&meter->segment_ll);
seg->color = LV_COLOR_BLUE;
seg->start_value = 20;
seg->end_value = 80;
seg->type = LV_METER_SEGMENT_TYPE_SCALE;
seg->width = 5;
return seg;
}
void lv_meter_set_value(lv_obj_t * obj, lv_meter_indicator_t * indic, int32_t value)
{
LV_ASSERT_OBJ(obj, LV_OBJX_NAME);
indic->value = value;
lv_obj_invalidate(obj);
}
/**
@ -142,24 +122,16 @@ void lv_linemeter_set_value(lv_obj_t * lmeter, int32_t value)
* @param min minimum value
* @param max maximum value
*/
void lv_linemeter_set_range(lv_obj_t * lmeter, int32_t min, int32_t max)
void lv_linemeter_set_range(lv_obj_t * obj, int32_t min, int32_t max)
{
LV_ASSERT_OBJ(lmeter, LV_OBJX_NAME);
LV_ASSERT_OBJ(obj, LV_OBJX_NAME);
lv_linemeter_ext_t * ext = lv_obj_get_ext_attr(lmeter);
if(ext->min_value == min && ext->max_value == max) return;
lv_meter_t * meter = (lv_meter_t *) obj;
if(meter->min_value == min && meter->max_value == max) return;
ext->max_value = max;
ext->min_value = min;
if(ext->cur_value > max) {
ext->cur_value = max;
lv_linemeter_set_value(lmeter, ext->cur_value);
}
if(ext->cur_value < min) {
ext->cur_value = min;
lv_linemeter_set_value(lmeter, ext->cur_value);
}
lv_obj_invalidate(lmeter);
meter->max_value = max;
meter->min_value = min;
lv_obj_invalidate(obj);
}
/**
@ -168,17 +140,17 @@ void lv_linemeter_set_range(lv_obj_t * lmeter, int32_t min, int32_t max)
* @param angle angle of the scale (0..360)
* @param line_cnt number of lines
*/
void lv_linemeter_set_scale(lv_obj_t * lmeter, uint16_t angle, uint16_t line_cnt)
void lv_linemeter_set_scale(lv_obj_t * obj, uint16_t angle, uint16_t line_cnt)
{
LV_ASSERT_OBJ(lmeter, LV_OBJX_NAME);
LV_ASSERT_OBJ(obj, LV_OBJX_NAME);
lv_meter_t * meter = (lv_meter_t *) obj;
lv_linemeter_ext_t * ext = lv_obj_get_ext_attr(lmeter);
if(ext->scale_angle == angle && ext->line_cnt == line_cnt) return;
if(meter->scale_angle == angle && meter->line_cnt == line_cnt) return;
ext->scale_angle = angle;
ext->line_cnt = line_cnt;
meter->scale_angle = angle;
meter->line_cnt = line_cnt;
lv_obj_invalidate(lmeter);
lv_obj_invalidate(obj);
}
/**
@ -186,29 +158,14 @@ void lv_linemeter_set_scale(lv_obj_t * lmeter, uint16_t angle, uint16_t line_cnt
* @param lmeter pointer to a line meter object
* @param angle angle where the meter will be facing (with its center)
*/
void lv_linemeter_set_angle_offset(lv_obj_t * lmeter, uint16_t angle)
void lv_linemeter_set_angle_offset(lv_obj_t * obj, uint16_t angle)
{
lv_linemeter_ext_t * ext = lv_obj_get_ext_attr(lmeter);
if(ext->angle_ofs == angle) return;
lv_meter_t * meter = (lv_meter_t *) obj;
if(meter->angle_ofs == angle) return;
ext->angle_ofs = angle;
meter->angle_ofs = angle;
lv_obj_invalidate(lmeter);
}
/**
* Set the orientation of the meter growth, clockwise or counterclockwise (mirrored)
* @param lmeter pointer to a line meter object
* @param mirror mirror setting
*/
void lv_linemeter_set_mirror(lv_obj_t * lmeter, bool mirror)
{
lv_linemeter_ext_t * ext = lv_obj_get_ext_attr(lmeter);
if(ext->mirrored == mirror) return;
ext->mirrored = mirror;
lv_obj_invalidate(lmeter);
lv_obj_invalidate(obj);
}
/*=====================
@ -220,12 +177,11 @@ void lv_linemeter_set_mirror(lv_obj_t * lmeter, bool mirror)
* @param lmeter pointer to a line meter object
* @return the value of the line meter
*/
int32_t lv_linemeter_get_value(const lv_obj_t * lmeter)
int32_t lv_meter_get_value(const lv_obj_t * obj, const lv_meter_indicator_t * indic)
{
LV_ASSERT_OBJ(lmeter, LV_OBJX_NAME);
LV_ASSERT_OBJ(obj, LV_OBJX_NAME);
lv_linemeter_ext_t * ext = lv_obj_get_ext_attr(lmeter);
return ext->cur_value;
return indic->value;
}
/**
@ -233,12 +189,11 @@ int32_t lv_linemeter_get_value(const lv_obj_t * lmeter)
* @param lmeter pointer to a line meter object
* @return the minimum value of the line meter
*/
int32_t lv_linemeter_get_min_value(const lv_obj_t * lmeter)
int32_t lv_meter_get_min_value(const lv_obj_t * obj)
{
LV_ASSERT_OBJ(lmeter, LV_OBJX_NAME);
lv_linemeter_ext_t * ext = lv_obj_get_ext_attr(lmeter);
return ext->min_value;
LV_ASSERT_OBJ(obj, LV_OBJX_NAME);
lv_meter_t * meter = (lv_meter_t *) obj;
return meter->min_value;
}
/**
@ -246,12 +201,11 @@ int32_t lv_linemeter_get_min_value(const lv_obj_t * lmeter)
* @param lmeter pointer to a line meter object
* @return the maximum value of the line meter
*/
int32_t lv_linemeter_get_max_value(const lv_obj_t * lmeter)
int32_t lv_meter_get_max_value(const lv_obj_t * obj)
{
LV_ASSERT_OBJ(lmeter, LV_OBJX_NAME);
lv_linemeter_ext_t * ext = lv_obj_get_ext_attr(lmeter);
return ext->max_value;
LV_ASSERT_OBJ(obj, LV_OBJX_NAME);
lv_meter_t * meter = (lv_meter_t *) obj;
return meter->max_value;
}
/**
@ -259,12 +213,11 @@ int32_t lv_linemeter_get_max_value(const lv_obj_t * lmeter)
* @param lmeter pointer to a line meter object
* @return number of the scale units
*/
uint16_t lv_linemeter_get_line_count(const lv_obj_t * lmeter)
uint16_t lv_linemeter_get_line_count(const lv_obj_t * obj)
{
LV_ASSERT_OBJ(lmeter, LV_OBJX_NAME);
lv_linemeter_ext_t * ext = lv_obj_get_ext_attr(lmeter);
return ext->line_cnt;
LV_ASSERT_OBJ(obj, LV_OBJX_NAME);
lv_meter_t * meter = (lv_meter_t *) obj;
return meter->line_cnt;
}
/**
@ -272,12 +225,11 @@ uint16_t lv_linemeter_get_line_count(const lv_obj_t * lmeter)
* @param lmeter pointer to a line meter object
* @return angle_ofs of the scale
*/
uint16_t lv_linemeter_get_scale_angle(const lv_obj_t * lmeter)
uint16_t lv_linemeter_get_scale_angle(const lv_obj_t * obj)
{
LV_ASSERT_OBJ(lmeter, LV_OBJX_NAME);
lv_linemeter_ext_t * ext = lv_obj_get_ext_attr(lmeter);
return ext->scale_angle;
LV_ASSERT_OBJ(obj, LV_OBJX_NAME);
lv_meter_t * meter = (lv_meter_t *) obj;
return meter->scale_angle;
}
/**
@ -285,218 +237,57 @@ uint16_t lv_linemeter_get_scale_angle(const lv_obj_t * lmeter)
* @param lmeter pointer to a line meter object
* @return angle offset (0..360)
*/
uint16_t lv_linemeter_get_angle_offset(lv_obj_t * lmeter)
uint16_t lv_linemeter_get_angle_offset(lv_obj_t * obj)
{
lv_linemeter_ext_t * ext = lv_obj_get_ext_attr(lmeter);
return ext->angle_ofs;
}
/**
* get the mirror setting for the line meter
* @param lmeter pointer to a line meter object
* @return mirror (true or false)
*/
bool lv_linemeter_get_mirror(lv_obj_t * lmeter)
{
lv_linemeter_ext_t * ext = lv_obj_get_ext_attr(lmeter);
return ext->mirrored;
}
void lv_linemeter_draw_scale(lv_obj_t * lmeter, const lv_area_t * clip_area, uint8_t part)
{
lv_linemeter_ext_t * ext = lv_obj_get_ext_attr(lmeter);
lv_coord_t left = lv_obj_get_style_pad_left(lmeter, LV_LINEMETER_PART_MAIN);
lv_coord_t right = lv_obj_get_style_pad_right(lmeter, LV_LINEMETER_PART_MAIN);
lv_coord_t top = lv_obj_get_style_pad_top(lmeter, LV_LINEMETER_PART_MAIN);
lv_coord_t r_out = (lv_obj_get_width(lmeter) - left - right) / 2 ;
lv_coord_t r_in = r_out - lv_obj_get_style_scale_width(lmeter, part);
if(r_in < 1) r_in = 1;
lv_coord_t x_ofs = lmeter->coords.x1 + r_out + left;
lv_coord_t y_ofs = lmeter->coords.y1 + r_out + top;
int16_t angle_ofs = ext->angle_ofs + 90 + (360 - ext->scale_angle) / 2;
int16_t level = ext->mirrored ?
(int32_t)((int32_t)(ext->max_value - ext->cur_value) * (ext->line_cnt - 1)) / (ext->max_value - ext->min_value) :
(int32_t)((int32_t)(ext->cur_value - ext->min_value) * (ext->line_cnt - 1)) / (ext->max_value - ext->min_value);
uint8_t i;
lv_color_t main_color = lv_obj_get_style_line_color(lmeter, part);
lv_color_t grad_color = lv_obj_get_style_scale_grad_color(lmeter, part);
lv_color_t end_color = lv_obj_get_style_scale_end_color(lmeter, part);
lv_draw_line_dsc_t line_dsc;
lv_draw_line_dsc_init(&line_dsc);
lv_obj_init_draw_line_dsc(lmeter, part, &line_dsc);
#if LV_LINEMETER_PRECISE == 2
line_dsc.raw_end = 1;
#endif
lv_coord_t end_line_width = lv_obj_get_style_scale_end_line_width(lmeter, part);
#if LV_LINEMETER_PRECISE > 0
lv_area_t mask_area;
mask_area.x1 = x_ofs - r_in;
mask_area.x2 = x_ofs + r_in - 1;
mask_area.y1 = y_ofs - r_in;
mask_area.y2 = y_ofs + r_in - 1;
lv_draw_mask_radius_param_t mask_in_param;
lv_draw_mask_radius_init(&mask_in_param, &mask_area, LV_RADIUS_CIRCLE, true);
int16_t mask_in_id = lv_draw_mask_add(&mask_in_param, 0);
#endif
#if LV_LINEMETER_PRECISE > 1
mask_area.x1 = x_ofs - r_out;
mask_area.x2 = x_ofs + r_out - 1;
mask_area.y1 = y_ofs - r_out;
mask_area.y2 = y_ofs + r_out - 1;
lv_draw_mask_radius_param_t mask_out_param;
lv_draw_mask_radius_init(&mask_out_param, &mask_area, LV_RADIUS_CIRCLE, false);
int16_t mask_out_id = lv_draw_mask_add(&mask_out_param, 0);
/*In calculation use a larger radius to avoid rounding errors */
lv_coord_t r_out_extra = r_out + LV_DPI;
#else
lv_coord_t r_out_extra = r_out;
#endif
for(i = 0; i < ext->line_cnt; i++) {
/* `* 256` for extra precision*/
int32_t angle_upscale = (i * ext->scale_angle * 256) / (ext->line_cnt - 1);
int32_t angle_normal = angle_upscale >> 8;
int32_t angle_low = (angle_upscale >> 8);
int32_t angle_high = angle_low + 1;
int32_t angle_rem = angle_upscale & 0xFF;
/*Interpolate sine and cos*/
int32_t sin_low = _lv_trigo_sin(angle_low + angle_ofs);
int32_t sin_high = _lv_trigo_sin(angle_high + angle_ofs);
int32_t sin_mid = (sin_low * (256 - angle_rem) + sin_high * angle_rem) >> 8;
int32_t cos_low = _lv_trigo_sin(angle_low + 90 + angle_ofs);
int32_t cos_high = _lv_trigo_sin(angle_high + 90 + angle_ofs);
int32_t cos_mid = (cos_low * (256 - angle_rem) + cos_high * angle_rem) >> 8;
/*Use the interpolated values to get x and y coordinates*/
int32_t y_out_extra = (int32_t)((int32_t)sin_mid * r_out_extra) >> (LV_TRIGO_SHIFT - 8);
int32_t x_out_extra = (int32_t)((int32_t)cos_mid * r_out_extra) >> (LV_TRIGO_SHIFT - 8);
/*Rounding*/
if(x_out_extra > 0) x_out_extra = (x_out_extra + 127) >> 8;
else x_out_extra = (x_out_extra - 127) >> 8;
if(y_out_extra > 0) y_out_extra = (y_out_extra + 127) >> 8;
else y_out_extra = (y_out_extra - 127) >> 8;
x_out_extra += x_ofs;
y_out_extra += y_ofs;
/*With no extra precision use the coordinates on the inner radius*/
#if LV_LINEMETER_PRECISE == 0
/*Use the interpolated values to get x and y coordinates*/
int32_t y_in_extra = (int32_t)((int32_t)sin_mid * r_in) >> (LV_TRIGO_SHIFT - 8);
int32_t x_in_extra = (int32_t)((int32_t)cos_mid * r_in) >> (LV_TRIGO_SHIFT - 8);
/*Rounding*/
if(x_in_extra > 0) x_in_extra = (x_in_extra + 127) >> 8;
else x_in_extra = (x_in_extra - 127) >> 8;
if(y_in_extra > 0) y_in_extra = (y_in_extra + 127) >> 8;
else y_in_extra = (y_in_extra - 127) >> 8;
x_in_extra += x_ofs;
y_in_extra += y_ofs;
#else
int32_t x_in_extra = x_ofs;
int32_t y_in_extra = y_ofs;
#endif
/*Use smaller clip area only around the visible line*/
int32_t y_in = (int32_t)((int32_t)_lv_trigo_sin(angle_normal + angle_ofs) * r_in) >> LV_TRIGO_SHIFT;
int32_t x_in = (int32_t)((int32_t)_lv_trigo_sin(angle_normal + 90 + angle_ofs) * r_in) >> LV_TRIGO_SHIFT;
x_in += x_ofs;
y_in += y_ofs;
int32_t y_out = (int32_t)((int32_t)_lv_trigo_sin(angle_normal + angle_ofs) * r_out) >> LV_TRIGO_SHIFT;
int32_t x_out = (int32_t)((int32_t)_lv_trigo_sin(angle_normal + 90 + angle_ofs) * r_out) >> LV_TRIGO_SHIFT;
x_out += x_ofs;
y_out += y_ofs;
lv_area_t clip_sub;
clip_sub.x1 = LV_MATH_MIN(x_in, x_out) - line_dsc.width;
clip_sub.x2 = LV_MATH_MAX(x_in, x_out) + line_dsc.width;
clip_sub.y1 = LV_MATH_MIN(y_in, y_out) - line_dsc.width;
clip_sub.y2 = LV_MATH_MAX(y_in, y_out) + line_dsc.width;
if(_lv_area_intersect(&clip_sub, &clip_sub, clip_area) == false) continue;
lv_point_t p1;
lv_point_t p2;
p2.x = x_in_extra;
p2.y = y_in_extra;
p1.x = x_out_extra;
p1.y = y_out_extra;
/* Set the color of the lines */
if((!ext->mirrored && i >= level) || (ext->mirrored && i <= level)) {
line_dsc.color = end_color;
line_dsc.width = end_line_width;
}
else {
line_dsc.color = lv_color_mix(grad_color, main_color, (255 * i) / ext->line_cnt);
}
lv_draw_line(&p1, &p2, &clip_sub, &line_dsc);
}
#if LV_LINEMETER_PRECISE > 0
lv_draw_mask_remove_id(mask_in_id);
#endif
#if LV_LINEMETER_PRECISE > 1
lv_draw_mask_remove_id(mask_out_id);
#endif
if(part == LV_LINEMETER_PART_MAIN && level < ext->line_cnt - 1) {
lv_coord_t border_width = lv_obj_get_style_scale_border_width(lmeter, part);
lv_coord_t end_border_width = lv_obj_get_style_scale_end_border_width(lmeter, part);
if(border_width || end_border_width) {
int16_t end_angle = ((level) * ext->scale_angle) / (ext->line_cnt - 1) + angle_ofs;
lv_draw_line_dsc_t arc_dsc;
lv_draw_line_dsc_init(&arc_dsc);
lv_obj_init_draw_line_dsc(lmeter, part, &arc_dsc);
if(border_width) {
arc_dsc.width = border_width;
arc_dsc.color = main_color;
lv_draw_arc(x_ofs, y_ofs, r_out, angle_ofs, end_angle, clip_area, &arc_dsc);
}
if(end_border_width) {
arc_dsc.width = end_border_width;
arc_dsc.color = end_color;
lv_draw_arc(x_ofs, y_ofs, r_out, end_angle, (angle_ofs + ext->scale_angle) % 360, clip_area, &arc_dsc);
}
}
}
LV_ASSERT_OBJ(obj, LV_OBJX_NAME);
lv_meter_t * meter = (lv_meter_t *) obj;
return meter->angle_ofs;
}
/**********************
* STATIC FUNCTIONS
**********************/
static void lv_meter_constructor(lv_obj_t * obj, lv_obj_t * parent, const lv_obj_t * copy)
{
LV_LOG_TRACE("line meter create started");
lv_obj_construct_base(obj, parent, copy);
lv_meter_t * meter = (lv_meter_t *) obj;
/*Initialize the allocated 'ext' */
meter->min_value = 0;
meter->max_value = 100;
meter->scale_angle = 240;
meter->angle_ofs = 0;
meter->line_cnt = 26;
meter->marker_nth = 5;
meter->indicator_stacked = 0;
_lv_ll_init(&meter->indic_ll, sizeof(lv_meter_indicator_t));
_lv_ll_init(&meter->segment_ll, sizeof(lv_meter_segment_t));
/*Init the new line meter line meter*/
if(copy == NULL) {
lv_obj_set_size(obj, 3 * LV_DPI / 2, 3 * LV_DPI / 2);
}
/*Copy an existing line meter*/
else {
// lv_linemeter_ext_t * copy_ext = lv_obj_get_ext_attr(copy);
// meter->scale_angle = copy_meter->scale_angle;
// meter->line_cnt = copy_meter->line_cnt;
// meter->min_value = copy_meter->min_value;
// meter->max_value = copy_meter->max_value;
// meter->cur_value = copy_meter->cur_value;
}
LV_LOG_INFO("line meter created");
}
static void lv_meter_destructor(lv_obj_t * obj)
{
}
/**
* Handle the drawing related tasks of the line meters
* @param lmeter pointer to an object
@ -507,22 +298,30 @@ void lv_linemeter_draw_scale(lv_obj_t * lmeter, const lv_area_t * clip_area, uin
* LV_DESIGN_DRAW_POST: drawing after every children are drawn
* @param return an element of `lv_design_res_t`
*/
static lv_design_res_t lv_linemeter_design(lv_obj_t * lmeter, const lv_area_t * clip_area, lv_design_mode_t mode)
static lv_design_res_t lv_meter_design(lv_obj_t * obj, const lv_area_t * clip_area, lv_design_mode_t mode)
{
/*Return false if the object is not covers the mask_p area*/
if(mode == LV_DESIGN_COVER_CHK) {
return LV_DESIGN_RES_NOT_COVER;
return lv_obj.design_cb(obj, clip_area, mode);
}
/*Draw the object*/
else if(mode == LV_DESIGN_DRAW_MAIN) {
lv_draw_rect_dsc_t bg_dsc;
lv_draw_rect_dsc_init(&bg_dsc);
lv_obj_init_draw_rect_dsc(lmeter, LV_LINEMETER_PART_MAIN, &bg_dsc);
lv_draw_rect(&lmeter->coords, clip_area, &bg_dsc);
lv_linemeter_draw_scale(lmeter, clip_area, LV_LINEMETER_PART_MAIN);
lv_obj.design_cb(obj, clip_area, mode);
lv_area_t scale_area;
lv_obj_get_coords(obj, &scale_area);
scale_area.x1 += lv_obj_get_style_pad_left(obj, LV_PART_MAIN);
scale_area.y1 += lv_obj_get_style_pad_top(obj, LV_PART_MAIN);
scale_area.x2 -= lv_obj_get_style_pad_right(obj, LV_PART_MAIN);
scale_area.y2 -= lv_obj_get_style_pad_bottom(obj, LV_PART_MAIN);
draw_arcs(obj, clip_area, &scale_area);
draw_lines_and_labels(obj, clip_area, &scale_area);
draw_needles(obj, clip_area, &scale_area);
}
/*Post draw when the children are drawn*/
else if(mode == LV_DESIGN_DRAW_POST) {
lv_obj.design_cb(obj, clip_area, mode);
}
return LV_DESIGN_RES_OK;
@ -535,19 +334,267 @@ static lv_design_res_t lv_linemeter_design(lv_obj_t * lmeter, const lv_area_t *
* @param param pointer to a signal specific variable
* @return LV_RES_OK: the object is not deleted in the function; LV_RES_INV: the object is deleted
*/
static lv_res_t lv_linemeter_signal(lv_obj_t * lmeter, lv_signal_t sign, void * param)
static lv_res_t lv_meter_signal(lv_obj_t * obj, lv_signal_t sign, void * param)
{
lv_res_t res;
/* Include the ancient signal function */
res = ancestor_signal(lmeter, sign, param);
res = lv_obj.signal_cb(obj, sign, param);
if(res != LV_RES_OK) return res;
if(sign == LV_SIGNAL_GET_TYPE) return _lv_obj_handle_get_type_signal(param, LV_OBJX_NAME);
if(sign == LV_SIGNAL_CLEANUP) {
/*Nothing to cleanup. (No dynamically allocated memory in 'ext')*/
}
// if(sign == LV_SIGNAL_GET_TYPE) return _lv_obj_handle_get_type_signal(param, LV_OBJX_NAME);
//
// if(sign == LV_SIGNAL_CLEANUP) {
// /*Nothing to cleanup. (No dynamically allocated memory in 'ext')*/
// }
return res;
}
static void draw_arcs(lv_obj_t * obj, const lv_area_t * clip_area, const lv_area_t * scale_area)
{
lv_meter_t * meter = (lv_meter_t *)obj;
lv_draw_line_dsc_t line_dsc;
lv_draw_line_dsc_init(&line_dsc);
lv_obj_init_draw_line_dsc(obj, LV_PART_ITEMS, &line_dsc);
line_dsc.width = 5;
int16_t angle_ofs = meter->angle_ofs + 90 + (360 - meter->scale_angle) / 2;
lv_coord_t r_out = lv_area_get_width(scale_area) / 2 ;
lv_point_t scale_center;
scale_center.x = scale_area->x1 + r_out;
scale_center.y = scale_area->y1 + r_out;
/*Draw the segments first*/
lv_meter_segment_t * seg;
_LV_LL_READ(&meter->segment_ll, seg) {
if(seg->type != LV_METER_SEGMENT_TYPE_ARC) continue;
int32_t start_angle = _lv_map(seg->start_value, meter->min_value, meter->max_value, 0, meter->scale_angle) + angle_ofs;
int32_t end_angle = _lv_map(seg->end_value, meter->min_value, meter->max_value, 0, meter->scale_angle) + angle_ofs;
line_dsc.color = seg->color;
line_dsc.width = seg->width;
lv_draw_arc(scale_center.x, scale_center.y, r_out, start_angle, end_angle, clip_area, &line_dsc);
}
lv_meter_indicator_t * indic;
int32_t value = 0;
if(meter->indicator_stacked) {
_LV_LL_READ_BACK(&meter->indic_ll, indic) {
if((indic->type & LV_METER_INDICATOR_TYPE_ARC) == false) continue;
int32_t start_angle = _lv_map(value, meter->min_value, meter->max_value, 0, meter->scale_angle) + angle_ofs;
value += indic->value;
int32_t end_angle = _lv_map(value, meter->min_value, meter->max_value, 0, meter->scale_angle) + angle_ofs;
line_dsc.color = indic->color;
line_dsc.width = 20;
lv_draw_arc(scale_center.x, scale_center.y, r_out, start_angle, end_angle, clip_area, &line_dsc);
r_out-=10;
}
} else {
_LV_LL_READ(&meter->indic_ll, indic) {
if((indic->type & LV_METER_INDICATOR_TYPE_ARC) == false) continue;
int32_t end_angle = _lv_map(indic->value, meter->min_value, meter->max_value, 0, meter->scale_angle) + angle_ofs;
line_dsc.color = indic->color;
line_dsc.width = 10;
lv_draw_arc(scale_center.x, scale_center.y, r_out, angle_ofs, end_angle, clip_area, &line_dsc);
r_out-=10;
}
}
}
static void draw_lines_and_labels(lv_obj_t * obj, const lv_area_t * clip_area, const lv_area_t * scale_area)
{
lv_meter_t * meter = (lv_meter_t *)obj;
lv_coord_t sub_tick_len = 10;
lv_coord_t major_tick_len = 20;
lv_coord_t r_out = lv_area_get_width(scale_area) / 2 ;
lv_coord_t r_in_sub = r_out - sub_tick_len;
lv_coord_t r_in_marker = r_out - major_tick_len;
if(r_in_marker < 1) r_in_marker = 1;
if(r_in_sub < 1) r_in_sub = 1;
lv_point_t scale_center;
scale_center.x = scale_area->x1 + r_out;
scale_center.y = scale_area->y1 + r_out;
int16_t angle_ofs = meter->angle_ofs + 90 + (360 - meter->scale_angle) / 2;
uint8_t i;
lv_draw_line_dsc_t line_sub_dsc;
lv_draw_line_dsc_init(&line_sub_dsc);
lv_obj_init_draw_line_dsc(obj, LV_PART_MAIN, &line_sub_dsc);
line_sub_dsc.width = 2;
lv_draw_line_dsc_t line_marker_dsc;
lv_draw_line_dsc_init(&line_marker_dsc);
lv_obj_init_draw_line_dsc(obj, LV_PART_MARKER, &line_marker_dsc);
line_marker_dsc.width = 5;
lv_draw_label_dsc_t label_dsc;
lv_draw_label_dsc_init(&label_dsc);
lv_obj_init_draw_label_dsc(obj, LV_PART_MARKER, &label_dsc);
uint32_t sub_cnt = meter->marker_nth - 1;
bool marker;
for(i = 0; i < meter->line_cnt; i++) {
if(sub_cnt == meter->marker_nth - 1) {
sub_cnt = 0;
marker = true;
} else {
sub_cnt++;
marker = false;
}
/* `* 256` for extra precision*/
int32_t angle_upscale = ((i * meter->scale_angle) << 8) / (meter->line_cnt - 1);
int32_t angle_low = (angle_upscale >> 8);
int32_t angle_high = angle_low + 1;
int32_t angle_rem = angle_upscale & 0xFF;
/*Interpolate sine and cos*/
int32_t sin_low = _lv_trigo_sin(angle_low + angle_ofs);
int32_t sin_high = _lv_trigo_sin(angle_high + angle_ofs);
int32_t sin_mid = (sin_low * (256 - angle_rem) + sin_high * angle_rem) >> 8;
int32_t cos_low = _lv_trigo_cos(angle_low + angle_ofs);
int32_t cos_high = _lv_trigo_cos(angle_high + angle_ofs);
int32_t cos_mid = (cos_low * (256 - angle_rem) + cos_high * angle_rem) >> 8;
lv_point_t p_inner;
lv_point_t p_outer;
/*Use the interpolated values to get the outer x and y coordinates*/
p_outer.x = (int32_t)(((int32_t)cos_mid * r_out + 127) >> (LV_TRIGO_SHIFT)) + scale_center.y;
p_outer.y = (int32_t)(((int32_t)sin_mid * r_out + 127) >> (LV_TRIGO_SHIFT)) + scale_center.x;
/*Use the interpolated values to get the inner x and y coordinates*/
uint32_t r_in = marker ? r_in_marker : r_in_sub;
p_inner.x = (int32_t)(((int32_t)cos_mid * r_in + 127) >> (LV_TRIGO_SHIFT)) + scale_center.y;
p_inner.y = (int32_t)(((int32_t)sin_mid * r_in + 127) >> (LV_TRIGO_SHIFT)) + scale_center.x;
lv_draw_line_dsc_t * line_dsc_act;
line_dsc_act = marker ? &line_marker_dsc : &line_sub_dsc;
int32_t value_of_line = _lv_map(i, 0, meter->line_cnt - 1, meter->min_value, meter->max_value);
lv_color_t line_color = line_dsc_act->color;
lv_meter_segment_t * seg;
_LV_LL_READ(&meter->segment_ll, seg) {
if((seg->type & LV_METER_SEGMENT_TYPE_SCALE) == false) continue;
if(value_of_line >= seg->start_value && value_of_line <= seg->end_value) line_color = seg->color;
}
lv_meter_indicator_t * indic;
if(!meter->indicator_stacked) {
_LV_LL_READ(&meter->indic_ll, indic) {
if((indic->type & LV_METER_INDICATOR_TYPE_SCALE) == false) continue;
if(value_of_line <= indic->value) line_color = indic->color;
}
} else {
int32_t last_value = meter->min_value;
_LV_LL_READ_BACK(&meter->indic_ll, indic) {
if((indic->type & LV_METER_INDICATOR_TYPE_SCALE) == false) continue;
if(value_of_line >= last_value && value_of_line <= last_value + indic->value) {
line_color = indic->color;
break;
}
last_value += indic->value;
}
}
lv_color_t line_color_ori = line_dsc_act->color;
line_dsc_act->color = line_color;
lv_draw_line(&p_inner, &p_outer, clip_area, line_dsc_act);
line_dsc_act->color = line_color_ori;
/*Draw the text*/
if(marker) {
uint32_t r_text = r_in_marker - 10;
lv_point_t p;
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_point_t label_size;
_lv_txt_get_size(&label_size, buf, label_dsc.font, label_dsc.letter_space, label_dsc.line_space,
LV_COORD_MAX, LV_TEXT_FLAG_NONE);
lv_area_t label_cord;
label_cord.x1 = p.x - label_size.x / 2;
label_cord.y1 = p.y - label_size.y / 2;
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);
}
}
}
static void draw_needles(lv_obj_t * obj, const lv_area_t * clip_area, const lv_area_t * scale_area)
{
lv_meter_t * meter = (lv_meter_t *)obj;
lv_coord_t r_out = lv_area_get_width(scale_area) / 2 ;
lv_point_t scale_center;
scale_center.x = scale_area->x1 + r_out;
scale_center.y = scale_area->y1 + r_out;
int16_t angle_ofs = meter->angle_ofs + 90 + (360 - meter->scale_angle) / 2;
lv_draw_line_dsc_t line_dsc;
lv_draw_line_dsc_init(&line_dsc);
lv_obj_init_draw_line_dsc(obj, LV_PART_INDICATOR, &line_dsc);
line_dsc.width = 2;
lv_draw_img_dsc_t img_dsc;
lv_draw_img_dsc_init(&img_dsc);
lv_obj_init_draw_img_dsc(obj, LV_PART_INDICATOR, &img_dsc);
lv_meter_indicator_t * indic;
int32_t value = 0;
_LV_LL_READ_BACK(&meter->indic_ll, indic) {
if((indic->type & LV_METER_INDICATOR_TYPE_NEEDLE) == false) continue;
if(meter->indicator_stacked) value += indic->value;
else value = indic->value;
int32_t angle = _lv_map(value, meter->min_value, meter->max_value, 0, meter->scale_angle) + angle_ofs;
/*Draw a line*/
if(indic->img_src == NULL) {
lv_point_t p_end;
p_end.y = (_lv_trigo_sin(angle) * r_out) / LV_TRIGO_SIN_MAX + scale_center.x;
p_end.x = (_lv_trigo_sin(angle + 90) * r_out) / LV_TRIGO_SIN_MAX + scale_center.y;
lv_draw_line(&scale_center, &p_end, clip_area, &line_dsc);
}
/*Draw an image*/
else {
lv_img_header_t info;
lv_img_decoder_get_info(indic->img_src, &info);
lv_area_t a;
a.x1 = scale_center.x - indic->img_pivot.x;
a.y1 = scale_center.y - indic->img_pivot.y;
a.x2 = a.x1 + info.w - 1;
a.y2 = a.y1 + info.h - 1;
img_dsc.recolor_opa = indic->img_recolor_opa;
img_dsc.recolor = indic->color;
angle = angle * 10;
if(angle > 3600) angle -= 3600;
img_dsc.angle = angle;
lv_draw_img(&a, clip_area, indic->img_src, &img_dsc);
}
}
}
#endif

View File

@ -15,7 +15,7 @@ extern "C" {
*********************/
#include "../lv_conf_internal.h"
#if LV_USE_LINEMETER != 0
#if LV_USE_METER != 0
#include "../lv_core/lv_obj.h"
@ -26,25 +26,50 @@ extern "C" {
/**********************
* TYPEDEFS
**********************/
typedef enum {
LV_METER_INDICATOR_TYPE_SCALE = 0x01,
LV_METER_INDICATOR_TYPE_NEEDLE = 0x02,
LV_METER_INDICATOR_TYPE_ARC = 0x04,
}lv_meter_indicator_type_t;
typedef enum {
LV_METER_SEGMENT_TYPE_SCALE = 0x1,
LV_METER_SEGMENT_TYPE_ARC = 0x2,
}lv_meter_segment_type_t;
typedef struct {
lv_color_t color;
void * img_src;
int32_t value;
lv_meter_indicator_type_t type;
lv_point_t img_pivot;
lv_opa_t img_recolor_opa;
}lv_meter_indicator_t;
typedef struct {
lv_color_t color;
int32_t start_value;
int32_t end_value;
int32_t width;
lv_meter_segment_type_t type;
}lv_meter_segment_t;
/*Data of line meter*/
typedef struct {
/*No inherited ext.*/ /*Ext. of ancestor*/
/*New data for this type */
lv_obj_t obj;
lv_ll_t segment_ll;
lv_ll_t indic_ll;
uint16_t scale_angle; /*Angle of the scale in deg. (0..360)*/
uint16_t angle_ofs;
uint16_t line_cnt; /*Count of lines */
int32_t cur_value;
uint16_t marker_nth; /*Every Nth line should be marker */
int32_t min_value;
int32_t max_value;
uint8_t mirrored : 1;
} lv_linemeter_ext_t;
/*Styles*/
enum {
LV_LINEMETER_PART_MAIN,
_LV_LINEMETER_PART_VIRTUAL_LAST,
};
typedef uint8_t lv_linemeter_part_t;
uint8_t indicator_stacked:1;
} lv_meter_t;
/**********************
* GLOBAL PROTOTYPES
@ -57,7 +82,7 @@ typedef uint8_t lv_linemeter_part_t;
* it
* @return pointer to the created line meter
*/
lv_obj_t * lv_linemeter_create(lv_obj_t * par, const lv_obj_t * copy);
lv_obj_t * lv_meter_create(lv_obj_t * par, const lv_obj_t * copy);
/*=====================
* Setter functions
@ -68,7 +93,11 @@ lv_obj_t * lv_linemeter_create(lv_obj_t * par, const lv_obj_t * copy);
* @param lmeter pointer to a line meter object
* @param value new value
*/
void lv_linemeter_set_value(lv_obj_t * lmeter, int32_t value);
lv_meter_indicator_t * lv_meter_add_indicator(lv_obj_t * obj);
lv_meter_segment_t * lv_meter_add_segment(lv_obj_t * obj);
void lv_meter_set_value(lv_obj_t * meter, lv_meter_indicator_t * indic, int32_t value);
/**
* Set minimum and the maximum values of a line meter
@ -76,7 +105,7 @@ void lv_linemeter_set_value(lv_obj_t * lmeter, int32_t value);
* @param min minimum value
* @param max maximum value
*/
void lv_linemeter_set_range(lv_obj_t * lmeter, int32_t min, int32_t max);
void lv_meter_set_range(lv_obj_t * meter, int32_t min, int32_t max);
/**
* Set the scale settings of a line meter
@ -84,21 +113,14 @@ void lv_linemeter_set_range(lv_obj_t * lmeter, int32_t min, int32_t max);
* @param angle angle of the scale (0..360)
* @param line_cnt number of lines
*/
void lv_linemeter_set_scale(lv_obj_t * lmeter, uint16_t angle, uint16_t line_cnt);
void lv_meter_set_scale(lv_obj_t * meter, uint16_t angle, uint16_t line_cnt, uint16_t nth_marker);
/**
* Set the set an offset for the line meter's angles to rotate it.
* @param lmeter pointer to a line meter object
* @param angle angle offset (0..360), rotates clockwise
*/
void lv_linemeter_set_angle_offset(lv_obj_t * lmeter, uint16_t angle);
/**
* Set the orientation of the meter growth, clockwise or counterclockwise (mirrored)
* @param lmeter pointer to a line meter object
* @param mirror mirror setting
*/
void lv_linemeter_set_mirror(lv_obj_t * lmeter, bool mirror);
void lv_meter_set_angle_offset(lv_obj_t * meter, uint16_t angle);
/*=====================
* Getter functions
@ -109,61 +131,52 @@ void lv_linemeter_set_mirror(lv_obj_t * lmeter, bool mirror);
* @param lmeter pointer to a line meter object
* @return the value of the line meter
*/
int32_t lv_linemeter_get_value(const lv_obj_t * lmeter);
int32_t lv_meter_get_value(const lv_obj_t * obj, const lv_meter_indicator_t * indic);
/**
* Get the minimum value of a line meter
* @param lmeter pointer to a line meter object
* @return the minimum value of the line meter
*/
int32_t lv_linemeter_get_min_value(const lv_obj_t * lmeter);
int32_t lv_meter_get_min_value(const lv_obj_t * meter);
/**
* Get the maximum value of a line meter
* @param lmeter pointer to a line meter object
* @return the maximum value of the line meter
*/
int32_t lv_linemeter_get_max_value(const lv_obj_t * lmeter);
int32_t lv_meter_get_max_value(const lv_obj_t * meter);
/**
* Get the scale number of a line meter
* @param lmeter pointer to a line meter object
* @return number of the scale units
*/
uint16_t lv_linemeter_get_line_count(const lv_obj_t * lmeter);
uint16_t lv_meter_get_line_count(const lv_obj_t * meter);
/**
* Get the scale angle of a line meter
* @param lmeter pointer to a line meter object
* @return angle of the scale
*/
uint16_t lv_linemeter_get_scale_angle(const lv_obj_t * lmeter);
uint16_t lv_meter_get_scale_angle(const lv_obj_t * meter);
/**
* Get the offset for the line meter.
* @param lmeter pointer to a line meter object
* @return angle offset (0..360)
*/
uint16_t lv_linemeter_get_angle_offset(lv_obj_t * lmeter);
uint16_t lv_meter_get_angle_offset(lv_obj_t * meter);
void lv_linemeter_draw_scale(lv_obj_t * lmeter, const lv_area_t * clip_area, uint8_t part);
/**
* get the mirror setting for the line meter
* @param lmeter pointer to a line meter object
* @return mirror (true or false)
*/
bool lv_linemeter_get_mirror(lv_obj_t * lmeter);
/**********************
* MACROS
**********************/
#endif /*LV_USE_LINEMETER*/
#endif /*LV_USE_METER*/
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /*LV_LINEMETER_H*/
#endif /*LV_METER_H*/

View File

@ -34,10 +34,11 @@
* STATIC PROTOTYPES
**********************/
static void lv_roller_constructor(lv_obj_t * obj, lv_obj_t * parent, const lv_obj_t * copy);
static void lv_roller_destructor(void * obj);
static lv_obj_t * lv_roller_label_create(lv_obj_t * parent, const lv_obj_t * copy);
static void lv_roller_destructor(lv_obj_t * obj);
static lv_design_res_t lv_roller_design(lv_obj_t * obj, const lv_area_t * clip_area, lv_design_mode_t mode);
static lv_design_res_t lv_roller_label_design(lv_obj_t * label, const lv_area_t * clip_area, lv_design_mode_t mode);
static void lv_roller_label_constructor(lv_obj_t * obj, lv_obj_t * parent, const lv_obj_t * copy);
static void lv_roller_label_destructor(lv_obj_t * obj);
static lv_res_t lv_roller_signal(lv_obj_t * obj, lv_signal_t sign, void * param);
static lv_res_t lv_roller_label_signal(lv_obj_t * label, lv_signal_t sign, void * param);
static void refr_position(lv_obj_t * obj, lv_anim_enable_t animen);
@ -52,8 +53,23 @@ static lv_coord_t get_selected_label_width(const lv_obj_t * obj);
/**********************
* STATIC VARIABLES
**********************/
lv_roller_class_t lv_roller;
lv_roller_label_class_t lv_roller_label;
const lv_obj_class_t lv_roller = {
.constructor = lv_roller_constructor,
.destructor = lv_roller_destructor,
.signal_cb = lv_roller_signal,
.design_cb = lv_roller_design,
.instance_size = sizeof(lv_roller_t),
.base_class = &lv_obj
};
const lv_obj_class_t lv_roller_label = {
.constructor = lv_roller_label_constructor,
.destructor = lv_roller_label_destructor,
.signal_cb = lv_roller_label_signal,
.design_cb = lv_roller_label_design,
.instance_size = sizeof(lv_label_t),
.base_class = &lv_label
};;
/**********************
* MACROS
@ -71,20 +87,7 @@ lv_roller_label_class_t lv_roller_label;
*/
lv_obj_t * lv_roller_create(lv_obj_t * parent, const lv_obj_t * copy)
{
if(!lv_roller._inited) {
LV_CLASS_INIT(lv_roller, lv_obj);
lv_roller.constructor = lv_roller_constructor;
lv_roller.destructor = lv_roller_destructor;
lv_roller.design_cb = lv_roller_design;
lv_roller.signal_cb = lv_roller_signal;
}
lv_obj_t * obj = lv_class_new(&lv_roller);
lv_roller.constructor(obj, parent, copy);
lv_obj_create_finish(obj, parent, copy);
return obj;
return lv_obj_create_from_class(&lv_roller, parent, copy);
}
/*=====================
@ -147,21 +150,6 @@ void lv_roller_set_options(lv_obj_t * obj, const char * options, lv_roller_mode_
}
/**
* Set the align of the roller's options (left or center)
* @param roller - pointer to a roller object
* @param align - one of lv_text_align_t values (left, right, center)
*/
void lv_roller_set_label_align(lv_obj_t * obj, lv_text_align_t align)
{
LV_ASSERT_OBJ(obj, LV_OBJX_NAME);
lv_obj_t * label = get_label(obj);
if(label == NULL) return; /*Probably the roller is being deleted if the label is NULL.*/
lv_label_set_align(label, align);
}
/**
* Set the selected option
* @param roller pointer to a roller object
@ -217,17 +205,6 @@ void lv_roller_set_visible_row_count(lv_obj_t * obj, uint8_t row_cnt)
lv_obj_set_height(obj, (lv_font_get_line_height(font) + line_space) * row_cnt);
}
/**
* Get the animation time of the roller
* @param roller pointer to a roller object
* @param the animation time in milliseconds
*/
void lv_roller_set_anim_time(lv_obj_t * obj, uint32_t anim_time)
{
lv_roller_t * roller = (lv_roller_t*)obj;
roller->anim_time = anim_time;
}
/*=====================
* Getter functions
*====================*/
@ -316,29 +293,6 @@ uint16_t lv_roller_get_option_cnt(const lv_obj_t * obj)
return roller->option_cnt;
}
}
/**
* Get the align attribute. Default alignment after _create is LV_TEXT_ALIGN_CENTER
* @param roller pointer to a roller object
* @return LV_TEXT_ALIGN_LEFT, LV_TEXT_ALIGN_RIGHT or LV_TEXT_ALIGN_CENTER
*/
lv_text_align_t lv_roller_get_label_align(const lv_obj_t * obj)
{
LV_ASSERT_OBJ(obj, LV_OBJX_NAME);
return lv_label_get_align(get_label(obj));
}
/**
* Get the animation time of the roller
* @param roller pointer to a roller object
* @return the animation time in milliseconds
*/
uint32_t lv_roller_get_anim_time(lv_obj_t * obj)
{
lv_roller_t * roller = (lv_roller_t*)obj;
return roller->anim_time;
}
/**********************
* STATIC FUNCTIONS
@ -348,8 +302,7 @@ uint32_t lv_roller_get_anim_time(lv_obj_t * obj)
static void lv_roller_constructor(lv_obj_t * obj, lv_obj_t * parent, const lv_obj_t * copy)
{
LV_CLASS_CONSTRUCTOR_BEGIN(obj, lv_roller)
lv_roller.base_p->constructor(obj, parent, copy);
lv_obj_construct_base(obj, parent, copy);
lv_roller_t * roller = (lv_roller_t*)obj;
@ -362,16 +315,14 @@ static void lv_roller_constructor(lv_obj_t * obj, lv_obj_t * parent, const lv_ob
if(copy == NULL) {
lv_obj_clear_flag(obj, LV_OBJ_FLAG_SCROLLABLE);
lv_obj_clear_flag(obj, LV_OBJ_FLAG_SCROLL_CHAIN);
roller->anim_time = LV_ROLLER_DEF_ANIM_TIME;
lv_obj_set_width(obj, LV_SIZE_AUTO);
lv_obj_t * label = lv_roller_label_create(obj, NULL);
lv_label_set_align(label, LV_TEXT_ALIGN_CENTER);
lv_obj_create_from_class(&lv_roller_label, obj, NULL);
lv_roller_set_options(obj, "Option 1\nOption 2\nOption 3\nOption 4\nOption 5", LV_ROLLER_MODE_NORMAL);
lv_roller_set_visible_row_count(obj, 3);
}
else {
lv_roller_label_create(obj, get_label(copy));
lv_obj_create_from_class(&lv_roller_label, obj, NULL);
lv_roller_t * copy_roller = (lv_roller_t *) copy;
roller->mode = copy_roller->mode;
roller->option_cnt = copy_roller->option_cnt;
@ -381,10 +332,9 @@ static void lv_roller_constructor(lv_obj_t * obj, lv_obj_t * parent, const lv_ob
LV_LOG_INFO("roller created");
LV_CLASS_CONSTRUCTOR_END(obj, lv_roller)
}
static void lv_roller_destructor(void * obj)
static void lv_roller_destructor(lv_obj_t * obj)
{
// lv_bar_t * bar = obj;
//
@ -394,30 +344,14 @@ static void lv_roller_destructor(void * obj)
// bar->class_p->base_p->destructor(obj);
}
/**
* Create a roller object
* @param par pointer to an object, it will be the parent of the new roller
* @param copy pointer to a roller object, if not NULL then the new object will be copied from it
* @return pointer to the created roller
*/
static lv_obj_t * lv_roller_label_create(lv_obj_t * parent, const lv_obj_t * copy)
static void lv_roller_label_constructor(lv_obj_t * obj, lv_obj_t * parent, const lv_obj_t * copy)
{
if(!lv_roller_label._inited) {
LV_CLASS_INIT(lv_roller_label, lv_label);
lv_roller_label.constructor = lv_label.constructor;
lv_roller_label.destructor = lv_label.destructor;
lv_roller_label.design_cb = lv_roller_label_design;
lv_roller_label.signal_cb = lv_roller_label_signal;
}
lv_obj_t * obj = lv_class_new(&lv_roller_label);
lv_roller_label.constructor(obj, parent, copy);
lv_obj_create_finish(obj, parent, copy);
return obj;
lv_label.constructor(obj, parent, copy);
}
static void lv_roller_label_destructor(lv_obj_t * obj)
{
lv_label.destructor(obj);
}
/**
* Handle the drawing related tasks of the rollers
* @param roller pointer to an object
@ -430,8 +364,6 @@ static lv_obj_t * lv_roller_label_create(lv_obj_t * parent, const lv_obj_t * cop
*/
static lv_design_res_t lv_roller_design(lv_obj_t * obj, const lv_area_t * clip_area, lv_design_mode_t mode)
{
lv_roller_t * roller = (lv_roller_t*)obj;
if(mode == LV_DESIGN_COVER_CHK) {
return lv_obj.design_cb(obj, clip_area, mode);
}
@ -467,16 +399,16 @@ static lv_design_res_t lv_roller_design(lv_obj_t * obj, const lv_area_t * clip_a
/*Redraw the text on the selected area*/
lv_area_t rect_area;
rect_area.y1 = roller->coords.y1 + (lv_obj_get_height(obj) - bg_font_h - label_dsc.line_space) / 2;
rect_area.y1 = obj->coords.y1 + (lv_obj_get_height(obj) - bg_font_h - label_dsc.line_space) / 2;
rect_area.y2 = rect_area.y1 + bg_font_h + label_dsc.line_space - 1;
rect_area.x1 = roller->coords.x1;
rect_area.x2 = roller->coords.x2;
rect_area.x1 = obj->coords.x1;
rect_area.x2 = obj->coords.x2;
lv_area_t mask_sel;
bool area_ok;
area_ok = _lv_area_intersect(&mask_sel, clip_area, &rect_area);
if(area_ok) {
lv_obj_t * label = get_label(obj);
lv_text_align_t label_align = lv_roller_get_label_align(obj);
lv_text_align_t label_align = lv_obj_get_style_text_align(label, LV_PART_MAIN);
if(LV_TEXT_ALIGN_CENTER == label_align) {
label_dsc.flag |= LV_TEXT_FLAG_CENTER;
@ -493,7 +425,7 @@ static lv_design_res_t lv_roller_design(lv_obj_t * obj, const lv_area_t * clip_a
/*Move the selected label proportionally with the background label*/
lv_coord_t roller_h = lv_obj_get_height(obj);
int32_t label_y_prop = label->coords.y1 - (roller_h / 2 +
roller->coords.y1); /*label offset from the middle line of the roller*/
obj->coords.y1); /*label offset from the middle line of the roller*/
label_y_prop = (label_y_prop << 14) / lv_obj_get_height(
label); /*Proportional position from the middle line (upscaled)*/
@ -503,7 +435,7 @@ static lv_design_res_t lv_roller_design(lv_obj_t * obj, const lv_area_t * clip_a
/*Apply the proportional position to the selected text*/
res_p.y -= corr;
int32_t label_sel_y = roller_h / 2 + roller->coords.y1;
int32_t label_sel_y = roller_h / 2 + obj->coords.y1;
label_sel_y += (label_y_prop * res_p.y) >> 14;
label_sel_y -= corr;
@ -734,7 +666,7 @@ static void refr_position(lv_obj_t * obj, lv_anim_enable_t anim_en)
anim_en = LV_ANIM_OFF;
#endif
lv_text_align_t align = lv_label_get_align(label);
lv_text_align_t align = lv_obj_get_style_text_align(label, LV_PART_MAIN);
switch(align) {
case LV_TEXT_ALIGN_CENTER:
lv_obj_set_x(label, (lv_obj_get_width_fit(obj) - lv_obj_get_width(label)) / 2);
@ -753,7 +685,7 @@ static void refr_position(lv_obj_t * obj, lv_anim_enable_t anim_en)
lv_coord_t line_space = lv_obj_get_style_text_line_space(obj, LV_PART_MAIN);
lv_coord_t font_h = lv_font_get_line_height(font);
lv_coord_t h = lv_obj_get_height_fit(obj);
uint16_t anim_time = lv_roller_get_anim_time(obj);
uint16_t anim_time = lv_obj_get_style_anim_time(obj, LV_PART_MAIN);
/* Normally the animation's `end_cb` sets correct position of the roller if infinite.
* But without animations do it manually*/
@ -848,7 +780,7 @@ static lv_res_t release_handler(lv_obj_t * obj)
lv_coord_t font_h = lv_font_get_line_height(font);
lv_coord_t label_unit = font_h + line_space;
lv_coord_t mid = roller->coords.y1 + (roller->coords.y2 - roller->coords.y1) / 2;
lv_coord_t mid = obj->coords.y1 + (obj->coords.y2 - obj->coords.y1) / 2;
lv_coord_t label_y1 = label->coords.y1 + _lv_scroll_throw_predict(indev, LV_DIR_VER);
int32_t id = (mid - label_y1) / label_unit;

View File

@ -36,40 +36,17 @@ enum {
typedef uint8_t lv_roller_mode_t;
LV_CLASS_DECLARE_START(lv_roller, lv_obj);
typedef struct {
lv_obj_t obj;
uint16_t option_cnt; /*Number of options*/
uint16_t sel_opt_id; /*Index of the current option*/
uint16_t sel_opt_id_ori; /*Store the original index on focus*/
lv_roller_mode_t mode : 1;
uint32_t moved : 1;
}lv_roller_t;
#define _lv_roller_constructor void (*constructor)(struct _lv_obj_t * obj, struct _lv_obj_t * parent, const struct _lv_obj_t * copy)
extern const lv_obj_class_t lv_roller;
#define _lv_roller_data \
_lv_obj_data \
uint16_t option_cnt; /*Number of options*/ \
uint16_t sel_opt_id; /*Index of the current option*/ \
uint16_t sel_opt_id_ori; /*Store the original index on focus*/ \
uint32_t anim_time; \
lv_roller_mode_t mode : 1; \
uint32_t moved : 1; \
#define _lv_roller_class_dsc \
_lv_obj_class_dsc \
LV_CLASS_DECLARE_END(lv_roller, lv_obj);
extern lv_roller_class_t lv_roller;
LV_CLASS_DECLARE_START(lv_roller_label, lv_label);
#define _lv_roller_label_constructor void (*constructor)(struct _lv_obj_t * obj, struct _lv_obj_t * parent, const struct _lv_obj_t * copy)
#define _lv_roller_label_data \
_lv_label_data \
#define _lv_roller_label_class_dsc \
_lv_label_class_dsc \
LV_CLASS_DECLARE_END(lv_roller_label, lv_label);
extern lv_roller_label_class_t lv_roller_label;
/**********************
* GLOBAL PROTOTYPES
@ -95,13 +72,6 @@ lv_obj_t * lv_roller_create(lv_obj_t * par, const lv_obj_t * copy);
*/
void lv_roller_set_options(lv_obj_t * roller, const char * options, lv_roller_mode_t mode);
/**
* Set the align of the roller's options (left, right or center[default])
* @param roller - pointer to a roller object
* @param align - one of lv_text_align_t values (left, right, center)
*/
void lv_roller_set_label_align(lv_obj_t * roller, lv_text_align_t align);
/**
* Set the selected option
* @param roller pointer to a roller object
@ -117,13 +87,6 @@ void lv_roller_set_selected(lv_obj_t * roller, uint16_t sel_opt, lv_anim_enable_
*/
void lv_roller_set_visible_row_count(lv_obj_t * roller, uint8_t row_cnt);
/**
* Get the animation time of the roller
* @param roller pointer to a roller object
* @param the animation time in milliseconds
*/
void lv_roller_set_anim_time(lv_obj_t * roller, uint32_t anim_time);
/*=====================
* Getter functions
*====================*/
@ -149,13 +112,6 @@ uint16_t lv_roller_get_option_cnt(const lv_obj_t * roller);
*/
void lv_roller_get_selected_str(const lv_obj_t * roller, char * buf, uint32_t buf_size);
/**
* Get the align attribute. Default alignment after _create is LV_TEXT_ALIGN_CENTER
* @param roller pointer to a roller object
* @return LV_TEXT_ALIGN_LEFT, LV_TEXT_ALIGN_RIGHT or LV_TEXT_ALIGN_CENTER
*/
lv_text_align_t lv_roller_get_label_align(const lv_obj_t * roller);
/**
* Get the options of a roller
* @param roller pointer to roller object
@ -163,13 +119,6 @@ lv_text_align_t lv_roller_get_label_align(const lv_obj_t * roller);
*/
const char * lv_roller_get_options(const lv_obj_t * roller);
/**
* Get the animation time of the roller
* @param roller pointer to a roller object
* @return the animation time in milliseconds
*/
uint32_t lv_roller_get_anim_time(lv_obj_t * roller);
/**********************
* MACROS
**********************/

View File

@ -100,10 +100,7 @@ bool lv_slider_is_dragged(const lv_obj_t * obj)
static void lv_slider_constructor(lv_obj_t * obj, lv_obj_t * parent, const lv_obj_t * copy)
{
LV_CLASS_CONSTRUCTOR_BEGIN(obj, lv_slider)
lv_bar.constructor(obj, parent, copy);
lv_obj_construct_base(obj, parent, copy);
lv_slider_t * slider = (lv_slider_t *)obj;
/*Initialize the allocated 'slider' */
@ -123,7 +120,6 @@ static void lv_slider_constructor(lv_obj_t * obj, lv_obj_t * parent, const lv_ob
lv_area_copy(&slider->right_knob_area, &copy_slider->right_knob_area);
}
LV_CLASS_CONSTRUCTOR_END(obj, lv_slider)
}
static void lv_slider_destructor(lv_obj_t * obj)

File diff suppressed because it is too large Load Diff

View File

@ -42,7 +42,6 @@ typedef bool (*lv_table_cell_drawer_cb_t)(lv_obj_t * table, uint32_t row, uint32
*/
typedef union {
struct {
uint8_t align : 2;
uint8_t right_merge : 1;
uint8_t crop : 1;
} s;
@ -58,7 +57,7 @@ typedef struct {
lv_coord_t * row_h;
lv_coord_t * col_w;
lv_table_cell_drawer_cb_t drawer_cb;
} lv_table_ext_t;
} lv_table_t;
extern const lv_obj_class_t lv_table;
@ -119,15 +118,6 @@ void lv_table_set_col_cnt(lv_obj_t * table, uint16_t col_cnt);
*/
void lv_table_set_col_width(lv_obj_t * table, uint16_t col_id, lv_coord_t w);
/**
* Set the text align in a cell
* @param table pointer to a Table object
* @param row id of the row [0 .. row_cnt -1]
* @param col id of the column [0 .. col_cnt -1]
* @param align LV_TEXT_ALIGN_LEFT or LV_TEXT_ALIGN_CENTER or LV_TEXT_ALIGN_RIGHT
*/
void lv_table_set_cell_align(lv_obj_t * table, uint16_t row, uint16_t col, lv_text_align_t align);
/**
* Set the cell crop. (Don't adjust the height of the cell according to its content)
* @param table pointer to a Table object