-
-
Notifications
You must be signed in to change notification settings - Fork 136
/
Copy pathview.h
146 lines (107 loc) · 4.52 KB
/
view.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#pragma once
#include <karm-gfx/icon.h>
#include <karm-image/picture.h>
#include <karm-scene/base.h>
#include <karm-text/prose.h>
#include "node.h"
namespace Karm::Ui {
// MARK: Base ------------------------------------------------------------------
template <typename Crtp>
struct View : public LeafNode<Crtp> {
Math::Recti _bound;
Math::Recti bound() override {
return _bound;
}
void layout(Math::Recti bound) override {
_bound = bound;
}
};
// MARK: Text ------------------------------------------------------------------
struct TextStyles {
private:
TextStyles() = default;
public:
static Text::ProseStyle displayLarge();
static Text::ProseStyle displayMedium();
static Text::ProseStyle displaySmall();
static Text::ProseStyle headlineLarge();
static Text::ProseStyle headlineMedium();
static Text::ProseStyle headlineSmall();
static Text::ProseStyle titleLarge();
static Text::ProseStyle titleMedium();
static Text::ProseStyle titleSmall();
static Text::ProseStyle labelLarge();
static Text::ProseStyle labelMedium();
static Text::ProseStyle labelSmall();
static Text::ProseStyle bodyLarge();
static Text::ProseStyle bodyMedium();
static Text::ProseStyle bodySmall();
static Text::ProseStyle codeLarge();
static Text::ProseStyle codeMedium();
static Text::ProseStyle codeSmall();
};
Child text(Text::ProseStyle style, Str text);
Child text(Str text);
Child text(Rc<Karm::Text::Prose> prose);
template <typename... Args>
inline Child text(Text::ProseStyle style, Str format, Args&&... args) {
return text(style, Io::format(format, std::forward<Args>(args)...));
}
template <typename... Args>
inline Child text(Str format, Args&&... args) {
return text(Io::format(format, std::forward<Args>(args)...));
}
#define DEF_STYLE(STYLE) \
inline Child STYLE(Str text) { return Karm::Ui::text(TextStyles::STYLE(), text); } \
inline Child STYLE(Gfx::Color color, Str text) { return Karm::Ui::text(TextStyles::STYLE().withColor(color), text); } \
template <typename... Args> \
inline Child STYLE(Str format, Args&&... args) { \
return text(TextStyles::STYLE(), format, std::forward<Args>(args)...); \
} \
template <typename... Args> \
inline Child STYLE(Gfx::Color color, Str format, Args&&... args) { \
return text(TextStyles::STYLE().withColor(color), format, std::forward<Args>(args)...); \
}
DEF_STYLE(displayLarge)
DEF_STYLE(displayMedium)
DEF_STYLE(displaySmall)
DEF_STYLE(headlineLarge)
DEF_STYLE(headlineMedium)
DEF_STYLE(headlineSmall)
DEF_STYLE(titleLarge)
DEF_STYLE(titleMedium)
DEF_STYLE(titleSmall)
DEF_STYLE(labelLarge)
DEF_STYLE(labelMedium)
DEF_STYLE(labelSmall)
DEF_STYLE(bodyLarge)
DEF_STYLE(bodyMedium)
DEF_STYLE(bodySmall)
DEF_STYLE(codeLarge)
DEF_STYLE(codeMedium)
DEF_STYLE(codeSmall)
#undef DEF_STYLE
// MARK: Icon ------------------------------------------------------------------
Child icon(Gfx::Icon icon, Opt<Gfx::Color> color = NONE);
Child icon(Mdi::Icon icon, f64 size, Opt<Gfx::Color> color = NONE);
// MARK: Image -----------------------------------------------------------------
Child image(Image::Picture image);
Child image(Image::Picture image, Math::Radiif radii);
// MARK: Canvas ----------------------------------------------------------------
using OnPaint = Func<void(Gfx::Canvas& g, Math::Vec2i size)>;
Child canvas(OnPaint onPaint);
Child canvas(Rc<Scene::Node> child, Scene::PaintOptions options = {});
// MARK: Blur ------------------------------------------------------------------
Child backgroundFilter(Gfx::Filter f, Child child);
inline auto backgroundFilter(Gfx::Filter f) {
return [=](Child child) {
return backgroundFilter(f, child);
};
}
Child foregroundFilter(Gfx::Filter f, Child child);
inline auto foregroundFilter(Gfx::Filter f) {
return [=](Child child) {
return foregroundFilter(f, child);
};
}
} // namespace Karm::Ui