Arc (lv_arc)
A background ring with a touch-adjustable foreground indicator arc.
Overview
The Arc draws a background ring and a foreground indicator arc. The indicator can be set programmatically or dragged by touch, and its value is interpreted within a configurable min/max range and start/end angles.
Learn more in the LVGL Open documentation.
/**
* @file lv_example_arc.c
*/
#include "../lv_examples.h"
/**
* @title Arc
* @brief A bound arc with named styles on its main, indicator and knob parts.
*
* The arc uses `bind_value` so dragging it updates `subject_value`, which the
* centered label reads back live. Named styles target the MAIN ring, the
* INDICATOR sweep and the KNOB separately via the `selector` attribute.
*/
void lv_example_arc(void)
{
static lv_style_t style_arc_main;
static lv_style_t style_arc_ind;
static lv_style_t style_arc_knob;
static lv_subject_t subject_value;
static bool inited = false;
if (!inited) {
/*Init all styles*/
lv_style_init(&style_arc_main);
lv_style_init(&style_arc_ind);
lv_style_init(&style_arc_knob);
lv_style_set_arc_color(&style_arc_main, lv_color_hex(0x334155));
lv_style_set_arc_width(&style_arc_main, 10);
lv_style_set_arc_color(&style_arc_ind, lv_color_hex(0x3b82f6));
lv_style_set_arc_width(&style_arc_ind, 10);
lv_style_set_bg_color(&style_arc_knob, lv_color_hex(0x3b82f6));
lv_style_set_pad_all(&style_arc_knob, 6);
lv_style_set_border_width(&style_arc_knob, 2);
lv_style_set_border_color(&style_arc_knob, lv_color_hex3(0xfff));
lv_style_set_shadow_offset_y(&style_arc_knob, 2);
lv_style_set_shadow_opa(&style_arc_knob, (255 * 50 / 100));
lv_style_set_shadow_width(&style_arc_knob, 10);
lv_subject_init_int(&subject_value, 50);
lv_subject_set_min_value_int(&subject_value, 0);
lv_subject_set_max_value_int(&subject_value, 100);
inited = true;
}
lv_obj_t * screen = lv_screen_active();
/* π‘ Drag the arc β the label tracks subject_value live. */
lv_obj_t * lv_arc_0 = lv_arc_create(screen);
lv_obj_set_size(lv_arc_0, 120, 120);
lv_obj_set_align(lv_arc_0, LV_ALIGN_CENTER);
lv_arc_bind_value(lv_arc_0, &subject_value);
lv_obj_add_style(lv_arc_0, &style_arc_main, 0);
lv_obj_add_style(lv_arc_0, &style_arc_ind, LV_PART_INDICATOR);
lv_obj_add_style(lv_arc_0, &style_arc_knob, LV_PART_KNOB);
lv_obj_t * lv_label_0 = lv_label_create(lv_arc_0);
lv_label_bind_text(lv_label_0, &subject_value, "value: %d");
lv_obj_set_align(lv_label_0, LV_ALIGN_CENTER);
}
<!--
@title Arc
@brief A bound arc with named styles on its main, indicator and knob parts.
The arc uses `bind_value` so dragging it updates `subject_value`, which the
centered label reads back live. Named styles target the MAIN ring, the
INDICATOR sweep and the KNOB separately via the `selector` attribute.
-->
<screen>
<styles>
<!-- Background ring -->
<style name="style_arc_main" arc_color="0x334155" arc_width="10" />
<!-- Active sweep -->
<style name="style_arc_ind" arc_color="0x3b82f6" arc_width="10" />
<!-- Knob -->
<style
name="style_arc_knob"
bg_color="0x3b82f6"
pad_all="6"
border_width="2"
border_color="0xfff"
shadow_offset_y="2"
shadow_opa="50%"
shadow_width="10"
/>
</styles>
<view>
<!-- π‘ Drag the arc β the label tracks subject_value live. -->
<lv_arc width="120" height="120" align="center" bind_value="subject_value">
<style name="style_arc_main" />
<style name="style_arc_ind" selector="indicator" />
<style name="style_arc_knob" selector="knob" />
<lv_label bind_text="subject_value" bind_text-fmt="value: %d" align="center" />
</lv_arc>
</view>
</screen>
Enumerations
lv_arc_mode β How the arcβs indicator grows
| Value | Description |
|---|---|
normal | Make the indicator grow clockwise |
symmetrical | Make the indicator grow symmetrically left and right from the midpoint |
reverse | Make the indicator grow counterclockwise |
Properties
Parts
Style parts of the widget with local style (e.g. style_bg_color-knob="0xff0000") or with style sheets (e.g. <style name="style_knob" selector="knob">). See Styles to learn more.
| Part | Description |
|---|---|
main | The background arc: arc_color, arc_width, arc_opa, arc_rounded and arc_image_src. Background properties draw a box behind it. |
indicator | The value arc drawn over the background: the arc_* properties. Its padding is relative to the background arc. |
knob | The handle at the end of the indicator: background, border, shadow and padding properties (padding enlarges it). |
Properties below are the widget's XML <api>; see API for how properties, parameters and elements work.
| Property | Type | Description |
|---|---|---|
start_angle | int | Set the start angle of the indicator |
end_angle | int | Set the end angle of the indicator |
bg_start_angle | int | Set the start angle of the background arc |
bg_end_angle | int | Set the end angle of the background arc |
rotation | int | Rotate the whole arc by a given angle |
min_value | int | Set the minimum value of the arc |
max_value | int | Set the maximum value of the arc |
value | int | Set the current value of the arc (between minimum and maximum) |
mode | enum:lv_arc_mode | Select how the indicator grows |
change_rate | int | How fast the arc should jump to the clicked value (deg/sec) |
knob_offset | int | Move the knob along the arc by this many degrees |
bind_value | subject | Bind the arcβs value to a subject |
Last updated on