Skip to content

Commit 2fa6dcb

Browse files
authored
Add clamping of the right side of the tape (#40)
* Add clamping of the right side of the tape * Bump version
1 parent 4d60284 commit 2fa6dcb

File tree

4 files changed

+15
-6
lines changed

4 files changed

+15
-6
lines changed

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "turing-machine"
3-
version = "1.3.3"
3+
version = "1.3.4"
44
edition = "2021"
55
authors = ["Marcos Gutiérrez Alonso <margual56@gmail.com>"]
66
description = "Turing Machine Simulator"

Trunk.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
[build]
2-
filehash = false
2+
filehash = false

src/turing_widget.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ impl Widget for &mut TuringWidget {
239239

240240
let pos = center + Vec2::new(self.offset * size.x, 0.0);
241241

242-
for i in 0..(self.tm.tape.len()) {
242+
for i in 0..(self.tm.tape.len() + 5) {
243243
let position = Pos2::new(
244244
pos.x + (i as f32 - self.tm.tape_position as f32) * size.x,
245245
pos.y,
@@ -248,7 +248,10 @@ impl Widget for &mut TuringWidget {
248248
if ui.is_rect_visible(rect) {
249249
if rect.min.x < self.left {
250250
rect.set_left(self.left);
251+
} else if rect.max.x > self.left + ui.ctx().screen_rect().width() - 200.0 {
252+
rect.set_right(self.left + ui.ctx().screen_rect().width() - 200.0);
251253
}
254+
252255
ui.painter()
253256
.rect_filled(rect, rounding, Color32::LIGHT_BLUE);
254257
ui.painter().rect_stroke(rect, rounding, stroke);
@@ -257,11 +260,17 @@ impl Widget for &mut TuringWidget {
257260
ui.painter().text(
258261
position,
259262
Align2::CENTER_CENTER,
260-
if self.tm.tape[i] { "1" } else { "0" },
263+
if self.tm.get(i).unwrap_or(false) {
264+
"1"
265+
} else {
266+
"0"
267+
},
261268
self.font_id.clone(),
262269
Color32::BLACK,
263270
);
264271
}
272+
} else {
273+
continue;
265274
}
266275
}
267276

0 commit comments

Comments
 (0)