Module px

Source
Expand description

Physical pixel coordinate system for Tessera UI framework.

This module provides types and operations for working with physical pixel coordinates, positions, and sizes. Physical pixels represent actual screen pixels and are used internally by the rendering system.

§Key Types

  • Px - A single physical pixel coordinate value that supports negative values for scrolling
  • PxPosition - A 2D position in physical pixel space (x, y coordinates)
  • PxSize - A 2D size in physical pixel space (width, height dimensions)

§Coordinate System

The coordinate system uses:

  • Origin (0, 0) at the top-left corner
  • X-axis increases to the right
  • Y-axis increases downward
  • Negative coordinates are supported for scrolling and off-screen positioning

§Conversion

Physical pixels can be converted to and from density-independent pixels (Dp):

§Example

use tessera_ui::px::{Px, PxPosition, PxSize};
use tessera_ui::dp::Dp;

// Create pixel values
let x = Px::new(100);
let y = Px::new(200);

// Create a position
let position = PxPosition::new(x, y);

// Create a size
let size = PxSize::new(Px::new(300), Px::new(400));

// Arithmetic operations
let offset_position = position.offset(Px::new(10), Px::new(-5));

// Convert between Dp and Px
let dp_value = Dp::new(16.0);
let px_value = Px::from_dp(dp_value);

Structs§

Px
A physical pixel coordinate value.
PxPosition
A 2D position in physical pixel space.
PxSize
A 2D size in physical pixel space.