Guide API
Skip to main content

Point

Struct Point 

Source
pub struct Point {
    pub x: i32,
    pub y: i32,
}
Expand description

A screen coordinate pair (x, y).

Use Point wherever you need a column/row position: view origins, cursor positions, mouse hit coordinates, or scroll offsets. Both fields are i32 because view origins go negative when a view is scrolled offscreen, and translation deltas are frequently negative. Conversion to an unsigned buffer index happens only at the screen boundary.

Point supports all four arithmetic operators (+, -, +=, -=) so you can translate positions and compute offsets without converting to tuples:

let origin = Point::new(5, 3);
let offset = Point::new(-2, 1);
assert_eq!(origin + offset, Point::new(3, 4));

Default returns Point::new(0, 0).

§Turbo Vision heritage

Ports TPoint from objects.h. Field names are lowercase (x, y) following Rust conventions; the original used uppercase X/Y.

Fields§

§x: i32

Screen column (horizontal position).

Zero is the leftmost column. Negative values occur when a view’s origin is scrolled to the left of the visible area. Write this field directly when constructing geometry; use Point::new to set both axes at once.

§y: i32

Screen row (vertical position).

Zero is the topmost row. Negative values occur when a view’s origin is scrolled above the visible area. Write this field directly when constructing geometry; use Point::new to set both axes at once.

Implementations§

Source§

impl Point

Source

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

Construct a point from a column x and row y.

This is a const fn, so it can be used in const and static contexts. For the zero point, Default::default() (or Point::default()) is equivalent and more expressive.

const ORIGIN: Point = Point::new(0, 0);
assert_eq!(ORIGIN, Point::default());

Trait Implementations§

Source§

impl Add for Point

Source§

fn add(self, rhs: Point) -> Point

Returns a new Point with both axes summed.

Use this to apply an offset to a position without mutating the original: child_origin + scroll_offset.

Source§

type Output = Point

The resulting type after applying the + operator.
Source§

impl AddAssign for Point

Source§

fn add_assign(&mut self, rhs: Point)

Shifts this point in place by adding rhs.

Use this to accumulate translation steps without allocating a new Point: cursor += delta.

Source§

impl Clone for Point

Source§

fn clone(&self) -> Point

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Copy for Point

Source§

impl Debug for Point

Source§

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

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

impl Default for Point

Source§

fn default() -> Point

Returns the “default value” for a type. Read more
Source§

impl Eq for Point

Source§

impl Hash for Point

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 Point

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Point

Source§

impl Sub for Point

Source§

fn sub(self, rhs: Point) -> Point

Returns a new Point with both axes subtracted.

Use this to compute the offset between two positions: mouse_pos - view_origin gives the hit position in view-local coordinates.

Source§

type Output = Point

The resulting type after applying the - operator.
Source§

impl SubAssign for Point

Source§

fn sub_assign(&mut self, rhs: Point)

Shifts this point in place by subtracting rhs.

Use this to undo a previously applied offset in place: cursor -= delta.

Auto Trait Implementations§

§

impl Freeze for Point

§

impl RefUnwindSafe for Point

§

impl Send for Point

§

impl Sync for Point

§

impl Unpin for Point

§

impl UnsafeUnpin for Point

§

impl UnwindSafe for Point

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> 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
Source§

impl<T> CustomValue for T
where T: Any + Debug,

Source§

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

Upcast Rc<Self> to Rc<dyn Any> so FieldValue::as_custom / FieldValue::value_as can downcast.
§

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.

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> 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.