handle only width/height for img

This commit is contained in:
Face
2025-09-10 21:43:57 +03:00
parent 4aa8e30a13
commit b4323acbd6

View File

@@ -33,3 +33,27 @@ func load_image_async(src: String, element: HTMLParser.HTMLElement, parser: HTML
size_flags_horizontal = Control.SIZE_EXPAND_FILL
size_flags_vertical = Control.SIZE_EXPAND_FILL
custom_minimum_size = Vector2.ZERO
else:
# Handle cases where only width or only height is specified
var texture_size = texture.get_size()
var aspect_ratio = texture_size.x / texture_size.y
if has_width and not has_height:
# Only width specified - calculate height to maintain aspect ratio
var width_pixels = SizingUtils.parse_size_value(width_val)
if width_pixels != null and typeof(width_pixels) != TYPE_STRING and width_pixels > 0:
var calculated_height = width_pixels / aspect_ratio
custom_minimum_size = Vector2(width_pixels, calculated_height)
elif has_height and not has_width:
# Only height specified - calculate width to maintain aspect ratio
var height_pixels = SizingUtils.parse_size_value(height_val)
if height_pixels != null and typeof(height_pixels) != TYPE_STRING and height_pixels > 0:
var calculated_width = height_pixels * aspect_ratio
custom_minimum_size = Vector2(calculated_width, height_pixels)
elif has_width and has_height:
# Both specified - use both values
var width_pixels = SizingUtils.parse_size_value(width_val)
var height_pixels = SizingUtils.parse_size_value(height_val)
if width_pixels != null and typeof(width_pixels) != TYPE_STRING and width_pixels > 0 and \
height_pixels != null and typeof(height_pixels) != TYPE_STRING and height_pixels > 0:
custom_minimum_size = Vector2(width_pixels, height_pixels)