pub struct Position {
pub x: u16,
pub y: u16,
}Expand description
Position in the terminal coordinate system.
The position is relative to the top left corner of the terminal window, with the top left corner being (0, 0). The x axis is horizontal increasing to the right, and the y axis is vertical increasing downwards.
Position is used throughout the layout system to represent specific points in the terminal.
It can be created from coordinates, tuples, or extracted from rectangular areas.
§Construction
§Conversion
from((u16, u16))- Create from(u16, u16)tuplefrom(Rect)- Create fromRect(uses top-left corner)- [
into((u16, u16))] - Convert to(u16, u16)tuple
§Movement
offset- Move by anOffsetAdd<Offset>andSub<Offset>- Shift by offsets with clampingAddAssign<Offset>andSubAssign<Offset>- In-place shifting
§Examples
use ratatui_core::layout::{Offset, Position, Rect};
// the following are all equivalent
let position = Position { x: 1, y: 2 };
let position = Position::new(1, 2);
let position = Position::from((1, 2));
let position = Position::from(Rect::new(1, 2, 3, 4));
// position can be converted back into the components when needed
let (x, y) = position.into();
// movement by offsets
let position = Position::new(5, 5) + Offset::new(2, -3);
assert_eq!(position, Position::new(7, 2));For comprehensive layout documentation and examples, see the layout module.
Fields§
§x: u16The x coordinate of the position
The x coordinate is relative to the left edge of the terminal window, with the left edge being 0.
y: u16The y coordinate of the position
The y coordinate is relative to the top edge of the terminal window, with the top edge being 0.
Implementations§
Trait Implementations§
Source§impl AddAssign<Offset> for Position
impl AddAssign<Offset> for Position
Source§fn add_assign(&mut self, offset: Offset)
fn add_assign(&mut self, offset: Offset)
Moves the position in place by the given offset.
Values that would move the position outside the u16 range are clamped to the nearest
edge.
Source§impl<'de> Deserialize<'de> for Position
impl<'de> Deserialize<'de> for Position
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<Position, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<Position, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Source§impl Ord for Position
impl Ord for Position
Source§impl PartialOrd for Position
impl PartialOrd for Position
Source§impl Serialize for Position
impl Serialize for Position
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 SubAssign<Offset> for Position
impl SubAssign<Offset> for Position
Source§fn sub_assign(&mut self, offset: Offset)
fn sub_assign(&mut self, offset: Offset)
Moves the position in place by the inverse of the given offset.
Values that would move the position outside the u16 range are clamped to the nearest
edge.
impl Copy for Position
impl Eq for Position
impl StructuralPartialEq for Position
Auto Trait Implementations§
impl Freeze for Position
impl RefUnwindSafe for Position
impl Send for Position
impl Sync for Position
impl Unpin for Position
impl UnsafeUnpin for Position
impl UnwindSafe for Position
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<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> 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> Pointable for T
impl<T> Pointable for T
Source§impl<T> ToCompactString for Twhere
T: Display,
impl<T> ToCompactString for Twhere
T: Display,
Source§fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
ToCompactString::to_compact_string() Read moreSource§fn to_compact_string(&self) -> CompactString
fn to_compact_string(&self) -> CompactString
CompactString. Read more