@@ -308,6 +308,9 @@ fn try_inline_builtin_function(
308308 let num = |n : f64 | Some ( Expression :: NumberLiteral ( n, Unit :: None ) ) ;
309309
310310 match b {
311+ BuiltinFunction :: GetWindowScaleFactor => {
312+ ga. const_scale_factor . map ( |factor| Expression :: NumberLiteral ( factor as _ , Unit :: None ) )
313+ }
311314 BuiltinFunction :: GetWindowDefaultFontSize => match ga. default_font_size {
312315 crate :: passes:: binding_analysis:: DefaultFontSize :: LogicalValue ( val) => {
313316 Some ( Expression :: NumberLiteral ( val as _ , Unit :: Px ) )
@@ -484,3 +487,35 @@ export component Foo inherits Window {{
484487 check_expression ( & out1_binding) ;
485488 }
486489}
490+
491+ #[ test]
492+ fn test_const_scale_factor ( ) {
493+ let source = r#"
494+ export component Foo inherits Window {
495+ out property <length> test: 10phx;
496+ }"# ;
497+
498+ let mut test_diags = crate :: diagnostics:: BuildDiagnostics :: default ( ) ;
499+ let doc_node = crate :: parser:: parse (
500+ source. to_string ( ) ,
501+ Some ( std:: path:: Path :: new ( "HELLO" ) ) ,
502+ & mut test_diags,
503+ ) ;
504+ let mut compiler_config =
505+ crate :: CompilerConfiguration :: new ( crate :: generator:: OutputFormat :: Interpreter ) ;
506+ compiler_config. style = Some ( "fluent" . into ( ) ) ;
507+ compiler_config. const_scale_factor = Some ( 2. ) ;
508+ let ( doc, diag, _) =
509+ spin_on:: spin_on ( crate :: compile_syntax_node ( doc_node, test_diags, compiler_config) ) ;
510+ assert ! ( !diag. has_errors( ) , "slint compile error {:#?}" , diag. to_string_vec( ) ) ;
511+
512+ let bindings = & doc. inner_components . last ( ) . unwrap ( ) . root_element . borrow ( ) . bindings ;
513+ let mut test_binding = bindings. get ( "test" ) . unwrap ( ) . borrow ( ) . expression . clone ( ) ;
514+ if let Expression :: Cast { from, to : _ } = test_binding {
515+ test_binding = * from;
516+ }
517+ assert ! (
518+ matches!( test_binding, Expression :: NumberLiteral ( val, _) if val == 5.0 ) ,
519+ "Expression should be 5.0: {test_binding:?}"
520+ ) ;
521+ }
0 commit comments