Skip to content

Commit 35690b8

Browse files
committed
Get interactive working
1 parent 7901fd9 commit 35690b8

File tree

3 files changed

+61
-30
lines changed

3 files changed

+61
-30
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
**/target
22
**/*.rs.bk
33
Cargo.lock
4+
*.log

log.log

-16
This file was deleted.

src/interactive.rs

+60-14
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,15 @@ pub struct NonogramView {
1313
}
1414

1515
impl NonogramView {
16+
// const FILLED_STRING: &'static str = "▣";
17+
// const NOT_FILLED_STRING: &'static str = "☒";
18+
// const UNKNOWN_STRING: &'static str = "☐";
1619
const FILLED_STRING: &'static str = "#";
1720
const NOT_FILLED_STRING: &'static str = "X";
1821
const UNKNOWN_STRING: &'static str = "_";
22+
const TOP_DIVIDER: char = '─';
23+
const SIDE_DIVIDER: char = '│';
24+
const CORNER_DIVIDER: char = '┌';
1925

2026
pub fn new(nonogram: Nonogram) -> Self {
2127
NonogramView {
@@ -108,10 +114,11 @@ impl NonogramView {
108114
let (row, col) = location;
109115
// all row/col clues + 1 for divider
110116
let x_offset = self.max_num_row_clues * self.row_clue_space_width() + 1;
111-
let y_offset = self.max_num_col_clues * self.col_clue_space_width() + 1;
112-
let x = x_offset + NonogramView::get_cell_width() * col;
117+
let y_offset = self.max_num_col_clues + 1;
118+
let x = x_offset + NonogramView::cell_width() * col;
113119
let y = y_offset + row;
114120
let position = (x, y);
121+
eprintln!("position: {:?}", position);
115122
let s = format!(
116123
"{:<width$}",
117124
NonogramView::maybe_tile_to_string(tile),
@@ -120,6 +127,42 @@ impl NonogramView {
120127
printer.print(position, &s);
121128
}
122129

130+
fn draw_borders(&self, printer: &Printer) {
131+
self.draw_top_border(printer);
132+
self.draw_side_border(printer);
133+
self.draw_corner_border(printer);
134+
}
135+
136+
fn draw_top_border(&self, printer: &Printer) {
137+
let x = self.max_num_row_clues * self.row_clue_space_width() + 1;
138+
let y = self.max_num_col_clues;
139+
let position = (x, y);
140+
let width = self.nonogram.num_cols() * NonogramView::cell_width();
141+
let s = NonogramView::TOP_DIVIDER.to_string().repeat(width);
142+
printer.print(position, &s);
143+
}
144+
145+
fn draw_side_border(&self, printer: &Printer) {
146+
let x = self.max_num_row_clues * self.row_clue_space_width();
147+
let y_offset = self.max_num_col_clues + 1;
148+
let s = NonogramView::SIDE_DIVIDER.to_string();
149+
eprintln!("s: {}", s);
150+
for j in 0..self.nonogram.num_rows() {
151+
let y = y_offset + j;
152+
let position = (x, y);
153+
eprintln!("position: {:?}", position);
154+
printer.print(position, &s);
155+
}
156+
}
157+
158+
fn draw_corner_border(&self, printer: &Printer) {
159+
let x = self.max_num_row_clues * self.row_clue_space_width();
160+
let y = self.max_num_col_clues;
161+
let position = (x, y);
162+
let s = NonogramView::CORNER_DIVIDER.to_string();
163+
printer.print(position, &s);
164+
}
165+
123166
fn row_clue_space_width(&self) -> usize {
124167
self.max_row_clue_width + 1
125168
}
@@ -147,20 +190,22 @@ impl NonogramView {
147190
.unwrap()
148191
}
149192

150-
fn get_cell_width() -> usize {
193+
fn cell_width() -> usize {
151194
NonogramView::get_max_cell_width() + 1
152195
}
153196

154197
fn get_max_cell_width() -> usize {
155-
[
156-
NonogramView::FILLED_STRING,
157-
NonogramView::NOT_FILLED_STRING,
158-
NonogramView::UNKNOWN_STRING,
159-
]
160-
.into_iter()
161-
.map(|s| s.len())
162-
.max()
163-
.unwrap()
198+
1
199+
// 2
200+
// [
201+
// NonogramView::FILLED_STRING,
202+
// NonogramView::NOT_FILLED_STRING,
203+
// NonogramView::UNKNOWN_STRING,
204+
// ]
205+
// .into_iter()
206+
// .map(|s| s.len())
207+
// .max()
208+
// .unwrap()
164209
}
165210
}
166211

@@ -177,6 +222,7 @@ impl View for NonogramView {
177222
// }
178223
self.draw_all_row_clues(printer);
179224
self.draw_all_col_clues(printer);
225+
self.draw_borders(printer);
180226
self.draw_grid(printer);
181227
}
182228

@@ -185,7 +231,7 @@ impl View for NonogramView {
185231
self.max_num_row_clues * self.row_clue_space_width();
186232
let col_clues_height = self.max_num_col_clues;
187233
let grid_width =
188-
self.nonogram.num_cols() * NonogramView::get_cell_width();
234+
self.nonogram.num_cols() * NonogramView::cell_width();
189235
let grid_height = self.nonogram.num_rows();
190236
// Clues + divider + grid
191237
let width = row_clues_width + 1 + grid_width;
@@ -194,7 +240,7 @@ impl View for NonogramView {
194240
eprintln!("max_num_col_clues: {}", self.max_num_col_clues);
195241
eprintln!("max_row_clue_width: {}", self.max_row_clue_width);
196242
eprintln!("max_col_clue_width: {}", self.max_col_clue_width);
197-
eprintln!("cell_width: {}", NonogramView::get_cell_width());
243+
eprintln!("cell_width: {}", NonogramView::cell_width());
198244
eprintln!("width: {}", width);
199245
eprintln!("height: {}", height);
200246
(width, height).into()

0 commit comments

Comments
 (0)