summaryrefslogtreecommitdiff
path: root/lib/lvgl/examples/widgets/bar
diff options
context:
space:
mode:
authorjacqueline <me@jacqueline.id.au>2023-06-01 15:41:47 +1000
committerjacqueline <me@jacqueline.id.au>2023-06-01 15:41:47 +1000
commitdd27c3530432ea0b09f01e604bf577f31d8ef841 (patch)
treebbf86cf81a78f0ff0b07f31f1c390db473f26fd3 /lib/lvgl/examples/widgets/bar
parent6fd588e970470b15936187980829916d0dbe77bb (diff)
downloadtangara-fw-dd27c3530432ea0b09f01e604bf577f31d8ef841.tar.gz
convert lvgl from submodule to a plain old directory
Diffstat (limited to 'lib/lvgl/examples/widgets/bar')
m---------lib/lvgl0
-rw-r--r--lib/lvgl/examples/widgets/bar/index.rst36
-rw-r--r--lib/lvgl/examples/widgets/bar/lv_example_bar_1.c12
-rw-r--r--lib/lvgl/examples/widgets/bar/lv_example_bar_1.py5
-rw-r--r--lib/lvgl/examples/widgets/bar/lv_example_bar_2.c34
-rw-r--r--lib/lvgl/examples/widgets/bar/lv_example_bar_2.py27
-rw-r--r--lib/lvgl/examples/widgets/bar/lv_example_bar_3.c40
-rw-r--r--lib/lvgl/examples/widgets/bar/lv_example_bar_3.py32
-rw-r--r--lib/lvgl/examples/widgets/bar/lv_example_bar_4.c27
-rw-r--r--lib/lvgl/examples/widgets/bar/lv_example_bar_4.py45
-rw-r--r--lib/lvgl/examples/widgets/bar/lv_example_bar_5.c32
-rw-r--r--lib/lvgl/examples/widgets/bar/lv_example_bar_5.py22
-rw-r--r--lib/lvgl/examples/widgets/bar/lv_example_bar_6.c69
-rw-r--r--lib/lvgl/examples/widgets/bar/lv_example_bar_6.py54
-rw-r--r--lib/lvgl/examples/widgets/bar/test.py57
15 files changed, 492 insertions, 0 deletions
diff --git a/lib/lvgl b/lib/lvgl
deleted file mode 160000
-Subproject 0732400e7b564dd0e7dc4a924619d8e19c5b23a
diff --git a/lib/lvgl/examples/widgets/bar/index.rst b/lib/lvgl/examples/widgets/bar/index.rst
new file mode 100644
index 00000000..4c4bb850
--- /dev/null
+++ b/lib/lvgl/examples/widgets/bar/index.rst
@@ -0,0 +1,36 @@
+Simple Bar
+""""""""""""""""
+
+.. lv_example:: widgets/bar/lv_example_bar_1
+ :language: c
+
+Styling a bar
+""""""""""""""""
+
+.. lv_example:: widgets/bar/lv_example_bar_2
+ :language: c
+
+Temperature meter
+""""""""""""""""""
+
+.. lv_example:: widgets/bar/lv_example_bar_3
+ :language: c
+
+Stripe pattern and range value
+""""""""""""""""""""""""""""""""
+
+.. lv_example:: widgets/bar/lv_example_bar_4
+ :language: c
+
+Bar with LTR and RTL base direction
+""""""""""""""""""""""""""""""""""""
+
+.. lv_example:: widgets/bar/lv_example_bar_5
+ :language: c
+
+Custom drawer to show the current value
+"""""""""""""""""""""""""""""""""""""""
+
+.. lv_example:: widgets/bar/lv_example_bar_6
+ :language: c
+
diff --git a/lib/lvgl/examples/widgets/bar/lv_example_bar_1.c b/lib/lvgl/examples/widgets/bar/lv_example_bar_1.c
new file mode 100644
index 00000000..3ea98ab9
--- /dev/null
+++ b/lib/lvgl/examples/widgets/bar/lv_example_bar_1.c
@@ -0,0 +1,12 @@
+#include "../../lv_examples.h"
+#if LV_USE_BAR && LV_BUILD_EXAMPLES
+
+void lv_example_bar_1(void)
+{
+ lv_obj_t * bar1 = lv_bar_create(lv_scr_act());
+ lv_obj_set_size(bar1, 200, 20);
+ lv_obj_center(bar1);
+ lv_bar_set_value(bar1, 70, LV_ANIM_OFF);
+}
+
+#endif
diff --git a/lib/lvgl/examples/widgets/bar/lv_example_bar_1.py b/lib/lvgl/examples/widgets/bar/lv_example_bar_1.py
new file mode 100644
index 00000000..874e3d75
--- /dev/null
+++ b/lib/lvgl/examples/widgets/bar/lv_example_bar_1.py
@@ -0,0 +1,5 @@
+bar1 = lv.bar(lv.scr_act())
+bar1.set_size(200, 20)
+bar1.center()
+bar1.set_value(70, lv.ANIM.OFF)
+
diff --git a/lib/lvgl/examples/widgets/bar/lv_example_bar_2.c b/lib/lvgl/examples/widgets/bar/lv_example_bar_2.c
new file mode 100644
index 00000000..2688cc2d
--- /dev/null
+++ b/lib/lvgl/examples/widgets/bar/lv_example_bar_2.c
@@ -0,0 +1,34 @@
+#include "../../lv_examples.h"
+#if LV_USE_BAR && LV_BUILD_EXAMPLES
+
+/**
+ * Example of styling the bar
+ */
+void lv_example_bar_2(void)
+{
+ static lv_style_t style_bg;
+ static lv_style_t style_indic;
+
+ lv_style_init(&style_bg);
+ lv_style_set_border_color(&style_bg, lv_palette_main(LV_PALETTE_BLUE));
+ lv_style_set_border_width(&style_bg, 2);
+ lv_style_set_pad_all(&style_bg, 6); /*To make the indicator smaller*/
+ lv_style_set_radius(&style_bg, 6);
+ lv_style_set_anim_time(&style_bg, 1000);
+
+ lv_style_init(&style_indic);
+ lv_style_set_bg_opa(&style_indic, LV_OPA_COVER);
+ lv_style_set_bg_color(&style_indic, lv_palette_main(LV_PALETTE_BLUE));
+ lv_style_set_radius(&style_indic, 3);
+
+ lv_obj_t * bar = lv_bar_create(lv_scr_act());
+ lv_obj_remove_style_all(bar); /*To have a clean start*/
+ lv_obj_add_style(bar, &style_bg, 0);
+ lv_obj_add_style(bar, &style_indic, LV_PART_INDICATOR);
+
+ lv_obj_set_size(bar, 200, 20);
+ lv_obj_center(bar);
+ lv_bar_set_value(bar, 100, LV_ANIM_ON);
+}
+
+#endif
diff --git a/lib/lvgl/examples/widgets/bar/lv_example_bar_2.py b/lib/lvgl/examples/widgets/bar/lv_example_bar_2.py
new file mode 100644
index 00000000..37dbc0d6
--- /dev/null
+++ b/lib/lvgl/examples/widgets/bar/lv_example_bar_2.py
@@ -0,0 +1,27 @@
+#
+# Example of styling the bar
+#
+style_bg = lv.style_t()
+style_indic = lv.style_t()
+
+style_bg.init()
+style_bg.set_border_color(lv.palette_main(lv.PALETTE.BLUE))
+style_bg.set_border_width(2)
+style_bg.set_pad_all(6) # To make the indicator smaller
+style_bg.set_radius(6)
+style_bg.set_anim_time(1000)
+
+style_indic.init()
+style_indic.set_bg_opa(lv.OPA.COVER)
+style_indic.set_bg_color(lv.palette_main(lv.PALETTE.BLUE))
+style_indic.set_radius(3)
+
+bar = lv.bar(lv.scr_act())
+bar.remove_style_all() # To have a clean start
+bar.add_style(style_bg, 0)
+bar.add_style(style_indic, lv.PART.INDICATOR)
+
+bar.set_size(200, 20)
+bar.center()
+bar.set_value(100, lv.ANIM.ON)
+
diff --git a/lib/lvgl/examples/widgets/bar/lv_example_bar_3.c b/lib/lvgl/examples/widgets/bar/lv_example_bar_3.c
new file mode 100644
index 00000000..eaa8487a
--- /dev/null
+++ b/lib/lvgl/examples/widgets/bar/lv_example_bar_3.c
@@ -0,0 +1,40 @@
+#include "../../lv_examples.h"
+#if LV_USE_BAR && LV_BUILD_EXAMPLES
+
+static void set_temp(void * bar, int32_t temp)
+{
+ lv_bar_set_value(bar, temp, LV_ANIM_ON);
+}
+
+/**
+ * A temperature meter example
+ */
+void lv_example_bar_3(void)
+{
+ static lv_style_t style_indic;
+
+ lv_style_init(&style_indic);
+ lv_style_set_bg_opa(&style_indic, LV_OPA_COVER);
+ lv_style_set_bg_color(&style_indic, lv_palette_main(LV_PALETTE_RED));
+ lv_style_set_bg_grad_color(&style_indic, lv_palette_main(LV_PALETTE_BLUE));
+ lv_style_set_bg_grad_dir(&style_indic, LV_GRAD_DIR_VER);
+
+ lv_obj_t * bar = lv_bar_create(lv_scr_act());
+ lv_obj_add_style(bar, &style_indic, LV_PART_INDICATOR);
+ lv_obj_set_size(bar, 20, 200);
+ lv_obj_center(bar);
+ lv_bar_set_range(bar, -20, 40);
+
+ lv_anim_t a;
+ lv_anim_init(&a);
+ lv_anim_set_exec_cb(&a, set_temp);
+ lv_anim_set_time(&a, 3000);
+ lv_anim_set_playback_time(&a, 3000);
+ lv_anim_set_var(&a, bar);
+ lv_anim_set_values(&a, -20, 40);
+ lv_anim_set_repeat_count(&a, LV_ANIM_REPEAT_INFINITE);
+ lv_anim_start(&a);
+}
+
+
+#endif
diff --git a/lib/lvgl/examples/widgets/bar/lv_example_bar_3.py b/lib/lvgl/examples/widgets/bar/lv_example_bar_3.py
new file mode 100644
index 00000000..c5f52f39
--- /dev/null
+++ b/lib/lvgl/examples/widgets/bar/lv_example_bar_3.py
@@ -0,0 +1,32 @@
+def set_temp(bar, temp):
+ bar.set_value(temp, lv.ANIM.ON)
+
+#
+# A temperature meter example
+#
+
+
+style_indic = lv.style_t()
+
+style_indic.init()
+style_indic.set_bg_opa(lv.OPA.COVER)
+style_indic.set_bg_color(lv.palette_main(lv.PALETTE.RED))
+style_indic.set_bg_grad_color(lv.palette_main(lv.PALETTE.BLUE))
+style_indic.set_bg_grad_dir(lv.GRAD_DIR.VER)
+
+bar = lv.bar(lv.scr_act())
+bar.add_style(style_indic, lv.PART.INDICATOR)
+bar.set_size(20, 200)
+bar.center()
+bar.set_range(-20, 40)
+
+a = lv.anim_t()
+a.init()
+a.set_time(3000)
+a.set_playback_time(3000)
+a.set_var(bar)
+a.set_values(-20, 40)
+a.set_repeat_count(lv.ANIM_REPEAT.INFINITE)
+a.set_custom_exec_cb(lambda a, val: set_temp(bar,val))
+lv.anim_t.start(a)
+
diff --git a/lib/lvgl/examples/widgets/bar/lv_example_bar_4.c b/lib/lvgl/examples/widgets/bar/lv_example_bar_4.c
new file mode 100644
index 00000000..f9abdf93
--- /dev/null
+++ b/lib/lvgl/examples/widgets/bar/lv_example_bar_4.c
@@ -0,0 +1,27 @@
+#include "../../lv_examples.h"
+#if LV_USE_BAR && LV_BUILD_EXAMPLES
+
+/**
+ * Bar with stripe pattern and ranged value
+ */
+void lv_example_bar_4(void)
+{
+ LV_IMG_DECLARE(img_skew_strip);
+ static lv_style_t style_indic;
+
+ lv_style_init(&style_indic);
+ lv_style_set_bg_img_src(&style_indic, &img_skew_strip);
+ lv_style_set_bg_img_tiled(&style_indic, true);
+ lv_style_set_bg_img_opa(&style_indic, LV_OPA_30);
+
+ lv_obj_t * bar = lv_bar_create(lv_scr_act());
+ lv_obj_add_style(bar, &style_indic, LV_PART_INDICATOR);
+
+ lv_obj_set_size(bar, 260, 20);
+ lv_obj_center(bar);
+ lv_bar_set_mode(bar, LV_BAR_MODE_RANGE);
+ lv_bar_set_value(bar, 90, LV_ANIM_OFF);
+ lv_bar_set_start_value(bar, 20, LV_ANIM_OFF);
+}
+
+#endif
diff --git a/lib/lvgl/examples/widgets/bar/lv_example_bar_4.py b/lib/lvgl/examples/widgets/bar/lv_example_bar_4.py
new file mode 100644
index 00000000..dcfb1924
--- /dev/null
+++ b/lib/lvgl/examples/widgets/bar/lv_example_bar_4.py
@@ -0,0 +1,45 @@
+#
+# get an icon
+#
+def get_icon(filename,xres,yres):
+ try:
+ sdl_filename = "../../assets/" + filename + "_" + str(xres) + "x" + str(yres) + "_argb8888.fnt"
+ print("file name: ", sdl_filename)
+ with open(sdl_filename,'rb') as f:
+ icon_data = f.read()
+ except:
+ print("Could not find image file: " + filename)
+ return None
+
+ icon_dsc = lv.img_dsc_t(
+ {
+ "header": {"always_zero": 0, "w": xres, "h": yres, "cf": lv.img.CF.TRUE_COLOR_ALPHA},
+ "data": icon_data,
+ "data_size": len(icon_data),
+ }
+ )
+ return icon_dsc
+
+#
+# Bar with stripe pattern and ranged value
+#
+
+img_skew_strip_dsc = get_icon("img_skew_strip",80,20)
+style_indic = lv.style_t()
+
+style_indic.init()
+style_indic.set_bg_img_src(img_skew_strip_dsc)
+style_indic.set_bg_img_tiled(True)
+style_indic.set_bg_img_opa(lv.OPA._30)
+
+bar = lv.bar(lv.scr_act())
+bar.add_style(style_indic, lv.PART.INDICATOR)
+
+bar.set_size(260, 20)
+bar.center()
+bar.set_mode(lv.bar.MODE.RANGE)
+bar.set_value(90, lv.ANIM.OFF)
+bar.set_start_value(20, lv.ANIM.OFF)
+
+
+
diff --git a/lib/lvgl/examples/widgets/bar/lv_example_bar_5.c b/lib/lvgl/examples/widgets/bar/lv_example_bar_5.c
new file mode 100644
index 00000000..c416380a
--- /dev/null
+++ b/lib/lvgl/examples/widgets/bar/lv_example_bar_5.c
@@ -0,0 +1,32 @@
+#include "../../lv_examples.h"
+#if LV_USE_BAR && LV_BUILD_EXAMPLES
+
+/**
+ * Bar with LTR and RTL base direction
+ */
+void lv_example_bar_5(void)
+{
+ lv_obj_t * label;
+
+
+ lv_obj_t * bar_ltr = lv_bar_create(lv_scr_act());
+ lv_obj_set_size(bar_ltr, 200, 20);
+ lv_bar_set_value(bar_ltr, 70, LV_ANIM_OFF);
+ lv_obj_align(bar_ltr, LV_ALIGN_CENTER, 0, -30);
+
+ label = lv_label_create(lv_scr_act());
+ lv_label_set_text(label, "Left to Right base direction");
+ lv_obj_align_to(label, bar_ltr, LV_ALIGN_OUT_TOP_MID, 0, -5);
+
+ lv_obj_t * bar_rtl = lv_bar_create(lv_scr_act());
+ lv_obj_set_style_base_dir(bar_rtl, LV_BASE_DIR_RTL, 0);
+ lv_obj_set_size(bar_rtl, 200, 20);
+ lv_bar_set_value(bar_rtl, 70, LV_ANIM_OFF);
+ lv_obj_align(bar_rtl, LV_ALIGN_CENTER, 0, 30);
+
+ label = lv_label_create(lv_scr_act());
+ lv_label_set_text(label, "Right to Left base direction");
+ lv_obj_align_to(label, bar_rtl, LV_ALIGN_OUT_TOP_MID, 0, -5);
+}
+
+#endif
diff --git a/lib/lvgl/examples/widgets/bar/lv_example_bar_5.py b/lib/lvgl/examples/widgets/bar/lv_example_bar_5.py
new file mode 100644
index 00000000..7c81ec8b
--- /dev/null
+++ b/lib/lvgl/examples/widgets/bar/lv_example_bar_5.py
@@ -0,0 +1,22 @@
+#
+# Bar with LTR and RTL base direction
+#
+
+bar_ltr = lv.bar(lv.scr_act())
+bar_ltr.set_size(200, 20)
+bar_ltr.set_value(70, lv.ANIM.OFF)
+bar_ltr.align(lv.ALIGN.CENTER, 0, -30)
+
+label = lv.label(lv.scr_act())
+label.set_text("Left to Right base direction")
+label.align_to(bar_ltr, lv.ALIGN.OUT_TOP_MID, 0, -5)
+
+bar_rtl = lv.bar(lv.scr_act())
+bar_rtl.set_style_base_dir(lv.BASE_DIR.RTL,0)
+bar_rtl.set_size(200, 20)
+bar_rtl.set_value(70, lv.ANIM.OFF)
+bar_rtl.align(lv.ALIGN.CENTER, 0, 30)
+
+label = lv.label(lv.scr_act())
+label.set_text("Right to Left base direction")
+label.align_to(bar_rtl, lv.ALIGN.OUT_TOP_MID, 0, -5)
diff --git a/lib/lvgl/examples/widgets/bar/lv_example_bar_6.c b/lib/lvgl/examples/widgets/bar/lv_example_bar_6.c
new file mode 100644
index 00000000..2a159cc5
--- /dev/null
+++ b/lib/lvgl/examples/widgets/bar/lv_example_bar_6.c
@@ -0,0 +1,69 @@
+#include "../../lv_examples.h"
+#if LV_USE_BAR && LV_BUILD_EXAMPLES
+
+static void set_value(void * bar, int32_t v)
+{
+ lv_bar_set_value(bar, v, LV_ANIM_OFF);
+}
+
+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;
+ lv_draw_label_dsc_init(&label_dsc);
+ label_dsc.font = LV_FONT_DEFAULT;
+
+ char buf[8];
+ lv_snprintf(buf, sizeof(buf), "%d", (int)lv_bar_get_value(obj));
+
+ lv_point_t txt_size;
+ lv_txt_get_size(&txt_size, buf, label_dsc.font, label_dsc.letter_space, label_dsc.line_space, LV_COORD_MAX,
+ label_dsc.flag);
+
+ lv_area_t txt_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;
+ 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 + (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);
+}
+
+/**
+ * Custom drawer on the bar to display the current value
+ */
+void lv_example_bar_6(void)
+{
+ lv_obj_t * bar = lv_bar_create(lv_scr_act());
+ lv_obj_add_event_cb(bar, event_cb, LV_EVENT_DRAW_PART_END, NULL);
+ lv_obj_set_size(bar, 200, 20);
+ lv_obj_center(bar);
+
+ 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_repeat_count(&a, LV_ANIM_REPEAT_INFINITE);
+ lv_anim_start(&a);
+
+}
+
+#endif
diff --git a/lib/lvgl/examples/widgets/bar/lv_example_bar_6.py b/lib/lvgl/examples/widgets/bar/lv_example_bar_6.py
new file mode 100644
index 00000000..9d68a871
--- /dev/null
+++ b/lib/lvgl/examples/widgets/bar/lv_example_bar_6.py
@@ -0,0 +1,54 @@
+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()
+
+ 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_cb(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)
+
diff --git a/lib/lvgl/examples/widgets/bar/test.py b/lib/lvgl/examples/widgets/bar/test.py
new file mode 100644
index 00000000..b7843558
--- /dev/null
+++ b/lib/lvgl/examples/widgets/bar/test.py
@@ -0,0 +1,57 @@
+#!/opt/bin/lv_micropython -i
+import lvgl as lv
+import display_driver
+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()
+
+ 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_cb(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)
+