feat(radio): modify Sensor Edit screens to show Ratio + Percentage (#4649)

This commit is contained in:
Frankie Arzu
2024-05-29 13:08:42 +10:00
committed by GitHub
parent 5d20c81126
commit c19f6402d0
5 changed files with 119 additions and 10 deletions
+50 -3
View File
@@ -390,6 +390,54 @@ class SensorSourceChoice : public SourceChoice
}
};
class SensorRatioEdit : Window
{
public:
SensorRatioEdit(Window* parent, const rect_t& rect, int vmin, int vmax,
std::function<int()> _getValue,
std::function<void(int)> _setValue) :
Window(parent, rect),
m_getValue(std::move(_getValue)),
m_setValue(std::move(_setValue))
{
setFlexLayout(LV_FLEX_FLOW_ROW, 75);
lv_obj_set_flex_align(lvobj, LV_FLEX_ALIGN_START, LV_FLEX_ALIGN_CENTER,
LV_FLEX_ALIGN_SPACE_AROUND);
editRatio = new NumberEdit(
this, rect_t{}, vmin, vmax, m_getValue,
[=](int32_t newValue) {
m_setValue(newValue);
setPercent();
},
PREC1);
editRatio->setZeroText("-");
percentText = new StaticText(this, rect_t{}, "");
setPercent();
}
protected:
int32_t ratioPercent;
NumberEdit* editRatio;
StaticText* percentText;
std::function<int()> m_getValue;
std::function<void(int)> m_setValue;
private:
void setPercent()
{
int32_t value = m_getValue();
if (value == 0) {
percentText->setText("");
} else {
std::string str =
formatNumberAsString((value * 1000) / 255, PREC1, 0, "", "%");
percentText->setText(str);
}
}
};
class SensorEditWindow : public Page
{
public:
@@ -697,9 +745,8 @@ class SensorEditWindow : public Page
paramLines[P_RATIO] = window->newLine(grid);
new StaticText(paramLines[P_RATIO], rect_t{}, STR_RATIO);
auto edit = new NumberEdit(paramLines[P_RATIO], rect_t{}, 0, 30000,
GET_SET_DEFAULT(sensor->custom.ratio), PREC1);
edit->setZeroText("-");
new SensorRatioEdit(paramLines[P_RATIO], rect_t{}, 0, 30000,
GET_SET_DEFAULT(sensor->custom.ratio));
paramLines[P_CELLINDEX] = window->newLine(grid);
new StaticText(paramLines[P_CELLINDEX], rect_t{}, STR_CELLINDEX);