mirror of
https://github.com/slint-ui/slint.git
synced 2025-11-03 05:12:55 +00:00
interpreter: Expose visibility of exported components
This commit is contained in:
parent
2f03bad1cc
commit
b5520ef370
4 changed files with 56 additions and 21 deletions
|
|
@ -46,7 +46,7 @@ impl JsComponentInstance {
|
|||
|
||||
#[napi]
|
||||
pub fn set_property(&self, env: Env, prop_name: String, js_value: JsUnknown) -> Result<()> {
|
||||
let ty = self
|
||||
let (ty, _) = self
|
||||
.inner
|
||||
.definition()
|
||||
.properties_and_callbacks()
|
||||
|
|
@ -88,7 +88,7 @@ impl JsComponentInstance {
|
|||
prop_name: String,
|
||||
js_value: JsUnknown,
|
||||
) -> Result<()> {
|
||||
let ty = self
|
||||
let (ty, _) = self
|
||||
.inner
|
||||
.definition()
|
||||
.global_properties_and_callbacks(global_name.as_str())
|
||||
|
|
@ -121,7 +121,7 @@ impl JsComponentInstance {
|
|||
) -> Result<()> {
|
||||
let function_ref = RefCountedReference::new(&env, callback)?;
|
||||
|
||||
let ty = self
|
||||
let (ty, _) = self
|
||||
.inner
|
||||
.definition()
|
||||
.properties_and_callbacks()
|
||||
|
|
@ -188,7 +188,7 @@ impl JsComponentInstance {
|
|||
) -> Result<()> {
|
||||
let function_ref = RefCountedReference::new(&env, callback)?;
|
||||
|
||||
let ty = self
|
||||
let (ty, _) = self
|
||||
.inner
|
||||
.definition()
|
||||
.global_properties_and_callbacks(global_name.as_str())
|
||||
|
|
@ -283,7 +283,7 @@ impl JsComponentInstance {
|
|||
callback_name: String,
|
||||
callback_arguments: Vec<JsUnknown>,
|
||||
) -> Result<JsUnknown> {
|
||||
let ty = self
|
||||
let (ty, _) = self
|
||||
.inner
|
||||
.definition()
|
||||
.properties_and_callbacks()
|
||||
|
|
@ -321,7 +321,7 @@ impl JsComponentInstance {
|
|||
callback_name: String,
|
||||
callback_arguments: Vec<JsUnknown>,
|
||||
) -> Result<JsUnknown> {
|
||||
let ty = self
|
||||
let (ty, _) = self
|
||||
.inner
|
||||
.definition()
|
||||
.global_properties_and_callbacks(global_name.as_str())
|
||||
|
|
|
|||
|
|
@ -1021,11 +1021,16 @@ impl ComponentDefinition {
|
|||
#[cfg(feature = "internal")]
|
||||
pub fn properties_and_callbacks(
|
||||
&self,
|
||||
) -> impl Iterator<Item = (String, i_slint_compiler::langtype::Type)> + '_ {
|
||||
) -> impl Iterator<
|
||||
Item = (
|
||||
String,
|
||||
(i_slint_compiler::langtype::Type, i_slint_compiler::object_tree::PropertyVisibility),
|
||||
),
|
||||
> + '_ {
|
||||
// We create here a 'static guard, because unfortunately the returned type would be restricted to the guard lifetime
|
||||
// which is not required, but this is safe because there is only one instance of the unerased type
|
||||
let guard = unsafe { generativity::Guard::new(generativity::Id::new()) };
|
||||
self.inner.unerase(guard).properties().map(|(s, t)| (s.to_string(), t))
|
||||
self.inner.unerase(guard).properties().map(|(s, t, v)| (s.to_string(), (t, v)))
|
||||
}
|
||||
|
||||
/// Returns an iterator over all publicly declared properties. Each iterator item is a tuple of property name
|
||||
|
|
@ -1034,7 +1039,7 @@ impl ComponentDefinition {
|
|||
// We create here a 'static guard, because unfortunately the returned type would be restricted to the guard lifetime
|
||||
// which is not required, but this is safe because there is only one instance of the unerased type
|
||||
let guard = unsafe { generativity::Guard::new(generativity::Id::new()) };
|
||||
self.inner.unerase(guard).properties().filter_map(|(prop_name, prop_type)| {
|
||||
self.inner.unerase(guard).properties().filter_map(|(prop_name, prop_type, _)| {
|
||||
if prop_type.is_property_type() {
|
||||
Some((prop_name.to_string(), prop_type.into()))
|
||||
} else {
|
||||
|
|
@ -1048,7 +1053,7 @@ impl ComponentDefinition {
|
|||
// We create here a 'static guard, because unfortunately the returned type would be restricted to the guard lifetime
|
||||
// which is not required, but this is safe because there is only one instance of the unerased type
|
||||
let guard = unsafe { generativity::Guard::new(generativity::Id::new()) };
|
||||
self.inner.unerase(guard).properties().filter_map(|(prop_name, prop_type)| {
|
||||
self.inner.unerase(guard).properties().filter_map(|(prop_name, prop_type, _)| {
|
||||
if matches!(prop_type, LangType::Callback { .. }) {
|
||||
Some(prop_name.to_string())
|
||||
} else {
|
||||
|
|
@ -1062,7 +1067,7 @@ impl ComponentDefinition {
|
|||
// We create here a 'static guard, because unfortunately the returned type would be restricted to the guard lifetime
|
||||
// which is not required, but this is safe because there is only one instance of the unerased type
|
||||
let guard = unsafe { generativity::Guard::new(generativity::Id::new()) };
|
||||
self.inner.unerase(guard).properties().filter_map(|(prop_name, prop_type)| {
|
||||
self.inner.unerase(guard).properties().filter_map(|(prop_name, prop_type, _)| {
|
||||
if matches!(prop_type, LangType::Function { .. }) {
|
||||
Some(prop_name.to_string())
|
||||
} else {
|
||||
|
|
@ -1090,14 +1095,24 @@ impl ComponentDefinition {
|
|||
pub fn global_properties_and_callbacks(
|
||||
&self,
|
||||
global_name: &str,
|
||||
) -> Option<impl Iterator<Item = (String, i_slint_compiler::langtype::Type)> + '_> {
|
||||
) -> Option<
|
||||
impl Iterator<
|
||||
Item = (
|
||||
String,
|
||||
(
|
||||
i_slint_compiler::langtype::Type,
|
||||
i_slint_compiler::object_tree::PropertyVisibility,
|
||||
),
|
||||
),
|
||||
> + '_,
|
||||
> {
|
||||
// We create here a 'static guard, because unfortunately the returned type would be restricted to the guard lifetime
|
||||
// which is not required, but this is safe because there is only one instance of the unerased type
|
||||
let guard = unsafe { generativity::Guard::new(generativity::Id::new()) };
|
||||
self.inner
|
||||
.unerase(guard)
|
||||
.global_properties(global_name)
|
||||
.map(|o| o.map(|(s, t)| (s.to_string(), t)))
|
||||
.map(|o| o.map(|(s, t, v)| (s.to_string(), (t, v))))
|
||||
}
|
||||
|
||||
/// List of publicly declared properties in the exported global singleton specified by its name.
|
||||
|
|
@ -1109,7 +1124,7 @@ impl ComponentDefinition {
|
|||
// which is not required, but this is safe because there is only one instance of the unerased type
|
||||
let guard = unsafe { generativity::Guard::new(generativity::Id::new()) };
|
||||
self.inner.unerase(guard).global_properties(global_name).map(|iter| {
|
||||
iter.filter_map(|(prop_name, prop_type)| {
|
||||
iter.filter_map(|(prop_name, prop_type, _)| {
|
||||
if prop_type.is_property_type() {
|
||||
Some((prop_name.to_string(), prop_type.into()))
|
||||
} else {
|
||||
|
|
@ -1125,7 +1140,7 @@ impl ComponentDefinition {
|
|||
// which is not required, but this is safe because there is only one instance of the unerased type
|
||||
let guard = unsafe { generativity::Guard::new(generativity::Id::new()) };
|
||||
self.inner.unerase(guard).global_properties(global_name).map(|iter| {
|
||||
iter.filter_map(|(prop_name, prop_type)| {
|
||||
iter.filter_map(|(prop_name, prop_type, _)| {
|
||||
if matches!(prop_type, LangType::Callback { .. }) {
|
||||
Some(prop_name.to_string())
|
||||
} else {
|
||||
|
|
@ -1141,7 +1156,7 @@ impl ComponentDefinition {
|
|||
// which is not required, but this is safe because there is only one instance of the unerased type
|
||||
let guard = unsafe { generativity::Guard::new(generativity::Id::new()) };
|
||||
self.inner.unerase(guard).global_properties(global_name).map(|iter| {
|
||||
iter.filter_map(|(prop_name, prop_type)| {
|
||||
iter.filter_map(|(prop_name, prop_type, _)| {
|
||||
if matches!(prop_type, LangType::Function { .. }) {
|
||||
Some(prop_name.to_string())
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -432,7 +432,13 @@ impl PopupMenuDescription {
|
|||
|
||||
fn internal_properties_to_public<'a>(
|
||||
prop_iter: impl Iterator<Item = (&'a SmolStr, &'a PropertyDeclaration)> + 'a,
|
||||
) -> impl Iterator<Item = (SmolStr, i_slint_compiler::langtype::Type)> + 'a {
|
||||
) -> impl Iterator<
|
||||
Item = (
|
||||
SmolStr,
|
||||
i_slint_compiler::langtype::Type,
|
||||
i_slint_compiler::object_tree::PropertyVisibility,
|
||||
),
|
||||
> + 'a {
|
||||
prop_iter.filter(|(_, v)| v.expose_in_public_api).map(|(s, v)| {
|
||||
let name = v
|
||||
.node
|
||||
|
|
@ -443,7 +449,7 @@ fn internal_properties_to_public<'a>(
|
|||
})
|
||||
.map(|n| n.to_smolstr())
|
||||
.unwrap_or_else(|| s.to_smolstr());
|
||||
(name, v.property_type.clone())
|
||||
(name, v.property_type.clone(), v.visibility.clone())
|
||||
})
|
||||
}
|
||||
|
||||
|
|
@ -471,7 +477,13 @@ impl ItemTreeDescription<'_> {
|
|||
/// We try to preserve the dashes and underscore as written in the property declaration
|
||||
pub fn properties(
|
||||
&self,
|
||||
) -> impl Iterator<Item = (SmolStr, i_slint_compiler::langtype::Type)> + '_ {
|
||||
) -> impl Iterator<
|
||||
Item = (
|
||||
SmolStr,
|
||||
i_slint_compiler::langtype::Type,
|
||||
i_slint_compiler::object_tree::PropertyVisibility,
|
||||
),
|
||||
> + '_ {
|
||||
internal_properties_to_public(self.public_properties.iter())
|
||||
}
|
||||
|
||||
|
|
@ -489,7 +501,15 @@ impl ItemTreeDescription<'_> {
|
|||
pub fn global_properties(
|
||||
&self,
|
||||
name: &str,
|
||||
) -> Option<impl Iterator<Item = (SmolStr, i_slint_compiler::langtype::Type)> + '_> {
|
||||
) -> Option<
|
||||
impl Iterator<
|
||||
Item = (
|
||||
SmolStr,
|
||||
i_slint_compiler::langtype::Type,
|
||||
i_slint_compiler::object_tree::PropertyVisibility,
|
||||
),
|
||||
> + '_,
|
||||
> {
|
||||
let g = self.compiled_globals.as_ref().expect("Root component should have globals");
|
||||
g.exported_globals_by_name
|
||||
.get(crate::normalize_identifier(name).as_ref())
|
||||
|
|
|
|||
|
|
@ -344,7 +344,7 @@ fn load_data(
|
|||
let obj = json.as_object().ok_or("The data is not a JSON object")?;
|
||||
for (name, v) in obj {
|
||||
match types.get(name.as_str()) {
|
||||
Some(t) => match slint_interpreter::Value::from_json(t, v) {
|
||||
Some((t, _)) => match slint_interpreter::Value::from_json(t, v) {
|
||||
Ok(v) => match instance.set_property(name, v) {
|
||||
Ok(()) => (),
|
||||
Err(e) => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue