slint-ui / slint

Slint is a declarative GUI toolkit to build native user interfaces for Rust, C++, or JavaScript apps.
https://slint.dev
Other
17.07k stars 573 forks source link

The button component cannot be displayed in Chinese #5456

Closed rulongche closed 2 months ago

rulongche commented 3 months ago

After setting the height of the button component, the preview display is normal, but the Chinese language cannot be displayed after publication Button { text: "复制"; height: 24px; } screenshot-20240622-180601

ogoffart commented 3 months ago

Thanks for filling an issue. Looks like a font problem. What platform and renderer are you using?

humbinal commented 2 months ago

Thanks for filling an issue. Looks like a font problem. What platform and renderer are you using?

I had the same problem, windows and winit renderer.

tronical commented 2 months ago

I think I can reproduce this. Here's a simpler test case:

import { Slider } from "std-widgets.slint";
export component Demo {
    width: 200px;
    height: 200px;
    Text {
        x: 50px;
        y: 50px;
        text: "Hello";
        height: sl.value * 1px;
    }

    sl := Slider {
        width: 100%;
        y: parent.height - self.height;
        value: 10;
        minimum: 8;
        maximum: 64;
    }
}

Observe how the text of the button appears and disappears depending on the height. When a Text element does not have sufficient height to display the text, it will not render anything.

In your case, as it happens, the height is insufficient for the font selected to display the Chinese text - I suspect the ascent/descent is just above the 24px you specify.

I recommend placing widgets into layouts and letting them resize based on their minimum size, instead of hard-coding a specific height. That way the application also works well when users have bigger font sizes configured on their system, for example, for improved readability.

tronical commented 2 months ago

Duplicate of #2029