1.10
widget.h
1/*
2 * Copyright (C) 2018 Microchip Technology Inc. All rights reserved.
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6#ifndef EGT_WIDGET_H
7#define EGT_WIDGET_H
8
14#include <egt/app.h>
15#include <egt/detail/enum.h>
16#include <egt/detail/meta.h>
17#include <egt/detail/range.h>
18#include <egt/event.h>
19#include <egt/flags.h>
20#include <egt/font.h>
21#include <egt/geometry.h>
22#include <egt/imagegroup.h>
23#include <egt/object.h>
24#include <egt/palette.h>
25#include <egt/screen.h>
26#include <egt/serialize.h>
27#include <egt/signal.h>
28#include <egt/theme.h>
29#include <egt/widgetflags.h>
30#include <iosfwd>
31#include <memory>
32#include <string>
33
34namespace egt
35{
36inline namespace v1
37{
38class Painter;
39class Frame;
40class Screen;
41
52class EGT_API Widget : public Object
53{
54public:
55
59 enum class Flag : uint32_t
60 {
64 plane_window = detail::bit(0),
65
69 window = detail::bit(1),
70
74 frame = detail::bit(2),
75
83 disabled = detail::bit(3),
84
88 readonly = detail::bit(4),
89
100 active = detail::bit(5),
101
105 invisible = detail::bit(6),
106
114 grab_mouse = detail::bit(7),
115
121 no_clip = detail::bit(8),
122
126 no_layout = detail::bit(9),
127
131 no_autoresize = detail::bit(10),
132
136 checked = detail::bit(11),
137
141 component = detail::bit(12),
142
147 user_drag = detail::bit(13),
148
153 user_track_drag = detail::bit(14),
154 };
155
158
165
168
171
174
183 explicit Widget(const Rect& rect = {},
184 const Widget::Flags& flags = {}) noexcept;
185
191 explicit Widget(Frame& parent, const Rect& rect = {},
192 const Widget::Flags& flags = {}) noexcept;
193
197 explicit Widget(Serializer::Properties& props) noexcept
198 : Widget(props, false)
199 {
200 }
201
202protected:
203
204 explicit Widget(Serializer::Properties& props, bool is_derived) noexcept;
205
206public:
207
208 Widget(const Widget&) = delete;
209 Widget& operator=(const Widget&) = delete;
210 Widget(Widget&&) noexcept = default;
211 Widget& operator=(Widget&&) noexcept = default;
212
238 virtual void draw(Painter& painter, const Rect& rect);
239
258 virtual void handle(Event& event);
259
266 void continue_drag(Event& event);
267
276 virtual void resize(const Size& size);
277
289 void resize_by_ratio(DefaultDim hratio, DefaultDim vratio);
290
298 void resize_by_ratio(DefaultDim ratio)
299 {
300 resize_by_ratio(ratio, ratio);
301 }
302
311 virtual void scale(float hscale, float vscale)
312 {
313 detail::ignoreparam(hscale);
314 detail::ignoreparam(vscale);
315 }
316
324 void scale(float scale)
325 {
326 this->scale(scale, scale);
327 }
328
335 {
336 if (!parent_in_layout() && !in_layout())
337 m_user_requested_box.width(w);
338
339 resize(Size(w, height()));
340 }
341
348 {
349 if (!parent_in_layout() && !in_layout())
350 m_user_requested_box.height(h);
351
352 resize(Size(width(), h));
353 }
354
363 virtual void move(const Point& point);
364
370 void x(DefaultDim x)
371 {
372 if (!parent_in_layout() && !in_layout())
373 m_user_requested_box.x(x);
374
375 move(Point(x, y()));
376 }
377
383 void y(DefaultDim y)
384 {
385 if (!parent_in_layout() && !in_layout())
386 m_user_requested_box.y(y);
387
388 move(Point(x(), y));
389 }
390
398 void move_to_center(const Point& point);
399
409
417 virtual void hide();
418
424 virtual void show();
425
431 EGT_NODISCARD bool visible() const
432 {
433 return !flags().is_set(Widget::Flag::invisible);
434 }
435
439 void visible(bool value);
440
447 {
448 if (visible())
449 hide();
450 else
451 show();
452 }
453
459 EGT_NODISCARD bool active() const;
460
466 void active(bool value);
467
473 EGT_NODISCARD bool readonly() const
474 {
475 return flags().is_set(Widget::Flag::readonly);
476 }
477
487 void readonly(bool value);
488
495 {
496 readonly(!readonly());
497 }
498
502 void disable();
503
507 void enable();
508
515 EGT_NODISCARD bool disabled() const
516 {
517 return flags().is_set(Widget::Flag::disabled);
518 }
519
526 {
527 if (disabled())
528 enable();
529 else
530 disable();
531 }
532
540 void disabled(bool value)
541 {
542 if (value)
543 disable();
544 else
545 enable();
546 }
547
548 EGT_NODISCARD bool user_drag() const
549 {
550 return flags().is_set(Widget::Flag::user_drag);
551 }
552
553 void user_drag(bool value)
554 {
555 if (flags().is_set(Widget::Flag::user_drag) != value)
556 {
557 if (value)
558 flags().set(Widget::Flag::user_drag);
559 else
560 flags().clear(Widget::Flag::user_drag);
561 }
562 }
563
564 EGT_NODISCARD bool user_track_drag() const
565 {
566 return flags().is_set(Widget::Flag::user_track_drag);
567 }
568
569 void user_track_drag(bool value)
570 {
571 if (flags().is_set(Widget::Flag::user_track_drag) != value)
572 {
573 if (value)
574 flags().set(Widget::Flag::user_track_drag);
575 else
576 flags().clear(Widget::Flag::user_track_drag);
577 }
578 }
579
583 bool can_handle_event() const
584 {
585 return !m_widget_flags.is_set(Flag::readonly) &&
586 !m_widget_flags.is_set(Flag::invisible) &&
587 !m_widget_flags.is_set(Flag::disabled);
588 }
589
593 EGT_NODISCARD bool hit(const DisplayPoint& point) const
594 {
595 auto pos = display_to_local(point);
596 return local_box().intersect(pos);
597 }
598
606 void grab_mouse(bool value);
607
611 EGT_NODISCARD bool grab_mouse() const;
612
616 EGT_NODISCARD bool plane_window() const;
617
625 void autoresize(bool value);
626
630 EGT_NODISCARD bool autoresize() const;
631
635 EGT_NODISCARD bool frame() const;
636
640 EGT_NODISCARD bool clip() const;
641
649 void no_layout(bool value);
650
654 EGT_NODISCARD bool no_layout() const;
655
661 EGT_NODISCARD float alpha() const
662 {
663 return m_alpha;
664 }
665
674 void alpha(float alpha);
675
684 virtual void damage();
685
703 virtual void damage(const Rect& rect);
704
713 EGT_NODISCARD const Rect& box() const
714 {
715 return m_box;
716 }
717
726 void box(const Rect& rect);
727
731 EGT_NODISCARD const Rect& user_requested_box() const
732 {
733 return m_user_requested_box;
734 }
735
739 EGT_NODISCARD const Size& size() const
740 {
741 return box().size();
742 }
743
747 EGT_NODISCARD const Point& point() const
748 {
749 return box().point();
750 }
751
755 EGT_NODISCARD DefaultDim width() const { return m_box.width(); }
756
760 EGT_NODISCARD DefaultDim height() const { return m_box.height(); }
761
765 EGT_NODISCARD DefaultDim x() const { return m_box.x(); }
766
770 EGT_NODISCARD DefaultDim y() const { return m_box.y(); }
771
775 EGT_NODISCARD Point center() const { return box().center(); }
776
780 EGT_NODISCARD Palette::GroupId group() const;
781
793 void palette(const Palette& palette);
794
801 EGT_NODISCARD const Palette& palette() const;
802
810
814 EGT_NODISCARD bool has_palette() const { return (bool)m_palette; }
815
828 EGT_NODISCARD const Pattern& color(Palette::ColorId id) const;
829
839 EGT_NODISCARD const Pattern& color(Palette::ColorId id, Palette::GroupId group) const;
840
852 const Pattern& color,
853 Palette::GroupId group = Palette::GroupId::normal);
854
861 EGT_NODISCARD Image* background(bool allow_fallback = false) const;
862
870 EGT_NODISCARD Image* background(Palette::GroupId group,
871 bool allow_fallback = false) const;
872
879 void background(const Image& image,
880 Palette::GroupId group = Palette::GroupId::normal);
881
887 void reset_background(Palette::GroupId group = Palette::GroupId::normal);
888
893
897 EGT_NODISCARD const Widget* parent() const;
898
905 EGT_NODISCARD virtual Screen* screen() const;
906
910 EGT_NODISCARD virtual bool has_screen() const { return false; }
911
919 void align(const AlignFlags& a);
920
924 EGT_NODISCARD const AlignFlags& align() const { return m_align; }
925
929 AlignFlags& align() { return m_align; }
930
936 void padding(DefaultDim padding)
937 {
938 if (detail::change_if_diff<>(m_padding, padding))
939 {
940 damage();
941 parent_layout();
942 }
943 }
944
950 EGT_NODISCARD DefaultDim padding() const { return m_padding; }
951
957 void margin(DefaultDim margin)
958 {
959 if (detail::change_if_diff<>(m_margin, margin))
960 {
961 damage();
962 parent_layout();
963 }
964 }
965
971 EGT_NODISCARD DefaultDim margin() const { return m_margin; }
972
978 void border(DefaultDim border)
979 {
980 if (detail::change_if_diff<>(m_border, border))
981 {
982 damage();
983 parent_layout();
984 }
985 }
986
992 EGT_NODISCARD DefaultDim border() const { return m_border; }
993
997 void border_radius(float radius)
998 {
999 if (detail::change_if_diff<>(m_border_radius, radius))
1000 damage();
1001 }
1002
1006 EGT_NODISCARD float border_radius() const { return m_border_radius; }
1007
1014 {
1015 if (detail::change_if_diff<>(m_border_flags, flags))
1016 damage();
1017 }
1018
1024 EGT_NODISCARD Theme::BorderFlags border_flags() const { return m_border_flags; }
1025
1033 void ratio(DefaultDim ratio)
1034 {
1035 this->ratio(ratio, ratio);
1036 }
1037
1044 void ratio(DefaultDim horizontal,
1045 DefaultDim vertical)
1046 {
1047 auto a = detail::change_if_diff<>(m_horizontal_ratio, horizontal);
1048 auto b = detail::change_if_diff<>(m_vertical_ratio, vertical);
1049 if (a || b)
1050 parent_layout();
1051 }
1052
1059 {
1060 if (detail::change_if_diff<>(m_vertical_ratio, vertical))
1061 parent_layout();
1062 }
1063
1067 EGT_NODISCARD DefaultDim vertical_ratio() const { return m_vertical_ratio; }
1068
1075 {
1076 if (detail::change_if_diff<>(m_horizontal_ratio, horizontal))
1077 parent_layout();
1078 }
1079
1083 EGT_NODISCARD DefaultDim horizontal_ratio() const { return m_horizontal_ratio; }
1084
1090 void yratio(DefaultDim yratio)
1091 {
1092 if (detail::change_if_diff<>(m_yratio, yratio))
1093 parent_layout();
1094 }
1095
1099 EGT_NODISCARD DefaultDim yratio() const { return m_yratio; }
1100
1106 void xratio(DefaultDim xratio)
1107 {
1108 if (detail::change_if_diff<>(m_xratio, xratio))
1109 parent_layout();
1110 }
1111
1115 EGT_NODISCARD DefaultDim xratio() const { return m_xratio; }
1116
1123 EGT_NODISCARD virtual Size min_size_hint() const;
1124
1134 void min_size_hint(const Size& size)
1135 {
1136 if (detail::change_if_diff<>(m_min_size, size))
1137 parent_layout();
1138 }
1139
1147 virtual void paint(Painter& painter);
1148
1154 virtual void paint_to_file(const std::string& filename = {});
1155
1161 using WalkCallback = std::function<bool(Widget* widget, int level)>;
1162
1176 virtual void walk(const WalkCallback& callback, int level = 0);
1177
1183 void focus(bool value);
1184
1190 EGT_NODISCARD bool focus() const { return m_focus; }
1191
1204 void fill_flags(const Theme::FillFlags& flags)
1205 {
1206 if (detail::change_if_diff<>(m_fill_flags, flags))
1207 damage();
1208 }
1209
1215 EGT_NODISCARD const Theme::FillFlags& fill_flags() const
1216 {
1217 return m_fill_flags;
1218 }
1219
1226 {
1227 return m_fill_flags;
1228 }
1229
1237 EGT_NODISCARD const Theme& theme() const;
1238
1245 virtual void zorder_down();
1246
1253 virtual void zorder_up();
1254
1260 virtual void zorder_bottom();
1261
1267 virtual void zorder_top();
1268
1274 EGT_NODISCARD virtual size_t zorder() const;
1275
1283 virtual void zorder(size_t rank);
1284
1292 void detach();
1293
1297 EGT_NODISCARD Point to_parent(const Point& r) const;
1298
1304 EGT_NODISCARD Rect to_parent(const Rect& r) const
1305 {
1306 return Rect(to_parent(r.point()), r.size());
1307 }
1308
1313
1318 EGT_NODISCARD size_t moat() const;
1319
1330 EGT_NODISCARD virtual Rect content_area() const;
1331
1335 EGT_NODISCARD bool in_layout() const
1336 {
1337 return m_in_layout;
1338 }
1339
1350 virtual void layout();
1351
1357 Palette::ColorId border) const;
1358
1364 Palette::ColorId border) const;
1365
1375
1384 virtual Point display_to_local(const DisplayPoint& p) const;
1385
1392 EGT_NODISCARD const Font& font() const;
1393
1400 void font(const Font& font)
1401 {
1402 if (m_font && *m_font == font)
1403 return;
1404
1405 m_font = std::make_unique<Font>(font);
1406 damage();
1407 layout();
1408 parent_layout();
1409 }
1410
1418 {
1419 if (m_font)
1420 {
1421 m_font.reset();
1422 damage();
1423 layout();
1424 parent_layout();
1425 }
1426 }
1427
1431 bool has_font() const { return (bool)m_font; }
1432
1438 EGT_NODISCARD bool checked() const
1439 {
1440 return flags().is_set(Widget::Flag::checked);
1441 }
1442
1446 virtual void checked(bool value);
1447
1453 EGT_NODISCARD virtual std::string type() const;
1454
1458 using WidgetId = uint64_t;
1459
1467 EGT_NODISCARD WidgetId widgetid() const
1468 {
1469 return m_widgetid;
1470 }
1471
1490 virtual void on_screen_resized();
1491
1495 virtual void serialize(Serializer& serializer) const;
1496
1500 virtual void serialize_children(Serializer& serializer) const { detail::ignoreparam(serializer); }
1501
1505 virtual void deserialize_children(const Deserializer& deserializer) { detail::ignoreparam(deserializer); }
1506
1510 virtual void post_deserialize(Serializer::Properties& props) { detail::ignoreparam(props); }
1511
1512 ~Widget() noexcept override;
1513
1514protected:
1515
1520 virtual void damage_from_subordinate(const Rect& rect)
1521 {
1522 damage(rect);
1523 }
1524
1525 virtual Point point_from_subordinate(const Widget& subordinate) const
1526 {
1527 detail::ignoreparam(subordinate);
1528 return point();
1529 }
1530
1537 virtual void begin_draw()
1538 {
1539 assert(0);
1540 }
1541
1548 void begin_draw(Widget* parent)
1549 {
1550 parent->begin_draw();
1551 }
1552
1556 EGT_NODISCARD virtual Point to_subordinate(const Point& p) const
1557 {
1558 return p - point();
1559 }
1560
1564 EGT_NODISCARD Rect to_subordinate(Rect rect) const
1565 {
1566 rect.point(to_subordinate(rect.point()));
1567 return rect;
1568 }
1569
1576 virtual Point to_panel(const Point& p);
1577
1584 void zorder_down(const Widget* widget);
1585
1592 void zorder_up(const Widget* widget);
1593
1600 void zorder_bottom(const Widget* widget);
1601
1608 void zorder_top(const Widget* widget);
1609
1615 size_t zorder(const Widget* widget) const;
1616
1623 void zorder(const Widget* widget, size_t rank);
1624
1632 void add_damage(const Rect& rect);
1633
1637 using ChildDrawCallback = std::function<void(Painter& painter, Widget* widget)>;
1638
1643 {
1644 return m_special_child_draw_callback;
1645 }
1646
1655 {
1656 return parent->special_child_draw_callback();
1657 }
1658
1663 {
1664 m_special_child_draw_callback = std::move(func);
1665 }
1666
1676 void special_child_draw(Painter& painter, Widget* widget)
1677 {
1678 if (m_special_child_draw_callback)
1679 m_special_child_draw_callback(painter, widget);
1680 else if (parent())
1681 parent()->special_child_draw(painter, widget);
1682 }
1683
1690 {
1691 if (has_screen())
1692 return this;
1693
1694 if (parent())
1695 return parent()->find_screen();
1696
1697 return nullptr;
1698 }
1699
1705 EGT_NODISCARD const Widget* find_screen() const
1706 {
1707 if (has_screen())
1708 return this;
1709
1710 if (parent())
1711 return parent()->find_screen();
1712
1713 return nullptr;
1714 }
1715
1719 EGT_NODISCARD const Widget::Flags& flags() const { return m_widget_flags; }
1720
1728 Widget::Flags& flags() { return m_widget_flags; }
1729
1733 EGT_NODISCARD virtual bool top_level() const { return false; }
1734
1738 virtual void set_parent(Widget* parent);
1739
1744 EGT_NODISCARD Rect local_box() const
1745 {
1746 return size();
1747 }
1748
1756 void start_drag(Event& event);
1757
1764 bool accept_drag() const { return internal_drag() || user_drag(); }
1765
1766 virtual bool internal_drag() const { return false; }
1767
1776 bool track_drag() const { return internal_track_drag() || user_track_drag(); }
1777
1778 virtual bool internal_track_drag() const { return false; }
1779
1784
1789
1795 Widget* m_parent{nullptr};
1796
1800 WidgetId m_widgetid{0};
1801
1805 EGT_NODISCARD bool parent_in_layout();
1806
1811
1816
1820 bool m_in_layout{false};
1821
1833
1835 void draw_subordinate(Painter& painter, const Rect& crect, Widget* child);
1836
1839
1841 using SubordinatesArray = std::list<std::shared_ptr<Widget>>;
1842
1845
1847 EGT_NODISCARD const detail::Range<SubordinatesArray>& children() const
1848 {
1849 return m_children;
1850 }
1851
1854 {
1855 return m_children;
1856 }
1857
1860
1863 {
1864 return m_components;
1865 }
1866
1869 {
1870 return m_components;
1871 }
1872
1875
1883 {
1884 m_children.begin(m_subordinates.begin());
1885 m_children.end(m_components_begin);
1886 m_components.begin(m_components_begin);
1887 m_components.end(m_subordinates.end());
1888 }
1889
1892 {
1893 return widget.component() ? components() : children();
1894 }
1895
1897 EGT_NODISCARD const detail::Range<SubordinatesArray>& range_from_widget(const Widget& widget) const
1898 {
1899 return widget.component() ? components() : children();
1900 }
1901
1903 void add_component(Widget& widget);
1904
1907
1909 void component(bool value);
1910
1912 EGT_NODISCARD bool component() const;
1919 SubordinatesArray::iterator m_components_begin;
1920
1923
1925 bool m_in_draw{false};
1926
1927private:
1928
1938 std::unique_ptr<Palette> m_palette;
1939
1943 ImageGroup m_backgrounds{"bg"};
1944
1948 Widget::Flags m_widget_flags{};
1949
1953 AlignFlags m_align{};
1954
1958 DefaultDim m_padding{0};
1959
1963 DefaultDim m_border{0};
1964
1968 float m_border_radius{};
1969
1973 Theme::BorderFlags m_border_flags{};
1974
1978 DefaultDim m_margin{0};
1979
1983 DefaultDim m_xratio{0};
1984
1988 DefaultDim m_yratio{0};
1989
1993 DefaultDim m_horizontal_ratio{0};
1994
1998 DefaultDim m_vertical_ratio{0};
1999
2003 bool m_focus{false};
2004
2008 float m_alpha{1.0f};
2009
2013 Theme::FillFlags m_fill_flags{};
2014
2018 void init(void);
2019
2026 std::unique_ptr<Font> m_font;
2027
2031 void deserialize(Serializer::Properties& props);
2032
2033 friend class Frame;
2034};
2035
2037template<>
2038EGT_API const std::pair<Widget::Flag, char const*> detail::EnumStrings<Widget::Flag>::data[15];
2039
2041EGT_API std::ostream& operator<<(std::ostream& os, const Widget::Flag& flag);
2043EGT_API std::ostream& operator<<(std::ostream& os, const Widget::Flags& flags);
2044
2045}
2046}
2047
2048#endif
Alignment flags.
Definition widgetflags.h:379
Definition serialize.h:200
EGT_NODISCARD constexpr bool is_set(const T flag) const noexcept
Test if the specified flag is set.
Definition flagsbase.h:64
Utility class for managing a set of flags with the ability to observe changes to the flags.
Definition flags.h:40
bool clear(T flag) noexcept
Clear a single flag.
Definition flags.h:125
bool set(T flag) noexcept
Set a single flag.
Definition flags.h:107
Manages a font and properties of a font.
Definition font.h:35
A Frame is a Widget that has children widgets.
Definition frame.h:45
Definition imagegroup.h:25
Raster image resource used for drawing or displaying.
Definition image.h:39
Base object class with fundamental properties.
Definition object.h:32
Drawing interface for 2D graphics.
Definition painter.h:45
Color palette that contains a 2 dimensional array of colors.
Definition palette.h:40
GroupId
Used to define a category of patterns that usually relate to the state of a widget.
Definition palette.h:219
ColorId
The Pattern identifier in the Palette.
Definition palette.h:239
A Pattern which can store one or more colors at different offsets (steps) which can be used to create...
Definition pattern.h:55
EGT_NODISCARD constexpr const SizeType< Dim, DimCompat > & size() const noexcept
Get the SizeType of the rectangle.
Definition geometry.h:738
EGT_NODISCARD constexpr const PointType< Dim, DimCompat > & point() const noexcept
Get the PointType of the rectangle.
Definition geometry.h:722
Manages one of more buffers that make up a Screen.
Definition screen.h:34
std::vector< Rect > DamageArray
Type used for damage arrays.
Definition screen.h:40
Abstract base serializer class.
Definition serialize.h:34
std::list< std::tuple< std::string, std::string, Serializer::Attributes > > Properties
Definition serialize.h:47
Signal class used for defining a signal and dispatching events.
Definition signal.h:30
Customizable characteristics for drawing widgets.
Definition theme.h:146
Base Widget class.
Definition widget.h:53
SubordinatesArray m_subordinates
Array of subordinates widgets split in child widgets and component widgets.
Definition widget.h:1844
bool track_drag() const
Tell the continue_drag() method whether the widget tracks 'pointer_drag*' events once they have cross...
Definition widget.h:1776
Signal on_hide
Invoked when a widget is hidden.
Definition widget.h:176
void y(DefaultDim y)
Set the Y coordinate of the box.
Definition widget.h:383
EGT_NODISCARD bool active() const
Get the active state.
void move_to_center(const Point &point)
Move the widget to the specified center point.
virtual void zorder_bottom()
Move the widget to the bottom.
void box(const Rect &rect)
Change the bounding box of the widget.
EGT_NODISCARD bool disabled() const
Return the disabled state of the widget.
Definition widget.h:515
EGT_NODISCARD const AlignFlags & align() const
Get the alignment.
Definition widget.h:924
virtual void post_deserialize(Serializer::Properties &props)
Resume deserializing of the widget after its children have been deserialized.
Definition widget.h:1510
virtual EGT_NODISCARD Screen * screen() const
Get a pointer to the Screen instance, using using a parent as necessary.
void color(Palette::ColorId id, const Pattern &color, Palette::GroupId group=Palette::GroupId::normal)
Add a color to the widget's instance palette.
virtual void move(const Point &point)
Move the Widget to a new position.
void font(const Font &font)
Set the widget Font.
Definition widget.h:1400
void min_size_hint(const Size &size)
Set the minimum size hint for the Widget.
Definition widget.h:1134
EGT_NODISCARD bool checked() const
Get the boolean checked state of the a widget.
Definition widget.h:1438
void horizontal_ratio(DefaultDim horizontal)
Set the horizontal ratio relative to parent.
Definition widget.h:1074
virtual EGT_NODISCARD std::string type() const
Returns a string representation of the type of this widget.
EGT_NODISCARD const Widget * parent() const
Get a pointer to the parent Widget, or nullptr if none exists.
virtual void checked(bool value)
Set the checked state of the widget.
EGT_NODISCARD bool readonly() const
Get the readonly state of the widget.
Definition widget.h:473
EGT_NODISCARD bool has_palette() const
Check whether the widget has a custom palette.
Definition widget.h:814
~Widget() noexcept override
virtual void damage(const Rect &rect)
Mark the specified rect as a damaged area of the widget.
void alpha(float alpha)
Set the alpha property.
void begin_draw(Widget *parent)
Call the begin_draw() method of the parent.
Definition widget.h:1548
EGT_NODISCARD const Widget * find_screen() const
Starting from this Widget, find the Widget that has a Screen.
Definition widget.h:1705
void border_radius(float radius)
Set the border radius.
Definition widget.h:997
void add_damage(const Rect &rect)
Add damage to the damage array.
void active(bool value)
Set the active state.
void no_layout(bool value)
Set the no_layout state.
EGT_NODISCARD bool no_layout() const
Return the no_layout state of the widget.
void reset_font()
Reset the widget's Font.
Definition widget.h:1417
EGT_NODISCARD DefaultDim margin() const
Get the margin width.
Definition widget.h:971
virtual void walk(const WalkCallback &callback, int level=0)
Walk the Widget tree and call callback with each Widget.
Rect m_box
Bounding box.
Definition widget.h:1783
EGT_NODISCARD Image * background(bool allow_fallback=false) const
Get the background image, if any, for the current group.
EGT_NODISCARD detail::Range< SubordinatesArray > & range_from_widget(const Widget &widget)
Return either components() or children() depending on widget.component()
Definition widget.h:1891
virtual bool internal_drag() const
Definition widget.h:1766
virtual void begin_draw()
Cause the widget to draw itself and all of its children.
Definition widget.h:1537
EGT_NODISCARD DefaultDim width() const
Width of the widget's box().
Definition widget.h:755
virtual void layout()
Perform layout of the Widget.
Widget * find_screen()
Starting from this Widget, find the Widget that has a Screen.
Definition widget.h:1689
void user_track_drag(bool value)
Definition widget.h:569
virtual void deserialize_children(const Deserializer &deserializer)
Deserialize the children of this widget.
Definition widget.h:1505
bool accept_drag() const
Tell the start_drag() method whether the widget accepts 'pointer_drag*' events.
Definition widget.h:1764
void zorder_up(const Widget *widget)
Move the specified widget zorder up relative to other widgets with the same parent.
EGT_NODISCARD DefaultDim x() const
X coordinate of the widget's box().
Definition widget.h:765
virtual void zorder_down()
Move this widgets zorder down relative to other widgets with the same parent.
void parent_layout()
Call our parent to do a layout.
void readonly(bool value)
Set the readonly state of the widget.
virtual void zorder(size_t rank)
Set the zorder of the widget.
void special_child_draw_callback(ChildDrawCallback func)
Set the special child draw callback.
Definition widget.h:1662
virtual EGT_NODISCARD size_t zorder() const
Get the zorder of the widget.
void disable_toggle()
Toggle the disabled state.
Definition widget.h:525
egt::Flags< Widget::Flag > Flags
Widget flags.
Definition widget.h:157
EGT_NODISCARD bool user_track_drag() const
Definition widget.h:564
void grab_mouse(bool value)
Set the grab_mouse state.
virtual void paint(Painter &painter)
Paint the Widget using a Painter.
EGT_NODISCARD detail::Range< SubordinatesArray > & components()
Return the array of components widgets.
Definition widget.h:1868
EGT_NODISCARD Theme::BorderFlags border_flags() const
Get the border flags.
Definition widget.h:1024
void scale(float scale)
Set the scale of the widget.
Definition widget.h:324
void update_subordinates_ranges()
Update the 'm_children' and 'm_components' members.
Definition widget.h:1882
virtual EGT_NODISCARD bool top_level() const
Is this widget a top level widget?
Definition widget.h:1733
EGT_NODISCARD detail::Range< SubordinatesArray > & children()
Return the array of child widgets.
Definition widget.h:1853
void enable()
Set the disabled state to false.
virtual void set_parent(Widget *parent)
Set this widget's parent.
void vertical_ratio(DefaultDim vertical)
Set the vertical ratio relative to parent.
Definition widget.h:1058
EGT_NODISCARD const Rect & user_requested_box() const
Get the box corresponding to the user requested one, not the actual one.
Definition widget.h:731
Signal on_gain_focus
Invoked when the widget gains focus.
Definition widget.h:167
virtual EGT_NODISCARD bool has_screen() const
Does this Widget have a screen?
Definition widget.h:910
virtual Point display_to_local(const DisplayPoint &p) const
Convert a display point to a local point.
EGT_NODISCARD const Size & size() const
Get the size of the widget's box().
Definition widget.h:739
void x(DefaultDim x)
Set the X coordinate of the box.
Definition widget.h:370
EGT_NODISCARD Point to_parent(const Point &r) const
Convert a point with a local origin to a parent origin.
virtual Point to_panel(const Point &p)
Convert a local point to the coordinate system of the current panel.
void palette(const Palette &palette)
Set the widget instance Palette.
void zorder_top(const Widget *widget)
Move the specified widget zorder to the top of the current list of widgets with the same parent.
void component(bool value)
Set the component flag.
EGT_NODISCARD ChildDrawCallback special_child_draw_callback() const
Get the special child draw callback.
Definition widget.h:1642
DisplayPoint local_to_display(const Point &p) const
Convert a local point to a display point.
EGT_NODISCARD const detail::Range< SubordinatesArray > & children() const
Return the array of child widgets.
Definition widget.h:1847
std::list< std::shared_ptr< Widget > > SubordinatesArray
Helper type for an array of subordinate widgets.
Definition widget.h:1841
Rect m_user_requested_box
Keep track of the box requested by the user.
Definition widget.h:1788
EGT_NODISCARD Point center() const
Get the center point of the widget's box().
Definition widget.h:775
Widget * parent()
Get a pointer to the parent Widget, or nullptr if none exists.
void border(DefaultDim border)
Set the border width.
Definition widget.h:978
void autoresize(bool value)
Set the autoresize state.
EGT_NODISCARD Palette::GroupId group() const
Get the current Palette::GroupId depending on the widget's state.
void focus(bool value)
Set the focus state.
EGT_NODISCARD const Theme & theme() const
Get the Widget Theme.
EGT_NODISCARD DefaultDim y() const
Y coordinate of the widget's box().
Definition widget.h:770
uint64_t WidgetId
Type used to identify a unique Widget ID.
Definition widget.h:1458
EGT_NODISCARD float alpha() const
Get the alpha property.
Definition widget.h:661
EGT_NODISCARD bool component() const
Get the component status.
void fill_flags(const Theme::FillFlags &flags)
Set the fill flags.
Definition widget.h:1204
EGT_NODISCARD bool grab_mouse() const
Return the grab_mouse state of the widget.
Widget(Serializer::Properties &props) noexcept
Definition widget.h:197
Signal on_checked_changed
Event signal.
Definition widget.h:164
EGT_NODISCARD const detail::Range< SubordinatesArray > & components() const
Return the array of components widgets.
Definition widget.h:1862
virtual bool internal_track_drag() const
Definition widget.h:1778
virtual void show()
Show the Widget.
Widget(Serializer::Properties &props, bool is_derived) noexcept
void start_drag(Event &event)
Handle 'pointer_drag_start' events and decide whether they are caught by this widget.
void background(const Image &image, Palette::GroupId group=Palette::GroupId::normal)
Add an image background to the widget's box.
void user_drag(bool value)
Definition widget.h:553
detail::Range< SubordinatesArray > m_components
Array of component widgets in the order they were added.
Definition widget.h:1874
Size m_min_size
Minimum size of the widget when not an empty value.
Definition widget.h:1815
virtual void serialize_children(Serializer &serializer) const
Serialize the widget's children to the specified serializer.
Definition widget.h:1500
EGT_NODISCARD bool plane_window() const
Return the plane_window state of the widget.
EGT_NODISCARD WidgetId widgetid() const
Get the unique id of the widget.
Definition widget.h:1467
EGT_NODISCARD const Palette & palette() const
Get the widget palette.
void border_flags(const Theme::BorderFlags &flags)
Set the border flags.
Definition widget.h:1013
Widget(const Widget &)=delete
void padding(DefaultDim padding)
Set the padding width.
Definition widget.h:936
void remove_component(Widget *widget)
Remove a component.
void disable()
Set the disabled state to true.
void height(DefaultDim h)
Change the height.
Definition widget.h:347
void zorder_down(const Widget *widget)
Move the specified widget zorder down relative to other widgets with the same parent.
EGT_NODISCARD bool user_drag() const
Definition widget.h:548
EGT_NODISCARD bool frame() const
Return the frame state of the widget.
EGT_NODISCARD bool parent_in_layout()
Indicate if our parent is computing the layout.
EGT_NODISCARD size_t moat() const
Get the sum of the margin(), padding(), and border() around the content of the widget.
SubordinatesArray::iterator m_components_begin
Iterator for the beginning of components which are positionned after children in the subordinates arr...
Definition widget.h:1919
EGT_NODISCARD DefaultDim horizontal_ratio() const
Get the horizontal ratio relative to parent.
Definition widget.h:1083
EGT_NODISCARD const Widget::Flags & flags() const
Get a const ref of the flags.
Definition widget.h:1719
EGT_NODISCARD bool clip() const
Return the clip state of the widget.
void reset_palette()
Clear the widget instance palette.
EGT_NODISCARD bool autoresize() const
Return the autoresize state of the widget.
EGT_NODISCARD const Theme::FillFlags & fill_flags() const
Get the fill flags.
Definition widget.h:1215
EGT_NODISCARD const Font & font() const
Get the widget Font.
detail::Range< SubordinatesArray > m_children
Array of child widgets in the order they were added.
Definition widget.h:1859
virtual EGT_NODISCARD Rect content_area() const
Return the area that content is allowed to be positioned into.
EGT_NODISCARD Image * background(Palette::GroupId group, bool allow_fallback=false) const
Get the background image, if any, for the given group.
EGT_NODISCARD const Point & point() const
Get the origin of the widget's box().
Definition widget.h:747
Widget(Widget &&) noexcept=default
EGT_NODISCARD DefaultDim vertical_ratio() const
Get the vertical ratio relative to parent.
Definition widget.h:1067
Widget(const Rect &rect={}, const Widget::Flags &flags={}) noexcept
EGT_NODISCARD const Pattern & color(Palette::ColorId id) const
Get a Widget color.
virtual EGT_NODISCARD Size min_size_hint() const
Get a minimum size hint for the Widget.
DisplayPoint display_origin()
Get the display origin of the Widget.
EGT_NODISCARD bool focus() const
Get the current focus state.
Definition widget.h:1190
virtual void paint_to_file(const std::string &filename={})
Draw the widget to a file.
void deserialize_leaf(Serializer::Properties &props)
Deserialize widget properties that require to call overridden methods.
void width(DefaultDim w)
Change the width.
Definition widget.h:334
Theme::FillFlags & fill_flags()
Get a modifiable fill flags reference.
Definition widget.h:1225
void zorder_bottom(const Widget *widget)
Move the specified widget zorder to the bottom of the current list of widgets with the same parent.
EGT_NODISCARD bool hit(const DisplayPoint &point) const
Returns true if the DisplayPoint is within the widget box.
Definition widget.h:593
void xratio(DefaultDim xratio)
Set the X position ratio relative to parent.
Definition widget.h:1106
EGT_NODISCARD DefaultDim padding() const
Return the padding width.
Definition widget.h:950
EGT_NODISCARD ChildDrawCallback special_child_draw_callback(Widget *parent) const
Get the child draw callback of the parent.
Definition widget.h:1654
void disabled(bool value)
Set the disabled state.
Definition widget.h:540
void ratio(DefaultDim horizontal, DefaultDim vertical)
Set the size ratio relative to parent.
Definition widget.h:1044
std::function< void(Painter &painter, Widget *widget)> ChildDrawCallback
Helper type that defines the special draw child callback.
Definition widget.h:1637
void draw_circle(Painter &painter, Palette::ColorId bg, Palette::ColorId border) const
Helper function to draw this widget's circle using the appropriate theme.
EGT_NODISCARD DefaultDim height() const
Height of the widget's box().
Definition widget.h:760
void detach()
Detach this widget from its parent.
Signal on_show
Invoked when a widget is shown.
Definition widget.h:173
virtual void hide()
Hide the Widget.
EGT_NODISCARD float border_radius() const
Get the border radius.
Definition widget.h:1006
void readonly_toggle()
Toggle the readonly state.
Definition widget.h:494
EGT_NODISCARD const detail::Range< SubordinatesArray > & range_from_widget(const Widget &widget) const
Return either components() or children() depending on widget.component()
Definition widget.h:1897
EGT_NODISCARD DefaultDim border() const
Get the border width.
Definition widget.h:992
virtual void scale(float hscale, float vscale)
Set the scale of the widget.
Definition widget.h:311
void move_to_center()
Move the widget to the center of its parent.
EGT_NODISCARD bool visible() const
Get the visible state of the widget.
Definition widget.h:431
virtual void zorder_up()
Move this widgets zorder up relative to other widgets with the same parent.
void add_component(Widget &widget)
Add a component.
virtual void damage()
Damage the box() of the widget and cause a redraw.
EGT_NODISCARD Rect local_box() const
Get the local box which is the same size as box(), but with the origin zeroed.
Definition widget.h:1744
EGT_NODISCARD Rect to_subordinate(Rect rect) const
Definition widget.h:1564
size_t zorder(const Widget *widget) const
Get the zorder of the widget.
Widget(Frame &parent, const Rect &rect={}, const Widget::Flags &flags={}) noexcept
void draw_box(Painter &painter, Palette::ColorId bg, Palette::ColorId border) const
Helper function to draw this widget's box using the appropriate theme.
Screen::DamageArray m_damage
The damage array for this widget.
Definition widget.h:1922
Widget & operator=(const Widget &)=delete
AlignFlags & align()
Get the alignment.
Definition widget.h:929
void visible(bool value)
Set the visible state.
bool has_font() const
Check whether the widget has a custom Font.
Definition widget.h:1431
bool can_handle_event() const
Returns true if the widget is capable of handling an event.
Definition widget.h:583
void reset_background(Palette::GroupId group=Palette::GroupId::normal)
Remove an image background from the widget's box.
Signal on_lost_focus
Invoked when the widget loses focus.
Definition widget.h:170
EGT_NODISCARD DefaultDim xratio() const
Get the X position ratio relative to parent.
Definition widget.h:1115
virtual Point point_from_subordinate(const Widget &subordinate) const
Definition widget.h:1525
virtual void serialize(Serializer &serializer) const
Serialize the widget to the specified serializer.
void yratio(DefaultDim yratio)
Set the Y position ratio relative to parent.
Definition widget.h:1090
EGT_NODISCARD bool in_layout() const
Indicate if the Widget is computing the layout or not.
Definition widget.h:1335
void align(const AlignFlags &a)
Align the widget.
Widget::Flags & flags()
Get a modifiable ref of the flags.
Definition widget.h:1728
void ratio(DefaultDim ratio)
Set the size ratio relative to parent.
Definition widget.h:1033
Flag
Common flags used for various widget properties.
Definition widget.h:60
virtual void zorder_top()
Move the widget to the top.
EGT_NODISCARD const Pattern & color(Palette::ColorId id, Palette::GroupId group) const
Get a Widget color.
void special_child_draw(Painter &painter, Widget *widget)
Special draw function that can be invoked when drawing each child.
Definition widget.h:1676
EGT_NODISCARD Rect to_parent(const Rect &r) const
Convert a point in a rect a local origin to a parent origin.
Definition widget.h:1304
void zorder(const Widget *widget, size_t rank)
Set the zorder of the widget.
EGT_NODISCARD const Rect & box() const
Bounding box for the Widget.
Definition widget.h:713
EGT_NODISCARD DefaultDim yratio() const
Get the Y position ratio relative to parent.
Definition widget.h:1099
virtual void on_screen_resized()
Called from ComposerScreen::resize().
ChildDrawCallback m_special_child_draw_callback
Used internally for calling the special child draw function.
Definition widget.h:1838
void margin(DefaultDim margin)
Set the margin width.
Definition widget.h:957
void visible_toggle()
Toggle the visibility state.
Definition widget.h:446
std::function< bool(Widget *widget, int level)> WalkCallback
Callback definition used by walk().
Definition widget.h:1161
virtual EGT_NODISCARD Point to_subordinate(const Point &p) const
Convert a point with an origin of the current widget to subordinate origin.
Definition widget.h:1556
Utility class to allow range loops from a subset of a container.
Definition range.h:26
void begin(typename T::iterator begin) noexcept
Definition range.h:30
void end(typename T::iterator end) noexcept
Definition range.h:50
EGT_API std::ostream & operator<<(std::ostream &os, const Color &color)
Overloaded std::ostream insertion operator.
int DefaultDim
Define the default dimension type used for geometry.
Definition geometry.h:34
EGT framework namespace.
Definition animation.h:24
A single event that has information about the event and state for the event.
Definition event.h:255
When using enum_to_string() and enum_from_string(), this type needs to be defined and specialized to ...
Definition enum.h:48