@@ -13,9 +13,15 @@ pub struct NonogramView {
13
13
}
14
14
15
15
impl NonogramView {
16
+ // const FILLED_STRING: &'static str = "▣";
17
+ // const NOT_FILLED_STRING: &'static str = "☒";
18
+ // const UNKNOWN_STRING: &'static str = "☐";
16
19
const FILLED_STRING : & ' static str = "#" ;
17
20
const NOT_FILLED_STRING : & ' static str = "X" ;
18
21
const UNKNOWN_STRING : & ' static str = "_" ;
22
+ const TOP_DIVIDER : char = '─' ;
23
+ const SIDE_DIVIDER : char = '│' ;
24
+ const CORNER_DIVIDER : char = '┌' ;
19
25
20
26
pub fn new ( nonogram : Nonogram ) -> Self {
21
27
NonogramView {
@@ -108,10 +114,11 @@ impl NonogramView {
108
114
let ( row, col) = location;
109
115
// all row/col clues + 1 for divider
110
116
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;
113
119
let y = y_offset + row;
114
120
let position = ( x, y) ;
121
+ eprintln ! ( "position: {:?}" , position) ;
115
122
let s = format ! (
116
123
"{:<width$}" ,
117
124
NonogramView :: maybe_tile_to_string( tile) ,
@@ -120,6 +127,42 @@ impl NonogramView {
120
127
printer. print ( position, & s) ;
121
128
}
122
129
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
+
123
166
fn row_clue_space_width ( & self ) -> usize {
124
167
self . max_row_clue_width + 1
125
168
}
@@ -147,20 +190,22 @@ impl NonogramView {
147
190
. unwrap ( )
148
191
}
149
192
150
- fn get_cell_width ( ) -> usize {
193
+ fn cell_width ( ) -> usize {
151
194
NonogramView :: get_max_cell_width ( ) + 1
152
195
}
153
196
154
197
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()
164
209
}
165
210
}
166
211
@@ -177,6 +222,7 @@ impl View for NonogramView {
177
222
// }
178
223
self . draw_all_row_clues ( printer) ;
179
224
self . draw_all_col_clues ( printer) ;
225
+ self . draw_borders ( printer) ;
180
226
self . draw_grid ( printer) ;
181
227
}
182
228
@@ -185,7 +231,7 @@ impl View for NonogramView {
185
231
self . max_num_row_clues * self . row_clue_space_width ( ) ;
186
232
let col_clues_height = self . max_num_col_clues ;
187
233
let grid_width =
188
- self . nonogram . num_cols ( ) * NonogramView :: get_cell_width ( ) ;
234
+ self . nonogram . num_cols ( ) * NonogramView :: cell_width ( ) ;
189
235
let grid_height = self . nonogram . num_rows ( ) ;
190
236
// Clues + divider + grid
191
237
let width = row_clues_width + 1 + grid_width;
@@ -194,7 +240,7 @@ impl View for NonogramView {
194
240
eprintln ! ( "max_num_col_clues: {}" , self . max_num_col_clues) ;
195
241
eprintln ! ( "max_row_clue_width: {}" , self . max_row_clue_width) ;
196
242
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 ( ) ) ;
198
244
eprintln ! ( "width: {}" , width) ;
199
245
eprintln ! ( "height: {}" , height) ;
200
246
( width, height) . into ( )
0 commit comments