Arc(圆弧) (lv_arc)¶
Overview(概述)¶
查看原文
The Arc consists of a background and a foreground arc. The foregrond (indicator) can be touch-adjusted.
圆弧由背景和前景弧组成。前景(指示器)可以进行触摸调整。
Parts and Styles¶
查看原文
LV_PART_MAIN
Draws a background using the typical background style properties and an arc using the arc style properties. The arc's size and position will respect the padding style properties.LV_PART_INDICATOR
Draws an other arc using the arc style properties. Its padding values are interpreted relative to the background arc.LV_PART_KNOB
Draws a handle on the end of the indicator using all background properties and padding values. With zero padding the knob size is the same as the indicator's width. Larger padding makes it larger, smaller padding makes it smaller.
LV_PART_MAIN
圆弧的背景部分。使用典型的背景样式属性绘制背景,使用圆弧样式属性绘制圆弧。 圆弧的大小和位置可以通过 padding 样式调整。LV_PART_INDICATOR
圆弧的指示器部分。使用 arc 样式属性绘制另一个圆弧。 它的填充值是相对于背景弧来设置的。LV_PART_KNOB
圆弧的旋钮部分。使用所有背景属性和填充值在指标的末尾绘制一个旋钮。如果使用零填充,旋钮大小与指示器的宽度相同。较大的填充使其更大,较小的填充使其更小。
Usage(用法)¶
Value and range(值和范围)¶
查看原文
A new value can be set using lv_arc_set_value(arc, new_value)
.
The value is interpreted in a range (minimum and maximum values) which can be modified with lv_arc_set_range(arc, min, max)
.
The default range is 0..100.
The indicator arc is drawn on the main part's arc. This if the value is set to maximum the indicator arc will cover the entire "background" arc.
To set the start and end angle of the background arc use the lv_arc_set_bg_angles(arc, start_angle, end_angle)
functions or lv_arc_set_bg_start/end_angle(arc, angle)
.
Zero degrees is at the middle right (3 o'clock) of the object and the degrees are increasing in clockwise direction. The angles should be in the [0;360] range.
可以通过 lv_arc_set_value(arc, new_value)
设置一个数值。
可以通过 lv_arc_set_range(arc, min, max)
指定数值的范围(最小值和最大值)。
如果没有指定数值范围,将使用默认范围 (0-100)。
指示器绘制在 LV_PART_MAIN 部分的弧上面。 如果指示器的值设置为最大值,则指示器弧将呈现一个闭合的狐(也就是圆形)。
要设置背景弧的开始和结束角度,请使用 lv_arc_set_bg_angles(arc, start_angle, end_angle)
函数或 lv_arc_set_bg_start/end_angle(arc, angle)
。
零度位于对象的中间右侧(3 点钟方向),并且度数沿顺时针方向增加。 角度应在 [0;360] 范围内。
Rotation(旋转)¶
查看原文
An offset to the 0 degree position can added with lv_arc_set_rotation(arc, deg)
.
可以使用 lv_arc_set_rotation(arc, deg)
添加到 0 度位置的偏移量。
Mode(模式)¶
查看原文
The arc can be one of the following modes:
LV_ARC_MODE_NORMAL
The indicator arc is drawn from the minimimum value to the current.LV_ARC_MODE_REVERSE
The indicator arc is drawn counter-clockwise from the maximum value to the current.LV_ARC_MODE_SYMMETRICAL
The indicator arc is drawn from the middle point to the current value.
The mode can be set by lv_arc_set_mode(arc, LV_ARC_MODE_...)
and used only if the the angle is set by lv_arc_set_value()
or the arc is adjusted by finger.
弧可以是以下模式之一:
LV_ARC_MODE_NORMAL
普通模式。指示器从最小值绘制到当前值。LV_ARC_MODE_REVERSE
反向模式。指示器从最大值到当前值逆时针绘制。LV_ARC_MODE_SYMMETRICAL
对称模式。指示器从中间点绘制到当前值。
可以通过 lv_arc_set_mode(arc, LV_ARC_MODE_...)
设置模式,并且仅当角度由 lv_arc_set_value()
设置或通过手指调整弧度时使用。
Change rate(变化率)¶
查看原文
If the arc is pressed the current value will set with a limited speed according to the set change rate.
The change rate is defined in degree/second unit and can be set with lv_arc_set_change_rage(arc, rate)
如果弧被按下,当前值将根据设置的 变化率 以有限的速度设置。
变化率以 度/秒 为单位定义,可以用 lv_arc_set_change_rage(arc, rate)
设置
Setting the indicator manually(手动设置指示器)¶
查看原文
It also possible to set the angles of the indicator arc directly with lv_arc_set_angles(arc, start_angle, end_angle)
function or lv_arc_set_start/end_angle(arc, start_angle)
.
In this case the set "value" and "mode" is ignored.
In other words, the angle and value settings are independent. You should exclusively use one or the other. Mixing the two might result in unintended behavior.
To make the arc non-adjustabe remove the style of the knob and make the object non-clickable:
也可以直接使用 lv_arc_set_angles(arc, start_angle, end_angle)
函数或 lv_arc_set_start/end_angle(arc, start_angle)
设置指示器的角度(零度位于对象的中间右侧(3 点钟方向),并且度数沿顺时针方向增加。)。
在这种情况下,设置的 “值” 和 “模式” 将被忽略。
换句话说,角度和值的设置是独立的。两者混合可能会导致意外行为。比如:
static void arc_event_cb(lv_event_t * e)
{
lv_obj_t * arc = lv_event_get_target(e);
lv_arc_set_bg_angles(arc, 0, lv_arc_get_value(arc));
lv_arc_set_angles(arc, 0, lv_arc_get_value(arc));
}
.....
lv_obj_add_event_cb(arc, arc_event_cb, LV_EVENT_VALUE_CHANGED, NULL);
.....
要使圆弧不可调整,请移除旋钮的样式并使对象不可点击:
lv_obj_remove_style(arc, NULL, LV_PART_KNOB);
lv_obj_clear_flag(arc, LV_OBJ_FLAG_CLICKABLE);
Events(事件)¶
查看原文
LV_EVENT_VALUE_CHANGED
sent when the arc is pressed/dragged to set a new value.LV_EVENT_DRAW_PART_BEGIN
andLV_EVENT_DRAW_PART_END
are sent with the following types:LV_ARC_DRAW_PART_BACKGROUND
The background arc.part
:LV_PART_MAIN
p1
: center of the arcradius
: radius of the arcarc_dsc
LV_ARC_DRAW_PART_FOREGROUND
The foreground arc.part
:LV_PART_INDICATOR
p1
: center of the arcradius
: radius of the arcarc_dsc
LV_ARC_DRAW_PART_KNOB The knob
part
:LV_PART_KNOB
draw_area
: the arae of the knobrect_dsc
:
See the events of the Base object too.
Learn more about Events.
按下或拖动圆弧设置新值时发送会
LV_EVENT_VALUE_CHANGED
LV_EVENT_DRAW_PART_BEGIN
和LV_EVENT_DRAW_PART_END
使用以下类型发送:LV_ARC_DRAW_PART_BACKGROUND
背景弧。部分
:LV_PART_MAIN
p1
:圆弧的中心radius
:弧的半径arc_dsc
LV_ARC_DRAW_PART_FOREGROUND
前景弧。部分
:LV_PART_INDICATOR
p1
:圆弧的中心radius
:弧的半径arc_dsc
LV_ARC_DRAW_PART_KNOB 旋钮
部分
:LV_PART_KNOB
draw_area
:旋钮的面积 -rect_dsc
:
参见 Base object 的事件。
详细了解 事件。
Keys(按键)¶
查看原文
LV_KEY_RIGHT/UP
Increases the value by one.LV_KEY_LEFT/DOWN
Decreases the value by one.
Learn more about Keys.
LV_KEY_RIGHT/UP
将值增加一。LV_KEY_LEFT/DOWN
将值减一。
了解有关 Keys 的更多信息。
Example¶
Simple Arc¶
C code
GitHub#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
# Create an Arc
arc = lv.arc(lv.scr_act())
arc.set_end_angle(200)
arc.set_size(150, 150)
arc.center()
Loader with Arc¶
C code
GitHub#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
#
# An `lv_timer` to call periodically to set the angles of the arc
#
class ArcLoader():
def __init__(self):
self.a = 270
def arc_loader_cb(self,tim,arc):
# print(tim,arc)
self.a += 5
arc.set_end_angle(self.a)
if self.a >= 270 + 360:
tim._del()
#
# Create an arc which acts as a loader.
#
# Create an Arc
arc = lv.arc(lv.scr_act())
arc.set_bg_angles(0, 360)
arc.set_angles(270, 270)
arc.center()
# create the loader
arc_loader = ArcLoader()
# Create an `lv_timer` to update the arc.
timer = lv.timer_create_basic()
timer.set_period(20)
timer.set_cb(lambda src: arc_loader.arc_loader_cb(timer,arc))
API¶
Typedefs
-
typedef uint8_t lv_arc_mode_t¶
Enums
-
enum [anonymous]¶
Values:
-
enumerator LV_ARC_MODE_NORMAL¶
-
enumerator LV_ARC_MODE_SYMMETRICAL¶
-
enumerator LV_ARC_MODE_REVERSE¶
-
enumerator LV_ARC_MODE_NORMAL¶
-
enum lv_arc_draw_part_type_t¶
type
field inlv_obj_draw_part_dsc_t
ifclass_p = lv_arc_class
Used inLV_EVENT_DRAW_PART_BEGIN
andLV_EVENT_DRAW_PART_END
Values:
-
enumerator LV_ARC_DRAW_PART_BACKGROUND¶
The background arc
-
enumerator LV_ARC_DRAW_PART_FOREGROUND¶
The foreground arc
-
enumerator LV_ARC_DRAW_PART_KNOB¶
The knob
-
enumerator LV_ARC_DRAW_PART_BACKGROUND¶
Functions
-
lv_obj_t *lv_arc_create(lv_obj_t *parent)¶
Create an arc object
- 参数
parent -- pointer to an object, it will be the parent of the new arc
- 返回
pointer to the created arc
-
void lv_arc_set_start_angle(lv_obj_t *arc, uint16_t start)¶
Set the start angle of an arc. 0 deg: right, 90 bottom, etc.
- 参数
arc -- pointer to an arc object
start -- the start angle
-
void lv_arc_set_end_angle(lv_obj_t *arc, uint16_t end)¶
Set the end angle of an arc. 0 deg: right, 90 bottom, etc.
- 参数
arc -- pointer to an arc object
end -- the end angle
-
void lv_arc_set_angles(lv_obj_t *arc, uint16_t start, uint16_t end)¶
Set the start and end angles
- 参数
arc -- pointer to an arc object
start -- the start angle
end -- the end angle
-
void lv_arc_set_bg_start_angle(lv_obj_t *arc, uint16_t start)¶
Set the start angle of an arc background. 0 deg: right, 90 bottom, etc.
- 参数
arc -- pointer to an arc object
start -- the start angle
-
void lv_arc_set_bg_end_angle(lv_obj_t *arc, uint16_t end)¶
Set the start angle of an arc background. 0 deg: right, 90 bottom etc.
- 参数
arc -- pointer to an arc object
end -- the end angle
-
void lv_arc_set_bg_angles(lv_obj_t *arc, uint16_t start, uint16_t end)¶
Set the start and end angles of the arc background
- 参数
arc -- pointer to an arc object
start -- the start angle
end -- the end angle
-
void lv_arc_set_rotation(lv_obj_t *arc, uint16_t rotation)¶
Set the rotation for the whole arc
- 参数
arc -- pointer to an arc object
rotation -- rotation angle
-
void lv_arc_set_mode(lv_obj_t *arc, lv_arc_mode_t type)¶
Set the type of arc.
- 参数
arc -- pointer to arc object
mode -- arc's mode
-
void lv_arc_set_value(lv_obj_t *arc, int16_t value)¶
Set a new value on the arc
- 参数
arc -- pointer to an arc object
value -- new value
-
void lv_arc_set_range(lv_obj_t *arc, int16_t min, int16_t max)¶
Set minimum and the maximum values of an arc
- 参数
arc -- pointer to the arc object
min -- minimum value
max -- maximum value
-
void lv_arc_set_change_rate(lv_obj_t *arc, uint16_t rate)¶
Set a change rate to limit the speed how fast the arc should reach the pressed point.
- 参数
arc -- pointer to an arc object
rate -- the change rate
-
uint16_t lv_arc_get_angle_start(lv_obj_t *obj)¶
Get the start angle of an arc.
- 参数
arc -- pointer to an arc object
- 返回
the start angle [0..360]
-
uint16_t lv_arc_get_angle_end(lv_obj_t *obj)¶
Get the end angle of an arc.
- 参数
arc -- pointer to an arc object
- 返回
the end angle [0..360]
-
uint16_t lv_arc_get_bg_angle_start(lv_obj_t *obj)¶
Get the start angle of an arc background.
- 参数
arc -- pointer to an arc object
- 返回
the start angle [0..360]
-
uint16_t lv_arc_get_bg_angle_end(lv_obj_t *obj)¶
Get the end angle of an arc background.
- 参数
arc -- pointer to an arc object
- 返回
the end angle [0..360]
-
int16_t lv_arc_get_value(const lv_obj_t *obj)¶
Get the value of an arc
- 参数
arc -- pointer to an arc object
- 返回
the value of the arc
-
int16_t lv_arc_get_min_value(const lv_obj_t *obj)¶
Get the minimum value of an arc
- 参数
arc -- pointer to an arc object
- 返回
the minimum value of the arc
-
int16_t lv_arc_get_max_value(const lv_obj_t *obj)¶
Get the maximum value of an arc
- 参数
arc -- pointer to an arc object
- 返回
the maximum value of the arc
-
lv_arc_mode_t lv_arc_get_mode(const lv_obj_t *obj)¶
Get whether the arc is type or not.
- 参数
arc -- pointer to an arc object
- 返回
arc's mode
Variables
-
const lv_obj_class_t lv_arc_class¶
-
struct lv_arc_t¶
Public Members
-
uint16_t rotation¶
-
uint16_t indic_angle_start¶
-
uint16_t indic_angle_end¶
-
uint16_t bg_angle_start¶
-
uint16_t bg_angle_end¶
-
int16_t value¶
-
int16_t min_value¶
-
int16_t max_value¶
-
uint16_t dragging¶
-
uint16_t type¶
-
uint16_t min_close¶
-
uint16_t chg_rate¶
-
uint32_t last_tick¶
-
int16_t last_angle¶
-
uint16_t rotation¶