What is the Type of length (in px)?

This Q. is very strange for me myself. But...

I have a border radius. Docs say:

Rectangle
border-radius ( length ): The size of the radius. (default value: 0)

When I use it rust works fine:

border-radius: 10px;

But ! When I try replace it with constant, rust-analyzer asks for type:

const MY_CNR = 10px ;
const MY_CNR   :  ???    = ???  ;

It sounds like you have a CSS length. Rust doesn't have any types for CSS in the standard library, so you'll have to tell us what library you are already using for working with CSS. What is the context in which border-radius: 10px; is appearing? Show much more of your code.

7 Likes

Quick google search point out Slint doc. Your mixing two languages.
More likely to get help from one of its contacts.

1 Like

Yes, it is https://slint-ui.com
Slint Memory Game Tutorial (Rust)

The tiles could have rounded corners, to look a little less sharp. The border-radius property of Rectangle can be used to achieve that.

border-radius (length): The size of the radius. (default value: 0)

It is not serious problem. Thank You..

Here's the rust slint documentation for the type mappings:

There they say both logical and physical lengths are mapped as bare f32, that is, 32 bit floating point. You should also not use a px suffix on the value outside of slint!, native Rust doesn't support custom suffixes.

2 Likes

Okay, I have understand, there is no Rust, but unknown language.. Thank you for showing how to work with documentation..

const MY_ANG :  f32 =   10.0/* px  */   ;
border-radius : MY_ANG /* 10px    */ ;   //  my
error: Unknown unqualified identifier 'MY_ANG'
   --> src\main.rs:119:29
    |
119 |             border-radius : MY_ANG /* 10px    */ ;   //  my
    |     

You can't use rust code (so rust contants) directly in the Slint DSL.
I think the way to do what you're doing is with a Slint global property. Something like this:

slint!{
export global Consts := {
   property <length> MY_ANG: 10px;
}
//...
Foo := Rectangle {
   border-radius : Consts.MY_ANG;
}
//...    
}

//...
const MY_ANG : f32 = 10.0;
my_app.global::<Consts>().set_MY_ANG(MY_ANG);

See Global in slint - Rust

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.