@ng-native/desktop 0.26.0 → 0.27.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -3
- package/bin/app-config.mjs +1 -0
- package/bin/archive.mjs +166 -0
- package/bin/autolink.mjs +61 -30
- package/bin/cli.mjs +127 -27
- package/bin/host.mjs +255 -58
- package/bin/package-linux.mjs +1394 -0
- package/bin/package.mjs +171 -35
- package/bin/plist.mjs +6 -2
- package/bin/png-icon.mjs +315 -0
- package/bin/prebuilt.mjs +147 -26
- package/bin/toolchain.mjs +258 -19
- package/native/CMakeLists.txt +64 -6
- package/native/appkit/CMakeLists.txt +2 -1
- package/native/appkit/appkit-backend.h +1 -0
- package/native/appkit/appkit-backend.mm +13 -0
- package/native/appkit/header-toolbar.mm +28 -25
- package/native/appkit/host-view.h +10 -0
- package/native/appkit/host-view.mm +146 -40
- package/native/appkit/input-replay.h +6 -0
- package/native/appkit/input-replay.mm +21 -12
- package/native/appkit/main.mm +11 -7
- package/native/appkit/native-controls.mm +13 -1
- package/native/appkit/split-view.mm +7 -13
- package/native/appkit/text-input-field.h +4 -0
- package/native/appkit/text-input-field.mm +20 -1
- package/native/cmake/curl.cmake +79 -0
- package/native/cmake/libraries/react-native-reanimated.cmake +5 -0
- package/native/cmake/libraries/react-native-worklets.cmake +5 -0
- package/native/cmake/linked-modules.cmake +20 -4
- package/native/cmake/react-native.cmake +18 -1
- package/native/core/include/ngn/accent-colors.h +38 -0
- package/native/core/include/ngn/accessibility-relations.h +65 -0
- package/native/core/include/ngn/accessibility.h +26 -0
- package/native/core/include/ngn/animated-frame-loop.h +56 -0
- package/native/core/include/ngn/app-info.h +24 -8
- package/native/core/include/ngn/app-menus.h +14 -1
- package/native/core/include/ngn/app-windows.h +15 -2
- package/native/core/include/ngn/aria-role.h +96 -0
- package/native/core/include/ngn/audio.h +2 -0
- package/native/core/include/ngn/camera.h +9 -0
- package/native/core/include/ngn/control-sizes.h +7 -2
- package/native/core/include/ngn/crash-report.h +31 -0
- package/native/core/include/ngn/curl-network.h +93 -0
- package/native/core/include/ngn/dbus-menu.h +39 -0
- package/native/core/include/ngn/default-menu.h +36 -0
- package/native/core/include/ngn/desktop-expo.h +7 -1
- package/native/core/include/ngn/desktop-modules.h +22 -0
- package/native/core/include/ngn/desktop-props.h +21 -1
- package/native/core/include/ngn/desktop-view-props.h +6 -0
- package/native/core/include/ngn/focus-order.h +10 -0
- package/native/core/include/ngn/header-bar.h +22 -0
- package/native/core/include/ngn/host-os.h +6 -0
- package/native/core/include/ngn/host-reload.h +21 -0
- package/native/core/include/ngn/host-state.h +23 -0
- package/native/core/include/ngn/image-source.h +26 -1
- package/native/core/include/ngn/input-script.h +3 -3
- package/native/core/include/ngn/input.h +4 -1
- package/native/core/include/ngn/launch-frame.h +21 -0
- package/native/core/include/ngn/launch-settings.h +23 -5
- package/native/core/include/ngn/mounting-backend.h +5 -0
- package/native/core/include/ngn/mounting-manager.h +1 -0
- package/native/core/include/ngn/native-controls.h +26 -5
- package/native/core/include/ngn/notification-schedule.h +74 -0
- package/native/core/include/ngn/notifications.h +2 -1
- package/native/core/include/ngn/openssl-update-crypto.h +15 -0
- package/native/core/include/ngn/photo-library.h +60 -20
- package/native/core/include/ngn/posix-locale.h +43 -0
- package/native/core/include/ngn/runtime.h +5 -0
- package/native/core/include/ngn/safe-areas.h +14 -2
- package/native/core/include/ngn/split-view.h +78 -0
- package/native/core/include/ngn/surface-metrics.h +7 -0
- package/native/core/include/ngn/system.h +14 -0
- package/native/core/include/ngn/text-input.h +13 -0
- package/native/core/include/ngn/text-units.h +38 -0
- package/native/core/include/ngn/updates.h +14 -2
- package/native/core/include/ngn/view-box.h +40 -0
- package/native/core/include/ngn/view-transform.h +15 -0
- package/native/core/include/ngn/web-browser.h +46 -0
- package/native/core/src/accent-colors.cpp +88 -0
- package/native/core/src/accessibility-relations.cpp +138 -0
- package/native/core/src/accessibility.cpp +50 -0
- package/native/core/src/animated-frame-loop.cpp +166 -0
- package/native/core/src/app-menus.cpp +26 -9
- package/native/core/src/app-windows.cpp +27 -6
- package/native/core/src/aria-role.cpp +127 -0
- package/native/core/src/control-sizes.cpp +9 -5
- package/native/core/src/crash-report.cpp +196 -0
- package/native/core/src/curl-network.cpp +1562 -0
- package/native/core/src/dbus-menu.cpp +71 -0
- package/native/core/src/default-menu.cpp +134 -0
- package/native/core/src/desktop-view-props.cpp +14 -0
- package/native/core/src/focus-order.cpp +19 -0
- package/native/core/src/header-bar.cpp +20 -0
- package/native/core/src/host-os.cpp +19 -0
- package/native/core/src/host-reload.cpp +45 -0
- package/native/core/src/host-state.cpp +8 -0
- package/native/core/src/image-source.cpp +90 -0
- package/native/core/src/input-dispatcher.cpp +27 -5
- package/native/core/src/input-script.cpp +3 -2
- package/native/core/src/launch-settings.cpp +76 -0
- package/native/core/src/libraries/react-native-reanimated.cpp +6 -1
- package/native/core/src/modules/app-info.cpp +55 -6
- package/native/core/src/modules/app-modules.cpp +1 -1
- package/native/core/src/modules/audio.cpp +4 -2
- package/native/core/src/modules/camera.cpp +8 -11
- package/native/core/src/modules/desktop-expo.cpp +10 -5
- package/native/core/src/modules/desktop-modules.cpp +106 -41
- package/native/core/src/modules/file-photo-picker.cpp +408 -0
- package/native/core/src/modules/notifications.cpp +13 -17
- package/native/core/src/modules/photo-library.cpp +42 -13
- package/native/core/src/modules/web-browser.cpp +89 -0
- package/native/core/src/mounting-manager.cpp +12 -0
- package/native/core/src/native-controls.cpp +42 -1
- package/native/core/src/notification-schedule.cpp +429 -0
- package/native/core/src/openssl-update-crypto.cpp +83 -0
- package/native/core/src/posix-locale.cpp +192 -0
- package/native/core/src/runtime.cpp +30 -1
- package/native/core/src/safe-areas.cpp +19 -4
- package/native/core/src/spawn-rules.cpp +4 -1
- package/native/core/src/split-view.cpp +93 -0
- package/native/core/src/system.cpp +19 -0
- package/native/core/src/text-input.cpp +18 -1
- package/native/core/src/text-units.cpp +99 -0
- package/native/core/src/updates.cpp +76 -17
- package/native/core/src/view-box.cpp +75 -40
- package/native/core/src/view-transform.cpp +28 -0
- package/native/docker/Dockerfile +38 -0
- package/native/docker/Dockerfile.fedora +36 -0
- package/native/docker/glibc-floor.sh +49 -0
- package/native/gtk/CMakeLists.txt +137 -0
- package/native/gtk/accent-colour.cpp +57 -0
- package/native/gtk/accent-colour.h +41 -0
- package/native/gtk/accessibility-settings.cpp +159 -0
- package/native/gtk/accessibility-settings.h +62 -0
- package/native/gtk/accessible-text.cpp +151 -0
- package/native/gtk/accessible-text.h +49 -0
- package/native/gtk/accessible.cpp +306 -0
- package/native/gtk/accessible.h +75 -0
- package/native/gtk/alerts.cpp +267 -0
- package/native/gtk/alerts.h +30 -0
- package/native/gtk/animation-frames.cpp +159 -0
- package/native/gtk/animation-frames.h +20 -0
- package/native/gtk/app-info.cpp +91 -0
- package/native/gtk/app-info.h +25 -0
- package/native/gtk/app-windows.cpp +439 -0
- package/native/gtk/app-windows.h +150 -0
- package/native/gtk/audio.cpp +370 -0
- package/native/gtk/audio.h +54 -0
- package/native/gtk/auth-session.cpp +73 -0
- package/native/gtk/auth-session.h +16 -0
- package/native/gtk/battery.cpp +110 -0
- package/native/gtk/battery.h +19 -0
- package/native/gtk/box-paint.cpp +262 -0
- package/native/gtk/box-paint.h +32 -0
- package/native/gtk/cairo-canvas.cpp +755 -0
- package/native/gtk/cairo-canvas.h +49 -0
- package/native/gtk/camera.cpp +909 -0
- package/native/gtk/camera.h +69 -0
- package/native/gtk/capture.cpp +46 -0
- package/native/gtk/capture.h +19 -0
- package/native/gtk/clock-format.cpp +151 -0
- package/native/gtk/clock-format.h +36 -0
- package/native/gtk/crypto.cpp +75 -0
- package/native/gtk/crypto.h +14 -0
- package/native/gtk/dbus-properties.cpp +131 -0
- package/native/gtk/dbus-properties.h +61 -0
- package/native/gtk/drag-and-drop.cpp +339 -0
- package/native/gtk/drag-and-drop.h +30 -0
- package/native/gtk/file-dialogs.cpp +239 -0
- package/native/gtk/file-dialogs.h +21 -0
- package/native/gtk/file-system.cpp +212 -0
- package/native/gtk/file-system.h +25 -0
- package/native/gtk/focus.cpp +282 -0
- package/native/gtk/focus.h +37 -0
- package/native/gtk/fonts.cpp +89 -0
- package/native/gtk/fonts.h +22 -0
- package/native/gtk/gst-frames.cpp +150 -0
- package/native/gtk/gst-frames.h +47 -0
- package/native/gtk/gst-playback.cpp +496 -0
- package/native/gtk/gst-playback.h +81 -0
- package/native/gtk/gtk-backend.cpp +690 -0
- package/native/gtk/gtk-backend.h +134 -0
- package/native/gtk/host-sources.cpp +354 -0
- package/native/gtk/host-sources.h +46 -0
- package/native/gtk/image-manipulator.cpp +254 -0
- package/native/gtk/image-manipulator.h +30 -0
- package/native/gtk/image-view.cpp +256 -0
- package/native/gtk/image-view.h +54 -0
- package/native/gtk/input-replay.cpp +299 -0
- package/native/gtk/input-replay.h +36 -0
- package/native/gtk/launcher-badge.cpp +29 -0
- package/native/gtk/launcher-badge.h +21 -0
- package/native/gtk/locales.cpp +131 -0
- package/native/gtk/locales.h +23 -0
- package/native/gtk/location.cpp +274 -0
- package/native/gtk/location.h +19 -0
- package/native/gtk/main.cpp +1092 -0
- package/native/gtk/menus.cpp +447 -0
- package/native/gtk/menus.h +100 -0
- package/native/gtk/native-controls.cpp +831 -0
- package/native/gtk/native-controls.h +58 -0
- package/native/gtk/network-state.cpp +72 -0
- package/native/gtk/network-state.h +24 -0
- package/native/gtk/notifications.cpp +235 -0
- package/native/gtk/notifications.h +30 -0
- package/native/gtk/pango-text.cpp +274 -0
- package/native/gtk/pango-text.h +73 -0
- package/native/gtk/portal.cpp +451 -0
- package/native/gtk/portal.h +71 -0
- package/native/gtk/printing.cpp +338 -0
- package/native/gtk/printing.h +34 -0
- package/native/gtk/proxy-resolver.cpp +74 -0
- package/native/gtk/proxy-resolver.h +20 -0
- package/native/gtk/screens.cpp +1461 -0
- package/native/gtk/screens.h +274 -0
- package/native/gtk/scroll-view.cpp +414 -0
- package/native/gtk/scroll-view.h +82 -0
- package/native/gtk/secret-store.cpp +120 -0
- package/native/gtk/secret-store.h +27 -0
- package/native/gtk/settings-portal.cpp +129 -0
- package/native/gtk/settings-portal.h +47 -0
- package/native/gtk/split-view.cpp +1105 -0
- package/native/gtk/split-view.h +195 -0
- package/native/gtk/status-notifier.cpp +487 -0
- package/native/gtk/status-notifier.h +43 -0
- package/native/gtk/surface-input.cpp +251 -0
- package/native/gtk/surface-input.h +57 -0
- package/native/gtk/system-access.cpp +295 -0
- package/native/gtk/system-access.h +37 -0
- package/native/gtk/text-field.cpp +827 -0
- package/native/gtk/text-field.h +78 -0
- package/native/gtk/video.cpp +527 -0
- package/native/gtk/video.h +47 -0
- package/native/gtk/view-widget.cpp +431 -0
- package/native/gtk/view-widget.h +105 -0
- package/native/gtk/window-scale.cpp +95 -0
- package/native/gtk/window-scale.h +35 -0
- package/native/scripts/atspi-check.py +310 -0
- package/native/scripts/atspi-check.test.py +48 -0
- package/native/scripts/build.sh +20 -3
- package/native/scripts/compilers.sh +17 -0
- package/native/scripts/deb-depends-check.sh +22 -0
- package/native/scripts/fetch.sh +23 -2
- package/native/scripts/launch-cell.sh +157 -0
- package/native/scripts/launch-probe.sh +14 -3
- package/native/scripts/make-prebuilt.mjs +133 -44
- package/native/scripts/prebuilt-host-cache.mjs +71 -40
- package/native/scripts/reset-for-compilers.sh +44 -0
- package/native/scripts/start-xvfb.sh +35 -0
- package/native/shim/paragraph-platform/react/renderer/components/text/HostPlatformParagraphProps.h +35 -0
- package/native/shim/view-platform/react/renderer/components/view/HostPlatformViewTraitsInitializer.h +5 -2
- package/native/shim/worklets/linux-reanimated-props.h +14 -0
- package/native/shim/worklets/linux-worklets.h +23 -0
- package/package.json +6 -3
- package/prebuilt.json +70 -6
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
#include "box-paint.h"
|
|
2
|
+
|
|
3
|
+
#include "cairo-canvas.h"
|
|
4
|
+
|
|
5
|
+
#include <algorithm>
|
|
6
|
+
#include <cmath>
|
|
7
|
+
#include <vector>
|
|
8
|
+
|
|
9
|
+
namespace ngn::gtk {
|
|
10
|
+
|
|
11
|
+
namespace {
|
|
12
|
+
|
|
13
|
+
bool rounded(const CornerRadii &r) {
|
|
14
|
+
return r != CornerRadii{};
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
bool visible(const std::optional<uint32_t> &argb) {
|
|
18
|
+
return argb && (*argb >> 24) != 0;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
SvgRect paddingBox(const BoxDescription &box) {
|
|
22
|
+
const auto &w = box.borderWidths;
|
|
23
|
+
const auto &b = box.bounds;
|
|
24
|
+
return {b.x + w.left, b.y + w.top, std::max(0.0, b.width - w.left - w.right), std::max(0.0, b.height - w.top - w.bottom)};
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
graphene_rect_t grapheneRect(const SvgRect &r) {
|
|
28
|
+
graphene_rect_t out;
|
|
29
|
+
graphene_rect_init(&out, static_cast<float>(r.x), static_cast<float>(r.y), static_cast<float>(r.width), static_cast<float>(r.height));
|
|
30
|
+
return out;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// The stops as GSK takes them: offsets clamped to 0 to 1 and never smaller than the one before.
|
|
34
|
+
std::vector<GskColorStop> colorStops(const SvgGradient &g) {
|
|
35
|
+
std::vector<GskColorStop> stops;
|
|
36
|
+
float last = 0;
|
|
37
|
+
for (const auto &[offset, argb] : g.stops) {
|
|
38
|
+
last = std::clamp(stops.empty() ? static_cast<float>(offset) : std::max(static_cast<float>(offset), last), 0.0f, 1.0f);
|
|
39
|
+
stops.push_back({last, rgbaOf(argb)});
|
|
40
|
+
}
|
|
41
|
+
if (stops.size() == 1) {
|
|
42
|
+
stops.push_back({1, stops[0].color});
|
|
43
|
+
}
|
|
44
|
+
return stops;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// The gradient filling `tile`, its own space's origin at the tile's top left (view-box.h). A linear
|
|
48
|
+
// gradient's transform is the identity; a radial one's places its centre and squashes its circle
|
|
49
|
+
// into the ellipse, which GSK takes as two radii.
|
|
50
|
+
void appendGradient(GtkSnapshot *snapshot, const SvgGradient &g, const SvgRect &tile) {
|
|
51
|
+
auto stops = colorStops(g);
|
|
52
|
+
if (stops.empty()) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
auto at = SvgMatrix::translate(tile.x, tile.y) * g.transform;
|
|
56
|
+
graphene_rect_t bounds = grapheneRect(tile);
|
|
57
|
+
if (g.radial) {
|
|
58
|
+
auto [cx, cy] = at.apply(g.x1, g.y1);
|
|
59
|
+
float rx = static_cast<float>(g.r * std::hypot(at.a, at.b)), ry = static_cast<float>(g.r * std::hypot(at.c, at.d));
|
|
60
|
+
if (!(rx > 0) || !(ry > 0)) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
graphene_point_t centre;
|
|
64
|
+
graphene_point_init(¢re, static_cast<float>(cx), static_cast<float>(cy));
|
|
65
|
+
gtk_snapshot_append_radial_gradient(snapshot, &bounds, ¢re, rx, ry, 0, 1, stops.data(), stops.size());
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
auto [x1, y1] = at.apply(g.x1, g.y1);
|
|
69
|
+
auto [x2, y2] = at.apply(g.x2, g.y2);
|
|
70
|
+
graphene_point_t start, end;
|
|
71
|
+
graphene_point_init(&start, static_cast<float>(x1), static_cast<float>(y1));
|
|
72
|
+
graphene_point_init(&end, static_cast<float>(x2), static_cast<float>(y2));
|
|
73
|
+
if (graphene_point_equal(&start, &end)) {
|
|
74
|
+
// No line to run along: CSS paints the last colour.
|
|
75
|
+
GdkRGBA last = stops.back().color;
|
|
76
|
+
gtk_snapshot_append_color(snapshot, &last, &bounds);
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
gtk_snapshot_append_linear_gradient(snapshot, &bounds, &start, &end, stops.data(), stops.size());
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// The distinct starts of the tiles along one axis, and the step between them when it is the same
|
|
83
|
+
// throughout.
|
|
84
|
+
std::optional<double> step(std::vector<double> starts, double size) {
|
|
85
|
+
std::sort(starts.begin(), starts.end());
|
|
86
|
+
starts.erase(std::unique(starts.begin(), starts.end(), [](double a, double b) { return std::abs(a - b) < 1e-6; }), starts.end());
|
|
87
|
+
if (starts.size() < 2) {
|
|
88
|
+
return size;
|
|
89
|
+
}
|
|
90
|
+
double by = starts[1] - starts[0];
|
|
91
|
+
for (size_t i = 2; i < starts.size(); ++i) {
|
|
92
|
+
if (std::abs(starts[i] - starts[i - 1] - by) > 1e-3) {
|
|
93
|
+
return std::nullopt;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return by;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// One background image: its first tile drawn once and repeated by GSK over the others, the gap
|
|
100
|
+
// between `space` tiles included.
|
|
101
|
+
void appendBackgroundLayer(GtkSnapshot *snapshot, const BackgroundLayer &layer) {
|
|
102
|
+
const auto &tiles = layer.tiles;
|
|
103
|
+
if (tiles.empty()) {
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
const SvgRect &first = tiles[0];
|
|
107
|
+
std::vector<double> xs, ys;
|
|
108
|
+
double left = first.x, top = first.y, right = first.x + first.width, bottom = first.y + first.height;
|
|
109
|
+
for (const auto &t : tiles) {
|
|
110
|
+
xs.push_back(t.x);
|
|
111
|
+
ys.push_back(t.y);
|
|
112
|
+
left = std::min(left, t.x);
|
|
113
|
+
top = std::min(top, t.y);
|
|
114
|
+
right = std::max(right, t.x + t.width);
|
|
115
|
+
bottom = std::max(bottom, t.y + t.height);
|
|
116
|
+
}
|
|
117
|
+
auto across = step(xs, first.width), down = step(ys, first.height);
|
|
118
|
+
if (tiles.size() == 1 || !across || !down) {
|
|
119
|
+
for (const auto &t : tiles) {
|
|
120
|
+
appendGradient(snapshot, layer.gradient, t);
|
|
121
|
+
}
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
graphene_rect_t all = grapheneRect({left, top, right - left, bottom - top});
|
|
125
|
+
graphene_rect_t one = grapheneRect({left, top, *across, *down});
|
|
126
|
+
gtk_snapshot_push_repeat(snapshot, &all, &one);
|
|
127
|
+
appendGradient(snapshot, layer.gradient, {left, top, first.width, first.height});
|
|
128
|
+
gtk_snapshot_pop(snapshot);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
bool dashed(const BoxDescription &box) {
|
|
132
|
+
return box.borderStyle == facebook::react::BorderStyle::Dashed || box.borderStyle == facebook::react::BorderStyle::Dotted;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
} // namespace
|
|
136
|
+
|
|
137
|
+
GdkRGBA rgbaOf(uint32_t argb) {
|
|
138
|
+
return {
|
|
139
|
+
static_cast<float>((argb >> 16) & 0xff) / 255.0f,
|
|
140
|
+
static_cast<float>((argb >> 8) & 0xff) / 255.0f,
|
|
141
|
+
static_cast<float>(argb & 0xff) / 255.0f,
|
|
142
|
+
static_cast<float>((argb >> 24) & 0xff) / 255.0f,
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
GskRoundedRect gskRoundedRect(const SvgRect &rect, const CornerRadii &radii) {
|
|
147
|
+
graphene_rect_t bounds;
|
|
148
|
+
graphene_rect_init(&bounds, static_cast<float>(rect.x), static_cast<float>(rect.y), static_cast<float>(rect.width), static_cast<float>(rect.height));
|
|
149
|
+
auto size = [](const CornerRadii::Corner &c) {
|
|
150
|
+
graphene_size_t s;
|
|
151
|
+
graphene_size_init(&s, static_cast<float>(std::max(0.0, c.x)), static_cast<float>(std::max(0.0, c.y)));
|
|
152
|
+
return s;
|
|
153
|
+
};
|
|
154
|
+
graphene_size_t tl = size(radii.topLeft), tr = size(radii.topRight), br = size(radii.bottomRight), bl = size(radii.bottomLeft);
|
|
155
|
+
GskRoundedRect out;
|
|
156
|
+
gsk_rounded_rect_init(&out, &bounds, &tl, &tr, &br, &bl);
|
|
157
|
+
gsk_rounded_rect_normalize(&out);
|
|
158
|
+
return out;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
void appendBox(GtkSnapshot *snapshot, const BoxDescription &box, const std::function<void()> &content) {
|
|
162
|
+
if (box.bounds.width <= 0 || box.bounds.height <= 0) {
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
GskRoundedRect outline = gskRoundedRect(box.bounds, box.radii);
|
|
166
|
+
|
|
167
|
+
// The outer shadows, the last listed at the bottom.
|
|
168
|
+
for (auto it = box.shadows.rbegin(); it != box.shadows.rend(); ++it) {
|
|
169
|
+
if (it->inset) {
|
|
170
|
+
continue;
|
|
171
|
+
}
|
|
172
|
+
GdkRGBA color = rgbaOf(0xff000000);
|
|
173
|
+
if (it->color) {
|
|
174
|
+
auto c = facebook::react::colorComponentsFromColor(it->color);
|
|
175
|
+
color = {c.red, c.green, c.blue, c.alpha};
|
|
176
|
+
}
|
|
177
|
+
gtk_snapshot_append_outset_shadow(
|
|
178
|
+
snapshot, &outline, &color, static_cast<float>(it->offsetX), static_cast<float>(it->offsetY),
|
|
179
|
+
static_cast<float>(it->spreadDistance), static_cast<float>(it->blurRadius));
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
if (visible(box.background) || !box.backgroundImages.empty()) {
|
|
183
|
+
if (rounded(box.radii)) {
|
|
184
|
+
gtk_snapshot_push_rounded_clip(snapshot, &outline);
|
|
185
|
+
} else {
|
|
186
|
+
gtk_snapshot_push_clip(snapshot, &outline.bounds);
|
|
187
|
+
}
|
|
188
|
+
if (visible(box.background)) {
|
|
189
|
+
GdkRGBA color = rgbaOf(*box.background);
|
|
190
|
+
gtk_snapshot_append_color(snapshot, &color, &outline.bounds);
|
|
191
|
+
}
|
|
192
|
+
for (const auto &layer : box.backgroundImages) {
|
|
193
|
+
appendBackgroundLayer(snapshot, layer);
|
|
194
|
+
}
|
|
195
|
+
gtk_snapshot_pop(snapshot);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
GskRoundedRect padding = gskRoundedRect(paddingBox(box), innerRadii(box.radii, box.borderWidths));
|
|
199
|
+
for (auto it = box.shadows.rbegin(); it != box.shadows.rend(); ++it) {
|
|
200
|
+
if (!it->inset) {
|
|
201
|
+
continue;
|
|
202
|
+
}
|
|
203
|
+
GdkRGBA color = rgbaOf(0xff000000);
|
|
204
|
+
if (it->color) {
|
|
205
|
+
auto c = facebook::react::colorComponentsFromColor(it->color);
|
|
206
|
+
color = {c.red, c.green, c.blue, c.alpha};
|
|
207
|
+
}
|
|
208
|
+
gtk_snapshot_append_inset_shadow(
|
|
209
|
+
snapshot, &padding, &color, static_cast<float>(it->offsetX), static_cast<float>(it->offsetY),
|
|
210
|
+
static_cast<float>(it->spreadDistance), static_cast<float>(it->blurRadius));
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
if (content) {
|
|
214
|
+
content();
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
const auto &w = box.borderWidths;
|
|
218
|
+
if (dashed(box) && (w.top > 0 || w.right > 0 || w.bottom > 0 || w.left > 0)) {
|
|
219
|
+
// GSK strokes paths only from GTK 4.14, and the host builds against 4.12: cairo strokes the
|
|
220
|
+
// dashes the core lays out, as on macOS.
|
|
221
|
+
graphene_rect_t bounds = grapheneRect(box.bounds);
|
|
222
|
+
cairo_t *cr = gtk_snapshot_append_cairo(snapshot, &bounds);
|
|
223
|
+
auto canvas = makeCairoCanvas(cr, box.bounds.width, box.bounds.height, 1);
|
|
224
|
+
// React Native's default border colour is black, as in the solid case below.
|
|
225
|
+
BoxDescription painted{
|
|
226
|
+
.bounds = box.bounds, .radii = box.radii, .borderWidths = box.borderWidths, .borderColors = box.borderColors, .borderStyle = box.borderStyle};
|
|
227
|
+
for (auto *side : {&painted.borderColors.top, &painted.borderColors.right, &painted.borderColors.bottom, &painted.borderColors.left}) {
|
|
228
|
+
if (!*side) {
|
|
229
|
+
*side = 0xff000000;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
drawBorder(painted, *canvas);
|
|
233
|
+
canvas.reset();
|
|
234
|
+
cairo_destroy(cr);
|
|
235
|
+
} else if (w.top > 0 || w.right > 0 || w.bottom > 0 || w.left > 0) {
|
|
236
|
+
// React Native's default border colour is black.
|
|
237
|
+
const auto &c = box.borderColors;
|
|
238
|
+
float widths[4] = {static_cast<float>(w.top), static_cast<float>(w.right), static_cast<float>(w.bottom), static_cast<float>(w.left)};
|
|
239
|
+
GdkRGBA colors[4] = {
|
|
240
|
+
rgbaOf(c.top.value_or(0xff000000)),
|
|
241
|
+
rgbaOf(c.right.value_or(0xff000000)),
|
|
242
|
+
rgbaOf(c.bottom.value_or(0xff000000)),
|
|
243
|
+
rgbaOf(c.left.value_or(0xff000000)),
|
|
244
|
+
};
|
|
245
|
+
gtk_snapshot_append_border(snapshot, &outline, widths, colors);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
bool pushOverflowClip(GtkSnapshot *snapshot, const BoxDescription &box) {
|
|
250
|
+
if (!box.clips) {
|
|
251
|
+
return false;
|
|
252
|
+
}
|
|
253
|
+
GskRoundedRect outline = gskRoundedRect(box.bounds, box.radii);
|
|
254
|
+
if (rounded(box.radii)) {
|
|
255
|
+
gtk_snapshot_push_rounded_clip(snapshot, &outline);
|
|
256
|
+
} else {
|
|
257
|
+
gtk_snapshot_push_clip(snapshot, &outline.bounds);
|
|
258
|
+
}
|
|
259
|
+
return true;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
} // namespace ngn::gtk
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// A view's box (describeBox, view-box.h) as GSK render nodes, in the order CSS paints it: the outer
|
|
2
|
+
// shadows, the last listed lowest; the background colour and then the background images in the
|
|
3
|
+
// border box's shape, each image's first tile under a repeat node; the inset shadows in the padding
|
|
4
|
+
// box; the border.
|
|
5
|
+
//
|
|
6
|
+
// A dashed or dotted border is a cairo node stroked by the core's drawBorder, as on macOS: GSK
|
|
7
|
+
// strokes paths only from GTK 4.14, and the host builds against el9's 4.12.
|
|
8
|
+
#pragma once
|
|
9
|
+
|
|
10
|
+
#include "ngn/view-box.h"
|
|
11
|
+
|
|
12
|
+
#include <gtk/gtk.h>
|
|
13
|
+
|
|
14
|
+
#include <functional>
|
|
15
|
+
|
|
16
|
+
namespace ngn::gtk {
|
|
17
|
+
|
|
18
|
+
GdkRGBA rgbaOf(uint32_t argb);
|
|
19
|
+
|
|
20
|
+
// The rect with its corners rounded, the radii scaled down together where neighbours overlap, as
|
|
21
|
+
// CSS does.
|
|
22
|
+
GskRoundedRect gskRoundedRect(const SvgRect &rect, const CornerRadii &radii);
|
|
23
|
+
|
|
24
|
+
// `content`, when given, draws between the inset shadows and the border, as a layer's contents
|
|
25
|
+
// draw under its border.
|
|
26
|
+
void appendBox(GtkSnapshot *snapshot, const BoxDescription &box, const std::function<void()> &content = nullptr);
|
|
27
|
+
|
|
28
|
+
// Cuts what follows to the box's shape when it clips its overflow: true when it pushed a clip,
|
|
29
|
+
// which the caller pops.
|
|
30
|
+
bool pushOverflowClip(GtkSnapshot *snapshot, const BoxDescription &box);
|
|
31
|
+
|
|
32
|
+
} // namespace ngn::gtk
|