A39模拟器
This commit is contained in:
26
MXC-A39/lvgl/examples/widgets/slider/index.rst
Normal file
26
MXC-A39/lvgl/examples/widgets/slider/index.rst
Normal file
@ -0,0 +1,26 @@
|
||||
C
|
||||
^
|
||||
|
||||
Simple Slider
|
||||
"""""""""""""""""""""""""
|
||||
|
||||
.. lv_example:: widgets/slider/lv_example_slider_1
|
||||
:language: c
|
||||
|
||||
Slider with custom style
|
||||
"""""""""""""""""""""""""
|
||||
|
||||
.. lv_example:: widgets/slider/lv_example_slider_2
|
||||
:language: c
|
||||
|
||||
Slider with extended drawer
|
||||
""""""""""""""""""""""""""""
|
||||
|
||||
.. lv_example:: widgets/slider/lv_example_slider_3
|
||||
:language: c
|
||||
|
||||
|
||||
MicroPython
|
||||
^^^^^^^^^^^
|
||||
|
||||
No examples yet.
|
33
MXC-A39/lvgl/examples/widgets/slider/lv_example_slider_1.c
Normal file
33
MXC-A39/lvgl/examples/widgets/slider/lv_example_slider_1.c
Normal file
@ -0,0 +1,33 @@
|
||||
#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;
|
||||
|
||||
/**
|
||||
* 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());
|
||||
lv_obj_center(slider);
|
||||
lv_obj_add_event_cb(slider, slider_event_cb, LV_EVENT_VALUE_CHANGED, NULL);
|
||||
|
||||
/*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%%", 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
|
37
MXC-A39/lvgl/examples/widgets/slider/lv_example_slider_1.py
Normal file
37
MXC-A39/lvgl/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)
|
57
MXC-A39/lvgl/examples/widgets/slider/lv_example_slider_2.c
Normal file
57
MXC-A39/lvgl/examples/widgets/slider/lv_example_slider_2.c
Normal file
@ -0,0 +1,57 @@
|
||||
#include "../../lv_examples.h"
|
||||
#if LV_USE_SLIDER && LV_BUILD_EXAMPLES
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Show how to style a slider.
|
||||
*/
|
||||
void lv_example_slider_2(void)
|
||||
{
|
||||
/*Create a transition*/
|
||||
static const lv_style_prop_t props[] = {LV_STYLE_BG_COLOR, 0};
|
||||
static lv_style_transition_dsc_t transition_dsc;
|
||||
lv_style_transition_dsc_init(&transition_dsc, props, lv_anim_path_linear, 300, 0, NULL);
|
||||
|
||||
static lv_style_t style_main;
|
||||
static lv_style_t style_indicator;
|
||||
static lv_style_t style_knob;
|
||||
static lv_style_t style_pressed_color;
|
||||
lv_style_init(&style_main);
|
||||
lv_style_set_bg_opa(&style_main, LV_OPA_COVER);
|
||||
lv_style_set_bg_color(&style_main, lv_color_hex3(0xbbb));
|
||||
lv_style_set_radius(&style_main, LV_RADIUS_CIRCLE);
|
||||
lv_style_set_pad_ver(&style_main, -2); /*Makes the indicator larger*/
|
||||
|
||||
lv_style_init(&style_indicator);
|
||||
lv_style_set_bg_opa(&style_indicator, LV_OPA_COVER);
|
||||
lv_style_set_bg_color(&style_indicator, lv_palette_main(LV_PALETTE_CYAN));
|
||||
lv_style_set_radius(&style_indicator, LV_RADIUS_CIRCLE);
|
||||
lv_style_set_transition(&style_indicator, &transition_dsc);
|
||||
|
||||
lv_style_init(&style_knob);
|
||||
lv_style_set_bg_opa(&style_knob, LV_OPA_COVER);
|
||||
lv_style_set_bg_color(&style_knob, lv_palette_main(LV_PALETTE_CYAN));
|
||||
lv_style_set_border_color(&style_knob, lv_palette_darken(LV_PALETTE_CYAN, 3));
|
||||
lv_style_set_border_width(&style_knob, 2);
|
||||
lv_style_set_radius(&style_knob, LV_RADIUS_CIRCLE);
|
||||
lv_style_set_pad_all(&style_knob, 6); /*Makes the knob larger*/
|
||||
lv_style_set_transition(&style_knob, &transition_dsc);
|
||||
|
||||
lv_style_init(&style_pressed_color);
|
||||
lv_style_set_bg_color(&style_pressed_color, lv_palette_darken(LV_PALETTE_CYAN, 2));
|
||||
|
||||
/*Create a slider and add the style*/
|
||||
lv_obj_t * slider = lv_slider_create(lv_scr_act());
|
||||
lv_obj_remove_style_all(slider); /*Remove the styles coming from the theme*/
|
||||
|
||||
lv_obj_add_style(slider, &style_main, LV_PART_MAIN);
|
||||
lv_obj_add_style(slider, &style_indicator, LV_PART_INDICATOR);
|
||||
lv_obj_add_style(slider, &style_pressed_color, LV_PART_INDICATOR | LV_STATE_PRESSED);
|
||||
lv_obj_add_style(slider, &style_knob, LV_PART_KNOB);
|
||||
lv_obj_add_style(slider, &style_pressed_color, LV_PART_KNOB | LV_STATE_PRESSED);
|
||||
|
||||
lv_obj_center(slider);
|
||||
}
|
||||
|
||||
#endif
|
23
MXC-A39/lvgl/examples/widgets/slider/lv_example_slider_2.py
Normal file
23
MXC-A39/lvgl/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)
|
57
MXC-A39/lvgl/examples/widgets/slider/lv_example_slider_3.c
Normal file
57
MXC-A39/lvgl/examples/widgets/slider/lv_example_slider_3.c
Normal file
@ -0,0 +1,57 @@
|
||||
#include "../../lv_examples.h"
|
||||
#if LV_USE_SLIDER && LV_BUILD_EXAMPLES
|
||||
|
||||
static void slider_event_cb(lv_event_t * e);
|
||||
|
||||
/**
|
||||
* Show the current value when the slider is pressed by extending the drawer
|
||||
*
|
||||
*/
|
||||
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());
|
||||
lv_obj_center(slider);
|
||||
|
||||
lv_slider_set_mode(slider, LV_SLIDER_MODE_RANGE);
|
||||
lv_slider_set_value(slider, 70, LV_ANIM_OFF);
|
||||
lv_slider_set_left_value(slider, 20, LV_ANIM_OFF);
|
||||
|
||||
lv_obj_add_event_cb(slider, slider_event_cb, LV_EVENT_ALL, NULL);
|
||||
lv_obj_refresh_ext_draw_size(slider);
|
||||
}
|
||||
|
||||
static void slider_event_cb(lv_event_t * e)
|
||||
{
|
||||
lv_event_code_t code = lv_event_get_code(e);
|
||||
lv_obj_t * obj = lv_event_get_target(e);
|
||||
|
||||
/*Provide some extra space for the value*/
|
||||
if(code == LV_EVENT_REFR_EXT_DRAW_SIZE) {
|
||||
lv_coord_t * size = lv_event_get_param(e);
|
||||
*size = LV_MAX(*size, 50);
|
||||
}
|
||||
else if(code == LV_EVENT_DRAW_PART_END) {
|
||||
lv_obj_draw_part_dsc_t * dsc = lv_event_get_param(e);
|
||||
if(dsc->part == LV_PART_INDICATOR) {
|
||||
char buf[16];
|
||||
lv_snprintf(buf, sizeof(buf), "%d - %d", lv_slider_get_left_value(obj), lv_slider_get_value(obj));
|
||||
|
||||
lv_point_t label_size;
|
||||
lv_txt_get_size(&label_size, buf, LV_FONT_DEFAULT, 0, 0, LV_COORD_MAX, 0);
|
||||
lv_area_t label_area;
|
||||
label_area.x1 = dsc->draw_area->x1 + lv_area_get_width(dsc->draw_area) / 2 - label_size.x / 2;
|
||||
label_area.x2 = label_area.x1 + label_size.x;
|
||||
label_area.y2 = dsc->draw_area->y1 - 10;
|
||||
label_area.y1 = label_area.y2 - label_size.y;
|
||||
|
||||
lv_draw_label_dsc_t label_draw_dsc;
|
||||
lv_draw_label_dsc_init(&label_draw_dsc);
|
||||
|
||||
lv_draw_label(&label_area, dsc->clip_area, &label_draw_dsc, buf, NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user