Struct PxPosition

Source
pub struct PxPosition {
    pub x: Px,
    pub y: Px,
}
Expand description

A 2D position in physical pixel space.

This type represents a position with x and y coordinates in physical pixel space. Physical pixels correspond directly to screen pixels and are used internally by the rendering system.

§Coordinate System

  • Origin (0, 0) is 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

§Examples

use tessera_ui::px::{Px, PxPosition};

// Create a position
let position = PxPosition::new(Px::new(100), Px::new(200));

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

// Calculate distance between positions
let other_position = PxPosition::new(Px::new(103), Px::new(196));
let distance = position.distance_to(other_position);

// Arithmetic operations
let sum = position + other_position;
let diff = position - other_position;

Fields§

§x: Px

The x-coordinate in physical pixels

§y: Px

The y-coordinate in physical pixels

Implementations§

Source§

impl PxPosition

Source

pub const ZERO: Self

A constant representing the zero position (0, 0).

Source

pub const fn new(x: Px, y: Px) -> Self

Creates a new position from x and y coordinates.

§Arguments
  • x - The x-coordinate in physical pixels
  • y - The y-coordinate in physical pixels
§Examples
use tessera_ui::px::{Px, PxPosition};

let position = PxPosition::new(Px::new(100), Px::new(200));
assert_eq!(position.x, Px::new(100));
assert_eq!(position.y, Px::new(200));
Source

pub fn offset(self, dx: Px, dy: Px) -> Self

Offsets the position by the given deltas.

§Panics

This function may panic on overflow in debug builds.

§Arguments
  • dx - The x-axis offset in physical pixels
  • dy - The y-axis offset in physical pixels
§Examples
use tessera_ui::px::{Px, PxPosition};

let position = PxPosition::new(Px::new(10), Px::new(20));
let offset_position = position.offset(Px::new(5), Px::new(-3));
assert_eq!(offset_position, PxPosition::new(Px::new(15), Px::new(17)));
Source

pub fn saturating_offset(self, dx: Px, dy: Px) -> Self

Offsets the position with saturating arithmetic.

This prevents overflow by clamping the result to the valid coordinate range.

§Arguments
  • dx - The x-axis offset in physical pixels
  • dy - The y-axis offset in physical pixels
§Examples
use tessera_ui::px::{Px, PxPosition};

let position = PxPosition::new(Px::new(10), Px::new(20));
let offset_position = position.saturating_offset(Px::new(5), Px::new(-3));
assert_eq!(offset_position, PxPosition::new(Px::new(15), Px::new(17)));

// Prevents overflow
let max_position = PxPosition::new(Px::new(i32::MAX), Px::new(i32::MAX));
let safe_offset = max_position.saturating_offset(Px::new(1), Px::new(1));
assert_eq!(safe_offset, max_position);
Source

pub fn distance_to(self, other: Self) -> f32

Calculates the Euclidean distance to another position.

§Arguments
  • other - The other position to calculate distance to
§Returns

The distance as a floating-point value

§Examples
use tessera_ui::px::{Px, PxPosition};

let pos1 = PxPosition::new(Px::new(0), Px::new(0));
let pos2 = PxPosition::new(Px::new(3), Px::new(4));
assert_eq!(pos1.distance_to(pos2), 5.0);
Source

pub fn to_f32_arr2(self) -> [f32; 2]

Converts the position to a 2D f32 array.

§Returns

An array [x, y] where both coordinates are converted to f32

§Examples
use tessera_ui::px::{Px, PxPosition};

let position = PxPosition::new(Px::new(10), Px::new(20));
assert_eq!(position.to_f32_arr2(), [10.0, 20.0]);
Source

pub fn to_f32_arr3(self) -> [f32; 3]

Converts the position to a 3D f32 array with z=0.

§Returns

An array [x, y, 0.0] where x and y are converted to f32 and z is 0.0

§Examples
use tessera_ui::px::{Px, PxPosition};

let position = PxPosition::new(Px::new(10), Px::new(20));
assert_eq!(position.to_f32_arr3(), [10.0, 20.0, 0.0]);
Source

pub fn from_f32_arr2(arr: [f32; 2]) -> Self

Creates a position from a 2D f32 array.

§Arguments
  • arr - An array [x, y] where both values will be converted to i32
§Examples
use tessera_ui::px::{Px, PxPosition};

let position = PxPosition::from_f32_arr2([10.5, 20.7]);
assert_eq!(position, PxPosition::new(Px::new(10), Px::new(20)));
Source

pub fn from_f32_arr3(arr: [f32; 3]) -> Self

Creates a position from a 3D f32 array, ignoring the z component.

§Arguments
  • arr - An array [x, y, z] where only x and y are used
§Examples
use tessera_ui::px::{Px, PxPosition};

let position = PxPosition::from_f32_arr3([10.5, 20.7, 30.9]);
assert_eq!(position, PxPosition::new(Px::new(10), Px::new(20)));
Source

pub fn to_f64_arr2(self) -> [f64; 2]

Converts the position to a 2D f64 array.

§Returns

An array [x, y] where both coordinates are converted to f64

§Examples
use tessera_ui::px::{Px, PxPosition};

let position = PxPosition::new(Px::new(10), Px::new(20));
assert_eq!(position.to_f64_arr2(), [10.0, 20.0]);
Source

pub fn to_f64_arr3(self) -> [f64; 3]

Converts the position to a 3D f64 array with z=0.

§Returns

An array [x, y, 0.0] where x and y are converted to f64 and z is 0.0

§Examples
use tessera_ui::px::{Px, PxPosition};

let position = PxPosition::new(Px::new(10), Px::new(20));
assert_eq!(position.to_f64_arr3(), [10.0, 20.0, 0.0]);
Source

pub fn from_f64_arr2(arr: [f64; 2]) -> Self

Creates a position from a 2D f64 array.

§Arguments
  • arr - An array [x, y] where both values will be converted to i32
§Examples
use tessera_ui::px::{Px, PxPosition};

let position = PxPosition::from_f64_arr2([10.5, 20.7]);
assert_eq!(position, PxPosition::new(Px::new(10), Px::new(20)));
Source

pub fn from_f64_arr3(arr: [f64; 3]) -> Self

Creates a position from a 3D f64 array, ignoring the z component.

§Arguments
  • arr - An array [x, y, z] where only x and y are used
§Examples
use tessera_ui::px::{Px, PxPosition};

let position = PxPosition::from_f64_arr3([10.5, 20.7, 30.9]);
assert_eq!(position, PxPosition::new(Px::new(10), Px::new(20)));

Trait Implementations§

Source§

impl Add for PxPosition

Source§

type Output = PxPosition

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Self) -> Self::Output

Performs the + operation. Read more
Source§

impl Clone for PxPosition

Source§

fn clone(&self) -> PxPosition

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for PxPosition

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<[Px; 2]> for PxPosition

Source§

fn from(pos: [Px; 2]) -> Self

Converts to this type from the input type.
Source§

impl From<[i32; 2]> for PxPosition

Source§

fn from(pos: [i32; 2]) -> Self

Converts to this type from the input type.
Source§

impl From<[u32; 2]> for PxPosition

Source§

fn from(pos: [u32; 2]) -> Self

Converts to this type from the input type.
Source§

impl From<PxPosition> for [Px; 2]

Source§

fn from(pos: PxPosition) -> Self

Converts to this type from the input type.
Source§

impl From<PxPosition> for [i32; 2]

Source§

fn from(pos: PxPosition) -> Self

Converts to this type from the input type.
Source§

impl From<PxPosition> for [u32; 2]

Source§

fn from(pos: PxPosition) -> Self

Converts to this type from the input type.
Source§

impl From<PxPosition> for PhysicalPosition<i32>

Source§

fn from(pos: PxPosition) -> Self

Converts to this type from the input type.
Source§

impl From<PxPosition> for Position

Source§

fn from(pos: PxPosition) -> Self

Converts to this type from the input type.
Source§

impl Hash for PxPosition

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for PxPosition

Source§

fn eq(&self, other: &PxPosition) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Sub for PxPosition

Source§

type Output = PxPosition

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Self) -> Self::Output

Performs the - operation. Read more
Source§

impl Copy for PxPosition

Source§

impl Eq for PxPosition

Source§

impl StructuralPartialEq for PxPosition

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> AsAny for T
where T: Any,

Source§

fn as_any(&self) -> &(dyn Any + 'static)

Returns a reference to the concrete type as &dyn Any.
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
§

impl<T> Downcast<T> for T

§

fn downcast(&self) -> &T

§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> Upcast<T> for T

§

fn upcast(&self) -> Option<&T>

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<T> WasmNotSend for T
where T: Send,

§

impl<T> WasmNotSendSync for T
where T: WasmNotSend + WasmNotSync,

§

impl<T> WasmNotSync for T
where T: Sync,