C++: Improve reliability of comparison operator of slint::Image

Call into the Rust implementation, so that we have to maintain only one
implementation.
This commit is contained in:
Simon Hausmann 2023-05-23 20:14:17 +02:00 committed by Simon Hausmann
parent f51ca82f10
commit 084ff70079
3 changed files with 13 additions and 2 deletions

View file

@ -208,6 +208,7 @@ fn gen_corelib(
"slint_image_load_from_path",
"slint_image_load_from_embedded_data",
"slint_image_from_embedded_textures",
"slint_image_compare_equal",
"Coord",
"LogicalRect",
"LogicalPoint",
@ -278,6 +279,7 @@ fn gen_corelib(
"slint_image_load_from_path",
"slint_image_load_from_embedded_data",
"slint_image_from_embedded_textures",
"slint_image_compare_equal",
"SharedPixelBuffer",
"SharedImageBuffer",
"StaticTextures",
@ -344,6 +346,7 @@ fn gen_corelib(
"slint_image_load_from_path",
"slint_image_load_from_embedded_data",
"slint_image_from_embedded_textures",
"slint_image_compare_equal",
]
.iter()
.filter(|exclusion| !rust_types.iter().any(|inclusion| inclusion == *exclusion))

View file

@ -199,9 +199,12 @@ public:
}
/// 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; }
friend bool operator==(const Image &a, const Image &b)
{
return cbindgen_private::types::slint_image_compare_equal(&a.data, &b.data);
}
/// Returns false if \a a refers to the same image as \a b; true otherwise.
friend bool operator!=(const Image &a, const Image &b) { return a.data != b.data; }
friend bool operator!=(const Image &a, const Image &b) { return !(a == b); }
/// \private
explicit Image(cbindgen_private::types::Image inner) : data(inner) { }

View file

@ -788,6 +788,11 @@ pub(crate) mod ffi {
) {
core::ptr::write(image, Image::from(ImageInner::StaticTextures(textures)));
}
#[no_mangle]
pub unsafe extern "C" fn slint_image_compare_equal(image1: &Image, image2: &Image) -> bool {
return image1.eq(image2);
}
}
/// This structure contains fields to identify and render an OpenGL texture that Slint borrows from the applicatin code.