mirror of
https://github.com/slint-ui/slint.git
synced 2025-10-01 06:11:16 +00:00
Add support for embedding data in generated C++ code
This allows compiling with SIXTYFPS_EMBED_RESOURCES=true and images/fonts are embedded as inline variables. Generated data is emitted into the header file as inline uint8_t sfps_embedded_resources_123[789] = { 0x1, 0x2, 0x3, };
This commit is contained in:
parent
30e79d3ea2
commit
c91a38cdce
4 changed files with 101 additions and 5 deletions
|
@ -863,7 +863,7 @@ auto blocking_invoke_from_event_loop(Functor f) -> std::invoke_result_t<Functor>
|
|||
namespace private_api {
|
||||
|
||||
/// Registers a font by the specified path. The path must refer to an existing
|
||||
/// TrueType font font.
|
||||
/// TrueType font.
|
||||
/// \returns an empty optional on success, otherwise an error string
|
||||
inline std::optional<SharedString> register_font_from_path(const SharedString &path)
|
||||
{
|
||||
|
@ -876,6 +876,20 @@ inline std::optional<SharedString> register_font_from_path(const SharedString &p
|
|||
}
|
||||
}
|
||||
|
||||
/// Registers a font by the data. The data must be valid TrueType font data.
|
||||
/// \returns an empty optional on success, otherwise an error string
|
||||
inline std::optional<SharedString> register_font_from_data(const uint8_t *data, std::size_t len)
|
||||
{
|
||||
SharedString maybe_err;
|
||||
cbindgen_private::sixtyfps_register_font_from_data({ const_cast<uint8_t *>(data), len },
|
||||
&maybe_err);
|
||||
if (!maybe_err.empty()) {
|
||||
return maybe_err;
|
||||
} else {
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} // namespace sixtyfps
|
||||
|
|
|
@ -69,6 +69,9 @@ public:
|
|||
/// 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; }
|
||||
|
||||
/// \private
|
||||
explicit Image(cbindgen_private::types::Image inner) : data(inner) { }
|
||||
|
||||
private:
|
||||
using Tag = cbindgen_private::types::ImageInner::Tag;
|
||||
using Data = cbindgen_private::types::Image;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue