Open3D (C++ API)  0.12.0
Widget.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 <memory>
30 #include <vector>
31 
33 
34 namespace open3d {
35 
36 namespace visualization {
37 namespace rendering {
38 class Renderer;
39 }
40 } // namespace visualization
41 
42 namespace visualization {
43 namespace gui {
44 
45 class Color;
46 struct MouseEvent;
47 struct KeyEvent;
48 struct TickEvent;
49 struct Theme;
50 
51 struct DrawContext {
52  const Theme& theme;
54  int uiOffsetX;
55  int uiOffsetY;
58  int emPx;
59  float frameDelta; // in seconds
60 };
61 
62 class Widget {
63  friend class Window;
64 
65 public:
66  Widget();
67  explicit Widget(const std::vector<std::shared_ptr<Widget>>& children);
68  virtual ~Widget();
69 
70  void AddChild(std::shared_ptr<Widget> child);
71  const std::vector<std::shared_ptr<Widget>> GetChildren() const;
72 
74  const Rect& GetFrame() const;
81  virtual void SetFrame(const Rect& f);
82 
83  const Color& GetBackgroundColor() const;
84  bool IsDefaultBackgroundColor() const;
85  void SetBackgroundColor(const Color& color);
86 
87  bool IsVisible() const;
88  virtual void SetVisible(bool vis);
89 
90  bool IsEnabled() const;
91  virtual void SetEnabled(bool enabled);
92 
93  static constexpr int DIM_GROW = 10000;
94  virtual Size CalcPreferredSize(const Theme& theme) const;
95 
96  virtual void Layout(const Theme& theme);
97 
98  enum class DrawResult { NONE, REDRAW, RELAYOUT };
104  virtual DrawResult Draw(const DrawContext& context);
105 
106  enum class EventResult { IGNORED, CONSUMED, DISCARD };
107 
111  virtual EventResult Mouse(const MouseEvent& e);
112 
116  virtual EventResult Key(const KeyEvent& e);
117 
121  virtual DrawResult Tick(const TickEvent& e);
122 
123 protected:
124  void DrawImGuiPushEnabledState();
125  void DrawImGuiPopEnabledState();
126 
127 private:
128  struct Impl;
129  std::unique_ptr<Impl> impl_;
130 };
131 
132 } // namespace gui
133 } // namespace visualization
134 } // namespace open3d
const Theme & theme
Definition: Widget.h:52
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:54
Definition: Theme.h:39
Definition: Window.h:50
visualization::rendering::Renderer & renderer
Definition: Widget.h:53
int emPx
Definition: Widget.h:58
Definition: Widget.h:62
math::float4 color
Definition: LineSetBuffers.cpp:64
int screenHeight
Definition: Widget.h:57
int uiOffsetY
Definition: Widget.h:55
EventResult
Definition: Widget.h:106
Definition: PinholeCameraIntrinsic.cpp:35
int screenWidth
Definition: Widget.h:56
float frameDelta
Definition: Widget.h:59
int uiOffsetX
Definition: Widget.h:54
Definition: Events.h:172
DrawResult
Definition: Widget.h:98
Definition: Color.h:35