mirror of
https://github.com/slint-ui/slint.git
synced 2025-09-27 12:29:41 +00:00

This is relatively straight-forward via a pass in the compiler to collect the resources to embed and then use include_bytes! (once per resource). What's really annoying is that the rust resource enum can't store a &'static [u8] because cbindgen doesn't represent that, probably because the slice representation isn't guaranteed to stay as it is. So instead this, for now, uses raw pointers.
69 lines
1.5 KiB
C++
69 lines
1.5 KiB
C++
#pragma once
|
|
#include <string_view>
|
|
#include "sixtyfps_resource_internal.h"
|
|
#include "sixtyfps_string.h"
|
|
|
|
namespace sixtyfps {
|
|
|
|
union ResourceData {
|
|
SharedString absolute_file_path;
|
|
struct {
|
|
void *ptr;
|
|
size_t len;
|
|
} slice;
|
|
|
|
ResourceData() { }
|
|
~ResourceData() { }
|
|
};
|
|
|
|
struct Resource
|
|
{
|
|
public:
|
|
using Tag = internal::types::Resource::Tag;
|
|
|
|
Resource() : tag(Tag::None) { }
|
|
Resource(const SharedString &file_path) : tag(Tag::AbsoluteFilePath)
|
|
{
|
|
new (&data.absolute_file_path) SharedString(file_path);
|
|
}
|
|
Resource(const Resource &other) : tag(other.tag)
|
|
{
|
|
switch (tag) {
|
|
case Tag::None:
|
|
break;
|
|
case Tag::AbsoluteFilePath:
|
|
new (&data.absolute_file_path) SharedString(other.data.absolute_file_path);
|
|
}
|
|
}
|
|
~Resource() { destroy(); }
|
|
Resource &operator=(const Resource &other)
|
|
{
|
|
if (this == &other)
|
|
return *this;
|
|
destroy();
|
|
tag = other.tag;
|
|
switch (tag) {
|
|
case Tag::None:
|
|
break;
|
|
case Tag::AbsoluteFilePath:
|
|
new (&data.absolute_file_path) SharedString(other.data.absolute_file_path);
|
|
}
|
|
return *this;
|
|
}
|
|
|
|
private:
|
|
void destroy()
|
|
{
|
|
switch (tag) {
|
|
case Tag::None:
|
|
break;
|
|
case Tag::AbsoluteFilePath:
|
|
data.absolute_file_path.~SharedString();
|
|
}
|
|
}
|
|
|
|
Tag tag;
|
|
ResourceData data;
|
|
};
|
|
|
|
}
|