Skip to content

0.15 Migration Guide: Provide examples for creating Rect with logical values (missing logical_rect method on Node - also see PR 15163 and PR 16375) #1920

Open
@janriemer

Description

@janriemer

Problem

From 0.14 -> 015 there are two changes that have led to my (toy) project being broken and I couldn't figure out for a while why it broke (⚠ I'm very new to GameDev and Bevy).

  • the first change, introduced in PR 16375, states that ComputedNode’s fields and methods now use physical coordinates, instead of logical coordinates and by multiplying the physical coordinates by the inverse_scale_factor will give the logical values.
  • the second change introduced in PR 15163, states that methods logical_rect and physical_rect have been removed from Node

IMHO, we should provide examples on how to reimplement logical_rect for oneself, if one decides that it is a useful method to have (I've done this now after migrating from 0.12. -> 0.15 by implementing an extension trait on Node).

Also both changes mentioned above should reference each other, because one change alone would probably have a small breaking impact, but in combination they have high potential for "invisibly" breaking apps (aka no compile errors, but wrong logic).

Proposed solution

An example that we should provide in migration guide for PR 15163, while referencing the other changes regarding ComputedNode:

0.14:

fn my_system(q_nodes: Query<&Node, &GlobalTransform>) {
    for (node, g_trans) in &q_nodes {
        let logical_rect = node.logical_rect(g_trans);
    }
}

0.15:

fn my_system(q_nodes: Query<&Node, &ComputedNode, &GlobalTransform>) {
    for (node, comp_node, g_trans) in &q_nodes {
        let logical_rect = Rect::from_center_size(
            // we convert both values to their logical values
            g_trans.translation.xy() * comp_node.inverse_scale_factor(),
            comp_node.size() * comp_node.inverse_scale_factor());
    }
}

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