Open3D (C++ API)  0.18.0+3975044
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 
10 #include <string>
11 
13 
14 namespace open3d {
15 namespace visualization {
16 namespace gui {
17 
18 struct Margins {
19  int left;
20  int top;
21  int right;
22  int bottom;
23 
30  Margins(); // all values zero
31  Margins(int px);
32  Margins(int horiz_px, int vert_px);
33  Margins(int left_px, int top_px, int right_px, int bottom_px);
34 
36  int GetHoriz() const;
38  int GetVert() const;
39 };
40 
43 class Layout1D : public Widget {
44  using Super = Widget;
45 
46 public:
47  enum Dir { VERT, HORIZ };
48 
49  static void debug_PrintPreferredSizes(Layout1D* layout,
50  const LayoutContext& context,
51  const Constraints& constraints,
52  int depth = 0);
53 
56  Layout1D(Dir dir,
57  int spacing,
58  const Margins& margins,
59  const std::vector<std::shared_ptr<Widget>>& children);
60  virtual ~Layout1D();
61 
62  int GetSpacing() const;
63  const Margins& GetMargins() const;
66  void SetSpacing(int spacing);
69  void SetMargins(const Margins& margins);
70 
72  const Constraints& constraints) const override;
73  void Layout(const LayoutContext& context) override;
74 
76  void AddFixed(int size);
81  void AddStretch();
82 
83 public:
84  class Fixed : public Widget {
85  public:
86  Fixed(int size, Dir dir);
88  const Constraints& constraints) const override;
89 
90  private:
91  int size_;
92  Dir dir_;
93  };
94 
95  class Stretch : public Widget {
96  Size CalcPreferredSize(const LayoutContext& context,
97  const Constraints& constraints) const override;
98  };
99 
100 protected:
101  int GetMinorAxisPreferredSize() const;
103 
105  std::vector<std::shared_ptr<Widget>> GetVisibleChildren() const;
106 
107 private:
108  struct Impl;
109  std::unique_ptr<Impl> impl_;
110 };
111 
113 class Vert : public Layout1D {
114 public:
115  static std::shared_ptr<Layout1D::Fixed> MakeFixed(int size);
116  static std::shared_ptr<Layout1D::Stretch> MakeStretch();
117 
118  Vert();
121  Vert(int spacing, const Margins& margins = Margins());
122  Vert(int spacing,
123  const Margins& margins,
124  const std::vector<std::shared_ptr<Widget>>& children);
125  virtual ~Vert();
126 
127  int GetPreferredWidth() const;
128  void SetPreferredWidth(int w);
129 };
130 
134 class CollapsableVert : public Vert {
135  using Super = Vert;
136 
137 public:
138  CollapsableVert(const char* text);
139  CollapsableVert(const char* text,
140  int spacing,
141  const Margins& margins = Margins());
142  virtual ~CollapsableVert();
143 
148  void SetIsOpen(bool is_open);
149 
151  bool GetIsOpen();
152 
153  void SetText(const char* text);
154  std::string GetText() const;
155 
156  FontId GetFontId() const;
157  void SetFontId(FontId font_id);
158 
160  const Constraints& constraints) const override;
161  void Layout(const LayoutContext& context) override;
162  Widget::DrawResult Draw(const DrawContext& context) override;
163 
164 private:
165  struct Impl;
166  std::unique_ptr<Impl> impl_;
167 };
168 
170 class ScrollableVert : public Vert {
171  using Super = Vert;
172 
173 public:
174  ScrollableVert();
175  ScrollableVert(int spacing, const Margins& margins = Margins());
176  ScrollableVert(int spacing,
177  const Margins& margins,
178  const std::vector<std::shared_ptr<Widget>>& children);
179  virtual ~ScrollableVert();
180 
181  Widget::DrawResult Draw(const DrawContext& context) override;
182 
183 private:
184  struct Impl;
185  std::unique_ptr<Impl> impl_;
186 };
187 
189 class Horiz : public Layout1D {
190 public:
191  static std::shared_ptr<Layout1D::Fixed> MakeFixed(int size);
192  static std::shared_ptr<Layout1D::Stretch> MakeStretch();
193  static std::shared_ptr<Horiz> MakeCentered(std::shared_ptr<Widget> w);
194 
195  Horiz();
198  Horiz(int spacing, const Margins& margins = Margins());
199  Horiz(int spacing,
200  const Margins& margins,
201  const std::vector<std::shared_ptr<Widget>>& children);
202  ~Horiz();
203 
204  int GetPreferredHeight() const;
205  void SetPreferredHeight(int h);
206 };
207 
211 class VGrid : public Widget {
212  using Super = Widget;
213 
214 public:
215  VGrid(int num_cols, int spacing = 0, const Margins& margins = Margins());
216  virtual ~VGrid();
217 
218  int GetSpacing() const;
219  const Margins& GetMargins() const;
220 
221  int GetPreferredWidth() const;
222  void SetPreferredWidth(int w);
223 
225  const Constraints& constraints) const override;
226  void Layout(const LayoutContext& context) override;
227 
228 private:
229  struct Impl;
230  std::unique_ptr<Impl> impl_;
231 };
232 
233 } // namespace gui
234 } // namespace visualization
235 } // namespace open3d
ImGuiContext * context
Definition: Window.cpp:76
void SetText(const char *text)
Definition: Layout.cpp:398
FontId GetFontId() const
Definition: Layout.cpp:407
CollapsableVert(const char *text)
Definition: Layout.cpp:382
void SetFontId(FontId font_id)
Definition: Layout.cpp:409
virtual ~CollapsableVert()
Definition: Layout.cpp:392
bool GetIsOpen()
Returns true if open and false if collapsed.
Definition: Layout.cpp:396
void Layout(const LayoutContext &context) override
Definition: Layout.cpp:435
Size CalcPreferredSize(const LayoutContext &context, const Constraints &constraints) const override
Definition: Layout.cpp:411
void SetIsOpen(bool is_open)
Definition: Layout.cpp:394
std::string GetText() const
Definition: Layout.cpp:405
Widget::DrawResult Draw(const DrawContext &context) override
Definition: Layout.cpp:450
Lays out widgets horizontally.
Definition: Layout.h:189
static std::shared_ptr< Horiz > MakeCentered(std::shared_ptr< Widget > w)
Definition: Layout.cpp:539
int GetPreferredHeight() const
Definition: Layout.cpp:558
Horiz()
Definition: Layout.cpp:546
void SetPreferredHeight(int h)
Definition: Layout.cpp:559
static std::shared_ptr< Layout1D::Stretch > MakeStretch()
Definition: Layout.cpp:535
~Horiz()
Definition: Layout.cpp:556
static std::shared_ptr< Layout1D::Fixed > MakeFixed(int size)
Definition: Layout.cpp:531
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:47
@ HORIZ
Definition: Layout.h:47
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:170
Widget::DrawResult Draw(const DrawContext &context) override
Definition: Layout.cpp:510
ScrollableVert()
Definition: Layout.cpp:493
virtual ~ScrollableVert()
Definition: Layout.cpp:508
Definition: Layout.h:211
virtual ~VGrid()
Definition: Layout.cpp:578
Size CalcPreferredSize(const LayoutContext &context, const Constraints &constraints) const override
Definition: Layout.cpp:586
VGrid(int num_cols, int spacing=0, const Margins &margins=Margins())
Definition: Layout.cpp:569
const Margins & GetMargins() const
Definition: Layout.cpp:581
void Layout(const LayoutContext &context) override
Definition: Layout.cpp:611
void SetPreferredWidth(int w)
Definition: Layout.cpp:584
int GetSpacing() const
Definition: Layout.cpp:580
int GetPreferredWidth() const
Definition: Layout.cpp:583
Lays out widgets vertically.
Definition: Layout.h:113
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:21
int bottom
Definition: Layout.h:22
int GetVert() const
Convenience function that returns top + bottom.
Definition: Layout.cpp:120
Margins()
Definition: Layout.cpp:111
int left
Definition: Layout.h:19
int top
Definition: Layout.h:20
int GetHoriz() const
Convenience function that returns left + right.
Definition: Layout.cpp:118
Definition: Layout.cpp:562