Struct macroquad_grid::Grid

source ·
pub struct Grid { /* private fields */ }
Expand description

the point of this crate!

used to represent and draw a grid to the screen heres the repo: https://github.com/TheDinner22/macroquad_grid

construction

use the new method or the default method

notes

only has private feilds so you interface with it via methods (mainly getters and setters)

stuff you can do

  • creating a grid
  • selecting a cell
  • changing selected cells color
  • changing default cell bg color
  • changing gap color
  • changing grids postion with Position enum
  • setting color of a specific cell
  • writing text to a specific cell
  • writing text to the selected cell
  • getting the selected cell’s index
  • drawing the grid

Implementations§

source§

impl Grid

source

pub fn set_x_offset(&mut self, x_offset: Position)

position the grid somewhere on the screen

source

pub fn set_y_offset(&mut self, y_offset: Position)

position the grid somewhere on the screen

source

pub fn new( width: f32, height: f32, x_cells: usize, y_cells: usize, gap: f32 ) -> Self

create a grid
problems

there are a shit ton of feilds and I wanted the new function to not have a trillion args. It is “normal” (more like intended) to create a new Grid and then call a bunch of setters to customize it to your liking

source

pub fn draw(&self)

draw it!

this does not change any state your gonna want to put this in the main loop or something like that

source

pub fn select_cell(&mut self, cell_index: Option<(usize, usize)>)

select a cell
warning

if the selected cell is out of bounds it might lead to a panic later

source

pub fn get_selected_cell_index(&self) -> Option<(usize, usize)>

returns the (row, col) index of the selected cell

source

pub fn color_cell(&mut self, row: usize, col: usize, color: Color)

changes the default bg color of the given cell

panics

if the row or col is out of bounds indexing into the 2D vector which represents the grid (its private u can’t see it)

source

pub fn set_cell_bg_color(&mut self, color: Color)

sets default bg color for all cells

different from color_cell becuase this one applies to all uncolored and unselected cells this function panics

source

pub fn set_gap_color(&mut self, color: Color)

color the gap between cells

source

pub fn set_selected_cell_color(&mut self, color: Color)

when selected, a cell will have this color

source

pub fn set_cell_text<T>(&mut self, row: usize, col: usize, text: Option<T>)where T: ToString,

write text to a cell
panics

if row and col are out of bounds

generic option

so the text arg is the text to be written

  • if the Option is None, there will be no text
  • if the Option is Some(text), I call text.to_string() and then write the resulting String to the screen
source

pub fn set_selected_cell_text<T>(&mut self, text: Option<T>)where T: ToString,

same as set_cell_text but instead of providing a row and col it just writes the text onto the selected cell

no selected cell

if there is no selected cell, this method does nothing

panics

if the selected cell happens to be out of bounds, this function panics

Trait Implementations§

source§

impl Default for Grid

source§

fn default() -> Self

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

Auto Trait Implementations§

§

impl RefUnwindSafe for Grid

§

impl Send for Grid

§

impl Sync for Grid

§

impl Unpin for Grid

§

impl UnwindSafe for Grid

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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.

§

impl<S> FromSample<S> for S

§

fn from_sample_(s: S) -> S

source§

impl<T, U> Into<U> for Twhere 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.

§

impl<T, U> ToSample<U> for Twhere U: FromSample<T>,

§

fn to_sample_(self) -> U

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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

impl<S, T> Duplex<S> for Twhere T: FromSample<S> + ToSample<S>,