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) -> Self
pub fn floor(&self) -> Self
Floors the Pixels value to the nearest whole number.
§Returns
Returns a new Pixels instance with the floored value.
Sourcepub fn round(&self) -> Self
pub fn round(&self) -> Self
Rounds the Pixels value to the nearest whole number.
§Returns
Returns a new Pixels instance with the rounded value.
Sourcepub fn ceil(&self) -> Self
pub fn ceil(&self) -> Self
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) -> Self
pub fn abs(&self) -> Self
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 moreSource§impl<'de> Deserialize<'de> for Pixels
impl<'de> Deserialize<'de> for Pixels
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>,
Source§impl<__RhsT> DivAssign<__RhsT> for Pixels
impl<__RhsT> DivAssign<__RhsT> for Pixels
Source§fn div_assign(&mut self, rhs: __RhsT)
fn div_assign(&mut self, rhs: __RhsT)
/= operation. Read moreSource§impl DivAssign for Pixels
impl DivAssign for Pixels
Source§fn div_assign(&mut self, rhs: Self)
fn div_assign(&mut self, rhs: Self)
/= operation. Read moreSource§impl From<Pixels> for AbsoluteLength
impl From<Pixels> for AbsoluteLength
Source§impl From<Pixels> for AvailableSpace
impl From<Pixels> for AvailableSpace
Source§impl From<Pixels> for DefiniteLength
impl From<Pixels> for DefiniteLength
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
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: Self)
fn rem_assign(&mut self, rhs: Self)
%= operation. Read moreSource§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 moreimpl Copy for Pixels
impl Eq for Pixels
impl StructuralPartialEq for Pixels
Auto Trait Implementations§
impl Freeze for Pixels
impl RefUnwindSafe for Pixels
impl Send for Pixels
impl Sync for Pixels
impl Unpin 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
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> 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().