ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
ProgressBar.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 <imgui.h>
11 
12 #include <cmath>
13 
15 #include "visualization/gui/Util.h"
16 
17 namespace cloudViewer {
18 namespace visualization {
19 namespace gui {
20 
22  float value_ = 0.0f;
23 };
24 
26 
28 
30 void ProgressBar::SetValue(float value) { impl_->value_ = value; }
31 
32 float ProgressBar::GetValue() const { return impl_->value_; }
33 
35  const Constraints& constraints) const {
36  return Size(constraints.width,
37  int(std::ceil(0.25 * context.theme.font_size)));
38 }
39 
41  auto& frame = GetFrame();
42  auto fg = context.theme.border_color;
43  auto color = colorToImguiRGBA(fg);
44  float rounding = frame.height / 2.0f;
45  ImGui::GetWindowDrawList()->AddRect(
46  ImVec2(float(frame.x), float(frame.y)),
47  ImVec2(float(frame.GetRight()), float(frame.GetBottom())), color,
48  rounding);
49  float x = float(frame.x) + float(frame.width) * impl_->value_;
50  x = std::max(x, float(frame.x + rounding));
51  ImGui::GetWindowDrawList()->AddRectFilled(
52  ImVec2(float(frame.x), float(frame.y)),
53  ImVec2(float(x), float(frame.GetBottom())), color,
54  frame.height / 2.0f);
55  return DrawResult::NONE;
56 }
57 
58 } // namespace gui
59 } // namespace visualization
60 } // namespace cloudViewer
Rect frame
math::float4 color
Widget::DrawResult Draw(const DrawContext &context) override
Definition: ProgressBar.cpp:40
void SetValue(float value)
ProgressBar values ranges from 0.0 (incomplete) to 1.0 (complete)
Definition: ProgressBar.cpp:30
Size CalcPreferredSize(const LayoutContext &context, const Constraints &constraints) const override
Definition: ProgressBar.cpp:34
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
MiniVec< float, N > ceil(const MiniVec< float, N > &a)
Definition: MiniVec.h:89
uint32_t colorToImguiRGBA(const Color &color)
Definition: Util.cpp:25
Generic file read and write utility for python interface.