@@ -466,7 +466,7 @@ pub(super) fn get_properties(
466466 group_priority : depth,
467467 } ) ;
468468
469- if b. name == "Image" {
469+ if b. name == "Image" || b . name == "Text" {
470470 result. extend ( get_reserved_properties (
471471 & b. name ,
472472 depth,
@@ -475,6 +475,18 @@ pub(super) fn get_properties(
475475 . cloned ( ) ,
476476 ) ) ;
477477 }
478+
479+ if matches ! ( b. name. as_str( ) , "GridLayout" | "HorizontalLayout" | "VerticalLayout" ) {
480+ // Add the padding that is otherwise filtered out
481+ result. extend ( get_reserved_properties (
482+ & b. name ,
483+ depth,
484+ i_slint_compiler:: typeregister:: RESERVED_LAYOUT_PROPERTIES
485+ . iter ( )
486+ . filter ( |x| x. 0 . starts_with ( "padding" ) )
487+ . cloned ( ) ,
488+ ) ) ;
489+ }
478490 }
479491 ElementType :: Global => {
480492 break ;
@@ -506,14 +518,17 @@ pub(super) fn get_properties(
506518 p
507519 } ) ,
508520 ) ;
521+
509522 result. extend (
510523 get_reserved_properties (
511524 "layout" ,
512525 depth + 2000 ,
513- i_slint_compiler:: typeregister:: RESERVED_LAYOUT_PROPERTIES . iter ( ) . cloned ( ) ,
526+ i_slint_compiler:: typeregister:: RESERVED_LAYOUT_PROPERTIES
527+ . iter ( )
528+ // padding for non-layout items is not yet implemented
529+ . filter ( |x| !x. 0 . starts_with ( "padding" ) )
530+ . cloned ( ) ,
514531 )
515- // padding arbitrary items is not yet implemented
516- . filter ( |x| !x. name . starts_with ( "padding" ) )
517532 . map ( |mut p| {
518533 match p. name . as_str ( ) {
519534 "min-width" => p. priority = 200 ,
@@ -1493,6 +1508,83 @@ component MainWindow inherits Window {
14931508 assert_eq ! ( foo_property. group, "Base1" ) ;
14941509 }
14951510
1511+ #[ test]
1512+ fn layout_padding ( ) {
1513+ let ( dc, url, _) = loaded_document_cache (
1514+ r#"import { LineEdit, Button, Slider, HorizontalBox, VerticalBox } from "std-widgets.slint";
1515+
1516+ component CustomL inherits HorizontalLayout {
1517+ padding-left: 10px;
1518+ @children
1519+ }
1520+
1521+ component MainWindow inherits Window {
1522+ rect1 := Rectangle {
1523+ lay1 := CustomL {
1524+ Button { text: "Button"; }
1525+ err := Error {}
1526+ Rectangle {}
1527+ lay2 := VerticalLayout {
1528+ Slider { value: 0.5; }
1529+ Button { text: "Button"; }
1530+ }
1531+ lay3 := VerticalBox {
1532+ slider2 := Slider { value: 0.5; }
1533+ Rectangle {}
1534+ }
1535+ }
1536+ }
1537+ }
1538+ "# . to_string ( ) ) ;
1539+
1540+ let doc = dc. get_document ( & url) . unwrap ( ) ;
1541+ let source = & doc. node . as_ref ( ) . unwrap ( ) . source_file ;
1542+ let ( l, c) = source. line_column ( source. source ( ) . unwrap ( ) . find ( "lay1 :=" ) . unwrap ( ) ) ;
1543+ let ( _, result) = properties_at_position_in_cache ( l as u32 , c as u32 , & dc, & url) . unwrap ( ) ;
1544+ let property = find_property ( & result, "padding" ) . unwrap ( ) ;
1545+ assert_eq ! ( property. ty, Type :: LogicalLength ) ;
1546+ let property = find_property ( & result, "padding-left" ) . unwrap ( ) ;
1547+ assert_eq ! ( property. ty, Type :: LogicalLength ) ;
1548+ let property = find_property ( & result, "padding-top" ) . unwrap ( ) ;
1549+ assert_eq ! ( property. ty, Type :: LogicalLength ) ;
1550+
1551+ let ( l, c) = source. line_column ( source. source ( ) . unwrap ( ) . find ( "lay2 :=" ) . unwrap ( ) ) ;
1552+ let ( _, result) = properties_at_position_in_cache ( l as u32 , c as u32 , & dc, & url) . unwrap ( ) ;
1553+ let property = find_property ( & result, "padding" ) . unwrap ( ) ;
1554+ assert_eq ! ( property. ty, Type :: LogicalLength ) ;
1555+ let property = find_property ( & result, "padding-left" ) . unwrap ( ) ;
1556+ assert_eq ! ( property. ty, Type :: LogicalLength ) ;
1557+ let property = find_property ( & result, "padding-top" ) . unwrap ( ) ;
1558+ assert_eq ! ( property. ty, Type :: LogicalLength ) ;
1559+
1560+ let ( l, c) = source. line_column ( source. source ( ) . unwrap ( ) . find ( "lay3 :=" ) . unwrap ( ) ) ;
1561+ let ( _, result) = properties_at_position_in_cache ( l as u32 , c as u32 , & dc, & url) . unwrap ( ) ;
1562+ let property = find_property ( & result, "padding" ) . unwrap ( ) ;
1563+ assert_eq ! ( property. ty, Type :: LogicalLength ) ;
1564+ let property = find_property ( & result, "padding-left" ) . unwrap ( ) ;
1565+ assert_eq ! ( property. ty, Type :: LogicalLength ) ;
1566+ let property = find_property ( & result, "padding-top" ) . unwrap ( ) ;
1567+ assert_eq ! ( property. ty, Type :: LogicalLength ) ;
1568+
1569+ let ( l, c) = source. line_column ( source. source ( ) . unwrap ( ) . find ( "rect1 :=" ) . unwrap ( ) ) ;
1570+ let ( _, result) = properties_at_position_in_cache ( l as u32 , c as u32 , & dc, & url) . unwrap ( ) ;
1571+ assert ! ( find_property( & result, "padding" ) . is_none( ) ) ;
1572+ assert ! ( find_property( & result, "padding-left" ) . is_none( ) ) ;
1573+ assert ! ( find_property( & result, "padding-top" ) . is_none( ) ) ;
1574+
1575+ let ( l, c) = source. line_column ( source. source ( ) . unwrap ( ) . find ( "slider2 :=" ) . unwrap ( ) ) ;
1576+ let ( _, result) = properties_at_position_in_cache ( l as u32 , c as u32 , & dc, & url) . unwrap ( ) ;
1577+ assert ! ( find_property( & result, "padding" ) . is_none( ) ) ;
1578+ assert ! ( find_property( & result, "padding-left" ) . is_none( ) ) ;
1579+ assert ! ( find_property( & result, "padding-top" ) . is_none( ) ) ;
1580+
1581+ let ( l, c) = source. line_column ( source. source ( ) . unwrap ( ) . find ( "err :=" ) . unwrap ( ) ) ;
1582+ let ( _, result) = properties_at_position_in_cache ( l as u32 , c as u32 , & dc, & url) . unwrap ( ) ;
1583+ assert ! ( dbg!( find_property( & result, "padding" ) ) . is_none( ) ) ;
1584+ assert ! ( find_property( & result, "padding-left" ) . is_none( ) ) ;
1585+ assert ! ( find_property( & result, "padding-top" ) . is_none( ) ) ;
1586+ }
1587+
14961588 #[ test]
14971589 fn test_invalid_properties ( ) {
14981590 let ( dc, url, _) = loaded_document_cache (
0 commit comments