view main trims & sliders: use flex layout
This commit is contained in:
committed by
Raphael Coeffic
parent
1219c676ef
commit
1443128b5f
@@ -22,13 +22,12 @@
|
||||
#include "layout_factory_impl.h"
|
||||
#include "layouts/trims.h"
|
||||
#include "layouts/sliders.h"
|
||||
#include "view_main_decoration.h"
|
||||
#include "view_main.h"
|
||||
|
||||
Layout::Layout(Window* parent, const LayoutFactory * factory, PersistentData * persistentData):
|
||||
LayoutBase(parent, {0, 0, LCD_W, LCD_H}, persistentData),
|
||||
factory(factory),
|
||||
decoration(new ViewMainDecoration(this, getRect()))
|
||||
decoration(new ViewMainDecoration(this))
|
||||
{
|
||||
adjustLayout();
|
||||
}
|
||||
@@ -105,9 +104,6 @@ void Layout::adjustLayout()
|
||||
setTrimsVisible(hasTrims());
|
||||
setFlightModeVisible(hasFlightMode());
|
||||
|
||||
// Re-compute positions
|
||||
decoration->adjustDecoration();
|
||||
|
||||
// and update relevant windows
|
||||
updateZones();
|
||||
|
||||
|
||||
@@ -27,8 +27,11 @@
|
||||
#include "translations.h"
|
||||
|
||||
#include "widgets/widgets_container_impl.h"
|
||||
#include "view_main_decoration.h"
|
||||
#include "layout.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
#define LAYOUT_COMMON_OPTIONS \
|
||||
{STR_TOP_BAR, ZoneOption::Bool, OPTION_VALUE_BOOL(true)}, \
|
||||
{STR_FLIGHT_MODE, ZoneOption::Bool, OPTION_VALUE_BOOL(true)}, \
|
||||
@@ -39,8 +42,6 @@
|
||||
#define LAYOUT_OPTIONS_END \
|
||||
{ nullptr, ZoneOption::Bool }
|
||||
|
||||
class ViewMainDecoration;
|
||||
|
||||
typedef WidgetsContainerImpl<MAX_LAYOUT_ZONES, MAX_LAYOUT_OPTIONS> LayoutBase;
|
||||
|
||||
class Layout: public LayoutBase
|
||||
@@ -99,7 +100,7 @@ class Layout: public LayoutBase
|
||||
|
||||
protected:
|
||||
const LayoutFactory * factory = nullptr;
|
||||
ViewMainDecoration* decoration = nullptr;
|
||||
std::unique_ptr<ViewMainDecoration> decoration;
|
||||
|
||||
// Decoration settings bitmask to detect updates
|
||||
uint8_t decorationSettings = 255;
|
||||
|
||||
@@ -22,6 +22,44 @@
|
||||
#include "sliders.h"
|
||||
#include "opentx.h"
|
||||
|
||||
enum slider_type {
|
||||
SLIDER_VERT,
|
||||
SLIDER_HORIZ,
|
||||
SLIDER_6POS,
|
||||
};
|
||||
|
||||
static void slider_self_size(lv_event_t* e)
|
||||
{
|
||||
lv_point_t* s = (lv_point_t*)lv_event_get_param(e);
|
||||
slider_type t = (slider_type)(long)lv_event_get_user_data(e);
|
||||
switch(t) {
|
||||
case SLIDER_VERT:
|
||||
s->y = VERTICAL_SLIDERS_HEIGHT;
|
||||
s->x = TRIM_SQUARE_SIZE;
|
||||
break;
|
||||
case SLIDER_HORIZ:
|
||||
s->x = HORIZONTAL_SLIDERS_WIDTH;
|
||||
s->y = TRIM_SQUARE_SIZE;
|
||||
break;
|
||||
case SLIDER_6POS:
|
||||
s->x = MULTIPOS_W;
|
||||
s->y = MULTIPOS_H;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
MainViewHorizontalSlider::MainViewHorizontalSlider(Window* parent,
|
||||
uint8_t idx) :
|
||||
MainViewSlider(parent, rect_t{}, idx)
|
||||
{
|
||||
void* user_data = (void*)SLIDER_HORIZ;
|
||||
lv_obj_add_event_cb(lvobj, slider_self_size, LV_EVENT_GET_SELF_SIZE,
|
||||
user_data);
|
||||
|
||||
setWidth(HORIZONTAL_SLIDERS_WIDTH);
|
||||
setHeight(TRIM_SQUARE_SIZE);
|
||||
}
|
||||
|
||||
void MainViewHorizontalSlider::paint(BitmapBuffer * dc)
|
||||
{
|
||||
// The ticks
|
||||
@@ -40,6 +78,17 @@ void MainViewHorizontalSlider::paint(BitmapBuffer * dc)
|
||||
drawTrimSquare(dc, x, 0, COLOR_THEME_FOCUS);
|
||||
}
|
||||
|
||||
MainView6POS::MainView6POS(Window* parent, uint8_t idx) :
|
||||
MainViewSlider(parent, rect_t{}, idx)
|
||||
{
|
||||
void* user_data = (void*)SLIDER_6POS;
|
||||
lv_obj_add_event_cb(lvobj, slider_self_size, LV_EVENT_GET_SELF_SIZE,
|
||||
user_data);
|
||||
|
||||
setWidth(MULTIPOS_W);
|
||||
setHeight(MULTIPOS_H);
|
||||
}
|
||||
|
||||
void MainView6POS::paint(BitmapBuffer * dc)
|
||||
{
|
||||
#if NUM_XPOTS > 0 // prevent compiler warning
|
||||
@@ -55,10 +104,21 @@ void MainView6POS::paint(BitmapBuffer * dc)
|
||||
auto value = 1 + (potsPos[idx] & 0x0f);
|
||||
x = TRIM_SQUARE_SIZE / 2 + divRoundClosest((width() - TRIM_SQUARE_SIZE) * (value -1) , 6);
|
||||
drawTrimSquare(dc, x, 0, COLOR_THEME_FOCUS);
|
||||
dc->drawNumber(x + 1, 0, value, COLOR_THEME_PRIMARY2);
|
||||
dc->drawNumber(x + 1, 0, value, FONT(XS) | COLOR_THEME_PRIMARY2);
|
||||
#endif
|
||||
}
|
||||
|
||||
MainViewVerticalSlider::MainViewVerticalSlider(Window* parent, uint8_t idx) :
|
||||
MainViewSlider(parent, rect_t{}, idx)
|
||||
{
|
||||
void* user_data = (void*)SLIDER_VERT;
|
||||
lv_obj_add_event_cb(lvobj, slider_self_size, LV_EVENT_GET_SELF_SIZE,
|
||||
user_data);
|
||||
|
||||
setHeight(VERTICAL_SLIDERS_HEIGHT);
|
||||
setWidth(TRIM_SQUARE_SIZE);
|
||||
}
|
||||
|
||||
void MainViewVerticalSlider::paint(BitmapBuffer * dc)
|
||||
{
|
||||
// The ticks
|
||||
|
||||
@@ -31,7 +31,7 @@ constexpr uint8_t SLIDER_TICKS_COUNT = 40;
|
||||
#endif
|
||||
constexpr coord_t HMARGIN = 5;
|
||||
constexpr coord_t HORIZONTAL_SLIDERS_WIDTH = SLIDER_TICKS_COUNT * 4 + TRIM_SQUARE_SIZE;
|
||||
constexpr coord_t MULTIPOS_H = 20;
|
||||
constexpr coord_t MULTIPOS_H = 18;
|
||||
constexpr coord_t MULTIPOS_W = 50;
|
||||
constexpr coord_t VERTICAL_SLIDERS_HEIGHT = SLIDER_TICKS_COUNT * 4 + TRIM_SQUARE_SIZE;
|
||||
|
||||
@@ -63,19 +63,21 @@ class MainViewHorizontalSlider : public MainViewSlider
|
||||
{
|
||||
public:
|
||||
using MainViewSlider::MainViewSlider;
|
||||
MainViewHorizontalSlider(Window* parent, uint8_t idx);
|
||||
void paint(BitmapBuffer * dc) override;
|
||||
};
|
||||
|
||||
class MainView6POS : public MainViewSlider
|
||||
{
|
||||
public:
|
||||
using MainViewSlider::MainViewSlider;
|
||||
// using MainViewSlider::MainViewSlider;
|
||||
MainView6POS(Window* parent, uint8_t idx);
|
||||
void paint(BitmapBuffer * dc) override;
|
||||
};
|
||||
|
||||
class MainViewVerticalSlider : public MainViewSlider
|
||||
{
|
||||
public:
|
||||
using MainViewSlider::MainViewSlider;
|
||||
MainViewVerticalSlider(Window* parent, uint8_t idx);
|
||||
void paint(BitmapBuffer * dc) override;
|
||||
};
|
||||
|
||||
@@ -20,8 +20,31 @@
|
||||
*/
|
||||
|
||||
#include "trims.h"
|
||||
#include "sliders.h"
|
||||
|
||||
#include "opentx.h"
|
||||
|
||||
enum trim_type {
|
||||
TRIM_VERT,
|
||||
TRIM_HORIZ,
|
||||
};
|
||||
|
||||
static void trim_self_size(lv_event_t* e)
|
||||
{
|
||||
lv_point_t* s = (lv_point_t*)lv_event_get_param(e);
|
||||
trim_type t = (trim_type)(long)lv_event_get_user_data(e);
|
||||
switch(t) {
|
||||
case TRIM_VERT:
|
||||
s->y = VERTICAL_SLIDERS_HEIGHT;
|
||||
s->x = TRIM_SQUARE_SIZE;
|
||||
break;
|
||||
case TRIM_HORIZ:
|
||||
s->x = HORIZONTAL_SLIDERS_WIDTH;
|
||||
s->y = TRIM_SQUARE_SIZE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void MainViewTrim::checkEvents()
|
||||
{
|
||||
Window::checkEvents();
|
||||
@@ -33,6 +56,16 @@ void MainViewTrim::checkEvents()
|
||||
}
|
||||
}
|
||||
|
||||
MainViewHorizontalTrim::MainViewHorizontalTrim(Window* parent, uint8_t idx) :
|
||||
MainViewTrim(parent, rect_t{}, idx)
|
||||
{
|
||||
void* user_data = (void*)TRIM_HORIZ;
|
||||
lv_obj_add_event_cb(lvobj, trim_self_size, LV_EVENT_GET_SELF_SIZE, user_data);
|
||||
|
||||
setWidth(HORIZONTAL_SLIDERS_WIDTH);
|
||||
setHeight(TRIM_SQUARE_SIZE);
|
||||
}
|
||||
|
||||
void MainViewHorizontalTrim::paint(BitmapBuffer * dc)
|
||||
{
|
||||
int32_t trimMin, trimMax;
|
||||
@@ -78,6 +111,16 @@ void MainViewHorizontalTrim::paint(BitmapBuffer * dc)
|
||||
}
|
||||
}
|
||||
|
||||
MainViewVerticalTrim::MainViewVerticalTrim(Window* parent, uint8_t idx) :
|
||||
MainViewTrim(parent, rect_t{}, idx)
|
||||
{
|
||||
void* user_data = (void*)TRIM_VERT;
|
||||
lv_obj_add_event_cb(lvobj, trim_self_size, LV_EVENT_GET_SELF_SIZE, user_data);
|
||||
|
||||
setHeight(VERTICAL_SLIDERS_HEIGHT);
|
||||
setWidth(TRIM_SQUARE_SIZE);
|
||||
}
|
||||
|
||||
void MainViewVerticalTrim::paint(BitmapBuffer * dc)
|
||||
{
|
||||
int32_t trimMin, trimMax;
|
||||
|
||||
@@ -43,14 +43,13 @@ class MainViewHorizontalTrim : public MainViewTrim
|
||||
{
|
||||
public:
|
||||
using MainViewTrim::MainViewTrim;
|
||||
|
||||
MainViewHorizontalTrim(Window* parent, uint8_t idx);
|
||||
void paint(BitmapBuffer * dc) override;
|
||||
};
|
||||
|
||||
class MainViewVerticalTrim : public MainViewTrim
|
||||
{
|
||||
public:
|
||||
using MainViewTrim::MainViewTrim;
|
||||
|
||||
MainViewVerticalTrim(Window* parent, uint8_t idx);
|
||||
void paint(BitmapBuffer * dc) override;
|
||||
};
|
||||
|
||||
@@ -94,12 +94,10 @@ void RadioCalibrationPage::buildBody(FormWindow * window)
|
||||
{(2 * window->width()) / 3, window->height() / 2, 0, 0},
|
||||
STICK4, STICK3);
|
||||
|
||||
rect_t r = { 0, 0, window->width(), window->height() };
|
||||
auto deco = new ViewMainDecoration(window, r);
|
||||
std::unique_ptr<ViewMainDecoration> deco(new ViewMainDecoration(window));
|
||||
deco->setTrimsVisible(false);
|
||||
deco->setSlidersVisible(true);
|
||||
deco->setFlightModeVisible(false);
|
||||
deco->adjustDecoration();
|
||||
|
||||
#if defined(PCBNV14)
|
||||
new TextButton(window, {LCD_W - 120, LCD_H - 140, 90, 40}, "Next",
|
||||
|
||||
@@ -31,314 +31,165 @@
|
||||
|
||||
#include "board.h"
|
||||
|
||||
ViewMainDecoration::ViewMainDecoration(Window* parent, const rect_t& rect) :
|
||||
Window(parent, rect, NO_FOCUS)
|
||||
static Window* create_layout_box(Window* parent, lv_align_t align,
|
||||
lv_flex_flow_t flow)
|
||||
{
|
||||
createSliders();
|
||||
createTrims();
|
||||
createFlightMode();
|
||||
lv_obj_t* lv_parent = parent->getLvObj();
|
||||
|
||||
auto box = lv_obj_create(lv_parent);
|
||||
lv_obj_set_size(box, LV_SIZE_CONTENT, LV_SIZE_CONTENT);
|
||||
lv_obj_set_align(box, align);
|
||||
lv_obj_set_flex_flow(box, flow);
|
||||
|
||||
if (_LV_FLEX_COLUMN & flow) {
|
||||
lv_obj_set_style_pad_row(box, 0, 0);
|
||||
} else {
|
||||
lv_obj_set_style_pad_column(box, 0, 0);
|
||||
}
|
||||
|
||||
return new Window(parent, box);
|
||||
}
|
||||
|
||||
ViewMainDecoration::ViewMainDecoration(Window* parent) :
|
||||
parent(parent)
|
||||
{
|
||||
memset(sliders, 0, sizeof(sliders));
|
||||
memset(trims, 0, sizeof(trims));
|
||||
flightMode = nullptr;
|
||||
|
||||
w_ml = create_layout_box(parent, LV_ALIGN_LEFT_MID, LV_FLEX_FLOW_ROW_REVERSE);
|
||||
w_mr = create_layout_box(parent, LV_ALIGN_RIGHT_MID, LV_FLEX_FLOW_ROW);
|
||||
w_bl = create_layout_box(parent, LV_ALIGN_BOTTOM_LEFT, LV_FLEX_FLOW_COLUMN);
|
||||
w_bc = create_layout_box(parent, LV_ALIGN_BOTTOM_MID, LV_FLEX_FLOW_COLUMN);
|
||||
w_br = create_layout_box(parent, LV_ALIGN_BOTTOM_RIGHT, LV_FLEX_FLOW_COLUMN);
|
||||
|
||||
createTrims(w_ml, w_mr, w_bl, w_br);
|
||||
createFlightMode(w_bc);
|
||||
createSliders(w_ml, w_mr, w_bl, w_bc, w_br);
|
||||
}
|
||||
|
||||
void ViewMainDecoration::setSlidersVisible(bool visible)
|
||||
{
|
||||
//
|
||||
// Horizontal Sliders
|
||||
//
|
||||
sliders[SLIDERS_POT1]->setHeight(visible ? TRIM_SQUARE_SIZE : 0);
|
||||
|
||||
if (IS_POT_MULTIPOS(POT2)) {
|
||||
sliders[SLIDERS_POT2]->setHeight(visible ? MULTIPOS_H : 0);
|
||||
}
|
||||
else if (IS_POT(POT2)) {
|
||||
sliders[SLIDERS_POT2]->setHeight(visible ? TRIM_SQUARE_SIZE : 0);
|
||||
}
|
||||
|
||||
#if defined(HARDWARE_POT3)
|
||||
sliders[SLIDERS_POT3]->setHeight(visible ? TRIM_SQUARE_SIZE : 0);
|
||||
#endif
|
||||
|
||||
#if NUM_SLIDERS > 0
|
||||
//
|
||||
// Vertical sliders
|
||||
//
|
||||
sliders[SLIDERS_REAR_LEFT]->setWidth(visible ? TRIM_SQUARE_SIZE : 0);
|
||||
|
||||
#if defined(HARDWARE_EXT1) || defined(PCBX12S)
|
||||
if (IS_POT_SLIDER_AVAILABLE(EXT1)) {
|
||||
sliders[SLIDERS_EXT1]->setWidth(visible ? TRIM_SQUARE_SIZE : 0);
|
||||
}
|
||||
#endif
|
||||
|
||||
sliders[SLIDERS_REAR_RIGHT]->setWidth(visible ? TRIM_SQUARE_SIZE : 0);
|
||||
|
||||
#if defined(HARDWARE_EXT2) || defined(PCBX12S)
|
||||
if (IS_POT_SLIDER_AVAILABLE(EXT2)) {
|
||||
sliders[SLIDERS_EXT2]->setWidth(visible ? TRIM_SQUARE_SIZE : 0);
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
if (visible) {
|
||||
visibilityMask |= VM_SLIDERS;
|
||||
}
|
||||
else {
|
||||
visibilityMask &= ~VM_SLIDERS;
|
||||
auto fct = !visible ? lv_obj_add_flag : lv_obj_clear_flag;
|
||||
for (int i=0; i < SLIDERS_MAX; i++) {
|
||||
if (sliders[i]) {
|
||||
fct(sliders[i]->getLvObj(), LV_OBJ_FLAG_HIDDEN);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ViewMainDecoration::setTrimsVisible(bool visible)
|
||||
{
|
||||
trims[TRIMS_LH]->setHeight(visible ? TRIM_SQUARE_SIZE : 0);
|
||||
trims[TRIMS_RH]->setHeight(visible ? TRIM_SQUARE_SIZE : 0);
|
||||
|
||||
trims[TRIMS_LV]->setWidth(visible ? TRIM_SQUARE_SIZE : 0);
|
||||
trims[TRIMS_RV]->setWidth(visible ? TRIM_SQUARE_SIZE : 0);
|
||||
|
||||
if (visible) {
|
||||
visibilityMask |= VM_TRIMS;
|
||||
}
|
||||
else {
|
||||
visibilityMask &= ~VM_TRIMS;
|
||||
auto fct = !visible ? lv_obj_add_flag : lv_obj_clear_flag;
|
||||
for (int i=0; i < TRIMS_MAX; i++) {
|
||||
if (trims[i]) {
|
||||
fct(trims[i]->getLvObj(), LV_OBJ_FLAG_HIDDEN);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ViewMainDecoration::setFlightModeVisible(bool visible)
|
||||
{
|
||||
flightMode->setHeight(visible ? FM_LABEL_HEIGHT : 0);
|
||||
|
||||
if (visible) {
|
||||
visibilityMask |= VM_FM;
|
||||
auto fct = !visible ? lv_obj_add_flag : lv_obj_clear_flag;
|
||||
if (flightMode) {
|
||||
fct(flightMode->getLvObj(), LV_OBJ_FLAG_HIDDEN);
|
||||
}
|
||||
else {
|
||||
visibilityMask &= ~VM_FM;
|
||||
}
|
||||
}
|
||||
|
||||
void ViewMainDecoration::adjustDecoration()
|
||||
{
|
||||
// Sliders are closer to the edge and must be computed first
|
||||
|
||||
// These are located on the bottom
|
||||
auto pos = bottom() - sliders[SLIDERS_POT1]->height();
|
||||
sliders[SLIDERS_POT1]->setTop(pos);
|
||||
|
||||
if (sliders[SLIDERS_POT2]) {
|
||||
auto sl = sliders[SLIDERS_POT2];
|
||||
sl->setTop(pos);
|
||||
if (IS_POT_MULTIPOS(POT2)) {
|
||||
sl->setWidth(MULTIPOS_W);
|
||||
sl->setLeft((width() - sl->width()) / 2); // This is the position of middle multipos pot
|
||||
}
|
||||
else { // if !IS_POT(POT2) -> sliders[SLIDERS_POT2] == nullptr
|
||||
sl->setWidth(HORIZONTAL_SLIDERS_WIDTH);
|
||||
sl->setLeft(width() - sl->width() - HMARGIN); // Normal pot position, align to right
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(HARDWARE_POT3)
|
||||
sliders[SLIDERS_POT3]->setTop(pos);
|
||||
#endif
|
||||
|
||||
// Horizontal trims are on top of horizontal sliders
|
||||
pos -= trims[TRIMS_LH]->height();
|
||||
trims[TRIMS_LH]->setTop(pos);
|
||||
trims[TRIMS_RH]->setTop(pos);
|
||||
|
||||
// Vertical trims/slider are on top of horizontal sliders with a small margin
|
||||
auto vertTop = pos - HMARGIN - VERTICAL_SLIDERS_HEIGHT;
|
||||
|
||||
#if NUM_SLIDERS > 0
|
||||
// Left side (vertical)
|
||||
pos = left();
|
||||
sliders[SLIDERS_REAR_LEFT]->setLeft(pos);
|
||||
sliders[SLIDERS_REAR_LEFT]->setTop(vertTop);
|
||||
|
||||
#if defined(HARDWARE_EXT1) || defined(PCBX12S) // TODO: define HARDWARE_EXT1 for X12S
|
||||
sliders[SLIDERS_EXT1]->setLeft(pos);
|
||||
if (IS_POT_SLIDER_AVAILABLE(EXT1)) {
|
||||
auto rl = sliders[SLIDERS_REAR_LEFT];
|
||||
auto e1 = sliders[SLIDERS_EXT1];
|
||||
|
||||
// If EXT1 is configured as a slider,
|
||||
// place it bellow rear-left slider (and make them smaller)
|
||||
rl->setHeight(VERTICAL_SLIDERS_HEIGHT / 2);
|
||||
e1->setTop(vertTop + rl->height() + HMARGIN/2);
|
||||
e1->setHeight(rl->height());
|
||||
}
|
||||
else {
|
||||
auto rl = sliders[SLIDERS_REAR_LEFT];
|
||||
auto e1 = sliders[SLIDERS_EXT1];
|
||||
|
||||
// Otherwise hide the extra slider and make rear-left fullsize
|
||||
rl->setHeight(VERTICAL_SLIDERS_HEIGHT);
|
||||
e1->setHeight(0);
|
||||
}
|
||||
#endif
|
||||
|
||||
// Right side (vertical)
|
||||
pos = right() - sliders[SLIDERS_REAR_RIGHT]->width();
|
||||
sliders[SLIDERS_REAR_RIGHT]->setLeft(pos);
|
||||
sliders[SLIDERS_REAR_RIGHT]->setTop(vertTop);
|
||||
|
||||
#if defined(HARDWARE_EXT2) || defined(PCBX12S)
|
||||
sliders[SLIDERS_EXT2]->setLeft(pos);
|
||||
if (IS_POT_SLIDER_AVAILABLE(EXT2)) {
|
||||
auto rr = sliders[SLIDERS_REAR_RIGHT];
|
||||
auto e2 = sliders[SLIDERS_EXT2];
|
||||
|
||||
// If EXT2 is configured as a slider,
|
||||
// place it bellow rear-left slider (and make them smaller)
|
||||
rr->setHeight(VERTICAL_SLIDERS_HEIGHT / 2);
|
||||
e2->setTop(vertTop + rr->height() + HMARGIN/2);
|
||||
e2->setHeight(rr->height());
|
||||
}
|
||||
else {
|
||||
auto rr = sliders[SLIDERS_REAR_RIGHT];
|
||||
auto e2 = sliders[SLIDERS_EXT2];
|
||||
|
||||
// Otherwise hide the extra slider and make rear-left fullsize
|
||||
rr->setHeight(VERTICAL_SLIDERS_HEIGHT);
|
||||
e2->setHeight(0);
|
||||
}
|
||||
#endif
|
||||
|
||||
// Finally place the vertical trims further from the edge
|
||||
trims[TRIMS_LV]->setLeft(sliders[SLIDERS_REAR_LEFT]->right());
|
||||
trims[TRIMS_LV]->setTop(vertTop);
|
||||
trims[TRIMS_RV]->setLeft(sliders[SLIDERS_REAR_RIGHT]->left() - trims[TRIMS_RV]->width());
|
||||
trims[TRIMS_RV]->setTop(vertTop);
|
||||
#else
|
||||
// No sliders: place the vertical trims on the edge
|
||||
trims[TRIMS_LV]->setLeft(left());
|
||||
trims[TRIMS_LV]->setTop(vertTop);
|
||||
trims[TRIMS_RV]->setLeft(right() - trims[TRIMS_RV]->width());
|
||||
trims[TRIMS_RV]->setTop(vertTop);
|
||||
#endif
|
||||
|
||||
// Place the flight-mode text box
|
||||
// -> between horiz trims (if existing)
|
||||
// else on top of horiz sliders
|
||||
//
|
||||
pos = trims[TRIMS_LH]->right();
|
||||
flightMode->setLeft(pos);
|
||||
|
||||
pos = trims[TRIMS_RH]->left() - pos;
|
||||
flightMode->setWidth(pos);
|
||||
flightMode->setInnerWidth(pos);
|
||||
|
||||
pos = sliders[SLIDERS_POT1]->top();
|
||||
pos -= flightMode->height();
|
||||
flightMode->setTop(pos);
|
||||
}
|
||||
|
||||
rect_t ViewMainDecoration::getMainZone() const
|
||||
{
|
||||
coord_t border = (getVisibilityMask() == VM_NONE ?
|
||||
0 : MAIN_ZONE_BORDER);
|
||||
rect_t zone = {
|
||||
trims[TRIMS_LV]->right() + border, border,
|
||||
0, 0 // let's compute them!
|
||||
};
|
||||
auto x_left = lv_obj_get_x2(w_ml->getLvObj()) + 1;
|
||||
auto x_right = lv_obj_get_x(w_mr->getLvObj());
|
||||
|
||||
zone.w = trims[TRIMS_RV]->left() - border - zone.x;
|
||||
lv_coord_t bottom = LCD_H;
|
||||
Window* boxes[] = { w_bl, w_bc, w_br };
|
||||
|
||||
// min(trims[TRIMS_LH]->top(), flightMode->top())
|
||||
if (trims[TRIMS_LH]->top() < flightMode->top())
|
||||
zone.h = trims[TRIMS_LH]->top();
|
||||
else
|
||||
zone.h = flightMode->top();
|
||||
for ( auto box : boxes ) {
|
||||
auto obj = box->getLvObj();
|
||||
auto y = lv_obj_get_y(obj);
|
||||
if (y < bottom) bottom = y;
|
||||
}
|
||||
|
||||
zone.h -= border + zone.y;
|
||||
|
||||
return zone;
|
||||
return rect_t{ x_left, 0, x_right - x_left, bottom};
|
||||
}
|
||||
|
||||
void ViewMainDecoration::createSliders()
|
||||
void ViewMainDecoration::createSliders(Window* ml, Window* mr, Window* bl, Window* bc, Window* br)
|
||||
{
|
||||
// fixed size array, so that works
|
||||
memset(sliders, 0, sizeof(sliders));
|
||||
|
||||
rect_t r = {
|
||||
// left
|
||||
HMARGIN, 0,
|
||||
HORIZONTAL_SLIDERS_WIDTH, 0
|
||||
};
|
||||
|
||||
sliders[SLIDERS_POT1] = new MainViewHorizontalSlider(this, r, CALIBRATED_POT1);
|
||||
Window* sl = new MainViewHorizontalSlider(bl, CALIBRATED_POT1);
|
||||
sl->updateSize();
|
||||
sliders[SLIDERS_POT1] = sl;
|
||||
|
||||
r = rect_t { 0, 0, 0, 0 };
|
||||
if (IS_POT_MULTIPOS(POT2)) {
|
||||
sliders[SLIDERS_POT2] = new MainView6POS(this, r, 1);
|
||||
sl = new MainView6POS(bc, 1);
|
||||
sl->updateSize();
|
||||
sliders[SLIDERS_POT2] = sl;
|
||||
}
|
||||
else if (IS_POT(POT2)) {
|
||||
sliders[SLIDERS_POT2] = new MainViewHorizontalSlider(this, r, CALIBRATED_POT2);
|
||||
sl = new MainViewHorizontalSlider(bc, CALIBRATED_POT2);
|
||||
sl->updateSize();
|
||||
sliders[SLIDERS_POT2] = sl;
|
||||
}
|
||||
|
||||
#if defined(HARDWARE_POT3)
|
||||
r = rect_t {
|
||||
// right
|
||||
width() - HORIZONTAL_SLIDERS_WIDTH - HMARGIN, 0,
|
||||
HORIZONTAL_SLIDERS_WIDTH, 0
|
||||
};
|
||||
|
||||
sliders[SLIDERS_POT3] = new MainViewHorizontalSlider(this, r, CALIBRATED_POT3);
|
||||
sl = new MainViewHorizontalSlider(br, CALIBRATED_POT3);
|
||||
sl->updateSize();
|
||||
sliders[SLIDERS_POT3] = sl;
|
||||
#endif
|
||||
|
||||
#if NUM_SLIDERS > 0
|
||||
r = rect_t { 0, 0, 0, 0 };
|
||||
sliders[SLIDERS_REAR_LEFT] = new MainViewVerticalSlider(this, r, CALIBRATED_SLIDER_REAR_LEFT);
|
||||
sliders[SLIDERS_REAR_RIGHT] = new MainViewVerticalSlider(this, r, CALIBRATED_SLIDER_REAR_RIGHT);
|
||||
sl = new MainViewVerticalSlider(ml, CALIBRATED_SLIDER_REAR_LEFT);
|
||||
sl->updateSize(); // only pos...
|
||||
sliders[SLIDERS_REAR_LEFT] = sl;
|
||||
|
||||
sl = new MainViewVerticalSlider(mr, CALIBRATED_SLIDER_REAR_RIGHT);
|
||||
sl->updateSize(); // only pos...
|
||||
sliders[SLIDERS_REAR_RIGHT] = sl;
|
||||
|
||||
#if defined(HARDWARE_EXT1) || defined(PCBX12S)
|
||||
sliders[SLIDERS_EXT1] = new MainViewVerticalSlider(this, r, CALIBRATED_POT_EXT1);
|
||||
if (IS_POT_SLIDER_AVAILABLE(EXT1)) {
|
||||
sl = new MainViewVerticalSlider(ml, CALIBRATED_POT_EXT1);
|
||||
sl->updateSize();
|
||||
sliders[SLIDERS_EXT1] = sl;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(HARDWARE_EXT2) || defined(PCBX12S)
|
||||
sliders[SLIDERS_EXT2] = new MainViewVerticalSlider(this, r, CALIBRATED_POT_EXT2);
|
||||
if (IS_POT_SLIDER_AVAILABLE(EXT2)) {
|
||||
sl = new MainViewVerticalSlider(mr, CALIBRATED_POT_EXT2);
|
||||
sl->updateSize();
|
||||
sliders[SLIDERS_EXT2] = sl;
|
||||
}
|
||||
#endif
|
||||
#endif // NUM_SLIDERS > 0
|
||||
}
|
||||
|
||||
void ViewMainDecoration::createTrims()
|
||||
void ViewMainDecoration::createTrims(Window* ml, Window* mr, Window* bl, Window* br)
|
||||
{
|
||||
// Trim order TRIM_LH, TRIM_LV, TRIM_RV, TRIM_RH
|
||||
|
||||
rect_t r = {
|
||||
left() + HMARGIN, 0,
|
||||
HORIZONTAL_SLIDERS_WIDTH, 0
|
||||
};
|
||||
Window* tr = new MainViewHorizontalTrim(bl, TRIMS_LH);
|
||||
tr->updateSize();
|
||||
trims[TRIMS_LH] = tr;
|
||||
|
||||
tr = new MainViewHorizontalTrim(br, TRIMS_RH);
|
||||
tr->updateSize();
|
||||
trims[TRIMS_RH] = tr;
|
||||
|
||||
tr = new MainViewVerticalTrim(ml, TRIMS_LV);
|
||||
tr->updateSize();
|
||||
trims[TRIMS_LV] = tr;
|
||||
|
||||
trims[TRIMS_LH] = new MainViewHorizontalTrim(this, r, TRIMS_LH);
|
||||
|
||||
r = rect_t {
|
||||
right() - HORIZONTAL_SLIDERS_WIDTH - HMARGIN, 0,
|
||||
HORIZONTAL_SLIDERS_WIDTH, 0
|
||||
};
|
||||
|
||||
trims[TRIMS_RH] = new MainViewHorizontalTrim(this, r, TRIMS_RH);
|
||||
|
||||
r = rect_t {
|
||||
0, 0, 0,
|
||||
VERTICAL_SLIDERS_HEIGHT
|
||||
};
|
||||
|
||||
trims[TRIMS_LV] = new MainViewVerticalTrim(this, r, TRIMS_LV);
|
||||
trims[TRIMS_RV] = new MainViewVerticalTrim(this, r, TRIMS_RV);
|
||||
tr = new MainViewVerticalTrim(mr, TRIMS_RV);
|
||||
tr->updateSize();
|
||||
trims[TRIMS_RV] = tr;
|
||||
}
|
||||
|
||||
void ViewMainDecoration::createFlightMode()
|
||||
void ViewMainDecoration::createFlightMode(Window* bc)
|
||||
{
|
||||
rect_t r = {
|
||||
// centered text box (50 pixels from either edge)
|
||||
// -> re-size once the other components are set
|
||||
50, 0, width() - 100, 0
|
||||
};
|
||||
|
||||
std::function<std::string()> getFM = []() -> std::string {
|
||||
return stringFromNtString(g_model.flightModeData[mixerCurrentFlightMode].name);
|
||||
};
|
||||
};
|
||||
|
||||
flightMode = new DynamicText(this, r, getFM, CENTERED | COLOR_THEME_SECONDARY1);
|
||||
flightMode = new DynamicText(bc, rect_t{}, getFM, COLOR_THEME_SECONDARY1);
|
||||
}
|
||||
|
||||
|
||||
@@ -25,44 +25,25 @@
|
||||
|
||||
constexpr coord_t FM_LABEL_HEIGHT = 20;
|
||||
|
||||
class ViewMainDecoration: public Window
|
||||
class ViewMainDecoration
|
||||
{
|
||||
public:
|
||||
ViewMainDecoration(Window * parent, const rect_t & rect);
|
||||
ViewMainDecoration(Window* parent);
|
||||
|
||||
// Set decoration visibility
|
||||
void setTrimsVisible(bool visible);
|
||||
void setSlidersVisible(bool visible);
|
||||
void setFlightModeVisible(bool visible);
|
||||
|
||||
// Re-calculate positions
|
||||
void adjustDecoration();
|
||||
|
||||
// Get the available space in the middle of the screen
|
||||
// (without decoration)
|
||||
rect_t getMainZone() const;
|
||||
|
||||
enum VisibilityMask {
|
||||
VM_NONE = 0,
|
||||
VM_TRIMS = 1 << 0,
|
||||
VM_SLIDERS = 1 << 1,
|
||||
VM_FM = 1 << 2,
|
||||
VM_ALL = VM_TRIMS | VM_SLIDERS | VM_FM,
|
||||
};
|
||||
|
||||
unsigned getVisibilityMask() const
|
||||
{
|
||||
return visibilityMask;
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
#if defined(DEBUG_WINDOWS)
|
||||
virtual std::string getName() const
|
||||
{
|
||||
return "ViewMainDecoration";
|
||||
}
|
||||
#endif
|
||||
|
||||
enum {
|
||||
SLIDERS_POT1 = 0,
|
||||
@@ -83,12 +64,18 @@ class ViewMainDecoration: public Window
|
||||
TRIMS_MAX
|
||||
};
|
||||
|
||||
Window* parent;
|
||||
Window* w_ml;
|
||||
Window* w_mr;
|
||||
Window* w_bl;
|
||||
Window* w_bc;
|
||||
Window* w_br;
|
||||
|
||||
Window* sliders[SLIDERS_MAX];
|
||||
Window* trims[TRIMS_MAX];
|
||||
Window* flightMode;
|
||||
unsigned visibilityMask = VM_NONE;
|
||||
|
||||
void createSliders();
|
||||
void createTrims();
|
||||
void createFlightMode();
|
||||
void createSliders(Window* ml, Window* mr, Window* bl, Window* bc, Window* br);
|
||||
void createTrims(Window* ml, Window* mr, Window* bl, Window* br);
|
||||
void createFlightMode(Window* bc);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user