Skip to main content

View

Struct View 

Source
pub struct View {
    pub source_x: u32,
    pub source_y: u32,
    pub source_width: u32,
    pub source_height: u32,
    pub target_width: u32,
    pub target_height: u32,
}
Expand description

Defines the mapping between a rectangular area of the source image and the target rendering area in the terminal.

The View struct is used to determine which pixels from the source image correspond to which character cells in the terminal output.

Fields§

§source_x: u32

The top-left X coordinate of the view on the source image (in pixels).

§source_y: u32

The top-left Y coordinate of the view on the source image (in pixels).

§source_width: u32

The width of the view on the source image (in pixels).

§source_height: u32

The height of the view on the source image (in pixels).

§target_width: u32

The width of the target render area (in terminal columns).

§target_height: u32

The height of the target render area (in terminal rows).

Implementations§

Source§

impl View

Source

pub fn calculate_scaling(&self) -> (f32, f32)

Calculates the scaling ratios between source and target dimensions.

§Returns

A tuple (x_ratio, y_ratio) representing source pixels per terminal cell.

Source

pub fn map_to_source( &self, x: u32, y: u32, x_ratio: f32, y_ratio: f32, ) -> (u32, u32, u32)

Maps a terminal cell coordinate (x, y) to the corresponding source image coordinates.

§Arguments
  • x - The terminal column index.
  • y - The terminal row index.
  • x_ratio - Source pixels per column.
  • y_ratio - Source pixels per row.
§Returns

A tuple (source_x, source_y_top, source_y_bottom) representing the starting pixel coordinates for the top and bottom halves of the character block.

Source

pub fn calculate_block_size(&self, x_ratio: f32, y_ratio: f32) -> (u32, u32)

Calculates the block dimensions for averaging colors.

§Arguments
  • x_ratio - Source pixels per column.
  • y_ratio - Source pixels per row.
§Returns

A tuple (block_width, block_height) representing the size of the pixel block to sample for each half-character.

Trait Implementations§

Source§

impl Clone for View

Source§

fn clone(&self) -> View

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for View

Source§

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

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

impl Copy for View

Auto Trait Implementations§

§

impl Freeze for View

§

impl RefUnwindSafe for View

§

impl Send for View

§

impl Sync for View

§

impl Unpin for View

§

impl UnsafeUnpin for View

§

impl UnwindSafe for View

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> 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

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

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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.