mirror of
https://github.com/slint-ui/slint.git
synced 2025-10-01 06:11:16 +00:00
Make ComponentDefinition::properties only list the public properties as it should
Fixes #242
This commit is contained in:
parent
ea8e8318b6
commit
236011d17c
4 changed files with 47 additions and 2 deletions
|
@ -22,6 +22,7 @@ All notable changes to this project will be documented in this file.
|
||||||
|
|
||||||
- Fixed C++ backend on windows
|
- Fixed C++ backend on windows
|
||||||
- `debug(...)` no longer break the LSP
|
- `debug(...)` no longer break the LSP
|
||||||
|
- ComponentDefinition::properties only expose public properties as documented
|
||||||
- Many more bugfixes
|
- Many more bugfixes
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -314,6 +314,23 @@ SCENARIO("Component Definition Properties")
|
||||||
REQUIRE(properties[0].property_type == Value::Type::String);
|
REQUIRE(properties[0].property_type == Value::Type::String);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SCENARIO("Component Definition Properties / Two-way bindings")
|
||||||
|
{
|
||||||
|
using namespace sixtyfps::interpreter;
|
||||||
|
using namespace sixtyfps;
|
||||||
|
|
||||||
|
ComponentCompiler compiler;
|
||||||
|
auto comp_def = *compiler.build_from_source(
|
||||||
|
"export Dummy := Rectangle { property <string> test <=> sub_object.test; "
|
||||||
|
" sub_object := Rectangle { property <string> test; }"
|
||||||
|
"}",
|
||||||
|
"");
|
||||||
|
auto properties = comp_def.properties();
|
||||||
|
REQUIRE(properties.size() == 1);
|
||||||
|
REQUIRE(properties[0].property_name == "test");
|
||||||
|
REQUIRE(properties[0].property_type == Value::Type::String);
|
||||||
|
}
|
||||||
|
|
||||||
SCENARIO("Invoke callback")
|
SCENARIO("Invoke callback")
|
||||||
{
|
{
|
||||||
using namespace sixtyfps::interpreter;
|
using namespace sixtyfps::interpreter;
|
||||||
|
|
|
@ -909,6 +909,30 @@ fn component_definition_properties() {
|
||||||
assert_eq!(props[0].1, ValueType::String);
|
assert_eq!(props[0].1, ValueType::String);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn component_definition_properties2() {
|
||||||
|
let mut compiler = ComponentCompiler::new();
|
||||||
|
let comp_def = spin_on::spin_on(
|
||||||
|
compiler.build_from_source(
|
||||||
|
r#"
|
||||||
|
export Dummy := Rectangle {
|
||||||
|
property <string> sub-text <=> sub.text;
|
||||||
|
sub := Text { property <int> private-not-exported; }
|
||||||
|
callback hello;
|
||||||
|
}"#
|
||||||
|
.into(),
|
||||||
|
"".into(),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let props = comp_def.properties().collect::<Vec<(_, _)>>();
|
||||||
|
|
||||||
|
assert_eq!(props.len(), 1);
|
||||||
|
assert_eq!(props[0].0, "sub_text");
|
||||||
|
assert_eq!(props[0].1, ValueType::String);
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(feature = "ffi")]
|
#[cfg(feature = "ffi")]
|
||||||
#[allow(missing_docs)]
|
#[allow(missing_docs)]
|
||||||
#[path = "ffi.rs"]
|
#[path = "ffi.rs"]
|
||||||
|
|
|
@ -313,8 +313,11 @@ impl<'id> ComponentDescription<'id> {
|
||||||
/// List of publicly declared properties or callbacks
|
/// List of publicly declared properties or callbacks
|
||||||
pub fn properties(
|
pub fn properties(
|
||||||
&self,
|
&self,
|
||||||
) -> impl ExactSizeIterator<Item = (String, sixtyfps_compilerlib::langtype::Type)> + '_ {
|
) -> impl Iterator<Item = (String, sixtyfps_compilerlib::langtype::Type)> + '_ {
|
||||||
self.public_properties.iter().map(|(s, v)| (s.clone(), v.property_type.clone()))
|
self.public_properties
|
||||||
|
.iter()
|
||||||
|
.filter(|(_, v)| v.expose_in_public_api)
|
||||||
|
.map(|(s, v)| (s.clone(), v.property_type.clone()))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Instantiate a runtime component from this ComponentDescription
|
/// Instantiate a runtime component from this ComponentDescription
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue