Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: make wake calculator collapsible #554

Merged
merged 1 commit into from
Feb 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
feat: make wake calculator collapsible
AndyTWF committed Feb 25, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 88869ac1e211741b5b2fd2b9345ea779619f9d01
45 changes: 31 additions & 14 deletions src/plugin/wake/WakeCalculatorDisplay.cpp
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@
#include "WakeCalculatorOptions.h"
#include "WakeIntervalFormatter.h"
#include "components/ClickableArea.h"
#include "components/TitleBar.h"
#include "components/CollapsibleWindowTitleBar.h"
#include "euroscope/EuroscopePluginLoopbackInterface.h"
#include "euroscope/EuroscopeRadarLoopbackInterface.h"
#include "euroscope/UserSetting.h"
@@ -27,11 +27,11 @@ namespace UKControllerPlugin::Wake {
int screenObjectId)
: options(std::move(options)), leadCallsignSelector(std::move(leadCallsignSelector)),
followCallsignSelector(std::move(followCallsignSelector)), wakeSchemeSelector(std::move(wakeSchemeSelector)),
plugin(plugin), screenObjectId(screenObjectId),
titleBar(Components::TitleBar::Create(L"Wake Turbulence Calculator", TitleBarArea())
->WithDrag(this->screenObjectId)
->WithDefaultBackgroundBrush()
->WithDefaultTextBrush()),
plugin(plugin), titleBar(Components::CollapsibleWindowTitleBar::Create(
L"Wake Turbulence Calculator",
TitleBarArea(),
[this]() -> bool { return this->contentCollapsed; },
screenObjectId)),
backgroundBrush(std::make_shared<Gdiplus::SolidBrush>(BACKGROUND_COLOUR)),
textBrush(std::make_shared<Gdiplus::SolidBrush>(TEXT_COLOUR)),
resultBrush(std::make_shared<Gdiplus::SolidBrush>(RESULT_COLOUR)),
@@ -86,6 +86,11 @@ namespace UKControllerPlugin::Wake {
options->FollowingAircraft("");
return;
}

if (objectDescription == "collapseButton") {
this->contentCollapsed = !this->contentCollapsed;
return;
}
}

void WakeCalculatorDisplay::Move(RECT position, std::string objectDescription)
@@ -138,14 +143,19 @@ namespace UKControllerPlugin::Wake {
Windows::GdiGraphicsInterface& graphics, Euroscope::EuroscopeRadarLoopbackInterface& radarScreen)
{
graphics.Translated(windowPosition.x, windowPosition.y, [&graphics, &radarScreen, this]() {
graphics.FillRect(this->contentArea, *backgroundBrush);
this->RenderScheme(graphics, radarScreen);
this->RenderIntermediate(graphics, radarScreen);
this->RenderMode(graphics, radarScreen);
this->RenderLead(graphics, radarScreen);
this->RenderFollowing(graphics, radarScreen);
this->RenderDividingLine(graphics);
this->RenderSeparationRequirement(graphics);
// Draw the content if not collapsed
if (!this->contentCollapsed) {
graphics.FillRect(this->contentArea, *backgroundBrush);
this->RenderScheme(graphics, radarScreen);
this->RenderIntermediate(graphics, radarScreen);
this->RenderMode(graphics, radarScreen);
this->RenderLead(graphics, radarScreen);
this->RenderFollowing(graphics, radarScreen);
this->RenderDividingLine(graphics);
this->RenderSeparationRequirement(graphics);
}

// Do title bar, so it's always on top.
titleBar->Draw(graphics, radarScreen);
});
}
@@ -164,13 +174,15 @@ namespace UKControllerPlugin::Wake {
0},
"");
this->visible = userSetting.GetBooleanEntry(ASR_KEY_VISIBILITY, false);
this->contentCollapsed = userSetting.GetBooleanEntry(ASR_KEY_COLLAPSED, false);
}

void WakeCalculatorDisplay::AsrClosingEvent(Euroscope::UserSetting& userSetting)
{
userSetting.Save(ASR_KEY_X_POS, ASR_DESCRIPTION_X_POS, windowPosition.x);
userSetting.Save(ASR_KEY_Y_POS, ASR_DESCRIPTION_Y_POS, windowPosition.y);
userSetting.Save(ASR_KEY_VISIBILITY, ASR_DESCRIPTION_VISIBILITY, visible);
userSetting.Save(ASR_KEY_COLLAPSED, ASR_DESCRIPTION_COLLAPSED, contentCollapsed);
}

auto WakeCalculatorDisplay::TitleBarArea() -> Gdiplus::Rect
@@ -361,4 +373,9 @@ namespace UKControllerPlugin::Wake {
{
this->visible = !this->visible;
}

auto WakeCalculatorDisplay::IsCollapsed() const -> bool
{
return this->contentCollapsed;
}
} // namespace UKControllerPlugin::Wake
9 changes: 6 additions & 3 deletions src/plugin/wake/WakeCalculatorDisplay.h
Original file line number Diff line number Diff line change
@@ -34,6 +34,7 @@ namespace UKControllerPlugin::Wake {
Euroscope::EuroscopePluginLoopbackInterface& plugin,
int screenObjectId);
[[nodiscard]] auto IsVisible() const -> bool override;
[[nodiscard]] auto IsCollapsed() const -> bool;
void LeftClick(
Euroscope::EuroscopeRadarLoopbackInterface& radarScreen,
int objectId,
@@ -91,9 +92,6 @@ namespace UKControllerPlugin::Wake {
// For getting flightplans
Euroscope::EuroscopePluginLoopbackInterface& plugin;

// The screen object id for click
const int screenObjectId;

// The titlebar
std::shared_ptr<Components::TitleBar> titleBar;

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

// Visibility
bool visible = false;

// Content collapsed
bool contentCollapsed = false;
};
} // namespace UKControllerPlugin::Wake
38 changes: 34 additions & 4 deletions test/plugin/wake/WakeCalculatorDisplayTest.cpp
Original file line number Diff line number Diff line change
@@ -45,6 +45,15 @@ namespace UKControllerPluginTest::Wake {
EXPECT_FALSE(display.IsVisible());
}

TEST_F(WakeCalculatorDisplayTest, ItCanBeCollapsedByClickButton)
{
EXPECT_FALSE(display.IsCollapsed());
display.LeftClick(radarScreen, 1, "collapseButton", {1, 2}, {});
EXPECT_TRUE(display.IsCollapsed());
display.LeftClick(radarScreen, 1, "collapseButton", {1, 2}, {});
EXPECT_FALSE(display.IsCollapsed());
}

TEST_F(WakeCalculatorDisplayTest, ItHasADefaultPosition)
{
const auto position = display.Position();
@@ -71,7 +80,7 @@ namespace UKControllerPluginTest::Wake {

TEST_F(WakeCalculatorDisplayTest, AsrLoadingLoadsPosition)
{
EXPECT_CALL(mockAsrProvider, GetKey(testing::_)).Times(1).WillRepeatedly(testing::Return(""));
EXPECT_CALL(mockAsrProvider, GetKey(testing::_)).Times(2).WillRepeatedly(testing::Return(""));

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

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

TEST_F(WakeCalculatorDisplayTest, AsrLoadingLoadsVisibility)
{
EXPECT_CALL(mockAsrProvider, GetKey(testing::_)).Times(2).WillRepeatedly(testing::Return(""));
EXPECT_CALL(mockAsrProvider, GetKey(testing::_)).Times(3).WillRepeatedly(testing::Return(""));

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

display.AsrLoadedEvent(userSettings);
EXPECT_TRUE(display.IsVisible());
}

TEST_F(WakeCalculatorDisplayTest, AsrLoadingLoadsCollapsed)
{
EXPECT_CALL(mockAsrProvider, GetKey(testing::_)).Times(3).WillRepeatedly(testing::Return(""));

EXPECT_CALL(mockAsrProvider, GetKey("wakeCalculatorCollapsed")).Times(1).WillOnce(testing::Return("1"));

display.AsrLoadedEvent(userSettings);
EXPECT_TRUE(display.IsCollapsed());
}

TEST_F(WakeCalculatorDisplayTest, AsrLoadingLoadsDefaultPosition)
{
display.Move({300, 400, 500, 600}, "");
EXPECT_CALL(mockAsrProvider, GetKey(testing::_)).Times(1).WillRepeatedly(testing::Return(""));
EXPECT_CALL(mockAsrProvider, GetKey(testing::_)).Times(2).WillRepeatedly(testing::Return(""));
EXPECT_CALL(mockAsrProvider, GetKey("wakeCalculatorXPosition")).Times(1).WillOnce(testing::Return(""));
EXPECT_CALL(mockAsrProvider, GetKey("wakeCalculatorYPosition")).Times(1).WillOnce(testing::Return(""));

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

display.AsrLoadedEvent(userSettings);
EXPECT_FALSE(display.IsVisible());
}

TEST_F(WakeCalculatorDisplayTest, AsrLoadingLoadsDefaultCollapsed)
{
display.Toggle();
EXPECT_CALL(mockAsrProvider, GetKey(testing::_)).Times(3).WillRepeatedly(testing::Return(""));
EXPECT_CALL(mockAsrProvider, GetKey("wakeCalculatorCollapsed")).Times(1).WillOnce(testing::Return(""));

display.AsrLoadedEvent(userSettings);
EXPECT_FALSE(display.IsCollapsed());
}

TEST_F(WakeCalculatorDisplayTest, AsrClosingSavesFields)
{
display.Toggle();
display.Move({300, 400, 500, 600}, "");
EXPECT_CALL(mockAsrProvider, SetKey("wakeCalculatorVisibility", "Wake Calculator Visibility", "1")).Times(1);
EXPECT_CALL(mockAsrProvider, SetKey("wakeCalculatorXPosition", "Wake Calculator X Position", "300")).Times(1);
EXPECT_CALL(mockAsrProvider, SetKey("wakeCalculatorYPosition", "Wake Calculator Y Position", "400")).Times(1);
EXPECT_CALL(mockAsrProvider, SetKey("wakeCalculatorCollapsed", "Wake Calculator Collapsed", "0")).Times(1);

display.AsrClosingEvent(userSettings);
}