feat: logically separate spacing and wrapping with matrix layout

This commit is contained in:
2025-06-07 14:19:58 -06:00
parent b1ac6988fa
commit 0711df8381
2 changed files with 24 additions and 16 deletions

View File

@@ -63,37 +63,38 @@ fn build_ui(app: &gtk::Application) {
let drawing_area = DrawingArea::new();
let rows = 100 as u8;
let cols = 100 as u8;
let rows = 36 as u8;
let cols = 72 as u8;
// Generate the matrix using iterators
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 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();
// 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);
let thing = String::from("ABCDEFG");
let thing = String::from("abcdefghijklmnop");
let ascii_values: &Vec<u8> = &thing.chars().map(|c| c as u8).collect();
let mut col_offset = 0;
for ch in ascii_values {
let char_matrix = &font_5x7.get_char_bitmap(*ch as u64).unwrap();
insert_matrix_at(
&mut dot_matrix,
&font_5x7.get_char_bitmap(*ch as u64).unwrap(),
char_matrix,
0,
col_offset * 6,
col_offset,
);
col_offset = col_offset + 1;
println!("length of character {}", char_matrix.first().unwrap().len());
col_offset += char_matrix.first().unwrap().len() + 1;
}
println!("{:?}", ascii_values);
drawing_area.set_draw_func(move |_area, cr, width, height| {
draw_dot_matrix(cr, width, height, &dot_matrix);
});
@@ -115,16 +116,23 @@ fn draw_dot_matrix(cr: &Context, width: i32, height: i32, matrix: &Vec<Vec<u8>>)
cr.set_source_rgb(1.0, 1.0, 0.0);
// Calculate spacing
let spacing_x = 25.0;
let spacing_y = 25.0;
let radius = 10.0;
let pos_x = 25.0;
let pos_y = 25.0;
let mut offset_row = 0.0;
let mut current_line_width = 0.0;
for (row_index, row) in matrix.iter().enumerate() {
if row_index != 0 && row_index % 8 == 0 {
offset_row += 25.0
}
for (col_index, &val) in row.iter().enumerate() {
if val == 1 {
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);
let x = (col_index as f64) * pos_x + pos_x;
let y = (row_index as f64) * pos_y + offset_row;
cr.rectangle(x, y, 20.0, 20.0);
let _ = cr.fill();
}
}

View File