diff options
Diffstat (limited to 'unity-shared')
| -rw-r--r-- | unity-shared/LayoutSystem.cpp | 38 | ||||
| -rw-r--r-- | unity-shared/LayoutSystem.h | 1 |
2 files changed, 39 insertions, 0 deletions
diff --git a/unity-shared/LayoutSystem.cpp b/unity-shared/LayoutSystem.cpp index f2ea8b87a..40a2a4485 100644 --- a/unity-shared/LayoutSystem.cpp +++ b/unity-shared/LayoutSystem.cpp @@ -35,6 +35,44 @@ void LayoutSystem::LayoutWindows(LayoutWindow::Vector const& windows, nux::Geome LayoutGridWindows(windows, max_bounds, final_bounds); } +void LayoutSystem::LayoutWindowsNearest(LayoutWindow::Vector& windows, nux::Geometry const& max_bounds, nux::Geometry& final_bounds) +{ + if (windows.empty()) + return; + + std::stable_sort(windows.begin(), windows.end(), + [](const LayoutWindow::Ptr& a, const LayoutWindow::Ptr& b) + { + int acentery = a->geo.y + a->geo.height / 2; + int bcentery = b->geo.y + b->geo.height / 2; + return acentery < bcentery; + }); + + LayoutGridWindows(windows, max_bounds, final_bounds); + + std::vector<LayoutWindow::Vector> rows = GetRows(windows, max_bounds); + LayoutWindow::Vector ordered_windows; + + for (auto row : rows) + { + std::stable_sort(row.begin(), row.end(), + [](const LayoutWindow::Ptr& a, const LayoutWindow::Ptr& b) + { + int acenterx = a->geo.x + a->geo.width / 2; + int bcenterx = b->geo.x + b->geo.width / 2; + return acenterx < bcenterx; + }); + + for (auto win : row) + { + ordered_windows.push_back(win); + } + } + + LayoutGridWindows(ordered_windows, max_bounds, final_bounds); + windows = ordered_windows; +} + nux::Size LayoutSystem::GridSizeForWindows(LayoutWindow::Vector const& windows, nux::Geometry const& max_bounds) const { unsigned count = windows.size(); diff --git a/unity-shared/LayoutSystem.h b/unity-shared/LayoutSystem.h index 6241f727c..9c1f7e04f 100644 --- a/unity-shared/LayoutSystem.h +++ b/unity-shared/LayoutSystem.h @@ -64,6 +64,7 @@ public: LayoutSystem(); void LayoutWindows(LayoutWindow::Vector const& windows, nux::Geometry const& max_bounds, nux::Geometry& final_bounds); + void LayoutWindowsNearest(LayoutWindow::Vector& windows, nux::Geometry const& max_bounds, nux::Geometry& final_bounds); std::vector<int> GetRowSizes(LayoutWindow::Vector const& windows, nux::Geometry const& max_bounds) const; protected: |
