Open3D (C++ API)  0.11.0
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 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 Theme& theme,
68  int depth = 0);
69 
72  Layout1D(Dir dir,
73  int spacing,
74  const Margins& margins,
75  const std::vector<std::shared_ptr<Widget>>& children);
76  virtual ~Layout1D();
77 
78  int GetSpacing() const;
79  const Margins& GetMargins() const;
82  void SetSpacing(int spacing);
85  void SetMargins(const Margins& margins);
86 
87  Size CalcPreferredSize(const Theme& theme) const override;
88  void Layout(const Theme& theme) override;
89 
91  void AddFixed(int size);
96  void AddStretch();
97 
98 public:
99  class Fixed : public Widget {
100  public:
101  Fixed(int size, Dir dir);
102  Size CalcPreferredSize(const Theme& theme) const override;
103 
104  private:
105  int size_;
106  Dir dir_;
107  };
108 
109  class Stretch : public Widget {
110  Size CalcPreferredSize(const Theme& theme) const override;
111  };
112 
113 protected:
114  Margins& GetMutableMargins();
115 
116 private:
117  struct Impl;
118  std::unique_ptr<Impl> impl_;
119 };
120 
122 class Vert : public Layout1D {
123 public:
124  static std::shared_ptr<Layout1D::Fixed> MakeFixed(int size);
125  static std::shared_ptr<Layout1D::Stretch> MakeStretch();
126 
127  Vert();
130  Vert(int spacing, const Margins& margins = Margins());
131  Vert(int spacing,
132  const Margins& margins,
133  const std::vector<std::shared_ptr<Widget>>& children);
134  virtual ~Vert();
135 };
136 
140 class CollapsableVert : public Vert {
141  using Super = Vert;
142 
143 public:
144  CollapsableVert(const char* text);
145  CollapsableVert(const char* text,
146  int spacing,
147  const Margins& margins = Margins());
148  virtual ~CollapsableVert();
149 
154  void SetIsOpen(bool is_open);
155 
156  Size CalcPreferredSize(const Theme& theme) const override;
157  void Layout(const Theme& theme) override;
158  Widget::DrawResult Draw(const DrawContext& context) override;
159 
160 private:
161  struct Impl;
162  std::unique_ptr<Impl> impl_;
163 };
164 
166 class Horiz : public Layout1D {
167 public:
168  static std::shared_ptr<Layout1D::Fixed> MakeFixed(int size);
169  static std::shared_ptr<Layout1D::Stretch> MakeStretch();
170  static std::shared_ptr<Horiz> MakeCentered(std::shared_ptr<Widget> w);
171 
172  Horiz();
175  Horiz(int spacing, const Margins& margins = Margins());
176  Horiz(int spacing,
177  const Margins& margins,
178  const std::vector<std::shared_ptr<Widget>>& children);
179  ~Horiz();
180 };
181 
185 class VGrid : public Widget {
186  using Super = Widget;
187 
188 public:
189  VGrid(int num_cols, int spacing = 0, const Margins& margins = Margins());
190  virtual ~VGrid();
191 
192  int GetSpacing() const;
193  const Margins& GetMargins() const;
194 
195  Size CalcPreferredSize(const Theme& theme) const override;
196  void Layout(const Theme& theme) override;
197 
198 private:
199  struct Impl;
200  std::unique_ptr<Impl> impl_;
201 };
202 
203 } // namespace gui
204 } // namespace visualization
205 } // namespace open3d
Definition: Theme.h:39
Lays out widgets vertically.
Definition: Layout.h:122
Definition: Widget.h:62
int size
Definition: FilePCD.cpp:59
int GetVert() const
Convenience function that returns top + bottom.
Definition: Layout.cpp:136
Definition: Layout.h:185
int GetHoriz() const
Convenience function that returns left + right.
Definition: Layout.cpp:134
Definition: PinholeCameraIntrinsic.cpp:35
int right
Definition: Layout.h:38
Margins()
Definition: Layout.cpp:127
int top
Definition: Layout.h:37
Lays out widgets horizontally.
Definition: Layout.h:166
int left
Definition: Layout.h:36
int bottom
Definition: Layout.h:39
DrawResult
Definition: Widget.h:98
Definition: Layout.cpp:457