1 #if !defined(_BTK_WIDGET_HPP_) 2 #define _BTK_WIDGET_HPP_ 4 #include "signal/signal.hpp" 5 #include "signal/function.hpp" 22 struct TextInputEvent;
24 enum class FocusPolicy{
33 bool user_rect =
false;
34 bool container =
false;
36 FocusPolicy focus = FocusPolicy::None;
39 enum class Align:unsigned int{
48 enum class Orientation:unsigned int{
59 class BTKAPI EventDispatcher{
61 using container_type = std::list<Widget*>;
63 EventDispatcher(container_type &w):
65 EventDispatcher(
const EventDispatcher &) =
delete;
66 ~EventDispatcher() =
default;
82 void set_focus_widget(
Widget *);
85 container_type& widgets;
86 Widget *focus_widget =
nullptr;
87 Widget *drag_widget =
nullptr;
88 Widget *cur_widget =
nullptr;
94 bool mouse_pressed =
false;
95 bool drag_rejected =
false;
100 bool managed_window =
false;
127 template<
class T,
class ...Args>
131 std::forward<Args>(args)...
133 widgets_list.push_back(ptr);
138 widgets_list.push_back(w);
155 bool remove(
Widget *widget);
163 bool detach(
Widget *widget);
177 bool handle(
Event &);
188 void set_focus_widget(
Widget *);
190 Widget *focus_widget =
nullptr;
191 Widget *drag_widget =
nullptr;
192 Widget *cur_widget =
nullptr;
198 bool mouse_pressed =
false;
199 bool drag_rejected =
false;
204 bool managed_window =
false;
213 std::list<Widget*> widgets_list;
229 this->parent = parent;
232 this->parent = &parent;
237 virtual void draw(Renderer &render) = 0;
244 virtual bool handle(
Event &);
245 bool visible()
const noexcept{
246 return not attr.hide;
248 Vec2 position()
const noexcept{
261 void set_rect(
const Rect &rect);
262 void set_rect(
int x,
int y,
int w,
int h){
265 void set_position(
const Vec2 &vec2){
266 set_rect(vec2.x,vec2.y,rect.w,rect.h);
268 int x()
const noexcept{
271 int y()
const noexcept{
274 int w()
const noexcept{
277 int h()
const noexcept{
280 bool is_enable()
const noexcept{
281 return not attr.disable;
295 return parent->window;
314 void draw(Renderer &);
316 Orientation orientation;
320 #endif // _BTK_WIDGET_HPP_
void PushEvent(Event *event, Window &receiver)
Push event to queue.
Definition: event.cpp:63
a SDL_Rect with methods
Definition: rect.hpp:10
This header include many useful containers.
Definition: async.hpp:7
A Basic Window.
Definition: window.hpp:20
A Event of text input.
Definition: event.hpp:237
A event about mouse click.
Definition: event.hpp:106
Function< bool(Event &)> ev_filter
Event filter.
Definition: widget.hpp:209
T & add(Args &&...args)
Add a widget to the Container.
Definition: widget.hpp:128
A event about keyboard.
Definition: event.hpp:171
Function< bool(Event &)> Filter
The event filter(return false to drop the event)
Definition: widget.hpp:117
Definition: signal.hpp:119
Function< bool(Event &)> & filter() noexcept
Get the Container EventFilter.
Definition: widget.hpp:183
A event about mouse motion.
Definition: event.hpp:216
A base event of all events.
Definition: event.hpp:17
Definition: window.hpp:39
Definition: event.hpp:287
A Container of Widget.
Definition: widget.hpp:108
Definition: widget.hpp:308