From 583c7a1b80821b7086ab91fb4195dbdc0134c9a6 Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Thu, 3 Mar 2022 14:39:11 +0100 Subject: [PATCH] Fix C++ build With ImageInner::StaticTextures (the variant) and StaticTextures (the struct), we need to disambiguate for the generated enum contructor functions. This is done by prefixing the enum variant with their name. --- api/cpp/cbindgen.rs | 1 + api/cpp/include/slint_image.h | 4 ++-- internal/compiler/generator/cpp.rs | 2 +- internal/core/graphics/image.rs | 1 + 4 files changed, 5 insertions(+), 3 deletions(-) diff --git a/api/cpp/cbindgen.rs b/api/cpp/cbindgen.rs index 03e565550..cefda5e24 100644 --- a/api/cpp/cbindgen.rs +++ b/api/cpp/cbindgen.rs @@ -227,6 +227,7 @@ fn gen_corelib( "slint_image_path", "SharedPixelBuffer", "SharedImageBuffer", + "StaticTextures", ], vec!["Color"], "slint_image_internal.h", diff --git a/api/cpp/include/slint_image.h b/api/cpp/include/slint_image.h index 6d5e05679..f6f8ef0e6 100644 --- a/api/cpp/include/slint_image.h +++ b/api/cpp/include/slint_image.h @@ -15,13 +15,13 @@ namespace slint { struct Image { public: - Image() : data(Data::None()) { } + Image() : data(Data::ImageInner_None()) { } /// Load an image from an image file static Image load_from_path(const SharedString &file_path) { Image img; - img.data = Data::AbsoluteFilePath(file_path); + img.data = Data::ImageInner_AbsoluteFilePath(file_path); return img; } diff --git a/internal/compiler/generator/cpp.rs b/internal/compiler/generator/cpp.rs index edd3227e7..915cf779e 100644 --- a/internal/compiler/generator/cpp.rs +++ b/internal/compiler/generator/cpp.rs @@ -1944,7 +1944,7 @@ fn compile_expression(expr: &llr::Expression, ctx: &EvaluationContext) -> String crate::expression_tree::ImageReference::EmbeddedData { resource_id, extension } => { let symbol = format!("slint_embedded_resource_{}", resource_id); format!( - r#"slint::Image(slint::cbindgen_private::types::ImageInner::EmbeddedData(slint::cbindgen_private::Slice{{std::data({}), std::size({})}}, slint::cbindgen_private::Slice{{const_cast(reinterpret_cast(u8"{}")), {}}}))"#, + r#"slint::Image(slint::cbindgen_private::types::ImageInner::ImageInner_EmbeddedData(slint::cbindgen_private::Slice{{std::data({}), std::size({})}}, slint::cbindgen_private::Slice{{const_cast(reinterpret_cast(u8"{}")), {}}}))"#, symbol, symbol, escape_string(extension), extension.as_bytes().len() ) } diff --git a/internal/core/graphics/image.rs b/internal/core/graphics/image.rs index 360b5fb9f..ed0586575 100644 --- a/internal/core/graphics/image.rs +++ b/internal/core/graphics/image.rs @@ -236,6 +236,7 @@ pub struct StaticTextures { /// A resource is a reference to binary data, for example images. They can be accessible on the file /// system or embedded in the resulting binary. Or they might be URLs to a web server and a downloaded /// is necessary before they can be used. +/// cbindgen:prefix-with-name #[derive(Clone, PartialEq, Debug)] #[repr(u8)] #[allow(missing_docs)]