A39模拟器
This commit is contained in:
19
MXC-A39/lvgl/examples/widgets/arc/index.rst
Normal file
19
MXC-A39/lvgl/examples/widgets/arc/index.rst
Normal file
@ -0,0 +1,19 @@
|
||||
C
|
||||
^
|
||||
|
||||
Simple Arc
|
||||
""""""""""""""""
|
||||
|
||||
.. lv_example:: widgets/arc/lv_example_arc_1
|
||||
:language: c
|
||||
|
||||
Loader with Arc
|
||||
""""""""""""""""
|
||||
|
||||
.. lv_example:: widgets/arc/lv_example_arc_2
|
||||
:language: c
|
||||
|
||||
MicroPython
|
||||
^^^^^^^^^^^
|
||||
|
||||
No examples yet.
|
16
MXC-A39/lvgl/examples/widgets/arc/lv_example_arc_1.c
Normal file
16
MXC-A39/lvgl/examples/widgets/arc/lv_example_arc_1.c
Normal file
@ -0,0 +1,16 @@
|
||||
#include "../../lv_examples.h"
|
||||
|
||||
#if LV_USE_ARC && LV_BUILD_EXAMPLES
|
||||
|
||||
void lv_example_arc_1(void)
|
||||
{
|
||||
/*Create an Arc*/
|
||||
lv_obj_t * arc = lv_arc_create(lv_scr_act());
|
||||
lv_obj_set_size(arc, 150, 150);
|
||||
lv_arc_set_rotation(arc, 135);
|
||||
lv_arc_set_bg_angles(arc, 0, 270);
|
||||
lv_arc_set_value(arc, 40);
|
||||
lv_obj_center(arc);
|
||||
}
|
||||
|
||||
#endif
|
12
MXC-A39/lvgl/examples/widgets/arc/lv_example_arc_1.py
Normal file
12
MXC-A39/lvgl/examples/widgets/arc/lv_example_arc_1.py
Normal file
@ -0,0 +1,12 @@
|
||||
# Create style for the Arcs
|
||||
style = lv.style_t()
|
||||
lv.style_copy(style, lv.style_plain)
|
||||
style.line.color = lv.color_make(0,0,255) # Arc color
|
||||
style.line.width = 8 # Arc width
|
||||
|
||||
# Create an Arc
|
||||
arc = lv.arc(lv.scr_act())
|
||||
arc.set_style(lv.arc.STYLE.MAIN, style) # Use the new style
|
||||
arc.set_angles(90, 60)
|
||||
arc.set_size(150, 150)
|
||||
arc.align(None, lv.ALIGN.CENTER, 0, 0)
|
37
MXC-A39/lvgl/examples/widgets/arc/lv_example_arc_2.c
Normal file
37
MXC-A39/lvgl/examples/widgets/arc/lv_example_arc_2.c
Normal file
@ -0,0 +1,37 @@
|
||||
#include "../../lv_examples.h"
|
||||
|
||||
#if LV_USE_ARC && LV_BUILD_EXAMPLES
|
||||
|
||||
static void set_angle(void * obj, int32_t v)
|
||||
{
|
||||
lv_arc_set_value(obj, v);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an arc which acts as a loader.
|
||||
*/
|
||||
void lv_example_arc_2(void)
|
||||
{
|
||||
/*Create an Arc*/
|
||||
lv_obj_t * arc = lv_arc_create(lv_scr_act());
|
||||
lv_arc_set_rotation(arc, 270);
|
||||
lv_arc_set_bg_angles(arc, 0, 360);
|
||||
lv_obj_remove_style(arc, NULL, LV_PART_KNOB); /*Be sure the knob is not displayed*/
|
||||
lv_obj_clear_flag(arc, LV_OBJ_FLAG_CLICKABLE); /*To not allow adjusting by click*/
|
||||
lv_obj_center(arc);
|
||||
|
||||
lv_anim_t a;
|
||||
lv_anim_init(&a);
|
||||
lv_anim_set_var(&a, arc);
|
||||
lv_anim_set_exec_cb(&a, set_angle);
|
||||
lv_anim_set_time(&a, 1000);
|
||||
lv_anim_set_repeat_count(&a, LV_ANIM_REPEAT_INFINITE); /*Just for the demo*/
|
||||
lv_anim_set_repeat_delay(&a, 500);
|
||||
lv_anim_set_values(&a, 0, 100);
|
||||
lv_anim_start(&a);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
#endif
|
43
MXC-A39/lvgl/examples/widgets/arc/lv_example_arc_2.py
Normal file
43
MXC-A39/lvgl/examples/widgets/arc/lv_example_arc_2.py
Normal file
@ -0,0 +1,43 @@
|
||||
# Create an arc which acts as a loader.
|
||||
class loader_arc(lv.arc):
|
||||
|
||||
def __init__(self, parent, color=lv.color_hex(0x000080),
|
||||
width=8, style=lv.style_plain, rate=20):
|
||||
super().__init__(parent)
|
||||
|
||||
self.a = 0
|
||||
self.rate = rate
|
||||
|
||||
# Create style for the Arcs
|
||||
self.style = lv.style_t()
|
||||
lv.style_copy(self.style, style)
|
||||
self.style.line.color = color
|
||||
self.style.line.width = width
|
||||
|
||||
# Create an Arc
|
||||
self.set_angles(180, 180);
|
||||
self.set_style(self.STYLE.MAIN, self.style);
|
||||
|
||||
# Spin the Arc
|
||||
self.spin()
|
||||
|
||||
def spin(self):
|
||||
# Create an `lv_task` to update the arc.
|
||||
lv.task_create(self.task_cb, self.rate, lv.TASK_PRIO.LOWEST, {})
|
||||
|
||||
|
||||
# An `lv_task` to call periodically to set the angles of the arc
|
||||
def task_cb(self, task):
|
||||
self.a+=5;
|
||||
if self.a >= 359: self.a = 359
|
||||
|
||||
if self.a < 180: self.set_angles(180-self.a, 180)
|
||||
else: self.set_angles(540-self.a, 180)
|
||||
|
||||
if self.a == 359:
|
||||
self.a = 0
|
||||
lv.task_del(task)
|
||||
|
||||
# Create a loader arc
|
||||
loader_arc = loader_arc(lv.scr_act())
|
||||
loader_arc.align(None, lv.ALIGN.CENTER, 0, 0)
|
Reference in New Issue
Block a user