Skip to content

Commit 7f9bb42

Browse files
authored
fix(color): built in widgets may crash when switching full screen mode, some layouts not resizing correctly (#7044)
1 parent f5da4b8 commit 7f9bb42

File tree

14 files changed

+60
-39
lines changed

14 files changed

+60
-39
lines changed

radio/src/gui/colorlcd/layouts/layout2x4.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class Layout2x4 : public Layout
6464

6565
void setPanels()
6666
{
67-
rect_t zone = Layout::getMainZone();
67+
rect_t zone = Layout::getWidgetsZone();
6868
if (mainZone.x != zone.x || mainZone.y != zone.y || mainZone.w != zone.w ||
6969
mainZone.h != zone.h) {
7070
mainZone = zone;

radio/src/gui/colorlcd/layouts/layout6x1.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class Layout6x1 : public Layout
5757

5858
void setPanel()
5959
{
60-
rect_t zone = Layout::getMainZone();
60+
rect_t zone = Layout::getWidgetsZone();
6161
if (mainZone.x != zone.x || mainZone.y != zone.y || mainZone.w != zone.w ||
6262
mainZone.h != zone.h) {
6363
mainZone = zone;

radio/src/gui/colorlcd/mainview/layout.cpp

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -335,26 +335,25 @@ void Layout::show(bool visible)
335335
}
336336
}
337337

338-
rect_t Layout::getMainZone() const
338+
bool Layout::hasFullScreenWidget() const
339339
{
340-
rect_t zone = decoration->getMainZone();
341-
if (hasSliders() || hasTrims() || hasFlightMode()) {
342-
// some decoration activated
343-
zone.x += PAD_LARGE;
344-
zone.y += PAD_LARGE;
345-
zone.w -= 2 * PAD_LARGE;
346-
zone.h -= 2 * PAD_LARGE;
347-
}
348-
if (hasTopbar()) {
349-
zone.y += EdgeTxStyles::MENU_HEADER_HEIGHT;
350-
zone.h -= EdgeTxStyles::MENU_HEADER_HEIGHT;
351-
}
352-
return zone;
340+
for (int i = 0; i < zoneCount; i += 1)
341+
if (widgets[i] && widgets[i]->isFullscreen())
342+
return true;
343+
return false;
344+
}
345+
346+
rect_t Layout::getWidgetsZone() const
347+
{
348+
if (hasFullScreenWidget())
349+
return {0, 0, LCD_W, LCD_H};
350+
351+
return decoration->getWidgetsZone(hasTopbar());
353352
}
354353

355354
rect_t Layout::getZone(unsigned int index) const
356355
{
357-
rect_t z = getMainZone();
356+
rect_t z = getWidgetsZone();
358357

359358
unsigned int i = index * 4;
360359

@@ -371,13 +370,11 @@ rect_t Layout::getZone(unsigned int index) const
371370
void Layout::checkEvents()
372371
{
373372
Window::checkEvents();
374-
rect_t z = getMainZone();
373+
rect_t z = getWidgetsZone();
375374
if (z.x != lastMainZone.x || z.y != lastMainZone.y || z.w != lastMainZone.w || z.h != lastMainZone.h) {
376375
lastMainZone = z;
377-
for (int i = 0; i < zoneCount; i++)
378-
if (widgets[i] && widgets[i]->isFullscreen())
379-
return;
380-
updateZones();
376+
if (!hasFullScreenWidget())
377+
updateZones();
381378
}
382379
}
383380

radio/src/gui/colorlcd/mainview/layout.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@ class Layout: public WidgetsContainer
121121

122122
void removeWidget(unsigned int index) override;
123123

124+
bool hasFullScreenWidget() const;
125+
124126
protected:
125127
const LayoutFactory* factory = nullptr;
126128
ViewMainDecoration* decoration = nullptr;
@@ -134,7 +136,7 @@ class Layout: public WidgetsContainer
134136
uint32_t lastRefresh = 0;
135137

136138
// Get the available space for widgets
137-
rect_t getMainZone() const;
139+
rect_t getWidgetsZone() const;
138140

139141
unsigned int getZonesCount() const override { return zoneCount; }
140142
rect_t getZone(unsigned int index) const override;

radio/src/gui/colorlcd/mainview/view_main_decoration.cpp

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,17 +108,22 @@ static bool canTrimShow(int idx)
108108
return false;
109109
}
110110

111-
rect_t ViewMainDecoration::getMainZone() const
111+
rect_t ViewMainDecoration::getWidgetsZone(bool showTopBar) const
112112
{
113-
coord_t x = 0, w = width(), h = height();
113+
coord_t x = 0, y = 0, w = width(), h = height();
114114
coord_t bh = 0;
115115

116+
if (showTopBar) {
117+
y = EdgeTxStyles::MENU_HEADER_HEIGHT;
118+
bh = EdgeTxStyles::MENU_HEADER_HEIGHT;
119+
}
120+
116121
if (showSliders) {
117122
if (hasVerticalSliders) {
118123
x += MainViewSlider::SLIDER_BAR_SIZE;
119124
w -= 2 * MainViewSlider::SLIDER_BAR_SIZE;
120125
}
121-
bh = MainViewSlider::SLIDER_BAR_SIZE;
126+
bh += MainViewSlider::SLIDER_BAR_SIZE;
122127
}
123128

124129
if (showTrims) {
@@ -139,9 +144,16 @@ rect_t ViewMainDecoration::getMainZone() const
139144
bh -= MainViewSlider::SLIDER_BAR_SIZE;
140145
}
141146

147+
if (showSliders || showTrims || showFM) {
148+
x += PAD_LARGE;
149+
y += PAD_LARGE;
150+
w -= PAD_LARGE * 2;
151+
bh += PAD_LARGE * 2;
152+
}
153+
142154
h -= bh;
143155

144-
return rect_t{x, 0, w, h};
156+
return rect_t{x, y, w, h};
145157
}
146158

147159
void ViewMainDecoration::createSliders(Window* ml, Window* mr, Window* bl, Window* bc, Window* br)

radio/src/gui/colorlcd/mainview/view_main_decoration.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class ViewMainDecoration : public Window
3737

3838
// Get the available space in the middle of the screen
3939
// (without decoration)
40-
rect_t getMainZone() const;
40+
rect_t getWidgetsZone(bool showTopBar) const;
4141

4242
protected:
4343
enum {

radio/src/gui/colorlcd/mainview/widget.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,8 @@ void Widget::setFullscreen(bool enable)
212212
fullscreen = enable;
213213

214214
// Show or hide ViewMain widgets and decorations
215-
Messaging::send(Messaging::DECORATION_UPDATE);
216215
ViewMain::instance()->show(!enable);
216+
Messaging::send(Messaging::DECORATION_UPDATE);
217217

218218
// Leave Fullscreen Mode
219219
if (!enable) {

radio/src/gui/colorlcd/widgets/gauge.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ class GaugeWidget : public Widget
8282

8383
void update() override
8484
{
85-
if (!loaded) return;
85+
if (!loaded || _deleted) return;
8686

8787
auto widgetData = getPersistentData();
8888

@@ -107,7 +107,7 @@ class GaugeWidget : public Widget
107107

108108
void foreground() override
109109
{
110-
if (!loaded) return;
110+
if (!loaded || _deleted) return;
111111

112112
auto newValue = getGuageValue();
113113
if (lastValue != newValue) {

radio/src/gui/colorlcd/widgets/modelbmp.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class ModelBitmapWidget : public Widget
5555

5656
void foreground() override
5757
{
58-
if (!loaded) return;
58+
if (!loaded || _deleted) return;
5959

6060
if (getHash() != deps_hash) {
6161
update();
@@ -68,7 +68,7 @@ class ModelBitmapWidget : public Widget
6868

6969
void update() override
7070
{
71-
if (!loaded) return;
71+
if (!loaded || _deleted) return;
7272

7373
auto widgetData = getPersistentData();
7474

radio/src/gui/colorlcd/widgets/outputs.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ class ChannelValue : public Window
9999

100100
void refresh()
101101
{
102-
if (!loaded) return;
102+
if (!loaded || _deleted) return;
103103

104104
int16_t value = channelOutputs[channel];
105105

0 commit comments

Comments
 (0)