#include <MRUIRectAllocator.h>
Inheritance diagram for MR::UI::RectAllocator:Classes | |
| struct | FindFreeRectResult |
Public Types | |
| using | FindPotentiallyOverlappingRects = std::function<void( Box2f target, std::function<void( const char* name, Box2f box )> overlaps )> |
Public Member Functions | |
| MRVIEWER_API | RectAllocator () |
| MRVIEWER_API FindFreeRectResult | findFreeRect (Box2f preferredRect, Box2f preferredBounds, FindPotentiallyOverlappingRects findOverlaps, ImVec2 axisWeights=ImVec2(1, 1)) |
Static Public Member Functions | |
| static bool | rectRectOverlap (Box2f a, Box2f b) |
A generic rect allocator. Given a set of rects and a target rect, finds the closest free rect next to the target (using dijkstra's algorithm). The class can be reused multiple times to avoid repeated heap allocation, it doesn't store any state other than memory pools. For optimal results you should bring your own AABB tree (see FindPotentiallyOverlappingRects) below, but in simple cases you can get away with a flat list.
| using MR::UI::RectAllocator::FindPotentiallyOverlappingRects = std::function<void( Box2f target, std::function<void( const char* name, Box2f box )> overlaps )> |
Given an input rect, this function must find all POTENTIALLY overlapping rects ("overlapping" means according to rectRectOverlap()). name is only useful for debugging.
| MRVIEWER_API MR::UI::RectAllocator::RectAllocator | ( | ) |
|
nodiscard |
Finds a free rectangle of the specified size, as close as possible to the specified position. On failure, returns .ok == false and returns the input rect unchanged.
| preferredBounds | The outer bounds that we try to fit the rect into. The input rect doesn't need to be in bounds, but we will not move it more out of bounds than it already is. |
| findOverlaps | Given any rect, this must return all existing rects potentially overlapping with it. |
| axisWeights | This sets the preference for X and Y axes. Larger number = less likely to shift over that axis. |
|
inlinestaticnodiscard |
Checks if two rects overlap. We can't use .intersects() here because we want .max to be exclusive, while .intersects() treats both bounds as inclusive.