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

slint-viewer: image loading support via save-data/load-data #6169

Open
ianhattendorf opened this issue Sep 16, 2024 · 4 comments · May be fixed by #6224
Open

slint-viewer: image loading support via save-data/load-data #6169

ianhattendorf opened this issue Sep 16, 2024 · 4 comments · May be fixed by #6224
Labels
a:tooling Tools (mT,bO) enhancement New feature or request good first issue Good for newcomers

Comments

@ianhattendorf
Copy link

It would be helpful to be able to load images via slint-viewer --load-data. Without this, it's hard to test components without hardcoding properties in .slint files. The same syntax as @image-url() would be enough IMO.

test.slint

export struct TestData {
    image: image,
}

export component Test inherits Rectangle {
    in property <TestData> test_data: {
        image: @image-url("./test.jpg")
    };

    Image {
        source: test_data.image;
    }
}
$ slint-viewer test.slint --style fluent --save-data test.json

test.json

{}

Expected:

{
  "test_data": {
    "image": "@image-url(\"./test.jpg\")"
  }
}
$ slint-viewer test.slint --style fluent --load-data test.json
Warning: cannot set property 'test_data' from data file: WrongType
@ogoffart ogoffart added enhancement New feature or request a:tooling Tools (mT,bO) labels Sep 16, 2024
@ogoffart
Copy link
Member

Thanks for filing an issue.

Not all images is made out of a path, but we can find out the path for the image that have one.

I think we could say that if the json contains a string, this is a URL.
I wonder if it is worth to try to save and load other kind of image by storing the raw data. (eg, png in base 64 as a data url)

@ianhattendorf
Copy link
Author

Right, I was thinking even just handling the path is much better off than before.

Raw image encoding as base64/data url would be nice but image paths are probably fine 95% of the time and a big improvement to the development experience.

I think we could say that if the json contains a string, this is a URL.

I think that's a good simple solution. I was originally worried about distinguishing between strings and images in the json, or a future raw image encoding scheme, however I'm probably over thinking it. The raw encoding scheme should probably just be a data URI, which is easy to test for.

@ogoffart
Copy link
Member

In order to do this, one needs to handle Value::Image here to save

_ => None,

and Type::Image here to load:
_ => slint_interpreter::Value::Void,

@ogoffart ogoffart added the good first issue Good for newcomers label Sep 18, 2024
@ianhattendorf
Copy link
Author

Thanks for the pointer, I'll take a look at implementing this when I have some time.

@ianhattendorf ianhattendorf linked a pull request Sep 19, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a:tooling Tools (mT,bO) enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants
@ogoffart @ianhattendorf and others