xbintsc 0.6.9 → 0.6.12

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.
Files changed (164) hide show
  1. package/dist/src/checker/globals.js +2 -1
  2. package/dist/src/checker/globals.js.map +1 -1
  3. package/dist/src/cli/help.d.ts +1 -1
  4. package/dist/src/cli/main.js +1 -0
  5. package/dist/src/cli/main.js.map +1 -1
  6. package/dist/src/codegen/generator/state.js +3 -0
  7. package/dist/src/codegen/generator/state.js.map +1 -1
  8. package/dist/src/codegen/generator/tables.js +3 -0
  9. package/dist/src/codegen/generator/tables.js.map +1 -1
  10. package/dist/src/driver/compiler.js +1 -1
  11. package/dist/src/driver/compiler.js.map +1 -1
  12. package/dist/src/driver/config.js +1 -0
  13. package/dist/src/driver/config.js.map +1 -1
  14. package/dist/src/driver/runtime-objects.d.ts +1 -1
  15. package/dist/src/driver/runtime-objects.js +2 -0
  16. package/dist/src/driver/runtime-objects.js.map +1 -1
  17. package/dist/src/driver/version.d.ts +1 -1
  18. package/dist/src/driver/version.js +1 -1
  19. package/dist/src/driver/version.js.map +1 -1
  20. package/dist/src/extensions/node/crypto/index.js +12 -1
  21. package/dist/src/extensions/node/crypto/index.js.map +1 -1
  22. package/dist/tests/driver/config.test.js +15 -2
  23. package/dist/tests/driver/config.test.js.map +1 -1
  24. package/dist/tests/e2e/compile-builtins.test.js +26 -0
  25. package/dist/tests/e2e/compile-builtins.test.js.map +1 -1
  26. package/dist/tests/e2e/compile-node.test.js +37 -1
  27. package/dist/tests/e2e/compile-node.test.js.map +1 -1
  28. package/dist/tests/e2e/crypto-random.test.d.ts +9 -0
  29. package/dist/tests/e2e/crypto-random.test.js +63 -0
  30. package/dist/tests/e2e/crypto-random.test.js.map +1 -0
  31. package/dist/tests/e2e/date-parse.test.js +27 -1
  32. package/dist/tests/e2e/date-parse.test.js.map +1 -1
  33. package/dist/tests/e2e/gui-css-coverage.test.js +1 -1
  34. package/dist/tests/e2e/gui-dom.test.js +29 -0
  35. package/dist/tests/e2e/gui-dom.test.js.map +1 -1
  36. package/dist/tests/e2e/gui-form.test.d.ts +9 -0
  37. package/dist/tests/e2e/gui-form.test.js +359 -0
  38. package/dist/tests/e2e/gui-form.test.js.map +1 -0
  39. package/dist/tests/e2e/gui-helpers.d.ts +2 -0
  40. package/dist/tests/e2e/gui-helpers.js +1 -0
  41. package/dist/tests/e2e/gui-helpers.js.map +1 -1
  42. package/dist/tests/e2e/gui-layout.test.js +47 -0
  43. package/dist/tests/e2e/gui-layout.test.js.map +1 -1
  44. package/dist/tests/e2e/gui-paint.test.js +108 -0
  45. package/dist/tests/e2e/gui-paint.test.js.map +1 -1
  46. package/dist/tests/e2e/gui-script-import-order.test.js +6 -1
  47. package/dist/tests/e2e/gui-script-import-order.test.js.map +1 -1
  48. package/dist/tests/e2e/gui-style.test.js +82 -0
  49. package/dist/tests/e2e/gui-style.test.js.map +1 -1
  50. package/dist/tests/e2e/gui-unsupported.test.d.ts +6 -0
  51. package/dist/tests/e2e/gui-unsupported.test.js +124 -0
  52. package/dist/tests/e2e/gui-unsupported.test.js.map +1 -0
  53. package/dist/tests/e2e/json-parse-errors.test.d.ts +9 -0
  54. package/dist/tests/e2e/json-parse-errors.test.js +48 -0
  55. package/dist/tests/e2e/json-parse-errors.test.js.map +1 -0
  56. package/doc/ai/extensions.md +7 -4
  57. package/doc/ai/language-support.md +2 -1
  58. package/doc/ai/zh-CN/extensions.md +6 -3
  59. package/doc/ai/zh-CN/language-support.md +2 -1
  60. package/doc/gui/api.md +8 -2
  61. package/doc/gui/dom.md +81 -4
  62. package/doc/gui/input.md +74 -3
  63. package/doc/gui/known-issues.md +12 -5
  64. package/doc/gui/layout.md +19 -6
  65. package/doc/gui/rendering.md +16 -9
  66. package/doc/implemented/node/crypto.md +8 -0
  67. package/doc/implemented/node/fs.md +1 -1
  68. package/doc/implemented/stdlib.md +10 -2
  69. package/doc/zh-CN/gui/api.md +8 -2
  70. package/doc/zh-CN/gui/dom.md +70 -4
  71. package/doc/zh-CN/gui/input.md +65 -4
  72. package/doc/zh-CN/gui/known-issues.md +11 -4
  73. package/doc/zh-CN/gui/layout.md +14 -4
  74. package/doc/zh-CN/gui/rendering.md +13 -10
  75. package/doc/zh-CN/implemented/node/crypto.md +6 -0
  76. package/doc/zh-CN/implemented/node/fs.md +1 -1
  77. package/doc/zh-CN/implemented/stdlib.md +10 -2
  78. package/package.json +7 -7
  79. package/runtime/ext_gui/clip_values.cpp +11 -0
  80. package/runtime/ext_gui/css.cpp +27 -2
  81. package/runtime/ext_gui/css_match.cpp +21 -1
  82. package/runtime/ext_gui/css_selector.cpp +23 -0
  83. package/runtime/ext_gui/css_sheet.cpp +7 -0
  84. package/runtime/ext_gui/document.cpp +15 -0
  85. package/runtime/ext_gui/document_animation.cpp +4 -1
  86. package/runtime/ext_gui/dom.h +41 -2
  87. package/runtime/ext_gui/dom_api.cpp +3 -0
  88. package/runtime/ext_gui/dom_api_document.cpp +28 -0
  89. package/runtime/ext_gui/dom_api_events.cpp +17 -14
  90. package/runtime/ext_gui/dom_api_form.cpp +567 -0
  91. package/runtime/ext_gui/dom_api_internal.h +46 -214
  92. package/runtime/ext_gui/dom_api_mutation.cpp +1 -1
  93. package/runtime/ext_gui/dom_api_node.cpp +10 -3
  94. package/runtime/ext_gui/dom_api_node_read.cpp +1 -1
  95. package/runtime/ext_gui/dom_api_proto.cpp +45 -0
  96. package/runtime/ext_gui/dom_api_webgl_methods.h +217 -0
  97. package/runtime/ext_gui/dom_parse.cpp +118 -1
  98. package/runtime/ext_gui/effect_values.cpp +28 -7
  99. package/runtime/ext_gui/form_focus.cpp +293 -0
  100. package/runtime/ext_gui/form_input.cpp +448 -0
  101. package/runtime/ext_gui/form_internal.h +30 -0
  102. package/runtime/ext_gui/form_shared.cpp +126 -0
  103. package/runtime/ext_gui/form_state.cpp +536 -0
  104. package/runtime/ext_gui/form_state.h +97 -0
  105. package/runtime/ext_gui/gradient_values.cpp +25 -5
  106. package/runtime/ext_gui/gui_engine.h +40 -4
  107. package/runtime/ext_gui/gui_events.cpp +63 -48
  108. package/runtime/ext_gui/inline_svg.cpp +3 -0
  109. package/runtime/ext_gui/layout.cpp +6 -0
  110. package/runtime/ext_gui/layout.h +4 -0
  111. package/runtime/ext_gui/layout_flow.cpp +35 -3
  112. package/runtime/ext_gui/layout_inline.cpp +80 -7
  113. package/runtime/ext_gui/media_query.cpp +7 -1
  114. package/runtime/ext_gui/paint.cpp +62 -24
  115. package/runtime/ext_gui/paint.h +7 -4
  116. package/runtime/ext_gui/paint_clip.cpp +74 -19
  117. package/runtime/ext_gui/paint_form.cpp +389 -0
  118. package/runtime/ext_gui/paint_internal.h +13 -1
  119. package/runtime/ext_gui/renderer_clip.cpp +19 -17
  120. package/runtime/ext_gui/style.cpp +5 -1
  121. package/runtime/ext_gui/style.h +5 -0
  122. package/runtime/ext_gui/style_cascade.cpp +2 -0
  123. package/runtime/ext_gui/style_internal.h +7 -2
  124. package/runtime/ext_gui/style_print.cpp +33 -0
  125. package/runtime/ext_gui/style_text.cpp +11 -0
  126. package/runtime/ext_gui/style_ua.cpp +42 -0
  127. package/runtime/ext_gui/style_values.cpp +89 -90
  128. package/runtime/ext_gui/transform.cpp +2 -0
  129. package/runtime/ext_gui/warnings.cpp +298 -0
  130. package/runtime/ext_gui/warnings.h +59 -0
  131. package/runtime/ext_gui/window.cpp +31 -55
  132. package/runtime/ext_gui/window_diagnostics.cpp +58 -0
  133. package/runtime/ext_gui/window_emit.cpp +51 -0
  134. package/runtime/ext_node/crypto/crypto.c +3 -2
  135. package/runtime/ext_node/crypto/crypto_hash.h +13 -0
  136. package/runtime/ext_node/crypto/crypto_random.c +339 -0
  137. package/runtime/ext_node/fs/async_worker.c +1 -1
  138. package/runtime/ext_node/fs/fs_ops.c +1 -1
  139. package/runtime/ext_node/fs/parts/platform.inc +65 -0
  140. package/runtime/rt.h +27 -0
  141. package/runtime/xt_crypto.c +132 -0
  142. package/runtime/xt_random.c +143 -0
  143. package/runtime/xt_regex/matcher.inc +9 -28
  144. package/runtime/xt_regex/parser.inc +65 -2
  145. package/runtime/xt_regex/types.inc +11 -1
  146. package/runtime/xt_regex.h +6 -2
  147. package/runtime/xt_stdlib/dispatch.inc +2 -0
  148. package/runtime/xt_stdlib/math.inc +1 -1
  149. package/runtime/xt_stdlib2/date.inc +204 -4
  150. package/runtime/xt_stdlib2/json.inc +4 -546
  151. package/runtime/xt_stdlib2/json_parse.inc +347 -0
  152. package/runtime/xt_stdlib2/json_stringify.inc +368 -0
  153. package/runtime/xt_stdlib2/regexp-match.inc +6 -11
  154. package/runtime/xt_stdlib2.c +0 -4
  155. package/runtime/xt_typed_array/elements.inc +6 -1
  156. package/src/checker/globals.ts +2 -0
  157. package/src/cli/main.ts +1 -0
  158. package/src/codegen/generator/state.ts +3 -0
  159. package/src/codegen/generator/tables.ts +3 -0
  160. package/src/driver/compiler.ts +1 -1
  161. package/src/driver/config.ts +1 -0
  162. package/src/driver/runtime-objects.ts +2 -0
  163. package/src/driver/version.ts +1 -1
  164. package/src/extensions/node/crypto/index.ts +12 -1
@@ -0,0 +1,389 @@
1
+ /*
2
+ * xbintsc GUI engine — form-control painting.
3
+ *
4
+ * The control's value, selection, caret and type-specific decorations
5
+ * (checkbox tick, radio dot, range thumb, select arrow, colour swatch) are
6
+ * painted from `Node::form`. Text is clipped to the content box so a long value
7
+ * cannot bleed over the border.
8
+ */
9
+
10
+ #include "paint_internal.h"
11
+
12
+ #include <algorithm>
13
+ #include <cmath>
14
+ #include <cstdio>
15
+ #include <cstdlib>
16
+ #include <string>
17
+ #include <vector>
18
+
19
+ #include "form_state.h"
20
+ #include "layout.h"
21
+
22
+ namespace xtgui {
23
+
24
+ namespace {
25
+
26
+ FontSpec specOf(const XtStyle &style) {
27
+ FontSpec spec;
28
+ spec.family = style.font_family;
29
+ spec.pixel_size = style.font_size;
30
+ spec.weight = style.font_weight;
31
+ spec.italic = style.font_style == FontStyle::Italic;
32
+ spec.letter_spacing = style.letter_spacing.unit == Unit::Px ? style.letter_spacing.value : 0.0f;
33
+ return spec;
34
+ }
35
+
36
+ float lineHeightOf(const XtStyle &style) { return style.font_size * 1.2f; }
37
+
38
+ void addRun(DisplayList &out, float x, float baseline, const std::string &text,
39
+ const XtStyle &style, const Color &color, const LayoutBox &box, const PaintClip &clip,
40
+ const paint_detail::FilterChain &chain, float viewportWidth, float viewportHeight) {
41
+ if (text.empty() || color.a <= 0.0f) return;
42
+ FontSpec spec = specOf(style);
43
+ float width = xt_text_measure_width(text, spec);
44
+ float height = lineHeightOf(style);
45
+ paint_detail::addTextRun(out, x, baseline, width, height, text, spec, color, box.world, clip,
46
+ style, chain, viewportWidth, viewportHeight);
47
+ }
48
+
49
+ float runWidth(const std::string &text, const XtStyle &style) {
50
+ return xt_text_measure_width(text, specOf(style));
51
+ }
52
+
53
+ float prefixWidth(const std::string &text, size_t units, const XtStyle &style) {
54
+ return runWidth(xt_form_utf16_slice(text, 0, units), style);
55
+ }
56
+
57
+ PaintClip intersectContent(const LayoutBox &box, const PaintClip &clip) {
58
+ PaintClip result = clip;
59
+ float x = box.content_x;
60
+ float y = box.content_y;
61
+ float width = box.content_width;
62
+ float height = box.content_height;
63
+ if (width < 0.0f) width = 0.0f;
64
+ if (height < 0.0f) height = 0.0f;
65
+ if (!clip.active) {
66
+ result.active = true;
67
+ result.x = x;
68
+ result.y = y;
69
+ result.width = width;
70
+ result.height = height;
71
+ return result;
72
+ }
73
+ float x0 = std::max(x, clip.x);
74
+ float y0 = std::max(y, clip.y);
75
+ float x1 = std::min(x + width, clip.x + clip.width);
76
+ float y1 = std::min(y + height, clip.y + clip.height);
77
+ result.x = x0;
78
+ result.y = y0;
79
+ result.width = std::max(0.0f, x1 - x0);
80
+ result.height = std::max(0.0f, y1 - y0);
81
+ return result;
82
+ }
83
+
84
+ void addRect(DisplayList &out, float x, float y, float width, float height, float radius,
85
+ const Color &color, const PaintClip &clip, const LayoutBox &box,
86
+ const paint_detail::FilterChain &chain) {
87
+ if (width <= 0.0f || height <= 0.0f || color.a <= 0.0f) return;
88
+ paint_detail::addRectFiltered(out, x, y, width, height, radius, color, clip, box.world, chain);
89
+ }
90
+
91
+ Color withAlpha(Color color, float alpha) {
92
+ color.a *= alpha;
93
+ return color;
94
+ }
95
+
96
+ Color shade(const XtStyle &style, bool disabled, float alpha) {
97
+ Color color = style.color;
98
+ if (disabled) color = Color{0.55f, 0.55f, 0.55f, color.a};
99
+ color.a *= alpha;
100
+ return color;
101
+ }
102
+
103
+ /** Split `text` into visual lines (`\n`) and report each line's UTF-16 range. */
104
+ struct VisualLine {
105
+ size_t start;
106
+ size_t end;
107
+ std::string text;
108
+ };
109
+
110
+ std::vector<VisualLine> splitLines(const std::string &text) {
111
+ std::vector<VisualLine> lines;
112
+ size_t byte_start = 0;
113
+ size_t units = 0;
114
+ size_t line_start_units = 0;
115
+ size_t offset = 0;
116
+ while (offset <= text.size()) {
117
+ if (offset == text.size() || text[offset] == '\n') {
118
+ VisualLine line;
119
+ line.start = line_start_units;
120
+ line.end = units;
121
+ line.text = text.substr(byte_start, offset - byte_start);
122
+ lines.push_back(line);
123
+ byte_start = offset + 1;
124
+ line_start_units = units;
125
+ if (offset == text.size()) break;
126
+ offset++;
127
+ continue;
128
+ }
129
+ size_t width = 1;
130
+ uint32_t code = (unsigned char)text[offset];
131
+ if (code < 0x80) width = 1;
132
+ else if ((code & 0xE0) == 0xC0) width = 2;
133
+ else if ((code & 0xF0) == 0xE0) width = 3;
134
+ else width = 4;
135
+ units += (code >= 0xF0) ? 2 : 1;
136
+ offset += width;
137
+ }
138
+ return lines;
139
+ }
140
+
141
+ void paintTextControl(const LayoutBox &box, const XtStyle &style, const FormState &state,
142
+ DisplayList &out, const PaintClip &clip,
143
+ const paint_detail::FilterChain &chain, float viewportWidth,
144
+ float viewportHeight) {
145
+ bool disabled = xt_form_is_disabled(box.node);
146
+ bool password = xt_form_type(box.node) == "password";
147
+ std::string display = state.value;
148
+ size_t caret = (size_t)state.selection_end;
149
+ if (state.composing) {
150
+ size_t length = xt_form_utf16_length(state.value);
151
+ size_t start = std::min((size_t)state.selection_start, length);
152
+ size_t end = std::min((size_t)state.selection_end, length);
153
+ display = xt_form_utf16_slice(state.value, 0, start) + state.composition +
154
+ xt_form_utf16_slice(state.value, end, length);
155
+ caret = start + xt_form_utf16_length(state.composition);
156
+ }
157
+ if (password) display = xt_form_mask(display);
158
+ size_t display_units = xt_form_utf16_length(display);
159
+ if (caret > display_units) caret = display_units;
160
+
161
+ float line_height = lineHeightOf(style);
162
+ FontSpec spec = specOf(style);
163
+ float ascent = 0.0f;
164
+ xt_text_metrics(spec, &ascent, nullptr, nullptr);
165
+ if (ascent <= 0.0f) ascent = style.font_size * 0.8f;
166
+
167
+ bool placeholder = display.empty() && !state.composing && !state.focused;
168
+ if (state.value.empty() && !state.composing) {
169
+ const std::string *hint = box.node->attr("placeholder");
170
+ if (hint != nullptr && !hint->empty() && state.value.empty()) {
171
+ std::string text = *hint;
172
+ float baseline = box.content_y + (box.content_height - line_height) / 2.0f + ascent;
173
+ addRun(out, box.content_x, baseline, text, style, shade(style, disabled, 0.45f), box, clip,
174
+ chain, viewportWidth, viewportHeight);
175
+ placeholder = true;
176
+ }
177
+ }
178
+
179
+ bool multiline = xt_form_is_textarea(box.node);
180
+ std::vector<VisualLine> lines = multiline ? splitLines(display) : std::vector<VisualLine>();
181
+ if (!multiline) {
182
+ VisualLine line;
183
+ line.start = 0;
184
+ line.end = display_units;
185
+ line.text = display;
186
+ lines.push_back(line);
187
+ }
188
+
189
+ size_t selection_start = (size_t)state.selection_start;
190
+ size_t selection_end = (size_t)state.selection_end;
191
+ if (selection_end < selection_start) std::swap(selection_start, selection_end);
192
+ bool has_selection = state.focused && selection_end > selection_start && !state.composing;
193
+ Color highlight{0.26f, 0.55f, 1.0f, 0.35f};
194
+
195
+ if (!placeholder) {
196
+ for (size_t index = 0; index < lines.size(); index++) {
197
+ const VisualLine &line = lines[index];
198
+ float y = multiline ? box.content_y + (float)index * line_height
199
+ : box.content_y + (box.content_height - line_height) / 2.0f;
200
+ if (multiline && y >= box.content_y + box.content_height) break;
201
+ float baseline = y + ascent;
202
+ if (has_selection) {
203
+ size_t start = std::max(selection_start, line.start);
204
+ size_t end = std::min(selection_end, line.end);
205
+ if (end > start) {
206
+ float x0 = box.content_x + prefixWidth(line.text, start - line.start, style);
207
+ float x1 = box.content_x + prefixWidth(line.text, end - line.start, style);
208
+ addRect(out, x0, y, x1 - x0, line_height, 0.0f, highlight, clip, box, chain);
209
+ }
210
+ }
211
+ addRun(out, box.content_x, baseline, line.text, style, shade(style, disabled, 1.0f), box,
212
+ clip, chain, viewportWidth, viewportHeight);
213
+ if (state.composing) {
214
+ float x0 = box.content_x;
215
+ float x1 = box.content_x + runWidth(line.text, style);
216
+ addRect(out, x0, y + line_height - 1.0f, x1 - x0, 1.0f, 0.0f,
217
+ shade(style, disabled, 0.9f), clip, box, chain);
218
+ }
219
+ }
220
+ }
221
+
222
+ if (state.focused && !state.composing && !has_selection) {
223
+ size_t line_index = 0;
224
+ size_t column = caret;
225
+ for (size_t index = 0; index < lines.size(); index++) {
226
+ if (caret >= lines[index].start && caret <= lines[index].end) {
227
+ line_index = index;
228
+ column = caret - lines[index].start;
229
+ break;
230
+ }
231
+ }
232
+ float y = multiline ? box.content_y + (float)line_index * line_height
233
+ : box.content_y + (box.content_height - line_height) / 2.0f;
234
+ float x = box.content_x + prefixWidth(lines[line_index].text, column, style);
235
+ addRect(out, x, y + 1.0f, 1.5f, line_height - 2.0f, 0.0f, shade(style, disabled, 1.0f), clip,
236
+ box, chain);
237
+ }
238
+ }
239
+
240
+ void paintCheckbox(const LayoutBox &box, const XtStyle &style, const FormState &state,
241
+ DisplayList &out, const PaintClip &clip, const paint_detail::FilterChain &chain,
242
+ bool radio) {
243
+ bool disabled = xt_form_is_disabled(box.node);
244
+ float size = std::max(13.0f, style.font_size * 0.9f);
245
+ float x = box.content_x + (box.content_width - size) / 2.0f;
246
+ float y = box.content_y + (box.content_height - size) / 2.0f;
247
+ Color border = disabled ? Color{0.6f, 0.6f, 0.6f, 1.0f} : Color{0.34f, 0.34f, 0.34f, 1.0f};
248
+ Color fill = disabled ? Color{0.94f, 0.94f, 0.94f, 1.0f} : Color{1.0f, 1.0f, 1.0f, 1.0f};
249
+ float radius = radio ? size / 2.0f : 2.0f;
250
+ addRect(out, x, y, size, size, radius, border, clip, box, chain);
251
+ addRect(out, x + 1.0f, y + 1.0f, size - 2.0f, size - 2.0f, std::max(0.0f, radius - 1.0f), fill,
252
+ clip, box, chain);
253
+ if (state.checked) {
254
+ Color accent = disabled ? Color{0.6f, 0.6f, 0.6f, 1.0f} : Color{0.17f, 0.42f, 0.69f, 1.0f};
255
+ if (radio) {
256
+ float inner = size - 8.0f;
257
+ addRect(out, x + 4.0f, y + 4.0f, inner, inner, inner / 2.0f, accent, clip, box, chain);
258
+ } else {
259
+ addRect(out, x + 3.0f, y + 3.0f, size - 6.0f, size - 6.0f, 1.0f, accent, clip, box, chain);
260
+ }
261
+ }
262
+ }
263
+
264
+ void paintRange(const LayoutBox &box, const XtStyle &style, const FormState &state,
265
+ DisplayList &out, const PaintClip &clip, const paint_detail::FilterChain &chain) {
266
+ bool disabled = xt_form_is_disabled(box.node);
267
+ double minimum = 0.0;
268
+ double maximum = 100.0;
269
+ const std::string *min_attr = box.node->attr("min");
270
+ const std::string *max_attr = box.node->attr("max");
271
+ if (min_attr != nullptr) minimum = std::strtod(min_attr->c_str(), nullptr);
272
+ if (max_attr != nullptr) maximum = std::strtod(max_attr->c_str(), nullptr);
273
+ if (maximum <= minimum) maximum = minimum + 1.0;
274
+ double value = std::strtod(state.value.c_str(), nullptr);
275
+ float fraction = (float)((value - minimum) / (maximum - minimum));
276
+ if (fraction < 0.0f) fraction = 0.0f;
277
+ if (fraction > 1.0f) fraction = 1.0f;
278
+ float track_height = 4.0f;
279
+ float track_y = box.content_y + (box.content_height - track_height) / 2.0f;
280
+ float thumb = 12.0f;
281
+ float travel = std::max(0.0f, box.content_width - thumb);
282
+ float thumb_x = box.content_x + fraction * travel;
283
+ float thumb_y = box.content_y + (box.content_height - thumb) / 2.0f;
284
+ Color track = disabled ? Color{0.8f, 0.8f, 0.8f, 1.0f} : Color{0.78f, 0.78f, 0.78f, 1.0f};
285
+ Color accent = disabled ? Color{0.6f, 0.6f, 0.6f, 1.0f} : Color{0.17f, 0.42f, 0.69f, 1.0f};
286
+ addRect(out, box.content_x, track_y, box.content_width, track_height, 2.0f, track, clip, box,
287
+ chain);
288
+ addRect(out, box.content_x, track_y, thumb_x - box.content_x + thumb / 2.0f, track_height, 2.0f,
289
+ accent, clip, box, chain);
290
+ addRect(out, thumb_x, thumb_y, thumb, thumb, thumb / 2.0f, accent, clip, box, chain);
291
+ }
292
+
293
+ void paintColorSwatch(const LayoutBox &box, const XtStyle &style, const FormState &state,
294
+ DisplayList &out, const PaintClip &clip,
295
+ const paint_detail::FilterChain &chain) {
296
+ float size = std::min(box.content_width, box.content_height);
297
+ if (size <= 0.0f) return;
298
+ float x = box.content_x + (box.content_width - size) / 2.0f;
299
+ float y = box.content_y + (box.content_height - size) / 2.0f;
300
+ Color color = xt_css_parse_color(state.value);
301
+ if (!color.valid) color = Color{0.0f, 0.0f, 0.0f, 1.0f};
302
+ addRect(out, x, y, size, size, 2.0f, Color{0.34f, 0.34f, 0.34f, 1.0f}, clip, box, chain);
303
+ addRect(out, x + 1.0f, y + 1.0f, size - 2.0f, size - 2.0f, 1.0f, color, clip, box, chain);
304
+ }
305
+
306
+ void paintSelect(const LayoutBox &box, const XtStyle &style, const FormState &state,
307
+ DisplayList &out, const PaintClip &clip, const paint_detail::FilterChain &chain,
308
+ float viewportWidth, float viewportHeight) {
309
+ const Node *option = xt_form_selected_option(box.node);
310
+ std::string label = option != nullptr ? xt_form_option_label(option) : "";
311
+ float line_height = lineHeightOf(style);
312
+ FontSpec spec = specOf(style);
313
+ float ascent = 0.0f;
314
+ xt_text_metrics(spec, &ascent, nullptr, nullptr);
315
+ if (ascent <= 0.0f) ascent = style.font_size * 0.8f;
316
+ float baseline = box.content_y + (box.content_height - line_height) / 2.0f + ascent;
317
+ addRun(out, box.content_x, baseline, label, style, shade(style, xt_form_is_disabled(box.node), 1.0f),
318
+ box, clip, chain, viewportWidth, viewportHeight);
319
+ /* A downward chevron on the right, like a native select. */
320
+ float arrow_size = 5.0f;
321
+ float ax = box.content_x + box.content_width - 10.0f;
322
+ float ay = box.content_y + (box.content_height - arrow_size) / 2.0f + 1.0f;
323
+ addRect(out, ax, ay, arrow_size, 1.5f, 0.0f, Color{0.25f, 0.25f, 0.25f, 1.0f}, clip, box, chain);
324
+ addRect(out, ax + 0.8f, ay + 1.2f, arrow_size - 1.6f, 1.5f, 0.0f,
325
+ Color{0.25f, 0.25f, 0.25f, 1.0f}, clip, box, chain);
326
+ }
327
+
328
+ void paintButtonLabel(const LayoutBox &box, const LayoutBox &shape, const XtStyle &style,
329
+ const std::string &label, DisplayList &out, const PaintClip &clip,
330
+ const paint_detail::FilterChain &chain, float viewportWidth,
331
+ float viewportHeight) {
332
+ float width = runWidth(label, style);
333
+ float line_height = lineHeightOf(style);
334
+ FontSpec spec = specOf(style);
335
+ float ascent = 0.0f;
336
+ xt_text_metrics(spec, &ascent, nullptr, nullptr);
337
+ if (ascent <= 0.0f) ascent = style.font_size * 0.8f;
338
+ float x = box.content_x + (box.content_width - width) / 2.0f;
339
+ float baseline = box.content_y + (box.content_height - line_height) / 2.0f + ascent;
340
+ addRun(out, x, baseline, label, style, shade(style, xt_form_is_disabled(box.node), 1.0f), shape,
341
+ clip, chain, viewportWidth, viewportHeight);
342
+ }
343
+
344
+ } // namespace
345
+
346
+ namespace paint_detail {
347
+
348
+ void xt_paint_form_control(const LayoutBox &box, const XtStyle &style, DisplayList &out,
349
+ const PaintClip &clip, const FilterChain &chain, float viewportWidth,
350
+ float viewportHeight) {
351
+ if (box.node == nullptr || !xt_form_is_control(box.node)) return;
352
+ const FormState *state = xt_form_state(box.node);
353
+ if (state == nullptr) return;
354
+ PaintClip content = intersectContent(box, clip);
355
+ std::string type = xt_form_type(box.node);
356
+ if (xt_form_is_textarea(box.node) || xt_form_is_text_like(box.node)) {
357
+ paintTextControl(box, style, *state, out, content, chain, viewportWidth, viewportHeight);
358
+ return;
359
+ }
360
+ if (type == "checkbox" || type == "radio") {
361
+ paintCheckbox(box, style, *state, out, content, chain, type == "radio");
362
+ return;
363
+ }
364
+ if (type == "range") {
365
+ paintRange(box, style, *state, out, content, chain);
366
+ return;
367
+ }
368
+ if (type == "color") {
369
+ paintColorSwatch(box, style, *state, out, content, chain);
370
+ return;
371
+ }
372
+ if (xt_form_is_select(box.node)) {
373
+ paintSelect(box, style, *state, out, content, chain, viewportWidth, viewportHeight);
374
+ return;
375
+ }
376
+ if (xt_form_is_button_like(box.node)) {
377
+ paintButtonLabel(box, box, style, xt_form_button_label(box.node), out, content, chain,
378
+ viewportWidth, viewportHeight);
379
+ return;
380
+ }
381
+ if (type == "file") {
382
+ paintButtonLabel(box, box, style, "Choose File", out, content, chain, viewportWidth,
383
+ viewportHeight);
384
+ }
385
+ }
386
+
387
+ } // namespace paint_detail
388
+
389
+ } // namespace xtgui
@@ -103,11 +103,23 @@ void addBitmapImage(DisplayList &out, std::shared_ptr<const PaintBitmap> bitmap,
103
103
  bool addBackdropFilter(DisplayList &out, const LayoutBox &box, const XtStyle &style,
104
104
  const PaintClip &clip, float viewportWidth, float viewportHeight);
105
105
 
106
+ /** Paint the value/selection/caret and type-specific decoration of a form
107
+ * control (`<input>`, `<textarea>`, `<select>`). */
108
+ void xt_paint_form_control(const LayoutBox &box, const XtStyle &style, DisplayList &out,
109
+ const PaintClip &clip, const FilterChain &chain,
110
+ float viewportWidth, float viewportHeight);
111
+
106
112
  /** Resolve `clip-path` into a device-space triangulated polygon. */
107
113
  int addClipPathForBox(DisplayList &out, const LayoutBox &box, const XtStyle &style,
108
114
  float viewportWidth, float viewportHeight);
109
115
 
110
- /** Push `index` onto a clip chain (at most two survive). */
116
+ /** Resolve the rounded padding box an `overflow` clip uses into a device-space
117
+ * triangulated polygon, approximating each corner with short chords. The
118
+ * corners stay round after a transform because every point is mapped. */
119
+ int addRoundedClipPath(DisplayList &out, const Matrix2D &world, float x, float y, float width,
120
+ float height, float radius);
121
+
122
+ /** Push `index` onto a clip chain (at most `PaintClip::kMaxPaths` survive). */
111
123
  PaintClip addClipPath(PaintClip clip, int index);
112
124
 
113
125
  } // namespace paint_detail
