Make conversion from float to int property truncate

- Make sure that in Rust and C++ we also truncate if the properties are
inlined
 - Change the interpreter to truncate

This is a redo of commit f5d003d but truncate instead of round

fixes #5689
This commit is contained in:
Olivier Goffart 2024-08-10 14:51:05 +02:00 committed by GitHub
parent 8e51563609
commit 51481b101c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 59 additions and 9 deletions

View file

@ -2768,11 +2768,14 @@ fn compile_expression(expr: &llr::Expression, ctx: &EvaluationContext) -> String
Expression::Cast { from, to } => {
let f = compile_expression(from, ctx);
match (from.ty(ctx), to) {
(Type::Float32, Type::Int32) => {
format!("static_cast<int>({f})")
}
(from, Type::String) if from.as_unit_product().is_some() => {
format!("slint::SharedString::from_number({})", f)
}
(Type::Float32, Type::Model) | (Type::Int32, Type::Model) => {
format!("std::make_shared<slint::private_api::UIntModel>(std::max(0, {}))", f)
format!("std::make_shared<slint::private_api::UIntModel>(std::max<int>(0, {}))", f)
}
(Type::Array(_), Type::Model) => f,
(Type::Float32, Type::Color) => {