update asserts
This commit is contained in:
35
examples/widgets/slider/lv_example_slider_1.c
Normal file
35
examples/widgets/slider/lv_example_slider_1.c
Normal file
@@ -0,0 +1,35 @@
|
||||
#include "../../../lvgl.h"
|
||||
#include <stdio.h>
|
||||
#if LV_USE_SLIDER
|
||||
|
||||
static void slider_event_cb(lv_obj_t * slider, lv_event_t event);
|
||||
static lv_obj_t * slider_label;
|
||||
|
||||
/**
|
||||
* A default slider with a label displaying the current value
|
||||
*/
|
||||
void lv_example_slider_1(void)
|
||||
{
|
||||
/* Create a slider in the center of the display */
|
||||
lv_obj_t * slider = lv_slider_create(lv_scr_act(), NULL);
|
||||
lv_obj_align(slider, NULL, LV_ALIGN_CENTER, 0, 0);
|
||||
lv_obj_add_event_cb(slider, slider_event_cb, NULL);
|
||||
|
||||
/* Create a label below the slider */
|
||||
slider_label = lv_label_create(lv_scr_act(), NULL);
|
||||
lv_label_set_text(slider_label, "0%");
|
||||
|
||||
lv_obj_align(slider_label, slider, LV_ALIGN_OUT_BOTTOM_MID, 0, 10);
|
||||
}
|
||||
|
||||
static void slider_event_cb(lv_obj_t * slider, lv_event_t event)
|
||||
{
|
||||
if(event == LV_EVENT_VALUE_CHANGED) {
|
||||
char buf[8];
|
||||
lv_snprintf(buf, sizeof(buf), "%d%%", lv_slider_get_value(slider));
|
||||
lv_label_set_text(slider_label, buf);
|
||||
lv_obj_align(slider_label, slider, LV_ALIGN_OUT_BOTTOM_MID, 0, 10);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
37
examples/widgets/slider/lv_example_slider_1.py
Normal file
37
examples/widgets/slider/lv_example_slider_1.py
Normal file
@@ -0,0 +1,37 @@
|
||||
def event_handler(obj, event):
|
||||
if event == lv.EVENT.VALUE_CHANGED:
|
||||
print("Value: %d" % obj.get_value())
|
||||
|
||||
# Create styles
|
||||
style_bg = lv.style_t()
|
||||
style_indic = lv.style_t()
|
||||
style_knob = lv.style_t()
|
||||
|
||||
lv.style_copy(style_bg, lv.style_pretty)
|
||||
style_bg.body.main_color = lv.color_make(0,0,0)
|
||||
style_bg.body.grad_color = lv.color_make(0x80, 0x80, 0x80)
|
||||
style_bg.body.radius = 800 # large enough to make a circle
|
||||
style_bg.body.border.color = lv.color_make(0xff,0xff,0xff)
|
||||
|
||||
lv.style_copy(style_indic, lv.style_pretty_color)
|
||||
style_indic.body.radius = 800
|
||||
style_indic.body.shadow.width = 8
|
||||
style_indic.body.shadow.color = style_indic.body.main_color
|
||||
style_indic.body.padding.left = 3
|
||||
style_indic.body.padding.right = 3
|
||||
style_indic.body.padding.top = 3
|
||||
style_indic.body.padding.bottom = 3
|
||||
|
||||
lv.style_copy(style_knob, lv.style_pretty)
|
||||
style_knob.body.radius = 800
|
||||
style_knob.body.opa = lv.OPA._70
|
||||
style_knob.body.padding.top = 10
|
||||
style_knob.body.padding.bottom = 10
|
||||
|
||||
# Create a slider
|
||||
slider = lv.slider(lv.scr_act())
|
||||
slider.set_style(lv.slider.STYLE.BG, style_bg)
|
||||
slider.set_style(lv.slider.STYLE.INDIC, style_indic)
|
||||
slider.set_style(lv.slider.STYLE.KNOB, style_knob)
|
||||
slider.align(None, lv.ALIGN.CENTER, 0, 0)
|
||||
slider.set_event_cb(event_handler)
|
||||
43
examples/widgets/slider/lv_example_slider_2.c
Normal file
43
examples/widgets/slider/lv_example_slider_2.c
Normal file
@@ -0,0 +1,43 @@
|
||||
#include "../../../lvgl.h"
|
||||
#include <stdio.h>
|
||||
#if LV_USE_SLIDER
|
||||
|
||||
static void slider_event_cb(lv_obj_t * slider, lv_event_t event);
|
||||
|
||||
static lv_style_t style_pr;
|
||||
static lv_style_t style_def;
|
||||
|
||||
/**
|
||||
* Show the current value when the slider if pressed (using only styles).
|
||||
*
|
||||
*/
|
||||
void lv_example_slider_2(void)
|
||||
{
|
||||
lv_style_init(&style_def);
|
||||
lv_style_set_content_opa(&style_def, LV_OPA_TRANSP);
|
||||
lv_style_set_content_align(&style_def, LV_ALIGN_OUT_TOP_MID);
|
||||
|
||||
lv_style_init(&style_pr);
|
||||
lv_style_set_content_opa(&style_pr, LV_OPA_COVER);
|
||||
lv_style_set_content_ofs_y(&style_pr, -15);
|
||||
|
||||
/* Create a slider in the center of the display */
|
||||
lv_obj_t * slider;
|
||||
slider = lv_slider_create(lv_scr_act(), NULL);
|
||||
lv_obj_align(slider, NULL, LV_ALIGN_CENTER, 0, 0);
|
||||
lv_obj_add_event_cb(slider, slider_event_cb, NULL);
|
||||
|
||||
lv_obj_add_style(slider, LV_PART_KNOB, LV_STATE_DEFAULT, &style_def);
|
||||
lv_obj_add_style(slider, LV_PART_KNOB, LV_STATE_PRESSED, &style_pr);
|
||||
}
|
||||
|
||||
static void slider_event_cb(lv_obj_t * slider, lv_event_t event)
|
||||
{
|
||||
if(event == LV_EVENT_VALUE_CHANGED) {
|
||||
static char buf[8];
|
||||
lv_snprintf(buf, sizeof(buf), "%u", lv_slider_get_value(slider));
|
||||
lv_obj_set_style_content_text(slider, LV_PART_KNOB, LV_STATE_DEFAULT, buf);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
23
examples/widgets/slider/lv_example_slider_2.py
Normal file
23
examples/widgets/slider/lv_example_slider_2.py
Normal file
@@ -0,0 +1,23 @@
|
||||
def slider_event_cb(slider, event):
|
||||
if event == lv.EVENT.VALUE_CHANGED:
|
||||
slider_label.set_text("%u" % slider.get_value())
|
||||
|
||||
# Create a slider in the center of the display
|
||||
slider = lv.slider(lv.scr_act())
|
||||
slider.set_width(200)
|
||||
slider.align(None, lv.ALIGN.CENTER, 0, 0)
|
||||
slider.set_event_cb(slider_event_cb)
|
||||
slider.set_range(0, 100)
|
||||
|
||||
# Create a label below the slider
|
||||
slider_label = lv.label(lv.scr_act())
|
||||
slider_label.set_text("0")
|
||||
slider_label.set_auto_realign(True)
|
||||
slider_label.align(slider, lv.ALIGN.OUT_BOTTOM_MID, 0, 10)
|
||||
|
||||
# Create an informative label
|
||||
info = lv.label(lv.scr_act())
|
||||
info.set_text("""Welcome to the slider+label demo!
|
||||
Move the slider and see that the label
|
||||
updates to match it.""")
|
||||
info.align(None, lv.ALIGN.IN_TOP_LEFT, 10, 10)
|
||||
39
examples/widgets/slider/lv_example_slider_3.c
Normal file
39
examples/widgets/slider/lv_example_slider_3.c
Normal file
@@ -0,0 +1,39 @@
|
||||
#include "../../../lvgl.h"
|
||||
#include <stdio.h>
|
||||
#if LV_USE_SLIDER
|
||||
|
||||
static void slider_event_cb(lv_obj_t * slider, lv_event_t event);
|
||||
|
||||
/**
|
||||
* Show the current value when the slider if pressed (using only styles).
|
||||
*
|
||||
*/
|
||||
void lv_example_slider_3(void)
|
||||
{
|
||||
/* Create a slider in the center of the display */
|
||||
lv_obj_t * slider;
|
||||
slider = lv_slider_create(lv_scr_act(), NULL);
|
||||
lv_obj_align(slider, NULL, LV_ALIGN_CENTER, 0, 0);
|
||||
lv_obj_add_event_cb(slider, slider_event_cb, NULL);
|
||||
lv_slider_set_type(slider, LV_SLIDER_TYPE_RANGE);
|
||||
|
||||
lv_slider_set_value(slider, 70, LV_ANIM_OFF);
|
||||
lv_slider_set_left_value(slider, 20, LV_ANIM_OFF);
|
||||
|
||||
/*Now use only a local style.*/
|
||||
lv_obj_set_style_content_ofs_y(slider, LV_PART_INDICATOR, LV_STATE_DEFAULT, -20);
|
||||
|
||||
/*To update the avlue text*/
|
||||
lv_event_send(slider, LV_EVENT_VALUE_CHANGED, NULL);
|
||||
}
|
||||
|
||||
static void slider_event_cb(lv_obj_t * slider, lv_event_t event)
|
||||
{
|
||||
if(event == LV_EVENT_VALUE_CHANGED) {
|
||||
static char buf[8];
|
||||
lv_snprintf(buf, sizeof(buf), "%d - %d", lv_slider_get_value(slider), lv_slider_get_left_value(slider));
|
||||
lv_obj_set_style_content_text(slider, LV_PART_INDICATOR, LV_STATE_DEFAULT, buf);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user