InlineImage custom size and flipping support - #25767
Conversation
|
Your PR caused a change in the graphical output of an example or rendering test. This might be intentional, but it could also mean that something broke! If it's expected, please add the M-Deliberate-Rendering-Change label. If this change seems unrelated to your PR, you can consider updating your PR to target the latest main branch, either by rebasing or merging main into it. |
viridia
left a comment
There was a problem hiding this comment.
Fine for now, but I assume we eventually want these to be Val units. (Particularly Em/Rem).
Yep I left
Could use |
It doesn't really matter; root is probably easier and more consistent. The practical use case is: "I want an icon that is 20% larger than the text height of the paragraph it's embedded in". Having a paragraph contained mixed sizes is rare; generally font size applies to an entire heading or caption. |
| impl InlineImage { | ||
| /// Resolve the inline box size. Preserves the image's aspect ratio if dimensions unset. | ||
| pub fn resolve_inline_box_size(&self, image_size: Vec2) -> Vec2 { | ||
| match (self.width, self.height) { |
There was a problem hiding this comment.
Probably dumb question but is zero a valid/possible image size here?
There was a problem hiding this comment.
No that's a reasonable question. I don't think this function should do any validation, that should be left up to the caller. Instead, I added some extra logic to the update_inline_image_boxes system that sets the InlineBox to zero if the resolved box size is invalid. IIRC it's not strictly necessary, images shouldn't be zero-sized and Parley will ignore any invalid values, but it seems okay as a low cost defensive measure.
| commands.spawn(Camera2d); | ||
| commands.spawn(( | ||
| Text::new("[Text]"), | ||
| TextFont::from_font_size(px(40.)), |
There was a problem hiding this comment.
Just for my learning what's the easiest way to see the new examples on an open PR? Not sure if screenshots in PR desc. are common practice to make it easier for reviewers.
There was a problem hiding this comment.
Sometimes I add screenshots, but they can be a bit unreliable. It's much better if reviewers run the examples and check that they work for themselves. I've had a couple of PRs where the changes were fine on my computer, but on other platforms there were graphical artifacts.
The examples here can be run with:
cargo run --example inline_image
cargo run --example testbed_ui -- inlineimage
Yeah I think I agree, we can just simplify things by assuming a uniform line height (taken from the root text section). I was thinking about how to implement automatic sizing that would adjust the image size to best fit the text layout, but it's not worth the effort for something very niche, however unsatisfying the alternative is. I'll still leave it for a follow up, as this is very simple and an obvious merge. |
Objective
Add support for custom sizing and flipping to
InlineImage.Solution
New fields
width,height,flip_x,flip_yonIinlineImage.Preserves the image's aspect ratio if dimensions unset.
Probably the dimensions should be
Vals but the implementation needs a bit of thinking about, so left it for a follow upTesting
Includes new test
resolve_inline_box_size.Updated the
inline_imageexample andinlineimageui testbed scene.