Open3D (C++ API)
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 
29 #include "Open3D/GUI/Widget.h"
30 
31 namespace open3d {
32 namespace gui {
33 
34 struct Margins {
35  int left;
36  int top;
37  int right;
38  int bottom;
39 
46  Margins(); // all values zero
47  Margins(int px);
48  Margins(int horiz_px, int vert_px);
49  Margins(int left_px, int top_px, int right_px, int bottom_px);
50 
52  int GetHoriz() const;
54  int GetVert() const;
55 };
56 
59 class Layout1D : public Widget {
60  using Super = Widget;
61 
62 public:
63  enum Dir { VERT, HORIZ };
64 
65  static void debug_PrintPreferredSizes(Layout1D* layout,
66  const Theme& theme,
67  int depth = 0);
68 
71  Layout1D(Dir dir,
72  int spacing,
73  const Margins& margins,
74  const std::vector<std::shared_ptr<Widget>>& children);
75  virtual ~Layout1D();
76 
77  int GetSpacing() const;
78  const Margins& GetMargins() const;
79 
80  Size CalcPreferredSize(const Theme& theme) const override;
81  void Layout(const Theme& theme) override;
82 
84  void AddFixed(int size);
89  void AddStretch();
90 
91 public:
92  class Fixed : public Widget {
93  public:
94  Fixed(int size, Dir dir);
95  Size CalcPreferredSize(const Theme& theme) const override;
96 
97  private:
98  int size_;
99  Dir dir_;
100  };
101 
102  class Stretch : public Widget {
103  Size CalcPreferredSize(const Theme& theme) const override;
104  };
105 
106 protected:
107  Margins& GetMutableMargins();
108 
109 private:
110  struct Impl;
111  std::unique_ptr<Impl> impl_;
112 };
113 
115 class Vert : public Layout1D {
116 public:
117  static std::shared_ptr<Layout1D::Fixed> MakeFixed(int size);
118  static std::shared_ptr<Layout1D::Stretch> MakeStretch();
119 
120  Vert();
123  Vert(int spacing, const Margins& margins = Margins());
124  Vert(int spacing,
125  const Margins& margins,
126  const std::vector<std::shared_ptr<Widget>>& children);
127  virtual ~Vert();
128 };
129 
133 class CollapsableVert : public Vert {
134  using Super = Vert;
135 
136 public:
137  CollapsableVert(const char* text);
138  CollapsableVert(const char* text,
139  int spacing,
140  const Margins& margins = Margins());
141  virtual ~CollapsableVert();
142 
147  void SetIsOpen(bool is_open);
148 
149  Size CalcPreferredSize(const Theme& theme) const override;
150  void Layout(const Theme& theme) override;
151  Widget::DrawResult Draw(const DrawContext& context) override;
152 
153 private:
154  struct Impl;
155  std::unique_ptr<Impl> impl_;
156 };
157 
159 class Horiz : public Layout1D {
160 public:
161  static std::shared_ptr<Layout1D::Fixed> MakeFixed(int size);
162  static std::shared_ptr<Layout1D::Stretch> MakeStretch();
163  static std::shared_ptr<Horiz> MakeCentered(std::shared_ptr<Widget> w);
164 
165  Horiz();
168  Horiz(int spacing, const Margins& margins = Margins());
169  Horiz(int spacing,
170  const Margins& margins,
171  const std::vector<std::shared_ptr<Widget>>& children);
172  ~Horiz();
173 };
174 
178 class VGrid : public Widget {
179  using Super = Widget;
180 
181 public:
182  VGrid(int num_cols, int spacing = 0, const Margins& margins = Margins());
183  virtual ~VGrid();
184 
185  int GetSpacing() const;
186  const Margins& GetMargins() const;
187 
188  Size CalcPreferredSize(const Theme& theme) const override;
189  void Layout(const Theme& theme) override;
190 
191 private:
192  struct Impl;
193  std::unique_ptr<Impl> impl_;
194 };
195 
196 } // namespace gui
197 } // namespace open3d
Dir
Definition: Layout.h:63
Definition: Layout.h:178
Margins()
Definition: Layout.cpp:125
Definition: Layout.cpp:330
Definition: Widget.cpp:42
int bottom
Definition: Layout.h:38
Definition: Gui.h:40
int left
Definition: Layout.h:35
Definition: Layout.h:102
int GetVert() const
Convenience function that returns top + bottom.
Definition: Layout.cpp:134
int size
Definition: FilePCD.cpp:57
Definition: Layout.cpp:454
Definition: Layout.h:63
Definition: Widget.h:43
int GetHoriz() const
Convenience function that returns left + right.
Definition: Layout.cpp:132
Lays out widgets horizontally.
Definition: Layout.h:159
Definition: Widget.h:53
Definition: Layout.h:92
Definition: Open3DViewer.h:29
Lays out widgets vertically.
Definition: Layout.h:115
Definition: Layout.h:34
int right
Definition: Layout.h:37
Definition: Layout.h:133
Definition: Layout.h:59
DrawResult
Definition: Widget.h:89
int top
Definition: Layout.h:36
Definition: Theme.h:38