Skip to main content

offset_for_center

Function offset_for_center 

Source
pub fn offset_for_center(
    parent: &LayoutRect,
    width: f32,
    height: f32,
    center_x: f32,
    center_y: f32,
) -> (f32, f32)
Expand description

Computes the offset that places a block closest to a target position, as the inverse of place_relative.

§Arguments

  • parent - Rect of the parent block.
  • width - Width of the block being placed.
  • height - Height of the block being placed.
  • center_x - Target X coordinate of the block’s center.
  • center_y - Target Y coordinate of the block’s center.

§Returns

The X and Y offsets. Axes on which the target overlaps the parent get a 0 offset, centering the block on the parent.