MeshLib C++ Docs
Loading...
Searching...
No Matches
MRUIRectAllocator.h
Go to the documentation of this file.
1#pragma once
2
3#include "exports.h"
4#include "MRMesh/MRBox.h"
5#include "MRMesh/MRphmap.h"
6#include "MRMesh/MRVector2.h"
8#include "MRImGui.h"
9
10namespace MR::UI
11{
12
19{
20public:
21 MRVIEWER_API RectAllocator();
22
24 {
25 Box2f rect;
26 bool ok = true;
27 [[nodiscard]] explicit operator bool() const { return ok; }
28 };
29
32 using FindPotentiallyOverlappingRects = std::function<void( Box2f target, std::function<void( const char* name, Box2f box )> overlaps )>;
33
36 [[nodiscard]] MRVIEWER_API FindFreeRectResult findFreeRect(
37 Box2f preferredRect,
40 Box2f preferredBounds,
44 ImVec2 axisWeights = ImVec2( 1, 1 )
45 );
46
49 [[nodiscard]] static bool rectRectOverlap( Box2f a, Box2f b )
50 {
51 return a.max.x > b.min.x && a.min.x < b.max.x && a.max.y > b.min.y && a.min.y < b.max.y;
52 }
53
54private:
56 phmap::flat_hash_map<Vector2f, float> visitedCoords;
57
58 struct CoordsToVisit
59 {
60 Vector2f pos;
61 float cost = 0;
62 std::array<float, 4> overlapWithBounds;
63 };
64 std::vector<CoordsToVisit> coordsToVisitHeap;
65};
66
69{
70public:
76 MRVIEWER_API void setFreeNextWindowPos( const char* expectedWindowName, ImVec2 defaultPos, ImGuiCond cond = ImGuiCond_Appearing, ImVec2 pivot = ImVec2() );
77
79 MRVIEWER_API void invalidateClosedWindows();
80private:
81 enum class AllocationState
82 {
83 None,
84 Requested,
85 WaitAppearing,
86 Set
87 };
88
89 struct WindowEntry
90 {
91 AllocationState state_{ AllocationState::None };
92 };
93 phmap::flat_hash_map<std::string, WindowEntry> windows_;
94};
96
99{
100public:
105 MRVIEWER_API ImVec2 createRect( ViewportId viewportId, std::string id, ImVec2 pos, ImVec2 size, bool forceExactPosition = false );
106
107private:
108 int lastFrameCount_ = -1;
109
110 struct Entry
111 {
112 Box2f box;
113 bool visitedThisFrame = true;
114 };
116 std::vector<phmap::flat_hash_map<std::string, Entry>> entries_;
117};
119
120}
A rect allocator for labels.
Definition MRUIRectAllocator.h:99
MRVIEWER_API ImVec2 createRect(ViewportId viewportId, std::string id, ImVec2 pos, ImVec2 size, bool forceExactPosition=false)
Definition MRUIRectAllocator.h:19
std::function< void(Box2f target, std::function< void(const char *name, Box2f box)> overlaps)> FindPotentiallyOverlappingRects
Definition MRUIRectAllocator.h:32
MRVIEWER_API RectAllocator()
static bool rectRectOverlap(Box2f a, Box2f b)
Definition MRUIRectAllocator.h:49
MRVIEWER_API FindFreeRectResult findFreeRect(Box2f preferredRect, Box2f preferredBounds, FindPotentiallyOverlappingRects findOverlaps, ImVec2 axisWeights=ImVec2(1, 1))
A rect allocator specifically for ImGui windows.
Definition MRUIRectAllocator.h:69
MRVIEWER_API void setFreeNextWindowPos(const char *expectedWindowName, ImVec2 defaultPos, ImGuiCond cond=ImGuiCond_Appearing, ImVec2 pivot=ImVec2())
MRVIEWER_API void invalidateClosedWindows()
Call this once at the begining of ImGui frame, to remove all closed windows from entries list.
Definition MRViewportId.h:16
ImVec2 size(const ViewportRectangle &rect)
Definition MRViewport.h:32
@ None
special value not to limit path in one slice
Definition MRVoxelPath.h:33
Definition MRUINonOverlappingLabels.h:10
MRVIEWER_API WindowRectAllocator & getDefaultWindowRectAllocator()
MRVIEWER_API LabelRectAllocator & getDefaultLabelRectAllocator()
Definition MRUIRectAllocator.h:24
bool ok
Definition MRUIRectAllocator.h:26
Box2f rect
Definition MRUIRectAllocator.h:25