@@ -10,6 +10,7 @@
10
10
  #include "renderer_internal.h"
11
11
 
12
12
  #include <algorithm>
13
+ #include <utility>
13
14
  #include <vector>
14
15
 
15
16
  namespace xtgui {
@@ -86,26 +87,27 @@ uint32_t appendClipped(std::vector<V> &out, const std::vector<V> &quad, const Pa
86
87
  appendFan(quad, &out);
87
88
  return 6;
88
89
  }
89
- const ClipPathGeometry *first = pathAt(list, clip.paths[0]);
90
- if (first == nullptr || first->triangles.empty()) return 0;
91
- uint32_t before = (uint32_t)out.size();
92
- if (clip.path_count == 1) {
93
- for (const ClipTriangle &triangle : first->triangles) {
94
- std::vector<V> clipped = clipToTriangle(quad, triangle, mix);
95
- if (clipped.size() >= 3) appendFan(clipped, &out);
96
- }
97
- } else {
98
- const ClipPathGeometry *second = pathAt(list, clip.paths[1]);
99
- if (second == nullptr || second->triangles.empty()) return 0;
100
- for (const ClipTriangle &outer : first->triangles) {
101
- std::vector<V> firstClip = clipToTriangle(quad, outer, mix);
102
- if (firstClip.size() < 3) continue;
103
- for (const ClipTriangle &inner : second->triangles) {
104
- std::vector<V> secondClip = clipToTriangle(firstClip, inner, mix);
105
- if (secondClip.size() >= 3) appendFan(secondClip, &out);
90
+ /* Start with the convex quad and clip it by every path in turn. Each path is
91
+ * a triangulated (possibly concave) polygon, so intersecting a convex piece
92
+ * with its triangles partitions it correctly; the result may be several
93
+ * convex pieces, which the next path clips independently. */
94
+ std::vector<std::vector<V>> pieces;
95
+ pieces.push_back(quad);
96
+ for (int p = 0; p < clip.path_count; p++) {
97
+ const ClipPathGeometry *path = pathAt(list, clip.paths[p]);
98
+ if (path == nullptr || path->triangles.empty()) return 0;
99
+ std::vector<std::vector<V>> next;
100
+ for (const std::vector<V> &piece : pieces) {
101
+ for (const ClipTriangle &triangle : path->triangles) {
102
+ std::vector<V> clipped = clipToTriangle(piece, triangle, mix);
103
+ if (clipped.size() >= 3) next.push_back(std::move(clipped));
106
104
  }
107
105
  }
106
+ pieces = std::move(next);
107
+ if (pieces.empty()) return 0;
108
108
  }
109
+ uint32_t before = (uint32_t)out.size();
110
+ for (const std::vector<V> &piece : pieces) appendFan(piece, &out);
109
111
  return (uint32_t)out.size() - before;
110
112
  }
111
113
 
@@ -10,6 +10,7 @@
10
10
 
11
11
  #include "css_internal.h"
12
12
  #include "perf.h"
13
+ #include "warnings.h"
13
14
 
14
15
  #include <algorithm>
15
16
  #include <cctype>
@@ -241,7 +242,9 @@ void applyCandidates(XtStyle *style, std::vector<Candidate> *candidates,
241
242
  if (xt_css_lower(value).find("current") != std::string::npos) {
242
243
  value = xt_style_replace_current_color(value, style->color);
243
244
  }
244
- xt_style_apply_declaration(style, property, value, nodeContext);
245
+ if (!xt_style_apply_declaration(style, property, value, nodeContext)) {
246
+ xt_warn_unsupported_property(property);
247
+ }
245
248
  }
246
249
  }
247
250
 
@@ -359,6 +362,7 @@ std::string resolveContent(const Node *origin, const std::string &raw, bool *gen
359
362
  }
360
363
  if (i < value.size() && value[i] == '(') {
361
364
  /* Unsupported function (`counter`, `counters`, `url`, …): skip it. */
365
+ xt_warn_unsupported_function("content", token);
362
366
  int depth = 0;
363
367
  for (; i < value.size(); i++) {
364
368
  if (value[i] == '(') depth++;
@@ -33,6 +33,8 @@ enum class AlignContent { Stretch, FlexStart, FlexEnd, Center, SpaceBetween, Spa
33
33
  enum class FloatSide { None, Left, Right };
34
34
  enum class Clear { None, Left, Right, Both };
35
35
  enum class TextAlign { Start, Center, End, Justify };
36
+ /** `text-overflow` on an overflowing line; the engine signals it with U+2026. */
37
+ enum class TextOverflow { Clip, Ellipsis };
36
38
  enum class WhiteSpace { Normal, NoWrap, Pre, PreWrap, PreLine };
37
39
  enum class Overflow { Visible, Hidden, Scroll, Auto };
38
40
  enum class BorderStyle { None, Solid, Dashed, Dotted };
@@ -304,6 +306,9 @@ struct XtStyle {
304
306
  Length line_height; // Auto = normal; Number = multiplier
305
307
 
306
308
  TextAlign text_align = TextAlign::Start; // inherited
309
+ /** `text-overflow`; not inherited. Only meaningful when the box clips
310
+ * (`overflow` other than `visible`). */
311
+ TextOverflow text_overflow = TextOverflow::Clip;
307
312
  WhiteSpace white_space = WhiteSpace::Normal; // inherited
308
313
  TextTransform text_transform = TextTransform::None; // inherited
309
314
  /** Resolved to pixels in the cascade (em is the element's own font size). */
@@ -18,6 +18,8 @@ void xt_style_apply_inherit(XtStyle *style, const XtStyle *parent, const std::st
18
18
  if (parent == nullptr) return;
19
19
  if (property == "color") {
20
20
  style->color = parent->color;
21
+ } else if (property == "text-overflow") {
22
+ style->text_overflow = parent->text_overflow;
21
23
  } else if (property == "clip-path") {
22
24
  style->clip_path = parent->clip_path;
23
25
  } else if (property == "font") {
@@ -36,8 +36,13 @@ void xt_style_apply_user_agent(const Node *node, XtStyle *style);
36
36
  float xt_style_border_radius_px(const Length &radius, float width, float height, float em,
37
37
  float root, float vw, float vh);
38
38
 
39
- /** Apply a parsed declaration to a computed style. */
40
- void xt_style_apply_declaration(XtStyle *style, const std::string &property,
39
+ /** Apply a parsed declaration to a computed style.
40
+ *
41
+ * Returns false only when the *property name* is not part of the engine's
42
+ * subset; a recognised property with an unparsable value returns true (the
43
+ * declaration is simply a no-op), so callers can warn about unknown properties
44
+ * without mistaking bad values for unsupported ones. */
45
+ bool xt_style_apply_declaration(XtStyle *style, const std::string &property,
41
46
  const std::string &rawValue, const ApplyContext &context);
42
47
 
43
48
  } // namespace xtgui
@@ -238,6 +238,15 @@ std::string xt_style_property_to_string(const XtStyle &style, const std::string
238
238
  static const char *const cursorNames[] = {"auto", "default", "pointer", "text", "move",
239
239
  "wait", "help", "not-allowed", "crosshair"};
240
240
  static const char *const borderStyleNames[] = {"none", "solid", "dashed", "dotted"};
241
+ auto borderColor = [&style]() {
242
+ return style.has_border_color ? formatColor(style.border_color) : formatColor(style.color);
243
+ };
244
+ auto borderWidth = [&style](const Length &length) {
245
+ /* A `none`/`hidden` border has a used width of zero, and `getComputedStyle`
246
+ * reports that resolved width. */
247
+ if (style.border_style == BorderStyle::None) return std::string("0px");
248
+ return formatLength(length);
249
+ };
241
250
 
242
251
  if (property == "display") {
243
252
  if (style.inline_level) return style.display == Display::Grid ? "inline-grid" : "inline-flex";
@@ -274,6 +283,9 @@ std::string xt_style_property_to_string(const XtStyle &style, const std::string
274
283
  }
275
284
  if (property == "text-align") return alignTextNames[(int)style.text_align];
276
285
  if (property == "text-transform") return textTransformNames[(int)style.text_transform];
286
+ if (property == "text-overflow") {
287
+ return style.text_overflow == TextOverflow::Ellipsis ? "ellipsis" : "clip";
288
+ }
277
289
  if (property == "letter-spacing") return formatLength(style.letter_spacing);
278
290
  if (property == "writing-mode") return writingModeNames[(int)style.writing_mode];
279
291
  if (property == "vertical-align") return formatLength(style.vertical_align);
@@ -314,6 +326,27 @@ std::string xt_style_property_to_string(const XtStyle &style, const std::string
314
326
  if (property == "flex-grow") return formatNumber(style.flex_grow);
315
327
  if (property == "flex-shrink") return formatNumber(style.flex_shrink);
316
328
  if (property == "flex-basis") return formatLength(style.flex_basis);
329
+ if (property == "border-top-width") return borderWidth(style.border_width.top);
330
+ if (property == "border-right-width") return borderWidth(style.border_width.right);
331
+ if (property == "border-bottom-width") return borderWidth(style.border_width.bottom);
332
+ if (property == "border-left-width") return borderWidth(style.border_width.left);
333
+ if (property == "border-width") {
334
+ return borderWidth(style.border_width.top) + " " + borderWidth(style.border_width.right) + " " +
335
+ borderWidth(style.border_width.bottom) + " " + borderWidth(style.border_width.left);
336
+ }
337
+ if (property == "border-top-style" || property == "border-right-style" ||
338
+ property == "border-bottom-style" || property == "border-left-style" ||
339
+ property == "border-style") {
340
+ return borderStyleNames[(int)style.border_style];
341
+ }
342
+ if (property == "border-top-color") return borderColor();
343
+ if (property == "border-right-color") return borderColor();
344
+ if (property == "border-bottom-color") return borderColor();
345
+ if (property == "border-left-color") return borderColor();
346
+ if (property == "border-color") {
347
+ std::string color = borderColor();
348
+ return color + " " + color + " " + color + " " + color;
349
+ }
317
350
  if (property == "border-radius") return formatLength(style.border_radius);
318
351
  if (property == "opacity") return formatNumber(style.opacity);
319
352
  if (property == "mix-blend-mode") {
@@ -167,6 +167,17 @@ bool xt_style_apply_text_property(XtStyle *style, const std::string &property,
167
167
  parseTextTransform(value, &style->text_transform);
168
168
  return true;
169
169
  }
170
+ if (property == "text-overflow") {
171
+ /* `clip | ellipsis` (the two-value `start end` form collapses to one
172
+ * behaviour here). A custom string is accepted as `clip`, which is still
173
+ * closer than dropping the declaration. */
174
+ bool ellipsis = false;
175
+ for (const std::string &token : splitTokens(lowerTrim(value))) {
176
+ if (token == "ellipsis") ellipsis = true;
177
+ }
178
+ style->text_overflow = ellipsis ? TextOverflow::Ellipsis : TextOverflow::Clip;
179
+ return true;
180
+ }
170
181
  if (property == "writing-mode") {
171
182
  parseWritingMode(value, &style->writing_mode);
172
183
  return true;
@@ -4,6 +4,7 @@
4
4
 
5
5
  #include "style_internal.h"
6
6
 
7
+ #include <cctype>
7
8
  #include <unordered_map>
8
9
 
9
10
  namespace xtgui {
@@ -38,6 +39,47 @@ void xt_style_apply_user_agent(const Node *node, XtStyle *style) {
38
39
  if (tag == "br") style->display = Display::Block;
39
40
  if (tag == "button" || tag == "input" || tag == "select" || tag == "textarea") {
40
41
  style->display = Display::InlineBlock;
42
+ /* The browser's form-control look: a 1px border, a white field background
43
+ * and the inherited font. The value/caret are painted by `paint_form.cpp`. */
44
+ style->border_style = BorderStyle::Solid;
45
+ style->border_width.set({1.0f, Unit::Px});
46
+ style->border_color = {0.46f, 0.46f, 0.46f, 1.0f};
47
+ style->has_border_color = true;
48
+ style->background = {1.0f, 1.0f, 1.0f, 1.0f};
49
+ style->has_background = true;
50
+ style->color = {0.1f, 0.1f, 0.1f, 1.0f};
51
+ style->padding.set({1.0f, Unit::Px});
52
+ style->padding.left = style->padding.right = {2.0f, Unit::Px};
53
+ }
54
+ if (tag == "input") {
55
+ const std::string *type = node->attr("type");
56
+ std::string kind;
57
+ if (type != nullptr) {
58
+ kind = *type;
59
+ for (char &c : kind) c = (char)std::tolower((unsigned char)c);
60
+ }
61
+ if (kind == "hidden") style->display = Display::None;
62
+ if (kind == "checkbox" || kind == "radio" || kind == "range") {
63
+ style->border_style = BorderStyle::None;
64
+ style->padding.set({0.0f, Unit::Px});
65
+ style->background = Color{0.0f, 0.0f, 0.0f, 0.0f};
66
+ style->has_background = false;
67
+ }
68
+ }
69
+ if (tag == "textarea") {
70
+ style->white_space = WhiteSpace::PreWrap;
71
+ }
72
+ if (tag == "button") {
73
+ style->background = {0.93f, 0.93f, 0.93f, 1.0f};
74
+ style->has_background = true;
75
+ style->padding.set({1.0f, Unit::Px});
76
+ style->padding.left = style->padding.right = {6.0f, Unit::Px};
77
+ }
78
+ if ((tag == "input" || tag == "textarea" || tag == "select" || tag == "button") &&
79
+ node->attr("disabled") != nullptr) {
80
+ style->color = {0.55f, 0.55f, 0.55f, 1.0f};
81
+ style->background = {0.95f, 0.95f, 0.95f, 1.0f};
82
+ style->has_background = true;
41
83
  }
42
84
  if (tag == "img") style->display = Display::InlineBlock;
43
85
  /* An inline `<svg>` is a replaced inline-block too: its intrinsic size comes