fix(color): widgets may move or resize when trims are disabled in flight modes (#6746)
This commit is contained in:
@@ -31,7 +31,7 @@
|
|||||||
#include "hal/adc_driver.h"
|
#include "hal/adc_driver.h"
|
||||||
|
|
||||||
ViewMainDecoration::ViewMainDecoration(Window* parent, bool showTrims, bool showSliders, bool showFM) :
|
ViewMainDecoration::ViewMainDecoration(Window* parent, bool showTrims, bool showSliders, bool showFM) :
|
||||||
parent(parent)
|
parent(parent), showTrims(showTrims), showSliders(showSliders), showFM(showFM)
|
||||||
{
|
{
|
||||||
w_ml = layoutBox(parent, LV_ALIGN_LEFT_MID, LV_FLEX_FLOW_ROW_REVERSE);
|
w_ml = layoutBox(parent, LV_ALIGN_LEFT_MID, LV_FLEX_FLOW_ROW_REVERSE);
|
||||||
w_mr = layoutBox(parent, LV_ALIGN_RIGHT_MID, LV_FLEX_FLOW_ROW);
|
w_mr = layoutBox(parent, LV_ALIGN_RIGHT_MID, LV_FLEX_FLOW_ROW);
|
||||||
@@ -41,11 +41,11 @@ ViewMainDecoration::ViewMainDecoration(Window* parent, bool showTrims, bool show
|
|||||||
w_bc = layoutBox(parent, LV_ALIGN_BOTTOM_MID, LV_FLEX_FLOW_COLUMN);
|
w_bc = layoutBox(parent, LV_ALIGN_BOTTOM_MID, LV_FLEX_FLOW_COLUMN);
|
||||||
lv_obj_set_flex_align(w_bc->getLvObj(), LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_SPACE_AROUND);
|
lv_obj_set_flex_align(w_bc->getLvObj(), LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_SPACE_AROUND);
|
||||||
|
|
||||||
if (showTrims)
|
if (this->showTrims)
|
||||||
createTrims(w_ml, w_mr, w_bl, w_br);
|
createTrims(w_ml, w_mr, w_bl, w_br);
|
||||||
if (showFM)
|
if (this->showFM)
|
||||||
createFlightMode(w_bc);
|
createFlightMode(w_bc);
|
||||||
if (showSliders)
|
if (this->showSliders)
|
||||||
createSliders(w_ml, w_mr, w_bl, w_bc, w_br);
|
createSliders(w_ml, w_mr, w_bl, w_bc, w_br);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -68,6 +68,7 @@ Window* ViewMainDecoration::layoutBox(Window* parent, lv_align_t align,
|
|||||||
|
|
||||||
void ViewMainDecoration::setSlidersVisible(bool visible)
|
void ViewMainDecoration::setSlidersVisible(bool visible)
|
||||||
{
|
{
|
||||||
|
showSliders = visible;
|
||||||
for (int i=0; i < SLIDERS_MAX; i++) {
|
for (int i=0; i < SLIDERS_MAX; i++) {
|
||||||
if (sliders[i]) {
|
if (sliders[i]) {
|
||||||
sliders[i]->show(visible);
|
sliders[i]->show(visible);
|
||||||
@@ -77,6 +78,7 @@ void ViewMainDecoration::setSlidersVisible(bool visible)
|
|||||||
|
|
||||||
void ViewMainDecoration::setTrimsVisible(bool visible)
|
void ViewMainDecoration::setTrimsVisible(bool visible)
|
||||||
{
|
{
|
||||||
|
showTrims = visible;
|
||||||
for (int i=0; i < TRIMS_MAX; i++) {
|
for (int i=0; i < TRIMS_MAX; i++) {
|
||||||
if (trims[i]) {
|
if (trims[i]) {
|
||||||
trims[i]->setVisible(visible);
|
trims[i]->setVisible(visible);
|
||||||
@@ -86,27 +88,55 @@ void ViewMainDecoration::setTrimsVisible(bool visible)
|
|||||||
|
|
||||||
void ViewMainDecoration::setFlightModeVisible(bool visible)
|
void ViewMainDecoration::setFlightModeVisible(bool visible)
|
||||||
{
|
{
|
||||||
|
showFM = visible;
|
||||||
if (flightMode)
|
if (flightMode)
|
||||||
flightMode->show(visible);
|
flightMode->show(visible);
|
||||||
}
|
}
|
||||||
|
|
||||||
rect_t ViewMainDecoration::getMainZone() const
|
// Check if trim may be visible in one or more flight modes
|
||||||
|
static bool canTrimShow(int idx)
|
||||||
{
|
{
|
||||||
// update layout first
|
idx = inputMappingConvertMode(idx);
|
||||||
lv_obj_update_layout(parent->getLvObj());
|
for (int i = 0; i < MAX_FLIGHT_MODES; i += 1) {
|
||||||
|
if (i == 0 || g_model.flightModeData[i].swtch != SWITCH_NONE) {
|
||||||
auto x_left = lv_obj_get_x2(w_ml->getLvObj());
|
trim_t v = getRawTrimValue(i, idx);
|
||||||
auto x_right = lv_obj_get_x(w_mr->getLvObj());
|
if (v.mode != TRIM_MODE_NONE && v.mode != TRIM_MODE_3POS)
|
||||||
|
return true;
|
||||||
lv_coord_t bottom = LCD_H;
|
}
|
||||||
Window* boxes[] = { w_bl, w_bc, w_br };
|
}
|
||||||
|
return false;
|
||||||
for ( auto box : boxes ) {
|
|
||||||
auto y = lv_obj_get_y(box->getLvObj());
|
|
||||||
if (y < bottom) bottom = y;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return rect_t{ x_left, 0, x_right - x_left, bottom};
|
rect_t ViewMainDecoration::getMainZone() const
|
||||||
|
{
|
||||||
|
coord_t x = 0, w = LCD_W, h = LCD_H;
|
||||||
|
|
||||||
|
if (showSliders) {
|
||||||
|
x += MainViewSlider::SLIDER_BAR_SIZE;
|
||||||
|
w -= 2 * MainViewSlider::SLIDER_BAR_SIZE;
|
||||||
|
h -= MainViewSlider::SLIDER_BAR_SIZE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (showTrims) {
|
||||||
|
if (canTrimShow(TRIMS_LV)) {
|
||||||
|
x += MainViewSlider::SLIDER_BAR_SIZE;
|
||||||
|
w -= MainViewSlider::SLIDER_BAR_SIZE;
|
||||||
|
}
|
||||||
|
if (canTrimShow(TRIMS_RV)) {
|
||||||
|
w -= MainViewSlider::SLIDER_BAR_SIZE;
|
||||||
|
}
|
||||||
|
if (showFM) {
|
||||||
|
h -= EdgeTxStyles::STD_FONT_HEIGHT;
|
||||||
|
} else {
|
||||||
|
if (canTrimShow(TRIMS_LH) || canTrimShow(TRIMS_RH)) {
|
||||||
|
h -= MainViewSlider::SLIDER_BAR_SIZE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (showFM) {
|
||||||
|
h -= EdgeTxStyles::STD_FONT_HEIGHT;
|
||||||
|
}
|
||||||
|
|
||||||
|
return rect_t{x, 0, w, h};
|
||||||
}
|
}
|
||||||
|
|
||||||
void ViewMainDecoration::createSliders(Window* ml, Window* mr, Window* bl, Window* bc, Window* br)
|
void ViewMainDecoration::createSliders(Window* ml, Window* mr, Window* bl, Window* bc, Window* br)
|
||||||
|
|||||||
@@ -40,6 +40,9 @@ class ViewMainDecoration
|
|||||||
rect_t getMainZone() const;
|
rect_t getMainZone() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
bool showTrims;
|
||||||
|
bool showSliders;
|
||||||
|
bool showFM;
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
SLIDERS_POT1 = 0,
|
SLIDERS_POT1 = 0,
|
||||||
|
|||||||
@@ -207,14 +207,16 @@ class OutputsWidget : public Widget
|
|||||||
if (chan != firstChan) { firstChan= chan; changed = true; }
|
if (chan != firstChan) { firstChan= chan; changed = true; }
|
||||||
|
|
||||||
// Get size
|
// Get size
|
||||||
uint8_t n = height() / ChannelValue::ROW_HEIGHT;
|
if (width() != lastWidth) { lastWidth = width(); changed = true; }
|
||||||
|
if (height() != lastHeight) { lastHeight = height(); changed = true; }
|
||||||
|
uint8_t n = lastHeight / ChannelValue::ROW_HEIGHT;
|
||||||
if (n != rows) { rows = n; changed = true; }
|
if (n != rows) { rows = n; changed = true; }
|
||||||
n = (width() > COLS_MIN_W) ? 2 : 1;
|
n = (lastWidth > COLS_MIN_W) ? 2 : 1;
|
||||||
if (n != cols) { cols = n; changed = true; }
|
if (n != cols) { cols = n; changed = true; }
|
||||||
|
|
||||||
if (changed) {
|
if (changed) {
|
||||||
clear();
|
clear();
|
||||||
coord_t colWidth = width() / cols;
|
coord_t colWidth = lastWidth / cols;
|
||||||
uint8_t chan = firstChan;
|
uint8_t chan = firstChan;
|
||||||
for (uint8_t c = 0; c < cols && chan <= MAX_OUTPUT_CHANNELS; c += 1) {
|
for (uint8_t c = 0; c < cols && chan <= MAX_OUTPUT_CHANNELS; c += 1) {
|
||||||
for (uint8_t r = 0; r < rows && chan <= MAX_OUTPUT_CHANNELS;
|
for (uint8_t r = 0; r < rows && chan <= MAX_OUTPUT_CHANNELS;
|
||||||
@@ -228,8 +230,8 @@ class OutputsWidget : public Widget
|
|||||||
static const ZoneOption options[];
|
static const ZoneOption options[];
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// Last time we refreshed the window
|
coord_t lastWidth = -1;
|
||||||
uint32_t lastRefresh = 0;
|
coord_t lastHeight = -1;
|
||||||
uint8_t firstChan = 255;
|
uint8_t firstChan = 255;
|
||||||
uint8_t cols = 0;
|
uint8_t cols = 0;
|
||||||
uint8_t rows = 0;
|
uint8_t rows = 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user