mirror of
https://github.com/slint-ui/slint.git
synced 2025-08-02 01:43:25 +00:00

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 ```
43 lines
1.7 KiB
Rust
43 lines
1.7 KiB
Rust
// Copyright © SixtyFPS GmbH <info@slint.dev>
|
|
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0
|
|
|
|
//! Passe lower the access to the global TextInputInterface.text-input-focused to getter or setter.
|
|
|
|
use crate::expression_tree::{BuiltinFunction, Expression};
|
|
use crate::namedreference::NamedReference;
|
|
use crate::object_tree::{visit_all_expressions, Component};
|
|
use std::rc::Rc;
|
|
|
|
pub fn lower_text_input_interface(component: &Rc<Component>) {
|
|
visit_all_expressions(component, |e, _| {
|
|
e.visit_recursive_mut(&mut |e| match e {
|
|
Expression::PropertyReference(nr) if is_input_text_focused_prop(nr) => {
|
|
*e = Expression::FunctionCall {
|
|
function: BuiltinFunction::TextInputFocused.into(),
|
|
arguments: vec![],
|
|
source_location: None,
|
|
};
|
|
}
|
|
Expression::SelfAssignment{ lhs, rhs, .. } => {
|
|
if matches!(&**lhs, Expression::PropertyReference(nr) if is_input_text_focused_prop(nr) ) {
|
|
let rhs = std::mem::take(&mut **rhs);
|
|
*e = Expression::FunctionCall {
|
|
function: BuiltinFunction::SetTextInputFocused.into(),
|
|
arguments: vec![rhs],
|
|
source_location: None,
|
|
};
|
|
}
|
|
|
|
}
|
|
_ => {}
|
|
})
|
|
})
|
|
}
|
|
|
|
fn is_input_text_focused_prop(nr: &NamedReference) -> bool {
|
|
if !nr.element().borrow().builtin_type().is_some_and(|bt| bt.name == "TextInputInterface") {
|
|
return false;
|
|
}
|
|
assert_eq!(nr.name(), "text-input-focused");
|
|
true
|
|
}
|