圆弧 (Geometry Arc)

概述

圆弧控件是一个轻量级的 GUI 绘图组件,专门用于在用户界面中绘制圆弧和圆环图形。该控件提供了简洁易用的 API ,支持自定义圆弧的起始角度、结束角度、线宽、颜色等属性,能够满足各种圆弧绘制需求。



核心功能

描述

API

创建控件

gui_lite_arc_create()

设置位置

gui_lite_arc_set_position()

设置半径

gui_lite_arc_set_radius()

设置颜色

gui_lite_arc_set_color()

设置起始角度

gui_lite_arc_set_start_angle()

设置结束角度

gui_lite_arc_set_end_angle()

设置线宽

gui_lite_arc_set_line_width()

注册点击事件回调

gui_lite_arc_on_click()

角度说明

圆弧的角度系统采用标准的数学坐标系:

  • : 3点钟方向(正东方向)

  • 90°: 6点钟方向(正南方向)

  • 180°: 9点钟方向(正西方向)

  • 270°: 12点钟方向(正北方向)

特性亮点

  • 高性能: 采用优化的绘制算法,确保流畅的渲染性能

  • 抗锯齿: 支持边缘抗锯齿,提供平滑的视觉效果

  • 灵活配置: 支持自定义角度范围、线宽和颜色

  • 轻量级: 内存占用小,适合嵌入式系统和资源受限环境

  • 圆环支持: 当起始角度和结束角度相差360°时,自动绘制完整圆环

应用场景

圆弧控件适用于以下场景:

  • 进度指示器: 用于显示加载进度、电池电量等

  • 仪表盘: 构建速度表、温度计等仪表界面

  • 数据可视化: 展示比例数据、统计图表

  • 用户界面装饰: 作为界面的装饰元素

  • 状态指示: 表示系统状态、连接状态等

配置说明

要使用圆弧控件,需要在配置文件中启用相应的宏定义:

menu_config.h 中添加:

#define CONFIG_REALTEK_BUILD_REAL_LITE_ARC 1

完整示例

#include "gui_components_init.h"
#include "gui_lite_geometry_arc.h"

static void create_activity_rings(float center_x, float center_y)
{
    // bg track color
    gui_color_t track_color_move     = gui_rgba(52, 14, 11, 200);
    gui_color_t track_color_exercise = gui_rgba(16, 37, 17, 200);
    gui_color_t track_color_stand    = gui_rgba(17, 32, 52, 200);
    // fg color
    gui_color_t col_move     = gui_rgba(255, 0, 0, 255);  // Move red
    gui_color_t col_exercise = gui_rgba(0, 255, 0, 255);  // Exercise green
    gui_color_t col_stand    = gui_rgba(0, 0, 255, 255);  // Stand blue

    // circle radius and thickness
    float outer_radius = 163.0f; float outer_thickness = 22.0f;
    float mid_radius   = 136.5f; float mid_thickness   = 22.0f;
    float inner_radius = 110.0f; float inner_thickness = 22.0f;

    uint16_t start_angle = 0;
    // background rings
    gui_lite_arc_t *ring_move = gui_lite_arc_create(gui_obj_get_root(), "test_ring_move", center_x,
                                                    center_y, outer_radius, 0, 360, outer_thickness,
                                                    track_color_move);
    gui_lite_arc_t *ring_exercise = gui_lite_arc_create(gui_obj_get_root(), "test_ring_exercise",
                                                        center_x, center_y, mid_radius, 0, 360, mid_thickness,
                                                        track_color_exercise);
    gui_lite_arc_t *ring_stand = gui_lite_arc_create(gui_obj_get_root(), "test_ring_stand", center_x,
                                                     center_y, inner_radius, 0, 360, inner_thickness,
                                                     track_color_stand);
    gui_lite_arc_set_style(ring_stand, center_x, center_y, inner_radius, 0, 360, inner_thickness,
                           track_color_stand);


    // arc style
    gui_lite_arc_t *arc_move = gui_lite_arc_create(gui_obj_get_root(), "test_arc_move", center_x,
                                                   center_y, outer_radius,
                                                   start_angle, start_angle + 252.0f, outer_thickness, col_move);
    gui_lite_arc_t *arc_exercise = gui_lite_arc_create(gui_obj_get_root(), "test_arc_exercise",
                                                       center_x, center_y, mid_radius,
                                                       start_angle, start_angle + 72.0f, mid_thickness, col_exercise);
    gui_lite_arc_t *arc_stand = gui_lite_arc_create(gui_obj_get_root(), "test_arc_stand", center_x,
                                                    center_y, inner_radius,
                                                    start_angle, start_angle + 198.0f, inner_thickness, col_stand);
}
static int geometry_demo_init(void)
{

    float center_x = 480 / 2.0f;
    float center_y = 480 / 2.0f;
    create_activity_rings(center_x, center_y);

    return 0;
}

GUI_INIT_APP_EXPORT(geometry_demo_init);

API

Defines

BLOCK_SIZE 100

Tile size for block-based rendering.

Functions

gui_lite_arc_t *gui_lite_arc_create(void *parent, const char *name, int x, int y, int radius, float start_angle, float end_angle, float line_width, gui_color_t color)

Create a new lite arc widget.

参数:
  • parent -- Parent widget or NULL for top-level widget.

  • name -- Name of the widget.

  • x -- Center X coordinate.

  • y -- Center Y coordinate.

  • radius -- Arc radius.

  • start_angle -- Start angle in degrees.

  • end_angle -- End angle in degrees.

  • line_width -- Line width.

  • color -- Arc color.

返回:

Pointer to the created lite arc widget.

void gui_lite_arc_set_position(gui_lite_arc_t *this, int x, int y)

Move arc geometry.

参数:
  • this -- Pointer to the arc widget.

  • x -- New center X coordinate relative to widget.

  • y -- New center Y coordinate relative to widget.

void gui_lite_arc_set_radius(gui_lite_arc_t *this, int radius)

Set the radius of the lite arc widget.

参数:
  • this -- Pointer to the lite arc widget.

  • radius -- Arc radius.

void gui_lite_arc_set_color(gui_lite_arc_t *this, gui_color_t color)

Set the color of the lite arc widget.

参数:
  • this -- Pointer to the lite arc widget.

  • color -- Arc color.

void gui_lite_arc_set_start_angle(gui_lite_arc_t *this, float start_angle)

Set the start angle of the lite arc widget.

参数:
  • this -- Pointer to the lite arc widget.

  • start_angle -- Start angle in degrees.

void gui_lite_arc_set_end_angle(gui_lite_arc_t *this, float end_angle)

Set the end angle of the lite arc widget.

参数:
  • this -- Pointer to the lite arc widget.

  • end_angle -- End angle in degrees.

void gui_lite_arc_set_line_width(gui_lite_arc_t *this, float line_width)

Set the line width of the lite arc widget.

参数:
  • this -- Pointer to the lite arc widget.

  • line_width -- Line width.

void gui_lite_arc_on_click(gui_lite_arc_t *this, void *callback, void *parameter)

Register click event callback for lite arc widget.

参数:
  • this -- Pointer to the arc widget.

  • callback -- Callback function pointer.

  • parameter -- Optional parameter to pass to callback.

struct gui_lite_arc_t

Lite arc widget structure.

Public Members

gui_obj_t base

Base widget.

draw_img_t *draw_img

Drawing image object.

uint8_t *pixel_buffer

Cached pixel buffer.

uint32_t buffer_size

Buffer size.

bool buffer_valid

Buffer cache valid flag.

DrawContext draw_ctx

Drawing context.

uint8_t opacity_value

Opacity value.

int x

Center X coordinate relative to widget.

int y

Center Y coordinate relative to widget.

int radius

Arc radius.

float start_angle

Start angle in degrees.

float end_angle

End angle in degrees.

float line_width

Line width.

gui_color_t color

Arc color (stored as uint32_t internally).

int cached_x
int cached_y
int cached_radius
float cached_start_angle
float cached_end_angle
float cached_line_width
gui_color_t cached_color