Open3D (C++ API)  0.12.0
TreeView.h
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - Open3D: www.open3d.org -
3 // ----------------------------------------------------------------------------
4 // The MIT License (MIT)
5 //
6 // Copyright (c) 2020 www.open3d.org
7 //
8 // Permission is hereby granted, free of charge, to any person obtaining a copy
9 // of this software and associated documentation files (the "Software"), to deal
10 // in the Software without restriction, including without limitation the rights
11 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 // copies of the Software, and to permit persons to whom the Software is
13 // furnished to do so, subject to the following conditions:
14 //
15 // The above copyright notice and this permission notice shall be included in
16 // all copies or substantial portions of the Software.
17 //
18 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24 // IN THE SOFTWARE.
25 // ----------------------------------------------------------------------------
26 
27 #pragma once
28 
29 #include <functional>
30 
32 
33 namespace open3d {
34 namespace visualization {
35 namespace gui {
36 
37 class Checkbox;
38 class ColorEdit;
39 class Label;
40 class NumberEdit;
41 
47 class CheckableTextTreeCell : public Widget {
48 public:
49  CheckableTextTreeCell(const char* text,
50  bool is_checked,
51  std::function<void(bool)> on_toggled);
53 
54  std::shared_ptr<Checkbox> GetCheckbox();
55  std::shared_ptr<Label> GetLabel();
56 
57  Size CalcPreferredSize(const Theme& theme) const override;
58  void Layout(const Theme& theme) override;
59 
60 private:
61  struct Impl;
62  std::unique_ptr<Impl> impl_;
63 };
64 
65 class LUTTreeCell : public Widget {
66 public:
67  LUTTreeCell(const char* text,
68  bool is_checked,
69  const Color& color,
70  std::function<void(bool)> on_enabled,
71  std::function<void(const Color&)> on_color_changed);
72  ~LUTTreeCell();
73 
74  std::shared_ptr<Checkbox> GetCheckbox();
75  std::shared_ptr<Label> GetLabel();
76  std::shared_ptr<ColorEdit> GetColorEdit();
77 
78  Size CalcPreferredSize(const Theme& theme) const override;
79  void Layout(const Theme& theme) override;
80 
81 private:
82  struct Impl;
83  std::unique_ptr<Impl> impl_;
84 };
85 
86 class ColormapTreeCell : public Widget {
87 public:
88  ColormapTreeCell(double value,
89  const Color& color,
90  std::function<void(double)> on_value_changed,
91  std::function<void(const Color&)> on_color_changed);
93 
94  std::shared_ptr<NumberEdit> GetNumberEdit();
95  std::shared_ptr<ColorEdit> GetColorEdit();
96 
97  Size CalcPreferredSize(const Theme& theme) const override;
98  void Layout(const Theme& theme) override;
99 
100 private:
101  struct Impl;
102  std::unique_ptr<Impl> impl_;
103 };
104 
105 class TreeView : public Widget {
106  using Super = Widget;
107 
108 public:
109  using ItemId = int;
110 
111  TreeView();
112  ~TreeView();
113 
116  ItemId GetRootItem() const;
118  ItemId AddItem(ItemId parent_id, std::shared_ptr<Widget> item);
120  ItemId AddTextItem(ItemId parent_id, const char* text);
122  void RemoveItem(ItemId item_id);
124  void Clear();
126  std::shared_ptr<Widget> GetItem(ItemId item_id) const;
127  std::vector<ItemId> GetItemChildren(ItemId parent_id) const;
128 
129  bool GetCanSelectItemsWithChildren() const;
133  void SetCanSelectItemsWithChildren(bool can_select);
134 
136  ItemId GetSelectedItemId() const;
138  void SetSelectedItemId(ItemId item_id);
139 
140  Size CalcPreferredSize(const Theme& theme) const override;
141 
142  void Layout(const Theme& theme) override;
143 
144  DrawResult Draw(const DrawContext& context) override;
145 
148  void SetOnSelectionChanged(
149  std::function<void(ItemId)> on_selection_changed);
150 
151 private:
152  struct Impl;
153  std::unique_ptr<Impl> impl_;
154 };
155 
156 } // namespace gui
157 } // namespace visualization
158 } // namespace open3d
Definition: Theme.h:39
~CheckableTextTreeCell()
Definition: TreeView.cpp:66
void Layout(const Theme &theme) override
Definition: TreeView.cpp:83
int ItemId
Definition: TreeView.h:109
Definition: Widget.h:62
Size CalcPreferredSize(const Theme &theme) const override
Definition: TreeView.cpp:76
math::float4 color
Definition: LineSetBuffers.cpp:64
Widget()
Definition: Widget.cpp:52
Definition: TreeView.cpp:217
const char const char value recording_handle imu_sample recording_handle uint8_t size_t data_size k4a_record_configuration_t config target_format k4a_capture_t capture_handle k4a_imu_sample_t imu_sample playback_handle k4a_logging_message_cb_t void min_level device_handle k4a_imu_sample_t timeout_in_ms capture_handle capture_handle capture_handle image_handle temperature_c int
Definition: K4aPlugin.cpp:479
std::shared_ptr< Label > GetLabel()
Definition: TreeView.cpp:72
Definition: PinholeCameraIntrinsic.cpp:35
std::shared_ptr< Checkbox > GetCheckbox()
Definition: TreeView.cpp:68
CheckableTextTreeCell(const char *text, bool is_checked, std::function< void(bool)> on_toggled)
Definition: TreeView.cpp:52
virtual DrawResult Draw(const DrawContext &context)
Definition: Widget.cpp:101
DrawResult
Definition: Widget.h:98
Definition: Color.h:35
Definition: TreeView.h:105