feat: start fonts ingesting

This commit is contained in:
Nathan
2025-06-05 17:44:29 -06:00
parent eb59c1b50a
commit a574def706
6 changed files with 395 additions and 15 deletions

View File

@@ -1,7 +1,9 @@
use rand::prelude::*;
mod font;
use gtk::cairo::Context;
use gtk::prelude::*;
use gtk::{Application, ApplicationWindow, DrawingArea};
use gtk::cairo::Context;
use rand::prelude::*;
fn main() {
let app = Application::builder()
@@ -13,7 +15,6 @@ fn main() {
}
fn build_ui(app: &gtk::Application) {
let window = ApplicationWindow::builder()
.application(app)
.title("Dot Matrix")
@@ -24,19 +25,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;
// Generate the matrix using iterators
let dot_matrix: Vec<Vec<u32>> = (0..rows)
.map(|_| {
(0..cols)
.map(|_| rng.random_range(0..=10))
.collect()
})
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();
insert_matrix_at(&mut dot_matrix, &insert_matrix, 0, 0);
drawing_area.set_draw_func(move |_area, cr, width, height| {
draw_dot_matrix(cr, width, height, &dot_matrix);
@@ -47,13 +47,13 @@ fn build_ui(app: &gtk::Application) {
}
fn draw_dot_matrix(cr: &Context, width: i32, height: i32, matrix: &Vec<Vec<u32>>) {
let rows = matrix.len();
let cols = if rows > 0 { matrix[0].len() } else { 0 };
// let rows = matrix.len();
// let _cols = if rows > 0 { matrix[0].len() } else { 0 };
// Background: dark gray
cr.set_source_rgb(0.1, 0.1, 0.1);
cr.rectangle(0.0, 0.0, width as f64, height as f64);
cr.fill();
let _ = cr.fill();
// Set dot color (yellow)
cr.set_source_rgb(1.0, 1.0, 0.0);
@@ -69,7 +69,22 @@ fn draw_dot_matrix(cr: &Context, width: i32, height: i32, matrix: &Vec<Vec<u32>>
let x = (col_index as f64 + 0.5) * spacing_x;
let y = (row_index as f64 + 0.5) * spacing_y;
cr.arc(x, y, radius, 0.0, std::f64::consts::PI * 2.0);
cr.fill();
let _ = cr.fill();
}
}
}
}
fn insert_matrix_at(
target: &mut Vec<Vec<u32>>,
insert: &Vec<Vec<u32>>,
row_offset: usize,
col_offset: usize,
) {
for (i, insert_row) in insert.iter().enumerate() {
for (j, &val) in insert_row.iter().enumerate() {
if row_offset + i < target.len() && col_offset + j < target[0].len() {
target[row_offset + i][col_offset + j] = val;
}
}
}