Open3D (C++ API)  0.13.0
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
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) 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 
31 namespace open3d {
32 namespace visualization {
33 namespace gui {
34 
35 struct 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 
60 class Layout1D : public Widget {
61  using Super = Widget;
62 
63 public:
64  enum Dir { VERT, HORIZ };
65 
66  static void debug_PrintPreferredSizes(Layout1D* layout,
67  const LayoutContext& context,
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 
88  Size CalcPreferredSize(const LayoutContext& context,
89  const Constraints& constraints) const override;
90  void Layout(const LayoutContext& context) override;
91 
93  void AddFixed(int size);
98  void AddStretch();
99 
100 public:
101  class Fixed : public Widget {
102  public:
103  Fixed(int size, Dir dir);
104  Size CalcPreferredSize(const LayoutContext& context,
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 
117 protected:
118  int GetMinorAxisPreferredSize() const;
119  void SetMinorAxisPreferredSize(int size);
120 
121  Margins& GetMutableMargins();
122 
123 private:
124  struct Impl;
125  std::unique_ptr<Impl> impl_;
126 };
127 
129 class Vert : public Layout1D {
130 public:
131  static std::shared_ptr<Layout1D::Fixed> MakeFixed(int size);
132  static std::shared_ptr<Layout1D::Stretch> MakeStretch();
133 
134  Vert();
137  Vert(int spacing, const Margins& margins = Margins());
138  Vert(int spacing,
139  const Margins& margins,
140  const std::vector<std::shared_ptr<Widget>>& children);
141  virtual ~Vert();
142 
143  int GetPreferredWidth() const;
144  void SetPreferredWidth(int w);
145 };
146 
150 class CollapsableVert : public Vert {
151  using Super = Vert;
152 
153 public:
154  CollapsableVert(const char* text);
155  CollapsableVert(const char* text,
156  int spacing,
157  const Margins& margins = Margins());
158  virtual ~CollapsableVert();
159 
164  void SetIsOpen(bool is_open);
165 
167  bool GetIsOpen();
168 
169  FontId GetFontId() const;
170  void SetFontId(FontId font_id);
171 
172  Size CalcPreferredSize(const LayoutContext& context,
173  const Constraints& constraints) const override;
174  void Layout(const LayoutContext& context) override;
175  Widget::DrawResult Draw(const DrawContext& context) override;
176 
177 private:
178  struct Impl;
179  std::unique_ptr<Impl> impl_;
180 };
181 
183 class ScrollableVert : public Vert {
184  using Super = Vert;
185 
186 public:
187  ScrollableVert();
188  ScrollableVert(int spacing, const Margins& margins = Margins());
189  ScrollableVert(int spacing,
190  const Margins& margins,
191  const std::vector<std::shared_ptr<Widget>>& children);
192  virtual ~ScrollableVert();
193 
194  Widget::DrawResult Draw(const DrawContext& context) override;
195 
196 private:
197  struct Impl;
198  std::unique_ptr<Impl> impl_;
199 };
200 
202 class Horiz : public Layout1D {
203 public:
204  static std::shared_ptr<Layout1D::Fixed> MakeFixed(int size);
205  static std::shared_ptr<Layout1D::Stretch> MakeStretch();
206  static std::shared_ptr<Horiz> MakeCentered(std::shared_ptr<Widget> w);
207 
208  Horiz();
211  Horiz(int spacing, const Margins& margins = Margins());
212  Horiz(int spacing,
213  const Margins& margins,
214  const std::vector<std::shared_ptr<Widget>>& children);
215  ~Horiz();
216 
217  int GetPreferredHeight() const;
218  void SetPreferredHeight(int h);
219 };
220 
224 class VGrid : public Widget {
225  using Super = Widget;
226 
227 public:
228  VGrid(int num_cols, int spacing = 0, const Margins& margins = Margins());
229  virtual ~VGrid();
230 
231  int GetSpacing() const;
232  const Margins& GetMargins() const;
233 
234  int GetPreferredWidth() const;
235  void SetPreferredWidth(int w);
236 
237  Size CalcPreferredSize(const LayoutContext& context,
238  const Constraints& constraints) const override;
239  void Layout(const LayoutContext& context) override;
240 
241 private:
242  struct Impl;
243  std::unique_ptr<Impl> impl_;
244 };
245 
246 } // namespace gui
247 } // namespace visualization
248 } // namespace open3d
void Draw(const std::vector< std::shared_ptr< geometry::Geometry3D >> &geometries, const std::string &window_name, int width, int height, const std::vector< DrawAction > &actions)
Definition: Draw.cpp:63
Lays out widgets vertically.
Definition: Layout.h:129
Definition: Widget.h:68
This a vertical layout that scrolls if it is smaller than its contents.
Definition: Layout.h:183
unsigned int FontId
Definition: Gui.h:87
ImGuiContext * context
Definition: Window.cpp:95
int size
Definition: FilePCD.cpp:59
int GetVert() const
Convenience function that returns top + bottom.
Definition: Layout.cpp:139
Definition: Layout.h:224
int GetHoriz() const
Convenience function that returns left + right.
Definition: Layout.cpp:137
Definition: PinholeCameraIntrinsic.cpp:35
int right
Definition: Layout.h:38
Margins()
Definition: Layout.cpp:130
int top
Definition: Layout.h:37
Lays out widgets horizontally.
Definition: Layout.h:202
int left
Definition: Layout.h:36
int bottom
Definition: Layout.h:39
DrawResult
Definition: Widget.h:114
Definition: Layout.cpp:567