Skip to content

Question: why layout values are rounded? #77

@twop

Description

@twop

Just spent an hour debugging why the leaf node I measured is set to 63.0 when my measure function returned 63.375

When I looked at the sources I found the explicit rounding in the algo.rs

fn round_layout(
    nodes: &mut [NodeData],
    children: &[sys::ChildrenVec<NodeId>],
    root: NodeId,
    abs_x: f32,
    abs_y: f32,
) {
    let layout = &mut nodes[root].layout;
    let abs_x = abs_x + layout.location.x;
    let abs_y = abs_y + layout.location.y;

    layout.location.x = sys::round(layout.location.x);
    layout.location.y = sys::round(layout.location.y);

    layout.size.width = sys::round(abs_x + layout.size.width) - sys::round(abs_x);
    layout.size.height = sys::round(abs_y + layout.size.height) - sys::round(abs_y);

    for child in &children[root] {
        Self::round_layout(nodes, children, *child, abs_x, abs_y);
    }
}

I couldn't find any mentions why the rounding is needed, thus I'm curious. It seems to be 100% intentional. Maybe add an explanation in the code annotations?

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingwontfixThis will not be worked on

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions