Open3D (C++ API)  0.17.0
Widget.h
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - Open3D: www.open3d.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2023 www.open3d.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
7 
8 #pragma once
9 
10 #include <memory>
11 #include <vector>
12 
14 
15 namespace open3d {
16 
17 namespace visualization {
18 namespace rendering {
19 class Renderer;
20 }
21 } // namespace visualization
22 
23 namespace visualization {
24 namespace gui {
25 
26 class Color;
27 struct MouseEvent;
28 struct KeyEvent;
29 struct TickEvent;
30 struct Theme;
31 
32 struct LayoutContext {
33  const Theme& theme;
35 };
36 
37 struct DrawContext {
38  const Theme& theme;
41  int uiOffsetX;
42  int uiOffsetY;
45  int emPx;
46  float frameDelta; // in seconds
47 };
48 
49 class Widget {
50  friend class Window;
51 
52 public:
53  Widget();
54  explicit Widget(const std::vector<std::shared_ptr<Widget>>& children);
55  virtual ~Widget();
56 
57  virtual void AddChild(std::shared_ptr<Widget> child);
58  virtual const std::vector<std::shared_ptr<Widget>> GetChildren() const;
59 
61  virtual const Rect& GetFrame() const;
68  virtual void SetFrame(const Rect& f);
69 
70  virtual const Color& GetBackgroundColor() const;
71  virtual bool IsDefaultBackgroundColor() const;
72  virtual void SetBackgroundColor(const Color& color);
73 
74  virtual bool IsVisible() const;
75  virtual void SetVisible(bool vis);
76 
77  virtual bool IsEnabled() const;
78  virtual void SetEnabled(bool enabled);
79 
80  virtual void SetTooltip(const char* text);
81  virtual const char* GetTooltip() const;
82 
83  static constexpr int DIM_GROW = 10000;
84  struct Constraints {
85  int width = DIM_GROW;
87  };
89  const Constraints& constraints) const;
90 
91  virtual Size CalcMinimumSize(const LayoutContext& context) const;
92 
93  virtual void Layout(const LayoutContext& context);
94 
95  enum class DrawResult { NONE, REDRAW, RELAYOUT };
101  virtual DrawResult Draw(const DrawContext& context);
102 
104 
108  virtual EventResult Mouse(const MouseEvent& e);
109 
113  virtual EventResult Key(const KeyEvent& e);
114 
118  virtual DrawResult Tick(const TickEvent& e);
119 
120 protected:
123  void DrawImGuiTooltip();
124 
125 private:
126  struct Impl;
127  std::unique_ptr<Impl> impl_;
128 };
129 
130 } // namespace gui
131 } // namespace visualization
132 } // namespace open3d
math::float4 color
Definition: LineSetBuffers.cpp:45
ImGuiContext * context
Definition: Window.cpp:76
Definition: Color.h:16
Definition: Widget.h:49
virtual void SetFrame(const Rect &f)
Definition: Widget.cpp:53
virtual Size CalcPreferredSize(const LayoutContext &context, const Constraints &constraints) const
Definition: Widget.cpp:77
void DrawImGuiPopEnabledState()
Definition: Widget.cpp:126
virtual void SetBackgroundColor(const Color &color)
Definition: Widget.cpp:61
void DrawImGuiPushEnabledState()
Definition: Widget.cpp:111
virtual const Rect & GetFrame() const
Returns the frame size in pixels.
Definition: Widget.cpp:51
virtual const char * GetTooltip() const
Definition: Widget.cpp:75
Widget()
Definition: Widget.cpp:34
static constexpr int DIM_GROW
Definition: Widget.h:83
virtual void Layout(const LayoutContext &context)
Definition: Widget.cpp:86
virtual Size CalcMinimumSize(const LayoutContext &context) const
Definition: Widget.cpp:82
virtual EventResult Mouse(const MouseEvent &e)
Definition: Widget.cpp:161
void DrawImGuiTooltip()
Definition: Widget.cpp:133
virtual EventResult Key(const KeyEvent &e)
Definition: Widget.cpp:185
virtual DrawResult Tick(const TickEvent &e)
Definition: Widget.cpp:189
virtual ~Widget()
Definition: Widget.cpp:41
virtual void SetVisible(bool vis)
Definition: Widget.cpp:67
virtual void SetEnabled(bool enabled)
Definition: Widget.cpp:71
virtual void AddChild(std::shared_ptr< Widget > child)
Definition: Widget.cpp:43
virtual bool IsEnabled() const
Definition: Widget.cpp:69
virtual DrawResult Draw(const DrawContext &context)
Definition: Widget.cpp:92
EventResult
Definition: Widget.h:103
virtual bool IsVisible() const
Definition: Widget.cpp:65
virtual const Color & GetBackgroundColor() const
Definition: Widget.cpp:55
virtual const std::vector< std::shared_ptr< Widget > > GetChildren() const
Definition: Widget.cpp:47
DrawResult
Definition: Widget.h:95
virtual bool IsDefaultBackgroundColor() const
Definition: Widget.cpp:57
virtual void SetTooltip(const char *text)
Definition: Widget.cpp:73
Definition: Window.h:30
Definition: PinholeCameraIntrinsic.cpp:16
const Theme & theme
Definition: Widget.h:38
int screenWidth
Definition: Widget.h:43
visualization::rendering::Renderer & renderer
Definition: Widget.h:39
int screenHeight
Definition: Widget.h:44
int uiOffsetY
Definition: Widget.h:42
float frameDelta
Definition: Widget.h:46
int emPx
Definition: Widget.h:45
int uiOffsetX
Definition: Widget.h:41
FontContext & fonts
Definition: Widget.h:40
Definition: Events.h:203
FontContext & fonts
Definition: Widget.h:34
const Theme & theme
Definition: Widget.h:33
Definition: Theme.h:20