arch(draw): add parallel rendering architecture
BREAKING CHANGE This is a huge update which introduces parallel rendering. lv_conf.h needs to be updated too.
This commit is contained in:
@@ -8,9 +8,6 @@ static void set_value(void * bar, int32_t v)
|
||||
|
||||
static void event_cb(lv_event_t * e)
|
||||
{
|
||||
lv_obj_draw_part_dsc_t * dsc = lv_event_get_draw_part_dsc(e);
|
||||
if(dsc->part != LV_PART_INDICATOR) return;
|
||||
|
||||
lv_obj_t * obj = lv_event_get_target(e);
|
||||
|
||||
lv_draw_label_dsc_t label_dsc;
|
||||
@@ -25,23 +22,28 @@ static void event_cb(lv_event_t * e)
|
||||
label_dsc.flag);
|
||||
|
||||
lv_area_t txt_area;
|
||||
txt_area.x1 = 0;
|
||||
txt_area.x2 = txt_size.x - 1;
|
||||
txt_area.y1 = 0;
|
||||
txt_area.y2 = txt_size.y - 1;
|
||||
|
||||
lv_bar_t * bar = (lv_bar_t *) obj;
|
||||
const lv_area_t * indic_area = &bar->indic_area;
|
||||
|
||||
/*If the indicator is long enough put the text inside on the right*/
|
||||
if(lv_area_get_width(dsc->draw_area) > txt_size.x + 20) {
|
||||
txt_area.x2 = dsc->draw_area->x2 - 5;
|
||||
txt_area.x1 = txt_area.x2 - txt_size.x + 1;
|
||||
if(lv_area_get_width(indic_area) > txt_size.x + 20) {
|
||||
lv_area_align(indic_area, &txt_area, LV_ALIGN_RIGHT_MID, -10, 0);
|
||||
label_dsc.color = lv_color_white();
|
||||
}
|
||||
/*If the indicator is still short put the text out of it on the right*/
|
||||
else {
|
||||
txt_area.x1 = dsc->draw_area->x2 + 5;
|
||||
txt_area.x2 = txt_area.x1 + txt_size.x - 1;
|
||||
lv_area_align(indic_area, &txt_area, LV_ALIGN_OUT_RIGHT_MID, 10, 0);
|
||||
label_dsc.color = lv_color_black();
|
||||
}
|
||||
|
||||
txt_area.y1 = dsc->draw_area->y1 + (lv_area_get_height(dsc->draw_area) - txt_size.y) / 2;
|
||||
txt_area.y2 = txt_area.y1 + txt_size.y - 1;
|
||||
|
||||
lv_draw_label(dsc->draw_ctx, &label_dsc, &txt_area, buf, NULL);
|
||||
label_dsc.text = buf;
|
||||
label_dsc.text_local = true;
|
||||
lv_layer_t * layer = lv_event_get_layer(e);
|
||||
lv_draw_label(layer, &label_dsc, &txt_area);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -50,17 +52,17 @@ static void event_cb(lv_event_t * e)
|
||||
void lv_example_bar_6(void)
|
||||
{
|
||||
lv_obj_t * bar = lv_bar_create(lv_scr_act());
|
||||
lv_obj_add_event(bar, event_cb, LV_EVENT_DRAW_PART_END, NULL);
|
||||
lv_obj_set_size(bar, 200, 20);
|
||||
lv_obj_center(bar);
|
||||
lv_obj_add_event(bar, event_cb, LV_EVENT_DRAW_MAIN_END, NULL);
|
||||
|
||||
lv_anim_t a;
|
||||
lv_anim_init(&a);
|
||||
lv_anim_set_var(&a, bar);
|
||||
lv_anim_set_values(&a, 0, 100);
|
||||
lv_anim_set_exec_cb(&a, set_value);
|
||||
lv_anim_set_time(&a, 2000);
|
||||
lv_anim_set_playback_time(&a, 2000);
|
||||
lv_anim_set_time(&a, 4000);
|
||||
lv_anim_set_playback_time(&a, 4000);
|
||||
lv_anim_set_repeat_count(&a, LV_ANIM_REPEAT_INFINITE);
|
||||
lv_anim_start(&a);
|
||||
|
||||
|
||||
@@ -1,54 +1 @@
|
||||
def set_value(bar, v):
|
||||
bar.set_value(v, lv.ANIM.OFF)
|
||||
|
||||
def event_cb(e):
|
||||
dsc = lv.obj_draw_part_dsc_t.__cast__(e.get_param())
|
||||
if dsc.part != lv.PART.INDICATOR:
|
||||
return
|
||||
|
||||
obj= e.get_target_obj()
|
||||
|
||||
label_dsc = lv.draw_label_dsc_t()
|
||||
label_dsc.init()
|
||||
# label_dsc.font = LV_FONT_DEFAULT;
|
||||
|
||||
value_txt = str(obj.get_value())
|
||||
txt_size = lv.point_t()
|
||||
lv.txt_get_size(txt_size, value_txt, label_dsc.font, label_dsc.letter_space, label_dsc.line_space, lv.COORD.MAX, label_dsc.flag)
|
||||
|
||||
txt_area = lv.area_t()
|
||||
# If the indicator is long enough put the text inside on the right
|
||||
if dsc.draw_area.get_width() > txt_size.x + 20:
|
||||
txt_area.x2 = dsc.draw_area.x2 - 5
|
||||
txt_area.x1 = txt_area.x2 - txt_size.x + 1
|
||||
label_dsc.color = lv.color_white()
|
||||
# If the indicator is still short put the text out of it on the right*/
|
||||
else:
|
||||
txt_area.x1 = dsc.draw_area.x2 + 5
|
||||
txt_area.x2 = txt_area.x1 + txt_size.x - 1
|
||||
label_dsc.color = lv.color_black()
|
||||
|
||||
txt_area.y1 = dsc.draw_area.y1 + (dsc.draw_area.get_height() - txt_size.y) // 2
|
||||
txt_area.y2 = txt_area.y1 + txt_size.y - 1
|
||||
|
||||
dsc.draw_ctx.label(label_dsc, txt_area, value_txt, None)
|
||||
|
||||
#
|
||||
# Custom drawer on the bar to display the current value
|
||||
#
|
||||
|
||||
bar = lv.bar(lv.scr_act())
|
||||
bar.add_event(event_cb, lv.EVENT.DRAW_PART_END, None)
|
||||
bar.set_size(200, 20)
|
||||
bar.center()
|
||||
|
||||
a = lv.anim_t()
|
||||
a.init()
|
||||
a.set_var(bar)
|
||||
a.set_values(0, 100)
|
||||
a.set_custom_exec_cb(lambda a,val: set_value(bar,val))
|
||||
a.set_time(2000)
|
||||
a.set_playback_time(2000)
|
||||
a.set_repeat_count(lv.ANIM_REPEAT_INFINITE)
|
||||
lv.anim_t.start(a)
|
||||
|
||||
pass
|
||||
|
||||
Reference in New Issue
Block a user