Skip to content

Commit

Permalink
fixed ProgressBar scrolling behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
cansik committed May 25, 2023
1 parent a5be78c commit 8ae0bfe
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 6 deletions.
15 changes: 9 additions & 6 deletions cpp/open3d/visualization/gui/ProgressBar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,19 @@ Widget::DrawResult ProgressBar::Draw(const DrawContext& context) {
auto fg = context.theme.border_color;
auto color = colorToImguiRGBA(fg);
float rounding = frame.height / 2.0f;

ImGui::GetWindowDrawList()->AddRect(
ImVec2(float(frame.x), float(frame.y)),
ImVec2(float(frame.GetRight()), float(frame.GetBottom())), color,
rounding);
ImVec2(float(frame.x), float(frame.y) - ImGui::GetScrollY()),
ImVec2(float(frame.GetRight()),
float(frame.GetBottom()) - ImGui::GetScrollY()),
color, rounding);
float x = float(frame.x) + float(frame.width) * impl_->value_;
x = std::max(x, float(frame.x + rounding));

ImGui::GetWindowDrawList()->AddRectFilled(
ImVec2(float(frame.x), float(frame.y)),
ImVec2(float(x), float(frame.GetBottom())), color,
frame.height / 2.0f);
ImVec2(float(frame.x), float(frame.y) - ImGui::GetScrollY()),
ImVec2(float(x), float(frame.GetBottom()) - ImGui::GetScrollY()),
color, frame.height / 2.0f);
return DrawResult::NONE;
}

Expand Down
36 changes: 36 additions & 0 deletions examples/cpp/BasicGUI.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#include "open3d/Open3D.h"

using namespace open3d;
using namespace open3d::visualization;

class BasicGUI {
public:
explicit BasicGUI() { gui::Application::GetInstance().Initialize(); }

void Run() {
auto window = std::make_shared<gui::Window>("Basic GUI", 200, 200);

auto scrollableVert = std::make_shared<gui::ScrollableVert>(10);

for (auto i = 0; i < 20; i++) {
auto label = std::make_shared<gui::Label>("Hello World");
scrollableVert->AddChild(label);
}

// add progress bar
auto progressBar = std::make_shared<gui::ProgressBar>();
progressBar->SetValue(0.5f);
scrollableVert->AddChild(progressBar);

window->AddChild(scrollableVert);

gui::Application::GetInstance().AddWindow(window);
gui::Application::GetInstance().Run();
}
};

int main(int argc, char *argv[]) {
auto gui = BasicGUI();
gui.Run();
return 0;
}

0 comments on commit 8ae0bfe

Please sign in to comment.