slint-ui / slint

Slint is a declarative GUI toolkit to build native user interfaces for Rust, C++, or JavaScript apps.
https://slint.dev
Other
17.57k stars 604 forks source link

Missing implementation for rotating Image using software renderer #3068

Open kivimango opened 1 year ago

kivimango commented 1 year ago

Hello !

I'm receiving a panic when i want to rotate the image in slint using software renderer (other platforms works ok)

thread 'main' panicked at 'not yet implemented', /home/user/.cargo/git/checkouts/slint-8153123e5dffa129/4a56531/internal/core/software_renderer.rs:1954:9

Could you please implement the code for rotating images for sw renderer too ? https://github.com/slint-ui/slint/blob/master/internal/core/software_renderer.rs#L1954

Also, i don't know if it is the intended way of work, but if i don't set the rotation-angle explicitly to 0 on the Image widget, changing it elsewhere, (for instance in the clicked() callback of a button) wont do anything.

Run it with

SLINT_BACKEND=winit-software cargo run

// Minimal, Reproducible Example 
slint::slint! {
import { Button, VerticalBox } from "std-widgets.slint";
export component Demo {
    VerticalBox {
        alignment: start;
        img := Image {
            source: @image-url("https://slint.dev/logo/slint-logo-full-light.svg");
            // when rotation-angle property is not set explicitly, setting it elsewhere wont do anything 
            rotation-angle: 0;
            height: 100px;
        }
        HorizontalLayout {
            alignment: center;
            Button {
                text: "Rotate";
                clicked => {
                img.rotation-angle += 90deg;
                }
            }
        }
    }
}
}

fn main() {
    Demo::new().unwrap().run().unwrap();
}
ogoffart commented 1 year ago

Thanks for your bug report!

The second part about binding not working when not initialized is indeed a bug. This is being fixed in #3077 Let's keep track only of the fact that the rotation is not implemented in the software renderer.

The software renderer is indeed lacking behind in therms of features.

In order to implement rotated image. This is the things that needs to be done:

  1. One need to implement the todo!() to store the angle in the self.current_state. https://github.com/slint-ui/slint/blob/3e420b32ad7a2e0bca6b3a3193d0c68d1302abf0/internal/core/software_renderer.rs#L1954

  2. And handle this rotation in SceneBuilder::draw_image_impl. This means computing the geometry of the bounding rectangle of the rotated image and store the rotation angle in the SceneTexture.

  1. adapt draw_functions::draw_texture_line to handle this angle. This means that for each pixel, we would have a pos which is computed with a matrix multiplication instead of having a contsant y_pos. Since this code is performence sensitive, we probably want to have two different code path. Instead of doing a matrix multiplication of each pixel, one can just cache a delta x and an delta y or something like that.
kivimango commented 1 year ago

Should have been open a two, separate issue. Will do next time. Thanks anyway.

hamboooooo commented 5 months ago

202406140039 Waiting

ogoffart commented 5 months ago

Thank for sharing the cool pictures @hamboooooo

This issue is currently not on our short-term roadmap. If it's important to you, we encourage you to take a shot at implementing it. We'd be happy to provide mentoring, tips, and review your pull request. Our roadmap is flexible and responsive to the needs of our users and customers. If this issue is a blocker for you, please let us know by email or chat. Share details about your project, and we'll consider prioritizing it or offering it as a service.