fix(color): built in widgets may crash when switching full screen mode, some layouts not resizing correctly (#7044)
This commit is contained in:
@@ -64,7 +64,7 @@ class Layout2x4 : public Layout
|
||||
|
||||
void setPanels()
|
||||
{
|
||||
rect_t zone = Layout::getMainZone();
|
||||
rect_t zone = Layout::getWidgetsZone();
|
||||
if (mainZone.x != zone.x || mainZone.y != zone.y || mainZone.w != zone.w ||
|
||||
mainZone.h != zone.h) {
|
||||
mainZone = zone;
|
||||
|
||||
@@ -57,7 +57,7 @@ class Layout6x1 : public Layout
|
||||
|
||||
void setPanel()
|
||||
{
|
||||
rect_t zone = Layout::getMainZone();
|
||||
rect_t zone = Layout::getWidgetsZone();
|
||||
if (mainZone.x != zone.x || mainZone.y != zone.y || mainZone.w != zone.w ||
|
||||
mainZone.h != zone.h) {
|
||||
mainZone = zone;
|
||||
|
||||
@@ -335,26 +335,25 @@ void Layout::show(bool visible)
|
||||
}
|
||||
}
|
||||
|
||||
rect_t Layout::getMainZone() const
|
||||
bool Layout::hasFullScreenWidget() const
|
||||
{
|
||||
rect_t zone = decoration->getMainZone();
|
||||
if (hasSliders() || hasTrims() || hasFlightMode()) {
|
||||
// some decoration activated
|
||||
zone.x += PAD_LARGE;
|
||||
zone.y += PAD_LARGE;
|
||||
zone.w -= 2 * PAD_LARGE;
|
||||
zone.h -= 2 * PAD_LARGE;
|
||||
}
|
||||
if (hasTopbar()) {
|
||||
zone.y += EdgeTxStyles::MENU_HEADER_HEIGHT;
|
||||
zone.h -= EdgeTxStyles::MENU_HEADER_HEIGHT;
|
||||
}
|
||||
return zone;
|
||||
for (int i = 0; i < zoneCount; i += 1)
|
||||
if (widgets[i] && widgets[i]->isFullscreen())
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
rect_t Layout::getWidgetsZone() const
|
||||
{
|
||||
if (hasFullScreenWidget())
|
||||
return {0, 0, LCD_W, LCD_H};
|
||||
|
||||
return decoration->getWidgetsZone(hasTopbar());
|
||||
}
|
||||
|
||||
rect_t Layout::getZone(unsigned int index) const
|
||||
{
|
||||
rect_t z = getMainZone();
|
||||
rect_t z = getWidgetsZone();
|
||||
|
||||
unsigned int i = index * 4;
|
||||
|
||||
@@ -371,13 +370,11 @@ rect_t Layout::getZone(unsigned int index) const
|
||||
void Layout::checkEvents()
|
||||
{
|
||||
Window::checkEvents();
|
||||
rect_t z = getMainZone();
|
||||
rect_t z = getWidgetsZone();
|
||||
if (z.x != lastMainZone.x || z.y != lastMainZone.y || z.w != lastMainZone.w || z.h != lastMainZone.h) {
|
||||
lastMainZone = z;
|
||||
for (int i = 0; i < zoneCount; i++)
|
||||
if (widgets[i] && widgets[i]->isFullscreen())
|
||||
return;
|
||||
updateZones();
|
||||
if (!hasFullScreenWidget())
|
||||
updateZones();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -121,6 +121,8 @@ class Layout: public WidgetsContainer
|
||||
|
||||
void removeWidget(unsigned int index) override;
|
||||
|
||||
bool hasFullScreenWidget() const;
|
||||
|
||||
protected:
|
||||
const LayoutFactory* factory = nullptr;
|
||||
ViewMainDecoration* decoration = nullptr;
|
||||
@@ -134,7 +136,7 @@ class Layout: public WidgetsContainer
|
||||
uint32_t lastRefresh = 0;
|
||||
|
||||
// Get the available space for widgets
|
||||
rect_t getMainZone() const;
|
||||
rect_t getWidgetsZone() const;
|
||||
|
||||
unsigned int getZonesCount() const override { return zoneCount; }
|
||||
rect_t getZone(unsigned int index) const override;
|
||||
|
||||
@@ -108,17 +108,22 @@ static bool canTrimShow(int idx)
|
||||
return false;
|
||||
}
|
||||
|
||||
rect_t ViewMainDecoration::getMainZone() const
|
||||
rect_t ViewMainDecoration::getWidgetsZone(bool showTopBar) const
|
||||
{
|
||||
coord_t x = 0, w = width(), h = height();
|
||||
coord_t x = 0, y = 0, w = width(), h = height();
|
||||
coord_t bh = 0;
|
||||
|
||||
if (showTopBar) {
|
||||
y = EdgeTxStyles::MENU_HEADER_HEIGHT;
|
||||
bh = EdgeTxStyles::MENU_HEADER_HEIGHT;
|
||||
}
|
||||
|
||||
if (showSliders) {
|
||||
if (hasVerticalSliders) {
|
||||
x += MainViewSlider::SLIDER_BAR_SIZE;
|
||||
w -= 2 * MainViewSlider::SLIDER_BAR_SIZE;
|
||||
}
|
||||
bh = MainViewSlider::SLIDER_BAR_SIZE;
|
||||
bh += MainViewSlider::SLIDER_BAR_SIZE;
|
||||
}
|
||||
|
||||
if (showTrims) {
|
||||
@@ -139,9 +144,16 @@ rect_t ViewMainDecoration::getMainZone() const
|
||||
bh -= MainViewSlider::SLIDER_BAR_SIZE;
|
||||
}
|
||||
|
||||
if (showSliders || showTrims || showFM) {
|
||||
x += PAD_LARGE;
|
||||
y += PAD_LARGE;
|
||||
w -= PAD_LARGE * 2;
|
||||
bh += PAD_LARGE * 2;
|
||||
}
|
||||
|
||||
h -= bh;
|
||||
|
||||
return rect_t{x, 0, w, h};
|
||||
return rect_t{x, y, w, h};
|
||||
}
|
||||
|
||||
void ViewMainDecoration::createSliders(Window* ml, Window* mr, Window* bl, Window* bc, Window* br)
|
||||
|
||||
@@ -37,7 +37,7 @@ class ViewMainDecoration : public Window
|
||||
|
||||
// Get the available space in the middle of the screen
|
||||
// (without decoration)
|
||||
rect_t getMainZone() const;
|
||||
rect_t getWidgetsZone(bool showTopBar) const;
|
||||
|
||||
protected:
|
||||
enum {
|
||||
|
||||
@@ -212,8 +212,8 @@ void Widget::setFullscreen(bool enable)
|
||||
fullscreen = enable;
|
||||
|
||||
// Show or hide ViewMain widgets and decorations
|
||||
Messaging::send(Messaging::DECORATION_UPDATE);
|
||||
ViewMain::instance()->show(!enable);
|
||||
Messaging::send(Messaging::DECORATION_UPDATE);
|
||||
|
||||
// Leave Fullscreen Mode
|
||||
if (!enable) {
|
||||
|
||||
@@ -82,7 +82,7 @@ class GaugeWidget : public Widget
|
||||
|
||||
void update() override
|
||||
{
|
||||
if (!loaded) return;
|
||||
if (!loaded || _deleted) return;
|
||||
|
||||
auto widgetData = getPersistentData();
|
||||
|
||||
@@ -107,7 +107,7 @@ class GaugeWidget : public Widget
|
||||
|
||||
void foreground() override
|
||||
{
|
||||
if (!loaded) return;
|
||||
if (!loaded || _deleted) return;
|
||||
|
||||
auto newValue = getGuageValue();
|
||||
if (lastValue != newValue) {
|
||||
|
||||
@@ -55,7 +55,7 @@ class ModelBitmapWidget : public Widget
|
||||
|
||||
void foreground() override
|
||||
{
|
||||
if (!loaded) return;
|
||||
if (!loaded || _deleted) return;
|
||||
|
||||
if (getHash() != deps_hash) {
|
||||
update();
|
||||
@@ -68,7 +68,7 @@ class ModelBitmapWidget : public Widget
|
||||
|
||||
void update() override
|
||||
{
|
||||
if (!loaded) return;
|
||||
if (!loaded || _deleted) return;
|
||||
|
||||
auto widgetData = getPersistentData();
|
||||
|
||||
|
||||
@@ -99,7 +99,7 @@ class ChannelValue : public Window
|
||||
|
||||
void refresh()
|
||||
{
|
||||
if (!loaded) return;
|
||||
if (!loaded || _deleted) return;
|
||||
|
||||
int16_t value = channelOutputs[channel];
|
||||
|
||||
|
||||
@@ -104,6 +104,8 @@ class RadioInfoWidget : public Widget
|
||||
|
||||
void update() override
|
||||
{
|
||||
if (_deleted) return;
|
||||
|
||||
auto widgetData = getPersistentData();
|
||||
|
||||
// get colors from options
|
||||
@@ -114,6 +116,8 @@ class RadioInfoWidget : public Widget
|
||||
|
||||
void foreground() override
|
||||
{
|
||||
if (_deleted) return;
|
||||
|
||||
usbIcon->show(usbPlugged());
|
||||
if (getSelectedUsbMode() == USB_UNSELECTED_MODE)
|
||||
usbIcon->setColor(COLOR_THEME_PRIMARY3_INDEX);
|
||||
@@ -243,11 +247,15 @@ class DateTimeWidget : public Widget
|
||||
|
||||
void foreground() override
|
||||
{
|
||||
if (_deleted) return;
|
||||
|
||||
Widget::checkEvents();
|
||||
}
|
||||
|
||||
void update() override
|
||||
{
|
||||
if (_deleted) return;
|
||||
|
||||
auto widgetData = getPersistentData();
|
||||
|
||||
// get color from options
|
||||
@@ -295,6 +303,8 @@ class InternalGPSWidget : public Widget
|
||||
|
||||
void foreground() override
|
||||
{
|
||||
if (_deleted) return;
|
||||
|
||||
bool hasGPS = serialGetModePort(UART_MODE_GPS) >= 0;
|
||||
|
||||
numSats->show(hasGPS && (gpsData.numSat > 0));
|
||||
|
||||
@@ -60,7 +60,7 @@ class TextWidget : public Widget
|
||||
|
||||
void update() override
|
||||
{
|
||||
if (!loaded) return;
|
||||
if (!loaded || _deleted) return;
|
||||
|
||||
auto widgetData = getPersistentData();
|
||||
|
||||
|
||||
@@ -107,7 +107,7 @@ class TimerWidget : public Widget
|
||||
|
||||
void foreground() override
|
||||
{
|
||||
if (!loaded) return;
|
||||
if (!loaded || _deleted) return;
|
||||
|
||||
auto widgetData = getPersistentData();
|
||||
|
||||
@@ -236,7 +236,7 @@ class TimerWidget : public Widget
|
||||
|
||||
void update() override
|
||||
{
|
||||
if (!loaded) return;
|
||||
if (!loaded || _deleted) return;
|
||||
|
||||
auto widgetData = getPersistentData();
|
||||
|
||||
|
||||
@@ -76,7 +76,7 @@ class ValueWidget : public Widget
|
||||
|
||||
void foreground() override
|
||||
{
|
||||
if (!loaded) return;
|
||||
if (!loaded || _deleted) return;
|
||||
|
||||
bool changed = false;
|
||||
|
||||
@@ -186,7 +186,7 @@ class ValueWidget : public Widget
|
||||
|
||||
void update() override
|
||||
{
|
||||
if (!loaded) return;
|
||||
if (!loaded || _deleted) return;
|
||||
|
||||
auto widgetData = getPersistentData();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user