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
impl Grid
sourcepub fn set_x_offset(&mut self, x_offset: Position)
pub fn set_x_offset(&mut self, x_offset: Position)
position the grid somewhere on the screen
sourcepub fn set_y_offset(&mut self, y_offset: Position)
pub fn set_y_offset(&mut self, y_offset: Position)
position the grid somewhere on the screen
sourcepub fn new(
width: f32,
height: f32,
x_cells: usize,
y_cells: usize,
gap: f32
) -> Self
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
sourcepub fn draw(&self)
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
sourcepub fn select_cell(&mut self, cell_index: Option<(usize, usize)>)
pub fn select_cell(&mut self, cell_index: Option<(usize, usize)>)
sourcepub fn get_selected_cell_index(&self) -> Option<(usize, usize)>
pub fn get_selected_cell_index(&self) -> Option<(usize, usize)>
returns the (row, col) index of the selected cell
sourcepub fn color_cell(&mut self, row: usize, col: usize, color: Color)
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)
sourcepub fn set_cell_bg_color(&mut self, color: Color)
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
sourcepub fn set_gap_color(&mut self, color: Color)
pub fn set_gap_color(&mut self, color: Color)
color the gap between cells
sourcepub fn set_selected_cell_color(&mut self, color: Color)
pub fn set_selected_cell_color(&mut self, color: Color)
when selected, a cell will have this color
sourcepub fn set_cell_text<T>(&mut self, row: usize, col: usize, text: Option<T>)where
T: ToString,
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
sourcepub fn set_selected_cell_text<T>(&mut self, text: Option<T>)where
T: ToString,
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