ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
WidgetStack.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 
9 
10 #include <stack>
11 
12 namespace cloudViewer {
13 namespace visualization {
14 namespace gui {
16  std::stack<std::shared_ptr<Widget>> widgets_;
17  std::function<void(std::shared_ptr<Widget>)> on_top_callback_;
18 };
19 
21 WidgetStack::~WidgetStack() = default;
22 
23 void WidgetStack::PushWidget(std::shared_ptr<Widget> widget) {
24  impl_->widgets_.push(widget);
25  SetWidget(widget);
26 }
27 
28 std::shared_ptr<Widget> WidgetStack::PopWidget() {
29  std::shared_ptr<Widget> ret;
30  if (!impl_->widgets_.empty()) {
31  ret = impl_->widgets_.top();
32  impl_->widgets_.pop();
33  if (!impl_->widgets_.empty()) {
34  SetWidget(impl_->widgets_.top());
35  if (impl_->on_top_callback_) {
36  impl_->on_top_callback_(impl_->widgets_.top());
37  }
38  } else {
39  SetWidget(nullptr);
40  }
41  }
42  return ret;
43 }
45  std::function<void(std::shared_ptr<Widget>)> onTopCallback) {
46  impl_->on_top_callback_ = onTopCallback;
47 }
48 
49 } // namespace gui
50 } // namespace visualization
51 } // namespace cloudViewer
virtual void SetWidget(std::shared_ptr< Widget > widget)
set a new widget to be delegated by this one.
Definition: WidgetProxy.cpp:27
WidgetStack manages multiple widgets in a stack.
Definition: WidgetStack.h:32
std::shared_ptr< Widget > PopWidget()
Pop the top most widget.
Definition: WidgetStack.cpp:28
void PushWidget(std::shared_ptr< Widget > widget)
Push a widget into stack so the it be the topmost widget.
Definition: WidgetStack.cpp:23
void SetOnTop(std::function< void(std::shared_ptr< Widget >)> onTopCallback)
Setup a callback while a widget is popped out and a new widget becomes the topmost one.
Definition: WidgetStack.cpp:44
Generic file read and write utility for python interface.
std::stack< std::shared_ptr< Widget > > widgets_
Definition: WidgetStack.cpp:16
std::function< void(std::shared_ptr< Widget >)> on_top_callback_
Definition: WidgetStack.cpp:17