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

Add fitMode property on Image Elements. #4206

Merged
merged 6 commits into from
Apr 26, 2022

Conversation

jpauloruschel
Copy link
Contributor

@jpauloruschel jpauloruschel commented Apr 22, 2022

Fixes #3726

Adds a new property to Element component, used only on Image: fitMode. Set how the content should be fitted and preserve the aspect ratio of the source texture or sprite. (nomenclature is borrowed from https://developer.mozilla.org/en-US/docs/Web/CSS/object-fit):

  • stretch (default; pc.FITMODE_STRETCH): Fit the content exactly to the Element's bounding box.
  • contain (pc.FITMODE_CONTAIN): Fit the content within the Element's bounding box while preserving its Aspect Ratio.
  • cover (pc.FITMODE_COVER): Fit the content to cover the entire Element's bounding box while preserving its Aspect Ratio.

Screenshot 2022-04-25 at 14 41 18

the white boxes are other Image elements placed on top of the actual image and are there just to represent the actual bounds of each Element

Extra: Cover + Masking

The cover setting works very well with an additional mask Element if the desired effect is to clip the content to only display the part inside the bounding box:

mask

I confirm I have read the contributing guidelines and signed the Contributor License Agreement.

@jpauloruschel jpauloruschel added the area: ui UI related issue label Apr 22, 2022
@jpauloruschel jpauloruschel requested a review from a team April 22, 2022 09:49
@jpauloruschel jpauloruschel self-assigned this Apr 22, 2022
Copy link
Contributor

@mvaligursky mvaligursky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Few small comments, but this looks great!

@jpauloruschel jpauloruschel changed the title Add aspectRatio setting on Image Elements. Add preserveAspect setting on Image Elements. Apr 22, 2022
@Maksims
Copy link
Contributor

Maksims commented Apr 22, 2022

If contain is used, the out of image part, will be discarded?

@mvaligursky mvaligursky self-requested a review April 22, 2022 12:56
@jpauloruschel
Copy link
Contributor Author

If contain is used, the out of image part, will be discarded?

What do you mean by 'discarded'? Both contain and cover change the vertices of the internal mesh used to render the element. So for contain, the part out of the image is completely empty.

@Maksims
Copy link
Contributor

Maksims commented Apr 22, 2022

If contain is used, the out of image part, will be discarded?

What do you mean by 'discarded'? Both contain and cover change the vertices of the internal mesh used to render the element. So for contain, the part out of the image is completely empty.

I see, just on a screenshot in PR, it showed grey areas.

@jpauloruschel
Copy link
Contributor Author

If contain is used, the out of image part, will be discarded?

What do you mean by 'discarded'? Both contain and cover change the vertices of the internal mesh used to render the element. So for contain, the part out of the image is completely empty.

I see, just on a screenshot in PR, it showed grey areas.

Aahh right! Yea sorry those are just other image elements placed on top just to represent the actual bounds. I updated the description to try and explain that further.

@jpauloruschel jpauloruschel changed the title Add preserveAspect setting on Image Elements. Add fitMode setting on Image Elements. Apr 25, 2022
@jpauloruschel jpauloruschel changed the title Add fitMode setting on Image Elements. Add fitMode property on Image Elements. Apr 26, 2022
@jpauloruschel jpauloruschel merged commit b3c03c9 into main Apr 26, 2022
@jpauloruschel jpauloruschel deleted the jpaulo-element-image-aspect branch April 26, 2022 12:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: ui UI related issue
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Have an Aspect Ratio component
4 participants