1 #ifndef TERMOX_WIDGET_WIDGET_HPP
2 #define TERMOX_WIDGET_WIDGET_HPP
13 #include <signals_light/signal.hpp>
15 #include <termox/common/fps.hpp>
16 #include <termox/common/transform_view.hpp>
17 #include <termox/painter/brush.hpp>
18 #include <termox/painter/color.hpp>
19 #include <termox/painter/glyph.hpp>
20 #include <termox/painter/painter.hpp>
21 #include <termox/system/key.hpp>
22 #include <termox/system/mouse.hpp>
23 #include <termox/widget/area.hpp>
24 #include <termox/widget/cursor.hpp>
25 #include <termox/widget/focus_policy.hpp>
26 #include <termox/widget/point.hpp>
27 #include <termox/widget/size_policy.hpp>
34 std::string name = std::string{};
35 Focus_policy focus_policy = Focus_policy::None;
40 bool brush_paints_wallpaper =
true;
45 template <
typename Signature>
46 using Signal = sl::Signal<Signature>;
52 Signal<void()> enabled;
53 Signal<void()> disabled;
54 Signal<void(
Widget&)> child_added;
55 Signal<void(
Widget&)> child_removed;
56 Signal<void(
Widget&)> child_polished;
57 Signal<void(Point, Point)> moved;
58 Signal<void(Area, Area)> resized;
59 Signal<void(Mouse
const&)> mouse_pressed;
60 Signal<void(Mouse
const&)> mouse_released;
61 Signal<void(Mouse
const&)> mouse_wheel_scrolled;
62 Signal<void(Mouse
const&)> mouse_moved;
63 Signal<void(Key)> key_pressed;
64 Signal<void(Key)> key_released;
65 Signal<void()> focused_in;
66 Signal<void()> focused_out;
67 Signal<void()> deleted;
72 Signal<bool(
Widget&)> enabled_filter;
73 Signal<bool(
Widget&)> disabled_filter;
77 Signal<bool(
Widget&, Point, Point)> moved_filter;
78 Signal<bool(
Widget&, Area, Area)> resized_filter;
79 Signal<bool(
Widget&, Mouse
const&)> mouse_pressed_filter;
80 Signal<bool(
Widget&, Mouse
const&)> mouse_released_filter;
81 Signal<bool(
Widget&, Mouse
const&)> mouse_wheel_scrolled_filter;
82 Signal<bool(
Widget&, Mouse
const&)> mouse_moved_filter;
83 Signal<bool(
Widget&, Key)> key_pressed_filter;
84 Signal<bool(
Widget&, Key)> key_released_filter;
85 Signal<bool(
Widget&)> focused_in_filter;
86 Signal<bool(
Widget&)> focused_out_filter;
87 Signal<bool(
Widget&)> deleted_filter;
89 Signal<bool(
Widget&)> timer_filter;
113 Focus_policy focus_policy_ = Focus_policy::None,
116 Brush brush_ = Brush{},
117 Glyph wallpaper = U
' ',
118 bool brush_paints_wallpaper =
true,
119 Cursor
cursor = Cursor{});
122 explicit Widget(Parameters p);
124 virtual ~
Widget() =
default;
139 [[nodiscard]]
auto name() const -> std::
string const&;
142 [[nodiscard]] auto
unique_id() const -> std::uint16_t;
159 [[nodiscard]] auto
is_enabled() const ->
bool;
167 [[nodiscard]] auto
top_left() const -> Point;
170 [[nodiscard]] auto
area() const -> Area;
216 auto constexpr dereference = [](
auto& widg_ptr) ->
Widget& {
225 auto constexpr dereference = [](
auto const& widg_ptr) ->
Widget const& {
249 [[nodiscard]] auto
child_count() const -> std::
size_t;
268 virtual auto
move_event(Point new_position, Point old_position) ->
bool;
271 virtual auto
resize_event(Area new_size, Area old_size) ->
bool;
329 Point old_position) ->
bool;
334 Area old_size) ->
bool;
374 bool enabled_ = false;
375 bool brush_paints_wallpaper_;
376 bool is_animated_ = false;
379 using Children_t = std::vector<std::unique_ptr<
Widget>>;
380 Children_t children_;
381 std::
size_t child_offset_ = 0;
385 Widget* parent_ =
nullptr;
387 std::set<
Widget*> event_filters_;
390 Point top_left_position_ = {0, 0};
395 std::uint16_t
const unique_id_;
409 [[nodiscard]]
auto widget(std::string name =
"",
410 Focus_policy focus_policy = Focus_policy::None,
411 Size_policy width_policy = Size_policy{},
412 Size_policy height_policy = Size_policy{},
413 Brush brush = Brush{},
414 Glyph wallpaper = U
' ',
415 bool brush_paints_wallpaper =
true,
416 Cursor cursor = Cursor{}) -> std::unique_ptr<Widget>;
419 [[nodiscard]]
auto widget(Widget::Parameters parameters)
420 -> std::unique_ptr<Widget>;
423 template <
typename Widget_t,
typename... Args>
424 [[nodiscard]]
auto make(Args&&... args) -> std::unique_ptr<Widget_t>
426 static_assert(std::is_base_of_v<Widget, Widget_t>,
427 "Must make a Widget derived type.");
428 return std::make_unique<Widget_t>(std::forward<Args>(args)...);
Holds the look of any paintable object with Traits and Colors.
Definition: brush.hpp:13
Holds and provides access to all data relevant to a Widget's cursor.
Definition: cursor.hpp:10
Contains functions to paint Glyphs to a Widget's screen area.
Definition: painter.hpp:21
Defines how a Layout should resize a Widget in one length Dimension.
Definition: size_policy.hpp:11
Holds a description of a paintable tile on the screen.
Definition: glyph.hpp:11