mirror of
https://github.com/slint-ui/slint.git
synced 2025-10-28 10:49:46 +00:00
C++: Fix ABI mismatch with Slice on MSVC AArch64
Some checks are pending
autofix.ci / format_fix (push) Waiting to run
autofix.ci / lint_typecheck (push) Waiting to run
CI / python_test (windows-2022) (push) Blocked by required conditions
CI / files-changed (push) Waiting to run
CI / build_and_test (--exclude bevy-example, ubuntu-22.04, 1.85) (push) Blocked by required conditions
CI / mcu (pico-st7789, thumbv6m-none-eabi) (push) Blocked by required conditions
CI / build_and_test (--exclude ffmpeg --exclude gstreamer-player, --exclude bevy-example, windows-2022, 1.85) (push) Blocked by required conditions
CI / build_and_test (--exclude ffmpeg --exclude gstreamer-player, macos-14, stable) (push) Blocked by required conditions
CI / build_and_test (--exclude ffmpeg --exclude gstreamer-player, windows-2022, beta) (push) Blocked by required conditions
CI / build_and_test (--exclude ffmpeg --exclude gstreamer-player, windows-2022, stable) (push) Blocked by required conditions
CI / build_and_test (ubuntu-22.04, nightly-2025-08-15) (push) Blocked by required conditions
CI / node_test (macos-14) (push) Blocked by required conditions
CI / node_test (ubuntu-22.04) (push) Blocked by required conditions
CI / node_test (windows-2022) (push) Blocked by required conditions
CI / python_test (macos-14) (push) Blocked by required conditions
CI / python_test (ubuntu-22.04) (push) Blocked by required conditions
CI / cpp_test_driver (macos-13) (push) Blocked by required conditions
CI / cpp_test_driver (ubuntu-22.04) (push) Blocked by required conditions
CI / cpp_test_driver (windows-2022) (push) Blocked by required conditions
CI / cpp_cmake (macos-14, 1.85) (push) Blocked by required conditions
CI / cpp_cmake (ubuntu-22.04, stable) (push) Blocked by required conditions
CI / cpp_cmake (windows-2022, nightly) (push) Blocked by required conditions
CI / mcu (pico2-st7789, thumbv8m.main-none-eabihf) (push) Blocked by required conditions
CI / mcu (stm32h735g, thumbv7em-none-eabihf) (push) Blocked by required conditions
CI / mcu-embassy (push) Blocked by required conditions
CI / ffi_32bit_build (push) Blocked by required conditions
CI / docs (push) Blocked by required conditions
CI / wasm (push) Blocked by required conditions
CI / wasm_demo (push) Blocked by required conditions
CI / tree-sitter (push) Blocked by required conditions
CI / updater_test (0.3.0) (push) Blocked by required conditions
CI / android (push) Blocked by required conditions
CI / miri (push) Blocked by required conditions
CI / cpp_package_test (push) Blocked by required conditions
CI / vsce_build_test (push) Blocked by required conditions
CI / fmt_test (push) Blocked by required conditions
CI / esp-idf-quick (push) Blocked by required conditions
CI / test-figma-inspector (push) Blocked by required conditions
Some checks are pending
autofix.ci / format_fix (push) Waiting to run
autofix.ci / lint_typecheck (push) Waiting to run
CI / python_test (windows-2022) (push) Blocked by required conditions
CI / files-changed (push) Waiting to run
CI / build_and_test (--exclude bevy-example, ubuntu-22.04, 1.85) (push) Blocked by required conditions
CI / mcu (pico-st7789, thumbv6m-none-eabi) (push) Blocked by required conditions
CI / build_and_test (--exclude ffmpeg --exclude gstreamer-player, --exclude bevy-example, windows-2022, 1.85) (push) Blocked by required conditions
CI / build_and_test (--exclude ffmpeg --exclude gstreamer-player, macos-14, stable) (push) Blocked by required conditions
CI / build_and_test (--exclude ffmpeg --exclude gstreamer-player, windows-2022, beta) (push) Blocked by required conditions
CI / build_and_test (--exclude ffmpeg --exclude gstreamer-player, windows-2022, stable) (push) Blocked by required conditions
CI / build_and_test (ubuntu-22.04, nightly-2025-08-15) (push) Blocked by required conditions
CI / node_test (macos-14) (push) Blocked by required conditions
CI / node_test (ubuntu-22.04) (push) Blocked by required conditions
CI / node_test (windows-2022) (push) Blocked by required conditions
CI / python_test (macos-14) (push) Blocked by required conditions
CI / python_test (ubuntu-22.04) (push) Blocked by required conditions
CI / cpp_test_driver (macos-13) (push) Blocked by required conditions
CI / cpp_test_driver (ubuntu-22.04) (push) Blocked by required conditions
CI / cpp_test_driver (windows-2022) (push) Blocked by required conditions
CI / cpp_cmake (macos-14, 1.85) (push) Blocked by required conditions
CI / cpp_cmake (ubuntu-22.04, stable) (push) Blocked by required conditions
CI / cpp_cmake (windows-2022, nightly) (push) Blocked by required conditions
CI / mcu (pico2-st7789, thumbv8m.main-none-eabihf) (push) Blocked by required conditions
CI / mcu (stm32h735g, thumbv7em-none-eabihf) (push) Blocked by required conditions
CI / mcu-embassy (push) Blocked by required conditions
CI / ffi_32bit_build (push) Blocked by required conditions
CI / docs (push) Blocked by required conditions
CI / wasm (push) Blocked by required conditions
CI / wasm_demo (push) Blocked by required conditions
CI / tree-sitter (push) Blocked by required conditions
CI / updater_test (0.3.0) (push) Blocked by required conditions
CI / android (push) Blocked by required conditions
CI / miri (push) Blocked by required conditions
CI / cpp_package_test (push) Blocked by required conditions
CI / vsce_build_test (push) Blocked by required conditions
CI / fmt_test (push) Blocked by required conditions
CI / esp-idf-quick (push) Blocked by required conditions
CI / test-figma-inspector (push) Blocked by required conditions
The second constructor of `Slice` causes the Slice to be passed differently (in different register) as a return value. So remove that constructor and use a helper function to construct a Slice
This commit is contained in:
parent
fd28676ab6
commit
a0192d443e
8 changed files with 65 additions and 86 deletions
|
|
@ -410,13 +410,7 @@ fn gen_corelib(
|
||||||
string_config.export.exclude = vec!["SharedString".into()];
|
string_config.export.exclude = vec!["SharedString".into()];
|
||||||
string_config.export.body.insert(
|
string_config.export.body.insert(
|
||||||
"Slice".to_owned(),
|
"Slice".to_owned(),
|
||||||
" const T &operator[](int i) const { return ptr[i]; }
|
" const T &operator[](int i) const { return ptr[i]; }".to_owned(),
|
||||||
/// Note: this doesn't initialize Slice properly, but we need to keep the struct as compatible with C
|
|
||||||
constexpr Slice() = default;
|
|
||||||
/// Rust uses a NonNull, so even empty slices shouldn't use nullptr
|
|
||||||
constexpr Slice(const T *ptr, uintptr_t len) : ptr(ptr ? const_cast<T*>(ptr) : reinterpret_cast<T*>(sizeof(T))), len(len) {}
|
|
||||||
"
|
|
||||||
.to_owned(),
|
|
||||||
);
|
);
|
||||||
cbindgen::Builder::new()
|
cbindgen::Builder::new()
|
||||||
.with_config(string_config)
|
.with_config(string_config)
|
||||||
|
|
|
||||||
|
|
@ -500,10 +500,7 @@ inline Struct::Struct(std::initializer_list<std::pair<std::string_view, Value>>
|
||||||
inline std::optional<Value> Struct::get_field(std::string_view name) const
|
inline std::optional<Value> Struct::get_field(std::string_view name) const
|
||||||
{
|
{
|
||||||
using namespace cbindgen_private;
|
using namespace cbindgen_private;
|
||||||
cbindgen_private::Slice<uint8_t> name_view {
|
cbindgen_private::Slice<uint8_t> name_view = slint::private_api::string_to_slice(name);
|
||||||
const_cast<unsigned char *>(reinterpret_cast<const unsigned char *>(name.data())),
|
|
||||||
name.size()
|
|
||||||
};
|
|
||||||
if (cbindgen_private::Value *field_val =
|
if (cbindgen_private::Value *field_val =
|
||||||
cbindgen_private::slint_interpreter_struct_get_field(&inner, name_view)) {
|
cbindgen_private::slint_interpreter_struct_get_field(&inner, name_view)) {
|
||||||
return Value(std::move(field_val));
|
return Value(std::move(field_val));
|
||||||
|
|
@ -513,10 +510,7 @@ inline std::optional<Value> Struct::get_field(std::string_view name) const
|
||||||
}
|
}
|
||||||
inline void Struct::set_field(std::string_view name, const Value &value)
|
inline void Struct::set_field(std::string_view name, const Value &value)
|
||||||
{
|
{
|
||||||
cbindgen_private::Slice<uint8_t> name_view {
|
cbindgen_private::Slice<uint8_t> name_view = slint::private_api::string_to_slice(name);
|
||||||
const_cast<unsigned char *>(reinterpret_cast<const unsigned char *>(name.data())),
|
|
||||||
name.size()
|
|
||||||
};
|
|
||||||
cbindgen_private::slint_interpreter_struct_set_field(&inner, name_view, value.inner);
|
cbindgen_private::slint_interpreter_struct_set_field(&inner, name_view, value.inner);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -661,11 +655,8 @@ public:
|
||||||
std::optional<Value> invoke(std::string_view name, std::span<const Value> args) const
|
std::optional<Value> invoke(std::string_view name, std::span<const Value> args) const
|
||||||
{
|
{
|
||||||
using namespace cbindgen_private;
|
using namespace cbindgen_private;
|
||||||
Slice<Box<cbindgen_private::Value>> args_view {
|
Slice<Box<cbindgen_private::Value>> args_view = slint::private_api::make_slice(
|
||||||
const_cast<Box<cbindgen_private::Value> *>(
|
reinterpret_cast<const Box<cbindgen_private::Value> *>(args.data()), args.size());
|
||||||
reinterpret_cast<const Box<cbindgen_private::Value> *>(args.data())),
|
|
||||||
args.size()
|
|
||||||
};
|
|
||||||
if (cbindgen_private::Value *rval_inner = slint_interpreter_component_instance_invoke(
|
if (cbindgen_private::Value *rval_inner = slint_interpreter_component_instance_invoke(
|
||||||
inner(), slint::private_api::string_to_slice(name), args_view)) {
|
inner(), slint::private_api::string_to_slice(name), args_view)) {
|
||||||
return Value(std::move(rval_inner));
|
return Value(std::move(rval_inner));
|
||||||
|
|
@ -796,12 +787,11 @@ public:
|
||||||
std::span<const Value> args) const
|
std::span<const Value> args) const
|
||||||
{
|
{
|
||||||
using namespace cbindgen_private;
|
using namespace cbindgen_private;
|
||||||
Slice<cbindgen_private::Box<cbindgen_private::Value>> args_view {
|
Slice<cbindgen_private::Box<cbindgen_private::Value>> args_view =
|
||||||
const_cast<cbindgen_private::Box<cbindgen_private::Value> *>(
|
slint::private_api::make_slice(
|
||||||
reinterpret_cast<const cbindgen_private::Box<cbindgen_private::Value> *>(
|
reinterpret_cast<const cbindgen_private::Box<cbindgen_private::Value> *>(
|
||||||
args.data())),
|
args.data()),
|
||||||
args.size()
|
args.size());
|
||||||
};
|
|
||||||
if (cbindgen_private::Value *rval_inner =
|
if (cbindgen_private::Value *rval_inner =
|
||||||
slint_interpreter_component_instance_invoke_global(
|
slint_interpreter_component_instance_invoke_global(
|
||||||
inner(), slint::private_api::string_to_slice(global),
|
inner(), slint::private_api::string_to_slice(global),
|
||||||
|
|
|
||||||
|
|
@ -95,10 +95,7 @@ public:
|
||||||
static SharedVector<ElementHandle> find_by_accessible_label(const ComponentHandle<T> &component,
|
static SharedVector<ElementHandle> find_by_accessible_label(const ComponentHandle<T> &component,
|
||||||
std::string_view label)
|
std::string_view label)
|
||||||
{
|
{
|
||||||
cbindgen_private::Slice<uint8_t> label_view {
|
cbindgen_private::Slice<uint8_t> label_view = private_api::string_to_slice(label);
|
||||||
const_cast<unsigned char *>(reinterpret_cast<const unsigned char *>(label.data())),
|
|
||||||
label.size()
|
|
||||||
};
|
|
||||||
auto vrc = component.into_dyn();
|
auto vrc = component.into_dyn();
|
||||||
SharedVector<ElementHandle> result;
|
SharedVector<ElementHandle> result;
|
||||||
cbindgen_private::slint_testing_element_find_by_accessible_label(
|
cbindgen_private::slint_testing_element_find_by_accessible_label(
|
||||||
|
|
@ -112,10 +109,7 @@ public:
|
||||||
static SharedVector<ElementHandle> find_by_element_id(const ComponentHandle<T> &component,
|
static SharedVector<ElementHandle> find_by_element_id(const ComponentHandle<T> &component,
|
||||||
std::string_view element_id)
|
std::string_view element_id)
|
||||||
{
|
{
|
||||||
cbindgen_private::Slice<uint8_t> element_id_view {
|
cbindgen_private::Slice<uint8_t> element_id_view = private_api::string_to_slice(element_id);
|
||||||
const_cast<unsigned char *>(reinterpret_cast<const unsigned char *>(element_id.data())),
|
|
||||||
element_id.size()
|
|
||||||
};
|
|
||||||
auto vrc = component.into_dyn();
|
auto vrc = component.into_dyn();
|
||||||
SharedVector<ElementHandle> result;
|
SharedVector<ElementHandle> result;
|
||||||
cbindgen_private::slint_testing_element_find_by_element_id(
|
cbindgen_private::slint_testing_element_find_by_element_id(
|
||||||
|
|
@ -129,10 +123,8 @@ public:
|
||||||
static SharedVector<ElementHandle>
|
static SharedVector<ElementHandle>
|
||||||
find_by_element_type_name(const ComponentHandle<T> &component, std::string_view type_name)
|
find_by_element_type_name(const ComponentHandle<T> &component, std::string_view type_name)
|
||||||
{
|
{
|
||||||
cbindgen_private::Slice<uint8_t> element_type_name_view {
|
cbindgen_private::Slice<uint8_t> element_type_name_view =
|
||||||
const_cast<unsigned char *>(reinterpret_cast<const unsigned char *>(type_name.data())),
|
private_api::string_to_slice(type_name);
|
||||||
type_name.size()
|
|
||||||
};
|
|
||||||
auto vrc = component.into_dyn();
|
auto vrc = component.into_dyn();
|
||||||
SharedVector<ElementHandle> result;
|
SharedVector<ElementHandle> result;
|
||||||
cbindgen_private::slint_testing_element_find_by_element_type_name(
|
cbindgen_private::slint_testing_element_find_by_element_type_name(
|
||||||
|
|
|
||||||
|
|
@ -117,8 +117,8 @@ inline SharedVector<float> solve_box_layout(const cbindgen_private::BoxLayoutDat
|
||||||
cbindgen_private::Slice<int> repeater_indexes)
|
cbindgen_private::Slice<int> repeater_indexes)
|
||||||
{
|
{
|
||||||
SharedVector<float> result;
|
SharedVector<float> result;
|
||||||
cbindgen_private::Slice<uint32_t> ri { reinterpret_cast<uint32_t *>(repeater_indexes.ptr),
|
cbindgen_private::Slice<uint32_t> ri =
|
||||||
repeater_indexes.len };
|
make_slice(reinterpret_cast<uint32_t *>(repeater_indexes.ptr), repeater_indexes.len);
|
||||||
cbindgen_private::slint_solve_box_layout(&data, ri, &result);
|
cbindgen_private::slint_solve_box_layout(&data, ri, &result);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
@ -233,9 +233,7 @@ inline SharedString translate_from_bundle(std::span<const char8_t *const> strs,
|
||||||
{
|
{
|
||||||
SharedString result;
|
SharedString result;
|
||||||
cbindgen_private::slint_translate_from_bundle(
|
cbindgen_private::slint_translate_from_bundle(
|
||||||
cbindgen_private::Slice<const char *>(
|
make_slice((reinterpret_cast<char const *const *>(strs.data())), strs.size()),
|
||||||
const_cast<char const **>(reinterpret_cast<char const *const *>(strs.data())),
|
|
||||||
strs.size()),
|
|
||||||
arguments, &result);
|
arguments, &result);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
@ -246,15 +244,12 @@ translate_from_bundle_with_plural(std::span<const char8_t *const> strs,
|
||||||
cbindgen_private::Slice<SharedString> arguments, int n)
|
cbindgen_private::Slice<SharedString> arguments, int n)
|
||||||
{
|
{
|
||||||
SharedString result;
|
SharedString result;
|
||||||
cbindgen_private::Slice<const char *> strs_slice(
|
cbindgen_private::Slice<const char *> strs_slice =
|
||||||
const_cast<char const **>(reinterpret_cast<char const *const *>(strs.data())),
|
make_slice(reinterpret_cast<char const *const *>(strs.data()), strs.size());
|
||||||
strs.size());
|
cbindgen_private::Slice<uint32_t> indices_slice =
|
||||||
cbindgen_private::Slice<uint32_t> indices_slice(
|
make_slice(reinterpret_cast<const uint32_t *>(indices.data()), indices.size());
|
||||||
const_cast<uint32_t *>(reinterpret_cast<const uint32_t *>(indices.data())),
|
cbindgen_private::Slice<uintptr_t (*)(int32_t)> plural_rules_slice =
|
||||||
indices.size());
|
make_slice(reinterpret_cast<uintptr_t (*const *)(int32_t)>(plural_rules.data()),
|
||||||
cbindgen_private::Slice<uintptr_t (*)(int32_t)> plural_rules_slice(
|
|
||||||
const_cast<uintptr_t (**)(int32_t)>(
|
|
||||||
reinterpret_cast<uintptr_t (*const *)(int32_t)>(plural_rules.data())),
|
|
||||||
plural_rules.size());
|
plural_rules.size());
|
||||||
cbindgen_private::slint_translate_from_bundle_with_plural(
|
cbindgen_private::slint_translate_from_bundle_with_plural(
|
||||||
strs_slice, indices_slice, plural_rules_slice, arguments, n, &result);
|
strs_slice, indices_slice, plural_rules_slice, arguments, n, &result);
|
||||||
|
|
|
||||||
|
|
@ -284,12 +284,7 @@ inline Image load_image_from_embedded_data(std::span<const uint8_t> data,
|
||||||
{
|
{
|
||||||
cbindgen_private::types::Image img(cbindgen_private::types::Image::ImageInner_None());
|
cbindgen_private::types::Image img(cbindgen_private::types::Image::ImageInner_None());
|
||||||
cbindgen_private::types::slint_image_load_from_embedded_data(
|
cbindgen_private::types::slint_image_load_from_embedded_data(
|
||||||
slint::cbindgen_private::Slice<uint8_t> { const_cast<uint8_t *>(data.data()),
|
make_slice(data.data(), data.size()), string_to_slice(extension), &img);
|
||||||
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);
|
return Image(img);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <string_view>
|
#include <string_view>
|
||||||
|
#include <span>
|
||||||
#include "slint_string_internal.h"
|
#include "slint_string_internal.h"
|
||||||
|
|
||||||
namespace slint {
|
namespace slint {
|
||||||
|
|
@ -223,11 +224,26 @@ private:
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace private_api {
|
namespace private_api {
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
inline cbindgen_private::Slice<T> make_slice(const T *ptr, size_t len)
|
||||||
|
{
|
||||||
|
return cbindgen_private::Slice<T> {
|
||||||
|
// Rust uses a NonNull, so even empty slices shouldn't use nullptr
|
||||||
|
.ptr = ptr ? const_cast<T *>(ptr) : reinterpret_cast<T *>(sizeof(T)),
|
||||||
|
.len = len,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T, size_t Extent>
|
||||||
|
inline cbindgen_private::Slice<std::remove_const_t<T>> make_slice(std::span<T, Extent> span)
|
||||||
|
{
|
||||||
|
return make_slice(span.data(), span.size());
|
||||||
|
}
|
||||||
|
|
||||||
inline cbindgen_private::Slice<uint8_t> string_to_slice(std::string_view str)
|
inline cbindgen_private::Slice<uint8_t> string_to_slice(std::string_view str)
|
||||||
{
|
{
|
||||||
return cbindgen_private::Slice<uint8_t> {
|
return make_slice(reinterpret_cast<const uint8_t *>(str.data()), str.size());
|
||||||
const_cast<unsigned char *>(reinterpret_cast<const unsigned char *>(str.data())), str.size()
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -216,8 +216,7 @@ public:
|
||||||
inline std::optional<SharedString> register_font_from_data(const uint8_t *data, std::size_t len)
|
inline std::optional<SharedString> register_font_from_data(const uint8_t *data, std::size_t len)
|
||||||
{
|
{
|
||||||
SharedString maybe_err;
|
SharedString maybe_err;
|
||||||
cbindgen_private::slint_register_font_from_data(
|
cbindgen_private::slint_register_font_from_data(&inner, make_slice(data, len), &maybe_err);
|
||||||
&inner, { const_cast<uint8_t *>(data), len }, &maybe_err);
|
|
||||||
if (!maybe_err.empty()) {
|
if (!maybe_err.empty()) {
|
||||||
return maybe_err;
|
return maybe_err;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -991,12 +991,14 @@ fn embed_resource(
|
||||||
)),
|
)),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}));
|
}));
|
||||||
let init = format!("slint::cbindgen_private::types::StaticTextures {{
|
let init = format!(
|
||||||
|
"slint::cbindgen_private::types::StaticTextures {{
|
||||||
.size = {{ {width}, {height} }},
|
.size = {{ {width}, {height} }},
|
||||||
.original_size = {{ {unscaled_width}, {unscaled_height} }},
|
.original_size = {{ {unscaled_width}, {unscaled_height} }},
|
||||||
.data = slint::cbindgen_private::Slice<uint8_t>{{ {data_name} , {count} }},
|
.data = slint::private_api::make_slice({data_name} , {count} ),
|
||||||
.textures = slint::cbindgen_private::Slice<slint::cbindgen_private::types::StaticTexture>{{ &{texture_name}, 1 }}
|
.textures = slint::private_api::make_slice(&{texture_name}, 1)
|
||||||
}}");
|
}}"
|
||||||
|
);
|
||||||
declarations.push(Declaration::Var(Var {
|
declarations.push(Declaration::Var(Var {
|
||||||
ty: "const slint::cbindgen_private::types::StaticTextures".into(),
|
ty: "const slint::cbindgen_private::types::StaticTextures".into(),
|
||||||
name: format_smolstr!("slint_embedded_resource_{}", resource.id),
|
name: format_smolstr!("slint_embedded_resource_{}", resource.id),
|
||||||
|
|
@ -1078,7 +1080,7 @@ fn embed_resource(
|
||||||
name: format_smolstr!("slint_embedded_resource_{}_glyphset_{}", resource.id, glyphset_index),
|
name: format_smolstr!("slint_embedded_resource_{}_glyphset_{}", resource.id, glyphset_index),
|
||||||
array_size: Some(glyphset.glyph_data.len()),
|
array_size: Some(glyphset.glyph_data.len()),
|
||||||
init: Some(format!("{{ {} }}", glyphset.glyph_data.iter().enumerate().map(|(glyph_index, glyph)| {
|
init: Some(format!("{{ {} }}", glyphset.glyph_data.iter().enumerate().map(|(glyph_index, glyph)| {
|
||||||
format!("{{ .x = {}, .y = {}, .width = {}, .height = {}, .x_advance = {}, .data = slint::cbindgen_private::Slice<uint8_t>{{ {}, {} }} }}",
|
format!("{{ .x = {}, .y = {}, .width = {}, .height = {}, .x_advance = {}, .data = slint::private_api::make_slice({}, {}) }}",
|
||||||
glyph.x, glyph.y, glyph.width, glyph.height, glyph.x_advance,
|
glyph.x, glyph.y, glyph.width, glyph.height, glyph.x_advance,
|
||||||
format!("slint_embedded_resource_{}_gs_{}_gd_{}", resource.id, glyphset_index, glyph_index),
|
format!("slint_embedded_resource_{}_gs_{}_gd_{}", resource.id, glyphset_index, glyph_index),
|
||||||
glyph.data.len()
|
glyph.data.len()
|
||||||
|
|
@ -1101,10 +1103,7 @@ fn embed_resource(
|
||||||
.iter()
|
.iter()
|
||||||
.enumerate()
|
.enumerate()
|
||||||
.map(|(glyphset_index, glyphset)| format!(
|
.map(|(glyphset_index, glyphset)| format!(
|
||||||
"{{ .pixel_size = {}, .glyph_data = slint::cbindgen_private::Slice<slint::cbindgen_private::BitmapGlyph>{{
|
"{{ .pixel_size = {}, .glyph_data = slint::private_api::make_slice({}, {}) }}",
|
||||||
{}, {}
|
|
||||||
}}
|
|
||||||
}}",
|
|
||||||
glyphset.pixel_size, format!("slint_embedded_resource_{}_glyphset_{}", resource.id, glyphset_index), glyphset.glyph_data.len()
|
glyphset.pixel_size, format!("slint_embedded_resource_{}_glyphset_{}", resource.id, glyphset_index), glyphset.glyph_data.len()
|
||||||
))
|
))
|
||||||
.join(", \n")
|
.join(", \n")
|
||||||
|
|
@ -1114,14 +1113,14 @@ fn embed_resource(
|
||||||
|
|
||||||
let init = format!(
|
let init = format!(
|
||||||
"slint::cbindgen_private::BitmapFont {{
|
"slint::cbindgen_private::BitmapFont {{
|
||||||
.family_name = slint::cbindgen_private::Slice<uint8_t>{{ {family_name_var} , {family_name_size} }},
|
.family_name = slint::private_api::make_slice({family_name_var} , {family_name_size}),
|
||||||
.character_map = slint::cbindgen_private::Slice<slint::cbindgen_private::CharacterMapEntry>{{ {charmap_var}, {charmap_size} }},
|
.character_map = slint::private_api::make_slice({charmap_var}, {charmap_size}),
|
||||||
.units_per_em = {units_per_em},
|
.units_per_em = {units_per_em},
|
||||||
.ascent = {ascent},
|
.ascent = {ascent},
|
||||||
.descent = {descent},
|
.descent = {descent},
|
||||||
.x_height = {x_height},
|
.x_height = {x_height},
|
||||||
.cap_height = {cap_height},
|
.cap_height = {cap_height},
|
||||||
.glyphs = slint::cbindgen_private::Slice<slint::cbindgen_private::BitmapGlyphs>{{ {glyphsets_var}, {glyphsets_size} }},
|
.glyphs = slint::private_api::make_slice({glyphsets_var}, {glyphsets_size}),
|
||||||
.weight = {weight},
|
.weight = {weight},
|
||||||
.italic = {italic},
|
.italic = {italic},
|
||||||
.sdf = {sdf},
|
.sdf = {sdf},
|
||||||
|
|
@ -1584,13 +1583,13 @@ fn generate_item_tree(
|
||||||
Access::Private,
|
Access::Private,
|
||||||
Declaration::Function(Function {
|
Declaration::Function(Function {
|
||||||
name: "item_tree".into(),
|
name: "item_tree".into(),
|
||||||
signature: "() -> slint::cbindgen_private::Slice<slint::private_api::ItemTreeNode>".into(),
|
signature: "() -> slint::cbindgen_private::Slice<slint::private_api::ItemTreeNode>"
|
||||||
|
.into(),
|
||||||
is_static: true,
|
is_static: true,
|
||||||
statements: Some(vec![
|
statements: Some(vec![
|
||||||
"static const slint::private_api::ItemTreeNode children[] {".to_owned(),
|
"static const slint::private_api::ItemTreeNode children[] {".to_owned(),
|
||||||
format!(" {} }};", item_tree_array.join(", \n")),
|
format!(" {} }};", item_tree_array.join(", \n")),
|
||||||
"return { const_cast<slint::private_api::ItemTreeNode*>(children), std::size(children) };"
|
"return slint::private_api::make_slice(std::span(children));".to_owned(),
|
||||||
.to_owned(),
|
|
||||||
]),
|
]),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}),
|
}),
|
||||||
|
|
@ -1605,8 +1604,7 @@ fn generate_item_tree(
|
||||||
statements: Some(vec![
|
statements: Some(vec![
|
||||||
"static const slint::private_api::ItemArrayEntry items[] {".to_owned(),
|
"static const slint::private_api::ItemArrayEntry items[] {".to_owned(),
|
||||||
format!(" {} }};", item_array.join(", \n")),
|
format!(" {} }};", item_array.join(", \n")),
|
||||||
"return { const_cast<slint::private_api::ItemArrayEntry*>(items), std::size(items) };"
|
"return slint::private_api::make_slice(std::span(items));".to_owned(),
|
||||||
.to_owned(),
|
|
||||||
]),
|
]),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}),
|
}),
|
||||||
|
|
@ -1803,7 +1801,7 @@ fn generate_item_tree(
|
||||||
.map(|l| format!("slint::private_api::string_to_slice({l:?})"))
|
.map(|l| format!("slint::private_api::string_to_slice({l:?})"))
|
||||||
.join(", ")
|
.join(", ")
|
||||||
));
|
));
|
||||||
create_code.push(format!("slint::cbindgen_private::slint_translate_set_bundled_languages({{ languages.data(), {lang_len} }});"));
|
create_code.push(format!("slint::cbindgen_private::slint_translate_set_bundled_languages(slint::private_api::make_slice(std::span(languages)));"));
|
||||||
}
|
}
|
||||||
|
|
||||||
create_code.push("self->globals = &self->m_globals;".into());
|
create_code.push("self->globals = &self->m_globals;".into());
|
||||||
|
|
@ -3397,7 +3395,7 @@ fn compile_expression(expr: &llr::Expression, ctx: &EvaluationContext) -> String
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
format!(
|
format!(
|
||||||
"slint::cbindgen_private::Slice<{ty}>{{ std::array<{ty}, {count}>{{ {val} }}.data(), {count} }}",
|
"slint::private_api::make_slice<{ty}>(std::array<{ty}, {count}>{{ {val} }}.data(), {count})",
|
||||||
count = values.len(),
|
count = values.len(),
|
||||||
ty = ty,
|
ty = ty,
|
||||||
val = val.join(", ")
|
val = val.join(", ")
|
||||||
|
|
@ -3511,7 +3509,7 @@ fn compile_expression(expr: &llr::Expression, ctx: &EvaluationContext) -> String
|
||||||
};
|
};
|
||||||
format!("slint::cbindgen_private::GridLayoutCellData {cv}_array [] = {{ {c} }};\
|
format!("slint::cbindgen_private::GridLayoutCellData {cv}_array [] = {{ {c} }};\
|
||||||
slint::cbindgen_private::slint_reorder_dialog_button_layout({cv}_array, {r});\
|
slint::cbindgen_private::slint_reorder_dialog_button_layout({cv}_array, {r});\
|
||||||
slint::cbindgen_private::Slice<slint::cbindgen_private::GridLayoutCellData> {cv} {{ std::data({cv}_array), std::size({cv}_array) }}",
|
slint::cbindgen_private::Slice<slint::cbindgen_private::GridLayoutCellData> {cv} = slint::private_api::make_slice(std::span({cv}_array))",
|
||||||
r = compile_expression(roles, ctx),
|
r = compile_expression(roles, ctx),
|
||||||
cv = cells_variable,
|
cv = cells_variable,
|
||||||
c = cells.join(", "),
|
c = cells.join(", "),
|
||||||
|
|
@ -4099,13 +4097,13 @@ fn box_layout_function(
|
||||||
let ri = repeated_indices.as_ref().map_or(String::new(), |ri| {
|
let ri = repeated_indices.as_ref().map_or(String::new(), |ri| {
|
||||||
write!(
|
write!(
|
||||||
push_code,
|
push_code,
|
||||||
"slint::cbindgen_private::Slice<int> {ri}{{ {ri}_array.data(), {ri}_array.size() }};"
|
"slint::cbindgen_private::Slice<int> {ri} = slint::private_api::make_slice(std::span({ri}_array));"
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
format!("std::array<int, {}> {}_array;", 2 * repeater_idx, ri)
|
format!("std::array<int, {}> {}_array;", 2 * repeater_idx, ri)
|
||||||
});
|
});
|
||||||
format!(
|
format!(
|
||||||
"[&]{{ {} {} slint::cbindgen_private::Slice<slint::cbindgen_private::BoxLayoutCellData>{}{{cells_vector.data(), cells_vector.size()}}; return {}; }}()",
|
"[&]{{ {} {} slint::cbindgen_private::Slice<slint::cbindgen_private::BoxLayoutCellData>{} = slint::private_api::make_slice(std::span(cells_vector)); return {}; }}()",
|
||||||
ri,
|
ri,
|
||||||
push_code,
|
push_code,
|
||||||
ident(cells_variable),
|
ident(cells_variable),
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue