@elurjs/universal 0.1.10 → 0.1.11
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/cli/create-app.mjs +4 -2
- package/cli/dev.mjs +1 -1
- package/cli/elur.mjs +18 -4
- package/docs/INSTALACION-Y-DEV.md +7 -4
- package/package.json +5 -1
- package/targets/linux/CMakeLists.txt +196 -0
- package/targets/linux/README.md +422 -0
- package/targets/linux/ci/tsan.supp +15 -0
- package/targets/linux/generated/elur_module_registrar.cpp +14 -0
- package/targets/linux/generated/module_sources.cmake +5 -0
- package/targets/linux/src/elur_applicator.cpp +5073 -0
- package/targets/linux/src/elur_applicator.h +387 -0
- package/targets/linux/src/elur_clip.cpp +76 -0
- package/targets/linux/src/elur_clip.h +23 -0
- package/targets/linux/src/elur_crypto_module.cpp +121 -0
- package/targets/linux/src/elur_events.h +57 -0
- package/targets/linux/src/elur_fonts.cpp +106 -0
- package/targets/linux/src/elur_fonts.h +31 -0
- package/targets/linux/src/elur_host.cpp +1041 -0
- package/targets/linux/src/elur_host.h +66 -0
- package/targets/linux/src/elur_http_module.cpp +437 -0
- package/targets/linux/src/elur_js.h +40 -0
- package/targets/linux/src/elur_modules.cpp +453 -0
- package/targets/linux/src/elur_modules.h +159 -0
- package/targets/linux/src/elur_renderer.h +46 -0
- package/targets/linux/src/elur_shot.cpp +64 -0
- package/targets/linux/src/elur_shot.h +17 -0
- package/targets/linux/src/elur_skia_a11y.cpp +987 -0
- package/targets/linux/src/elur_skia_a11y.h +146 -0
- package/targets/linux/src/elur_skia_app.cpp +1770 -0
- package/targets/linux/src/elur_skia_app.h +18 -0
- package/targets/linux/src/elur_state_module.cpp +99 -0
- package/targets/linux/src/elur_tck_module.cpp +186 -0
- package/targets/linux/src/elur_ui_module.cpp +84 -0
- package/targets/linux/src/elur_yoga.cpp +452 -0
- package/targets/linux/src/elur_yoga.h +95 -0
- package/targets/linux/src/main.cpp +294 -0
- package/targets/windows/Package.appxmanifest +28 -0
- package/targets/windows/README.md +44 -0
- package/targets/windows/elur-windows.vcxproj +133 -0
- package/targets/windows/packages.config +10 -0
- package/targets/windows/src/elur_crypto_module_win.cpp +106 -0
- package/targets/windows/src/elur_events.h +58 -0
- package/targets/windows/src/elur_host_win.cpp +645 -0
- package/targets/windows/src/elur_host_win.h +75 -0
- package/targets/windows/src/elur_http_module_win.cpp +331 -0
- package/targets/windows/src/elur_js.h +40 -0
- package/targets/windows/src/elur_modules.cpp +460 -0
- package/targets/windows/src/elur_modules.h +159 -0
- package/targets/windows/src/elur_state_module.cpp +99 -0
- package/targets/windows/src/elur_ui_module_win.cpp +75 -0
- package/targets/windows/src/elur_uia_host.h +129 -0
- package/targets/windows/src/elur_win_applicator.cpp +3118 -0
- package/targets/windows/src/elur_win_applicator.h +186 -0
- package/targets/windows/src/elur_yoga.cpp +452 -0
- package/targets/windows/src/elur_yoga.h +95 -0
- package/targets/windows/src/main.cpp +321 -0
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
// elur_win_applicator.h — aplicador del host Windows (ADR-0220):
|
|
2
|
+
// DisplayOp → controles WinUI 3 (Microsoft.UI.Xaml) + árbol Yoga
|
|
3
|
+
// espejo (elur_yoga.cpp compartido) + eventos → __elur_*.
|
|
4
|
+
//
|
|
5
|
+
// Modelo: Canvas por nodo contenedor — Yoga entrega left/top
|
|
6
|
+
// relativos al padre (mismo contrato que GtkFixed), Canvas::SetLeft/
|
|
7
|
+
// SetTop posiciona el wrapper Border de cada hijo. `scroll-view`
|
|
8
|
+
// lleva ScrollViewer + Canvas interno. `button` absorbe sus hijos
|
|
9
|
+
// text como label (paridad GTK/Android). Medida de hojas vía
|
|
10
|
+
// UIElement::Measure en el hilo UI (perfil S — no cruza hilos).
|
|
11
|
+
#pragma once
|
|
12
|
+
|
|
13
|
+
#include "elur_events.h"
|
|
14
|
+
#include "elur_host_win.h"
|
|
15
|
+
#include "elur_uia_host.h"
|
|
16
|
+
#include <quickjs.h>
|
|
17
|
+
#include <memory>
|
|
18
|
+
#include <string>
|
|
19
|
+
#include <unordered_map>
|
|
20
|
+
#include <unordered_set>
|
|
21
|
+
#include <vector>
|
|
22
|
+
#include <winrt/Microsoft.UI.Xaml.Controls.h>
|
|
23
|
+
#include <winrt/Microsoft.UI.Xaml.h>
|
|
24
|
+
|
|
25
|
+
namespace mux = winrt::Microsoft::UI::Xaml;
|
|
26
|
+
namespace muxc = winrt::Microsoft::UI::Xaml::Controls;
|
|
27
|
+
|
|
28
|
+
namespace elur {
|
|
29
|
+
|
|
30
|
+
// ADR-0147 — un tramo inline del prop `spans`: rango UTF-16 [s,e)
|
|
31
|
+
// sobre el texto renderizado, estilo tipográfico y href opcional.
|
|
32
|
+
// `kids` = spans contenidos enteros (solapamiento solo por anidación).
|
|
33
|
+
struct WinSpan {
|
|
34
|
+
int s = 0, e = 0;
|
|
35
|
+
std::string href;
|
|
36
|
+
std::unordered_map<std::string, std::string> style;
|
|
37
|
+
std::vector<WinSpan> kids;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
struct WinNode {
|
|
41
|
+
int id = 0;
|
|
42
|
+
std::string type;
|
|
43
|
+
// Elemento posicionado en el Canvas del padre: siempre el ElurHost
|
|
44
|
+
// (ContentControl con AutomationPeer propio — selected/expanded/
|
|
45
|
+
// valueText, ADR-0220). Dentro va el Border de chrome (bg/corners/
|
|
46
|
+
// borde en un solo sitio, paridad css-on-widget del GTK) o el control
|
|
47
|
+
// directo (button/input/switch/slider).
|
|
48
|
+
mux::UIElement el{nullptr};
|
|
49
|
+
muxc::ContentControl host{nullptr};
|
|
50
|
+
std::shared_ptr<ElurA11y> a11y;
|
|
51
|
+
muxc::Border border{nullptr};
|
|
52
|
+
muxc::Canvas inner{nullptr}; // superficie de hijos
|
|
53
|
+
muxc::TextBlock textBlock{nullptr};
|
|
54
|
+
muxc::Button button{nullptr};
|
|
55
|
+
muxc::TextBox input{nullptr};
|
|
56
|
+
muxc::ToggleSwitch sw{nullptr};
|
|
57
|
+
muxc::CheckBox check{nullptr}; // switch variant="checkbox"
|
|
58
|
+
muxc::RadioButton radio{nullptr}; // switch variant="radio"
|
|
59
|
+
muxc::Slider slider{nullptr};
|
|
60
|
+
muxc::ScrollViewer scroll{nullptr};
|
|
61
|
+
muxc::RefreshContainer refresh{nullptr}; // monta al llegar refresh/refreshing
|
|
62
|
+
muxc::Image image{nullptr};
|
|
63
|
+
// switch activo real: apunta a sw/check/radio según `variant`
|
|
64
|
+
// (recrea el control — ToggleSwitch ≠ CheckBox ≠ RadioButton).
|
|
65
|
+
mux::UIElement swEl{nullptr};
|
|
66
|
+
std::string variant = "switch";
|
|
67
|
+
std::string fallbackSrc;
|
|
68
|
+
// ADR-0204: estado ya materializado — el attach de load/error hace
|
|
69
|
+
// replay igual que imgLoaded/imgFailed en GTK.
|
|
70
|
+
bool imgLoaded = false, imgFailed = false;
|
|
71
|
+
bool imgLoadFallback = false, imgFailFallback = false;
|
|
72
|
+
int imgW = 0, imgH = 0;
|
|
73
|
+
// ADR-0147: spans del TextBlock — si hay, updateText materializa
|
|
74
|
+
// Inlines (Run/Span/Hyperlink) en vez de asignar .Text plano.
|
|
75
|
+
std::vector<WinSpan> spans;
|
|
76
|
+
std::unordered_map<std::string, EventBind> events;
|
|
77
|
+
std::unordered_map<std::string, std::string> visual;
|
|
78
|
+
std::string textValue;
|
|
79
|
+
bool suppressSignal = false;
|
|
80
|
+
bool alignSet = false;
|
|
81
|
+
float fontSizePx = 0;
|
|
82
|
+
float inputMinH = 0;
|
|
83
|
+
winrt::event_token tokClick{};
|
|
84
|
+
winrt::event_token tokText{};
|
|
85
|
+
winrt::event_token tokToggle{};
|
|
86
|
+
winrt::event_token tokView{};
|
|
87
|
+
winrt::event_token tokSlider{};
|
|
88
|
+
winrt::event_token tokCheckOn{}, tokCheckOff{};
|
|
89
|
+
winrt::event_token tokRadioOn{}, tokRadioOff{};
|
|
90
|
+
winrt::event_token tokImgOpen{}, tokImgFail{};
|
|
91
|
+
winrt::event_token tokRefresh{};
|
|
92
|
+
// pan por ManipulationDelta en el elemento gestual (el recognizer
|
|
93
|
+
// vive en el control más profundo — los deltas no burbujean):
|
|
94
|
+
// panMoved = slop 8px cruzado (paridad GtkGestureDrag).
|
|
95
|
+
bool panMoved = false;
|
|
96
|
+
// Path de ratón: WinUI 3 desktop solo alimenta manipulaciones de
|
|
97
|
+
// touch/pen — el drag de ratón se mide por PointerMoved (GTK idem).
|
|
98
|
+
bool panMouseDown = false;
|
|
99
|
+
float panSX = 0, panSY = 0;
|
|
100
|
+
// pinch: solo gesto de 2+ contactos — el delta dispara con
|
|
101
|
+
// cualquier manipulación, la cuenta de punteros lo distingue.
|
|
102
|
+
int ptrCount = 0;
|
|
103
|
+
bool pinchActive = false;
|
|
104
|
+
// longPress por timer (mouse): Holding solo llega de touch/pen.
|
|
105
|
+
mux::DispatcherTimer lpTimer{nullptr};
|
|
106
|
+
float lpX = 0, lpY = 0;
|
|
107
|
+
// lpFired: el click que cierra un longPress no es press (ADR-0179).
|
|
108
|
+
bool lpFired = false;
|
|
109
|
+
float layX = 0, layY = 0, layW = -1, layH = -1;
|
|
110
|
+
// ADR-0150: sticky — umbral lógico desde el top + scroll ancestro
|
|
111
|
+
// enganchado; stickyBaseY = top de contenido sin translation.
|
|
112
|
+
bool sticky = false;
|
|
113
|
+
float stickyTop = 0, stickyBaseY = 0, stickyShift = 0;
|
|
114
|
+
bool stickyBaseValid = false;
|
|
115
|
+
muxc::ScrollViewer stickyScroll{nullptr};
|
|
116
|
+
winrt::event_token tokSticky{};
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
class WinApplicator {
|
|
120
|
+
public:
|
|
121
|
+
void init(const muxc::Canvas &root, const HostOptions &opts,
|
|
122
|
+
HostCallbacks cb);
|
|
123
|
+
void applyFrame(JSContext *ctx, JSValueConst v); // {frame,ops}
|
|
124
|
+
void setViewport(int w, int h);
|
|
125
|
+
void setRtl(bool rtl);
|
|
126
|
+
void shutdown();
|
|
127
|
+
|
|
128
|
+
HostCallbacks cb_{};
|
|
129
|
+
std::unordered_map<int, WinNode> nodes_;
|
|
130
|
+
bool trace = false;
|
|
131
|
+
void emitEvent(WinNode &n, const char *event, const char *origin,
|
|
132
|
+
const std::string &dataJson, const EventBind &bind);
|
|
133
|
+
void emitKeyFor(int id, winrt::Windows::System::VirtualKey k);
|
|
134
|
+
|
|
135
|
+
private:
|
|
136
|
+
muxc::Canvas root_{nullptr};
|
|
137
|
+
int vpW_ = 390, vpH_ = 844;
|
|
138
|
+
bool rtl_ = false;
|
|
139
|
+
int applyCycle_ = 0;
|
|
140
|
+
bool densityReported_ = false;
|
|
141
|
+
std::unordered_map<std::string, int> unknownOps_, unknownProps_,
|
|
142
|
+
unknownStyles_;
|
|
143
|
+
// ADR-0179: atajos `shortcut` — registro {id, combo canónico} como
|
|
144
|
+
// en GTK; el hook PreviewKeyDown del root se instala al primero.
|
|
145
|
+
struct Hotkey { int id; std::string combo; };
|
|
146
|
+
std::vector<Hotkey> hotkeys_;
|
|
147
|
+
bool hotkeyHooked_ = false;
|
|
148
|
+
void ensureHotkeyHook();
|
|
149
|
+
void dropHotkeys(int id);
|
|
150
|
+
void ensureStickyScroll(WinNode &n);
|
|
151
|
+
void applySticky(int id);
|
|
152
|
+
// ADR-0013/0165: nav-* — hijo detachado de un `shell` retenido como
|
|
153
|
+
// overlay (el nav-* del mismo batch lo re-inserta parallax).
|
|
154
|
+
mux::UIElement detachedEl_{nullptr};
|
|
155
|
+
float detX_ = 0, detY_ = 0, detW_ = 0, detH_ = 0;
|
|
156
|
+
void navTransition(const std::string &op, JSContext *ctx,
|
|
157
|
+
JSValueConst jop);
|
|
158
|
+
void clearDetached();
|
|
159
|
+
|
|
160
|
+
void createNode(int id, const std::string &type);
|
|
161
|
+
void deleteNode(int id);
|
|
162
|
+
void updateText(WinNode &n, const std::string &val);
|
|
163
|
+
void updateStyle(WinNode &n, JSContext *ctx, JSValueConst style);
|
|
164
|
+
void updateProp(WinNode &n, const std::string &key, JSContext *ctx,
|
|
165
|
+
JSValueConst val);
|
|
166
|
+
void attachEvent(int id, const std::string &event,
|
|
167
|
+
const std::string &handler, bool continuous,
|
|
168
|
+
const std::string &payload);
|
|
169
|
+
void onA11yInvoke(int id, const char *act);
|
|
170
|
+
void detachEvent(int id, const std::string &event);
|
|
171
|
+
void swapVariant(WinNode &n, const std::string &variant);
|
|
172
|
+
void wireCheckLike(int id, WinNode &n);
|
|
173
|
+
void ensureRefresh(WinNode &n);
|
|
174
|
+
void applySpans(WinNode &n);
|
|
175
|
+
muxc::Canvas surfaceOf(int parentId); // 0/desconocido → root_
|
|
176
|
+
void applyVisual(WinNode &n);
|
|
177
|
+
void relayout();
|
|
178
|
+
void measureLeaf(int id, float w, int wMode, float h, int hMode,
|
|
179
|
+
float &ow, float &oh);
|
|
180
|
+
void warnOnce(std::unordered_map<std::string, int> &m, const char *kind,
|
|
181
|
+
const std::string &what);
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
extern WinApplicator g_winapp;
|
|
185
|
+
|
|
186
|
+
} // namespace elur
|
|
@@ -0,0 +1,452 @@
|
|
|
1
|
+
// elur_yoga.cpp — ver header. Árbol Yoga del host Linux: la tabla
|
|
2
|
+
// clave→setter vive en native/layout (elur::layout, ADR-0174); aquí
|
|
3
|
+
// solo queda el estado del árbol, la medida de hojas y la guarda de
|
|
4
|
+
// padding en hojas con measureFunc (el host lo suma al widget). Se
|
|
5
|
+
// omiten: JNI/density (in-process), rowTrees (cap native-list ausente)
|
|
6
|
+
// y delegado `layout` (pendiente).
|
|
7
|
+
|
|
8
|
+
#include "elur_yoga.h"
|
|
9
|
+
#include <cstdio>
|
|
10
|
+
#include <functional>
|
|
11
|
+
#include <layout/elur_layout_style.h>
|
|
12
|
+
#include <unordered_map>
|
|
13
|
+
#include <vector>
|
|
14
|
+
|
|
15
|
+
namespace elur::yoga {
|
|
16
|
+
namespace {
|
|
17
|
+
|
|
18
|
+
struct Entry {
|
|
19
|
+
YGNodeRef node = nullptr;
|
|
20
|
+
std::string type;
|
|
21
|
+
bool emitted = false;
|
|
22
|
+
float lastX = 0, lastY = 0, lastW = -1, lastH = -1;
|
|
23
|
+
// Padding resuelto por edge físico — solo lo consume el host en
|
|
24
|
+
// hojas con measureFunc (Yoga lo salta ahí); en contenedores el
|
|
25
|
+
// padding vive en el árbol y esto queda a 0.
|
|
26
|
+
float padL = 0, padT = 0, padR = 0, padB = 0;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
std::unordered_map<int, Entry> g_nodes;
|
|
30
|
+
YGNodeRef g_root = nullptr;
|
|
31
|
+
YGConfigRef g_config = nullptr;
|
|
32
|
+
float g_vpW = 0, g_vpH = 0;
|
|
33
|
+
bool g_rtl = false;
|
|
34
|
+
bool g_dirty = false;
|
|
35
|
+
bool g_hasViewport = false;
|
|
36
|
+
MeasureHook g_measure;
|
|
37
|
+
BaselineHook g_baseline;
|
|
38
|
+
std::unordered_map<int, int> g_absorbedByButton;
|
|
39
|
+
|
|
40
|
+
bool isLeafType(const std::string &t) {
|
|
41
|
+
return t == "text" || t == "image" || t == "text-input" || t == "switch" ||
|
|
42
|
+
t == "slider";
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
YGSize measureLeaf(YGNodeConstRef node, float w, YGMeasureMode wMode, float h,
|
|
46
|
+
YGMeasureMode hMode) {
|
|
47
|
+
intptr_t ctx = reinterpret_cast<intptr_t>(YGNodeGetContext(node));
|
|
48
|
+
if (ctx == 0 || !g_measure)
|
|
49
|
+
return {0, 0};
|
|
50
|
+
float ow = 0, oh = 0;
|
|
51
|
+
g_measure(static_cast<int>(ctx), w, static_cast<int>(wMode), h,
|
|
52
|
+
static_cast<int>(hMode), ow, oh);
|
|
53
|
+
return {ow, oh};
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
float baselineLeaf(YGNodeConstRef node, float w, float h) {
|
|
57
|
+
intptr_t ctx = reinterpret_cast<intptr_t>(YGNodeGetContext(node));
|
|
58
|
+
if (ctx == 0 || !g_baseline)
|
|
59
|
+
return h;
|
|
60
|
+
return g_baseline(static_cast<int>(ctx), w, h);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
void emitDfs(YGNodeRef yg, int skipId, const RectSink &sink, int &count) {
|
|
64
|
+
(void)skipId;
|
|
65
|
+
uint32_t n = YGNodeGetChildCount(yg);
|
|
66
|
+
for (uint32_t i = 0; i < n; i++) {
|
|
67
|
+
YGNodeRef child = YGNodeGetChild(yg, i);
|
|
68
|
+
int id =
|
|
69
|
+
static_cast<int>(reinterpret_cast<intptr_t>(YGNodeGetContext(child)));
|
|
70
|
+
if (id != 0) {
|
|
71
|
+
auto it = g_nodes.find(id);
|
|
72
|
+
if (it != g_nodes.end()) {
|
|
73
|
+
Entry &e = it->second;
|
|
74
|
+
float x = YGNodeLayoutGetLeft(child);
|
|
75
|
+
float y = YGNodeLayoutGetTop(child);
|
|
76
|
+
float w = YGNodeLayoutGetWidth(child);
|
|
77
|
+
float h = YGNodeLayoutGetHeight(child);
|
|
78
|
+
if (!e.emitted || x != e.lastX || y != e.lastY || w != e.lastW ||
|
|
79
|
+
h != e.lastH) {
|
|
80
|
+
e.emitted = true;
|
|
81
|
+
e.lastX = x;
|
|
82
|
+
e.lastY = y;
|
|
83
|
+
e.lastW = w;
|
|
84
|
+
e.lastH = h;
|
|
85
|
+
sink(id, x, y, w, h);
|
|
86
|
+
count++;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
emitDfs(child, skipId, sink, count);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
} // namespace
|
|
95
|
+
|
|
96
|
+
void init() {
|
|
97
|
+
g_config = YGConfigNew();
|
|
98
|
+
// Paridad con Android (ADR-0110): errata None explícita — Yoga 3.2 es
|
|
99
|
+
// W3C-conforme por defecto; fijarlo blinda el contrato ante upstream.
|
|
100
|
+
YGConfigSetErrata(g_config, YGErrataNone);
|
|
101
|
+
// PointScaleFactor: default 1.0 igual que Android (que tampoco lo
|
|
102
|
+
// fija — el grid es en unidades lógicas, la density se divide en la
|
|
103
|
+
// frontera). Yoga ceil-ea medidas de hoja al grid (14.4→15/16
|
|
104
|
+
// mientras la fila floor-ea a 14) — divergencia Yoga↔CSS compartida
|
|
105
|
+
// con Android, no específica de Linux.
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
void shutdown() {
|
|
109
|
+
// g_root es también entrada de g_nodes (se asigna en nodeCreate) —
|
|
110
|
+
// un solo free por nodo: el loop los libera todos.
|
|
111
|
+
for (auto &kv : g_nodes)
|
|
112
|
+
YGNodeFree(kv.second.node);
|
|
113
|
+
g_nodes.clear();
|
|
114
|
+
g_root = nullptr;
|
|
115
|
+
if (g_config)
|
|
116
|
+
YGConfigFree(g_config);
|
|
117
|
+
g_config = nullptr;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
void setViewport(float w, float h, bool rtl) {
|
|
121
|
+
g_vpW = w;
|
|
122
|
+
g_vpH = h;
|
|
123
|
+
g_rtl = rtl;
|
|
124
|
+
g_hasViewport = w > 0 && h > 0;
|
|
125
|
+
g_dirty = true;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
bool hasViewport() { return g_hasViewport; }
|
|
129
|
+
void markDirty() { g_dirty = true; }
|
|
130
|
+
|
|
131
|
+
void markAllLeavesDirty() {
|
|
132
|
+
for (auto &kv : g_nodes)
|
|
133
|
+
if (YGNodeHasMeasureFunc(kv.second.node))
|
|
134
|
+
YGNodeMarkDirty(kv.second.node);
|
|
135
|
+
g_dirty = true;
|
|
136
|
+
}
|
|
137
|
+
void setMeasureHook(MeasureHook hook) { g_measure = std::move(hook); }
|
|
138
|
+
void setBaselineHook(BaselineHook hook) { g_baseline = std::move(hook); }
|
|
139
|
+
|
|
140
|
+
void nodeCreate(int id, const std::string &type) {
|
|
141
|
+
Entry e;
|
|
142
|
+
e.type = type;
|
|
143
|
+
e.node = YGNodeNewWithConfig(g_config);
|
|
144
|
+
if (type == "column")
|
|
145
|
+
YGNodeStyleSetFlexDirection(e.node, YGFlexDirectionColumn);
|
|
146
|
+
else if (type == "row")
|
|
147
|
+
YGNodeStyleSetFlexDirection(e.node, YGFlexDirectionRow);
|
|
148
|
+
else if (type == "scroll-view")
|
|
149
|
+
// ADR-0128: contenedor de scroll — los hijos se miden sin límite
|
|
150
|
+
// en el eje principal (overflow:auto web).
|
|
151
|
+
YGNodeStyleSetOverflow(e.node, YGOverflowScroll);
|
|
152
|
+
YGNodeSetContext(e.node, reinterpret_cast<void *>(static_cast<intptr_t>(id)));
|
|
153
|
+
if (isLeafType(type)) {
|
|
154
|
+
YGNodeSetMeasureFunc(e.node, measureLeaf);
|
|
155
|
+
YGNodeSetBaselineFunc(e.node, baselineLeaf);
|
|
156
|
+
}
|
|
157
|
+
g_nodes[id] = e;
|
|
158
|
+
// El primer nodo creado es la raíz (paridad Android: no hay root
|
|
159
|
+
// sintético — el shell recibe las dims del viewport directas).
|
|
160
|
+
if (!g_root)
|
|
161
|
+
g_root = e.node;
|
|
162
|
+
g_dirty = true;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
void nodeDelete(int id) {
|
|
166
|
+
auto it = g_nodes.find(id);
|
|
167
|
+
if (it == g_nodes.end())
|
|
168
|
+
return;
|
|
169
|
+
YGNodeRef yg = it->second.node;
|
|
170
|
+
if (YGNodeRef owner = YGNodeGetOwner(yg))
|
|
171
|
+
YGNodeRemoveChild(owner, yg);
|
|
172
|
+
// destroy libera el nodo (detach no): hijos detach primero, luego free.
|
|
173
|
+
while (YGNodeGetChildCount(yg) > 0)
|
|
174
|
+
YGNodeRemoveChild(yg, YGNodeGetChild(yg, 0));
|
|
175
|
+
YGNodeFree(yg);
|
|
176
|
+
if (g_root == yg)
|
|
177
|
+
g_root = nullptr;
|
|
178
|
+
for (auto &kv : g_absorbedByButton)
|
|
179
|
+
if (kv.second == id)
|
|
180
|
+
kv.second = 0;
|
|
181
|
+
g_absorbedByButton.erase(id);
|
|
182
|
+
g_nodes.erase(it);
|
|
183
|
+
g_dirty = true;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
void clearPadding(YGNodeRef n) {
|
|
187
|
+
for (int e = YGEdgeLeft; e <= YGEdgeAll; e++)
|
|
188
|
+
YGNodeStyleSetPadding(n, static_cast<YGEdge>(e), YGUndefined);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
void markLeafDirty(int id) {
|
|
192
|
+
auto ab = g_absorbedByButton.find(id);
|
|
193
|
+
if (ab != g_absorbedByButton.end() && ab->second != 0)
|
|
194
|
+
id = ab->second;
|
|
195
|
+
auto it = g_nodes.find(id);
|
|
196
|
+
if (it == g_nodes.end())
|
|
197
|
+
return;
|
|
198
|
+
if (YGNodeHasMeasureFunc(it->second.node)) {
|
|
199
|
+
YGNodeMarkDirty(it->second.node);
|
|
200
|
+
g_dirty = true;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
void nodeInsert(int parentId, int childId, int index) {
|
|
205
|
+
auto p = g_nodes.find(parentId);
|
|
206
|
+
auto c = g_nodes.find(childId);
|
|
207
|
+
// La raíz (shell) no tiene padre en el árbol — insert-child a 0 solo
|
|
208
|
+
// ancla el widget en el surface del host, no entra a Yoga.
|
|
209
|
+
if (p == g_nodes.end() || c == g_nodes.end())
|
|
210
|
+
return;
|
|
211
|
+
YGNodeRef parent = p->second.node;
|
|
212
|
+
// button absorbe todo hijo como label: no entra al árbol; el padre
|
|
213
|
+
// pasa a medirse como hoja (paridad con yogaInsertChild Android).
|
|
214
|
+
if (p->second.type == "button") {
|
|
215
|
+
YGNodeSetMeasureFunc(p->second.node, measureLeaf);
|
|
216
|
+
g_absorbedByButton[childId] = parentId;
|
|
217
|
+
clearPadding(p->second.node);
|
|
218
|
+
g_dirty = true;
|
|
219
|
+
return;
|
|
220
|
+
}
|
|
221
|
+
// Re-parenting/reorder: InsertChild aborta si el hijo ya tiene
|
|
222
|
+
// owner (move-child, popPreview) → detach primero.
|
|
223
|
+
if (YGNodeRef owner = YGNodeGetOwner(c->second.node))
|
|
224
|
+
YGNodeRemoveChild(owner, c->second.node);
|
|
225
|
+
uint32_t count = YGNodeGetChildCount(parent);
|
|
226
|
+
YGNodeInsertChild(parent, c->second.node,
|
|
227
|
+
static_cast<uint32_t>(index) > count
|
|
228
|
+
? count
|
|
229
|
+
: static_cast<uint32_t>(index));
|
|
230
|
+
g_dirty = true;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
void nodeRemove(int parentId, int childId) {
|
|
234
|
+
auto p = g_nodes.find(parentId);
|
|
235
|
+
auto c = g_nodes.find(childId);
|
|
236
|
+
if (p == g_nodes.end() || c == g_nodes.end())
|
|
237
|
+
return;
|
|
238
|
+
YGNodeRef parent = p->second.node;
|
|
239
|
+
// Hijo absorbido: nunca se insertó — solo limpiar la redirección.
|
|
240
|
+
if (g_absorbedByButton.erase(childId) > 0) {
|
|
241
|
+
if (YGNodeHasMeasureFunc(parent))
|
|
242
|
+
YGNodeMarkDirty(parent);
|
|
243
|
+
g_dirty = true;
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
246
|
+
YGNodeRemoveChild(parent, c->second.node);
|
|
247
|
+
g_dirty = true;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
void nodeMove(int parentId, int childId, int index) {
|
|
251
|
+
nodeRemove(parentId, childId);
|
|
252
|
+
nodeInsert(parentId, childId, index);
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
void nodeSetStyle(int id, const std::string &key, bool isNum, double num,
|
|
256
|
+
const std::string &str) {
|
|
257
|
+
auto it = g_nodes.find(id);
|
|
258
|
+
if (it == g_nodes.end())
|
|
259
|
+
return;
|
|
260
|
+
// Padding en hoja con measure func: lo lleva el widget en su
|
|
261
|
+
// medida — aplicarlo también aquí lo contaría dos veces (igual
|
|
262
|
+
// que Android: applyLeafPadding host-side).
|
|
263
|
+
if (key.rfind("padding", 0) == 0 && YGNodeHasMeasureFunc(it->second.node)) {
|
|
264
|
+
// Hoja medida: el padding lo suma el host a la medida (padW/padH
|
|
265
|
+
// Android) y lo aplica al widget — no entra al árbol.
|
|
266
|
+
float pv = static_cast<float>(num);
|
|
267
|
+
switch (elur::layout::edgeOf(key.substr(7))) {
|
|
268
|
+
case YGEdgeAll:
|
|
269
|
+
it->second.padL = it->second.padR = it->second.padT = it->second.padB =
|
|
270
|
+
pv;
|
|
271
|
+
break;
|
|
272
|
+
case YGEdgeHorizontal:
|
|
273
|
+
it->second.padL = it->second.padR = pv;
|
|
274
|
+
break;
|
|
275
|
+
case YGEdgeVertical:
|
|
276
|
+
it->second.padT = it->second.padB = pv;
|
|
277
|
+
break;
|
|
278
|
+
case YGEdgeLeft:
|
|
279
|
+
it->second.padL = pv;
|
|
280
|
+
break;
|
|
281
|
+
case YGEdgeRight:
|
|
282
|
+
it->second.padR = pv;
|
|
283
|
+
break;
|
|
284
|
+
case YGEdgeTop:
|
|
285
|
+
it->second.padT = pv;
|
|
286
|
+
break;
|
|
287
|
+
case YGEdgeBottom:
|
|
288
|
+
it->second.padB = pv;
|
|
289
|
+
break;
|
|
290
|
+
case YGEdgeStart:
|
|
291
|
+
if (g_rtl)
|
|
292
|
+
it->second.padR = pv;
|
|
293
|
+
else
|
|
294
|
+
it->second.padL = pv;
|
|
295
|
+
break;
|
|
296
|
+
case YGEdgeEnd:
|
|
297
|
+
if (g_rtl)
|
|
298
|
+
it->second.padL = pv;
|
|
299
|
+
else
|
|
300
|
+
it->second.padR = pv;
|
|
301
|
+
break;
|
|
302
|
+
default:
|
|
303
|
+
break;
|
|
304
|
+
}
|
|
305
|
+
g_dirty = true; // la medida de la hoja cambia
|
|
306
|
+
YGNodeMarkDirty(it->second.node);
|
|
307
|
+
return;
|
|
308
|
+
}
|
|
309
|
+
if (elur::layout::applyStyleProp(it->second.node, key, num, str, isNum))
|
|
310
|
+
g_dirty = true;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
void nodeSetText(int id) { markLeafDirty(id); }
|
|
314
|
+
|
|
315
|
+
void nodeSetDir(int id, bool rtl) {
|
|
316
|
+
auto it = g_nodes.find(id);
|
|
317
|
+
if (it == g_nodes.end())
|
|
318
|
+
return;
|
|
319
|
+
YGNodeStyleSetDirection(it->second.node,
|
|
320
|
+
rtl ? YGDirectionRTL : YGDirectionLTR);
|
|
321
|
+
g_dirty = true;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
void absorbIntoButton(int textId, int buttonId) {
|
|
325
|
+
g_absorbedByButton[textId] = buttonId;
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
int layoutIfDirty(const RectSink &sink) {
|
|
329
|
+
if (!g_dirty || !g_hasViewport || !g_root)
|
|
330
|
+
return 0;
|
|
331
|
+
g_dirty = false;
|
|
332
|
+
YGNodeStyleSetWidth(g_root, g_vpW);
|
|
333
|
+
YGNodeStyleSetHeight(g_root, g_vpH);
|
|
334
|
+
YGNodeCalculateLayout(g_root, g_vpW, g_vpH,
|
|
335
|
+
g_rtl ? YGDirectionRTL : YGDirectionLTR);
|
|
336
|
+
int count = 0;
|
|
337
|
+
// La raíz (shell) también emite: es el viewport de pantallas y su
|
|
338
|
+
// widget nativo necesita la caja para recortar transiciones nav-*
|
|
339
|
+
// (ElurClip — sin box propio reportaría la unión de hijos y la
|
|
340
|
+
// ventana crecería con el off-canvas).
|
|
341
|
+
int rid =
|
|
342
|
+
static_cast<int>(reinterpret_cast<intptr_t>(YGNodeGetContext(g_root)));
|
|
343
|
+
if (rid != 0) {
|
|
344
|
+
auto it = g_nodes.find(rid);
|
|
345
|
+
if (it != g_nodes.end()) {
|
|
346
|
+
Entry &e = it->second;
|
|
347
|
+
float x = YGNodeLayoutGetLeft(g_root);
|
|
348
|
+
float y = YGNodeLayoutGetTop(g_root);
|
|
349
|
+
float w = YGNodeLayoutGetWidth(g_root);
|
|
350
|
+
float h = YGNodeLayoutGetHeight(g_root);
|
|
351
|
+
if (!e.emitted || x != e.lastX || y != e.lastY || w != e.lastW ||
|
|
352
|
+
h != e.lastH) {
|
|
353
|
+
e.emitted = true;
|
|
354
|
+
e.lastX = x;
|
|
355
|
+
e.lastY = y;
|
|
356
|
+
e.lastW = w;
|
|
357
|
+
e.lastH = h;
|
|
358
|
+
sink(rid, x, y, w, h);
|
|
359
|
+
count++;
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
emitDfs(g_root, 0, sink, count);
|
|
364
|
+
return count;
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
void dumpRects(FILE *out) {
|
|
368
|
+
if (!g_root)
|
|
369
|
+
return;
|
|
370
|
+
auto num = [](float v, char *b) {
|
|
371
|
+
snprintf(b, 24, "%.4g", v);
|
|
372
|
+
for (char *p = b; *p; p++)
|
|
373
|
+
if (*p == ',')
|
|
374
|
+
*p = '.';
|
|
375
|
+
return b;
|
|
376
|
+
};
|
|
377
|
+
fprintf(out, "[rect] begin\n");
|
|
378
|
+
int rid =
|
|
379
|
+
static_cast<int>(reinterpret_cast<intptr_t>(YGNodeGetContext(g_root)));
|
|
380
|
+
if (rid) {
|
|
381
|
+
char x[24], y[24], w[24], h[24];
|
|
382
|
+
fprintf(out, "[rect] id=%d p=-1 %s,%s,%s,%s\n", rid,
|
|
383
|
+
num(YGNodeLayoutGetLeft(g_root), x),
|
|
384
|
+
num(YGNodeLayoutGetTop(g_root), y),
|
|
385
|
+
num(YGNodeLayoutGetWidth(g_root), w),
|
|
386
|
+
num(YGNodeLayoutGetHeight(g_root), h));
|
|
387
|
+
}
|
|
388
|
+
std::function<void(YGNodeRef)> dfs = [&](YGNodeRef yg) {
|
|
389
|
+
int pid =
|
|
390
|
+
static_cast<int>(reinterpret_cast<intptr_t>(YGNodeGetContext(yg)));
|
|
391
|
+
uint32_t n = YGNodeGetChildCount(yg);
|
|
392
|
+
for (uint32_t i = 0; i < n; i++) {
|
|
393
|
+
YGNodeRef child = YGNodeGetChild(yg, i);
|
|
394
|
+
// display:none no genera caja — el colector web filtra los suyos
|
|
395
|
+
// (cs.display==="none" → skip); misma semántica para que el
|
|
396
|
+
// árbol de comparación no cuente nodos fantasma.
|
|
397
|
+
if (YGNodeStyleGetDisplay(child) == YGDisplayNone)
|
|
398
|
+
continue;
|
|
399
|
+
int id =
|
|
400
|
+
static_cast<int>(reinterpret_cast<intptr_t>(YGNodeGetContext(child)));
|
|
401
|
+
if (id) {
|
|
402
|
+
char x[24], y[24], w[24], h[24];
|
|
403
|
+
fprintf(out, "[rect] id=%d p=%d %s,%s,%s,%s\n", id, pid,
|
|
404
|
+
num(YGNodeLayoutGetLeft(child), x),
|
|
405
|
+
num(YGNodeLayoutGetTop(child), y),
|
|
406
|
+
num(YGNodeLayoutGetWidth(child), w),
|
|
407
|
+
num(YGNodeLayoutGetHeight(child), h));
|
|
408
|
+
}
|
|
409
|
+
dfs(child);
|
|
410
|
+
}
|
|
411
|
+
};
|
|
412
|
+
dfs(g_root);
|
|
413
|
+
fprintf(out, "[rect] end\n");
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
void padOf(int id, float &l, float &t, float &r, float &b) {
|
|
417
|
+
auto it = g_nodes.find(id);
|
|
418
|
+
if (it == g_nodes.end()) {
|
|
419
|
+
l = t = r = b = 0;
|
|
420
|
+
return;
|
|
421
|
+
}
|
|
422
|
+
l = it->second.padL;
|
|
423
|
+
t = it->second.padT;
|
|
424
|
+
r = it->second.padR;
|
|
425
|
+
b = it->second.padB;
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
bool rectOf(int id, float &x, float &y, float &w, float &h) {
|
|
429
|
+
auto it = g_nodes.find(id);
|
|
430
|
+
if (it == g_nodes.end())
|
|
431
|
+
return false;
|
|
432
|
+
x = YGNodeLayoutGetLeft(it->second.node);
|
|
433
|
+
y = YGNodeLayoutGetTop(it->second.node);
|
|
434
|
+
w = YGNodeLayoutGetWidth(it->second.node);
|
|
435
|
+
h = YGNodeLayoutGetHeight(it->second.node);
|
|
436
|
+
return true;
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
std::string nodeType(int id) {
|
|
440
|
+
auto it = g_nodes.find(id);
|
|
441
|
+
return it == g_nodes.end() ? std::string() : it->second.type;
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
float nodeStyleMargin(int id, YGEdge edge) {
|
|
445
|
+
auto it = g_nodes.find(id);
|
|
446
|
+
if (it == g_nodes.end() || !it->second.node)
|
|
447
|
+
return 0.f;
|
|
448
|
+
YGValue v = YGNodeStyleGetMargin(it->second.node, edge);
|
|
449
|
+
return v.unit == YGUnitPoint ? v.value : 0.f;
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
} // namespace elur::yoga
|