ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
StackedWidget.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 <algorithm> // for std::max, std::min
11 
12 namespace cloudViewer {
13 namespace visualization {
14 namespace gui {
15 
17  int selected_index_ = 0;
18 };
19 
21 
23 
25  impl_->selected_index_ = index;
26 }
27 
28 int StackedWidget::GetSelectedIndex() const { return impl_->selected_index_; }
29 
31  const Constraints& constraints) const {
32  Size size(0, 0);
33  for (auto child : GetChildren()) {
34  auto sz = child->CalcPreferredSize(context, constraints);
35  size.width = std::max(size.width, sz.width);
36  size.height = std::max(size.height, sz.height);
37  }
38  return size;
39 }
40 
42  auto& frame = GetFrame();
43  for (auto child : GetChildren()) {
44  child->SetFrame(frame);
45  }
46 
48 }
49 
51  // Don't Super, because Widget::Draw will draw all the children,
52  // and we only want to draw the selected child.
53  if (impl_->selected_index_ >= 0 &&
54  impl_->selected_index_ < int(GetChildren().size())) {
55  return GetChildren()[impl_->selected_index_]->Draw(context);
56  }
57  return DrawResult::NONE;
58 }
59 
60 } // namespace gui
61 } // namespace visualization
62 } // namespace cloudViewer
Rect frame
int size
void Layout(const LayoutContext &context) override
int GetSelectedIndex() const
Returns the index of the selected child.
Widget::DrawResult Draw(const DrawContext &context) override
Size CalcPreferredSize(const LayoutContext &context, const Constraints &constraints) const override
void SetSelectedIndex(int index)
Sets the index of the child to draw.
virtual const std::vector< std::shared_ptr< Widget > > GetChildren() const
Definition: Widget.cpp:47
virtual void Layout(const LayoutContext &context)
Definition: Widget.cpp:86
virtual const Rect & GetFrame() const
Returns the frame size in pixels.
Definition: Widget.cpp:51
int max(int a, int b)
Definition: cutil_math.h:48
ImGuiContext * context
Definition: Window.cpp:76
Generic file read and write utility for python interface.