diff --git a/api/sixtyfps-cpp/include/sixtyfps_interpreter.h b/api/sixtyfps-cpp/include/sixtyfps_interpreter.h index 32af3829d..2e5ff9a5a 100644 --- a/api/sixtyfps-cpp/include/sixtyfps_interpreter.h +++ b/api/sixtyfps-cpp/include/sixtyfps_interpreter.h @@ -469,6 +469,19 @@ public: cbindgen_private::sixtyfps_interpreter_component_compiler_set_include_paths(&inner, &paths); } + void set_style(std::string_view style) + { + cbindgen_private::sixtyfps_interpreter_component_compiler_set_style( + &inner, sixtyfps::private_api::string_to_slice(style)); + } + + sixtyfps::SharedString style() const + { + sixtyfps::SharedString s; + cbindgen_private::sixtyfps_interpreter_component_compiler_get_style(&inner, &s); + return s; + } + sixtyfps::SharedVector include_paths() const { sixtyfps::SharedVector paths; diff --git a/api/sixtyfps-cpp/tests/tests.cpp b/api/sixtyfps-cpp/tests/tests.cpp index e17141e55..744c492c4 100644 --- a/api/sixtyfps-cpp/tests/tests.cpp +++ b/api/sixtyfps-cpp/tests/tests.cpp @@ -259,6 +259,13 @@ SCENARIO("Component Compiler") REQUIRE(out_paths[1] == "path2"); } + SECTION("configure style") + { + REQUIRE(compiler.style() == ""); + compiler.set_style("ugly"); + REQUIRE(compiler.style() == "ugly"); + } + SECTION("Compile failure from source") { auto result = compiler.build_from_source("Syntax Error!!", ""); diff --git a/sixtyfps_runtime/interpreter/api.rs b/sixtyfps_runtime/interpreter/api.rs index afa292be7..739518fb0 100644 --- a/sixtyfps_runtime/interpreter/api.rs +++ b/sixtyfps_runtime/interpreter/api.rs @@ -368,6 +368,11 @@ impl ComponentCompiler { self.config.style = Some(style); } + /// Returns the style the compiler is currently using when compiling .60 files. + pub fn style(&self) -> Option<&String> { + self.config.style.as_ref() + } + /// Create a new configuration that will use the provided callback for loading. pub fn set_file_loader( &mut self, @@ -1295,6 +1300,25 @@ pub(crate) mod ffi { .set_include_paths(paths.iter().map(|path| path.as_str().into()).collect()) } + #[no_mangle] + pub unsafe extern "C" fn sixtyfps_interpreter_component_compiler_set_style( + compiler: &mut ComponentCompilerOpaque, + style: Slice, + ) { + compiler + .as_component_compiler_mut() + .set_style(std::str::from_utf8(&style).unwrap().to_string()) + } + + #[no_mangle] + pub unsafe extern "C" fn sixtyfps_interpreter_component_compiler_get_style( + compiler: &ComponentCompilerOpaque, + style_out: &mut SharedString, + ) { + *style_out = + compiler.as_component_compiler().style().map_or(SharedString::default(), |s| s.into()); + } + #[no_mangle] pub unsafe extern "C" fn sixtyfps_interpreter_component_compiler_get_include_paths( compiler: &ComponentCompilerOpaque,