Spinner (lv_spinner)
A continuously rotating arc that indicates an activity is in progress.
Overview
The Spinner shows a continuously rotating arc over a ring to indicate that an activity is in progress. Its spin duration and arc length are configurable.
Learn more in the LVGL Open documentation.
/**
* @file lv_example_spinner.c
*/
#include "../lv_examples.h"
/**
* @title Spinner
* @brief Two spinners with different speeds, sweeps and arc styling.
*
* `anim_duration` is the time for one full turn and `arc_sweep` is the
* length of the moving arc (180–360 works best). The two spinners use
* different values and style the MAIN ring and INDICATOR arc independently.
*/
void lv_example_spinner(void)
{
static lv_style_t style_track;
static lv_style_t style_ind;
static lv_style_t style_ind2;
static bool inited = false;
if (!inited) {
/*Init all styles*/
lv_style_init(&style_track);
lv_style_init(&style_ind);
lv_style_init(&style_ind2);
lv_style_set_arc_color(&style_track, lv_color_hex(0x334155));
lv_style_set_arc_width(&style_track, 8);
lv_style_set_arc_color(&style_ind, lv_color_hex(0x3b82f6));
lv_style_set_arc_width(&style_ind, 8);
lv_style_set_arc_color(&style_ind2, lv_color_hex(0xf59e0b));
lv_style_set_arc_width(&style_ind2, 12);
lv_style_set_pad_all(&style_ind2, -2);
inited = true;
}
lv_obj_t * screen = lv_screen_active();
lv_obj_set_flex_flow(screen, LV_FLEX_FLOW_ROW);
lv_obj_set_style_flex_main_place(screen, LV_FLEX_ALIGN_SPACE_EVENLY, 0);
lv_obj_set_style_flex_cross_place(screen, LV_FLEX_ALIGN_CENTER, 0);
lv_obj_set_style_flex_track_place(screen, LV_FLEX_ALIGN_CENTER, 0);
/* Slow, long sweep */
lv_obj_t * lv_spinner_0 = lv_spinner_create(screen);
lv_obj_set_size(lv_spinner_0, 80, 80);
lv_spinner_set_anim_duration(lv_spinner_0, 2000);
lv_spinner_set_arc_sweep(lv_spinner_0, 270);
lv_obj_add_style(lv_spinner_0, &style_track, 0);
lv_obj_add_style(lv_spinner_0, &style_ind, LV_PART_INDICATOR);
/* Fast, short sweep */
lv_obj_t * lv_spinner_1 = lv_spinner_create(screen);
lv_obj_set_size(lv_spinner_1, 80, 80);
lv_spinner_set_anim_duration(lv_spinner_1, 700);
lv_spinner_set_arc_sweep(lv_spinner_1, 220);
lv_obj_add_style(lv_spinner_1, &style_track, 0);
lv_obj_add_style(lv_spinner_1, &style_ind2, LV_PART_INDICATOR);
}
<!--
@title Spinner
@brief Two spinners with different speeds, sweeps and arc styling.
`anim_duration` is the time for one full turn and `arc_sweep` is the
length of the moving arc (180–360 works best). The two spinners use
different values and style the MAIN ring and INDICATOR arc independently.
-->
<screen>
<styles>
<style name="style_track" arc_color="0x334155" arc_width="8" />
<style name="style_ind" arc_color="0x3b82f6" arc_width="8" />
<style name="style_ind2" arc_color="0xf59e0b" arc_width="12" pad_all="-2" />
</styles>
<view
flex_flow="row"
style_flex_main_place="space_evenly"
style_flex_cross_place="center"
style_flex_track_place="center"
>
<!-- Slow, long sweep -->
<lv_spinner width="80" height="80" anim_duration="2000" arc_sweep="270">
<style name="style_track" />
<style name="style_ind" selector="indicator" />
</lv_spinner>
<!-- Fast, short sweep -->
<lv_spinner width="80" height="80" anim_duration="700" arc_sweep="220">
<style name="style_track" />
<style name="style_ind2" selector="indicator" />
</lv_spinner>
</view>
</screen>
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 (extends lv_arc): arc_color, arc_width, arc_opa, arc_rounded. |
indicator | The spinning arc that animates around: the arc_* properties. |
Properties below are the widget's XML <api>; see API for how properties, parameters and elements work.
| Property | Type | Description |
|---|---|---|
anim_duration | int | Set the animation time of the spinner. |
arc_sweep | int | Set the animation arc length of the spinner. The animation is suited to values between 180 and 360. |
Last updated on