mirror of
https://github.com/slint-ui/slint.git
synced 2025-09-30 22:01:13 +00:00
Add API to sixtyfps::Image in Rust and C++ to access the optional path
This commit is contained in:
parent
bbe178aadf
commit
4eef8c7688
5 changed files with 39 additions and 0 deletions
|
@ -147,6 +147,7 @@ fn gen_corelib(root_dir: &Path, include_dir: &Path) -> anyhow::Result<()> {
|
|||
"sixtyfps_color_brighter",
|
||||
"sixtyfps_color_darker",
|
||||
"sixtyfps_image_size",
|
||||
"sixtyfps_image_path",
|
||||
]
|
||||
.iter()
|
||||
.map(|x| x.to_string())
|
||||
|
@ -205,6 +206,7 @@ fn gen_corelib(root_dir: &Path, include_dir: &Path) -> anyhow::Result<()> {
|
|||
"Image",
|
||||
"Size",
|
||||
"sixtyfps_image_size",
|
||||
"sixtyfps_image_path",
|
||||
"SharedPixelBuffer",
|
||||
"SharedImageBuffer",
|
||||
],
|
||||
|
@ -253,6 +255,7 @@ fn gen_corelib(root_dir: &Path, include_dir: &Path) -> anyhow::Result<()> {
|
|||
"sixtyfps_color_brighter",
|
||||
"sixtyfps_color_darker",
|
||||
"sixtyfps_image_size",
|
||||
"sixtyfps_image_path",
|
||||
]
|
||||
.iter()
|
||||
.filter(|exclusion| !rust_types.iter().any(|inclusion| inclusion == *exclusion))
|
||||
|
|
|
@ -54,6 +54,16 @@ public:
|
|||
/// Returns the size of the Image in pixels.
|
||||
Size size() const { return cbindgen_private::types::sixtyfps_image_size(&data); }
|
||||
|
||||
/// Returns the path of the image on disk, if it was constructed via Image::load_from_path().
|
||||
std::optional<sixtyfps::SharedString> path() const
|
||||
{
|
||||
if (auto *str = cbindgen_private::types::sixtyfps_image_path(&data)) {
|
||||
return *str;
|
||||
} else {
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns true if \a a refers to the same image as \a b; false otherwise.
|
||||
friend bool operator==(const Image &a, const Image &b) { return a.data == b.data; }
|
||||
/// Returns false if \a a refers to the same image as \a b; true otherwise.
|
||||
|
|
|
@ -86,6 +86,9 @@ TEST_CASE("Image")
|
|||
REQUIRE(size.width == 0.);
|
||||
REQUIRE(size.height == 0.);
|
||||
}
|
||||
{
|
||||
REQUIRE(!img.path().has_value());
|
||||
}
|
||||
|
||||
img = Image::load_from_path(SOURCE_DIR "/../../vscode_extension/extension-logo.png");
|
||||
{
|
||||
|
@ -93,6 +96,11 @@ TEST_CASE("Image")
|
|||
REQUIRE(size.width == 128.);
|
||||
REQUIRE(size.height == 128.);
|
||||
}
|
||||
{
|
||||
auto actual_path = img.path();
|
||||
REQUIRE(actual_path.has_value());
|
||||
REQUIRE(*actual_path == SOURCE_DIR "/../../vscode_extension/extension-logo.png");
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("SharedVector")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue