#[repr(transparent)]pub struct DevicePixels(pub i32);Expand description
重导出几何类型(Point、Size、Bounds 等) 表示显示设备上的物理像素。
DevicePixels 是一个度量单位,指设备屏幕上的实际像素。
此类型用于需要精确像素操作的场景,如渲染图形或与在像素级别操作的硬件交互。
与可能受设备缩放因子影响的逻辑像素不同,DevicePixels 始终对应显示设备上的真实像素。
Tuple Fields§
§0: i32Implementations§
Source§impl DevicePixels
impl DevicePixels
Sourcepub fn to_bytes(self, bytes_per_pixel: u8) -> u32
pub fn to_bytes(self, bytes_per_pixel: u8) -> u32
将 DevicePixels 值转换为内存中表示所需的字节数。
此函数在处理需要存储在缓冲区中的图形数据时很有用, 如图像或帧缓冲区,其中每个像素可能由特定字节数表示。
§参数
bytes_per_pixel- 表示单个像素所用的字节数。
§返回值
内存中表示 DevicePixels 值所需的字节数。
§示例
let pixels = DevicePixels(10); // 10 个设备像素
let bytes_per_pixel = 4; // 假设每个像素由 4 字节表示(如 RGBA)
let total_bytes = pixels.to_bytes(bytes_per_pixel);
assert_eq!(total_bytes, 40); // 10 像素 * 4 字节/像素 = 40 字节Trait Implementations§
Source§impl Add for DevicePixels
impl Add for DevicePixels
Source§impl AddAssign for DevicePixels
impl AddAssign for DevicePixels
Source§fn add_assign(&mut self, __rhs: Self)
fn add_assign(&mut self, __rhs: Self)
Performs the
+= operation. Read moreSource§impl Clone for DevicePixels
impl Clone for DevicePixels
impl Copy for DevicePixels
Source§impl Debug for DevicePixels
impl Debug for DevicePixels
Source§impl Default for DevicePixels
impl Default for DevicePixels
Source§impl<'de> Deserialize<'de> for DevicePixels
impl<'de> Deserialize<'de> for DevicePixels
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl<__derive_more_Rhs> Div<__derive_more_Rhs> for DevicePixels
impl<__derive_more_Rhs> Div<__derive_more_Rhs> for DevicePixels
impl Eq for DevicePixels
Source§impl From<DevicePixels> for i32
impl From<DevicePixels> for i32
Source§fn from(device_pixels: DevicePixels) -> Self
fn from(device_pixels: DevicePixels) -> Self
Converts to this type from the input type.
Source§impl From<DevicePixels> for u32
impl From<DevicePixels> for u32
Source§fn from(device_pixels: DevicePixels) -> Self
fn from(device_pixels: DevicePixels) -> Self
Converts to this type from the input type.
Source§impl From<DevicePixels> for u64
impl From<DevicePixels> for u64
Source§fn from(device_pixels: DevicePixels) -> Self
fn from(device_pixels: DevicePixels) -> Self
Converts to this type from the input type.
Source§impl From<DevicePixels> for usize
impl From<DevicePixels> for usize
Source§fn from(device_pixels: DevicePixels) -> Self
fn from(device_pixels: DevicePixels) -> Self
Converts to this type from the input type.
Source§impl From<DevicePixels> for ScaledPixels
impl From<DevicePixels> for ScaledPixels
Source§fn from(device: DevicePixels) -> Self
fn from(device: DevicePixels) -> Self
Converts to this type from the input type.
Source§impl From<ScaledPixels> for DevicePixels
impl From<ScaledPixels> for DevicePixels
Source§fn from(scaled: ScaledPixels) -> Self
fn from(scaled: ScaledPixels) -> Self
Converts to this type from the input type.
Source§impl From<i32> for DevicePixels
impl From<i32> for DevicePixels
Source§impl From<u32> for DevicePixels
impl From<u32> for DevicePixels
Source§impl From<u64> for DevicePixels
impl From<u64> for DevicePixels
Source§impl From<usize> for DevicePixels
impl From<usize> for DevicePixels
Source§impl Hash for DevicePixels
impl Hash for DevicePixels
Source§impl Ord for DevicePixels
impl Ord for DevicePixels
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§fn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the minimum of two values. Read more
Source§impl PartialEq for DevicePixels
impl PartialEq for DevicePixels
Source§impl PartialOrd for DevicePixels
impl PartialOrd for DevicePixels
Source§impl Serialize for DevicePixels
impl Serialize for DevicePixels
impl StructuralPartialEq for DevicePixels
Source§impl Sub for DevicePixels
impl Sub for DevicePixels
Source§impl SubAssign for DevicePixels
impl SubAssign for DevicePixels
Source§fn sub_assign(&mut self, __rhs: Self)
fn sub_assign(&mut self, __rhs: Self)
Performs the
-= operation. Read moreAuto Trait Implementations§
impl Forget for DevicePixels
impl Freeze for DevicePixels
impl Move for DevicePixels
impl RefUnwindSafe for DevicePixels
impl Send for DevicePixels
impl Sync for DevicePixels
impl Unpin for DevicePixels
impl UnsafeUnpin for DevicePixels
impl UnwindSafe for DevicePixels
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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