]> git.localhorst.tv Git - blobs.git/blob - src/ui/Widget.hpp
fix layout
[blobs.git] / src / ui / Widget.hpp
1 #ifndef BLOBS_UI_WIDGET_HPP_
2 #define BLOBS_UI_WIDGET_HPP_
3
4 #include "../math/glm.hpp"
5
6
7 namespace blobs {
8 namespace app {
9         struct Assets;
10 }
11 namespace graphics {
12         class Viewport;
13 }
14 namespace ui {
15
16 class Widget {
17
18 public:
19         Widget();
20         virtual ~Widget();
21
22         Widget(const Widget &) = delete;
23         Widget &operator =(const Widget &) = delete;
24
25         Widget(Widget &&) = delete;
26         Widget &operator =(Widget &&) = delete;
27
28 public:
29         void SetParent(Widget &) noexcept;
30         bool HasParent() const noexcept { return parent; }
31         Widget &GetParent() noexcept { return *parent; }
32         const Widget &GetParent() const noexcept { return *parent; }
33
34         Widget *Position(const glm::vec2 &p) noexcept { pos = p; return this; }
35         const glm::vec2 &Position() const noexcept { return pos; }
36
37         Widget *ZIndex(float z) noexcept { z_index = z; return this; }
38         float ZIndex() const noexcept { return z_index; }
39
40         bool DirtyLayout() const noexcept { return dirty_layout; }
41         void BreakLayout() noexcept;
42         void BreakParentLayout() noexcept;
43         void Layout();
44
45         virtual glm::vec2 Size() = 0;
46         virtual void Draw(app::Assets &, graphics::Viewport &) noexcept = 0;
47
48 private:
49         virtual void FixLayout() { }
50
51 private:
52         Widget *parent;
53         glm::vec2 pos;
54         float z_index;
55         bool dirty_layout;
56
57 };
58
59 }
60 }
61
62 #endif