bWidgets
Core widget toolkit designed for Blender
bwWidget.h
Go to the documentation of this file.
1#pragma once
2
3#include <optional>
4#include <typeinfo>
5
6#include "bwDistance.h"
8#include "bwRectangle.h"
9#include "bwStyleProperties.h"
11
12namespace bWidgets {
13
14class bwEvent;
15class bwMouseButtonEvent;
16class bwMouseButtonDragEvent;
17class bwStyle;
18
22class bwWidget {
23 public:
24 enum class State {
25 NORMAL = 0,
26 HIGHLIGHTED,
27 SUNKEN,
28
29 STATE_TOT
30 };
31
32 bwWidget(std::optional<unsigned int> width_hint, std::optional<unsigned int> height_hint);
33 virtual ~bwWidget() = default;
34
35 /* Disable these constructors/operators. Not really needed and would add complexity for
36 * sub-classes. */
37 bwWidget() = delete;
38 bwWidget(const bwWidget&) = delete;
39 bwWidget(bwWidget&&) = delete;
40 auto operator=(const bwWidget&) = delete;
41 auto operator=(bwWidget&&) = delete;
42
43 auto getState() const -> State;
44 auto setState(State) -> bwWidget&;
45 auto hide(bool _hidden = true) -> bwWidget&;
46 auto isHidden() -> bool;
47
48 virtual auto getTypeIdentifier() const -> std::string_view = 0;
49
50 virtual void draw(bwStyle& style) = 0;
51 virtual auto isCoordinateInside(const bwPoint& point) const -> bool;
52 virtual auto getLabel() const -> const std::string*;
53 virtual auto canAlign() const -> bool;
54 virtual auto createHandler() -> std::unique_ptr<bwScreenGraph::EventHandler> = 0;
55
62
68 unsigned int width_hint, height_hint;
69
71
72 protected:
73 void initialize();
74 virtual void registerProperties();
75
76 private:
87 bool hidden{false};
88
89 State state;
90};
91
121template<class T, class _RawT = typename std::remove_pointer<T>::type>
122inline auto widget_cast(bwWidget& widget) -> _RawT*
123{
124 static_assert(std::is_base_of<bwWidget, _RawT>::value, "Type is not a widget");
125
126 return dynamic_cast<_RawT*>(&widget);
127}
128
134template<class T,
135 class _RawT = typename std::remove_pointer<typename std::remove_const<T>::type>::type>
136inline auto widget_cast(const bwWidget& widget) -> const _RawT*
137{
138 static_assert(std::is_base_of<bwWidget, _RawT>::value, "Type is not a widget");
139
140 return dynamic_cast<const _RawT*>(&widget);
141}
142
148template<class T, class _RawT = typename std::remove_pointer<T>::type>
149inline auto widget_cast(bwWidget* widget) -> _RawT*
150{
151 static_assert(std::is_base_of<bwWidget, _RawT>::value, "Type is not a widget");
152
153 return dynamic_cast<_RawT*>(widget);
154}
155
161template<class T,
162 class _RawT = typename std::remove_pointer<typename std::remove_const<T>::type>::type>
163inline auto widget_cast(const bwWidget* widget) -> const _RawT*
164{
165 static_assert(std::is_base_of<bwWidget, _RawT>::value, "Type is not a widget");
166
167 return dynamic_cast<const _RawT*>(widget);
168}
169
170} // namespace bWidgets
Definition: bwPoint.h:7
Manage a list of properties (bwStyleProperty instances).
Definition: bwStyleProperties.h:77
Definition: bwStyle.h:10
Abstract base class that all widgets derive from.
Definition: bwWidget.h:22
State
Definition: bwWidget.h:24
auto getState() const -> State
Definition: bwWidget.cc:20
bwRectanglePixel rectangle
Definition: bwWidget.h:61
bwWidget(bwWidget &&)=delete
virtual void registerProperties()
Definition: bwWidget.cc:62
void initialize()
Additional initialization that can't be done in bwWidget constructor.
Definition: bwWidget.cc:55
bwWidget(const bwWidget &)=delete
bwStyleProperties style_properties
Definition: bwWidget.h:70
auto operator=(bwWidget &&)=delete
virtual auto createHandler() -> std::unique_ptr< bwScreenGraph::EventHandler >=0
auto isHidden() -> bool
Definition: bwWidget.cc:37
virtual ~bwWidget()=default
unsigned int height_hint
Definition: bwWidget.h:68
virtual auto getTypeIdentifier() const -> std::string_view=0
virtual auto isCoordinateInside(const bwPoint &point) const -> bool
Definition: bwWidget.cc:15
auto operator=(const bwWidget &)=delete
auto hide(bool _hidden=true) -> bwWidget &
Definition: bwWidget.cc:31
unsigned int width_hint
Definition: bwWidget.h:68
virtual auto canAlign() const -> bool
Definition: bwWidget.cc:47
virtual auto getLabel() const -> const std::string *
Definition: bwWidget.cc:42
auto setState(State) -> bwWidget &
Definition: bwWidget.cc:25
virtual void draw(bwStyle &style)=0
Definition: bwContext.h:3
auto widget_cast(bwWidget &widget) -> _RawT *
Definition: bwWidget.h:122