@geastack/engine 0.1.30 → 0.1.32

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@geastack/engine",
3
- "version": "0.1.30",
3
+ "version": "0.1.32",
4
4
  "description": "GeaStack rendering engine, intrinsic JSX primitives, and native engine backends.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -1817,7 +1817,7 @@ void CanvasRenderingContext2D::setFont(const std::string &font)
1817
1817
  void CanvasRenderingContext2D::clear()
1818
1818
  {
1819
1819
  if (recordingPresentBatch()) {
1820
- appendPresentClear(0);
1820
+ appendPresentClear(gea::framework::graphics::pixel::nativeColor(0, 0, 0));
1821
1821
  return;
1822
1822
  }
1823
1823
  auto *surface = drawingCanvas();
package/ui/style.cpp CHANGED
@@ -11941,6 +11941,61 @@ void replayInlineStyles(int node)
11941
11941
  #endif
11942
11942
  }
11943
11943
 
11944
+ #if GEA_UI_IMAGE_NODES
11945
+ struct ImageDimensionHint {
11946
+ double value = -1;
11947
+ bool percentage = false;
11948
+ };
11949
+
11950
+ ImageDimensionHint parseImageDimensionHint(const char *value)
11951
+ {
11952
+ if (!value) return {};
11953
+ while (*value == ' ' || *value == '\t' || *value == '\r' ||
11954
+ *value == '\n' || *value == '\f') ++value;
11955
+ if (*value < '0' || *value > '9') return {};
11956
+
11957
+ double number = 0;
11958
+ while (*value >= '0' && *value <= '9') {
11959
+ number = number * 10 + (*value++ - '0');
11960
+ }
11961
+ if (*value == '.') {
11962
+ ++value;
11963
+ for (double place = 0.1; *value >= '0' && *value <= '9'; place *= 0.1) {
11964
+ number += (*value++ - '0') * place;
11965
+ }
11966
+ }
11967
+ return {number, *value == '%'};
11968
+ }
11969
+
11970
+ void applyImageDimensionHints(int node)
11971
+ {
11972
+ auto &tree = Tree::instance();
11973
+ const auto width = parseImageDimensionHint(tree.getAttribute(node, "width"));
11974
+ const auto height = parseImageDimensionHint(tree.getAttribute(node, "height"));
11975
+
11976
+ const auto apply = [&](ImageDimensionHint hint, Property length, Property percentage) {
11977
+ if (hint.value < 0) return;
11978
+ if (hint.percentage) {
11979
+ tree.setStyleFromClass(node, percentage, roundToInt(std::min(32767.0, hint.value * 10)));
11980
+ } else {
11981
+ tree.setStyleFromClass(node, length, roundToInt(std::min(32767.0, hint.value * g_device_pixel_ratio)));
11982
+ }
11983
+ };
11984
+ apply(width, Property::Width, Property::WidthPercent);
11985
+ apply(height, Property::Height, Property::HeightPercent);
11986
+ #if GEA_CSS_ASPECT_RATIO
11987
+ if (!width.percentage && !height.percentage && width.value > 0 && height.value > 0) {
11988
+ // A negative ratio encodes CSS 'auto <ratio>': use the natural ratio
11989
+ // once the image is available, otherwise use the attribute pair.
11990
+ const float ratio = static_cast<float>(-width.value / height.value);
11991
+ int encoded;
11992
+ std::memcpy(&encoded, &ratio, sizeof(encoded));
11993
+ tree.setStyleFromClass(node, Property::AspectRatio, encoded);
11994
+ }
11995
+ #endif
11996
+ }
11997
+ #endif
11998
+
11944
11999
  void applyDefaultStyleOverrides(int node)
11945
12000
  {
11946
12001
  auto &state = treeState();
@@ -11950,6 +12005,9 @@ void applyDefaultStyleOverrides(int node)
11950
12005
  const NodeStyleOverride &entry = rd->defaultStyles.at(i);
11951
12006
  Tree::instance().setStyleFromClass(node, entry.property, entry.value);
11952
12007
  }
12008
+ #if GEA_UI_IMAGE_NODES
12009
+ if (state.nodes[node].type == NodeType::Image) applyImageDimensionHints(node);
12010
+ #endif
11953
12011
  }
11954
12012
 
11955
12013
  #if GEA_CSS_PSEUDO_ELEMENTS
@@ -36,6 +36,11 @@ bool sameName(const char *a, const char *b)
36
36
  return a && b && std::strcmp(a, b) == 0;
37
37
  }
38
38
 
39
+ bool isImageDimensionAttribute(const Node &node, const char *name)
40
+ {
41
+ return node.type == NodeType::Image && (sameName(name, "width") || sameName(name, "height"));
42
+ }
43
+
39
44
  bool audioBooleanAttributeEnabled(const char *value)
40
45
  {
41
46
  if (!value) return false;
@@ -963,6 +968,9 @@ void Tree::setAttribute(int node, const char *name, const char *value)
963
968
  if (state.nodes[node].type == NodeType::Image && sameName(name, "fit")) {
964
969
  Style(node).imageFit(imageFitAttributeValue(value));
965
970
  }
971
+ if (isImageDimensionAttribute(state.nodes[node], name)) {
972
+ StyleSheet::instance().recomputeSubtree(node);
973
+ }
966
974
  applyAudioAttribute(*this, node, name, value ? value : "");
967
975
  if (state.nodes[node].type == NodeType::VirtualList) VirtualListRenderer::configureAttribute(node, name, value);
968
976
  // Tree::setText marks render.dirty + non_scroll_dirty so the
@@ -998,6 +1006,9 @@ void Tree::removeAttribute(int node, const char *name)
998
1006
  if (!rd) return; // no rare-data block → no attributes to remove
999
1007
  const bool hadAttribute = rd->attributes.remove(name);
1000
1008
  if (!hadAttribute) return;
1009
+ if (isImageDimensionAttribute(state.nodes[node], name)) {
1010
+ StyleSheet::instance().recomputeSubtree(node);
1011
+ }
1001
1012
  if (state.nodes[node].type == NodeType::Image && sameName(name, "src")) {
1002
1013
  setStyleFromClass(node, Property::ImageId, -1);
1003
1014
  markDisplayListDirty();