From 88c0323e6ca4c887f2a6cf6a2d80f453656f7611 Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Thu, 28 Aug 2025 15:46:32 +0200 Subject: [PATCH] Rename "Live Reload" feature to "Live Preview for Rust/C++" --- .github/workflows/ci.yaml | 6 +-- CHANGELOG.md | 4 +- api/cpp/CMakeLists.txt | 2 +- api/cpp/Cargo.toml | 2 +- api/cpp/cbindgen.rs | 2 +- api/cpp/include/slint-interpreter.h | 6 +-- api/cpp/include/slint_live_reload.h | 34 ++++++------ api/rs/build/lib.rs | 2 +- api/rs/slint/Cargo.toml | 10 ++-- api/rs/slint/private_unstable_api.rs | 4 +- internal/compiler/generator.rs | 4 +- internal/compiler/generator/cpp.rs | 4 +- ...cpp_live_reload.rs => cpp_live_preview.rs} | 54 +++++++++---------- internal/compiler/generator/rust.rs | 4 +- ...st_live_reload.rs => rust_live_preview.rs} | 42 +++++++-------- internal/interpreter/Cargo.toml | 2 +- internal/interpreter/lib.rs | 4 +- .../{live_reload.rs => live_preview.rs} | 18 ++++--- tests/driver/rust/build.rs | 14 ++--- xtask/src/cppdocs.rs | 2 +- 20 files changed, 111 insertions(+), 109 deletions(-) rename internal/compiler/generator/{cpp_live_reload.rs => cpp_live_preview.rs} (89%) rename internal/compiler/generator/{rust_live_reload.rs => rust_live_preview.rs} (92%) rename internal/interpreter/{live_reload.rs => live_preview.rs} (97%) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 438f5c32a..deae7b453 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -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() }} diff --git a/CHANGELOG.md b/CHANGELOG.md index 9ce343883..c6e677c23 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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` and `Extend` 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 diff --git a/api/cpp/CMakeLists.txt b/api/cpp/CMakeLists.txt index 24baeab84..b64b5f1d8 100644 --- a/api/cpp/CMakeLists.txt +++ b/api/cpp/CMakeLists.txt @@ -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") diff --git a/api/cpp/Cargo.toml b/api/cpp/Cargo.toml index aaef3f70b..b69015596 100644 --- a/api/cpp/Cargo.toml +++ b/api/cpp/Cargo.toml @@ -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"] diff --git a/api/cpp/cbindgen.rs b/api/cpp/cbindgen.rs index 7a05dee04..90149769e 100644 --- a/api/cpp/cbindgen.rs +++ b/api/cpp/cbindgen.rs @@ -986,7 +986,7 @@ macro_rules! declare_features { declare_features! { interpreter - live_reload + live_preview testing backend_qt backend_winit diff --git a/api/cpp/include/slint-interpreter.h b/api/cpp/include/slint-interpreter.h index 978f10b85..efdf1939e 100644 --- a/api/cpp/include/slint-interpreter.h +++ b/api/cpp/include/slint-interpreter.h @@ -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) { } }; diff --git a/api/cpp/include/slint_live_reload.h b/api/cpp/include/slint_live_reload.h index 8669d3320..64ac6acd5 100644 --- a/api/cpp/include/slint_live_reload.h +++ b/api/cpp/include/slint_live_reload.h @@ -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 requires(std::convertible_to) @@ -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 args_slice { reinterpret_cast(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(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(*reinterpret_cast(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 diff --git a/api/rs/build/lib.rs b/api/rs/build/lib.rs index 228283f09..fc525799c 100644 --- a/api/rs/build/lib.rs +++ b/api/rs/build/lib.rs @@ -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={}", diff --git a/api/rs/slint/Cargo.toml b/api/rs/slint/Cargo.toml index 642c1db1b..ed0c601eb 100644 --- a/api/rs/slint/Cargo.toml +++ b/api/rs/slint/Cargo.toml @@ -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 } diff --git a/api/rs/slint/private_unstable_api.rs b/api/rs/slint/private_unstable_api.rs index f7ea9572b..5a9652f18 100644 --- a/api/rs/slint/private_unstable_api.rs +++ b/api/rs/slint/private_unstable_api.rs @@ -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; } diff --git a/internal/compiler/generator.rs b/internal/compiler/generator.rs index e48065dcc..f957178a0 100644 --- a/internal/compiler/generator.rs +++ b/internal/compiler/generator.rs @@ -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 { diff --git a/internal/compiler/generator/cpp.rs b/internal/compiler/generator/cpp.rs index 48d9d1104..1c5fa10da 100644 --- a/internal/compiler/generator/cpp.rs +++ b/internal/compiler/generator/cpp.rs @@ -681,8 +681,8 @@ pub fn generate( config: Config, compiler_config: &CompilerConfiguration, ) -> std::io::Result { - 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); diff --git a/internal/compiler/generator/cpp_live_reload.rs b/internal/compiler/generator/cpp_live_preview.rs similarity index 89% rename from internal/compiler/generator/cpp_live_reload.rs rename to internal/compiler/generator/cpp_live_preview.rs index e4ca27f18..8294867f4 100644 --- a/internal/compiler/generator/cpp_live_reload.rs +++ b/internal/compiler/generator/cpp_live_preview.rs @@ -17,7 +17,7 @@ pub fn generate( ) -> std::io::Result { let mut file = super::cpp::generate_types(&doc.used_types.borrow().structs_and_enums, &config); - file.includes.push("".into()); + file.includes.push("".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) {{ return T(live_reload); }}", + "{0}if constexpr(std::is_same_v) {{ 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 include_paths{{ {} }};", compiler_config.include_paths.iter().map(|p| format!("\"{}\"", escape_string(&p.to_string_lossy()))).join(", ")), format!("slint::SharedVector 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::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::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::>(); 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::>(); 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 = 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 = 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()); diff --git a/internal/compiler/generator/rust.rs b/internal/compiler/generator/rust.rs index f88faee3f..16374b9ad 100644 --- a/internal/compiler/generator/rust.rs +++ b/internal/compiler/generator/rust.rs @@ -156,8 +156,8 @@ pub fn generate( doc: &Document, compiler_config: &CompilerConfiguration, ) -> std::io::Result { - 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) = diff --git a/internal/compiler/generator/rust_live_reload.rs b/internal/compiler/generator/rust_live_preview.rs similarity index 92% rename from internal/compiler/generator/rust_live_reload.rs rename to internal/compiler/generator/rust_live_preview.rs index ceadfc70a..f400501e5 100644 --- a/internal/compiler/generator/rust_live_reload.rs +++ b/internal/compiler/generator/rust_live_preview.rs @@ -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::Rc); + pub struct #public_component_id(sp::Rc<::core::cell::RefCell>, sp::Rc); impl #public_component_id { pub fn new() -> sp::Result { - 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>; + type WeakInner = sp::Weak<::core::cell::RefCell>; fn as_weak(&self) -> slint::Weak { 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 ::core::convert::From<#public_component_id> for sp::VRc - where Self : ::core::convert::From + where Self : ::core::convert::From { 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); + pub struct #public_component_id<'a>(&'a ::core::cell::RefCell); 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::>(); let fields = names.iter().map(|k| ident(k)).collect::>(); 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::>(); // 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::>(); let fields = field_names.iter().map(|k| ident(k)).collect::>(); 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 for #ty { + impl TryFrom for #ty { type Error = (); - fn try_from(v: sp::live_reload::Value) -> sp::Result { + fn try_from(v: sp::live_preview::Value) -> sp::Result { 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::>(); 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 for #ty { + impl TryFrom for #ty { type Error = (); - fn try_from(v: sp::live_reload::Value) -> sp::Result { + fn try_from(v: sp::live_preview::Value) -> sp::Result { match v { - sp::live_reload::Value::EnumerationValue(enumeration, value) => { + sp::live_preview::Value::EnumerationValue(enumeration, value) => { if enumeration != #name { return sp::Err(()); } diff --git a/internal/interpreter/Cargo.toml b/internal/interpreter/Cargo.toml index 5ba9ffbf9..8e399b99a 100644 --- a/internal/interpreter/Cargo.toml +++ b/internal/interpreter/Cargo.toml @@ -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] diff --git a/internal/interpreter/lib.rs b/internal/interpreter/lib.rs index c20af23fb..80672394f 100644 --- a/internal/interpreter/lib.rs +++ b/internal/interpreter/lib.rs @@ -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)] diff --git a/internal/interpreter/live_reload.rs b/internal/interpreter/live_preview.rs similarity index 97% rename from internal/interpreter/live_reload.rs rename to internal/interpreter/live_preview.rs index ee395c6d8..8463ecbf3 100644 --- a/internal/interpreter/live_reload.rs +++ b/internal/interpreter/live_preview.rs @@ -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, component_name: Slice, include_paths: &SharedVector, @@ -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, 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, ) -> *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, args: Slice>, @@ -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, 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, ) { diff --git a/tests/driver/rust/build.rs b/tests/driver/rust/build.rs index 2b7f3e10a..061a7c107 100644 --- a/tests/driver/rust/build.rs +++ b/tests/driver/rust/build.rs @@ -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"); } diff --git a/xtask/src/cppdocs.rs b/xtask/src/cppdocs.rs index 23c462a10..073563cc8 100644 --- a/xtask/src/cppdocs.rs +++ b/xtask/src/cppdocs.rs @@ -85,7 +85,7 @@ pub fn generate(show_warnings: bool, experimental: bool) -> Result<(), Box