Rise
The Vieneo Province
Loading...
Searching...
No Matches
Tests/DialogLayoutTests.cpp

Source at documentation-generation time. See Test catalog for fixture associations.

1#include "../Dialogs/DialogLayout.h"
2#include <cmath>
3#include <cstdlib>
4#include <iostream>
5
6namespace
7{
8 void Check(bool condition, const char* message)
9 {
10 if (!condition) { std::cerr << "FAIL: " << message << '\n'; std::exit(1); }
11 }
12
13 bool Near(float a, float b) { return std::fabs(a - b) < 0.01f; }
14
16 {
18 sizes[DialogLayout::People] = {0, 0, 764, 184};
19 sizes[DialogLayout::Waypoints] = {0, 0, 767, 189};
20 sizes[DialogLayout::Players] = {0, 0, 129, 152};
21 sizes[DialogLayout::Biometer] = {0, 0, 170, 152};
22 sizes[DialogLayout::Intermedia] = {0, 0, 259, 152};
23 sizes[DialogLayout::Information] = {0, 0, 256, 232};
24 sizes[DialogLayout::Configuration] = {0, 0, 640, 568};
25 sizes[DialogLayout::Communications] = {0, 0, 843, 168};
26 sizes[DialogLayout::ExternalCamera] = {0, 0, 544, 152};
27 return sizes;
28 }
29}
30
31int main()
32{
34 DialogLayout::ReferenceHeight, Sizes(), 232);
35 const float expectedX[] = {138, 139, 1149, 133, 1281, 712, 136, 306, 1538};
36 const float expectedY[] = {1018, 1015, 16, 16, 16, 429, 317, 0, 16};
37 for (int id = 0; id < DialogLayout::Count; ++id)
38 {
39 Check(Near(reference[id].x, expectedX[id]) && Near(reference[id].y, expectedY[id]),
40 "reference layout matches saved positions to the displayed pixel");
41 }
42
43 const auto fullHd = DialogLayout::Defaults(1920, 1080, Sizes(), 232);
44 Check(fullHd[DialogLayout::Communications].width < 843, "narrow Communications first");
45 Check(Near(fullHd[DialogLayout::ExternalCamera].y, 16), "keep one row when shrinking chat is sufficient");
46 Check(Near(fullHd[DialogLayout::ExternalCamera].x + 544, 1920), "fit the complete top row");
47
48 const auto compact = DialogLayout::Defaults(1366, 768, Sizes(), 232);
49 Check(compact[DialogLayout::ExternalCamera].y > compact[DialogLayout::Intermedia].y + 152,
50 "wrap Camera below the first row when chat reaches its minimum");
51 Check(Near(compact[DialogLayout::People].y + 184 - 768,
52 reference[DialogLayout::People].y + 184 - DialogLayout::ReferenceHeight), "preserve bottom margin");
53
54 for (const auto screen : {std::array<float, 3>{3440, 1351, 1.1f}, {1920, 1080, 1},
55 {2560, 1440, 1.5f}, {3840, 2160, 2}, {1366, 768, 1}, {800, 600, 1}})
56 {
57 const float width = screen[0] / screen[2], height = screen[1] / screen[2];
58 const auto layout = DialogLayout::Defaults(width, height, Sizes(), 232);
59 for (const auto& panel : layout)
60 Check(panel.x >= 0 && panel.y >= 0 && panel.x + panel.width <= width + 0.01f &&
61 panel.y + panel.height <= height + 0.01f, "panels remain inside the scaled viewport");
62 Check(Near(layout[DialogLayout::Players].x, layout[DialogLayout::Communications].x + layout[DialogLayout::Communications].width) &&
63 Near(layout[DialogLayout::Players].y, layout[DialogLayout::Communications].y + 16), "Players remains docked");
64 }
65 const auto largeText = DialogLayout::Defaults(1366, 768, Sizes(), 440);
66 Check(largeText[DialogLayout::Communications].width >= 440, "respect localized title and tab minimum width");
67 std::cout << "PASS: saved layout, chat shrink/wrap, docking, bottom anchors, resolution and UI scaling\n";
68}
constexpr float ReferenceHeight
Layout Defaults(float width, float height, Layout panels, float minimumChatWidth)
std::array< Panel, Count > Layout
constexpr float ReferenceWidth
bool Near(const Body &b, const Triangle &t, double extra)
Definition RigidProp.h:141