#[repr(C)]pub struct Point<T: Clone + Debug + Default + PartialEq> {
pub x: T,
pub y: T,
}Expand description
A position or offset in two-dimensional space.
GPUI’s coordinate system has its origin at the top left corner of the window. The x axis
increases to the right and the y axis increases downward, so a larger y is lower on the
screen. Coordinates are in logical pixels: px(1.) is one logical pixel, which the platform
scales to device pixels for the display. Use Pixels for positions that the UI lays out.
Point<T> works with any T that is Clone, Debug, Default and PartialEq. The
arithmetic and ordering methods also need T to support the matching operators.
Bounds uses points for its origin. For how positions map onto the layout tree, see
layout and style.
§Examples
use gpui::{Point, point, px};
let card = point(px(20.), px(30.));
let offset = point(px(5.), px(-10.));
assert_eq!(card + offset, point(px(25.), px(20.)));Fields§
§x: TThe horizontal coordinate, increasing to the right.
y: TThe vertical coordinate, increasing downward.
Implementations§
Source§impl<T: Clone + Debug + Default + PartialEq> Point<T>
impl<T: Clone + Debug + Default + PartialEq> Point<T>
Source§impl Point<Pixels>
impl Point<Pixels>
Sourcepub fn scale(&self, factor: f32) -> Point<ScaledPixels>
pub fn scale(&self, factor: f32) -> Point<ScaledPixels>
Multiplies both coordinates by factor, producing ScaledPixels.
Pass the display’s scale factor, such as 2.0 on a Retina display, to convert a logical
position into the scaled space that GPUI draws in.
§Examples
let p = Point { x: Pixels::from(10.0), y: Pixels::from(20.0) };
let scaled_p = p.scale(1.5);
assert_eq!(scaled_p, Point { x: ScaledPixels::from(15.0), y: ScaledPixels::from(30.0) });Sourcepub fn is_nearly_eq(&self, other: &Self, epsilon: Pixels) -> bool
pub fn is_nearly_eq(&self, other: &Self, epsilon: Pixels) -> bool
Returns true if both coordinates differ from other by less than epsilon.
Use this to compare positions computed with floating point arithmetic. The comparison is
strict: a difference of exactly epsilon returns false.
§Examples
let p1 = Point { x: Pixels::from(1.0), y: Pixels::from(1.0) };
let p2 = Point { x: Pixels::from(3.0), y: Pixels::from(-2.0) };
assert_eq!(p1.is_nearly_eq(&p2, Pixels::from(4.0)), true);Source§impl<T> Point<T>
impl<T> Point<T>
Sourcepub fn relative_to(&self, origin: &Point<T>) -> Point<T>
pub fn relative_to(&self, origin: &Point<T>) -> Point<T>
Returns this point’s position relative to origin.
Subtracts origin from both coordinates. Bounds::localize uses it to convert a point in
window coordinates into a bounds rectangle’s local coordinates.
§Examples
let pointer = point(px(150.), px(90.));
let element_origin = point(px(100.), px(80.));
assert_eq!(pointer.relative_to(&element_origin), point(px(50.), px(10.)));Source§impl<T> Point<T>
impl<T> Point<T>
Sourcepub fn max(&self, other: &Self) -> Self
pub fn max(&self, other: &Self) -> Self
Returns a point with the larger x and the larger y of self and other.
§Examples
let p1 = Point { x: 3, y: 7 };
let p2 = Point { x: 5, y: 2 };
assert_eq!(p1.max(&p2), Point { x: 5, y: 7 });Sourcepub fn min(&self, other: &Self) -> Self
pub fn min(&self, other: &Self) -> Self
Returns a point with the smaller x and the smaller y of self and other.
§Examples
let p1 = Point { x: 3, y: 7 };
let p2 = Point { x: 5, y: 2 };
assert_eq!(p1.min(&p2), Point { x: 3, y: 2 });Sourcepub fn clamp(&self, min: &Self, max: &Self) -> Self
pub fn clamp(&self, min: &Self, max: &Self) -> Self
Limits each coordinate to the range from min to max.
A coordinate below min becomes min, and a coordinate above max becomes max. If min
is greater than max in a coordinate, that coordinate becomes max.
§Examples
let p = Point { x: 10, y: 20 };
let min = Point { x: 0, y: 5 };
let max = Point { x: 15, y: 25 };
assert_eq!(p.clamp(&min, &max), Point { x: 10, y: 20 });
let p_out_of_bounds = Point { x: -5, y: 30 };
assert_eq!(p_out_of_bounds.clamp(&min, &max), Point { x: 0, y: 25 });Trait Implementations§
Source§impl<T> AddAssign for Point<T>
impl<T> AddAssign for Point<T>
Source§fn add_assign(&mut self, __rhs: Self)
fn add_assign(&mut self, __rhs: Self)
+= operation. Read moreimpl<T: Copy + Clone + Debug + Default + PartialEq> Copy for Point<T>
Source§impl<'de, T> Deserialize<'de> for Point<T>
impl<'de, T> Deserialize<'de> for Point<T>
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>,
impl<T: Eq + Clone + Debug + Default + PartialEq> Eq for Point<T>
Source§impl<T, T2> From<Point<T>> for Point<T2>
impl<T, T2> From<Point<T>> for Point<T2>
Source§fn from(point: TaffyPoint<T>) -> Point<T2>
fn from(point: TaffyPoint<T>) -> Point<T2>
Source§impl<T: Clone + Debug + Default + PartialEq> From<PointRefinement<T>> for Point<T>
impl<T: Clone + Debug + Default + PartialEq> From<PointRefinement<T>> for Point<T>
Source§fn from(value: PointRefinement<T>) -> Self
fn from(value: PointRefinement<T>) -> Self
Source§impl<T> JsonSchema for Point<T>
impl<T> JsonSchema for Point<T>
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<T, S> MulAssign<S> for Point<T>
impl<T, S> MulAssign<S> for Point<T>
Source§fn mul_assign(&mut self, rhs: S)
fn mul_assign(&mut self, rhs: S)
*= operation. Read moreSource§impl<T: Clone + Debug + Default + PartialEq> Refineable for Point<T>
impl<T: Clone + Debug + Default + PartialEq> Refineable for Point<T>
type Refinement = PointRefinement<T>
Source§fn refine(&mut self, refinement: &Self::Refinement)
fn refine(&mut self, refinement: &Self::Refinement)
Source§fn refined(self, refinement: Self::Refinement) -> Self
fn refined(self, refinement: Self::Refinement) -> Self
self and calling
refine on it.Source§fn is_superset_of(&self, refinement: &Self::Refinement) -> bool
fn is_superset_of(&self, refinement: &Self::Refinement) -> bool
true if this instance would contain all values from the refinement. Read moreSource§fn subtract(&self, refinement: &Self::Refinement) -> Self::Refinement
fn subtract(&self, refinement: &Self::Refinement) -> Self::Refinement
impl<T: PartialEq + Clone + Debug + Default + PartialEq> StructuralPartialEq for Point<T>
Auto Trait Implementations§
impl<T> Freeze for Point<T>where
T: Freeze,
impl<T> RefUnwindSafe for Point<T>where
T: RefUnwindSafe,
impl<T> Send for Point<T>where
T: Send,
impl<T> Sync for Point<T>where
T: Sync,
impl<T> Unpin for Point<T>where
T: Unpin,
impl<T> UnsafeUnpin for Point<T>where
T: UnsafeUnpin,
impl<T> UnwindSafe for Point<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<S, D, Swp, Dwp, T> AdaptInto<D, Swp, Dwp, T> for Swhere
T: Real + Zero + Arithmetics + Clone,
Swp: WhitePoint<T>,
Dwp: WhitePoint<T>,
D: AdaptFrom<S, Swp, Dwp, T>,
impl<S, D, Swp, Dwp, T> AdaptInto<D, Swp, Dwp, T> for Swhere
T: Real + Zero + Arithmetics + Clone,
Swp: WhitePoint<T>,
Dwp: WhitePoint<T>,
D: AdaptFrom<S, Swp, Dwp, T>,
Source§fn adapt_into_using<M>(self, method: M) -> Dwhere
M: TransformMatrix<T>,
fn adapt_into_using<M>(self, method: M) -> Dwhere
M: TransformMatrix<T>,
replaced by palette::chromatic_adaptation::AdaptIntoUnclamped
Source§fn adapt_into(self) -> D
fn adapt_into(self) -> D
replaced by palette::chromatic_adaptation::AdaptIntoUnclamped
Source§impl<T, C> AdaptIntoUnclamped<T> for Cwhere
T: AdaptFromUnclamped<C>,
impl<T, C> AdaptIntoUnclamped<T> for Cwhere
T: AdaptFromUnclamped<C>,
Source§type Scalar = <T as AdaptFromUnclamped<C>>::Scalar
type Scalar = <T as AdaptFromUnclamped<C>>::Scalar
Source§fn adapt_into_unclamped_with<M>(self) -> Twhere
M: LmsToXyz<<C as AdaptIntoUnclamped<T>>::Scalar> + XyzToLms<<C as AdaptIntoUnclamped<T>>::Scalar>,
fn adapt_into_unclamped_with<M>(self) -> Twhere
M: LmsToXyz<<C as AdaptIntoUnclamped<T>>::Scalar> + XyzToLms<<C as AdaptIntoUnclamped<T>>::Scalar>,
Source§impl<T, C> ArraysFrom<C> for Twhere
C: IntoArrays<T>,
impl<T, C> ArraysFrom<C> for Twhere
C: IntoArrays<T>,
Source§fn arrays_from(colors: C) -> T
fn arrays_from(colors: C) -> T
Source§impl<T, C> ArraysInto<C> for Twhere
C: FromArrays<T>,
impl<T, C> ArraysInto<C> for Twhere
C: FromArrays<T>,
Source§fn arrays_into(self) -> C
fn arrays_into(self) -> C
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<WpParam, T, U> Cam16IntoUnclamped<WpParam, T> for Uwhere
T: FromCam16Unclamped<WpParam, U>,
impl<WpParam, T, U> Cam16IntoUnclamped<WpParam, T> for Uwhere
T: FromCam16Unclamped<WpParam, U>,
Source§type Scalar = <T as FromCam16Unclamped<WpParam, U>>::Scalar
type Scalar = <T as FromCam16Unclamped<WpParam, U>>::Scalar
parameters when converting.Source§fn cam16_into_unclamped(
self,
parameters: BakedParameters<WpParam, <U as Cam16IntoUnclamped<WpParam, T>>::Scalar>,
) -> T
fn cam16_into_unclamped( self, parameters: BakedParameters<WpParam, <U as Cam16IntoUnclamped<WpParam, T>>::Scalar>, ) -> T
self into C, using the provided parameters.impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T, C> ComponentsFrom<C> for Twhere
C: IntoComponents<T>,
impl<T, C> ComponentsFrom<C> for Twhere
C: IntoComponents<T>,
Source§fn components_from(colors: C) -> T
fn components_from(colors: C) -> T
Source§impl<T, C> ComponentsInto<C> for T
impl<T, C> ComponentsInto<C> for T
Source§fn components_into(self) -> C
fn components_into(self) -> C
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
key and return true if they are equal.Source§impl<T> FromAngle<T> for T
impl<T> FromAngle<T> for T
Source§fn from_angle(angle: T) -> T
fn from_angle(angle: T) -> T
angle.Source§impl<T, U> FromStimulus<U> for Twhere
U: IntoStimulus<T>,
impl<T, U> FromStimulus<U> for Twhere
U: IntoStimulus<T>,
Source§fn from_stimulus(other: U) -> T
fn from_stimulus(other: U) -> T
other into Self, while performing the appropriate scaling,
rounding and clamping.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, U> IntoAngle<U> for Twhere
U: FromAngle<T>,
impl<T, U> IntoAngle<U> for Twhere
U: FromAngle<T>,
Source§fn into_angle(self) -> U
fn into_angle(self) -> U
T.Source§impl<WpParam, T, U> IntoCam16Unclamped<WpParam, T> for Uwhere
T: Cam16FromUnclamped<WpParam, U>,
impl<WpParam, T, U> IntoCam16Unclamped<WpParam, T> for Uwhere
T: Cam16FromUnclamped<WpParam, U>,
Source§type Scalar = <T as Cam16FromUnclamped<WpParam, U>>::Scalar
type Scalar = <T as Cam16FromUnclamped<WpParam, U>>::Scalar
parameters when converting.Source§fn into_cam16_unclamped(
self,
parameters: BakedParameters<WpParam, <U as IntoCam16Unclamped<WpParam, T>>::Scalar>,
) -> T
fn into_cam16_unclamped( self, parameters: BakedParameters<WpParam, <U as IntoCam16Unclamped<WpParam, T>>::Scalar>, ) -> T
self into C, using the provided parameters.Source§impl<T, U> IntoColor<U> for Twhere
U: FromColor<T>,
impl<T, U> IntoColor<U> for Twhere
U: FromColor<T>,
Source§fn into_color(self) -> U
fn into_color(self) -> U
Source§impl<T, U> IntoColorUnclamped<U> for Twhere
U: FromColorUnclamped<T>,
impl<T, U> IntoColorUnclamped<U> for Twhere
U: FromColorUnclamped<T>,
Source§fn into_color_unclamped(self) -> U
fn into_color_unclamped(self) -> U
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<T> IntoStimulus<T> for T
impl<T> IntoStimulus<T> for T
Source§fn into_stimulus(self) -> T
fn into_stimulus(self) -> T
self into T, while performing the appropriate scaling,
rounding and clamping.Source§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
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().Source§impl<T> Serialize for T
impl<T> Serialize for T
fn erased_serialize(&self, serializer: &mut dyn Serializer) -> Result<(), Error>
fn do_erased_serialize( &self, serializer: &mut dyn Serializer, ) -> Result<(), ErrorImpl>
Source§impl<T, C> TryComponentsInto<C> for Twhere
C: TryFromComponents<T>,
impl<T, C> TryComponentsInto<C> for Twhere
C: TryFromComponents<T>,
Source§type Error = <C as TryFromComponents<T>>::Error
type Error = <C as TryFromComponents<T>>::Error
try_into_colors fails to cast.Source§fn try_components_into(self) -> Result<C, <T as TryComponentsInto<C>>::Error>
fn try_components_into(self) -> Result<C, <T as TryComponentsInto<C>>::Error>
Source§impl<T, U> TryIntoColor<U> for Twhere
U: TryFromColor<T>,
impl<T, U> TryIntoColor<U> for Twhere
U: TryFromColor<T>,
Source§fn try_into_color(self) -> Result<U, OutOfBounds<U>>
fn try_into_color(self) -> Result<U, OutOfBounds<U>>
OutOfBounds error is returned which contains
the unclamped color. Read more