ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
WidgetProxy.cpp
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - CloudViewer: www.cloudViewer.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2024 www.cloudViewer.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
7 
8 #include "WidgetProxy.h"
9 
12 
13 namespace cloudViewer {
14 namespace visualization {
15 namespace gui {
17  std::shared_ptr<Widget> widget_;
18  bool need_layout_ = false;
19 };
20 
23 
24 std::shared_ptr<Widget> WidgetProxy::GetActiveWidget() const {
25  return impl_->widget_;
26 }
27 void WidgetProxy::SetWidget(std::shared_ptr<Widget> widget) {
28  impl_->widget_ = widget;
29  impl_->need_layout_ = true;
30 }
31 std::shared_ptr<Widget> WidgetProxy::GetWidget() { return GetActiveWidget(); }
32 void WidgetProxy::AddChild(std::shared_ptr<Widget> child) {
33  auto widget = GetActiveWidget();
34  if (widget) {
35  widget->AddChild(child);
36  }
37 }
38 
39 const std::vector<std::shared_ptr<Widget>> WidgetProxy::GetChildren() const {
40  auto widget = GetActiveWidget();
41  if (widget) {
42  return widget->GetChildren();
43  }
44  return Widget::GetChildren();
45 }
46 
47 const Rect& WidgetProxy::GetFrame() const {
48  auto widget = GetActiveWidget();
49  if (widget) {
50  return widget->GetFrame();
51  }
52  return Widget::GetFrame();
53 }
54 
55 void WidgetProxy::SetFrame(const Rect& f) {
56  auto widget = GetActiveWidget();
57  if (widget) {
58  widget->SetFrame(f);
59  }
61 }
62 
64  auto widget = GetActiveWidget();
65  if (widget) {
66  return widget->GetBackgroundColor();
67  }
69 }
70 
72  auto widget = GetActiveWidget();
73  if (widget) {
74  return widget->IsDefaultBackgroundColor();
75  }
77 }
78 
80  auto widget = GetActiveWidget();
81  if (widget) {
82  widget->SetBackgroundColor(color);
83  }
85 }
86 
87 bool WidgetProxy::IsVisible() const {
88  auto widget = GetActiveWidget();
89  if (widget) {
90  return Widget::IsVisible() && widget->IsVisible();
91  }
92  return false;
93 }
94 
95 void WidgetProxy::SetVisible(bool vis) {
96  auto widget = GetActiveWidget();
97  if (widget) {
98  widget->SetVisible(vis);
99  }
100 }
101 
103  auto widget = GetActiveWidget();
104  if (widget) {
105  return Widget::IsEnabled() && widget->IsEnabled();
106  }
107  return false;
108 }
109 
110 void WidgetProxy::SetEnabled(bool enabled) {
111  auto widget = GetActiveWidget();
112  if (widget) {
113  widget->SetEnabled(enabled);
114  }
115 }
116 
117 void WidgetProxy::SetTooltip(const char* text) {
118  auto widget = GetActiveWidget();
119  if (widget) {
120  widget->SetTooltip(text);
121  }
122  Widget::SetTooltip(text);
123 }
124 
125 const char* WidgetProxy::GetTooltip() const {
126  auto widget = GetActiveWidget();
127  if (widget) {
128  return widget->GetTooltip();
129  }
130  return Widget::GetTooltip();
131 }
132 
134  const Constraints& constraints) const {
135  auto widget = GetActiveWidget();
136  if (widget) {
137  return widget->CalcPreferredSize(context, constraints);
138  }
139  return Widget::CalcPreferredSize(context, constraints);
140 }
141 
143  auto widget = GetActiveWidget();
144  if (widget) {
145  return widget->CalcMinimumSize(context);
146  }
148 }
149 
151  auto widget = GetActiveWidget();
152  if (widget) {
153  widget->Layout(context);
154  }
155 }
156 
158  if (!IsVisible()) {
159  return DrawResult::NONE;
160  }
161 
163  auto widget = GetActiveWidget();
164  if (widget) {
165  result = widget->Draw(context);
166  }
167  if (impl_->need_layout_) {
168  impl_->need_layout_ = false;
170  }
171  return result;
172 }
173 
175  if (!IsVisible()) {
176  return EventResult::IGNORED;
177  }
178  auto widget = GetActiveWidget();
179  if (widget) {
180  return widget->Mouse(e);
181  }
182  return EventResult::DISCARD;
183 }
184 
186  if (!IsVisible()) {
187  return EventResult::IGNORED;
188  }
189  auto widget = GetActiveWidget();
190  if (widget) {
191  return widget->Key(e);
192  }
193  return EventResult::DISCARD;
194 }
195 
197  auto result = DrawResult::NONE;
198  auto widget = GetActiveWidget();
199  if (widget) {
200  result = widget->Tick(e);
201  }
202  return result;
203 }
204 
205 } // namespace gui
206 } // namespace visualization
207 } // namespace cloudViewer
math::float4 color
core::Tensor result
Definition: VtkUtils.cpp:76
Widget container to delegate any widget dynamically.
Definition: WidgetProxy.h:47
EventResult Mouse(const MouseEvent &e) override
Size CalcMinimumSize(const LayoutContext &context) const override
virtual std::shared_ptr< Widget > GetActiveWidget() const
Definition: WidgetProxy.cpp:24
const Color & GetBackgroundColor() const override
Definition: WidgetProxy.cpp:63
void AddChild(std::shared_ptr< Widget > child) override
Definition: WidgetProxy.cpp:32
const char * GetTooltip() const override
const std::vector< std::shared_ptr< Widget > > GetChildren() const override
Definition: WidgetProxy.cpp:39
const Rect & GetFrame() const override
Returns the frame size in pixels.
Definition: WidgetProxy.cpp:47
DrawResult Tick(const TickEvent &e) override
void SetBackgroundColor(const Color &color) override
Definition: WidgetProxy.cpp:79
EventResult Key(const KeyEvent &e) override
void SetFrame(const Rect &f) override
Definition: WidgetProxy.cpp:55
Size CalcPreferredSize(const LayoutContext &context, const Constraints &constraints) const override
void SetEnabled(bool enabled) override
void Layout(const LayoutContext &context) override
DrawResult Draw(const DrawContext &context) override
virtual std::shared_ptr< Widget > GetWidget()
Retrieve current delegated widget.
Definition: WidgetProxy.cpp:31
virtual void SetWidget(std::shared_ptr< Widget > widget)
set a new widget to be delegated by this one.
Definition: WidgetProxy.cpp:27
void SetTooltip(const char *text) override
virtual const Color & GetBackgroundColor() const
Definition: Widget.cpp:55
virtual void SetTooltip(const char *text)
Definition: Widget.cpp:73
virtual Size CalcPreferredSize(const LayoutContext &context, const Constraints &constraints) const
Definition: Widget.cpp:77
virtual const std::vector< std::shared_ptr< Widget > > GetChildren() const
Definition: Widget.cpp:47
virtual bool IsEnabled() const
Definition: Widget.cpp:69
virtual void SetFrame(const Rect &f)
Definition: Widget.cpp:53
virtual const Rect & GetFrame() const
Returns the frame size in pixels.
Definition: Widget.cpp:51
virtual void SetBackgroundColor(const Color &color)
Definition: Widget.cpp:61
virtual const char * GetTooltip() const
Definition: Widget.cpp:75
virtual bool IsDefaultBackgroundColor() const
Definition: Widget.cpp:57
virtual Size CalcMinimumSize(const LayoutContext &context) const
Definition: Widget.cpp:82
virtual bool IsVisible() const
Definition: Widget.cpp:65
ImGuiContext * context
Definition: Window.cpp:76
Generic file read and write utility for python interface.