Module px

Module px 

Source
Expand description

§Physical Pixel Types

§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):

From & Into traits are also implemented for seamless conversion between Px and Dp.

§Example

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

// 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(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.
PxRect
A 2D rectangle in physical pixel space.
PxSize
A 2D size in physical pixel space.