-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrender.hxx
More file actions
93 lines (77 loc) · 2.66 KB
/
render.hxx
File metadata and controls
93 lines (77 loc) · 2.66 KB
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
#ifndef GITCODE_RENDER_PREVIEW_HXX
#define GITCODE_RENDER_PREVIEW_HXX
#include <string>
#include <string_view>
#include <vector>
namespace gitcode::render {
enum class Tone {
kNeutral,
kSoftAccent,
kWarning,
};
struct TitlePresentation {
std::string text;
Tone tone = Tone::kNeutral;
bool underline = false;
bool center_aligned = true;
};
struct PreviewLine {
int number = 0;
std::string text;
bool highlighted = false;
};
struct RenderSpan {
std::string text;
Tone tone = Tone::kNeutral;
};
struct PreviewDocument {
std::string language;
bool fold_gutter_visible = false;
std::vector<PreviewLine> lines;
};
struct PreviewSettings {
bool phone_layout = true;
bool clickable_title = true;
bool fold_supported = false;
};
struct ViewportMetrics {
int width = 0;
int height = 0;
bool compact = false;
};
struct Palette {
std::string foreground;
std::string muted;
std::string soft_accent;
std::string warning;
};
class PreviewRenderer {
public:
explicit PreviewRenderer(Palette palette = {});
[[nodiscard]] TitlePresentation BuildTitle(std::string_view workspace_name,
const PreviewSettings& settings,
const ViewportMetrics& viewport) const;
[[nodiscard]] PreviewDocument BuildDocument(std::string_view language,
const PreviewSettings& settings,
const std::vector<std::string>& source_lines) const;
private:
Palette palette_;
};
[[nodiscard]] TitlePresentation BuildMobileTitle(std::string_view workspace_name,
bool clickable);
[[nodiscard]] TitlePresentation BuildTabletTitle(std::string_view workspace_name);
[[nodiscard]] PreviewDocument BuildCodePreview(std::string_view language,
bool fold_supported,
const std::vector<std::string>& source_lines);
[[nodiscard]] std::string RenderPlainTextNotice(std::string_view extension);
[[nodiscard]] std::string RenderLineNumber(int line_number);
[[nodiscard]] std::string RenderStatusBadge(Tone tone,
std::string_view text);
[[nodiscard]] RenderSpan RenderLanguageChip(std::string_view language,
bool legacy_mode);
[[nodiscard]] RenderSpan RenderSyncStatus(bool stale);
[[nodiscard]] Palette DefaultPalette();
[[nodiscard]] ViewportMetrics ClassifyViewport(int width,
int height);
} // namespace gitcode::render
#endif // GITCODE_RENDER_PREVIEW_HXX