Rename "Live Reload" feature to "Live Preview for Rust/C++"
Some checks are pending
autofix.ci / format_fix (push) Waiting to run
autofix.ci / lint_typecheck (push) Waiting to run
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 / 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) (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 / python_test (windows-2022) (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 / fmt_test (push) Blocked by required conditions
CI / esp-idf-quick (push) Blocked by required conditions
CI / android (push) Blocked by required conditions
CI / miri (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 / cpp_package_test (push) Blocked by required conditions
CI / vsce_build_test (push) Blocked by required conditions
CI / mcu (pico-st7789, thumbv6m-none-eabi) (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 / test-figma-inspector (push) Blocked by required conditions

This commit is contained in:
Olivier Goffart 2025-08-28 15:46:32 +02:00
parent 860be0c410
commit 88c0323e6c
20 changed files with 111 additions and 109 deletions

View file

@ -106,10 +106,10 @@ jobs:
- name: Run tests (qt)
run: cargo test --verbose --all-features --workspace ${{ matrix.extra_args }} ${{ matrix.maybe_exclude_bevy }} --exclude slint-node --exclude pyslint --exclude test-driver-node --exclude slint-node --exclude test-driver-nodejs --exclude test-driver-cpp --exclude mcu-board-support --exclude mcu-embassy --exclude printerdemo_mcu --exclude uefi-demo --exclude slint-cpp --exclude slint-python --bin test-driver-rust -- _qt --test-threads=1
shell: bash
- name: live-reload test
- name: live-preview for rust test
env:
SLINT_LIVE_RELOAD: 1
run: cargo test --verbose --features=build-time,slint/live-reload -p test-driver-rust -- --skip=_qt::t
SLINT_LIVE_PREVIEW: 1
run: cargo test --verbose --features=build-time,slint/live-preview -p test-driver-rust -- --skip=_qt::t
shell: bash
- name: Archive screenshots after failed tests
if: ${{ failure() }}

View file

@ -53,7 +53,7 @@ All notable changes to this project are documented in this file.
- Upgraded WGPU dependency to version 26: The `unstable-wgpu-26` Cargo feature replaces the old `unstable-wgpu-24` feature,
and the `slint::wgpu_26` module replaces the `slint::wgpu_24` module. There were no further changes to the API.
- Fixed compilation of generated code if the slint code declares a type named `core`.
- Support for live-reload with the `slint/live-reload` feature and `SLINT_LIVE_RELOAD` env variable
- Support for live-preview with the `slint/live-preview` feature and `SLINT_LIVE_PREVIEW` env variable
- winit: Added API to await for the existence of the winit window
- Added `FromIterator<char>` and `Extend<char>` for `SharedString`
- Added `SharedVector::reserve()`
@ -61,7 +61,7 @@ All notable changes to this project are documented in this file.
### C++
- Added `SharedString::clear()`.
- Support for live-reload with the `SLINT_FEATURE_LIVE_RELOAD` feature and `SLINT_LIVE_RELOAD` env variable
- Support for live-preview with the `SLINT_FEATURE_LIVE_PREVIEW` feature and `SLINT_LIVE_PREVIEW` env variable
- `SLINT_FEATURE_RENDERER_FEMTOVG_WGPU` is no longer enabled by default
- esp-idf: `slint::invoke_from_event_loop` can now be invoked before starting the event loop.
- Fixed Windows AArch64 support

View file

@ -92,7 +92,7 @@ define_renderer_winit_compat_option(skia-vulkan)
define_renderer_winit_compat_option(software)
define_cargo_dependent_feature(interpreter "Enable support for the Slint interpreter to load .slint files at run-time" ON "NOT SLINT_FEATURE_FREESTANDING")
define_cargo_dependent_feature(live-reload "Enable support for the Slint live-reload to re-load changed .slint files at run-time" OFF "SLINT_FEATURE_INTERPRETER")
define_cargo_dependent_feature(live-preview "Enable support for the Slint live-preview to re-load changed .slint files at run-time" OFF "SLINT_FEATURE_INTERPRETER")
define_cargo_dependent_feature(backend-winit "Enable support for the winit crate to interaction with all windowing systems." ON "NOT SLINT_FEATURE_FREESTANDING")
define_cargo_dependent_feature(backend-winit-x11 "Enable support for the winit create to interact only with the X11 windowing system on Unix. Enable this option and turn off SLINT_FEATURE_BACKEND_WINIT for a smaller build with just X11 support on Unix." OFF "NOT SLINT_FEATURE_FREESTANDING")

View file

@ -26,7 +26,7 @@ name = "slint_cpp"
# the C++ crate's CMakeLists.txt as well as cbindgen.rs
[features]
interpreter = ["slint-interpreter", "std"]
live-reload = ["interpreter", "slint-interpreter/internal-live-reload"]
live-preview = ["interpreter", "slint-interpreter/internal-live-preview"]
# Enable some function used by the integration tests
testing = ["dep:i-slint-backend-testing"]

View file

@ -986,7 +986,7 @@ macro_rules! declare_features {
declare_features! {
interpreter
live_reload
live_preview
testing
backend_qt
backend_winit

View file

@ -26,7 +26,7 @@ struct ErasedItemTreeBox : vtable::Dyn
ErasedItemTreeBox(ErasedItemTreeBox &) = delete;
};
}
namespace slint::private_api::live_reload {
namespace slint::private_api::live_preview {
class LiveReloadingComponent;
class LiveReloadModelWrapperBase;
}
@ -400,8 +400,8 @@ private:
slint::cbindgen_private::Value *inner;
friend struct Struct;
friend class ComponentInstance;
friend class slint::private_api::live_reload::LiveReloadingComponent;
friend class slint::private_api::live_reload::LiveReloadModelWrapperBase;
friend class slint::private_api::live_preview::LiveReloadingComponent;
friend class slint::private_api::live_preview::LiveReloadModelWrapperBase;
// Internal constructor that takes ownership of the value
explicit Value(slint::cbindgen_private::Value *&&inner) : inner(inner) { }
};

View file

@ -5,14 +5,14 @@
#include "slint.h"
#ifndef SLINT_FEATURE_LIVE_RELOAD
# error SLINT_FEATURE_LIVE_RELOAD must be activated
#ifndef SLINT_FEATURE_LIVE_PREVIEW
# error SLINT_FEATURE_LIVE_PREVIEW must be activated
#else
# include "slint-interpreter.h"
/// Internal API to support the live-reload generated code
namespace slint::private_api::live_reload {
/// Internal API to support the live-preview generated code
namespace slint::private_api::live_preview {
template<typename T>
requires(std::convertible_to<T, slint::interpreter::Value>)
@ -137,7 +137,7 @@ public:
std::string_view style)
{
assert_main_thread();
inner = cbindgen_private::slint_live_reload_new(
inner = cbindgen_private::slint_live_preview_new(
string_to_slice(file_name), string_to_slice(component_name), &include_paths,
&libraries, string_to_slice(style));
}
@ -145,36 +145,36 @@ public:
LiveReloadingComponent(const LiveReloadingComponent &other) : inner(other.inner)
{
assert_main_thread();
cbindgen_private::slint_live_reload_clone(other.inner);
cbindgen_private::slint_live_preview_clone(other.inner);
}
LiveReloadingComponent &operator=(const LiveReloadingComponent &other)
{
assert_main_thread();
if (this == &other)
return *this;
cbindgen_private::slint_live_reload_drop(inner);
cbindgen_private::slint_live_preview_drop(inner);
inner = other.inner;
cbindgen_private::slint_live_reload_clone(inner);
cbindgen_private::slint_live_preview_clone(inner);
return *this;
}
~LiveReloadingComponent()
{
assert_main_thread();
cbindgen_private::slint_live_reload_drop(inner);
cbindgen_private::slint_live_preview_drop(inner);
}
void set_property(std::string_view name, const interpreter::Value &value) const
{
assert_main_thread();
return cbindgen_private::slint_live_reload_set_property(inner, string_to_slice(name),
value.inner);
return cbindgen_private::slint_live_preview_set_property(inner, string_to_slice(name),
value.inner);
}
interpreter::Value get_property(std::string_view name) const
{
assert_main_thread();
auto val = slint::interpreter::Value(
cbindgen_private::slint_live_reload_get_property(inner, string_to_slice(name)));
cbindgen_private::slint_live_preview_get_property(inner, string_to_slice(name)));
return val;
}
@ -186,7 +186,7 @@ public:
cbindgen_private::Slice<cbindgen_private::Value *> args_slice {
reinterpret_cast<cbindgen_private::Value **>(args_values.data()), args_values.size()
};
interpreter::Value val(cbindgen_private::slint_live_reload_invoke(
interpreter::Value val(cbindgen_private::slint_live_preview_invoke(
inner, string_to_slice(name), args_slice));
return val;
}
@ -208,7 +208,7 @@ public:
r.inner = cbindgen_private::slint_interpreter_value_new();
return inner;
};
return cbindgen_private::slint_live_reload_set_callback(
return cbindgen_private::slint_live_preview_set_callback(
inner, slint::private_api::string_to_slice(name), actual_cb,
new F(std::move(callback)), [](void *data) { delete reinterpret_cast<F *>(data); });
}
@ -216,7 +216,7 @@ public:
slint::Window &window() const
{
const cbindgen_private::WindowAdapterRcOpaque *win_ptr = nullptr;
cbindgen_private::slint_live_reload_window(inner, &win_ptr);
cbindgen_private::slint_live_preview_window(inner, &win_ptr);
return const_cast<slint::Window &>(*reinterpret_cast<const slint::Window *>(win_ptr));
}
@ -376,6 +376,6 @@ from_slint_value(const slint::interpreter::Value &value,
return {};
}
} // namespace slint::private_api::live_reload
} // namespace slint::private_api::live_preview
#endif // SLINT_FEATURE_LIVE_RELOAD
#endif // SLINT_FEATURE_LIVE_PREVIEW

View file

@ -442,7 +442,7 @@ pub fn compile_with_config(
println!("cargo:rerun-if-env-changed=SLINT_ASSET_SECTION");
println!("cargo:rerun-if-env-changed=SLINT_EMBED_RESOURCES");
println!("cargo:rerun-if-env-changed=SLINT_EMIT_DEBUG_INFO");
println!("cargo:rerun-if-env-changed=SLINT_LIVE_RELOAD");
println!("cargo:rerun-if-env-changed=SLINT_LIVE_PREVIEW");
println!(
"cargo:rustc-env=SLINT_INCLUDE_GENERATED={}",

View file

@ -83,18 +83,18 @@ raw-window-handle-06 = ["dep:raw-window-handle-06", "i-slint-backend-selector/ra
## AVIF, BMP, DDS, Farbfeld, GIF, HDR, ICO, JPEG, EXR, PNG, PNM, QOI, TGA, TIFF, WebP.
image-default-formats = ["i-slint-core/image-default-formats"]
## Enable the live reload feature
## Enable the live preview feature
##
## Enable this feature to reload the .slint files at runtime and reload it whenever the files are modified on disk.
## For this feature to work, it's also required to set the `SLINT_LIVE_RELOAD` environment variable during
## For this feature to work, it's also required to set the `SLINT_LIVE_PREVIEW` environment variable during
## application compilation.
##
## This is a feature for debugging and development. It's not recommended to add this feature to your Cargo.toml.
## Instead, use the `--features` command line argument like so when building your app:
## ```bash
## SLINT_LIVE_RELOAD=1 cargo build --features slint/live-reload
## SLINT_LIVE_PREVIEW=1 cargo build --features slint/live-preview
## ```
live-reload = ["dep:slint-interpreter"]
live-preview = ["dep:slint-interpreter"]
#! ### Backends
@ -234,7 +234,7 @@ i-slint-core = { workspace = true }
slint-macros = { workspace = true }
i-slint-backend-selector = { workspace = true }
i-slint-core-macros = { workspace = true }
slint-interpreter = { workspace = true, optional = true, default-features = false, features = ["display-diagnostics", "compat-1-2", "internal-live-reload"] }
slint-interpreter = { workspace = true, optional = true, default-features = false, features = ["display-diagnostics", "compat-1-2", "internal-live-preview"] }
const-field-offset = { version = "0.1.2", path = "../../../helper_crates/const-field-offset" }
document-features = { version = "0.2.0", optional = true }

View file

@ -235,6 +235,6 @@ pub mod re_exports {
pub use unicode_segmentation::UnicodeSegmentation;
pub use vtable::{self, *};
#[cfg(feature = "live-reload")]
pub use slint_interpreter::live_reload;
#[cfg(feature = "live-preview")]
pub use slint_interpreter::live_preview;
}

View file

@ -22,11 +22,11 @@ use crate::CompilerConfiguration;
#[cfg(feature = "cpp")]
pub mod cpp;
#[cfg(feature = "cpp")]
pub mod cpp_live_reload;
pub mod cpp_live_preview;
#[cfg(feature = "rust")]
pub mod rust;
#[cfg(feature = "rust")]
pub mod rust_live_reload;
pub mod rust_live_preview;
#[derive(Clone, Debug, PartialEq)]
pub enum OutputFormat {

View file

@ -681,8 +681,8 @@ pub fn generate(
config: Config,
compiler_config: &CompilerConfiguration,
) -> std::io::Result<impl std::fmt::Display> {
if std::env::var("SLINT_LIVE_RELOAD").is_ok() {
return super::cpp_live_reload::generate(doc, config, compiler_config);
if std::env::var("SLINT_LIVE_PREVIEW").is_ok() {
return super::cpp_live_preview::generate(doc, config, compiler_config);
}
let mut file = generate_types(&doc.used_types.borrow().structs_and_enums, &config);

View file

@ -17,7 +17,7 @@ pub fn generate(
) -> std::io::Result<File> {
let mut file = super::cpp::generate_types(&doc.used_types.borrow().structs_and_enums, &config);
file.includes.push("<slint_live_reload.h>".into());
file.includes.push("<slint_live_preview.h>".into());
generate_value_conversions(&mut file, &doc.used_types.borrow().structs_and_enums);
@ -74,8 +74,8 @@ fn generate_public_component(
component_struct.members.push((
Access::Private,
Declaration::Var(Var {
ty: "slint::private_api::live_reload::LiveReloadingComponent".into(),
name: "live_reload".into(),
ty: "slint::private_api::live_preview::LiveReloadingComponent".into(),
name: "live_preview".into(),
..Default::default()
}),
));
@ -83,7 +83,7 @@ fn generate_public_component(
let mut global_accessor_function_body = Vec::new();
for glob in unit.globals.iter().filter(|glob| glob.exported && glob.must_generate()) {
let accessor_statement = format!(
"{0}if constexpr(std::is_same_v<T, {1}>) {{ return T(live_reload); }}",
"{0}if constexpr(std::is_same_v<T, {1}>) {{ return T(live_preview); }}",
if global_accessor_function_body.is_empty() { "" } else { "else " },
concatenate_ident(&glob.name),
);
@ -138,8 +138,8 @@ fn generate_public_component(
let create_code = vec![
format!("slint::SharedVector<slint::SharedString> include_paths{{ {} }};", compiler_config.include_paths.iter().map(|p| format!("\"{}\"", escape_string(&p.to_string_lossy()))).join(", ")),
format!("slint::SharedVector<slint::SharedString> library_paths{{ {} }};", compiler_config.library_paths.iter().map(|(l, p)| format!("\"{l}={}\"", p.to_string_lossy())).join(", ")),
format!("auto live_reload = slint::private_api::live_reload::LiveReloadingComponent({main_file:?}, {:?}, include_paths, library_paths, \"{}\");", component.name, compiler_config.style.as_ref().unwrap_or(&String::new())),
format!("auto self_rc = vtable::VRc<slint::private_api::ItemTreeVTable, {component_id}>::make(std::move(live_reload));"),
format!("auto live_preview = slint::private_api::live_preview::LiveReloadingComponent({main_file:?}, {:?}, include_paths, library_paths, \"{}\");", component.name, compiler_config.style.as_ref().unwrap_or(&String::new())),
format!("auto self_rc = vtable::VRc<slint::private_api::ItemTreeVTable, {component_id}>::make(std::move(live_preview));"),
format!("return slint::ComponentHandle<{component_id}>(self_rc);"),
];
@ -159,9 +159,9 @@ fn generate_public_component(
Declaration::Function(Function {
is_constructor_or_destructor: true,
name: ident(&component_struct.name),
signature: "(slint::private_api::live_reload::LiveReloadingComponent live_reload)"
signature: "(slint::private_api::live_preview::LiveReloadingComponent live_preview)"
.into(),
constructor_member_initializers: vec!["live_reload(std::move(live_reload))".into()],
constructor_member_initializers: vec!["live_preview(std::move(live_preview))".into()],
statements: Some(vec![]),
..Default::default()
}),
@ -192,7 +192,7 @@ fn generate_public_component(
Declaration::Function(Function {
name: "window".into(),
signature: "() const -> slint::Window&".into(),
statements: Some(vec!["return live_reload.window();".into()]),
statements: Some(vec!["return live_preview.window();".into()]),
..Default::default()
}),
));
@ -221,8 +221,8 @@ fn generate_global(file: &mut File, global: &llr::GlobalComponent) {
global_struct.members.push((
Access::Private,
Declaration::Var(Var {
ty: "const slint::private_api::live_reload::LiveReloadingComponent&".into(),
name: "live_reload".into(),
ty: "const slint::private_api::live_preview::LiveReloadingComponent&".into(),
name: "live_preview".into(),
..Default::default()
}),
));
@ -233,9 +233,9 @@ fn generate_global(file: &mut File, global: &llr::GlobalComponent) {
is_constructor_or_destructor: true,
name: ident(&global.name),
signature:
"(const slint::private_api::live_reload::LiveReloadingComponent &live_reload)"
"(const slint::private_api::live_preview::LiveReloadingComponent &live_preview)"
.into(),
constructor_member_initializers: vec!["live_reload(live_reload)".into()],
constructor_member_initializers: vec!["live_preview(live_preview)".into()],
statements: Some(vec![]),
..Default::default()
}),
@ -267,7 +267,7 @@ fn generate_public_api_for_properties(
let param_types =
callback.args.iter().map(|t| t.cpp_type().unwrap()).collect::<Vec<_>>();
let callback_emitter = vec![format!(
"return {}(live_reload.invoke(\"{prefix}{prop_name}\" {}));",
"return {}(live_preview.invoke(\"{prefix}{prop_name}\" {}));",
convert_from_value_fn(&callback.return_type),
(0..callback.args.len()).map(|i| format!(", arg_{i}")).join(""),
)];
@ -311,9 +311,9 @@ fn generate_public_api_for_properties(
)),
signature: "(Functor && callback_handler) const".into(),
statements: Some(vec![
"using slint::private_api::live_reload::into_slint_value;".into(),
"using slint::private_api::live_preview::into_slint_value;".into(),
format!(
"live_reload.set_callback(\"{prefix}{prop_name}\", [callback_handler]([[maybe_unused]] auto args) {{ {return_statement} }});",
"live_preview.set_callback(\"{prefix}{prop_name}\", [callback_handler]([[maybe_unused]] auto args) {{ {return_statement} }});",
),
]),
..Default::default()
@ -324,7 +324,7 @@ fn generate_public_api_for_properties(
function.args.iter().map(|t| t.cpp_type().unwrap()).collect::<Vec<_>>();
let ret = function.return_type.cpp_type().unwrap();
let call_code = vec![format!(
"return {}(live_reload.invoke(\"{prefix}{prop_name}\"{}));",
"return {}(live_preview.invoke(\"{prefix}{prop_name}\"{}));",
convert_from_value_fn(&function.return_type),
(0..function.args.len()).map(|i| format!(", arg_{i}")).join("")
)];
@ -347,7 +347,7 @@ fn generate_public_api_for_properties(
} else {
let cpp_property_type = p.ty.cpp_type().expect("Invalid type in public properties");
let prop_getter: Vec<String> = vec![format!(
"return {}(live_reload.get_property(\"{prefix}{prop_name}\"));",
"return {}(live_preview.get_property(\"{prefix}{prop_name}\"));",
convert_from_value_fn(&p.ty)
)];
declarations.push((
@ -362,9 +362,9 @@ fn generate_public_api_for_properties(
if !p.read_only {
let prop_setter: Vec<String> = vec![
"using slint::private_api::live_reload::into_slint_value;".into(),
"using slint::private_api::live_preview::into_slint_value;".into(),
format!(
"live_reload.set_property(\"{prefix}{prop_name}\", {}(value));",
"live_preview.set_property(\"{prefix}{prop_name}\", {}(value));",
convert_to_value_fn(&p.ty)
),
];
@ -457,7 +457,7 @@ fn convert_from_value_fn(ty: &Type) -> String {
match ty {
Type::Struct(s) if s.name.is_none() => {
let mut init = s.fields.iter().map(|(name, ty)| {
format!("slint::private_api::live_reload::from_slint_value<{}>(s.get_field(\"{name}\").value())", ty.cpp_type().unwrap())
format!("slint::private_api::live_preview::from_slint_value<{}>(s.get_field(\"{name}\").value())", ty.cpp_type().unwrap())
});
format!(
"([](const slint::interpreter::Value &v) {{ auto s = v.to_struct().value(); return std::make_tuple({}); }})",
@ -465,7 +465,7 @@ fn convert_from_value_fn(ty: &Type) -> String {
)
}
_ => format!(
"slint::private_api::live_reload::from_slint_value<{}>",
"slint::private_api::live_preview::from_slint_value<{}>",
ty.cpp_type().unwrap_or_default()
),
}
@ -477,11 +477,11 @@ fn generate_value_conversions(file: &mut File, structs_and_enums: &[Type]) {
Type::Struct(s) if s.name.is_some() && s.node.is_some() => {
let name = ident(&s.name.as_ref().unwrap());
let mut to_statements = vec![
"using slint::private_api::live_reload::into_slint_value;".into(),
"using slint::private_api::live_preview::into_slint_value;".into(),
"slint::interpreter::Struct s;".into(),
];
let mut from_statements = vec![
"using slint::private_api::live_reload::from_slint_value;".into(),
"using slint::private_api::live_preview::from_slint_value;".into(),
"slint::interpreter::Struct s = val.to_struct().value();".into(),
format!("{name} self;"),
];
@ -491,7 +491,7 @@ fn generate_value_conversions(file: &mut File, structs_and_enums: &[Type]) {
ident(f)
));
from_statements.push(format!(
"self.{} = slint::private_api::live_reload::from_slint_value<{}>(s.get_field(\"{f}\").value());",
"self.{} = slint::private_api::live_preview::from_slint_value<{}>(s.get_field(\"{f}\").value());",
ident(f),
t.cpp_type().unwrap()
));
@ -519,7 +519,7 @@ fn generate_value_conversions(file: &mut File, structs_and_enums: &[Type]) {
}
Type::Enumeration(e) => {
let mut from_statements = vec![
"auto value_str = slint::private_api::live_reload::LiveReloadingComponent::get_enum_value(val);".to_string(),
"auto value_str = slint::private_api::live_preview::LiveReloadingComponent::get_enum_value(val);".to_string(),
];
let mut to_statements = vec!["switch (self) {".to_string()];
let name = ident(&e.name);
@ -531,7 +531,7 @@ fn generate_value_conversions(file: &mut File, structs_and_enums: &[Type]) {
from_statements.push(format!(
"if (value_str == \"{value}\") return {name}::{variant_name};"
));
to_statements.push(format!("case {name}::{variant_name}: return slint::private_api::live_reload::LiveReloadingComponent::value_from_enum(\"{}\", \"{value}\");", e.name));
to_statements.push(format!("case {name}::{variant_name}: return slint::private_api::live_preview::LiveReloadingComponent::value_from_enum(\"{}\", \"{value}\");", e.name));
}
from_statements.push("return {};".to_string());
to_statements.push("}".to_string());

View file

@ -156,8 +156,8 @@ pub fn generate(
doc: &Document,
compiler_config: &CompilerConfiguration,
) -> std::io::Result<TokenStream> {
if std::env::var("SLINT_LIVE_RELOAD").is_ok() {
return super::rust_live_reload::generate(doc, compiler_config);
if std::env::var("SLINT_LIVE_PREVIEW").is_ok() {
return super::rust_live_preview::generate(doc, compiler_config);
}
let (structs_and_enums_ids, inner_module) =

View file

@ -168,15 +168,15 @@ fn generate_public_component(
let style = compiler_config.style.iter();
quote!(
pub struct #public_component_id(sp::Rc<::core::cell::RefCell<sp::live_reload::LiveReloadingComponent>>, sp::Rc<dyn sp::WindowAdapter>);
pub struct #public_component_id(sp::Rc<::core::cell::RefCell<sp::live_preview::LiveReloadingComponent>>, sp::Rc<dyn sp::WindowAdapter>);
impl #public_component_id {
pub fn new() -> sp::Result<Self, slint::PlatformError> {
let mut compiler = sp::live_reload::Compiler::default();
let mut compiler = sp::live_preview::Compiler::default();
compiler.set_include_paths([#(#include_paths.into()),*].into_iter().collect());
compiler.set_library_paths([#(#library_paths.into()),*].into_iter().collect());
#(compiler.set_style(#style.to_string());)*
let instance = sp::live_reload::LiveReloadingComponent::new(compiler, #main_file.into(), #component_name.into())?;
let instance = sp::live_preview::LiveReloadingComponent::new(compiler, #main_file.into(), #component_name.into())?;
let window_adapter = sp::WindowInner::from_pub(slint::ComponentHandle::window(instance.borrow().instance())).window_adapter();
sp::Ok(Self(instance, window_adapter))
}
@ -185,7 +185,7 @@ fn generate_public_component(
}
impl slint::ComponentHandle for #public_component_id {
type WeakInner = sp::Weak<::core::cell::RefCell<sp::live_reload::LiveReloadingComponent>>;
type WeakInner = sp::Weak<::core::cell::RefCell<sp::live_preview::LiveReloadingComponent>>;
fn as_weak(&self) -> slint::Weak<Self> {
slint::Weak::new(sp::Rc::downgrade(&self.0))
}
@ -224,7 +224,7 @@ fn generate_public_component(
/// This is needed for the the internal tests (eg `slint_testing::send_keyboard_string_sequence`)
impl<X> ::core::convert::From<#public_component_id> for sp::VRc<sp::ItemTreeVTable, X>
where Self : ::core::convert::From<sp::live_reload::ComponentInstance>
where Self : ::core::convert::From<sp::live_preview::ComponentInstance>
{
fn from(value: #public_component_id) -> Self {
Self::from(slint::ComponentHandle::clone_strong(value.0.borrow().instance()))
@ -328,7 +328,7 @@ fn generate_global(global: &llr::GlobalComponent, root: &llr::CompilationUnit) -
quote!(
#[allow(unused)]
pub struct #public_component_id<'a>(&'a ::core::cell::RefCell<sp::live_reload::LiveReloadingComponent>);
pub struct #public_component_id<'a>(&'a ::core::cell::RefCell<sp::live_preview::LiveReloadingComponent>);
impl<'a> #public_component_id<'a> {
#(#property_and_callback_accessors)*
@ -347,13 +347,13 @@ fn convert_to_value_fn(ty: &Type) -> TokenStream {
let names = s.fields.keys().map(|k| k.as_str()).collect::<Vec<_>>();
let fields = names.iter().map(|k| ident(k)).collect::<Vec<_>>();
quote!((|(#(#fields,)*)| {
sp::live_reload::Value::Struct([#((#names.to_string(), sp::live_reload::Value::from(#fields)),)*].into_iter().collect())
sp::live_preview::Value::Struct([#((#names.to_string(), sp::live_preview::Value::from(#fields)),)*].into_iter().collect())
}))
}
Type::Array(a) if matches!(a.as_ref(), Type::Struct(s) if s.name.is_none()) => {
let conf_fn = convert_to_value_fn(a.as_ref());
quote!((|model: sp::ModelRc<_>| -> sp::live_reload::Value {
sp::live_reload::Value::Model(sp::ModelRc::new(model.map(#conf_fn)))
quote!((|model: sp::ModelRc<_>| -> sp::live_preview::Value {
sp::live_preview::Value::Model(sp::ModelRc::new(model.map(#conf_fn)))
}))
}
_ => quote!(::core::convert::From::from),
@ -367,15 +367,15 @@ fn convert_from_value_fn(ty: &Type) -> TokenStream {
Type::Struct(s) if s.name.is_none() => {
let names = s.fields.keys().map(|k| k.as_str()).collect::<Vec<_>>();
// anonymous struct is mapped to a tuple
quote!((|v: sp::live_reload::Value| -> sp::Result<_, ()> {
let sp::live_reload::Value::Struct(s) = v else { return sp::Err(()) };
quote!((|v: sp::live_preview::Value| -> sp::Result<_, ()> {
let sp::live_preview::Value::Struct(s) = v else { return sp::Err(()) };
sp::Ok((#(s.get_field(#names).ok_or(())?.clone().try_into().map_err(|_|())?,)*))
}))
}
Type::Array(a) if matches!(a.as_ref(), Type::Struct(s) if s.name.is_none()) => {
let conf_fn = convert_from_value_fn(a.as_ref());
quote!((|v: sp::live_reload::Value| -> sp::Result<_, ()> {
let sp::live_reload::Value::Model(model) = v else { return sp::Err(()) };
quote!((|v: sp::live_preview::Value| -> sp::Result<_, ()> {
let sp::live_preview::Value::Model(model) = v else { return sp::Err(()) };
sp::Ok(sp::ModelRc::new(model.map(|x| #conf_fn(x).unwrap_or_default())))
}))
}
@ -395,16 +395,16 @@ fn generate_value_conversions(used_types: &[Type]) -> TokenStream {
let field_names = fields.keys().map(|k| k.as_str()).collect::<Vec<_>>();
let fields = field_names.iter().map(|k| ident(k)).collect::<Vec<_>>();
Some(quote!{
impl From<#ty> for sp::live_reload::Value {
impl From<#ty> for sp::live_preview::Value {
fn from(_value: #ty) -> Self {
Self::Struct([#((#field_names.to_string(), #convert_to_value(_value.#fields)),)*].into_iter().collect())
}
}
impl TryFrom<sp::live_reload::Value> for #ty {
impl TryFrom<sp::live_preview::Value> for #ty {
type Error = ();
fn try_from(v: sp::live_reload::Value) -> sp::Result<Self, ()> {
fn try_from(v: sp::live_preview::Value) -> sp::Result<Self, ()> {
match v {
sp::live_reload::Value::Struct(_x) => {
sp::live_preview::Value::Struct(_x) => {
sp::Ok(Self {
#(#fields: #convert_from_value(_x.get_field(#field_names).ok_or(())?.clone()).map_err(|_|())?,)*
})
@ -424,7 +424,7 @@ fn generate_value_conversions(used_types: &[Type]) -> TokenStream {
let val_names = en.values.iter().map(|v| v.as_str()).collect::<Vec<_>>();
Some(quote!{
impl From<#ty> for sp::live_reload::Value {
impl From<#ty> for sp::live_preview::Value {
fn from(v: #ty) -> Self {
fn to_string(v: #ty) -> String {
match v {
@ -434,11 +434,11 @@ fn generate_value_conversions(used_types: &[Type]) -> TokenStream {
Self::EnumerationValue(#name.to_owned(), to_string(v))
}
}
impl TryFrom<sp::live_reload::Value> for #ty {
impl TryFrom<sp::live_preview::Value> for #ty {
type Error = ();
fn try_from(v: sp::live_reload::Value) -> sp::Result<Self, ()> {
fn try_from(v: sp::live_preview::Value) -> sp::Result<Self, ()> {
match v {
sp::live_reload::Value::EnumerationValue(enumeration, value) => {
sp::live_preview::Value::EnumerationValue(enumeration, value) => {
if enumeration != #name {
return sp::Err(());
}

View file

@ -131,7 +131,7 @@ internal-highlight = []
internal-json = ["dep:serde_json"]
# (internal)
internal-live-reload = ["dep:notify", "display-diagnostics"]
internal-live-preview = ["dep:notify", "display-diagnostics"]
[dependencies]

View file

@ -88,8 +88,8 @@ mod global_component;
pub mod highlight;
#[cfg(feature = "internal-json")]
pub mod json;
#[cfg(feature = "internal-live-reload")]
pub mod live_reload;
#[cfg(feature = "internal-live-preview")]
pub mod live_preview;
mod value_model;
#[doc(inline)]

View file

@ -314,7 +314,7 @@ mod ffi {
#[unsafe(no_mangle)]
/// LibraryPath is an array of string that have in the form `lib=...`
pub extern "C" fn slint_live_reload_new(
pub extern "C" fn slint_live_preview_new(
file_name: Slice<u8>,
component_name: Slice<u8>,
include_paths: &SharedVector<SharedString>,
@ -346,19 +346,21 @@ mod ffi {
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn slint_live_reload_clone(
pub unsafe extern "C" fn slint_live_preview_clone(
component: *const LiveReloadingComponentInner,
) {
Rc::increment_strong_count(component);
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn slint_live_reload_drop(component: *const LiveReloadingComponentInner) {
pub unsafe extern "C" fn slint_live_preview_drop(
component: *const LiveReloadingComponentInner,
) {
Rc::decrement_strong_count(component);
}
#[unsafe(no_mangle)]
pub extern "C" fn slint_live_reload_set_property(
pub extern "C" fn slint_live_preview_set_property(
component: &LiveReloadingComponentInner,
property: Slice<u8>,
value: &Value,
@ -372,7 +374,7 @@ mod ffi {
}
#[unsafe(no_mangle)]
pub extern "C" fn slint_live_reload_get_property(
pub extern "C" fn slint_live_preview_get_property(
component: &LiveReloadingComponentInner,
property: Slice<u8>,
) -> *mut Value {
@ -386,7 +388,7 @@ mod ffi {
}
#[unsafe(no_mangle)]
pub extern "C" fn slint_live_reload_invoke(
pub extern "C" fn slint_live_preview_invoke(
component: &LiveReloadingComponentInner,
callback: Slice<u8>,
args: Slice<Box<Value>>,
@ -402,7 +404,7 @@ mod ffi {
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn slint_live_reload_set_callback(
pub unsafe extern "C" fn slint_live_preview_set_callback(
component: &LiveReloadingComponentInner,
callback: Slice<u8>,
callback_handler: extern "C" fn(
@ -424,7 +426,7 @@ mod ffi {
/// Same precondition as slint_interpreter_component_instance_window
#[unsafe(no_mangle)]
pub unsafe extern "C" fn slint_live_reload_window(
pub unsafe extern "C" fn slint_live_preview_window(
component: &LiveReloadingComponentInner,
out: *mut *const i_slint_core::window::ffi::WindowAdapterRcOpaque,
) {

View file

@ -5,7 +5,7 @@ use std::io::{BufWriter, Write};
use std::path::Path;
fn main() -> std::io::Result<()> {
let live_reload = std::env::var("SLINT_LIVE_RELOAD").is_ok();
let live_preview = std::env::var("SLINT_LIVE_PREVIEW").is_ok();
let mut generated_file = BufWriter::new(std::fs::File::create(
Path::new(&std::env::var_os("OUT_DIR").unwrap()).join("generated.rs"),
@ -21,17 +21,17 @@ fn main() -> std::io::Result<()> {
let source = std::fs::read_to_string(&testcase.absolute_path)?;
let ignored = if testcase.is_ignored("rust") {
"#[ignore = \"testcase ignored for rust\"]"
} else if (cfg!(not(feature = "build-time")) || live_reload)
} else if (cfg!(not(feature = "build-time")) || live_preview)
&& source.contains("//bundle-translations")
{
"#[ignore = \"translation bundle not working with the macro\"]"
} else if live_reload && source.contains("ComponentContainer") {
} else if live_preview && source.contains("ComponentContainer") {
"#[ignore = \"ComponentContainer doesn't work with the interpreter\"]"
} else if live_reload && source.contains("#3464") {
} else if live_preview && source.contains("#3464") {
"#[ignore = \"issue #3464 not fixed with the interpreter\"]"
} else if live_reload && module_name.contains("widgets_menubar") {
} else if live_preview && module_name.contains("widgets_menubar") {
"#[ignore = \"issue #8454 causes crashes\"]"
} else if live_reload && module_name.contains("write_to_model") {
} else if live_preview && module_name.contains("write_to_model") {
"#[ignore = \"Interpreted model don't forward to underlying models for anonymous structs\"]"
} else {
""
@ -74,7 +74,7 @@ fn main() -> std::io::Result<()> {
// By default resources are embedded. The WASM example builds provide test coverage for that. This switch
// provides test coverage for the non-embedding case, compiling tests without embedding the images.
if !live_reload {
if !live_preview {
println!("cargo:rustc-env=SLINT_EMBED_RESOURCES=false");
}

View file

@ -85,7 +85,7 @@ pub fn generate(show_warnings: bool, experimental: bool) -> Result<(), Box<dyn s
let generated_headers_dir = docs_build_dir.join("generated_include");
let enabled_features = cbindgen::EnabledFeatures {
interpreter: true,
live_reload: false,
live_preview: false,
testing: true,
backend_qt: true,
backend_winit: true,