10[[nodiscard]]
static std::optional<float> adjustWindowPositionForResizedViewPort(
11 float oldViewPortSize,
float newViewPortSize,
float relWindowPos,
float windowSize)
14 if (newViewPortSize < windowSize)
return {};
17 float windowEndPos = relWindowPos + windowSize;
18 float distanceToLeft = relWindowPos;
19 float distanceToRight = oldViewPortSize - windowEndPos;
21 if (distanceToLeft < distanceToRight) {
23 float newDistanceToLeft = distanceToLeft;
24 float newWindowPos = newDistanceToLeft;
25 float newWindowEndPos = newWindowPos + windowSize;
26 float newDistanceToRight = newViewPortSize - newWindowEndPos;
29 if (newDistanceToLeft > newDistanceToRight) {
31 newWindowPos = (newViewPortSize - windowSize) * 0.5f;
35 float newDistanceToRight = distanceToRight;
36 float newWidowEndPos = newViewPortSize - newDistanceToRight;
37 float newWindowPos = newWidowEndPos - windowSize;
38 float newDistanceToLeft = newWindowPos;
39 if (newDistanceToRight > newDistanceToLeft) {
40 newWindowPos = (newViewPortSize - windowSize) * 0.5f;
48 if (setMainViewPort) {
49 setMainViewPort =
false;
50 const auto* mainViewPort = ImGui::GetMainViewport();
51 ImGui::SetNextWindowViewport(mainViewPort->ID);
57 const auto* mainViewPort = ImGui::GetMainViewport();
58 const auto* windowViewPort = ImGui::GetWindowViewport();
59 bool isOnMainViewPort = windowViewPort == mainViewPort;
60 gl::vec2 newViewPortSize = mainViewPort->Size;
61 gl::vec2 mainViewPortPos = mainViewPort->Pos;
64 if (oldIsOnMainViewPort && (oldViewPortSize != newViewPortSize)) {
65 gl::vec2 windowSize = ImGui::GetWindowSize();
66 if (!isOnMainViewPort) {
71 setMainViewPort =
true;
72 isOnMainViewPort =
true;
73 relWindowPos = oldRelWindowPos;
75 auto newPosX = adjustWindowPositionForResizedViewPort(
76 oldViewPortSize.x, newViewPortSize.x, relWindowPos.x, windowSize.x);
77 auto newPosY = adjustWindowPositionForResizedViewPort(
78 oldViewPortSize.y, newViewPortSize.y, relWindowPos.y, windowSize.y);
79 if (newPosX && newPosY) {
80 relWindowPos =
gl::vec2{*newPosX, *newPosY};
81 ImGui::SetWindowPos(mainViewPortPos + relWindowPos);
86 oldViewPortSize = newViewPortSize;
87 oldRelWindowPos = relWindowPos;
88 oldIsOnMainViewPort = isOnMainViewPort;
90 return isOnMainViewPort;
bool loadLine(std::string_view name, zstring_view value)
void save(ImGuiTextBuffer &buf)
Like std::string_view, but with the extra guarantee that it refers to a zero-terminated string.
This file implemented 3 utility functions:
bool loadOnePersistent(std::string_view name, zstring_view value, C &c, const std::tuple< Elements... > &tup)
void savePersistent(ImGuiTextBuffer &buf, C &c, const std::tuple< Elements... > &tup)