MeshLib C++ Docs
Loading...
Searching...
No Matches
MR::UI::RectAllocator Class Reference

#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)
 

Detailed Description

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.

Member Typedef Documentation

◆ FindPotentiallyOverlappingRects

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.

Constructor & Destructor Documentation

◆ RectAllocator()

MRVIEWER_API MR::UI::RectAllocator::RectAllocator ( )

Member Function Documentation

◆ findFreeRect()

MRVIEWER_API FindFreeRectResult MR::UI::RectAllocator::findFreeRect ( Box2f preferredRect,
Box2f preferredBounds,
FindPotentiallyOverlappingRects findOverlaps,
ImVec2 axisWeights = ImVec2(1, 1) )
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.

Parameters
preferredBoundsThe 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.
findOverlapsGiven any rect, this must return all existing rects potentially overlapping with it.
axisWeightsThis sets the preference for X and Y axes. Larger number = less likely to shift over that axis.

◆ rectRectOverlap()

static bool MR::UI::RectAllocator::rectRectOverlap ( Box2f a,
Box2f b )
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.


The documentation for this class was generated from the following file: