Open3D (C++ API)  0.15.1
Layout.h
Go to the documentation of this file.
1// ----------------------------------------------------------------------------
2// - Open3D: www.open3d.org -
3// ----------------------------------------------------------------------------
4// The MIT License (MIT)
5//
6// Copyright (c) 2018-2021 www.open3d.org
7//
8// Permission is hereby granted, free of charge, to any person obtaining a copy
9// of this software and associated documentation files (the "Software"), to deal
10// in the Software without restriction, including without limitation the rights
11// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12// copies of the Software, and to permit persons to whom the Software is
13// furnished to do so, subject to the following conditions:
14//
15// The above copyright notice and this permission notice shall be included in
16// all copies or substantial portions of the Software.
17//
18// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24// IN THE SOFTWARE.
25// ----------------------------------------------------------------------------
26
27#pragma once
28
30
31namespace open3d {
32namespace visualization {
33namespace gui {
34
35struct Margins {
36 int left;
37 int top;
38 int right;
39 int bottom;
40
47 Margins(); // all values zero
48 Margins(int px);
49 Margins(int horiz_px, int vert_px);
50 Margins(int left_px, int top_px, int right_px, int bottom_px);
51
53 int GetHoriz() const;
55 int GetVert() const;
56};
57
60class Layout1D : public Widget {
61 using Super = Widget;
62
63public:
64 enum Dir { VERT, HORIZ };
65
66 static void debug_PrintPreferredSizes(Layout1D* layout,
68 const Constraints& constraints,
69 int depth = 0);
70
73 Layout1D(Dir dir,
74 int spacing,
75 const Margins& margins,
76 const std::vector<std::shared_ptr<Widget>>& children);
77 virtual ~Layout1D();
78
79 int GetSpacing() const;
80 const Margins& GetMargins() const;
83 void SetSpacing(int spacing);
86 void SetMargins(const Margins& margins);
87
89 const Constraints& constraints) const override;
90 void Layout(const LayoutContext& context) override;
91
93 void AddFixed(int size);
98 void AddStretch();
99
100public:
101 class Fixed : public Widget {
102 public:
103 Fixed(int size, Dir dir);
105 const Constraints& constraints) const override;
106
107 private:
108 int size_;
109 Dir dir_;
110 };
111
112 class Stretch : public Widget {
113 Size CalcPreferredSize(const LayoutContext& context,
114 const Constraints& constraints) const override;
115 };
116
117protected:
118 int GetMinorAxisPreferredSize() const;
120
122 std::vector<std::shared_ptr<Widget>> GetVisibleChildren() const;
123
124private:
125 struct Impl;
126 std::unique_ptr<Impl> impl_;
127};
128
130class Vert : public Layout1D {
131public:
132 static std::shared_ptr<Layout1D::Fixed> MakeFixed(int size);
133 static std::shared_ptr<Layout1D::Stretch> MakeStretch();
134
135 Vert();
138 Vert(int spacing, const Margins& margins = Margins());
139 Vert(int spacing,
140 const Margins& margins,
141 const std::vector<std::shared_ptr<Widget>>& children);
142 virtual ~Vert();
143
144 int GetPreferredWidth() const;
145 void SetPreferredWidth(int w);
146};
147
151class CollapsableVert : public Vert {
152 using Super = Vert;
153
154public:
155 CollapsableVert(const char* text);
156 CollapsableVert(const char* text,
157 int spacing,
158 const Margins& margins = Margins());
159 virtual ~CollapsableVert();
160
165 void SetIsOpen(bool is_open);
166
168 bool GetIsOpen();
169
170 FontId GetFontId() const;
171 void SetFontId(FontId font_id);
172
174 const Constraints& constraints) const override;
175 void Layout(const LayoutContext& context) override;
177
178private:
179 struct Impl;
180 std::unique_ptr<Impl> impl_;
181};
182
184class ScrollableVert : public Vert {
185 using Super = Vert;
186
187public:
189 ScrollableVert(int spacing, const Margins& margins = Margins());
190 ScrollableVert(int spacing,
191 const Margins& margins,
192 const std::vector<std::shared_ptr<Widget>>& children);
193 virtual ~ScrollableVert();
194
196
197private:
198 struct Impl;
199 std::unique_ptr<Impl> impl_;
200};
201
203class Horiz : public Layout1D {
204public:
205 static std::shared_ptr<Layout1D::Fixed> MakeFixed(int size);
206 static std::shared_ptr<Layout1D::Stretch> MakeStretch();
207 static std::shared_ptr<Horiz> MakeCentered(std::shared_ptr<Widget> w);
208
209 Horiz();
212 Horiz(int spacing, const Margins& margins = Margins());
213 Horiz(int spacing,
214 const Margins& margins,
215 const std::vector<std::shared_ptr<Widget>>& children);
216 ~Horiz();
217
218 int GetPreferredHeight() const;
219 void SetPreferredHeight(int h);
220};
221
225class VGrid : public Widget {
226 using Super = Widget;
227
228public:
229 VGrid(int num_cols, int spacing = 0, const Margins& margins = Margins());
230 virtual ~VGrid();
231
232 int GetSpacing() const;
233 const Margins& GetMargins() const;
234
235 int GetPreferredWidth() const;
236 void SetPreferredWidth(int w);
237
239 const Constraints& constraints) const override;
240 void Layout(const LayoutContext& context) override;
241
242private:
243 struct Impl;
244 std::unique_ptr<Impl> impl_;
245};
246
247} // namespace gui
248} // namespace visualization
249} // namespace open3d
ImGuiContext * context
Definition: Window.cpp:95
FontId GetFontId() const
Definition: Layout.cpp:420
CollapsableVert(const char *text)
Definition: Layout.cpp:401
void SetFontId(FontId font_id)
Definition: Layout.cpp:422
virtual ~CollapsableVert()
Definition: Layout.cpp:414
bool GetIsOpen()
Returns true if open and false if collapsed.
Definition: Layout.cpp:418
void Layout(const LayoutContext &context) override
Definition: Layout.cpp:448
Size CalcPreferredSize(const LayoutContext &context, const Constraints &constraints) const override
Definition: Layout.cpp:424
void SetIsOpen(bool is_open)
Definition: Layout.cpp:416
Widget::DrawResult Draw(const DrawContext &context) override
Definition: Layout.cpp:463
Lays out widgets horizontally.
Definition: Layout.h:203
static std::shared_ptr< Horiz > MakeCentered(std::shared_ptr< Widget > w)
Definition: Layout.cpp:552
int GetPreferredHeight() const
Definition: Layout.cpp:571
Horiz()
Definition: Layout.cpp:559
void SetPreferredHeight(int h)
Definition: Layout.cpp:572
static std::shared_ptr< Layout1D::Stretch > MakeStretch()
Definition: Layout.cpp:548
~Horiz()
Definition: Layout.cpp:569
static std::shared_ptr< Layout1D::Fixed > MakeFixed(int size)
Definition: Layout.cpp:544
Fixed(int size, Dir dir)
Definition: Layout.cpp:196
Size CalcPreferredSize(const LayoutContext &context, const Constraints &constraints) const override
Definition: Layout.cpp:198
const Margins & GetMargins() const
Definition: Layout.cpp:225
int GetSpacing() const
Definition: Layout.cpp:224
void SetMargins(const Margins &margins)
Definition: Layout.cpp:237
static void debug_PrintPreferredSizes(Layout1D *layout, const LayoutContext &context, const Constraints &constraints, int depth=0)
Definition: Layout.cpp:149
Margins & GetMutableMargins()
Definition: Layout.cpp:226
Size CalcPreferredSize(const LayoutContext &context, const Constraints &constraints) const override
Definition: Layout.cpp:253
void AddStretch()
Definition: Layout.cpp:251
void SetSpacing(int spacing)
Definition: Layout.cpp:236
Layout1D(Dir dir, int spacing, const Margins &margins, const std::vector< std::shared_ptr< Widget > > &children)
Definition: Layout.cpp:212
virtual ~Layout1D()
Definition: Layout.cpp:222
@ VERT
Definition: Layout.h:64
@ HORIZ
Definition: Layout.h:64
void Layout(const LayoutContext &context) override
Definition: Layout.cpp:277
std::vector< std::shared_ptr< Widget > > GetVisibleChildren() const
Definition: Layout.cpp:227
void SetMinorAxisPreferredSize(int size)
Definition: Layout.cpp:247
void AddFixed(int size)
Adds a fixed number of pixels after the previously added widget.
Definition: Layout.cpp:239
int GetMinorAxisPreferredSize() const
Definition: Layout.cpp:243
This a vertical layout that scrolls if it is smaller than its contents.
Definition: Layout.h:184
Widget::DrawResult Draw(const DrawContext &context) override
Definition: Layout.cpp:523
ScrollableVert()
Definition: Layout.cpp:506
virtual ~ScrollableVert()
Definition: Layout.cpp:521
Definition: Layout.h:225
virtual ~VGrid()
Definition: Layout.cpp:591
Size CalcPreferredSize(const LayoutContext &context, const Constraints &constraints) const override
Definition: Layout.cpp:599
VGrid(int num_cols, int spacing=0, const Margins &margins=Margins())
Definition: Layout.cpp:582
const Margins & GetMargins() const
Definition: Layout.cpp:594
void Layout(const LayoutContext &context) override
Definition: Layout.cpp:624
void SetPreferredWidth(int w)
Definition: Layout.cpp:597
int GetSpacing() const
Definition: Layout.cpp:593
int GetPreferredWidth() const
Definition: Layout.cpp:596
Lays out widgets vertically.
Definition: Layout.h:130
static std::shared_ptr< Layout1D::Stretch > MakeStretch()
Definition: Layout.cpp:374
Vert()
Definition: Layout.cpp:378
static std::shared_ptr< Layout1D::Fixed > MakeFixed(int size)
Definition: Layout.cpp:370
void SetPreferredWidth(int w)
Definition: Layout.cpp:391
int GetPreferredWidth() const
Definition: Layout.cpp:390
virtual ~Vert()
Definition: Layout.cpp:388
Definition: Widget.h:68
Widget()
Definition: Widget.cpp:53
DrawResult
Definition: Widget.h:114
int size
Definition: FilePCD.cpp:59
unsigned int FontId
Definition: Gui.h:87
Definition: PinholeCameraIntrinsic.cpp:35
int right
Definition: Layout.h:38
int bottom
Definition: Layout.h:39
int GetVert() const
Convenience function that returns top + bottom.
Definition: Layout.cpp:139
Margins()
Definition: Layout.cpp:130
int left
Definition: Layout.h:36
int top
Definition: Layout.h:37
int GetHoriz() const
Convenience function that returns left + right.
Definition: Layout.cpp:137
Definition: Layout.cpp:575