feat: check in

This commit is contained in:
2025-06-06 07:50:10 -06:00
parent a574def706
commit f504f3c09a
6 changed files with 89 additions and 33 deletions

View File

@@ -1,9 +1,9 @@
mod font;
use crate::font::Font; // this brings in the struct Font
use gtk::cairo::Context;
use gtk::prelude::*;
use gtk::{Application, ApplicationWindow, DrawingArea};
use rand::prelude::*;
fn main() {
let app = Application::builder()
@@ -24,19 +24,18 @@ fn build_ui(app: &gtk::Application) {
let drawing_area = DrawingArea::new();
let mut rng = rand::rng();
let rows = 100 as u32;
let cols = 100 as u32;
let rows = 100 as u8;
let cols = 100 as u8;
// Generate the matrix using iterators
let mut dot_matrix: Vec<Vec<u32>> = (0..rows)
.map(|_| (0..cols).map(|_| rng.random_range(0..=10)).collect())
.collect();
let insert_matrix: Vec<Vec<u32>> = (0..7).map(|_| (0..5).map(|_| 1).collect()).collect();
let mut dot_matrix: Vec<Vec<u8>> = (0..rows).map(|_| (0..cols).map(|_| 0).collect()).collect();
let insert_matrix: Vec<Vec<u8>> = (0..7).map(|_| (0..5).map(|_| 1).collect()).collect();
let font_5x7: Font = Font::new("5x7");
let char_bitmap = font_5x7.get_char_bitmap(1).unwrap();
insert_matrix_at(&mut dot_matrix, &insert_matrix, 0, 0);
insert_matrix_at(&mut dot_matrix, &insert_matrix, 0, 6);
insert_matrix_at(&mut dot_matrix, &char_bitmap, 0, 12);
drawing_area.set_draw_func(move |_area, cr, width, height| {
draw_dot_matrix(cr, width, height, &dot_matrix);
@@ -46,7 +45,7 @@ fn build_ui(app: &gtk::Application) {
window.show();
}
fn draw_dot_matrix(cr: &Context, width: i32, height: i32, matrix: &Vec<Vec<u32>>) {
fn draw_dot_matrix(cr: &Context, width: i32, height: i32, matrix: &Vec<Vec<u8>>) {
// let rows = matrix.len();
// let _cols = if rows > 0 { matrix[0].len() } else { 0 };
@@ -59,9 +58,9 @@ fn draw_dot_matrix(cr: &Context, width: i32, height: i32, matrix: &Vec<Vec<u32>>
cr.set_source_rgb(1.0, 1.0, 0.0);
// Calculate spacing
let spacing_x = 8.0;
let spacing_y = 8.0;
let radius = 2.0;
let spacing_x = 25.0;
let spacing_y = 25.0;
let radius = 10.0;
for (row_index, row) in matrix.iter().enumerate() {
for (col_index, &val) in row.iter().enumerate() {
@@ -76,8 +75,8 @@ fn draw_dot_matrix(cr: &Context, width: i32, height: i32, matrix: &Vec<Vec<u32>>
}
fn insert_matrix_at(
target: &mut Vec<Vec<u32>>,
insert: &Vec<Vec<u32>>,
target: &mut Vec<Vec<u8>>,
insert: &Vec<Vec<u8>>,
row_offset: usize,
col_offset: usize,
) {