Loading [MathJax]/extensions/TeX/AMSsymbols.js
Open3D (C++ API)  0.16.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) 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 
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  std::vector<std::shared_ptr<Widget>> GetVisibleChildren() const;
123 
124 private:
125  struct Impl;
126  std::unique_ptr<Impl> impl_;
127 };
128 
130 class Vert : public Layout1D {
131 public:
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 
151 class CollapsableVert : public Vert {
152  using Super = Vert;
153 
154 public:
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 
173  Size CalcPreferredSize(const LayoutContext& context,
174  const Constraints& constraints) const override;
175  void Layout(const LayoutContext& context) override;
176  Widget::DrawResult Draw(const DrawContext& context) override;
177 
178 private:
179  struct Impl;
180  std::unique_ptr<Impl> impl_;
181 };
182 
184 class ScrollableVert : public Vert {
185  using Super = Vert;
186 
187 public:
188  ScrollableVert();
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 
195  Widget::DrawResult Draw(const DrawContext& context) override;
196 
197 private:
198  struct Impl;
199  std::unique_ptr<Impl> impl_;
200 };
201 
203 class Horiz : public Layout1D {
204 public:
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 
225 class VGrid : public Widget {
226  using Super = Widget;
227 
228 public:
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 
238  Size CalcPreferredSize(const LayoutContext& context,
239  const Constraints& constraints) const override;
240  void Layout(const LayoutContext& context) override;
241 
242 private:
243  struct Impl;
244  std::unique_ptr<Impl> impl_;
245 };
246 
247 } // namespace gui
248 } // namespace visualization
249 } // 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:130
Definition: Widget.h:68
This a vertical layout that scrolls if it is smaller than its contents.
Definition: Layout.h:184
unsigned int FontId
Definition: Gui.h:87
ImGuiContext * context
Definition: Window.cpp:95
int GetVert() const
Convenience function that returns top + bottom.
Definition: Layout.cpp:139
Definition: Layout.h:225
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:203
int left
Definition: Layout.h:36
int bottom
Definition: Layout.h:39
DrawResult
Definition: Widget.h:114
int size
Definition: FilePCD.cpp:59
Definition: Layout.cpp:575