Skip to main content

GridCalc

Struct GridCalc 

Source
pub struct GridCalc {
    pub x: i32,
    pub y: i32,
    pub cols: usize,
    pub col_w: i32,
    pub row_h: i32,
    pub col_gap: i32,
    pub row_gap: i32,
}
Expand description

Pure-geometry grid calculator for manual widget layouts.

Unlike Grid, this does not own widgets — it only computes cell Rects from (row, col) indices, making it suitable for custom widgets that do their own drawing and hit-testing.

let g = GridCalc::new(10, 20, 2, 100, 40).gap(4, 2);
let r = g.cell(1, 0);
assert_eq!(r, Rect { x: 10, y: 62, width: 100, height: 40 });

Fields§

§x: i32

Top-left origin X.

§y: i32

Top-left origin Y.

§cols: usize

Number of columns.

§col_w: i32

Width of each cell.

§row_h: i32

Height of each cell.

§col_gap: i32

Horizontal gap between columns.

§row_gap: i32

Vertical gap between rows.

Implementations§

Source§

impl GridCalc

Source

pub const fn new(x: i32, y: i32, cols: usize, col_w: i32, row_h: i32) -> Self

Create a grid calculator with the given origin, column count, and cell size.

Source

pub const fn gap(self, col_gap: i32, row_gap: i32) -> Self

Set inter-cell gaps.

Source

pub const fn cell(&self, row: usize, col: usize) -> Rect

Return the Rect for the cell at (row, col).

Source

pub const fn row_span(&self, row: usize) -> Rect

Return a Rect spanning all columns for the given row.

Source

pub const fn total_width(&self) -> i32

Total width of the grid (all columns + gaps).

Source

pub const fn total_height(&self, rows: usize) -> i32

Total height of the grid for the given number of rows.

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