Open3D (C++ API)  0.18.0+252c867
Layout.h
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - Open3D: www.open3d.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2023 www.open3d.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
7 
8 #pragma once
9 
11 
12 namespace open3d {
13 namespace visualization {
14 namespace gui {
15 
16 struct Margins {
17  int left;
18  int top;
19  int right;
20  int bottom;
21 
28  Margins(); // all values zero
29  Margins(int px);
30  Margins(int horiz_px, int vert_px);
31  Margins(int left_px, int top_px, int right_px, int bottom_px);
32 
34  int GetHoriz() const;
36  int GetVert() const;
37 };
38 
41 class Layout1D : public Widget {
42  using Super = Widget;
43 
44 public:
45  enum Dir { VERT, HORIZ };
46 
47  static void debug_PrintPreferredSizes(Layout1D* layout,
48  const LayoutContext& context,
49  const Constraints& constraints,
50  int depth = 0);
51 
54  Layout1D(Dir dir,
55  int spacing,
56  const Margins& margins,
57  const std::vector<std::shared_ptr<Widget>>& children);
58  virtual ~Layout1D();
59 
60  int GetSpacing() const;
61  const Margins& GetMargins() const;
64  void SetSpacing(int spacing);
67  void SetMargins(const Margins& margins);
68 
70  const Constraints& constraints) const override;
71  void Layout(const LayoutContext& context) override;
72 
74  void AddFixed(int size);
79  void AddStretch();
80 
81 public:
82  class Fixed : public Widget {
83  public:
84  Fixed(int size, Dir dir);
86  const Constraints& constraints) const override;
87 
88  private:
89  int size_;
90  Dir dir_;
91  };
92 
93  class Stretch : public Widget {
94  Size CalcPreferredSize(const LayoutContext& context,
95  const Constraints& constraints) const override;
96  };
97 
98 protected:
99  int GetMinorAxisPreferredSize() const;
101 
103  std::vector<std::shared_ptr<Widget>> GetVisibleChildren() const;
104 
105 private:
106  struct Impl;
107  std::unique_ptr<Impl> impl_;
108 };
109 
111 class Vert : public Layout1D {
112 public:
113  static std::shared_ptr<Layout1D::Fixed> MakeFixed(int size);
114  static std::shared_ptr<Layout1D::Stretch> MakeStretch();
115 
116  Vert();
119  Vert(int spacing, const Margins& margins = Margins());
120  Vert(int spacing,
121  const Margins& margins,
122  const std::vector<std::shared_ptr<Widget>>& children);
123  virtual ~Vert();
124 
125  int GetPreferredWidth() const;
126  void SetPreferredWidth(int w);
127 };
128 
132 class CollapsableVert : public Vert {
133  using Super = Vert;
134 
135 public:
136  CollapsableVert(const char* text);
137  CollapsableVert(const char* text,
138  int spacing,
139  const Margins& margins = Margins());
140  virtual ~CollapsableVert();
141 
146  void SetIsOpen(bool is_open);
147 
149  bool GetIsOpen();
150 
151  FontId GetFontId() const;
152  void SetFontId(FontId font_id);
153 
155  const Constraints& constraints) const override;
156  void Layout(const LayoutContext& context) override;
157  Widget::DrawResult Draw(const DrawContext& context) override;
158 
159 private:
160  struct Impl;
161  std::unique_ptr<Impl> impl_;
162 };
163 
165 class ScrollableVert : public Vert {
166  using Super = Vert;
167 
168 public:
169  ScrollableVert();
170  ScrollableVert(int spacing, const Margins& margins = Margins());
171  ScrollableVert(int spacing,
172  const Margins& margins,
173  const std::vector<std::shared_ptr<Widget>>& children);
174  virtual ~ScrollableVert();
175 
176  Widget::DrawResult Draw(const DrawContext& context) override;
177 
178 private:
179  struct Impl;
180  std::unique_ptr<Impl> impl_;
181 };
182 
184 class Horiz : public Layout1D {
185 public:
186  static std::shared_ptr<Layout1D::Fixed> MakeFixed(int size);
187  static std::shared_ptr<Layout1D::Stretch> MakeStretch();
188  static std::shared_ptr<Horiz> MakeCentered(std::shared_ptr<Widget> w);
189 
190  Horiz();
193  Horiz(int spacing, const Margins& margins = Margins());
194  Horiz(int spacing,
195  const Margins& margins,
196  const std::vector<std::shared_ptr<Widget>>& children);
197  ~Horiz();
198 
199  int GetPreferredHeight() const;
200  void SetPreferredHeight(int h);
201 };
202 
206 class VGrid : public Widget {
207  using Super = Widget;
208 
209 public:
210  VGrid(int num_cols, int spacing = 0, const Margins& margins = Margins());
211  virtual ~VGrid();
212 
213  int GetSpacing() const;
214  const Margins& GetMargins() const;
215 
216  int GetPreferredWidth() const;
217  void SetPreferredWidth(int w);
218 
220  const Constraints& constraints) const override;
221  void Layout(const LayoutContext& context) override;
222 
223 private:
224  struct Impl;
225  std::unique_ptr<Impl> impl_;
226 };
227 
228 } // namespace gui
229 } // namespace visualization
230 } // namespace open3d
ImGuiContext * context
Definition: Window.cpp:76
FontId GetFontId() const
Definition: Layout.cpp:401
CollapsableVert(const char *text)
Definition: Layout.cpp:382
void SetFontId(FontId font_id)
Definition: Layout.cpp:403
virtual ~CollapsableVert()
Definition: Layout.cpp:395
bool GetIsOpen()
Returns true if open and false if collapsed.
Definition: Layout.cpp:399
void Layout(const LayoutContext &context) override
Definition: Layout.cpp:429
Size CalcPreferredSize(const LayoutContext &context, const Constraints &constraints) const override
Definition: Layout.cpp:405
void SetIsOpen(bool is_open)
Definition: Layout.cpp:397
Widget::DrawResult Draw(const DrawContext &context) override
Definition: Layout.cpp:444
Lays out widgets horizontally.
Definition: Layout.h:184
static std::shared_ptr< Horiz > MakeCentered(std::shared_ptr< Widget > w)
Definition: Layout.cpp:533
int GetPreferredHeight() const
Definition: Layout.cpp:552
Horiz()
Definition: Layout.cpp:540
void SetPreferredHeight(int h)
Definition: Layout.cpp:553
static std::shared_ptr< Layout1D::Stretch > MakeStretch()
Definition: Layout.cpp:529
~Horiz()
Definition: Layout.cpp:550
static std::shared_ptr< Layout1D::Fixed > MakeFixed(int size)
Definition: Layout.cpp:525
Fixed(int size, Dir dir)
Definition: Layout.cpp:177
Size CalcPreferredSize(const LayoutContext &context, const Constraints &constraints) const override
Definition: Layout.cpp:179
const Margins & GetMargins() const
Definition: Layout.cpp:206
int GetSpacing() const
Definition: Layout.cpp:205
Layout1D(Dir dir, int spacing, const Margins &margins, const std::vector< std::shared_ptr< Widget >> &children)
Definition: Layout.cpp:193
void SetMargins(const Margins &margins)
Definition: Layout.cpp:218
static void debug_PrintPreferredSizes(Layout1D *layout, const LayoutContext &context, const Constraints &constraints, int depth=0)
Definition: Layout.cpp:130
Margins & GetMutableMargins()
Definition: Layout.cpp:207
Size CalcPreferredSize(const LayoutContext &context, const Constraints &constraints) const override
Definition: Layout.cpp:234
void AddStretch()
Definition: Layout.cpp:232
void SetSpacing(int spacing)
Definition: Layout.cpp:217
virtual ~Layout1D()
Definition: Layout.cpp:203
@ VERT
Definition: Layout.h:45
@ HORIZ
Definition: Layout.h:45
void Layout(const LayoutContext &context) override
Definition: Layout.cpp:258
std::vector< std::shared_ptr< Widget > > GetVisibleChildren() const
Definition: Layout.cpp:208
void SetMinorAxisPreferredSize(int size)
Definition: Layout.cpp:228
void AddFixed(int size)
Adds a fixed number of pixels after the previously added widget.
Definition: Layout.cpp:220
int GetMinorAxisPreferredSize() const
Definition: Layout.cpp:224
This a vertical layout that scrolls if it is smaller than its contents.
Definition: Layout.h:165
Widget::DrawResult Draw(const DrawContext &context) override
Definition: Layout.cpp:504
ScrollableVert()
Definition: Layout.cpp:487
virtual ~ScrollableVert()
Definition: Layout.cpp:502
Definition: Layout.h:206
virtual ~VGrid()
Definition: Layout.cpp:572
Size CalcPreferredSize(const LayoutContext &context, const Constraints &constraints) const override
Definition: Layout.cpp:580
VGrid(int num_cols, int spacing=0, const Margins &margins=Margins())
Definition: Layout.cpp:563
const Margins & GetMargins() const
Definition: Layout.cpp:575
void Layout(const LayoutContext &context) override
Definition: Layout.cpp:605
void SetPreferredWidth(int w)
Definition: Layout.cpp:578
int GetSpacing() const
Definition: Layout.cpp:574
int GetPreferredWidth() const
Definition: Layout.cpp:577
Lays out widgets vertically.
Definition: Layout.h:111
static std::shared_ptr< Layout1D::Stretch > MakeStretch()
Definition: Layout.cpp:355
Vert()
Definition: Layout.cpp:359
static std::shared_ptr< Layout1D::Fixed > MakeFixed(int size)
Definition: Layout.cpp:351
void SetPreferredWidth(int w)
Definition: Layout.cpp:372
int GetPreferredWidth() const
Definition: Layout.cpp:371
virtual ~Vert()
Definition: Layout.cpp:369
Definition: Widget.h:49
Widget()
Definition: Widget.cpp:34
DrawResult
Definition: Widget.h:95
int size
Definition: FilePCD.cpp:40
unsigned int FontId
Definition: Gui.h:68
Definition: PinholeCameraIntrinsic.cpp:16
int right
Definition: Layout.h:19
int bottom
Definition: Layout.h:20
int GetVert() const
Convenience function that returns top + bottom.
Definition: Layout.cpp:120
Margins()
Definition: Layout.cpp:111
int left
Definition: Layout.h:17
int top
Definition: Layout.h:18
int GetHoriz() const
Convenience function that returns left + right.
Definition: Layout.cpp:118
Definition: Layout.cpp:556