Attempt to get the "image-in-corelib" feature compile with C++

This commit is contained in:
Olivier Goffart 2022-06-29 14:55:22 +02:00 committed by Simon Hausmann
parent 67a2f0ce3f
commit 65346c699c
7 changed files with 90 additions and 38 deletions

View file

@ -199,6 +199,7 @@ fn gen_corelib(
"slint_image_size",
"slint_image_path",
"slint_image_load_from_path",
"slint_image_load_from_embedded_data",
"Coord",
]
.iter()
@ -253,7 +254,7 @@ fn gen_corelib(
.context("Unable to generate bindings for slint_properties_internal.h")?
.write_to_file(include_dir.join("slint_properties_internal.h"));
for (rust_types, extra_excluded_types, internal_header) in [
for (rust_types, extra_excluded_types, internal_header, prelude) in [
(
vec![
"ImageInner",
@ -262,27 +263,32 @@ fn gen_corelib(
"slint_image_size",
"slint_image_path",
"slint_image_load_from_path",
"slint_image_load_from_embedded_data",
"SharedPixelBuffer",
"SharedImageBuffer",
"StaticTextures",
],
vec!["Color"],
"slint_image_internal.h",
"namespace slint::cbindgen_private { struct ParsedSVG{}; struct HTMLImage{}; using namespace vtable; }",
),
(
vec!["Color", "slint_color_brighter", "slint_color_darker"],
vec![],
"slint_color_internal.h",
"",
),
(
vec!["PathData", "PathElement", "slint_new_path_elements", "slint_new_path_events"],
vec![],
"slint_pathdata_internal.h",
"",
),
(
vec!["Brush", "LinearGradient", "GradientStop", "RadialGradient"],
vec!["Color"],
"slint_brush_internal.h",
"",
),
]
.iter()
@ -314,6 +320,7 @@ fn gen_corelib(
"slint_image_size",
"slint_image_path",
"slint_image_load_from_path",
"slint_image_load_from_embedded_data",
]
.iter()
.filter(|exclusion| !rust_types.iter().any(|inclusion| inclusion == *exclusion))
@ -338,6 +345,8 @@ fn gen_corelib(
private_exported_types.extend(special_config.export.include.iter().cloned());
special_config.after_includes = (!prelude.is_empty()).then(|| prelude.to_string());
cbindgen::Builder::new()
.with_config(special_config)
.with_src(crate_dir.join("graphics.rs"))

View file

@ -60,4 +60,13 @@ private:
Data data;
};
namespace private_api {
inline Image load_image_from_embedded_data(std::span<const uint8_t> data, std::string_view extension) {
cbindgen_private::types::Image img(cbindgen_private::types::Image::ImageInner_None());
cbindgen_private::types::slint_image_load_from_embedded_data(
slint::cbindgen_private::Slice<uint8_t>{const_cast<uint8_t *>(data.data()), data.size()}, slint::cbindgen_private::Slice<uint8_t>{const_cast<uint8_t *>(reinterpret_cast<const uint8_t *>(extension.data())), extension.size()}, &img);
return Image(img);
}
}
}