pub struct Pixels(/* private fields */);Expand description
Represents a length in pixels, the base unit of measurement in the UI framework.
Pixels is a value type that represents an absolute length in pixels, which is used
for specifying sizes, positions, and distances in the UI. It is the fundamental unit
of measurement for all visual elements and layout calculations.
The inner value is an f32, allowing for sub-pixel precision which can be useful for
anti-aliasing and animations. However, when applied to actual pixel grids, the value
is typically rounded to the nearest integer.
§Examples
use gpui::{Pixels, ScaledPixels};
// Define a length of 10 pixels
let length = Pixels::from(10.0);
// Define a length and scale it by a factor of 2
let scaled_length = length.scale(2.0);
assert_eq!(scaled_length, ScaledPixels::from(20.0));Implementations§
Source§impl Pixels
impl Pixels
Sourcepub fn floor(&self) -> Pixels
pub fn floor(&self) -> Pixels
Floors the Pixels value to the nearest whole number.
§Returns
Returns a new Pixels instance with the floored value.
Sourcepub fn round(&self) -> Pixels
pub fn round(&self) -> Pixels
Rounds the Pixels value to the nearest whole number.
§Returns
Returns a new Pixels instance with the rounded value.
Sourcepub fn ceil(&self) -> Pixels
pub fn ceil(&self) -> Pixels
Returns the ceiling of the Pixels value to the nearest whole number.
§Returns
Returns a new Pixels instance with the ceiling value.
Sourcepub fn scale(&self, factor: f32) -> ScaledPixels
pub fn scale(&self, factor: f32) -> ScaledPixels
Scales the Pixels value by a given factor, producing ScaledPixels.
This method is used when adjusting pixel values for display scaling factors, such as high DPI (dots per inch) or Retina displays, where the pixel density is higher and thus requires scaling to maintain visual consistency and readability.
The resulting ScaledPixels represent the scaled value which can be used for rendering
calculations where display scaling is considered.
Sourcepub fn abs(&self) -> Pixels
pub fn abs(&self) -> Pixels
Returns the absolute value of the Pixels.
§Returns
A new Pixels instance with the absolute value of the original Pixels.
Trait Implementations§
Source§impl AddAssign for Pixels
impl AddAssign for Pixels
Source§fn add_assign(&mut self, __rhs: Pixels)
fn add_assign(&mut self, __rhs: Pixels)
+= operation. Read moreimpl Copy for Pixels
Source§impl<'de> Deserialize<'de> for Pixels
impl<'de> Deserialize<'de> for Pixels
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<Pixels, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<Pixels, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Source§impl DivAssign for Pixels
impl DivAssign for Pixels
Source§fn div_assign(&mut self, rhs: Pixels)
fn div_assign(&mut self, rhs: Pixels)
/= operation. Read moreSource§impl<__derive_more_Rhs> DivAssign<__derive_more_Rhs> for Pixels
impl<__derive_more_Rhs> DivAssign<__derive_more_Rhs> for Pixels
Source§fn div_assign(&mut self, __rhs: __derive_more_Rhs)
fn div_assign(&mut self, __rhs: __derive_more_Rhs)
/= operation. Read moreimpl Eq for Pixels
Source§impl From<Pixels> for AbsoluteLength
impl From<Pixels> for AbsoluteLength
Source§fn from(pixels: Pixels) -> AbsoluteLength
fn from(pixels: Pixels) -> AbsoluteLength
Source§impl From<Pixels> for DefiniteLength
impl From<Pixels> for DefiniteLength
Source§fn from(pixels: Pixels) -> DefiniteLength
fn from(pixels: Pixels) -> DefiniteLength
Source§impl From<Pixels> for AvailableSpace
impl From<Pixels> for AvailableSpace
Source§fn from(pixels: Pixels) -> AvailableSpace
fn from(pixels: Pixels) -> AvailableSpace
Source§impl Interpolate for Pixels
impl Interpolate for Pixels
Source§impl JsonSchema for Pixels
impl JsonSchema for Pixels
Source§fn schema_id() -> Cow<'static, str>
fn schema_id() -> Cow<'static, str>
Source§fn json_schema(generator: &mut SchemaGenerator) -> Schema
fn json_schema(generator: &mut SchemaGenerator) -> Schema
Source§fn inline_schema() -> bool
fn inline_schema() -> bool
$ref keyword. Read moreSource§impl MulAssign<f32> for Pixels
impl MulAssign<f32> for Pixels
Source§fn mul_assign(&mut self, rhs: f32)
fn mul_assign(&mut self, rhs: f32)
*= operation. Read moreSource§impl Ord for Pixels
impl Ord for Pixels
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
1.21.0 (const: unstable) · Source§fn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialOrd for Pixels
impl PartialOrd for Pixels
Source§impl RemAssign for Pixels
impl RemAssign for Pixels
Source§fn rem_assign(&mut self, rhs: Pixels)
fn rem_assign(&mut self, rhs: Pixels)
%= operation. Read moreSource§impl Serialize for Pixels
impl Serialize for Pixels
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
Source§impl SpringTarget for Pixels
impl SpringTarget for Pixels
impl StructuralPartialEq for Pixels
Source§impl SubAssign for Pixels
impl SubAssign for Pixels
Source§fn sub_assign(&mut self, __rhs: Pixels)
fn sub_assign(&mut self, __rhs: Pixels)
-= operation. Read moreAuto Trait Implementations§
impl Freeze for Pixels
impl RefUnwindSafe for Pixels
impl Send for Pixels
impl Sync for Pixels
impl Unpin for Pixels
impl UnsafeUnpin for Pixels
impl UnwindSafe for Pixels
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
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<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
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.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
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
key and return true if they are equal.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§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> Interpolate for Twhere
T: Lerp,
impl<T> Interpolate for Twhere
T: Lerp,
fn interpolate(&self, target: &T, progress: f32) -> T
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> ⓘ
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> ⓘ
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 moreSource§impl<K> MapSeekTarget<K> for Kwhere
K: Ord,
impl<K> MapSeekTarget<K> for Kwhere
K: Ord,
fn cmp_cursor(&self, cursor_location: &K) -> Ordering
Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian().