fix(color): built in widgets may crash when switching full screen mode, some layouts not resizing correctly (#7044)

This commit is contained in:
philmoz
2026-01-30 12:03:30 +10:00
committed by GitHub
parent f5da4b83d4
commit 7f9bb42902
14 changed files with 60 additions and 39 deletions
+1 -1
View File
@@ -64,7 +64,7 @@ class Layout2x4 : public Layout
void setPanels() 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 || if (mainZone.x != zone.x || mainZone.y != zone.y || mainZone.w != zone.w ||
mainZone.h != zone.h) { mainZone.h != zone.h) {
mainZone = zone; mainZone = zone;
+1 -1
View File
@@ -57,7 +57,7 @@ class Layout6x1 : public Layout
void setPanel() 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 || if (mainZone.x != zone.x || mainZone.y != zone.y || mainZone.w != zone.w ||
mainZone.h != zone.h) { mainZone.h != zone.h) {
mainZone = zone; mainZone = zone;
+17 -20
View File
@@ -335,26 +335,25 @@ void Layout::show(bool visible)
} }
} }
rect_t Layout::getMainZone() const bool Layout::hasFullScreenWidget() const
{ {
rect_t zone = decoration->getMainZone(); for (int i = 0; i < zoneCount; i += 1)
if (hasSliders() || hasTrims() || hasFlightMode()) { if (widgets[i] && widgets[i]->isFullscreen())
// some decoration activated return true;
zone.x += PAD_LARGE; return false;
zone.y += PAD_LARGE; }
zone.w -= 2 * PAD_LARGE;
zone.h -= 2 * PAD_LARGE; rect_t Layout::getWidgetsZone() const
} {
if (hasTopbar()) { if (hasFullScreenWidget())
zone.y += EdgeTxStyles::MENU_HEADER_HEIGHT; return {0, 0, LCD_W, LCD_H};
zone.h -= EdgeTxStyles::MENU_HEADER_HEIGHT;
} return decoration->getWidgetsZone(hasTopbar());
return zone;
} }
rect_t Layout::getZone(unsigned int index) const rect_t Layout::getZone(unsigned int index) const
{ {
rect_t z = getMainZone(); rect_t z = getWidgetsZone();
unsigned int i = index * 4; unsigned int i = index * 4;
@@ -371,13 +370,11 @@ rect_t Layout::getZone(unsigned int index) const
void Layout::checkEvents() void Layout::checkEvents()
{ {
Window::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) { if (z.x != lastMainZone.x || z.y != lastMainZone.y || z.w != lastMainZone.w || z.h != lastMainZone.h) {
lastMainZone = z; lastMainZone = z;
for (int i = 0; i < zoneCount; i++) if (!hasFullScreenWidget())
if (widgets[i] && widgets[i]->isFullscreen()) updateZones();
return;
updateZones();
} }
} }
+3 -1
View File
@@ -121,6 +121,8 @@ class Layout: public WidgetsContainer
void removeWidget(unsigned int index) override; void removeWidget(unsigned int index) override;
bool hasFullScreenWidget() const;
protected: protected:
const LayoutFactory* factory = nullptr; const LayoutFactory* factory = nullptr;
ViewMainDecoration* decoration = nullptr; ViewMainDecoration* decoration = nullptr;
@@ -134,7 +136,7 @@ class Layout: public WidgetsContainer
uint32_t lastRefresh = 0; uint32_t lastRefresh = 0;
// Get the available space for widgets // Get the available space for widgets
rect_t getMainZone() const; rect_t getWidgetsZone() const;
unsigned int getZonesCount() const override { return zoneCount; } unsigned int getZonesCount() const override { return zoneCount; }
rect_t getZone(unsigned int index) const override; rect_t getZone(unsigned int index) const override;
@@ -108,17 +108,22 @@ static bool canTrimShow(int idx)
return false; 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; coord_t bh = 0;
if (showTopBar) {
y = EdgeTxStyles::MENU_HEADER_HEIGHT;
bh = EdgeTxStyles::MENU_HEADER_HEIGHT;
}
if (showSliders) { if (showSliders) {
if (hasVerticalSliders) { if (hasVerticalSliders) {
x += MainViewSlider::SLIDER_BAR_SIZE; x += MainViewSlider::SLIDER_BAR_SIZE;
w -= 2 * MainViewSlider::SLIDER_BAR_SIZE; w -= 2 * MainViewSlider::SLIDER_BAR_SIZE;
} }
bh = MainViewSlider::SLIDER_BAR_SIZE; bh += MainViewSlider::SLIDER_BAR_SIZE;
} }
if (showTrims) { if (showTrims) {
@@ -139,9 +144,16 @@ rect_t ViewMainDecoration::getMainZone() const
bh -= MainViewSlider::SLIDER_BAR_SIZE; 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; 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) 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 // Get the available space in the middle of the screen
// (without decoration) // (without decoration)
rect_t getMainZone() const; rect_t getWidgetsZone(bool showTopBar) const;
protected: protected:
enum { enum {
+1 -1
View File
@@ -212,8 +212,8 @@ void Widget::setFullscreen(bool enable)
fullscreen = enable; fullscreen = enable;
// Show or hide ViewMain widgets and decorations // Show or hide ViewMain widgets and decorations
Messaging::send(Messaging::DECORATION_UPDATE);
ViewMain::instance()->show(!enable); ViewMain::instance()->show(!enable);
Messaging::send(Messaging::DECORATION_UPDATE);
// Leave Fullscreen Mode // Leave Fullscreen Mode
if (!enable) { if (!enable) {
+2 -2
View File
@@ -82,7 +82,7 @@ class GaugeWidget : public Widget
void update() override void update() override
{ {
if (!loaded) return; if (!loaded || _deleted) return;
auto widgetData = getPersistentData(); auto widgetData = getPersistentData();
@@ -107,7 +107,7 @@ class GaugeWidget : public Widget
void foreground() override void foreground() override
{ {
if (!loaded) return; if (!loaded || _deleted) return;
auto newValue = getGuageValue(); auto newValue = getGuageValue();
if (lastValue != newValue) { if (lastValue != newValue) {
+2 -2
View File
@@ -55,7 +55,7 @@ class ModelBitmapWidget : public Widget
void foreground() override void foreground() override
{ {
if (!loaded) return; if (!loaded || _deleted) return;
if (getHash() != deps_hash) { if (getHash() != deps_hash) {
update(); update();
@@ -68,7 +68,7 @@ class ModelBitmapWidget : public Widget
void update() override void update() override
{ {
if (!loaded) return; if (!loaded || _deleted) return;
auto widgetData = getPersistentData(); auto widgetData = getPersistentData();
+1 -1
View File
@@ -99,7 +99,7 @@ class ChannelValue : public Window
void refresh() void refresh()
{ {
if (!loaded) return; if (!loaded || _deleted) return;
int16_t value = channelOutputs[channel]; int16_t value = channelOutputs[channel];
@@ -104,6 +104,8 @@ class RadioInfoWidget : public Widget
void update() override void update() override
{ {
if (_deleted) return;
auto widgetData = getPersistentData(); auto widgetData = getPersistentData();
// get colors from options // get colors from options
@@ -114,6 +116,8 @@ class RadioInfoWidget : public Widget
void foreground() override void foreground() override
{ {
if (_deleted) return;
usbIcon->show(usbPlugged()); usbIcon->show(usbPlugged());
if (getSelectedUsbMode() == USB_UNSELECTED_MODE) if (getSelectedUsbMode() == USB_UNSELECTED_MODE)
usbIcon->setColor(COLOR_THEME_PRIMARY3_INDEX); usbIcon->setColor(COLOR_THEME_PRIMARY3_INDEX);
@@ -243,11 +247,15 @@ class DateTimeWidget : public Widget
void foreground() override void foreground() override
{ {
if (_deleted) return;
Widget::checkEvents(); Widget::checkEvents();
} }
void update() override void update() override
{ {
if (_deleted) return;
auto widgetData = getPersistentData(); auto widgetData = getPersistentData();
// get color from options // get color from options
@@ -295,6 +303,8 @@ class InternalGPSWidget : public Widget
void foreground() override void foreground() override
{ {
if (_deleted) return;
bool hasGPS = serialGetModePort(UART_MODE_GPS) >= 0; bool hasGPS = serialGetModePort(UART_MODE_GPS) >= 0;
numSats->show(hasGPS && (gpsData.numSat > 0)); numSats->show(hasGPS && (gpsData.numSat > 0));
+1 -1
View File
@@ -60,7 +60,7 @@ class TextWidget : public Widget
void update() override void update() override
{ {
if (!loaded) return; if (!loaded || _deleted) return;
auto widgetData = getPersistentData(); auto widgetData = getPersistentData();
+2 -2
View File
@@ -107,7 +107,7 @@ class TimerWidget : public Widget
void foreground() override void foreground() override
{ {
if (!loaded) return; if (!loaded || _deleted) return;
auto widgetData = getPersistentData(); auto widgetData = getPersistentData();
@@ -236,7 +236,7 @@ class TimerWidget : public Widget
void update() override void update() override
{ {
if (!loaded) return; if (!loaded || _deleted) return;
auto widgetData = getPersistentData(); auto widgetData = getPersistentData();
+2 -2
View File
@@ -76,7 +76,7 @@ class ValueWidget : public Widget
void foreground() override void foreground() override
{ {
if (!loaded) return; if (!loaded || _deleted) return;
bool changed = false; bool changed = false;
@@ -186,7 +186,7 @@ class ValueWidget : public Widget
void update() override void update() override
{ {
if (!loaded) return; if (!loaded || _deleted) return;
auto widgetData = getPersistentData(); auto widgetData = getPersistentData();