Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preserve aspect ratio of images #242

Merged
merged 19 commits into from
Oct 17, 2024
Merged

Preserve aspect ratio of images #242

merged 19 commits into from
Oct 17, 2024

Commits on Oct 17, 2024

  1. Add img-max-bounds HTML test

    Tests several combinations of size contraints on images so we can check
    if the aspect ratio is kept or not.
    rodarima committed Oct 17, 2024
    Configuration menu
    Copy the full SHA
    277b72c View commit details
    Browse the repository at this point in the history
  2. Round final relative CSS length

    Prevents errors by one pixel
    rodarima committed Oct 17, 2024
    Configuration menu
    Copy the full SHA
    25a381f View commit details
    Browse the repository at this point in the history
  3. Preserve aspect ratio of images

    When posible, change the image size so the aspect ratio is always
    preserved. This is only posible when one or both dimensions have some
    room to play. When both dimensions are not fixed, a naive algorithm
    tries to satisfy all {min,max}-{width,height} and aspect ratio
    constraints, but it may fail. In that case, the aspect ratio is not
    preserved.
    
    Fixes the HTML tests img-aspect-ratio and img-max-bounds.
    rodarima committed Oct 17, 2024
    Configuration menu
    Copy the full SHA
    557e194 View commit details
    Browse the repository at this point in the history
  4. Don't apply min/max-width if the width is auto

    Prevents reducing the available width of a body with width:auto and
    min-width:100px to 100px.
    
    The Widget::calcFinalWidth() method is also heavily documented, so we
    can understand precisely what it does.
    rodarima committed Oct 17, 2024
    Configuration menu
    Copy the full SHA
    6321304 View commit details
    Browse the repository at this point in the history
  5. Set the viewport width as initial width value

    When the initial width is -1, the contrainsts of min-width and max-width
    are not applied. If we set the viewport width after calcFinalWidth() it
    may exceed max-width. It is guaranteed to return a value different from
    -1 when the initial width is positive.
    rodarima committed Oct 17, 2024
    Configuration menu
    Copy the full SHA
    c11d213 View commit details
    Browse the repository at this point in the history
  6. Expand percentage height values for requisitions

    When correcting a requisition, percent values were not being computed
    which prevents the min-height or max-height values to be taken into
    account.
    rodarima committed Oct 17, 2024
    Configuration menu
    Copy the full SHA
    931f824 View commit details
    Browse the repository at this point in the history
  7. Configuration menu
    Copy the full SHA
    bcc4fac View commit details
    Browse the repository at this point in the history
  8. Configuration menu
    Copy the full SHA
    b6c8599 View commit details
    Browse the repository at this point in the history
  9. Allow widgets to adjust new requisition

    When a widget calls the parent to correct its own requisition, let the
    child widget perform adjustments on the requisition. This allows images
    to control the height when the parent changes the width, so the image
    can preserve its own aspect ratio.
    rodarima committed Oct 17, 2024
    Configuration menu
    Copy the full SHA
    4962383 View commit details
    Browse the repository at this point in the history
  10. Configuration menu
    Copy the full SHA
    7d7212a View commit details
    Browse the repository at this point in the history
  11. Add comment for dubious call

    rodarima committed Oct 17, 2024
    Configuration menu
    Copy the full SHA
    519f5c8 View commit details
    Browse the repository at this point in the history
  12. Only use the viewport height with forceValue set

    For cases where the available height is being computed and the CSS
    style has the height to auto, there available height is infinite. Don't
    return the viewport unless forceValue is set.
    rodarima committed Oct 17, 2024
    Configuration menu
    Copy the full SHA
    a4301a9 View commit details
    Browse the repository at this point in the history
  13. Add support for aspect ratio in Widget

    Images should preserve their own aspect ratio, which is determined by
    the image buffer size, also known as the intrinsic size. Currently, when
    a child requests a requisition to be corrected by correctRequisition(),
    only the size was adjusted, ignoring the aspect ratio.
    
    The new Widget ratio variable holds the desired aspect ratio for the
    widget, and will only be taken into account when non-zero. In that case,
    then correcting the requisition, a naive algorithm tries to first
    increase the length of the small size to fill the preferred aspect
    ratio. In the case that it is not enough, the larger size is then
    decreased to fit the aspect ratio. And if that doesn't work either, the
    aspect ratio is not enforced and the widget will be distorted.
    
    There are special cases for correctRequisition() depending if the parent
    exists or not. The same approach is taken for both cases, but using the
    viewport size instead of the parent size.
    rodarima committed Oct 17, 2024
    Configuration menu
    Copy the full SHA
    7823c15 View commit details
    Browse the repository at this point in the history
  14. Use maximum size for pathological CSS cases

    When CSS min-{width,height} > max-{width,height} set the
    max-{width,heigh} to the maximum value min-{width,height}.
    rodarima committed Oct 17, 2024
    Configuration menu
    Copy the full SHA
    e4fbfd6 View commit details
    Browse the repository at this point in the history
  15. Configuration menu
    Copy the full SHA
    ae0a634 View commit details
    Browse the repository at this point in the history
  16. Remove aspect ratio logic from Image

    The aspect ratio is now preserved by Widget::correctRequisition(), so we
    don't need to do more steps after the call.
    rodarima committed Oct 17, 2024
    Configuration menu
    Copy the full SHA
    15b878c View commit details
    Browse the repository at this point in the history
  17. Configuration menu
    Copy the full SHA
    df3ed48 View commit details
    Browse the repository at this point in the history
  18. Configuration menu
    Copy the full SHA
    51e023b View commit details
    Browse the repository at this point in the history
  19. Use the aspect ratio of the content box

    The requisition box includes the margin, padding and border. To compute
    the aspect ratio of the image we need to remove them to get the content
    box. Once the adjustment is done, we add the borders again.
    rodarima committed Oct 17, 2024
    Configuration menu
    Copy the full SHA
    572b934 View commit details
    Browse the repository at this point in the history