Add getter/setter for the style

This commit is contained in:
Simon Hausmann 2021-03-19 17:17:57 +01:00
parent 59d6866b13
commit fd9d154b27
3 changed files with 44 additions and 0 deletions

View file

@ -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<sixtyfps::SharedString> include_paths() const
{
sixtyfps::SharedVector<sixtyfps::SharedString> paths;

View file

@ -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!!", "");

View file

@ -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<u8>,
) {
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,