STTArc 是基于 LVGL Arc 的弧形指示条,可用于仪表进度、旋钮输入和环形状态显示。它继承 STTWidget,因此位置、显隐、事件、变量绑定和通用样式也可使用 STTWidget 接口。
#include "widgets/STTArc.h"
using namespace stt;
STTArc* arc = new STTArc(getRuntime(), parent, "arcPressure");
arc->setMainArg(20, 20, 180, 180, 30, 0, 100, 135, 45);
构造参数依次为 Runtime、父控件和控件 ID。父控件及其底层 LVGL object 必须有效,生命周期应长于子控件。
arc->setMainStyle(
9999, 0xffffff, 0xffffff, 0, 0,
0, 0x000000, 16, 0xd0d0d0, true, ""
);
arc->setIndicStyle(0x00a65a, true, 16, "");
arc->setKnobStyle(true, 4, 0xffffff, 0xe0e0e0, 1,
0x666666, 1, 9999, "");
arc->setRange(0, 100);
arc->setValue(65);
角度坐标以右侧为 0 度,下方为 90 度,顺时针增加。start=135、end=45 表示跨过 360 度形成约 270 度的弧。
void setMainArg(
int x = 0, int y = 0, int w = 200, int h = 200,
int value = 50, int min = 0, int max = 100,
int start = 135, int end = 45
);
当前实现顺序为 setValue(value)、setMinValue(min)、setMaxValue(max)、设置背景弧起止角。若 value 超出最终范围,最终显示由 LVGL 的范围规则决定。更稳妥的做法是初始化后再显式 setRange 和 setValue。
配置整体背景、边框和背景弧:
arc->setMainStyle(
9999, // 背景圆角
0xffffff, // 背景主色
0xffffff, // 背景渐变色
0, // 0 无渐变,1 上下,2 左右
0, // 背景透明度 0..255
0, // 边框宽度
0x000000, // 边框颜色
20, // 背景弧宽度
0xdddddd, // 背景弧颜色
true, // 圆头
"" // 背景弧图片
);
图片只有在 FileUtil::fileExists 返回 true 时才应用。路径字符串被保存在控件内部,可使用文件路径。
arc->setIndicStyle(0x1a2b3c, true, 20, "");
arc->setKnobStyle(true, 2, 0xffffff, 0xeeeeee, 1,
0x333333, 1, 9999, "");
setKnobStyle(false, ...) 会移除旋钮部分样式并把控件设为不可点击;true 会设为可点击。r_mod 实际作为 knob 的 padding,直径相对弧宽发生变化。
| 方法 | 说明 |
|---|---|
| setStartAngle / setEndAngle | 设置指示弧起点或终点 |
| setAngles | 同时设置指示弧起止角 |
| setBgStartAngle / setBgEndAngle | 设置背景弧起点或终点 |
| setBgAngles | 同时设置背景弧起止角 |
| setRotation | 整体顺时针旋转 |
| getAngleStart / getAngleEnd | 读取指示弧角度 |
| getBgAngleStart / getBgAngleEnd | 读取背景弧角度 |
负角度会不断加 360 转成非负值;大于 360 的值未在 STTArc 层归一化,最终由 LVGL 处理。
arc->setAngles(210, 330)
->setBgAngles(210, 330)
->setRotation(15);
setMode 支持:
| mode | 含义 |
|---|---|
| 0 | 常规正向 |
| 1 | 对称 |
| 2 | 反向,点击改值兼容性受限 |
超出 0..2 的 mode 会被改为 0。
arc->setMode(0);
int mode = arc->getMode();
arc->setRange(-50, 150)
->setValue(80)
->setChangeRate(120);
int value = arc->getValue();
int low = arc->getMinValue();
int high = arc->getMaxValue();
API: