Skip to content

Commit

Permalink
Added gui::TreeView widget (#2081)
Browse files Browse the repository at this point in the history
  • Loading branch information
prewettg committed Jul 21, 2020
1 parent a3621c5 commit e2ade74
Show file tree
Hide file tree
Showing 12 changed files with 499 additions and 20 deletions.
1 change: 1 addition & 0 deletions cpp/open3d/Open3D.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
#include "open3d/visualization/gui/TabControl.h"
#include "open3d/visualization/gui/TextEdit.h"
#include "open3d/visualization/gui/Theme.h"
#include "open3d/visualization/gui/TreeView.h"
#include "open3d/visualization/gui/Window.h"
#include "open3d/visualization/utility/DrawGeometry.h"
#include "open3d/visualization/utility/SelectionPolygon.h"
Expand Down
7 changes: 6 additions & 1 deletion cpp/open3d/visualization/gui/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,12 @@ Application::Application() : impl_(new Application::Impl()) {
impl_->theme_.combobox_hover_color = Color(0.5, 0.5, 0.5);
impl_->theme_.combobox_arrow_background_color = highlight_color;
impl_->theme_.slider_grab_color = Color(0.666, 0.666, 0.666);
impl_->theme_.text_edit_background_color = Color(0.25, 0.25, 0.25);
impl_->theme_.text_edit_background_color = Color(0.1, 0.1, 0.1);
impl_->theme_.list_background_color = Color(0.1, 0.1, 0.1);
impl_->theme_.list_hover_color = Color(0.6, 0.6, 0.6);
impl_->theme_.list_selected_color = Color(0.5, 0.5, 0.5);
impl_->theme_.tree_background_color = impl_->theme_.list_background_color;
impl_->theme_.tree_selected_color = impl_->theme_.list_selected_color;
impl_->theme_.tab_inactive_color = impl_->theme_.button_color;
impl_->theme_.tab_hover_color = impl_->theme_.button_hover_color;
impl_->theme_.tab_active_color = impl_->theme_.button_active_color;
Expand Down
29 changes: 28 additions & 1 deletion cpp/open3d/visualization/gui/ListView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include <sstream>

#include "open3d/visualization/gui/Theme.h"
#include "open3d/visualization/gui/Util.h"

namespace open3d {
namespace visualization {
Expand Down Expand Up @@ -102,6 +103,15 @@ Widget::DrawResult ListView::Draw(const DrawContext &context) {
ImVec2(frame.x - context.uiOffsetX, frame.y - context.uiOffsetY));
ImGui::PushItemWidth(frame.width);

ImGui::PushStyleColor(ImGuiCol_FrameBg,
colorToImgui(context.theme.list_background_color));
ImGui::PushStyleColor(ImGuiCol_Header, // selection color
colorToImgui(context.theme.list_selected_color));
ImGui::PushStyleColor(ImGuiCol_HeaderHovered, // hover color
colorToImgui(Color(0, 0, 0, 0)));
ImGui::PushStyleColor(ImGuiCol_HeaderActive, // click-hold color
colorToImgui(context.theme.list_selected_color));

int height_in_items =
int(std::floor(frame.height / ImGui::GetFrameHeight()));

Expand All @@ -113,6 +123,20 @@ Widget::DrawResult ListView::Draw(const DrawContext &context) {
height_in_items)) {
for (size_t i = 0; i < impl_->items_.size(); ++i) {
bool is_selected = (int(i) == impl_->selected_index_);
// ImGUI's list wants to hover over items, which is not done by
// any major OS, is pretty unnecessary (you can see the cursor
// right over the row), and acts really weird. Worse, the hover
// is drawn instead of the selection color. So to get rid of it
// we need hover to be the selected color iff this item is
// selected, otherwise we want it to be transparent.
if (is_selected) {
ImGui::PushStyleColor(
ImGuiCol_HeaderHovered,
colorToImgui(context.theme.list_selected_color));
} else {
ImGui::PushStyleColor(ImGuiCol_HeaderHovered,
colorToImgui(Color(0, 0, 0, 0)));
}
if (ImGui::Selectable(impl_->items_[i].c_str(), &is_selected,
ImGuiSelectableFlags_AllowDoubleClick)) {
if (is_selected) {
Expand All @@ -125,19 +149,22 @@ Widget::DrawResult ListView::Draw(const DrawContext &context) {
is_double_click = true;
}
}
ImGui::PopStyleColor();
}
ImGui::ListBoxFooter();

if (new_selected_idx != impl_->selected_index_ || is_double_click) {
impl_->selected_index_ = new_selected_idx;
if (impl_->on_value_changed_) {
impl_->on_value_changed_(GetSelectedValue(), is_double_click);
result = Widget::DrawResult::REDRAW;
}
result = Widget::DrawResult::REDRAW;
}
}
DrawImGuiPopEnabledState();

ImGui::PopStyleColor(4);

ImGui::PopItemWidth();
return result;
}
Expand Down
6 changes: 2 additions & 4 deletions cpp/open3d/visualization/gui/ProgressBar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <cmath>

#include "open3d/visualization/gui/Theme.h"
#include "open3d/visualization/gui/Util.h"

namespace open3d {
namespace visualization {
Expand All @@ -55,10 +56,7 @@ Size ProgressBar::CalcPreferredSize(const Theme& theme) const {
Widget::DrawResult ProgressBar::Draw(const DrawContext& context) {
auto& frame = GetFrame();
auto fg = context.theme.border_color;
auto color = IM_COL32(int(std::round(255.0f * fg.GetRed())),
int(std::round(255.0f * fg.GetGreen())),
int(std::round(255.0f * fg.GetBlue())),
int(std::round(255.0f * fg.GetAlpha())));
auto color = colorToImguiRGBA(fg);
float rounding = frame.height / 2.0f;
ImGui::GetWindowDrawList()->AddRect(
ImVec2(frame.x, frame.y),
Expand Down
7 changes: 7 additions & 0 deletions cpp/open3d/visualization/gui/Theme.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,13 @@ struct Theme {

Color text_edit_background_color;

Color list_background_color;
Color list_hover_color;
Color list_selected_color;

Color tree_background_color;
Color tree_selected_color;

Color tab_inactive_color;
Color tab_hover_color;
Color tab_active_color;
Expand Down
Loading

0 comments on commit e2ade74

Please sign in to comment.