use crate::data::Config; use crate::file::ThymeFile; pub struct Pattern { pub thyme: ThymeFile, // pub image: Image, pub config: Config, // pub mapping: Mapping, } impl Pattern { pub fn draw(&self, ctx: cairo::Context) -> Result<(), Box> { let width = self.thyme.width; let height = self.thyme.height; ctx.set_source_rgb(1.0, 1.0, 1.0); ctx.paint()?; let layout = pangocairo::functions::create_layout(&ctx).unwrap(); let font = pango::FontDescription::from_string(&self.config.font); layout.set_width(2880); layout.set_font_description(Some(&font)); ctx.set_source_rgb(0.0, 0.0, 0.0); for i in 0..=width { ctx.move_to(self.config.scale(i), 0.0); ctx.line_to(self.config.scale(i), self.config.scale(height)); ctx.set_line_width(if i % self.config.grid_every == 0 { self.config.major_line_weight } else { self.config.line_weight }); ctx.stroke()?; } for j in 0..=height { ctx.move_to(0.0, self.config.scale(j)); ctx.line_to(self.config.scale(width), self.config.scale(j)); ctx.set_line_width(if j % self.config.grid_every == 0 { self.config.major_line_weight } else { self.config.line_weight }); ctx.stroke()?; } ctx.set_source_rgb(0.0, 0.0, 0.0); for ((x, y), stitch) in self.thyme.iter() { if let Some((_, color)) = stitch { ctx.move_to(self.config.scale(x) + 5.0, self.config.scale(y) + 3.0); layout.set_text(&color.symbol); pangocairo::functions::show_layout(&ctx, &layout); } } Ok(()) } }