mirror of
https://github.com/slint-ui/slint.git
synced 2025-11-02 04:48:27 +00:00
Auto-fixed clippy::unnecessary_map_or
This is a hacky approach, but does help a lot with the tedious fixes. See https://rust-lang.github.io/rust-clippy/master/index.html#/unnecessary_map_or ``` __CARGO_FIX_YOLO=1 cargo clippy --fix --all-targets --workspace --exclude gstreamer-player --exclude i-slint-backend-linuxkms --exclude uefi-demo --exclude ffmpeg -- -A clippy::all -W clippy::unnecessary_map_or cargo fmt --all ```
This commit is contained in:
parent
4ae2627ade
commit
bcb2953f00
61 changed files with 145 additions and 163 deletions
|
|
@ -192,7 +192,7 @@ fn ensure_cargo_rerun_for_crate(
|
||||||
dependencies.push(crate_dir.to_path_buf());
|
dependencies.push(crate_dir.to_path_buf());
|
||||||
for entry in std::fs::read_dir(crate_dir)? {
|
for entry in std::fs::read_dir(crate_dir)? {
|
||||||
let entry = entry?;
|
let entry = entry?;
|
||||||
if entry.path().extension().map_or(false, |e| e == "rs") {
|
if entry.path().extension().is_some_and(|e| e == "rs") {
|
||||||
dependencies.push(entry.path());
|
dependencies.push(entry.path());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -162,7 +162,7 @@ impl i_slint_renderer_skia::software_surface::RenderBuffer for SkiaTestSoftwareB
|
||||||
|
|
||||||
let mut shared_pixel_buffer = self.pixels.borrow_mut().take();
|
let mut shared_pixel_buffer = self.pixels.borrow_mut().take();
|
||||||
|
|
||||||
if shared_pixel_buffer.as_ref().map_or(false, |existing_buffer| {
|
if shared_pixel_buffer.as_ref().is_some_and(|existing_buffer| {
|
||||||
existing_buffer.width() != width.get() || existing_buffer.height() != height.get()
|
existing_buffer.width() != width.get() || existing_buffer.height() != height.get()
|
||||||
}) {
|
}) {
|
||||||
shared_pixel_buffer = None;
|
shared_pixel_buffer = None;
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ fn main() {
|
||||||
println!("cargo:rustc-check-cfg=cfg(no_qt)");
|
println!("cargo:rustc-check-cfg=cfg(no_qt)");
|
||||||
|
|
||||||
println!("cargo:rerun-if-env-changed=SLINT_NO_QT");
|
println!("cargo:rerun-if-env-changed=SLINT_NO_QT");
|
||||||
if std::env::var("TARGET").map_or(false, |t| t.starts_with("wasm"))
|
if std::env::var("TARGET").is_ok_and(|t| t.starts_with("wasm"))
|
||||||
|| std::env::var("SLINT_NO_QT").is_ok()
|
|| std::env::var("SLINT_NO_QT").is_ok()
|
||||||
{
|
{
|
||||||
println!("cargo:rustc-cfg=no_qt");
|
println!("cargo:rustc-cfg=no_qt");
|
||||||
|
|
|
||||||
|
|
@ -51,31 +51,29 @@ impl SingleElementMatch {
|
||||||
fn matches(&self, element: &ElementHandle) -> bool {
|
fn matches(&self, element: &ElementHandle) -> bool {
|
||||||
match self {
|
match self {
|
||||||
SingleElementMatch::MatchById { id, root_base } => {
|
SingleElementMatch::MatchById { id, root_base } => {
|
||||||
if element.id().map_or(false, |candidate_id| candidate_id == id) {
|
if element.id().is_some_and(|candidate_id| candidate_id == id) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
root_base.as_ref().map_or(false, |root_base| {
|
root_base.as_ref().is_some_and(|root_base| {
|
||||||
element
|
element
|
||||||
.type_name()
|
.type_name()
|
||||||
.map_or(false, |type_name_candidate| type_name_candidate == root_base)
|
.is_some_and(|type_name_candidate| type_name_candidate == root_base)
|
||||||
|| element
|
|| element
|
||||||
.bases()
|
.bases()
|
||||||
.map_or(false, |mut bases| bases.any(|base| base == root_base))
|
.is_some_and(|mut bases| bases.any(|base| base == root_base))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
SingleElementMatch::MatchByTypeName(type_name) => element
|
SingleElementMatch::MatchByTypeName(type_name) => element
|
||||||
.type_name()
|
.type_name()
|
||||||
.map_or(false, |candidate_type_name| candidate_type_name == type_name),
|
.is_some_and(|candidate_type_name| candidate_type_name == type_name),
|
||||||
SingleElementMatch::MatchByTypeNameOrBase(type_name) => {
|
SingleElementMatch::MatchByTypeNameOrBase(type_name) => {
|
||||||
element
|
element
|
||||||
.type_name()
|
.type_name()
|
||||||
.map_or(false, |candidate_type_name| candidate_type_name == type_name)
|
.is_some_and(|candidate_type_name| candidate_type_name == type_name)
|
||||||
|| element
|
|| element.bases().is_some_and(|mut bases| bases.any(|base| base == type_name))
|
||||||
.bases()
|
|
||||||
.map_or(false, |mut bases| bases.any(|base| base == type_name))
|
|
||||||
}
|
}
|
||||||
SingleElementMatch::MatchByAccessibleRole(role) => {
|
SingleElementMatch::MatchByAccessibleRole(role) => {
|
||||||
element.accessible_role().map_or(false, |candidate_role| candidate_role == *role)
|
element.accessible_role() == Some(*role)
|
||||||
}
|
}
|
||||||
SingleElementMatch::MatchByPredicate(predicate) => (predicate)(element),
|
SingleElementMatch::MatchByPredicate(predicate) => (predicate)(element),
|
||||||
}
|
}
|
||||||
|
|
@ -285,7 +283,7 @@ impl ElementHandle {
|
||||||
.root_element()
|
.root_element()
|
||||||
.query_descendants()
|
.query_descendants()
|
||||||
.match_predicate(move |elem| {
|
.match_predicate(move |elem| {
|
||||||
elem.accessible_label().map_or(false, |candidate_label| candidate_label == label)
|
elem.accessible_label().is_some_and(|candidate_label| candidate_label == label)
|
||||||
})
|
})
|
||||||
.find_all();
|
.find_all();
|
||||||
results.into_iter()
|
results.into_iter()
|
||||||
|
|
|
||||||
|
|
@ -262,7 +262,7 @@ impl NodeCollection {
|
||||||
window_adapter_weak
|
window_adapter_weak
|
||||||
.upgrade()
|
.upgrade()
|
||||||
.filter(|window_adapter| {
|
.filter(|window_adapter| {
|
||||||
window_adapter.winit_window().map_or(false, |winit_window| winit_window.has_focus())
|
window_adapter.winit_window().is_some_and(|winit_window| winit_window.has_focus())
|
||||||
})
|
})
|
||||||
.and_then(|window_adapter| {
|
.and_then(|window_adapter| {
|
||||||
let window_inner = WindowInner::from_pub(window_adapter.window());
|
let window_inner = WindowInner::from_pub(window_adapter.window());
|
||||||
|
|
|
||||||
|
|
@ -606,7 +606,7 @@ impl WinitWindowAccessor for i_slint_core::api::Window {
|
||||||
.window_adapter()
|
.window_adapter()
|
||||||
.internal(i_slint_core::InternalToken)
|
.internal(i_slint_core::InternalToken)
|
||||||
.and_then(|wa| wa.as_any().downcast_ref::<WinitWindowAdapter>())
|
.and_then(|wa| wa.as_any().downcast_ref::<WinitWindowAdapter>())
|
||||||
.map_or(false, |adapter| adapter.winit_window().is_some())
|
.is_some_and(|adapter| adapter.winit_window().is_some())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn with_winit_window<T>(
|
fn with_winit_window<T>(
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ fn widget_library() -> &'static [(&'static str, &'static BuiltinDirectory<'stati
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
for style in cargo_manifest_dir.join(&library_dir).read_dir()?.filter_map(Result::ok) {
|
for style in cargo_manifest_dir.join(&library_dir).read_dir()?.filter_map(Result::ok) {
|
||||||
if !style.file_type().map_or(false, |f| f.is_dir()) {
|
if !style.file_type().is_ok_and(|f| f.is_dir()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
let path = style.path();
|
let path = style.path();
|
||||||
|
|
@ -50,7 +50,7 @@ fn process_style(cargo_manifest_dir: &Path, path: &Path) -> std::io::Result<Stri
|
||||||
.read_dir()?
|
.read_dir()?
|
||||||
.filter_map(Result::ok)
|
.filter_map(Result::ok)
|
||||||
.filter(|entry| {
|
.filter(|entry| {
|
||||||
entry.file_type().map_or(false, |f| !f.is_dir())
|
entry.file_type().is_ok_and(|f| !f.is_dir())
|
||||||
&& entry
|
&& entry
|
||||||
.path()
|
.path()
|
||||||
.extension()
|
.extension()
|
||||||
|
|
|
||||||
|
|
@ -173,7 +173,7 @@ pub fn load_from_path(path: &Path) -> Result<String, Diagnostic> {
|
||||||
level: DiagnosticLevel::Error,
|
level: DiagnosticLevel::Error,
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
if path.extension().map_or(false, |e| e == "rs") {
|
if path.extension().is_some_and(|e| e == "rs") {
|
||||||
return crate::lexer::extract_rust_macro(string).ok_or_else(|| Diagnostic {
|
return crate::lexer::extract_rust_macro(string).ok_or_else(|| Diagnostic {
|
||||||
message: "No `slint!` macro".into(),
|
message: "No `slint!` macro".into(),
|
||||||
span: SourceLocation {
|
span: SourceLocation {
|
||||||
|
|
|
||||||
|
|
@ -1357,7 +1357,7 @@ impl Expression {
|
||||||
.property_analysis
|
.property_analysis
|
||||||
.borrow()
|
.borrow()
|
||||||
.get(nr.name())
|
.get(nr.name())
|
||||||
.map_or(false, |d| d.is_linked_to_read_only)
|
.is_some_and(|d| d.is_linked_to_read_only)
|
||||||
{
|
{
|
||||||
true
|
true
|
||||||
} else if ctx.is_legacy_component() {
|
} else if ctx.is_legacy_component() {
|
||||||
|
|
|
||||||
|
|
@ -410,7 +410,7 @@ pub fn handle_property_bindings_init(
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
processed.insert(nr);
|
processed.insert(nr);
|
||||||
if binding_expression.analysis.as_ref().map_or(false, |a| a.is_const) {
|
if binding_expression.analysis.as_ref().is_some_and(|a| a.is_const) {
|
||||||
// We must first handle all dependent properties in case it is a constant property
|
// We must first handle all dependent properties in case it is a constant property
|
||||||
|
|
||||||
binding_expression.expression.visit_recursive(&mut |e| {
|
binding_expression.expression.visit_recursive(&mut |e| {
|
||||||
|
|
@ -468,7 +468,7 @@ pub fn for_each_const_properties(
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|(_, x)| {
|
.filter(|(_, x)| {
|
||||||
x.property_type.is_property_type() &&
|
x.property_type.is_property_type() &&
|
||||||
!matches!( &x.property_type, crate::langtype::Type::Struct(s) if s.name.as_ref().map_or(false, |name| name.ends_with("::StateInfo")))
|
!matches!( &x.property_type, crate::langtype::Type::Struct(s) if s.name.as_ref().is_some_and(|name| name.ends_with("::StateInfo")))
|
||||||
})
|
})
|
||||||
.map(|(k, _)| k.clone()),
|
.map(|(k, _)| k.clone()),
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -277,7 +277,7 @@ fn lower_sub_component(
|
||||||
|
|
||||||
if let Some(parent) = component.parent_element.upgrade() {
|
if let Some(parent) = component.parent_element.upgrade() {
|
||||||
// Add properties for the model data and index
|
// Add properties for the model data and index
|
||||||
if parent.borrow().repeated.as_ref().map_or(false, |x| !x.is_conditional_element) {
|
if parent.borrow().repeated.as_ref().is_some_and(|x| !x.is_conditional_element) {
|
||||||
sub_component.properties.push(Property {
|
sub_component.properties.push(Property {
|
||||||
name: "model_data".into(),
|
name: "model_data".into(),
|
||||||
ty: crate::expression_tree::Expression::RepeaterModelReference {
|
ty: crate::expression_tree::Expression::RepeaterModelReference {
|
||||||
|
|
@ -429,7 +429,7 @@ fn lower_sub_component(
|
||||||
let expression =
|
let expression =
|
||||||
super::lower_expression::lower_expression(&binding.expression, &mut ctx).into();
|
super::lower_expression::lower_expression(&binding.expression, &mut ctx).into();
|
||||||
|
|
||||||
let is_constant = binding.analysis.as_ref().map_or(false, |a| a.is_const);
|
let is_constant = binding.analysis.as_ref().is_some_and(|a| a.is_const);
|
||||||
let animation = binding
|
let animation = binding
|
||||||
.animation
|
.animation
|
||||||
.as_ref()
|
.as_ref()
|
||||||
|
|
@ -446,7 +446,7 @@ fn lower_sub_component(
|
||||||
|
|
||||||
let is_state_info = matches!(
|
let is_state_info = matches!(
|
||||||
e.borrow().lookup_property(p).property_type,
|
e.borrow().lookup_property(p).property_type,
|
||||||
Type::Struct(s) if s.name.as_ref().map_or(false, |name| name.ends_with("::StateInfo"))
|
Type::Struct(s) if s.name.as_ref().is_some_and(|name| name.ends_with("::StateInfo"))
|
||||||
);
|
);
|
||||||
|
|
||||||
sub_component.property_init.push((
|
sub_component.property_init.push((
|
||||||
|
|
@ -640,7 +640,7 @@ fn get_property_analysis(elem: &ElementRc, p: &str) -> crate::object_tree::Prope
|
||||||
let base = elem.borrow().base_type.clone();
|
let base = elem.borrow().base_type.clone();
|
||||||
match base {
|
match base {
|
||||||
ElementType::Native(n) => {
|
ElementType::Native(n) => {
|
||||||
if n.properties.get(p).map_or(false, |p| p.is_native_output()) {
|
if n.properties.get(p).is_some_and(|p| p.is_native_output()) {
|
||||||
a.is_set = true;
|
a.is_set = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -892,7 +892,7 @@ fn lower_global_expressions(
|
||||||
}
|
}
|
||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
};
|
};
|
||||||
let is_constant = binding.borrow().analysis.as_ref().map_or(false, |a| a.is_const);
|
let is_constant = binding.borrow().analysis.as_ref().is_some_and(|a| a.is_const);
|
||||||
lowered.init_values[property_index] = Some(BindingExpression {
|
lowered.init_values[property_index] = Some(BindingExpression {
|
||||||
expression: expression.into(),
|
expression: expression.into(),
|
||||||
animation: None,
|
animation: None,
|
||||||
|
|
|
||||||
|
|
@ -147,7 +147,7 @@ pub(crate) fn load_builtins(register: &mut TypeRegister) {
|
||||||
Global,
|
Global,
|
||||||
NativeParent(Rc<BuiltinElement>),
|
NativeParent(Rc<BuiltinElement>),
|
||||||
}
|
}
|
||||||
let base = if c.child_text(SyntaxKind::Identifier).map_or(false, |t| t == "global") {
|
let base = if c.child_text(SyntaxKind::Identifier).is_some_and(|t| t == "global") {
|
||||||
Base::Global
|
Base::Global
|
||||||
} else if let Some(base) = e.QualifiedName() {
|
} else if let Some(base) = e.QualifiedName() {
|
||||||
let base = QualifiedTypeName::from_node(base).to_smolstr();
|
let base = QualifiedTypeName::from_node(base).to_smolstr();
|
||||||
|
|
|
||||||
|
|
@ -71,7 +71,7 @@ impl<'a> LookupCtx<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_legacy_component(&self) -> bool {
|
pub fn is_legacy_component(&self) -> bool {
|
||||||
self.component_scope.first().map_or(false, |e| e.borrow().is_legacy_syntax)
|
self.component_scope.first().is_some_and(|e| e.borrow().is_legacy_syntax)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// True if the element is in the same component as the scope
|
/// True if the element is in the same component as the scope
|
||||||
|
|
@ -535,7 +535,7 @@ impl LookupType {
|
||||||
if c.root_element
|
if c.root_element
|
||||||
.borrow()
|
.borrow()
|
||||||
.builtin_type()
|
.builtin_type()
|
||||||
.map_or(false, |x| x.is_internal && x.name == name)
|
.is_some_and(|x| x.is_internal && x.name == name)
|
||||||
&& !ctx.type_register.expose_internal_types
|
&& !ctx.type_register.expose_internal_types
|
||||||
{
|
{
|
||||||
None
|
None
|
||||||
|
|
|
||||||
|
|
@ -76,20 +76,20 @@ impl NamedReference {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if e.property_analysis.borrow().get(self.name()).map_or(false, |a| a.is_set_externally) {
|
if e.property_analysis.borrow().get(self.name()).is_some_and(|a| a.is_set_externally) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
drop(e);
|
drop(e);
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
let e = elem.borrow();
|
let e = elem.borrow();
|
||||||
if e.property_analysis.borrow().get(self.name()).map_or(false, |a| a.is_set) {
|
if e.property_analysis.borrow().get(self.name()).is_some_and(|a| a.is_set) {
|
||||||
// if the property is set somewhere, it is not constant
|
// if the property is set somewhere, it is not constant
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(b) = e.bindings.get(self.name()) {
|
if let Some(b) = e.bindings.get(self.name()) {
|
||||||
if check_binding && !b.borrow().analysis.as_ref().map_or(false, |a| a.is_const) {
|
if check_binding && !b.borrow().analysis.as_ref().is_some_and(|a| a.is_const) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if !b.borrow().two_way_bindings.iter().all(|n| n.is_constant()) {
|
if !b.borrow().two_way_bindings.iter().all(|n| n.is_constant()) {
|
||||||
|
|
|
||||||
|
|
@ -414,7 +414,7 @@ impl Component {
|
||||||
root_element: Element::from_node(
|
root_element: Element::from_node(
|
||||||
node.Element(),
|
node.Element(),
|
||||||
"root".into(),
|
"root".into(),
|
||||||
if node.child_text(SyntaxKind::Identifier).map_or(false, |t| t == "global") {
|
if node.child_text(SyntaxKind::Identifier).is_some_and(|t| t == "global") {
|
||||||
ElementType::Global
|
ElementType::Global
|
||||||
} else {
|
} else {
|
||||||
ElementType::Error
|
ElementType::Error
|
||||||
|
|
@ -790,7 +790,7 @@ pub fn pretty_print(
|
||||||
indent!();
|
indent!();
|
||||||
write!(f, "{name}: ")?;
|
write!(f, "{name}: ")?;
|
||||||
expression_tree::pretty_print(f, &expr.expression)?;
|
expression_tree::pretty_print(f, &expr.expression)?;
|
||||||
if expr.analysis.as_ref().map_or(false, |a| a.is_const) {
|
if expr.analysis.as_ref().is_some_and(|a| a.is_const) {
|
||||||
write!(f, "/*const*/")?;
|
write!(f, "/*const*/")?;
|
||||||
}
|
}
|
||||||
writeln!(f, ";")?;
|
writeln!(f, ";")?;
|
||||||
|
|
@ -959,13 +959,12 @@ impl Element {
|
||||||
node.States().for_each(|n| error_on(&n, "states"));
|
node.States().for_each(|n| error_on(&n, "states"));
|
||||||
node.Transitions().for_each(|n| error_on(&n, "transitions"));
|
node.Transitions().for_each(|n| error_on(&n, "transitions"));
|
||||||
node.CallbackDeclaration().for_each(|cb| {
|
node.CallbackDeclaration().for_each(|cb| {
|
||||||
if parser::identifier_text(&cb.DeclaredIdentifier()).map_or(false, |s| s == "init")
|
if parser::identifier_text(&cb.DeclaredIdentifier()).is_some_and(|s| s == "init") {
|
||||||
{
|
|
||||||
error_on(&cb, "an 'init' callback")
|
error_on(&cb, "an 'init' callback")
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
node.CallbackConnection().for_each(|cb| {
|
node.CallbackConnection().for_each(|cb| {
|
||||||
if parser::identifier_text(&cb).map_or(false, |s| s == "init") {
|
if parser::identifier_text(&cb).is_some_and(|s| s == "init") {
|
||||||
error_on(&cb, "an 'init' callback")
|
error_on(&cb, "an 'init' callback")
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
@ -1130,7 +1129,7 @@ impl Element {
|
||||||
unwrap_or_continue!(parser::identifier_text(&sig_decl.DeclaredIdentifier()); diag);
|
unwrap_or_continue!(parser::identifier_text(&sig_decl.DeclaredIdentifier()); diag);
|
||||||
|
|
||||||
let pure = Some(
|
let pure = Some(
|
||||||
sig_decl.child_token(SyntaxKind::Identifier).map_or(false, |t| t.text() == "pure"),
|
sig_decl.child_token(SyntaxKind::Identifier).is_some_and(|t| t.text() == "pure"),
|
||||||
);
|
);
|
||||||
|
|
||||||
let PropertyLookupResult {
|
let PropertyLookupResult {
|
||||||
|
|
@ -1819,7 +1818,7 @@ impl Element {
|
||||||
/// If `need_explicit` is true, then only consider binding set in the code, not the ones set
|
/// If `need_explicit` is true, then only consider binding set in the code, not the ones set
|
||||||
/// by the compiler later.
|
/// by the compiler later.
|
||||||
pub fn is_binding_set(self: &Element, property_name: &str, need_explicit: bool) -> bool {
|
pub fn is_binding_set(self: &Element, property_name: &str, need_explicit: bool) -> bool {
|
||||||
if self.bindings.get(property_name).map_or(false, |b| {
|
if self.bindings.get(property_name).is_some_and(|b| {
|
||||||
b.borrow().has_binding() && (!need_explicit || b.borrow().priority > 0)
|
b.borrow().has_binding() && (!need_explicit || b.borrow().priority > 0)
|
||||||
}) {
|
}) {
|
||||||
true
|
true
|
||||||
|
|
|
||||||
|
|
@ -79,7 +79,7 @@ impl PropertyPath {
|
||||||
|| enclosing
|
|| enclosing
|
||||||
.parent_element
|
.parent_element
|
||||||
.upgrade()
|
.upgrade()
|
||||||
.map_or(false, |e| check_that_element_is_in_the_component(&e, c))
|
.is_some_and(|e| check_that_element_is_in_the_component(&e, c))
|
||||||
}
|
}
|
||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
debug_assert!(
|
debug_assert!(
|
||||||
|
|
@ -207,7 +207,7 @@ fn analyze_binding(
|
||||||
let mut depends_on_external = DependsOnExternal(false);
|
let mut depends_on_external = DependsOnExternal(false);
|
||||||
let element = current.prop.element();
|
let element = current.prop.element();
|
||||||
let name = current.prop.name();
|
let name = current.prop.name();
|
||||||
if context.currently_analyzing.back().map_or(false, |r| r == current)
|
if (context.currently_analyzing.back() == Some(current))
|
||||||
&& !element.borrow().bindings[name].borrow().two_way_bindings.is_empty()
|
&& !element.borrow().bindings[name].borrow().two_way_bindings.is_empty()
|
||||||
{
|
{
|
||||||
let span = element.borrow().bindings[name]
|
let span = element.borrow().bindings[name]
|
||||||
|
|
@ -242,7 +242,7 @@ fn analyze_binding(
|
||||||
}
|
}
|
||||||
|
|
||||||
let binding = &element.borrow().bindings[name];
|
let binding = &element.borrow().bindings[name];
|
||||||
if binding.borrow().analysis.as_ref().map_or(false, |a| a.no_external_dependencies) {
|
if binding.borrow().analysis.as_ref().is_some_and(|a| a.no_external_dependencies) {
|
||||||
return depends_on_external;
|
return depends_on_external;
|
||||||
} else if !context.visited.insert(current.clone()) {
|
} else if !context.visited.insert(current.clone()) {
|
||||||
return DependsOnExternal(true);
|
return DependsOnExternal(true);
|
||||||
|
|
@ -527,7 +527,7 @@ fn visit_implicit_layout_info_dependencies(
|
||||||
.property_analysis
|
.property_analysis
|
||||||
.borrow()
|
.borrow()
|
||||||
.get("wrap")
|
.get("wrap")
|
||||||
.map_or(false, |a| a.is_set || a.is_set_externally);
|
.is_some_and(|a| a.is_set || a.is_set_externally);
|
||||||
if wrap_set && orientation == Orientation::Vertical {
|
if wrap_set && orientation == Orientation::Vertical {
|
||||||
vis(&NamedReference::new(item, SmolStr::new_static("width")).into(), N);
|
vis(&NamedReference::new(item, SmolStr::new_static("width")).into(), N);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -47,9 +47,6 @@ fn has_any_children(e: &Element) -> bool {
|
||||||
/// Returns true if the property is set.
|
/// Returns true if the property is set.
|
||||||
fn is_property_set(e: &Element, property_name: &str) -> bool {
|
fn is_property_set(e: &Element, property_name: &str) -> bool {
|
||||||
e.bindings.contains_key(property_name)
|
e.bindings.contains_key(property_name)
|
||||||
|| e.property_analysis
|
|| e.property_analysis.borrow().get(property_name).is_some_and(|a| a.is_set || a.is_linked)
|
||||||
.borrow()
|
|
||||||
.get(property_name)
|
|
||||||
.map_or(false, |a| a.is_set || a.is_linked)
|
|
||||||
|| matches!(&e.base_type, ElementType::Component(base) if is_property_set(&base.root_element.borrow(), property_name))
|
|| matches!(&e.base_type, ElementType::Component(base) if is_property_set(&base.root_element.borrow(), property_name))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ pub fn handle_clip(
|
||||||
&(),
|
&(),
|
||||||
&mut |elem_rc: &ElementRc, _| {
|
&mut |elem_rc: &ElementRc, _| {
|
||||||
let elem = elem_rc.borrow();
|
let elem = elem_rc.borrow();
|
||||||
if elem.native_class().map_or(false, |n| Rc::ptr_eq(&n, &native_clip)) {
|
if elem.native_class().is_some_and(|n| Rc::ptr_eq(&n, &native_clip)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if elem.bindings.contains_key("clip")
|
if elem.bindings.contains_key("clip")
|
||||||
|
|
@ -34,7 +34,7 @@ pub fn handle_clip(
|
||||||
.property_analysis
|
.property_analysis
|
||||||
.borrow()
|
.borrow()
|
||||||
.get("clip")
|
.get("clip")
|
||||||
.map_or(false, |a| a.is_set || a.is_linked)
|
.is_some_and(|a| a.is_set || a.is_linked)
|
||||||
{
|
{
|
||||||
match elem.builtin_type().as_ref().map(|ty| ty.name.as_str()) {
|
match elem.builtin_type().as_ref().map(|ty| ty.name.as_str()) {
|
||||||
Some("Rectangle") => {}
|
Some("Rectangle") => {}
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ fn simplify_expression(expr: &mut Expression) -> bool {
|
||||||
if nr.is_constant()
|
if nr.is_constant()
|
||||||
&& !match nr.ty() {
|
&& !match nr.ty() {
|
||||||
Type::Struct(s) => {
|
Type::Struct(s) => {
|
||||||
s.name.as_ref().map_or(false, |name| name.ends_with("::StateInfo"))
|
s.name.as_ref().is_some_and(|name| name.ends_with("::StateInfo"))
|
||||||
}
|
}
|
||||||
_ => false,
|
_ => false,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,7 @@ struct DedupPropState<'a> {
|
||||||
|
|
||||||
impl<'a> DedupPropState<'a> {
|
impl<'a> DedupPropState<'a> {
|
||||||
fn add(&self, nr: &NamedReference) {
|
fn add(&self, nr: &NamedReference) {
|
||||||
if self.parent_state.map_or(false, |pc| pc.add_from_children(nr)) {
|
if self.parent_state.is_some_and(|pc| pc.add_from_children(nr)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let mut use_counts = self.counts.borrow_mut();
|
let mut use_counts = self.counts.borrow_mut();
|
||||||
|
|
@ -62,7 +62,7 @@ impl<'a> DedupPropState<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn add_from_children(&self, nr: &NamedReference) -> bool {
|
fn add_from_children(&self, nr: &NamedReference) -> bool {
|
||||||
if self.parent_state.map_or(false, |pc| pc.add_from_children(nr)) {
|
if self.parent_state.is_some_and(|pc| pc.add_from_children(nr)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
let mut use_counts = self.counts.borrow_mut();
|
let mut use_counts = self.counts.borrow_mut();
|
||||||
|
|
|
||||||
|
|
@ -193,7 +193,7 @@ fn gen_layout_info_prop(elem: &ElementRc, diag: &mut BuildDiagnostics) {
|
||||||
}
|
}
|
||||||
let explicit_constraints =
|
let explicit_constraints =
|
||||||
LayoutConstraints::new(c, diag, DiagnosticLevel::Error);
|
LayoutConstraints::new(c, diag, DiagnosticLevel::Error);
|
||||||
let use_implicit_size = c.borrow().builtin_type().map_or(false, |b| {
|
let use_implicit_size = c.borrow().builtin_type().is_some_and(|b| {
|
||||||
b.default_size_binding == DefaultSizeBinding::ImplicitSize
|
b.default_size_binding == DefaultSizeBinding::ImplicitSize
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -507,7 +507,7 @@ fn adjust_image_clip_rect(elem: &ElementRc, builtin: &Rc<BuiltinElement>) {
|
||||||
|
|
||||||
if builtin.native_class.properties.keys().any(|p| {
|
if builtin.native_class.properties.keys().any(|p| {
|
||||||
elem.borrow().bindings.contains_key(p)
|
elem.borrow().bindings.contains_key(p)
|
||||||
|| elem.borrow().property_analysis.borrow().get(p).map_or(false, |a| a.is_used())
|
|| elem.borrow().property_analysis.borrow().get(p).is_some_and(|a| a.is_used())
|
||||||
}) {
|
}) {
|
||||||
let source = NamedReference::new(elem, SmolStr::new_static("source"));
|
let source = NamedReference::new(elem, SmolStr::new_static("source"));
|
||||||
let x = NamedReference::new(elem, SmolStr::new_static("source-clip-x"));
|
let x = NamedReference::new(elem, SmolStr::new_static("source-clip-x"));
|
||||||
|
|
|
||||||
|
|
@ -121,7 +121,7 @@ pub fn ensure_window(
|
||||||
} = expr
|
} = expr
|
||||||
{
|
{
|
||||||
for arg in arguments.iter_mut() {
|
for arg in arguments.iter_mut() {
|
||||||
if matches!(arg, Expression::ElementReference(elr) if elr.upgrade().map_or(false, |elemrc| Rc::ptr_eq(&elemrc, &win_elem)))
|
if matches!(arg, Expression::ElementReference(elr) if elr.upgrade().is_some_and(|elemrc| Rc::ptr_eq(&elemrc, &win_elem)))
|
||||||
{
|
{
|
||||||
*arg = Expression::ElementReference(Rc::downgrade(&new_root))
|
*arg = Expression::ElementReference(Rc::downgrade(&new_root))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -276,8 +276,7 @@ fn call_set_focus_function(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let builtin_focus_function =
|
let builtin_focus_function = element.borrow().builtin_type().is_some_and(|ty| ty.accepts_focus);
|
||||||
element.borrow().builtin_type().map_or(false, |ty| ty.accepts_focus);
|
|
||||||
|
|
||||||
if declares_focus_function {
|
if declares_focus_function {
|
||||||
Some(Expression::FunctionCall {
|
Some(Expression::FunctionCall {
|
||||||
|
|
|
||||||
|
|
@ -102,7 +102,7 @@ fn lower_element_layout(
|
||||||
&& component
|
&& component
|
||||||
.parent_element
|
.parent_element
|
||||||
.upgrade()
|
.upgrade()
|
||||||
.map_or(false, |e| e.borrow().repeated.is_some()),
|
.is_some_and(|e| e.borrow().repeated.is_some()),
|
||||||
"Error should have been caught at element lookup time"
|
"Error should have been caught at element lookup time"
|
||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
|
|
@ -709,7 +709,7 @@ fn create_layout_item(
|
||||||
diag: &mut BuildDiagnostics,
|
diag: &mut BuildDiagnostics,
|
||||||
) -> Option<CreateLayoutItemResult> {
|
) -> Option<CreateLayoutItemResult> {
|
||||||
let fix_explicit_percent = |prop: &str, item: &ElementRc| {
|
let fix_explicit_percent = |prop: &str, item: &ElementRc| {
|
||||||
if !item.borrow().bindings.get(prop).map_or(false, |b| b.borrow().ty() == Type::Percent) {
|
if !item.borrow().bindings.get(prop).is_some_and(|b| b.borrow().ty() == Type::Percent) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let mut item = item.borrow_mut();
|
let mut item = item.borrow_mut();
|
||||||
|
|
|
||||||
|
|
@ -52,7 +52,7 @@ pub(crate) fn lower_property_to_element(
|
||||||
.property_analysis
|
.property_analysis
|
||||||
.borrow()
|
.borrow()
|
||||||
.get(property_name)
|
.get(property_name)
|
||||||
.map_or(false, |a| a.is_set || a.is_linked))
|
.is_some_and(|a| a.is_set || a.is_linked))
|
||||||
};
|
};
|
||||||
|
|
||||||
for mut child in old_children {
|
for mut child in old_children {
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,7 @@ pub fn lower_text_input_interface(component: &Rc<Component>) {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_input_text_focused_prop(nr: &NamedReference) -> bool {
|
fn is_input_text_focused_prop(nr: &NamedReference) -> bool {
|
||||||
if !nr.element().borrow().builtin_type().map_or(false, |bt| bt.name == "TextInputInterface") {
|
if !nr.element().borrow().builtin_type().is_some_and(|bt| bt.name == "TextInputInterface") {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
assert_eq!(nr.name(), "text-input-focused");
|
assert_eq!(nr.name(), "text-input-focused");
|
||||||
|
|
|
||||||
|
|
@ -63,11 +63,11 @@ fn can_optimize(elem: &ElementRc) -> bool {
|
||||||
|
|
||||||
let analysis = e.property_analysis.borrow();
|
let analysis = e.property_analysis.borrow();
|
||||||
for coord in ["x", "y"] {
|
for coord in ["x", "y"] {
|
||||||
if e.bindings.contains_key(coord) || analysis.get(coord).map_or(false, |a| a.is_set) {
|
if e.bindings.contains_key(coord) || analysis.get(coord).is_some_and(|a| a.is_set) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if analysis.get("absolute-position").map_or(false, |a| a.is_read) {
|
if analysis.get("absolute-position").is_some_and(|a| a.is_read) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -173,7 +173,7 @@ pub fn remove_aliases(doc: &Document, diag: &mut BuildDiagnostics) {
|
||||||
.property_analysis
|
.property_analysis
|
||||||
.borrow()
|
.borrow()
|
||||||
.get(remove.name())
|
.get(remove.name())
|
||||||
.map_or(false, |v| v.is_read_externally || v.is_set_externally);
|
.is_some_and(|v| v.is_read_externally || v.is_set_externally);
|
||||||
if let Some(d) = elem.property_declarations.get_mut(remove.name()) {
|
if let Some(d) = elem.property_declarations.get_mut(remove.name()) {
|
||||||
if d.expose_in_public_api || used_externally {
|
if d.expose_in_public_api || used_externally {
|
||||||
d.is_alias = Some(to.clone());
|
d.is_alias = Some(to.clone());
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ pub fn remove_unused_properties(doc: &Document) {
|
||||||
for (prop, decl) in &elem.property_declarations {
|
for (prop, decl) in &elem.property_declarations {
|
||||||
if !decl.expose_in_public_api
|
if !decl.expose_in_public_api
|
||||||
&& !elem.named_references.is_referenced(prop)
|
&& !elem.named_references.is_referenced(prop)
|
||||||
&& !elem.property_analysis.borrow().get(prop).map_or(false, |v| v.is_used())
|
&& !elem.property_analysis.borrow().get(prop).is_some_and(|v| v.is_used())
|
||||||
&& !elem.change_callbacks.contains_key(prop)
|
&& !elem.change_callbacks.contains_key(prop)
|
||||||
{
|
{
|
||||||
to_remove.insert(prop.to_owned());
|
to_remove.insert(prop.to_owned());
|
||||||
|
|
|
||||||
|
|
@ -449,7 +449,7 @@ impl Expression {
|
||||||
return Expression::Invalid;
|
return Expression::Invalid;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
if subs.next().map_or(false, |s| s.kind() != SyntaxKind::Comma) {
|
if subs.next().is_some_and(|s| s.kind() != SyntaxKind::Comma) {
|
||||||
ctx.diag.push_error(
|
ctx.diag.push_error(
|
||||||
"Angle expression must be an angle followed by a comma".into(),
|
"Angle expression must be an angle followed by a comma".into(),
|
||||||
&node,
|
&node,
|
||||||
|
|
@ -475,7 +475,7 @@ impl Expression {
|
||||||
ctx.diag.push_error("'at' in @radial-gradient is not yet supported".into(), &comma);
|
ctx.diag.push_error("'at' in @radial-gradient is not yet supported".into(), &comma);
|
||||||
return Expression::Invalid;
|
return Expression::Invalid;
|
||||||
}
|
}
|
||||||
if comma.as_ref().map_or(false, |s| s.kind() != SyntaxKind::Comma) {
|
if comma.as_ref().is_some_and(|s| s.kind() != SyntaxKind::Comma) {
|
||||||
ctx.diag.push_error(
|
ctx.diag.push_error(
|
||||||
"'circle' must be followed by a comma".into(),
|
"'circle' must be followed by a comma".into(),
|
||||||
comma.as_ref().map_or(&node, |x| x as &dyn Spanned),
|
comma.as_ref().map_or(&node, |x| x as &dyn Spanned),
|
||||||
|
|
@ -1383,15 +1383,11 @@ fn continue_lookup_within_element(
|
||||||
let e_borrowed = e.borrow();
|
let e_borrowed = e.borrow();
|
||||||
let mut id = e_borrowed.id.as_str();
|
let mut id = e_borrowed.id.as_str();
|
||||||
if id.is_empty() {
|
if id.is_empty() {
|
||||||
if ctx.component_scope.last().map_or(false, |x| Rc::ptr_eq(&e, x)) {
|
if ctx.component_scope.last().is_some_and(|x| Rc::ptr_eq(&e, x)) {
|
||||||
id = "self";
|
id = "self";
|
||||||
} else if ctx.component_scope.first().map_or(false, |x| Rc::ptr_eq(&e, x)) {
|
} else if ctx.component_scope.first().is_some_and(|x| Rc::ptr_eq(&e, x)) {
|
||||||
id = "root";
|
id = "root";
|
||||||
} else if ctx
|
} else if ctx.component_scope.iter().nth_back(1).is_some_and(|x| Rc::ptr_eq(&e, x))
|
||||||
.component_scope
|
|
||||||
.iter()
|
|
||||||
.nth_back(1)
|
|
||||||
.map_or(false, |x| Rc::ptr_eq(&e, x))
|
|
||||||
{
|
{
|
||||||
id = "parent";
|
id = "parent";
|
||||||
}
|
}
|
||||||
|
|
@ -1459,7 +1455,7 @@ fn continue_lookup_within_element(
|
||||||
} else if lookup_result.property_visibility == PropertyVisibility::Protected
|
} else if lookup_result.property_visibility == PropertyVisibility::Protected
|
||||||
&& !local_to_component
|
&& !local_to_component
|
||||||
&& !(lookup_result.is_in_direct_base
|
&& !(lookup_result.is_in_direct_base
|
||||||
&& ctx.component_scope.first().map_or(false, |x| Rc::ptr_eq(x, elem)))
|
&& ctx.component_scope.first().is_some_and(|x| Rc::ptr_eq(x, elem)))
|
||||||
{
|
{
|
||||||
ctx.diag.push_error(format!("The function '{}' is protected", second.text()), &second);
|
ctx.diag.push_error(format!("The function '{}' is protected", second.text()), &second);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -33,10 +33,9 @@ pub fn handle_visible(
|
||||||
component,
|
component,
|
||||||
&(),
|
&(),
|
||||||
&mut |elem: &ElementRc, _| {
|
&mut |elem: &ElementRc, _| {
|
||||||
let is_lowered_from_visible_property =
|
let is_lowered_from_visible_property = elem.borrow().native_class().is_some_and(|n| {
|
||||||
elem.borrow().native_class().map_or(false, |n| {
|
Rc::ptr_eq(&n, &native_clip) && elem.borrow().id.ends_with("-visibility")
|
||||||
Rc::ptr_eq(&n, &native_clip) && elem.borrow().id.ends_with("-visibility")
|
});
|
||||||
});
|
|
||||||
if is_lowered_from_visible_property {
|
if is_lowered_from_visible_property {
|
||||||
// This is the element we just created. Skip it.
|
// This is the element we just created. Skip it.
|
||||||
return;
|
return;
|
||||||
|
|
@ -55,7 +54,7 @@ pub fn handle_visible(
|
||||||
.property_analysis
|
.property_analysis
|
||||||
.borrow()
|
.borrow()
|
||||||
.get("visible")
|
.get("visible")
|
||||||
.map_or(false, |a| a.is_set || a.is_linked))
|
.is_some_and(|a| a.is_set || a.is_linked))
|
||||||
};
|
};
|
||||||
|
|
||||||
for mut child in old_children {
|
for mut child in old_children {
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,7 @@ fn syntax_tests() -> std::io::Result<()> {
|
||||||
let mut test_entries = Vec::new();
|
let mut test_entries = Vec::new();
|
||||||
for entry in std::fs::read_dir(format!("{}/tests/syntax", env!("CARGO_MANIFEST_DIR")))? {
|
for entry in std::fs::read_dir(format!("{}/tests/syntax", env!("CARGO_MANIFEST_DIR")))? {
|
||||||
let entry = entry?;
|
let entry = entry?;
|
||||||
if entry.file_type().map_or(false, |f| f.is_dir()) {
|
if entry.file_type().is_ok_and(|f| f.is_dir()) {
|
||||||
let path = entry.path();
|
let path = entry.path();
|
||||||
for test_entry in path.read_dir()? {
|
for test_entry in path.read_dir()? {
|
||||||
let test_entry = test_entry?;
|
let test_entry = test_entry?;
|
||||||
|
|
|
||||||
|
|
@ -1503,7 +1503,7 @@ impl TypeLoader {
|
||||||
))
|
))
|
||||||
.chain(
|
.chain(
|
||||||
(file_to_import == "std-widgets.slint"
|
(file_to_import == "std-widgets.slint"
|
||||||
|| referencing_file.map_or(false, |x| x.starts_with("builtin:/")))
|
|| referencing_file.is_some_and(|x| x.starts_with("builtin:/")))
|
||||||
.then(|| format!("builtin:/{}", self.style).into()),
|
.then(|| format!("builtin:/{}", self.style).into()),
|
||||||
)
|
)
|
||||||
.find_map(|include_dir| {
|
.find_map(|include_dir| {
|
||||||
|
|
@ -1647,7 +1647,7 @@ fn get_native_style(all_loaded_files: &mut std::collections::BTreeSet<PathBuf>)
|
||||||
/// Because from a proc_macro, we don't actually know the path of the current file, and this
|
/// Because from a proc_macro, we don't actually know the path of the current file, and this
|
||||||
/// is why we must be relative to CARGO_MANIFEST_DIR.
|
/// is why we must be relative to CARGO_MANIFEST_DIR.
|
||||||
pub fn base_directory(referencing_file: &Path) -> PathBuf {
|
pub fn base_directory(referencing_file: &Path) -> PathBuf {
|
||||||
if referencing_file.extension().map_or(false, |e| e == "rs") {
|
if referencing_file.extension().is_some_and(|e| e == "rs") {
|
||||||
// For .rs file, this is a rust macro, and rust macro locates the file relative to the CARGO_MANIFEST_DIR which is the directory that has a Cargo.toml file.
|
// For .rs file, this is a rust macro, and rust macro locates the file relative to the CARGO_MANIFEST_DIR which is the directory that has a Cargo.toml file.
|
||||||
let mut candidate = referencing_file;
|
let mut candidate = referencing_file;
|
||||||
loop {
|
loop {
|
||||||
|
|
|
||||||
|
|
@ -1343,7 +1343,7 @@ pub(crate) mod ffi {
|
||||||
width: &mut u32,
|
width: &mut u32,
|
||||||
height: &mut u32,
|
height: &mut u32,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
image.to_rgb8().map_or(false, |pixel_buffer| {
|
image.to_rgb8().is_some_and(|pixel_buffer| {
|
||||||
*data = pixel_buffer.data.clone();
|
*data = pixel_buffer.data.clone();
|
||||||
*width = pixel_buffer.width();
|
*width = pixel_buffer.width();
|
||||||
*height = pixel_buffer.height();
|
*height = pixel_buffer.height();
|
||||||
|
|
@ -1358,7 +1358,7 @@ pub(crate) mod ffi {
|
||||||
width: &mut u32,
|
width: &mut u32,
|
||||||
height: &mut u32,
|
height: &mut u32,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
image.to_rgba8().map_or(false, |pixel_buffer| {
|
image.to_rgba8().is_some_and(|pixel_buffer| {
|
||||||
*data = pixel_buffer.data.clone();
|
*data = pixel_buffer.data.clone();
|
||||||
*width = pixel_buffer.width();
|
*width = pixel_buffer.width();
|
||||||
*height = pixel_buffer.height();
|
*height = pixel_buffer.height();
|
||||||
|
|
@ -1373,7 +1373,7 @@ pub(crate) mod ffi {
|
||||||
width: &mut u32,
|
width: &mut u32,
|
||||||
height: &mut u32,
|
height: &mut u32,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
image.to_rgba8_premultiplied().map_or(false, |pixel_buffer| {
|
image.to_rgba8_premultiplied().is_some_and(|pixel_buffer| {
|
||||||
*data = pixel_buffer.data.clone();
|
*data = pixel_buffer.data.clone();
|
||||||
*width = pixel_buffer.width();
|
*width = pixel_buffer.width();
|
||||||
*height = pixel_buffer.height();
|
*height = pixel_buffer.height();
|
||||||
|
|
|
||||||
|
|
@ -645,7 +645,7 @@ pub(crate) fn send_exit_events(
|
||||||
for (idx, it) in old_input_state.item_stack.iter().enumerate() {
|
for (idx, it) in old_input_state.item_stack.iter().enumerate() {
|
||||||
let Some(item) = it.0.upgrade() else { break };
|
let Some(item) = it.0.upgrade() else { break };
|
||||||
let g = item.geometry();
|
let g = item.geometry();
|
||||||
let contains = pos.map_or(false, |p| g.contains(p));
|
let contains = pos.is_some_and(|p| g.contains(p));
|
||||||
if let Some(p) = pos.as_mut() {
|
if let Some(p) = pos.as_mut() {
|
||||||
*p -= g.origin.to_vector();
|
*p -= g.origin.to_vector();
|
||||||
}
|
}
|
||||||
|
|
@ -758,7 +758,7 @@ fn send_mouse_event_to_item(
|
||||||
let mut event_for_children = mouse_event;
|
let mut event_for_children = mouse_event;
|
||||||
event_for_children.translate(-geom.origin.to_vector());
|
event_for_children.translate(-geom.origin.to_vector());
|
||||||
|
|
||||||
let filter_result = if mouse_event.position().map_or(false, |p| geom.contains(p))
|
let filter_result = if mouse_event.position().is_some_and(|p| geom.contains(p))
|
||||||
|| crate::item_rendering::is_clipping_item(item)
|
|| crate::item_rendering::is_clipping_item(item)
|
||||||
{
|
{
|
||||||
item.as_ref().input_event_filter_before_children(
|
item.as_ref().input_event_filter_before_children(
|
||||||
|
|
|
||||||
|
|
@ -185,7 +185,7 @@ impl<T: Clone> ItemCache<T> {
|
||||||
pub fn is_clipping_item(item: Pin<ItemRef>) -> bool {
|
pub fn is_clipping_item(item: Pin<ItemRef>) -> bool {
|
||||||
//(FIXME: there should be some flag in the vtable instead of down-casting)
|
//(FIXME: there should be some flag in the vtable instead of down-casting)
|
||||||
ItemRef::downcast_pin::<Flickable>(item).is_some()
|
ItemRef::downcast_pin::<Flickable>(item).is_some()
|
||||||
|| ItemRef::downcast_pin::<Clip>(item).map_or(false, |clip_item| clip_item.as_ref().clip())
|
|| ItemRef::downcast_pin::<Clip>(item).is_some_and(|clip_item| clip_item.as_ref().clip())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Renders the children of the item with the specified index into the renderer.
|
/// Renders the children of the item with the specified index into the renderer.
|
||||||
|
|
@ -1043,7 +1043,7 @@ impl<T: ItemRenderer + ItemRendererFeatures> ItemRenderer for PartialRenderer<'_
|
||||||
};
|
};
|
||||||
|
|
||||||
let clipped_geom = self.get_current_clip().intersection(&item_bounding_rect);
|
let clipped_geom = self.get_current_clip().intersection(&item_bounding_rect);
|
||||||
let draw = clipped_geom.map_or(false, |clipped_geom| {
|
let draw = clipped_geom.is_some_and(|clipped_geom| {
|
||||||
let clipped_geom = clipped_geom.translate(self.translation());
|
let clipped_geom = clipped_geom.translate(self.translation());
|
||||||
self.dirty_region.draw_intersects(clipped_geom)
|
self.dirty_region.draw_intersects(clipped_geom)
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -68,7 +68,7 @@ impl ComponentContainer {
|
||||||
vtable::VRc::borrow_pin(&parent).as_ref().window_adapter(false, &mut window);
|
vtable::VRc::borrow_pin(&parent).as_ref().window_adapter(false, &mut window);
|
||||||
}
|
}
|
||||||
let prevent_focus_change =
|
let prevent_focus_change =
|
||||||
window.as_ref().map_or(false, |w| w.window().0.prevent_focus_change.replace(true));
|
window.as_ref().is_some_and(|w| w.window().0.prevent_focus_change.replace(true));
|
||||||
|
|
||||||
let factory_context = FactoryContext {
|
let factory_context = FactoryContext {
|
||||||
parent_item_tree: self.my_component.get().unwrap().clone(),
|
parent_item_tree: self.my_component.get().unwrap().clone(),
|
||||||
|
|
|
||||||
|
|
@ -241,7 +241,7 @@ impl FlickableData {
|
||||||
}
|
}
|
||||||
MouseEvent::Moved { position } => {
|
MouseEvent::Moved { position } => {
|
||||||
let do_intercept = inner.capture_events
|
let do_intercept = inner.capture_events
|
||||||
|| inner.pressed_time.map_or(false, |pressed_time| {
|
|| inner.pressed_time.is_some_and(|pressed_time| {
|
||||||
if crate::animations::current_tick() - pressed_time > DURATION_THRESHOLD {
|
if crate::animations::current_tick() - pressed_time > DURATION_THRESHOLD {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -684,7 +684,7 @@ pub fn reorder_dialog_button_layout(cells: &mut [GridLayoutCellData], roles: &[D
|
||||||
std::env::var("XDG_CURRENT_DESKTOP")
|
std::env::var("XDG_CURRENT_DESKTOP")
|
||||||
.ok()
|
.ok()
|
||||||
.and_then(|v| v.as_bytes().first().copied())
|
.and_then(|v| v.as_bytes().first().copied())
|
||||||
.map_or(false, |x| x.eq_ignore_ascii_case(&b'K'))
|
.is_some_and(|x| x.eq_ignore_ascii_case(&b'K'))
|
||||||
}
|
}
|
||||||
#[cfg(not(feature = "std"))]
|
#[cfg(not(feature = "std"))]
|
||||||
let is_kde = || true;
|
let is_kde = || true;
|
||||||
|
|
|
||||||
|
|
@ -574,7 +574,7 @@ impl PropertyHandle {
|
||||||
/// Implementation of Self::set_binding.
|
/// Implementation of Self::set_binding.
|
||||||
fn set_binding_impl(&self, binding: *mut BindingHolder) {
|
fn set_binding_impl(&self, binding: *mut BindingHolder) {
|
||||||
let previous_binding_intercepted = self.access(|b| {
|
let previous_binding_intercepted = self.access(|b| {
|
||||||
b.map_or(false, |b| unsafe {
|
b.is_some_and(|b| unsafe {
|
||||||
// Safety: b is a BindingHolder<T>
|
// Safety: b is a BindingHolder<T>
|
||||||
(b.vtable.intercept_set_binding)(&*b as *const BindingHolder, binding)
|
(b.vtable.intercept_set_binding)(&*b as *const BindingHolder, binding)
|
||||||
})
|
})
|
||||||
|
|
@ -878,7 +878,7 @@ impl<T: Clone> Property<T> {
|
||||||
T: PartialEq,
|
T: PartialEq,
|
||||||
{
|
{
|
||||||
let previous_binding_intercepted = self.handle.access(|b| {
|
let previous_binding_intercepted = self.handle.access(|b| {
|
||||||
b.map_or(false, |b| unsafe {
|
b.is_some_and(|b| unsafe {
|
||||||
// Safety: b is a BindingHolder<T>
|
// Safety: b is a BindingHolder<T>
|
||||||
(b.vtable.intercept_set)(&*b as *const BindingHolder, &t as *const T as *const ())
|
(b.vtable.intercept_set)(&*b as *const BindingHolder, &t as *const T as *const ())
|
||||||
})
|
})
|
||||||
|
|
@ -950,7 +950,7 @@ impl<T: Clone> Property<T> {
|
||||||
/// Any of the properties accessed during the last evaluation of the closure called
|
/// Any of the properties accessed during the last evaluation of the closure called
|
||||||
/// from the last call to evaluate is potentially dirty.
|
/// from the last call to evaluate is potentially dirty.
|
||||||
pub fn is_dirty(&self) -> bool {
|
pub fn is_dirty(&self) -> bool {
|
||||||
self.handle.access(|binding| binding.map_or(false, |b| b.dirty.get()))
|
self.handle.access(|binding| binding.is_some_and(|b| b.dirty.get()))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Internal function to mark the property as dirty and notify dependencies, regardless of
|
/// Internal function to mark the property as dirty and notify dependencies, regardless of
|
||||||
|
|
|
||||||
|
|
@ -34,9 +34,10 @@ pub unsafe extern "C" fn slint_property_set_changed(
|
||||||
handle: &PropertyHandleOpaque,
|
handle: &PropertyHandleOpaque,
|
||||||
value: *const c_void,
|
value: *const c_void,
|
||||||
) {
|
) {
|
||||||
if !handle.0.access(|b| {
|
if !handle
|
||||||
b.map_or(false, |b| (b.vtable.intercept_set)(&*b as *const BindingHolder, value))
|
.0
|
||||||
}) {
|
.access(|b| b.is_some_and(|b| (b.vtable.intercept_set)(&*b as *const BindingHolder, value)))
|
||||||
|
{
|
||||||
handle.0.remove_binding();
|
handle.0.remove_binding();
|
||||||
}
|
}
|
||||||
handle.0.mark_dirty();
|
handle.0.mark_dirty();
|
||||||
|
|
@ -143,7 +144,7 @@ pub unsafe extern "C" fn slint_property_set_binding_internal(
|
||||||
/// Returns whether the property behind this handle is marked as dirty
|
/// Returns whether the property behind this handle is marked as dirty
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn slint_property_is_dirty(handle: &PropertyHandleOpaque) -> bool {
|
pub extern "C" fn slint_property_is_dirty(handle: &PropertyHandleOpaque) -> bool {
|
||||||
handle.0.access(|binding| binding.map_or(false, |b| b.dirty.get()))
|
handle.0.access(|binding| binding.is_some_and(|b| b.dirty.get()))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Marks the property as dirty and notifies dependencies.
|
/// Marks the property as dirty and notifies dependencies.
|
||||||
|
|
|
||||||
|
|
@ -1045,7 +1045,7 @@ impl WindowInner {
|
||||||
pub fn supports_native_menu_bar(&self) -> bool {
|
pub fn supports_native_menu_bar(&self) -> bool {
|
||||||
self.window_adapter()
|
self.window_adapter()
|
||||||
.internal(crate::InternalToken)
|
.internal(crate::InternalToken)
|
||||||
.map_or(false, |x| x.supports_native_menu_bar())
|
.is_some_and(|x| x.supports_native_menu_bar())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Setup the native menu bar
|
/// Setup the native menu bar
|
||||||
|
|
@ -1720,9 +1720,7 @@ pub mod ffi {
|
||||||
handle: *const WindowAdapterRcOpaque,
|
handle: *const WindowAdapterRcOpaque,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
let window_adapter = &*(handle as *const Rc<dyn WindowAdapter>);
|
let window_adapter = &*(handle as *const Rc<dyn WindowAdapter>);
|
||||||
window_adapter
|
window_adapter.internal(crate::InternalToken).is_some_and(|x| x.supports_native_menu_bar())
|
||||||
.internal(crate::InternalToken)
|
|
||||||
.map_or(false, |x| x.supports_native_menu_bar())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Setup the native menu bar
|
/// Setup the native menu bar
|
||||||
|
|
|
||||||
|
|
@ -40,13 +40,13 @@ pub fn collect_test_cases(sub_folders: &str) -> std::io::Result<Vec<TestCase>> {
|
||||||
let mut all_styles = vec!["fluent", "material", "cupertino", "cosmic"];
|
let mut all_styles = vec!["fluent", "material", "cupertino", "cosmic"];
|
||||||
|
|
||||||
// It is in the target/xxx/build directory
|
// It is in the target/xxx/build directory
|
||||||
if std::env::var_os("OUT_DIR").map_or(false, |path| {
|
if std::env::var_os("OUT_DIR").is_some_and(|path| {
|
||||||
// Same logic as in i-slint-backend-selector's build script to get the path
|
// Same logic as in i-slint-backend-selector's build script to get the path
|
||||||
let mut path: PathBuf = path.into();
|
let mut path: PathBuf = path.into();
|
||||||
path.pop();
|
path.pop();
|
||||||
path.pop();
|
path.pop();
|
||||||
path.push("SLINT_DEFAULT_STYLE.txt");
|
path.push("SLINT_DEFAULT_STYLE.txt");
|
||||||
std::fs::read_to_string(path).map_or(false, |style| style.trim().contains("qt"))
|
std::fs::read_to_string(path).is_ok_and(|style| style.trim().contains("qt"))
|
||||||
}) {
|
}) {
|
||||||
all_styles.push("qt");
|
all_styles.push("qt");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -226,7 +226,7 @@ fn compare_images(
|
||||||
|
|
||||||
if result.is_err()
|
if result.is_err()
|
||||||
&& rotated == RenderingRotation::NoRotation
|
&& rotated == RenderingRotation::NoRotation
|
||||||
&& std::env::var("SLINT_CREATE_SCREENSHOTS").map_or(false, |var| var == "1")
|
&& std::env::var("SLINT_CREATE_SCREENSHOTS").is_ok_and(|var| var == "1")
|
||||||
{
|
{
|
||||||
eprintln!("saving rendered image as comparison to reference failed");
|
eprintln!("saving rendered image as comparison to reference failed");
|
||||||
image::save_buffer(
|
image::save_buffer(
|
||||||
|
|
|
||||||
|
|
@ -185,7 +185,7 @@ fn main() -> std::io::Result<()> {
|
||||||
}
|
}
|
||||||
for resource in doc.embedded_file_resources.borrow().keys() {
|
for resource in doc.embedded_file_resources.borrow().keys() {
|
||||||
if !fileaccess::load_file(std::path::Path::new(resource))
|
if !fileaccess::load_file(std::path::Path::new(resource))
|
||||||
.map_or(false, |f| f.is_builtin())
|
.is_some_and(|f| f.is_builtin())
|
||||||
{
|
{
|
||||||
write!(f, " {resource}")?;
|
write!(f, " {resource}")?;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -286,7 +286,7 @@ impl ElementRcNode {
|
||||||
|
|
||||||
pub fn contains_offset(&self, offset: TextSize) -> bool {
|
pub fn contains_offset(&self, offset: TextSize) -> bool {
|
||||||
self.with_element_node(|node| {
|
self.with_element_node(|node| {
|
||||||
node.parent().map_or(false, |n| n.text_range().contains(offset))
|
node.parent().is_some_and(|n| n.text_range().contains(offset))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -336,7 +336,7 @@ impl DocumentCache {
|
||||||
.borrow()
|
.borrow()
|
||||||
.debug
|
.debug
|
||||||
.iter()
|
.iter()
|
||||||
.position(|n| n.node.parent().map_or(false, |n| n.text_range().contains(offset)))
|
.position(|n| n.node.parent().is_some_and(|n| n.text_range().contains(offset)))
|
||||||
}
|
}
|
||||||
|
|
||||||
for component in &document.inner_components {
|
for component in &document.inner_components {
|
||||||
|
|
|
||||||
|
|
@ -693,7 +693,7 @@ fn format_conditional_expression(
|
||||||
writer: &mut impl TokenWriter,
|
writer: &mut impl TokenWriter,
|
||||||
state: &mut FormatState,
|
state: &mut FormatState,
|
||||||
) -> Result<(), std::io::Error> {
|
) -> Result<(), std::io::Error> {
|
||||||
let has_if = node.child_text(SyntaxKind::Identifier).map_or(false, |x| x == "if");
|
let has_if = node.child_text(SyntaxKind::Identifier).is_some_and(|x| x == "if");
|
||||||
|
|
||||||
let mut sub = node.children_with_tokens();
|
let mut sub = node.children_with_tokens();
|
||||||
if has_if {
|
if has_if {
|
||||||
|
|
@ -979,7 +979,7 @@ fn format_state(
|
||||||
writer: &mut impl TokenWriter,
|
writer: &mut impl TokenWriter,
|
||||||
state: &mut FormatState,
|
state: &mut FormatState,
|
||||||
) -> Result<(), std::io::Error> {
|
) -> Result<(), std::io::Error> {
|
||||||
let has_when = node.child_text(SyntaxKind::Identifier).map_or(false, |x| x == "when");
|
let has_when = node.child_text(SyntaxKind::Identifier).is_some_and(|x| x == "when");
|
||||||
let mut sub = node.children_with_tokens();
|
let mut sub = node.children_with_tokens();
|
||||||
let ok = if has_when {
|
let ok = if has_when {
|
||||||
whitespace_to(&mut sub, SyntaxKind::DeclaredIdentifier, writer, state, "")?
|
whitespace_to(&mut sub, SyntaxKind::DeclaredIdentifier, writer, state, "")?
|
||||||
|
|
|
||||||
|
|
@ -423,7 +423,7 @@ pub fn register_request_handlers(rh: &mut RequestHandler) {
|
||||||
let gp = p.parent();
|
let gp = p.parent();
|
||||||
|
|
||||||
if p.kind() == SyntaxKind::DeclaredIdentifier
|
if p.kind() == SyntaxKind::DeclaredIdentifier
|
||||||
&& gp.as_ref().map_or(false, |n| n.kind() == SyntaxKind::Component)
|
&& gp.as_ref().is_some_and(|n| n.kind() == SyntaxKind::Component)
|
||||||
{
|
{
|
||||||
let element = gp.as_ref().unwrap().child_node(SyntaxKind::Element).unwrap();
|
let element = gp.as_ref().unwrap().child_node(SyntaxKind::Element).unwrap();
|
||||||
|
|
||||||
|
|
@ -439,7 +439,7 @@ pub fn register_request_handlers(rh: &mut RequestHandler) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if p.kind() == SyntaxKind::QualifiedName
|
if p.kind() == SyntaxKind::QualifiedName
|
||||||
&& gp.as_ref().map_or(false, |n| n.kind() == SyntaxKind::Element)
|
&& gp.as_ref().is_some_and(|n| n.kind() == SyntaxKind::Element)
|
||||||
{
|
{
|
||||||
let range = util::node_to_lsp_range(&p);
|
let range = util::node_to_lsp_range(&p);
|
||||||
|
|
||||||
|
|
@ -448,7 +448,7 @@ pub fn register_request_handlers(rh: &mut RequestHandler) {
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.parent()
|
.parent()
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.map_or(false, |n| n.kind() != SyntaxKind::Component)
|
.is_some_and(|n| n.kind() != SyntaxKind::Component)
|
||||||
{
|
{
|
||||||
ctx.server_notifier.send_message_to_preview(
|
ctx.server_notifier.send_message_to_preview(
|
||||||
common::LspToPreviewMessage::HighlightFromEditor {
|
common::LspToPreviewMessage::HighlightFromEditor {
|
||||||
|
|
@ -1070,7 +1070,7 @@ fn get_code_actions(
|
||||||
NodeOrToken::Node(_) => is_sub_element(n.kind()),
|
NodeOrToken::Node(_) => is_sub_element(n.kind()),
|
||||||
NodeOrToken::Token(t) => {
|
NodeOrToken::Token(t) => {
|
||||||
t.kind() == SyntaxKind::Whitespace
|
t.kind() == SyntaxKind::Whitespace
|
||||||
&& t.next_sibling_or_token().map_or(false, |n| is_sub_element(n.kind()))
|
&& t.next_sibling_or_token().is_some_and(|n| is_sub_element(n.kind()))
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
|
||||||
|
|
@ -59,7 +59,7 @@ pub(crate) fn completion_at(
|
||||||
} else if let Some(element) = syntax_nodes::Element::new(node.clone()) {
|
} else if let Some(element) = syntax_nodes::Element::new(node.clone()) {
|
||||||
if token.kind() == SyntaxKind::At
|
if token.kind() == SyntaxKind::At
|
||||||
|| (token.kind() == SyntaxKind::Identifier
|
|| (token.kind() == SyntaxKind::Identifier
|
||||||
&& token.prev_token().map_or(false, |t| t.kind() == SyntaxKind::At))
|
&& token.prev_token().is_some_and(|t| t.kind() == SyntaxKind::At))
|
||||||
{
|
{
|
||||||
return Some(vec![CompletionItem::new_simple("children".into(), String::new())]);
|
return Some(vec![CompletionItem::new_simple("children".into(), String::new())]);
|
||||||
}
|
}
|
||||||
|
|
@ -69,7 +69,7 @@ pub(crate) fn completion_at(
|
||||||
let is_global = node
|
let is_global = node
|
||||||
.parent()
|
.parent()
|
||||||
.and_then(|n| n.child_text(SyntaxKind::Identifier))
|
.and_then(|n| n.child_text(SyntaxKind::Identifier))
|
||||||
.map_or(false, |k| k == "global");
|
.is_some_and(|k| k == "global");
|
||||||
|
|
||||||
// add keywords
|
// add keywords
|
||||||
r.extend(
|
r.extend(
|
||||||
|
|
@ -201,7 +201,7 @@ pub(crate) fn completion_at(
|
||||||
) {
|
) {
|
||||||
if token.kind() == SyntaxKind::At
|
if token.kind() == SyntaxKind::At
|
||||||
|| (token.kind() == SyntaxKind::Identifier
|
|| (token.kind() == SyntaxKind::Identifier
|
||||||
&& token.prev_token().map_or(false, |t| t.kind() == SyntaxKind::At))
|
&& token.prev_token().is_some_and(|t| t.kind() == SyntaxKind::At))
|
||||||
{
|
{
|
||||||
return Some(
|
return Some(
|
||||||
[
|
[
|
||||||
|
|
@ -360,7 +360,7 @@ pub(crate) fn completion_at(
|
||||||
&& offset >= id_range.end()
|
&& offset >= id_range.end()
|
||||||
&& !c
|
&& !c
|
||||||
.children_with_tokens()
|
.children_with_tokens()
|
||||||
.any(|c| c.as_token().map_or(false, |t| t.text() == "inherits"))
|
.any(|c| c.as_token().is_some_and(|t| t.text() == "inherits"))
|
||||||
{
|
{
|
||||||
let mut c = CompletionItem::new_simple("inherits".into(), String::new());
|
let mut c = CompletionItem::new_simple("inherits".into(), String::new());
|
||||||
c.kind = Some(CompletionItemKind::KEYWORD);
|
c.kind = Some(CompletionItemKind::KEYWORD);
|
||||||
|
|
|
||||||
|
|
@ -107,7 +107,7 @@ pub fn get_semantic_tokens(
|
||||||
SyntaxKind::ExportIdentifier => {
|
SyntaxKind::ExportIdentifier => {
|
||||||
Some((
|
Some((
|
||||||
self::TYPE,
|
self::TYPE,
|
||||||
if token.parent().parent().map_or(false, |p| {
|
if token.parent().parent().is_some_and(|p| {
|
||||||
p.children().any(|n| n.kind() == SyntaxKind::ExportName)
|
p.children().any(|n| n.kind() == SyntaxKind::ExportName)
|
||||||
}) {
|
}) {
|
||||||
0
|
0
|
||||||
|
|
@ -119,16 +119,18 @@ pub fn get_semantic_tokens(
|
||||||
SyntaxKind::ExportName => Some((self::TYPE, 1 << self::DECLARATION)),
|
SyntaxKind::ExportName => Some((self::TYPE, 1 << self::DECLARATION)),
|
||||||
SyntaxKind::ImportSpecifier => Some((self::KEYWORD, 0)),
|
SyntaxKind::ImportSpecifier => Some((self::KEYWORD, 0)),
|
||||||
SyntaxKind::ImportIdentifier => Some((self::KEYWORD, 0)),
|
SyntaxKind::ImportIdentifier => Some((self::KEYWORD, 0)),
|
||||||
SyntaxKind::ExternalName => Some((
|
SyntaxKind::ExternalName => {
|
||||||
self::TYPE,
|
Some((
|
||||||
if token.parent().parent().map_or(false, |p| {
|
self::TYPE,
|
||||||
p.children().any(|n| n.kind() == SyntaxKind::InternalName)
|
if token.parent().parent().is_some_and(|p| {
|
||||||
}) {
|
p.children().any(|n| n.kind() == SyntaxKind::InternalName)
|
||||||
0
|
}) {
|
||||||
} else {
|
0
|
||||||
1 << self::DECLARATION
|
} else {
|
||||||
},
|
1 << self::DECLARATION
|
||||||
)),
|
},
|
||||||
|
))
|
||||||
|
}
|
||||||
SyntaxKind::InternalName => Some((self::TYPE, 1 << self::DECLARATION)),
|
SyntaxKind::InternalName => Some((self::TYPE, 1 << self::DECLARATION)),
|
||||||
SyntaxKind::ObjectTypeMember => Some((self::PROPERTY, 1 << self::DEFINITION)),
|
SyntaxKind::ObjectTypeMember => Some((self::PROPERTY, 1 << self::DEFINITION)),
|
||||||
SyntaxKind::StructDeclaration => Some((self::KEYWORD, 0)),
|
SyntaxKind::StructDeclaration => Some((self::KEYWORD, 0)),
|
||||||
|
|
|
||||||
|
|
@ -131,7 +131,7 @@ pub fn lookup_current_element_type(mut node: SyntaxNode, tr: &TypeRegister) -> O
|
||||||
|
|
||||||
let parent = node.parent()?;
|
let parent = node.parent()?;
|
||||||
if parent.kind() == SyntaxKind::Component
|
if parent.kind() == SyntaxKind::Component
|
||||||
&& parent.child_text(SyntaxKind::Identifier).map_or(false, |x| x == "global")
|
&& parent.child_text(SyntaxKind::Identifier).is_some_and(|x| x == "global")
|
||||||
{
|
{
|
||||||
return Some(ElementType::Global);
|
return Some(ElementType::Global);
|
||||||
}
|
}
|
||||||
|
|
@ -202,7 +202,7 @@ pub fn with_property_lookup_ctx<R>(
|
||||||
loop {
|
loop {
|
||||||
scope.push(it.clone());
|
scope.push(it.clone());
|
||||||
if let Some(c) = it.clone().borrow().children.iter().find(|c| {
|
if let Some(c) = it.clone().borrow().children.iter().find(|c| {
|
||||||
c.borrow().debug.first().map_or(false, |n| n.node.text_range().contains(offset))
|
c.borrow().debug.first().is_some_and(|n| n.node.text_range().contains(offset))
|
||||||
}) {
|
}) {
|
||||||
it = c.clone();
|
it = c.clone();
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -239,7 +239,7 @@ pub fn with_property_lookup_ctx<R>(
|
||||||
|
|
||||||
if let Some(cb) = element
|
if let Some(cb) = element
|
||||||
.CallbackConnection()
|
.CallbackConnection()
|
||||||
.find(|p| i_slint_compiler::parser::identifier_text(p).map_or(false, |x| x == prop_name))
|
.find(|p| i_slint_compiler::parser::identifier_text(p).is_some_and(|x| x == prop_name))
|
||||||
{
|
{
|
||||||
lookup_context.arguments = cb
|
lookup_context.arguments = cb
|
||||||
.DeclaredIdentifier()
|
.DeclaredIdentifier()
|
||||||
|
|
@ -247,7 +247,7 @@ pub fn with_property_lookup_ctx<R>(
|
||||||
.collect();
|
.collect();
|
||||||
} else if let Some(f) = element.Function().find(|p| {
|
} else if let Some(f) = element.Function().find(|p| {
|
||||||
i_slint_compiler::parser::identifier_text(&p.DeclaredIdentifier())
|
i_slint_compiler::parser::identifier_text(&p.DeclaredIdentifier())
|
||||||
.map_or(false, |x| x == prop_name)
|
.is_some_and(|x| x == prop_name)
|
||||||
}) {
|
}) {
|
||||||
lookup_context.arguments = f
|
lookup_context.arguments = f
|
||||||
.ArgumentDeclaration()
|
.ArgumentDeclaration()
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ pub(crate) fn fold_node(
|
||||||
let parent = &state.lookup_change.scope[state.lookup_change.scope.len() - 2];
|
let parent = &state.lookup_change.scope[state.lookup_change.scope.len() - 2];
|
||||||
|
|
||||||
if !is_layout_base(parent) && !is_path(elem) && elem.borrow().is_legacy_syntax {
|
if !is_layout_base(parent) && !is_path(elem) && elem.borrow().is_legacy_syntax {
|
||||||
let extend = elem.borrow().builtin_type().map_or(false, |b| {
|
let extend = elem.borrow().builtin_type().is_some_and(|b| {
|
||||||
b.default_size_binding
|
b.default_size_binding
|
||||||
!= i_slint_compiler::langtype::DefaultSizeBinding::ImplicitSize
|
!= i_slint_compiler::langtype::DefaultSizeBinding::ImplicitSize
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -12,13 +12,10 @@ pub(crate) fn fold_node(
|
||||||
_args: &Cli,
|
_args: &Cli,
|
||||||
) -> std::io::Result<bool> {
|
) -> std::io::Result<bool> {
|
||||||
if node.kind() == SyntaxKind::PropertyDeclaration
|
if node.kind() == SyntaxKind::PropertyDeclaration
|
||||||
&& node
|
&& node.parent().and_then(|n| n.parent()).is_some_and(|n| n.kind() == SyntaxKind::Component)
|
||||||
.parent()
|
|
||||||
.and_then(|n| n.parent())
|
|
||||||
.map_or(false, |n| n.kind() == SyntaxKind::Component)
|
|
||||||
{
|
{
|
||||||
// check that the first identifier is "property" as opposed to an already converted "in-out" token
|
// check that the first identifier is "property" as opposed to an already converted "in-out" token
|
||||||
if node.child_token(SyntaxKind::Identifier).map_or(false, |t| t.text() == "property") {
|
if node.child_token(SyntaxKind::Identifier).is_some_and(|t| t.text() == "property") {
|
||||||
// Consider that all property are in-out, because we don't do enough analysis in the slint-updater to know
|
// Consider that all property are in-out, because we don't do enough analysis in the slint-updater to know
|
||||||
// if they should be private
|
// if they should be private
|
||||||
write!(file, "in-out ")?;
|
write!(file, "in-out ")?;
|
||||||
|
|
|
||||||
|
|
@ -45,11 +45,11 @@ pub(crate) fn fold_node(
|
||||||
) -> std::io::Result<bool> {
|
) -> std::io::Result<bool> {
|
||||||
let kind = node.kind();
|
let kind = node.kind();
|
||||||
if kind == SyntaxKind::QualifiedName
|
if kind == SyntaxKind::QualifiedName
|
||||||
&& node.parent().map_or(false, |n| n.kind() == SyntaxKind::Expression)
|
&& node.parent().is_some_and(|n| n.kind() == SyntaxKind::Expression)
|
||||||
{
|
{
|
||||||
return fully_qualify_property_access(node, file, state);
|
return fully_qualify_property_access(node, file, state);
|
||||||
} else if kind == SyntaxKind::Element
|
} else if kind == SyntaxKind::Element
|
||||||
&& node.parent().map_or(false, |n| n.kind() == SyntaxKind::Component)
|
&& node.parent().is_some_and(|n| n.kind() == SyntaxKind::Component)
|
||||||
{
|
{
|
||||||
return move_properties_to_root(node, state, file, args);
|
return move_properties_to_root(node, state, file, args);
|
||||||
} else if kind == SyntaxKind::Element {
|
} else if kind == SyntaxKind::Element {
|
||||||
|
|
@ -64,7 +64,7 @@ pub(crate) fn fold_node(
|
||||||
kind,
|
kind,
|
||||||
SyntaxKind::Binding | SyntaxKind::TwoWayBinding | SyntaxKind::CallbackConnection
|
SyntaxKind::Binding | SyntaxKind::TwoWayBinding | SyntaxKind::CallbackConnection
|
||||||
) && !state.lookup_change.property_mappings.is_empty()
|
) && !state.lookup_change.property_mappings.is_empty()
|
||||||
&& node.parent().map_or(false, |n| n.kind() == SyntaxKind::Element)
|
&& node.parent().is_some_and(|n| n.kind() == SyntaxKind::Element)
|
||||||
{
|
{
|
||||||
if let Some(el) = &state.current_elem {
|
if let Some(el) = &state.current_elem {
|
||||||
let prop_name = i_slint_compiler::parser::normalize_identifier(
|
let prop_name = i_slint_compiler::parser::normalize_identifier(
|
||||||
|
|
@ -139,14 +139,14 @@ fn fully_qualify_property_access(
|
||||||
if state
|
if state
|
||||||
.current_component
|
.current_component
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.map_or(false, |c| Rc::ptr_eq(&element, &c.root_element))
|
.is_some_and(|c| Rc::ptr_eq(&element, &c.root_element))
|
||||||
{
|
{
|
||||||
write!(file, "root.")?;
|
write!(file, "root.")?;
|
||||||
} else if state
|
} else if state
|
||||||
.lookup_change
|
.lookup_change
|
||||||
.scope
|
.scope
|
||||||
.last()
|
.last()
|
||||||
.map_or(false, |e| Rc::ptr_eq(&element, e))
|
.is_some_and(|e| Rc::ptr_eq(&element, e))
|
||||||
{
|
{
|
||||||
if let Some(replace_self) = &state.lookup_change.replace_self {
|
if let Some(replace_self) = &state.lookup_change.replace_self {
|
||||||
write!(file, "{replace_self}.")?;
|
write!(file, "{replace_self}.")?;
|
||||||
|
|
@ -325,11 +325,7 @@ fn ensure_element_has_id(
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn enter_element(state: &mut crate::State) {
|
pub(crate) fn enter_element(state: &mut crate::State) {
|
||||||
if state
|
if state.lookup_change.scope.last().is_some_and(|e| e.borrow().base_type.to_string() == "Path")
|
||||||
.lookup_change
|
|
||||||
.scope
|
|
||||||
.last()
|
|
||||||
.map_or(false, |e| e.borrow().base_type.to_string() == "Path")
|
|
||||||
{
|
{
|
||||||
// Path's sub-elements have strange lookup rules: They are considering self as the Path
|
// Path's sub-elements have strange lookup rules: They are considering self as the Path
|
||||||
state.lookup_change.replace_self = Some("parent".into());
|
state.lookup_change.replace_self = Some("parent".into());
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ pub(crate) fn fold_node(
|
||||||
let kind = node.kind();
|
let kind = node.kind();
|
||||||
if kind == SyntaxKind::Component && node.child_token(SyntaxKind::ColonEqual).is_some() {
|
if kind == SyntaxKind::Component && node.child_token(SyntaxKind::ColonEqual).is_some() {
|
||||||
let is_global =
|
let is_global =
|
||||||
node.child_token(SyntaxKind::Identifier).map_or(false, |t| t.text() == "global");
|
node.child_token(SyntaxKind::Identifier).is_some_and(|t| t.text() == "global");
|
||||||
if !is_global {
|
if !is_global {
|
||||||
write!(file, "component ")?;
|
write!(file, "component ")?;
|
||||||
}
|
}
|
||||||
|
|
@ -22,11 +22,11 @@ pub(crate) fn fold_node(
|
||||||
if n.kind() == SyntaxKind::ColonEqual {
|
if n.kind() == SyntaxKind::ColonEqual {
|
||||||
if !is_global {
|
if !is_global {
|
||||||
let t = n.as_token().unwrap();
|
let t = n.as_token().unwrap();
|
||||||
if t.prev_token().map_or(false, |t| t.kind() != SyntaxKind::Whitespace) {
|
if t.prev_token().is_some_and(|t| t.kind() != SyntaxKind::Whitespace) {
|
||||||
write!(file, " ")?;
|
write!(file, " ")?;
|
||||||
}
|
}
|
||||||
write!(file, "inherits")?;
|
write!(file, "inherits")?;
|
||||||
if t.next_token().map_or(false, |t| t.kind() != SyntaxKind::Whitespace) {
|
if t.next_token().is_some_and(|t| t.kind() != SyntaxKind::Whitespace) {
|
||||||
write!(file, " ")?;
|
write!(file, " ")?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ pub(crate) fn fold_node(
|
||||||
_args: &Cli,
|
_args: &Cli,
|
||||||
) -> std::io::Result<bool> {
|
) -> std::io::Result<bool> {
|
||||||
if let Some(s) = syntax_nodes::CallbackDeclaration::new(node.clone()) {
|
if let Some(s) = syntax_nodes::CallbackDeclaration::new(node.clone()) {
|
||||||
if state.current_elem.as_ref().map_or(false, |e| e.borrow().is_legacy_syntax)
|
if state.current_elem.as_ref().is_some_and(|e| e.borrow().is_legacy_syntax)
|
||||||
&& s.child_text(SyntaxKind::Identifier).as_deref() != Some("pure")
|
&& s.child_text(SyntaxKind::Identifier).as_deref() != Some("pure")
|
||||||
{
|
{
|
||||||
if s.ReturnType().is_some() {
|
if s.ReturnType().is_some() {
|
||||||
|
|
@ -42,7 +42,7 @@ pub(crate) fn fold_node(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if let Some(s) = syntax_nodes::Function::new(node.clone()) {
|
} else if let Some(s) = syntax_nodes::Function::new(node.clone()) {
|
||||||
if state.current_elem.as_ref().map_or(false, |e| e.borrow().is_legacy_syntax)
|
if state.current_elem.as_ref().is_some_and(|e| e.borrow().is_legacy_syntax)
|
||||||
&& s.ReturnType().is_some()
|
&& s.ReturnType().is_some()
|
||||||
{
|
{
|
||||||
let (mut pure, mut public) = (false, false);
|
let (mut pure, mut public) = (false, false);
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ pub(crate) fn fold_node(
|
||||||
if t.state_id == state_id
|
if t.state_id == state_id
|
||||||
&& t.node
|
&& t.node
|
||||||
.parent()
|
.parent()
|
||||||
.map_or(false, |p| p.kind() == SyntaxKind::Transitions)
|
.is_some_and(|p| p.kind() == SyntaxKind::Transitions)
|
||||||
{
|
{
|
||||||
for c in t.node.children_with_tokens() {
|
for c in t.node.children_with_tokens() {
|
||||||
if !matches!(
|
if !matches!(
|
||||||
|
|
|
||||||
|
|
@ -223,10 +223,10 @@ fn visit_node(
|
||||||
.borrow()
|
.borrow()
|
||||||
.children
|
.children
|
||||||
.iter()
|
.iter()
|
||||||
.find(|c| c.borrow().debug.first().map_or(false, |n| n.node.node == node.node))
|
.find(|c| c.borrow().debug.first().is_some_and(|n| n.node.node == node.node))
|
||||||
.cloned()
|
.cloned()
|
||||||
} else if let Some(parent_co) = &state.current_component {
|
} else if let Some(parent_co) = &state.current_component {
|
||||||
if node.parent().map_or(false, |n| n.kind() == SyntaxKind::Component) {
|
if node.parent().is_some_and(|n| n.kind() == SyntaxKind::Component) {
|
||||||
state.current_elem = Some(parent_co.root_element.clone())
|
state.current_elem = Some(parent_co.root_element.clone())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ pub(crate) fn fold_node(
|
||||||
) -> std::io::Result<bool> {
|
) -> std::io::Result<bool> {
|
||||||
let kind = node.kind();
|
let kind = node.kind();
|
||||||
if kind == SyntaxKind::QualifiedName
|
if kind == SyntaxKind::QualifiedName
|
||||||
&& node.parent().map_or(false, |n| n.kind() == SyntaxKind::Expression)
|
&& node.parent().is_some_and(|n| n.kind() == SyntaxKind::Expression)
|
||||||
{
|
{
|
||||||
let q = i_slint_compiler::object_tree::QualifiedTypeName::from_node(node.clone().into())
|
let q = i_slint_compiler::object_tree::QualifiedTypeName::from_node(node.clone().into())
|
||||||
.to_string();
|
.to_string();
|
||||||
|
|
|
||||||
|
|
@ -83,7 +83,7 @@ fn find_licenses_directories(dir: &Path) -> Result<Vec<PathBuf>> {
|
||||||
let dot_name: &OsStr = &OsStr::new(".");
|
let dot_name: &OsStr = &OsStr::new(".");
|
||||||
|
|
||||||
for d in std::fs::read_dir(dir)?
|
for d in std::fs::read_dir(dir)?
|
||||||
.filter(|d| d.as_ref().map_or(false, |e| e.file_type().map_or(false, |f| f.is_dir())))
|
.filter(|d| d.as_ref().is_ok_and(|e| e.file_type().is_ok_and(|f| f.is_dir())))
|
||||||
{
|
{
|
||||||
let path = d?.path();
|
let path = d?.path();
|
||||||
let parent_path = path.parent().expect("This is a subdirectory, so it must have a parent!");
|
let parent_path = path.parent().expect("This is a subdirectory, so it must have a parent!");
|
||||||
|
|
@ -124,7 +124,7 @@ fn populate_license_map(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_symlink(path: &Path) -> bool {
|
fn is_symlink(path: &Path) -> bool {
|
||||||
std::fs::symlink_metadata(path).map_or(false, |m| m.file_type().is_symlink())
|
std::fs::symlink_metadata(path).is_ok_and(|m| m.file_type().is_symlink())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn validate_license_directory(dir: &Path, licenses: &[String], fix_it: bool) -> Result<()> {
|
fn validate_license_directory(dir: &Path, licenses: &[String], fix_it: bool) -> Result<()> {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue