-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Adding feature: Image rotation #2334
Conversation
Proposed syntax: Image::new("icon.png")
.rotation(rotation_radians)
.rotation_layout(RotationLayout::Change), Output: (Left is clip.mp4 |
The image widget's layout modification changes the way image displayed when loaded for me. When commented/before changes (\w Uncommented, Uncommented, Also, I'm not sure if it's expected behavior, but aspect ratio on rotation looks weird. On the screenshots below, the left image is rotated using Default (no rotation): 90 degree rotation: |
I see, thanks for pointing out. The rotation should probably be done before the content fit layout applies, is that correct? |
That sounds correct. For now it looks like it's keeping the aspect ration of the created widget, scaling actual content inside on rotation, I think. |
Hmmm. Loaded image and rotation itself looks correct now, but I have a feeling widget's bounds or axis are not changed on rotation? That's noticeable when changing the size of window with rotated image in it, especially when using 2024-03-18.21-00-58.mp4Or 2024-03-18.21-05-52.mp4Sorry, if my assumptions are incorrect, I've only tested these changes in my usecase. |
Yes I removed the layout changes, because I was not able to correctly implement all of the edge cases. I will give this another go, but for now the rotation only visually changes the image, not affecting the layout |
I now added support for the content_fit scaling for both the wgpu and tiny_skia backend. Can you double check whether it behaves as expected on your end now @Gigas002 ? |
Example for two images with width clip1.mp4With clip2.mp4With clip3.mp4 |
Thank you, @DKolter ! Works great on my end 👍 |
Ah, sorry, @DKolter, I didn't notice it on a first run. After careful view, the The default 2024-03-25.19-59-59.mp4When using this PR's build: 2024-03-25.19-58-03.mp4I'm not actually sure if it counts as breaking behavior or not, but decided to report it just in case. I think we can The others |
One more issue I've noticed is related to "big" images. I can't say for sure how big these should be, but sometimes the image gets weirdly cropped and layout is a bit off. Here's an example of image I can repro this: And I also use rotated 90 degree rotated version of this image. Used Master branch: This PR: Use command to rotate this image 90 degree: Rotated image: Use command to rotate this rotated image 90 degree: |
For the first issue: Yes, matching on the content fit is probably the best solution, because it requires special treatment for Second issue: Can you add more details to each image which parameters you passed to which branch? It seems to me, that |
The second issue happens for both let handle = Handle::from_path(image_path);
let image = Image::new(handle)
.content_fit(ContentFit::Fill)
.filter_method(FilterMethod::Linear)
.width(Length::Fill)
.height(Length::Fill)
.rotation(self.rotation)
.rotation_layout(iced::RotationLayout::Change); The rotation is 90 degrees in radians and triggered on button event. Other parameters are the same. I'm loading the above image and a rotated version of that image. After the image had loaded, I'm playing with window sizes, image rotation and swapping the images. |
I was able to reproduce the issue, it only appears with the wgpu backend, which suggests that there is an issue with either the transformations applied in the shader or with the way the image is being split into parts when it is too large. I will look into it |
Both issues should be resolved now, iced and wgpu backend behave the same now. In the future we could also add the rotation behaviour to the other elements, such as the Svg widget |
Thank you! Will comment again as I'll be able to run some tests later.
I'm currently testing it with |
Tried out all the |
I added the same feature to the |
Hey, @DKolter ! I'm a bit busy this week, so I can't promise I'll be able to try out these changes soon, but I'll try to find some time, maybe on weekends. |
Hey, @DKolter! Was able to run some tests again, looks great to me so far. Sometimes I notice a small flickering while resizing the window with Also, would it be OK to ping you if/when my PR with |
Hey @Gigas002 , thanks for checking out the changes! I would gladly help you with the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Looks great 🥳
I have simplified and renamed some stuff here and there. The most important change is the removal of the scale
argument to draw_image
and draw_svg
. It seemed redundant since we are already providing specific image bounds
.
I have also created a new ferris
example to showcase both the ContentFit
and Rotation
strategies:
2024-05-02.17-12-11.mp4
Let me know what you think!
Co-authored-by: DKolter <68352124+DKolter@users.noreply.github.com>
Fixed 2024-05-03.07-03-52.mp4 |
Hello dear core team!
For one of my projects, I have found the need to draw a rotated image as a part of an animation in a custom
Widget
implementation. I have added a
rotation
field to theimage::Renderer::draw
function and have implemented the necessary shader code for the wgpu renderer and tiny_skia renderer.There is also a small app for testing this behaviour, which currently looks like this:
clip.mp4
scale_factor
has been tested too, which caused some issues on the tiny_skia renderer previously.As discussed with @hecrj, it might be benefical to add a property to the
widget::Image
too, but there was still some discussion on whether the layout should change when the image is rotated. For example when rotated by 45 degrees, the layout bounds would increase in all directions. This could be a wanted effect, but also unwanted for i.e. animations like in the example app.Please let me know what you think!
Thanks for your great work on iced