Skip to content

Possibly outdated examples: LayoutSize should be equal to DeviceSize in value? #4759

Open
@ruifengx

Description

@ruifengx

I am currently experimenting with WebRender, and I am following the examples. Specifically, I replicated the logic in examples/boilerplate.rs and had some problems with the following line:

let layout_size = device_size.to_f32() / euclid::Scale::new(device_pixel_ratio);

Since methods like DisplayListBuilder::push_rect accepts LayoutSize as well, I presume that they should also be scaled in the same manner. Here is what my toy example looks like (on Windows 11):

scale = 1.5 scale = 1.0
Scale NoScale

Note: 1.5 is the system scale factor. The two versions differ in the way DeviceSize is transformed into LayoutSize. The left one uses Scale::new(window.scale_factor() as f32), and the right one uses Scale::identity().

The reddish rectangle has bounds LayoutRect::from_size(layout_size), and the text is laid out with the same bounds. It should be clear from the screenshot that in the scale = 1.0 version the rectangle is correctly covering the whole window, while the scale = 1.5 version is incorrectly scaled down.

Searching in this repository I found 25f674b, where the device_pixel_ratio option is removed from WebRenderOptions, and uses of such value is replaced by a hardcoded 1.0.

Now I wonder, is the examples doing the correct thing? To add to the point, I see an extremely large window (larger than my screen so I cannot take a screenshot) when I cargo run --bin basic. Could someone please educate me on this LayoutSize/DeviceSize/Scale situation? Thanks in advance!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions