Open3D (C++ API)  0.13.0
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
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) 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 
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 LayoutContext {
52  const Theme& theme;
54 };
55 
56 struct DrawContext {
57  const Theme& theme;
60  int uiOffsetX;
61  int uiOffsetY;
64  int emPx;
65  float frameDelta; // in seconds
66 };
67 
68 class Widget {
69  friend class Window;
70 
71 public:
72  Widget();
73  explicit Widget(const std::vector<std::shared_ptr<Widget>>& children);
74  virtual ~Widget();
75 
76  void AddChild(std::shared_ptr<Widget> child);
77  const std::vector<std::shared_ptr<Widget>> GetChildren() const;
78 
80  const Rect& GetFrame() const;
87  virtual void SetFrame(const Rect& f);
88 
89  const Color& GetBackgroundColor() const;
90  bool IsDefaultBackgroundColor() const;
91  void SetBackgroundColor(const Color& color);
92 
93  bool IsVisible() const;
94  virtual void SetVisible(bool vis);
95 
96  bool IsEnabled() const;
97  virtual void SetEnabled(bool enabled);
98 
99  void SetTooltip(const char* text);
100  const char* GetTooltip() const;
101 
102  static constexpr int DIM_GROW = 10000;
103  struct Constraints {
104  int width = DIM_GROW;
105  int height = DIM_GROW;
106  };
107  virtual Size CalcPreferredSize(const LayoutContext& context,
108  const Constraints& constraints) const;
109 
110  virtual Size CalcMinimumSize(const LayoutContext& context) const;
111 
112  virtual void Layout(const LayoutContext& context);
113 
114  enum class DrawResult { NONE, REDRAW, RELAYOUT };
120  virtual DrawResult Draw(const DrawContext& context);
121 
122  enum class EventResult { IGNORED, CONSUMED, DISCARD };
123 
127  virtual EventResult Mouse(const MouseEvent& e);
128 
132  virtual EventResult Key(const KeyEvent& e);
133 
137  virtual DrawResult Tick(const TickEvent& e);
138 
139 protected:
140  void DrawImGuiPushEnabledState();
141  void DrawImGuiPopEnabledState();
142  void DrawImGuiTooltip();
143 
144 private:
145  struct Impl;
146  std::unique_ptr<Impl> impl_;
147 };
148 
149 } // namespace gui
150 } // namespace visualization
151 } // namespace open3d
const Theme & theme
Definition: Widget.h:57
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
Definition: Theme.h:39
Definition: Window.h:49
visualization::rendering::Renderer & renderer
Definition: Widget.h:58
int emPx
Definition: Widget.h:64
Definition: Widget.h:68
ImGuiContext * context
Definition: Window.cpp:95
math::float4 color
Definition: LineSetBuffers.cpp:64
int screenHeight
Definition: Widget.h:63
int uiOffsetY
Definition: Widget.h:61
const Theme & theme
Definition: Widget.h:52
FontContext & fonts
Definition: Widget.h:53
EventResult
Definition: Widget.h:122
Definition: PinholeCameraIntrinsic.cpp:35
int screenWidth
Definition: Widget.h:62
int height
Definition: FilePCD.cpp:72
float frameDelta
Definition: Widget.h:65
int uiOffsetX
Definition: Widget.h:60
Definition: Events.h:210
DrawResult
Definition: Widget.h:114
FontContext & fonts
Definition: Widget.h:59
Definition: Color.h:35
int width
Definition: FilePCD.cpp:71