feat: logically separate spacing and wrapping with matrix layout
This commit is contained in:
@@ -63,37 +63,38 @@ fn build_ui(app: >k::Application) {
|
|||||||
|
|
||||||
let drawing_area = DrawingArea::new();
|
let drawing_area = DrawingArea::new();
|
||||||
|
|
||||||
let rows = 100 as u8;
|
let rows = 36 as u8;
|
||||||
let cols = 100 as u8;
|
let cols = 72 as u8;
|
||||||
|
|
||||||
// Generate the matrix using iterators
|
// Generate the matrix using iterators
|
||||||
let mut dot_matrix: Vec<Vec<u8>> = (0..rows).map(|_| (0..cols).map(|_| 0).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 insert_matrix: Vec<Vec<u8>> = (0..7).map(|_| (0..5).map(|_| 1).collect()).collect();
|
||||||
let font_5x7: Font = Font::new("5x7");
|
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, 0);
|
||||||
// insert_matrix_at(&mut dot_matrix, &insert_matrix, 0, 6);
|
// insert_matrix_at(&mut dot_matrix, &insert_matrix, 0, 6);
|
||||||
// insert_matrix_at(&mut dot_matrix, &char_bitmap, 0, 12);
|
// 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 ascii_values: &Vec<u8> = &thing.chars().map(|c| c as u8).collect();
|
||||||
|
|
||||||
let mut col_offset = 0;
|
let mut col_offset = 0;
|
||||||
|
|
||||||
for ch in ascii_values {
|
for ch in ascii_values {
|
||||||
|
let char_matrix = &font_5x7.get_char_bitmap(*ch as u64).unwrap();
|
||||||
|
|
||||||
insert_matrix_at(
|
insert_matrix_at(
|
||||||
&mut dot_matrix,
|
&mut dot_matrix,
|
||||||
&font_5x7.get_char_bitmap(*ch as u64).unwrap(),
|
char_matrix,
|
||||||
0,
|
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| {
|
drawing_area.set_draw_func(move |_area, cr, width, height| {
|
||||||
draw_dot_matrix(cr, width, height, &dot_matrix);
|
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);
|
cr.set_source_rgb(1.0, 1.0, 0.0);
|
||||||
|
|
||||||
// Calculate spacing
|
// Calculate spacing
|
||||||
let spacing_x = 25.0;
|
let pos_x = 25.0;
|
||||||
let spacing_y = 25.0;
|
let pos_y = 25.0;
|
||||||
let radius = 10.0;
|
|
||||||
|
let mut offset_row = 0.0;
|
||||||
|
let mut current_line_width = 0.0;
|
||||||
|
|
||||||
for (row_index, row) in matrix.iter().enumerate() {
|
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() {
|
for (col_index, &val) in row.iter().enumerate() {
|
||||||
if val == 1 {
|
if val == 1 {
|
||||||
let x = (col_index as f64 + 0.5) * spacing_x;
|
let x = (col_index as f64) * pos_x + pos_x;
|
||||||
let y = (row_index as f64 + 0.5) * spacing_y;
|
let y = (row_index as f64) * pos_y + offset_row;
|
||||||
cr.arc(x, y, radius, 0.0, std::f64::consts::PI * 2.0);
|
cr.rectangle(x, y, 20.0, 20.0);
|
||||||
|
|
||||||
let _ = cr.fill();
|
let _ = cr.fill();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
0
dot-matrix/src/matrix/matrix.rs
Normal file
0
dot-matrix/src/matrix/matrix.rs
Normal file
Reference in New Issue
Block a user