Open3D (C++ API)  0.16.0
Widget.h
Go to the documentation of this file.
1// ----------------------------------------------------------------------------
2// - Open3D: www.open3d.org -
3// ----------------------------------------------------------------------------
4// The MIT License (MIT)
5//
6// Copyright (c) 2018-2021 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 <memory>
30#include <vector>
31
33
34namespace open3d {
35
36namespace visualization {
37namespace rendering {
38class Renderer;
39}
40} // namespace visualization
41
42namespace visualization {
43namespace gui {
44
45class Color;
46struct MouseEvent;
47struct KeyEvent;
48struct TickEvent;
49struct Theme;
50
52 const Theme& theme;
54};
55
57 const Theme& theme;
64 int emPx;
65 float frameDelta; // in seconds
66};
67
68class Widget {
69 friend class Window;
70
71public:
72 Widget();
73 explicit Widget(const std::vector<std::shared_ptr<Widget>>& children);
74 virtual ~Widget();
75
76 virtual void AddChild(std::shared_ptr<Widget> child);
77 virtual const std::vector<std::shared_ptr<Widget>> GetChildren() const;
78
80 virtual const Rect& GetFrame() const;
87 virtual void SetFrame(const Rect& f);
88
89 virtual const Color& GetBackgroundColor() const;
90 virtual bool IsDefaultBackgroundColor() const;
91 virtual void SetBackgroundColor(const Color& color);
92
93 virtual bool IsVisible() const;
94 virtual void SetVisible(bool vis);
95
96 virtual bool IsEnabled() const;
97 virtual void SetEnabled(bool enabled);
98
99 virtual void SetTooltip(const char* text);
100 virtual const char* GetTooltip() const;
101
102 static constexpr int DIM_GROW = 10000;
103 struct Constraints {
106 };
108 const Constraints& constraints) const;
109
110 virtual Size CalcMinimumSize(const LayoutContext& context) const;
111
112 virtual void Layout(const LayoutContext& context);
113
114 enum class DrawResult { NONE, REDRAW, RELAYOUT };
120 virtual DrawResult Draw(const DrawContext& context);
121
122 enum class EventResult { IGNORED, CONSUMED, DISCARD };
123
127 virtual EventResult Mouse(const MouseEvent& e);
128
132 virtual EventResult Key(const KeyEvent& e);
133
137 virtual DrawResult Tick(const TickEvent& e);
138
139protected:
142 void DrawImGuiTooltip();
143
144private:
145 struct Impl;
146 std::unique_ptr<Impl> impl_;
147};
148
149} // namespace gui
150} // namespace visualization
151} // namespace open3d
math::float4 color
Definition: LineSetBuffers.cpp:64
ImGuiContext * context
Definition: Window.cpp:95
Definition: Color.h:35
Definition: Widget.h:68
virtual void SetFrame(const Rect &f)
Definition: Widget.cpp:72
virtual Size CalcPreferredSize(const LayoutContext &context, const Constraints &constraints) const
Definition: Widget.cpp:96
void DrawImGuiPopEnabledState()
Definition: Widget.cpp:145
virtual void SetBackgroundColor(const Color &color)
Definition: Widget.cpp:80
void DrawImGuiPushEnabledState()
Definition: Widget.cpp:130
virtual const Rect & GetFrame() const
Returns the frame size in pixels.
Definition: Widget.cpp:70
virtual const char * GetTooltip() const
Definition: Widget.cpp:94
Widget()
Definition: Widget.cpp:53
static constexpr int DIM_GROW
Definition: Widget.h:102
virtual void Layout(const LayoutContext &context)
Definition: Widget.cpp:105
virtual Size CalcMinimumSize(const LayoutContext &context) const
Definition: Widget.cpp:101
virtual EventResult Mouse(const MouseEvent &e)
Definition: Widget.cpp:180
void DrawImGuiTooltip()
Definition: Widget.cpp:152
virtual EventResult Key(const KeyEvent &e)
Definition: Widget.cpp:204
virtual DrawResult Tick(const TickEvent &e)
Definition: Widget.cpp:208
virtual ~Widget()
Definition: Widget.cpp:60
virtual void SetVisible(bool vis)
Definition: Widget.cpp:86
virtual void SetEnabled(bool enabled)
Definition: Widget.cpp:90
virtual void AddChild(std::shared_ptr< Widget > child)
Definition: Widget.cpp:62
virtual bool IsEnabled() const
Definition: Widget.cpp:88
virtual DrawResult Draw(const DrawContext &context)
Definition: Widget.cpp:111
EventResult
Definition: Widget.h:122
virtual bool IsVisible() const
Definition: Widget.cpp:84
virtual const Color & GetBackgroundColor() const
Definition: Widget.cpp:74
virtual const std::vector< std::shared_ptr< Widget > > GetChildren() const
Definition: Widget.cpp:66
DrawResult
Definition: Widget.h:114
virtual bool IsDefaultBackgroundColor() const
Definition: Widget.cpp:76
virtual void SetTooltip(const char *text)
Definition: Widget.cpp:92
Definition: Window.h:49
Definition: PinholeCameraIntrinsic.cpp:35
const Theme & theme
Definition: Widget.h:57
int screenWidth
Definition: Widget.h:62
visualization::rendering::Renderer & renderer
Definition: Widget.h:58
int screenHeight
Definition: Widget.h:63
int uiOffsetY
Definition: Widget.h:61
float frameDelta
Definition: Widget.h:65
int emPx
Definition: Widget.h:64
int uiOffsetX
Definition: Widget.h:60
FontContext & fonts
Definition: Widget.h:59
Definition: Events.h:222
FontContext & fonts
Definition: Widget.h:53
const Theme & theme
Definition: Widget.h:52
Definition: Theme.h:39