Skip to content

Commit 1c0a18d

Browse files
author
Andy Ford
authored
Merge pull request #554 from AndyTWF/collapsible-wake-calculator
feat: make wake calculator collapsible
2 parents 12d0f04 + 88869ac commit 1c0a18d

File tree

3 files changed

+71
-21
lines changed

3 files changed

+71
-21
lines changed

src/plugin/wake/WakeCalculatorDisplay.cpp

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#include "WakeCalculatorOptions.h"
77
#include "WakeIntervalFormatter.h"
88
#include "components/ClickableArea.h"
9-
#include "components/TitleBar.h"
9+
#include "components/CollapsibleWindowTitleBar.h"
1010
#include "euroscope/EuroscopePluginLoopbackInterface.h"
1111
#include "euroscope/EuroscopeRadarLoopbackInterface.h"
1212
#include "euroscope/UserSetting.h"
@@ -27,11 +27,11 @@ namespace UKControllerPlugin::Wake {
2727
int screenObjectId)
2828
: options(std::move(options)), leadCallsignSelector(std::move(leadCallsignSelector)),
2929
followCallsignSelector(std::move(followCallsignSelector)), wakeSchemeSelector(std::move(wakeSchemeSelector)),
30-
plugin(plugin), screenObjectId(screenObjectId),
31-
titleBar(Components::TitleBar::Create(L"Wake Turbulence Calculator", TitleBarArea())
32-
->WithDrag(this->screenObjectId)
33-
->WithDefaultBackgroundBrush()
34-
->WithDefaultTextBrush()),
30+
plugin(plugin), titleBar(Components::CollapsibleWindowTitleBar::Create(
31+
L"Wake Turbulence Calculator",
32+
TitleBarArea(),
33+
[this]() -> bool { return this->contentCollapsed; },
34+
screenObjectId)),
3535
backgroundBrush(std::make_shared<Gdiplus::SolidBrush>(BACKGROUND_COLOUR)),
3636
textBrush(std::make_shared<Gdiplus::SolidBrush>(TEXT_COLOUR)),
3737
resultBrush(std::make_shared<Gdiplus::SolidBrush>(RESULT_COLOUR)),
@@ -86,6 +86,11 @@ namespace UKControllerPlugin::Wake {
8686
options->FollowingAircraft("");
8787
return;
8888
}
89+
90+
if (objectDescription == "collapseButton") {
91+
this->contentCollapsed = !this->contentCollapsed;
92+
return;
93+
}
8994
}
9095

9196
void WakeCalculatorDisplay::Move(RECT position, std::string objectDescription)
@@ -138,14 +143,19 @@ namespace UKControllerPlugin::Wake {
138143
Windows::GdiGraphicsInterface& graphics, Euroscope::EuroscopeRadarLoopbackInterface& radarScreen)
139144
{
140145
graphics.Translated(windowPosition.x, windowPosition.y, [&graphics, &radarScreen, this]() {
141-
graphics.FillRect(this->contentArea, *backgroundBrush);
142-
this->RenderScheme(graphics, radarScreen);
143-
this->RenderIntermediate(graphics, radarScreen);
144-
this->RenderMode(graphics, radarScreen);
145-
this->RenderLead(graphics, radarScreen);
146-
this->RenderFollowing(graphics, radarScreen);
147-
this->RenderDividingLine(graphics);
148-
this->RenderSeparationRequirement(graphics);
146+
// Draw the content if not collapsed
147+
if (!this->contentCollapsed) {
148+
graphics.FillRect(this->contentArea, *backgroundBrush);
149+
this->RenderScheme(graphics, radarScreen);
150+
this->RenderIntermediate(graphics, radarScreen);
151+
this->RenderMode(graphics, radarScreen);
152+
this->RenderLead(graphics, radarScreen);
153+
this->RenderFollowing(graphics, radarScreen);
154+
this->RenderDividingLine(graphics);
155+
this->RenderSeparationRequirement(graphics);
156+
}
157+
158+
// Do title bar, so it's always on top.
149159
titleBar->Draw(graphics, radarScreen);
150160
});
151161
}
@@ -164,13 +174,15 @@ namespace UKControllerPlugin::Wake {
164174
0},
165175
"");
166176
this->visible = userSetting.GetBooleanEntry(ASR_KEY_VISIBILITY, false);
177+
this->contentCollapsed = userSetting.GetBooleanEntry(ASR_KEY_COLLAPSED, false);
167178
}
168179

169180
void WakeCalculatorDisplay::AsrClosingEvent(Euroscope::UserSetting& userSetting)
170181
{
171182
userSetting.Save(ASR_KEY_X_POS, ASR_DESCRIPTION_X_POS, windowPosition.x);
172183
userSetting.Save(ASR_KEY_Y_POS, ASR_DESCRIPTION_Y_POS, windowPosition.y);
173184
userSetting.Save(ASR_KEY_VISIBILITY, ASR_DESCRIPTION_VISIBILITY, visible);
185+
userSetting.Save(ASR_KEY_COLLAPSED, ASR_DESCRIPTION_COLLAPSED, contentCollapsed);
174186
}
175187

176188
auto WakeCalculatorDisplay::TitleBarArea() -> Gdiplus::Rect
@@ -361,4 +373,9 @@ namespace UKControllerPlugin::Wake {
361373
{
362374
this->visible = !this->visible;
363375
}
376+
377+
auto WakeCalculatorDisplay::IsCollapsed() const -> bool
378+
{
379+
return this->contentCollapsed;
380+
}
364381
} // namespace UKControllerPlugin::Wake

src/plugin/wake/WakeCalculatorDisplay.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ namespace UKControllerPlugin::Wake {
3434
Euroscope::EuroscopePluginLoopbackInterface& plugin,
3535
int screenObjectId);
3636
[[nodiscard]] auto IsVisible() const -> bool override;
37+
[[nodiscard]] auto IsCollapsed() const -> bool;
3738
void LeftClick(
3839
Euroscope::EuroscopeRadarLoopbackInterface& radarScreen,
3940
int objectId,
@@ -91,9 +92,6 @@ namespace UKControllerPlugin::Wake {
9192
// For getting flightplans
9293
Euroscope::EuroscopePluginLoopbackInterface& plugin;
9394

94-
// The screen object id for click
95-
const int screenObjectId;
96-
9795
// The titlebar
9896
std::shared_ptr<Components::TitleBar> titleBar;
9997

@@ -137,8 +135,13 @@ namespace UKControllerPlugin::Wake {
137135
const std::string ASR_DESCRIPTION_X_POS = "Wake Calculator X Position";
138136
const std::string ASR_KEY_Y_POS = "wakeCalculatorYPosition";
139137
const std::string ASR_DESCRIPTION_Y_POS = "Wake Calculator Y Position";
138+
const std::string ASR_KEY_COLLAPSED = "wakeCalculatorCollapsed";
139+
const std::string ASR_DESCRIPTION_COLLAPSED = "Wake Calculator Collapsed";
140140

141141
// Visibility
142142
bool visible = false;
143+
144+
// Content collapsed
145+
bool contentCollapsed = false;
143146
};
144147
} // namespace UKControllerPlugin::Wake

test/plugin/wake/WakeCalculatorDisplayTest.cpp

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,15 @@ namespace UKControllerPluginTest::Wake {
4545
EXPECT_FALSE(display.IsVisible());
4646
}
4747

48+
TEST_F(WakeCalculatorDisplayTest, ItCanBeCollapsedByClickButton)
49+
{
50+
EXPECT_FALSE(display.IsCollapsed());
51+
display.LeftClick(radarScreen, 1, "collapseButton", {1, 2}, {});
52+
EXPECT_TRUE(display.IsCollapsed());
53+
display.LeftClick(radarScreen, 1, "collapseButton", {1, 2}, {});
54+
EXPECT_FALSE(display.IsCollapsed());
55+
}
56+
4857
TEST_F(WakeCalculatorDisplayTest, ItHasADefaultPosition)
4958
{
5059
const auto position = display.Position();
@@ -71,7 +80,7 @@ namespace UKControllerPluginTest::Wake {
7180

7281
TEST_F(WakeCalculatorDisplayTest, AsrLoadingLoadsPosition)
7382
{
74-
EXPECT_CALL(mockAsrProvider, GetKey(testing::_)).Times(1).WillRepeatedly(testing::Return(""));
83+
EXPECT_CALL(mockAsrProvider, GetKey(testing::_)).Times(2).WillRepeatedly(testing::Return(""));
7584

7685
EXPECT_CALL(mockAsrProvider, GetKey("wakeCalculatorXPosition")).Times(1).WillOnce(testing::Return("250"));
7786

@@ -85,18 +94,28 @@ namespace UKControllerPluginTest::Wake {
8594

8695
TEST_F(WakeCalculatorDisplayTest, AsrLoadingLoadsVisibility)
8796
{
88-
EXPECT_CALL(mockAsrProvider, GetKey(testing::_)).Times(2).WillRepeatedly(testing::Return(""));
97+
EXPECT_CALL(mockAsrProvider, GetKey(testing::_)).Times(3).WillRepeatedly(testing::Return(""));
8998

9099
EXPECT_CALL(mockAsrProvider, GetKey("wakeCalculatorVisibility")).Times(1).WillOnce(testing::Return("1"));
91100

92101
display.AsrLoadedEvent(userSettings);
93102
EXPECT_TRUE(display.IsVisible());
94103
}
95104

105+
TEST_F(WakeCalculatorDisplayTest, AsrLoadingLoadsCollapsed)
106+
{
107+
EXPECT_CALL(mockAsrProvider, GetKey(testing::_)).Times(3).WillRepeatedly(testing::Return(""));
108+
109+
EXPECT_CALL(mockAsrProvider, GetKey("wakeCalculatorCollapsed")).Times(1).WillOnce(testing::Return("1"));
110+
111+
display.AsrLoadedEvent(userSettings);
112+
EXPECT_TRUE(display.IsCollapsed());
113+
}
114+
96115
TEST_F(WakeCalculatorDisplayTest, AsrLoadingLoadsDefaultPosition)
97116
{
98117
display.Move({300, 400, 500, 600}, "");
99-
EXPECT_CALL(mockAsrProvider, GetKey(testing::_)).Times(1).WillRepeatedly(testing::Return(""));
118+
EXPECT_CALL(mockAsrProvider, GetKey(testing::_)).Times(2).WillRepeatedly(testing::Return(""));
100119
EXPECT_CALL(mockAsrProvider, GetKey("wakeCalculatorXPosition")).Times(1).WillOnce(testing::Return(""));
101120
EXPECT_CALL(mockAsrProvider, GetKey("wakeCalculatorYPosition")).Times(1).WillOnce(testing::Return(""));
102121

@@ -109,20 +128,31 @@ namespace UKControllerPluginTest::Wake {
109128
TEST_F(WakeCalculatorDisplayTest, AsrLoadingLoadsDefaultVisibility)
110129
{
111130
display.Toggle();
112-
EXPECT_CALL(mockAsrProvider, GetKey(testing::_)).Times(2).WillRepeatedly(testing::Return(""));
131+
EXPECT_CALL(mockAsrProvider, GetKey(testing::_)).Times(3).WillRepeatedly(testing::Return(""));
113132
EXPECT_CALL(mockAsrProvider, GetKey("wakeCalculatorVisibility")).Times(1).WillOnce(testing::Return(""));
114133

115134
display.AsrLoadedEvent(userSettings);
116135
EXPECT_FALSE(display.IsVisible());
117136
}
118137

138+
TEST_F(WakeCalculatorDisplayTest, AsrLoadingLoadsDefaultCollapsed)
139+
{
140+
display.Toggle();
141+
EXPECT_CALL(mockAsrProvider, GetKey(testing::_)).Times(3).WillRepeatedly(testing::Return(""));
142+
EXPECT_CALL(mockAsrProvider, GetKey("wakeCalculatorCollapsed")).Times(1).WillOnce(testing::Return(""));
143+
144+
display.AsrLoadedEvent(userSettings);
145+
EXPECT_FALSE(display.IsCollapsed());
146+
}
147+
119148
TEST_F(WakeCalculatorDisplayTest, AsrClosingSavesFields)
120149
{
121150
display.Toggle();
122151
display.Move({300, 400, 500, 600}, "");
123152
EXPECT_CALL(mockAsrProvider, SetKey("wakeCalculatorVisibility", "Wake Calculator Visibility", "1")).Times(1);
124153
EXPECT_CALL(mockAsrProvider, SetKey("wakeCalculatorXPosition", "Wake Calculator X Position", "300")).Times(1);
125154
EXPECT_CALL(mockAsrProvider, SetKey("wakeCalculatorYPosition", "Wake Calculator Y Position", "400")).Times(1);
155+
EXPECT_CALL(mockAsrProvider, SetKey("wakeCalculatorCollapsed", "Wake Calculator Collapsed", "0")).Times(1);
126156

127157
display.AsrClosingEvent(userSettings);
128158
}

0 commit comments

Comments
 (0)