Skip to content

Commit

Permalink
Refactored GuiVisualizer so that the view settings are more independe…
Browse files Browse the repository at this point in the history
…nt and more MVC-like
  • Loading branch information
prewettg committed Jun 30, 2020
1 parent ef9f6f2 commit bb5fbf8
Show file tree
Hide file tree
Showing 13 changed files with 1,394 additions and 916 deletions.
3 changes: 3 additions & 0 deletions cpp/open3d/visualization/gui/Color.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ Color::Color() : rgba_{0.0f, 0.0f, 0.0f, 1.0f} {}
Color::Color(float r, float g, float b, float a /*= 1.0*/)
: rgba_{r, g, b, a} {}

Color::Color(const Eigen::Vector3f& rgb)
: rgba_{rgb.x(), rgb.y(), rgb.z(), 1.0f} {}

bool Color::operator==(const Color& rhs) const {
return (this->rgba_[0] == rhs.rgba_[0] && this->rgba_[1] == rhs.rgba_[1] &&
this->rgba_[2] == rhs.rgba_[2] && this->rgba_[3] == rhs.rgba_[3]);
Expand Down
3 changes: 3 additions & 0 deletions cpp/open3d/visualization/gui/Color.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@

#pragma once

#include <Eigen/Geometry>

namespace open3d {
namespace visualization {
namespace gui {
Expand All @@ -34,6 +36,7 @@ class Color {
public:
Color();
Color(float r, float g, float b, float a = 1.0);
Color(const Eigen::Vector3f& rgb); // not explicit: want auto-convert

float GetRed() const;
float GetGreen() const;
Expand Down
9 changes: 7 additions & 2 deletions cpp/open3d/visualization/gui/Combobox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ void Combobox::RemoveItem(int index) {
}
}

int Combobox::GetNumberOfItems() const {
return static_cast<int>(impl_->items_.size());
}

const char* Combobox::GetItem(int index) const {
return impl_->items_[index].c_str();
}
Expand All @@ -131,14 +135,15 @@ void Combobox::SetSelectedIndex(int index) {
}
}

void Combobox::SetSelectedValue(const char* value) {
bool Combobox::SetSelectedValue(const char* value) {
std::string svalue = value;
for (size_t i = 0; i < impl_->items_.size(); ++i) {
if (impl_->items_[i] == svalue) {
SetSelectedIndex(i);
return;
return true;
}
}
return false;
}

void Combobox::SetOnValueChanged(
Expand Down
6 changes: 4 additions & 2 deletions cpp/open3d/visualization/gui/Combobox.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ class Combobox : public Widget {
/// Removes the item at \param index.
void RemoveItem(int index);

int GetNumberOfItems() const;

/// Returns the text of the item at \param index. \param index must be
/// valid.
const char* GetItem(int index) const;
Expand All @@ -69,8 +71,8 @@ class Combobox : public Widget {
/// callback.
void SetSelectedIndex(int index);
/// Sets the selected item by value. Does nothing if \param value is not an
/// item. Does not call the onValueChanged callback
void SetSelectedValue(const char* value);
/// item, but will return false. Does not call the onValueChanged callback
bool SetSelectedValue(const char* value);

Size CalcPreferredSize(const Theme& theme) const override;

Expand Down
3 changes: 3 additions & 0 deletions cpp/open3d/visualization/gui/Layout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,9 @@ int Layout1D::GetSpacing() const { return impl_->spacing_; }
const Margins& Layout1D::GetMargins() const { return impl_->margins_; }
Margins& Layout1D::GetMutableMargins() { return impl_->margins_; }

void Layout1D::SetSpacing(int spacing) { impl_->spacing_ = spacing; }
void Layout1D::SetMargins(const Margins& margins) { impl_->margins_ = margins; }

void Layout1D::AddFixed(int size) {
AddChild(std::make_shared<Fixed>(size, impl_->dir_));
}
Expand Down
6 changes: 6 additions & 0 deletions cpp/open3d/visualization/gui/Layout.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ class Layout1D : public Widget {

int GetSpacing() const;
const Margins& GetMargins() const;
/// Sets spacing. Need to signal a relayout after calling (unless it is
/// before a layout that will happen, such as before adding as a child).
void SetSpacing(int spacing);
/// Sets margins. Need to signal a relayout after calling (unless it is
/// before a layout that will happen, such as before adding as a child).
void SetMargins(const Margins& margins);

Size CalcPreferredSize(const Theme& theme) const override;
void Layout(const Theme& theme) override;
Expand Down
Loading

0 comments on commit bb5fbf8

Please sign in to comment.