fix(color): T15 curve preview, cleanup curve edit layout (#5329)

This commit is contained in:
philmoz
2024-07-29 09:34:06 +10:00
committed by GitHub
parent 2638c6d229
commit 24732e200b
2 changed files with 191 additions and 218 deletions
+104 -111
View File
@@ -32,54 +32,72 @@ static const lv_coord_t default_col_dsc[] = {LV_GRID_CONTENT,
static const lv_coord_t default_row_dsc[] = {LV_GRID_CONTENT, static const lv_coord_t default_row_dsc[] = {LV_GRID_CONTENT,
LV_GRID_TEMPLATE_LAST}; LV_GRID_TEMPLATE_LAST};
CurveDataEdit::CurveDataEdit(Window* parent, const rect_t& rect, class CurveDataEdit : public Window
uint8_t index) : {
public:
CurveDataEdit(Window* parent, const rect_t& rect, uint8_t index) :
Window(parent, rect), index(index) Window(parent, rect), index(index)
{ {
etx_scrollbar(lvobj); etx_scrollbar(lvobj);
lv_obj_set_style_max_height(lvobj, rect.h, LV_PART_MAIN);
padAll(PAD_ZERO);
padBottom(PAD_SMALL);
} }
void CurveDataEdit::curvePointsRow(FormLine* parent, int start, int count, void setCurveEdit(CurveEdit* _curveEdit)
{
curveEdit = _curveEdit;
update();
}
void update()
{
clear();
memset(numEditX, 0, sizeof(numEditX));
CurveHeader& curve = g_model.curves[index];
uint8_t curvePointsCount = 5 + curve.points;
coord_t y = 0;
for (int i = 0; i < curvePointsCount; i += 5) {
int count = 5;
if (i + count > curvePointsCount) count = curvePointsCount - i;
curvePointsRow(this, y, i, count, curvePointsCount,
curve.type == CURVE_TYPE_CUSTOM);
y += ROW_HEIGHT;
}
}
static LAYOUT_VAL(ROW_HEIGHT, 82, 82)
static LAYOUT_VAL(NUM_BTN_WIDTH, 48, 48)
static LAYOUT_VAL(NUM_HDR_HEIGHT, 15, 15)
static LAYOUT_VAL(PTNUM_X, 15, 15)
static LAYOUT_VAL(PTNUM_H, 13, 13)
protected:
uint8_t index;
CurveEdit* curveEdit;
NumberEdit* numEditX[16];
void curvePointsRow(Window* parent, coord_t y, int start, int count,
int curvePointsCount, bool isCustom) int curvePointsCount, bool isCustom)
{ {
static const lv_coord_t points_col_dsc[] = {11,
LV_GRID_FR(1),
LV_GRID_FR(1),
LV_GRID_FR(1),
LV_GRID_FR(1),
LV_GRID_FR(1),
LV_GRID_TEMPLATE_LAST};
auto form = new Window(parent, rect_t{});
form->padAll(PAD_TINY);
form->setFlexLayout(LV_FLEX_FLOW_COLUMN, PAD_ZERO);
FlexGridLayout grid(points_col_dsc, default_row_dsc, PAD_ZERO);
auto line = form->newLine(grid);
line->padTop(-PAD_SMALL);
line->padBottom(PAD_ZERO);
line->padLeft(PAD_SMALL);
line->padRight(PAD_SMALL);
line->setHeight(NUM_HDR_HEIGHT);
lv_obj_set_grid_align(line->getLvObj(), LV_GRID_ALIGN_SPACE_BETWEEN,
LV_GRID_ALIGN_SPACE_BETWEEN);
// Point number // Point number
grid.nextCell();
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
(new StaticText(line, rect_t{}, std::to_string(i + start + 1), new StaticText(parent,
FONT(XS) | CENTERED | COLOR_THEME_PRIMARY1)) {PTNUM_X + (i * (NUM_BTN_WIDTH + PAD_TINY)), y,
->setHeight(10); NUM_BTN_WIDTH, PTNUM_H},
std::to_string(i + start + 1),
COLOR_THEME_PRIMARY1 | FONT(XS) | CENTERED);
} }
line = form->newLine(grid); y += NUM_HDR_HEIGHT;
line->padAll(PAD_ZERO);
line->setHeight(EdgeTxStyles::UI_ELEMENT_HEIGHT + PAD_TINY * 2);
lv_obj_set_grid_align(line->getLvObj(), LV_GRID_ALIGN_SPACE_BETWEEN,
LV_GRID_ALIGN_SPACE_BETWEEN);
new StaticText(line, rect_t{}, "X", CENTERED | COLOR_THEME_PRIMARY1); new StaticText(
parent, {1, y + PAD_MEDIUM, PTNUM_X, EdgeTxStyles::UI_ELEMENT_HEIGHT},
"X", COLOR_THEME_PRIMARY1 | CENTERED);
int8_t* points = curveAddress(index); int8_t* points = curveAddress(index);
@@ -88,9 +106,11 @@ void CurveDataEdit::curvePointsRow(FormLine* parent, int start, int count,
uint8_t i = 0; uint8_t i = 0;
uint8_t c = count; uint8_t c = count;
if (start == 0) { if (start == 0) {
(new StaticText(line, rect_t{}, "-100", new StaticText(
CENTERED | COLOR_THEME_SECONDARY1)) parent,
->padTop(1); {PTNUM_X + (i * (NUM_BTN_WIDTH + PAD_TINY)), y + PAD_MEDIUM,
NUM_BTN_WIDTH, EdgeTxStyles::UI_ELEMENT_HEIGHT},
"-100", COLOR_THEME_SECONDARY1 | CENTERED);
i += 1; i += 1;
} }
if ((start + count) == curvePointsCount) { if ((start + count) == curvePointsCount) {
@@ -100,7 +120,9 @@ void CurveDataEdit::curvePointsRow(FormLine* parent, int start, int count,
for (; i < c; i++) { for (; i < c; i++) {
uint8_t px = i + start - 1; uint8_t px = i + start - 1;
numEditX[px] = new NumberEdit( numEditX[px] = new NumberEdit(
line, rect_t{0, 0, NUM_BTN_WIDTH, 0}, parent,
{PTNUM_X + (i * (NUM_BTN_WIDTH + PAD_TINY)), y, NUM_BTN_WIDTH,
EdgeTxStyles::UI_ELEMENT_HEIGHT},
(px == 0) ? -100 : points[curvePointsCount + px - 1], (px == 0) ? -100 : points[curvePointsCount + px - 1],
(px == curvePointsCount - 3) ? 100 (px == curvePointsCount - 3) ? 100
: points[curvePointsCount + px + 1], : points[curvePointsCount + px + 1],
@@ -115,75 +137,49 @@ void CurveDataEdit::curvePointsRow(FormLine* parent, int start, int count,
} }
SET_DIRTY(); SET_DIRTY();
curveEdit->updatePreview(); curveEdit->updatePreview();
}, CENTERED); },
lv_obj_set_grid_cell(numEditX[px]->getLvObj(), LV_GRID_ALIGN_CENTER, CENTERED);
i + 1, 1, LV_GRID_ALIGN_CENTER, 0, 1);
} }
if ((start + count) == curvePointsCount) { if ((start + count) == curvePointsCount) {
(new StaticText(line, rect_t{}, "100", new StaticText(
CENTERED | COLOR_THEME_SECONDARY1)) parent,
->padTop(1); {PTNUM_X + (i * (NUM_BTN_WIDTH + PAD_TINY)), y + PAD_MEDIUM,
NUM_BTN_WIDTH, EdgeTxStyles::UI_ELEMENT_HEIGHT},
"100", COLOR_THEME_SECONDARY1 | CENTERED);
} }
} else { } else {
for (uint8_t i = 0; i < count; i++) { for (uint8_t i = 0; i < count; i++) {
(new StaticText( new StaticText(
line, rect_t{0, 1, 0, 0}, parent,
rect_t{PTNUM_X + (i * (NUM_BTN_WIDTH + PAD_TINY)), y + PAD_MEDIUM,
NUM_BTN_WIDTH, EdgeTxStyles::UI_ELEMENT_HEIGHT},
std::to_string(-100 + (200 * (i + start)) / (curvePointsCount - 1)), std::to_string(-100 + (200 * (i + start)) / (curvePointsCount - 1)),
CENTERED | COLOR_THEME_SECONDARY1)) COLOR_THEME_SECONDARY1 | CENTERED);
->padTop(1);
} }
} }
line = form->newLine(grid); y += EdgeTxStyles::UI_ELEMENT_HEIGHT + PAD_TINY;
line->padAll(PAD_ZERO);
line->setHeight(EdgeTxStyles::UI_ELEMENT_HEIGHT + PAD_TINY * 2);
lv_obj_set_grid_align(line->getLvObj(), LV_GRID_ALIGN_SPACE_BETWEEN,
LV_GRID_ALIGN_SPACE_BETWEEN);
new StaticText(line, rect_t{}, "Y", CENTERED | COLOR_THEME_PRIMARY1); new StaticText(
parent, {1, y + PAD_MEDIUM, PTNUM_X, EdgeTxStyles::UI_ELEMENT_HEIGHT},
"Y", COLOR_THEME_PRIMARY1 | CENTERED);
// y value // y value
for (uint8_t i = 0; i < count; i++) { for (uint8_t i = 0; i < count; i++) {
auto numedit = new NumberEdit( auto numedit = new NumberEdit(
line, rect_t{0, 0, NUM_BTN_WIDTH, 0}, -100, 100, parent,
GET_VALUE(points[i + start]), {PTNUM_X + (i * (NUM_BTN_WIDTH + PAD_TINY)), y, NUM_BTN_WIDTH,
EdgeTxStyles::UI_ELEMENT_HEIGHT},
-100, 100, GET_VALUE(points[i + start]),
[=](int32_t newValue) { [=](int32_t newValue) {
points[i + start] = newValue; points[i + start] = newValue;
SET_DIRTY(); SET_DIRTY();
curveEdit->updatePreview(); curveEdit->updatePreview();
}, CENTERED); },
lv_obj_set_grid_cell(numedit->getLvObj(), LV_GRID_ALIGN_CENTER, i + 1, 1, CENTERED);
LV_GRID_ALIGN_CENTER, 0, 1);
}
}
void CurveDataEdit::update()
{
clear();
memset(numEditX, 0, sizeof(numEditX));
auto form = new Window(this, rect_t{});
form->padAll(PAD_ZERO);
form->padBottom(PAD_SMALL);
form->setFlexLayout();
FlexGridLayout grid(default_col_dsc, default_row_dsc);
CurveHeader& curve = g_model.curves[index];
uint8_t curvePointsCount = 5 + curve.points;
for (int i = 0; i < curvePointsCount; i += 5) {
int count = 5;
if (i + count > curvePointsCount) count = curvePointsCount - i;
auto line = form->newLine(grid);
line->padAll(PAD_ZERO);
lv_obj_set_grid_align(line->getLvObj(), LV_GRID_ALIGN_SPACE_BETWEEN,
LV_GRID_ALIGN_SPACE_BETWEEN);
curvePointsRow(line, i, count, curvePointsCount,
curve.type == CURVE_TYPE_CUSTOM);
} }
} }
};
void CurveEdit::SetCurrentSource(mixsrc_t source) void CurveEdit::SetCurrentSource(mixsrc_t source)
{ {
@@ -207,9 +203,6 @@ CurveEdit::CurveEdit(Window* parent, const rect_t& rect, uint8_t index) :
current(0) current(0)
{ {
setWindowFlag(NO_FOCUS); setWindowFlag(NO_FOCUS);
TRACE("CurveEdit::currentSource=%d\tCurveEdit::lockSource=%d",
CurveEdit::currentSource, CurveEdit::lockSource);
updatePreview(); updatePreview();
} }
@@ -232,15 +225,14 @@ void CurveEdit::checkEvents()
CurveEdit::currentSource = val + 1 - MIXSRC_FIRST_INPUT; CurveEdit::currentSource = val + 1 - MIXSRC_FIRST_INPUT;
else { else {
CurveEdit::currentSource = expoAddress(val - 1)->srcRaw; CurveEdit::currentSource = expoAddress(val - 1)->srcRaw;
TRACE("Detected source=%d", val);
} }
TRACE("Applied source=%d", CurveEdit::currentSource);
} }
} }
Window::checkEvents(); Window::checkEvents();
} }
CurveEditWindow::CurveEditWindow(uint8_t index, std::function<void(void)> refreshView) : CurveEditWindow::CurveEditWindow(uint8_t index,
std::function<void(void)> refreshView) :
Page(ICON_MODEL_CURVES, PAD_ZERO), index(index), refreshView(refreshView) Page(ICON_MODEL_CURVES, PAD_ZERO), index(index), refreshView(refreshView)
{ {
buildBody(body); buildBody(body);
@@ -271,13 +263,11 @@ void CurveEditWindow::buildBody(Window* window)
#if PORTRAIT_LCD #if PORTRAIT_LCD
lv_obj_set_flex_flow(line->getLvObj(), LV_FLEX_FLOW_COLUMN); lv_obj_set_flex_flow(line->getLvObj(), LV_FLEX_FLOW_COLUMN);
coord_t curveWidth = window->width() - 88;
coord_t boxWidth = window->width(); coord_t boxWidth = window->width();
coord_t boxHeight = window->height() - curveWidth; coord_t boxHeight = window->height() - CURVE_WIDTH;
#else #else
lv_obj_set_flex_flow(line->getLvObj(), LV_FLEX_FLOW_ROW); lv_obj_set_flex_flow(line->getLvObj(), LV_FLEX_FLOW_ROW);
coord_t curveWidth = window->height() - 2 * PAD_MEDIUM; coord_t boxWidth = window->width() - CURVE_WIDTH;
coord_t boxWidth = window->width() - curveWidth;
coord_t boxHeight = window->height(); coord_t boxHeight = window->height();
#endif #endif
@@ -302,11 +292,11 @@ void CurveEditWindow::buildBody(Window* window)
// Name // Name
new StaticText(iLine, rect_t{}, STR_NAME); new StaticText(iLine, rect_t{}, STR_NAME);
new ModelTextEdit(iLine, rect_t{}, curve.name, new ModelTextEdit(iLine, rect_t{}, curve.name, sizeof(curve.name));
sizeof(curve.name));
// Smooth // Smooth
auto smooth = new TextButton(iLine, rect_t{0, 0, 70, 0}, STR_SMOOTH, [=]() { auto smooth =
new TextButton(iLine, rect_t{0, 0, NUMEDT_W, 0}, STR_SMOOTH, [=]() {
g_model.curves[index].smooth = !g_model.curves[index].smooth; g_model.curves[index].smooth = !g_model.curves[index].smooth;
curveEdit->updatePreview(); curveEdit->updatePreview();
return g_model.curves[index].smooth; return g_model.curves[index].smooth;
@@ -321,7 +311,7 @@ void CurveEditWindow::buildBody(Window* window)
// Type // Type
new StaticText(iLine, rect_t{}, STR_TYPE); new StaticText(iLine, rect_t{}, STR_TYPE);
new Choice( new Choice(
iLine, rect_t{0, 0, 100, 0}, STR_CURVE_TYPES, 0, 1, iLine, {0, 0, TextEdit::DEF_W, 0}, STR_CURVE_TYPES, 0, 1,
GET_DEFAULT(g_model.curves[index].type), [=](int32_t newValue) { GET_DEFAULT(g_model.curves[index].type), [=](int32_t newValue) {
CurveHeader& curve = g_model.curves[index]; CurveHeader& curve = g_model.curves[index];
if (newValue != curve.type) { if (newValue != curve.type) {
@@ -346,8 +336,8 @@ void CurveEditWindow::buildBody(Window* window)
}); });
// Points count // Points count
auto edit = new NumberEdit( auto edit = new Choice(
iLine, rect_t{0, 0, 70, 0}, 2, 17, iLine, {0, 0, NUMEDT_W, 0}, 2, 17,
GET_DEFAULT(g_model.curves[index].points + 5), [=](int32_t newValue) { GET_DEFAULT(g_model.curves[index].points + 5), [=](int32_t newValue) {
newValue -= 5; newValue -= 5;
CurveHeader& curve = g_model.curves[index]; CurveHeader& curve = g_model.curves[index];
@@ -372,23 +362,26 @@ void CurveEditWindow::buildBody(Window* window)
} }
} }
}); });
edit->setSuffix(STR_PTS); edit->setTextHandler([=](int value) {
edit->setDefault(5); return std::to_string(value) + STR_PTS;
});
iLine = form->newLine(iGrid); iLine = form->newLine(iGrid);
iLine->padAll(PAD_ZERO); iLine->padAll(PAD_ZERO);
iLine->padTop(PAD_SMALL);
iLine->padBottom(PAD_SMALL);
lv_obj_set_grid_align(iLine->getLvObj(), LV_GRID_ALIGN_SPACE_BETWEEN, lv_obj_set_grid_align(iLine->getLvObj(), LV_GRID_ALIGN_SPACE_BETWEEN,
LV_GRID_ALIGN_SPACE_BETWEEN); LV_GRID_ALIGN_SPACE_BETWEEN);
curveDataEdit = new CurveDataEdit( curveDataEdit = new CurveDataEdit(
iLine, rect_t{0, 0, box->width(), box->height() - 82}, index); iLine,
rect_t{
0, 0, box->width(),
box->height() - (EdgeTxStyles::UI_ELEMENT_HEIGHT + PAD_TINY * 2) * 2},
index);
// Curve editor // Curve editor
lv_obj_set_flex_align(line->getLvObj(), LV_FLEX_ALIGN_CENTER, lv_obj_set_flex_align(line->getLvObj(), LV_FLEX_ALIGN_CENTER,
LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_SPACE_AROUND); LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_SPACE_AROUND);
curveEdit = new CurveEdit(line, {0, 0, curveWidth, curveWidth}, index); curveEdit = new CurveEdit(line, {0, 0, CURVE_WIDTH, CURVE_WIDTH}, index);
curveDataEdit->setCurveEdit(curveEdit); curveDataEdit->setCurveEdit(curveEdit);
} }
+8 -28
View File
@@ -21,11 +21,12 @@
#pragma once #pragma once
#include "curve.h"
#include "page.h" #include "page.h"
#include "window.h" #include "window.h"
#include "curve.h"
class NumberEdit; class NumberEdit;
class CurveDataEdit;
class CurveEdit : public Window class CurveEdit : public Window
{ {
@@ -35,8 +36,7 @@ class CurveEdit: public Window
void deleteLater(bool detach = true, bool trash = true) override void deleteLater(bool detach = true, bool trash = true) override
{ {
if (_deleted) if (_deleted) return;
return;
preview.deleteLater(true, false); preview.deleteLater(true, false);
@@ -55,34 +55,14 @@ class CurveEdit: public Window
static bool lockSource; static bool lockSource;
}; };
class CurveDataEdit : public Window
{
public:
CurveDataEdit(Window * parent, const rect_t & rect, uint8_t index);
void setCurveEdit(CurveEdit* _curveEdit)
{
curveEdit = _curveEdit;
update();
}
void update();
static LAYOUT_VAL(NUM_BTN_WIDTH, 48, 48)
static LAYOUT_VAL(NUM_HDR_HEIGHT, 12, 12)
protected:
uint8_t index;
CurveEdit * curveEdit;
NumberEdit* numEditX[16];
void curvePointsRow(FormLine* parent, int start, int count, int curvePointsCount, bool isCustom);
};
class CurveEditWindow : public Page class CurveEditWindow : public Page
{ {
public: public:
CurveEditWindow(uint8_t index, std::function<void(void)> refreshView = nullptr); CurveEditWindow(uint8_t index,
std::function<void(void)> refreshView = nullptr);
static LAYOUT_VAL(NUMEDT_W, 70, 70)
static LAYOUT_VAL(CURVE_WIDTH, 215, 232)
protected: protected:
uint8_t index; uint8_t index;