Skip to main content

MathBox

Struct MathBox 

Source
pub struct MathBox {
    pub width: usize,
    pub height: usize,
    pub baseline: usize,
    /* private fields */
}
Expand description

Represents a box of grapheme clusters for rendering math expressions. Uses a 2D grid with baseline tracking for proper vertical alignment. Each cell holds a grapheme cluster (base char + combining marks).

Fields§

§width: usize§height: usize§baseline: usize

The baseline row (0-indexed from top)

Implementations§

Source§

impl MathBox

Source

pub fn from_text(text: &str) -> Self

Create a MathBox from a single-line string

Source

pub fn empty(width: usize, height: usize, baseline: usize) -> Self

Create an empty MathBox with specified dimensions

Source

pub fn from_lines(lines: Vec<String>, baseline: usize) -> Self

Create a MathBox from multiple lines

Source

pub fn get(&self, x: usize, y: usize) -> char

Get grapheme at position (returns space if out of bounds or empty)

Source

pub fn get_grapheme(&self, x: usize, y: usize) -> &str

Get full grapheme cluster at position

Source

pub fn set(&mut self, x: usize, y: usize, ch: char)

Set character at position

Source

pub fn set_grapheme(&mut self, x: usize, y: usize, g: &str)

Set grapheme cluster at position

Source

pub fn blit(&mut self, other: &MathBox, x_offset: usize, y_offset: usize)

Copy another MathBox into this one at the specified offset

Source

pub fn concat_horizontal(boxes: &[MathBox]) -> MathBox

Concatenate horizontally, aligning by baseline

Source

pub fn stack_vertical(boxes: &[MathBox]) -> MathBox

Stack vertically, centered horizontally

Source

pub fn fill_row(&mut self, y: usize, ch: char)

Fill a row with a character

Source

pub fn fill_col(&mut self, x: usize, ch: char)

Fill a column with a character

Source

pub fn to_string(&self) -> String

Convert to string representation

Source

pub fn to_lines(&self) -> Vec<String>

Get lines as vector of strings

Trait Implementations§

Source§

impl Clone for MathBox

Source§

fn clone(&self) -> MathBox

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 MathBox

Source§

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

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

impl Default for MathBox

Source§

fn default() -> Self

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

Auto Trait Implementations§

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