Repository navigation
Expand file tree
/
Copy pathview_tests.cpp
More file actions
52 lines (46 loc) · 1.73 KB
/
Copy pathview_tests.cpp
File metadata and controls
52 lines (46 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
//------------------------------------------------------------------------------
// The view: where navigation takes it, and the grid drawn under it.
//------------------------------------------------------------------------------
# include "harness.h"
# include <cmath>
namespace {
// Vertices in the color of the grid at zoom 1.
int GridVertices(const ImDrawList* drawList)
{
const ImU32 color = ImGui::ColorConvertFloat4ToU32(ed::GetStyle().Colors[ed::StyleColor_Grid]);
int count = 0;
for (auto& vertex : drawList->VtxBuffer)
if (vertex.col == color)
++count;
return count;
}
} // namespace
TEST_CASE(GridAtTinyZoom, "view.grid_at_tiny_zoom_is_bounded", "CORE-10", test::TestFlags_None)
{
auto content = [](int)
{
ed::BeginNode(1);
ImGui::TextUnformatted("Node");
ed::EndNode();
};
{
test::Storage storage;
test::Session session(&storage);
session.Frame(content);
session.Frame(content);
const int gridVertices = session.Use([&] { return GridVertices(session.DrawList); });
test::Check(gridVertices > 0, "grid drawn at zoom 1: %d vertices", gridVertices);
}
// Zoom levels down to 1e-6, where the view is 10^9 units across.
test::Storage storage;
storage.Global = R"({"view":{"scroll":{"x":0,"y":0},"zoom":0.000001}})";
auto config = test::MakeConfig(&storage);
config.CustomZoomLevels.push_back(1e-6f);
config.CustomZoomLevels.push_back(1.0f);
test::Session session(config);
session.Settings = &storage;
for (int i = 0; i < 3; ++i)
session.Frame(content);
const float zoom = session.Use([] { return test::CurrentZoom(); });
test::Check(zoom < 1e-5f, "view zoomed out to %g", zoom);
}