Open3D (C++ API)
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 
32 #include "Open3D/GUI/Gui.h"
33 
34 namespace open3d {
35 namespace gui {
36 
37 class Color;
38 struct MouseEvent;
39 struct KeyEvent;
40 struct TickEvent;
41 struct Theme;
42 
43 struct DrawContext {
44  const Theme& theme;
45  int uiOffsetX;
46  int uiOffsetY;
49  int emPx;
50  float frameDelta; // in seconds
51 };
52 
53 class Widget {
54  friend class Window;
55 
56 public:
57  Widget();
58  explicit Widget(const std::vector<std::shared_ptr<Widget>>& children);
59  virtual ~Widget();
60 
61  void AddChild(std::shared_ptr<Widget> child);
62  const std::vector<std::shared_ptr<Widget>> GetChildren() const;
63 
65  const Rect& GetFrame() const;
72  virtual void SetFrame(const Rect& f);
73 
74  const Color& GetBackgroundColor() const;
75  bool IsDefaultBackgroundColor() const;
76  void SetBackgroundColor(const Color& color);
77 
78  bool IsVisible() const;
79  virtual void SetVisible(bool vis);
80 
81  bool IsEnabled() const;
82  virtual void SetEnabled(bool enabled);
83 
84  static constexpr int DIM_GROW = 10000;
85  virtual Size CalcPreferredSize(const Theme& theme) const;
86 
87  virtual void Layout(const Theme& theme);
88 
89  enum class DrawResult { NONE, REDRAW, RELAYOUT };
95  virtual DrawResult Draw(const DrawContext& context);
96 
97  enum class EventResult { IGNORED, CONSUMED, DISCARD };
98 
102  virtual EventResult Mouse(const MouseEvent& e);
103 
107  virtual EventResult Key(const KeyEvent& e);
108 
112  virtual DrawResult Tick(const TickEvent& e);
113 
114 protected:
115  void DrawImGuiPushEnabledState();
116  void DrawImGuiPopEnabledState();
117 
118 private:
119  struct Impl;
120  std::unique_ptr<Impl> impl_;
121 };
122 
123 } // namespace gui
124 } // namespace open3d
int screenWidth
Definition: Widget.h:47
Definition: Events.h:171
EventResult
Definition: Widget.h:97
Definition: Widget.cpp:42
int emPx
Definition: Widget.h:49
float frameDelta
Definition: Widget.h:50
Definition: Gui.h:40
const Theme & theme
Definition: Widget.h:44
int screenHeight
Definition: Widget.h:48
Definition: Window.h:49
math::float4 color
Definition: LineSetBuffers.cpp:46
Definition: Color.h:32
Definition: Widget.h:43
Definition: Events.h:74
Definition: Widget.h:53
Definition: Events.h:53
Definition: Open3DViewer.h:29
Definition: Gui.h:48
DrawResult
Definition: Widget.h:89
int uiOffsetY
Definition: Widget.h:46
int uiOffsetX
Definition: Widget.h:45
Definition: Theme.h:38