feat(bar): reverse drawing direction of lv_bar if min > max (#4654)

Signed-off-by: wangxuedong <wangxuedong@xiaomi.com>
This commit is contained in:
xaowang96
2023-10-21 05:22:56 +08:00
committed by GitHub
parent c0356c9380
commit 8f57f12a44
14 changed files with 217 additions and 65 deletions

View File

@@ -17,4 +17,8 @@ Slider with extended drawer
.. lv_example:: widgets/slider/lv_example_slider_3
:language: c
Slider with opposite direction
------------------------------
.. lv_example:: widgets/slider/lv_example_slider_4
:language: c

View File

@@ -0,0 +1,34 @@
#include "../../lv_examples.h"
#if LV_USE_SLIDER && LV_BUILD_EXAMPLES
static void slider_event_cb(lv_event_t * e);
static lv_obj_t * slider_label;
/**
* Slider with opposite direction
*/
void lv_example_slider_4(void)
{
/*Create a slider in the center of the display*/
lv_obj_t * slider = lv_slider_create(lv_scr_act());
lv_obj_center(slider);
lv_obj_add_event(slider, slider_event_cb, LV_EVENT_VALUE_CHANGED, NULL);
/*Reverse the direction of the slider*/
lv_slider_set_range(slider, 100, 0);
/*Create a label below the slider*/
slider_label = lv_label_create(lv_scr_act());
lv_label_set_text(slider_label, "0%");
lv_obj_align_to(slider_label, slider, LV_ALIGN_OUT_BOTTOM_MID, 0, 10);
}
static void slider_event_cb(lv_event_t * e)
{
lv_obj_t * slider = lv_event_get_target(e);
char buf[8];
lv_snprintf(buf, sizeof(buf), "%d%%", (int)lv_slider_get_value(slider));
lv_label_set_text(slider_label, buf);
lv_obj_align_to(slider_label, slider, LV_ALIGN_OUT_BOTTOM_MID, 0, 10);
}
#endif

View File

@@ -0,0 +1,21 @@
#
# Slider with opposite direction
#
def slider_event_cb(e):
slider = e.get_target_obj()
slider_label.set_text("{:d}%".format(slider.get_value()))
slider_label.align_to(slider, lv.ALIGN.OUT_BOTTOM_MID, 0, 10)
# Create a slider in the center of the display
slider = lv.slider(lv.screen_active())
slider.center()
slider.add_event(slider_event_cb, lv.EVENT.VALUE_CHANGED, None)
slider.set_range(100, 0)
# Create a label below the slider
slider_label = lv.label(lv.screen_active())
slider_label.set_text("0%")
slider_label.align_to(slider, lv.ALIGN.OUT_BOTTOM_MID, 0, 10)