From 0ca1b4ba546faf64f2a32792ce0bbb576a7ab801 Mon Sep 17 00:00:00 2001 From: CrispyPin Date: Mon, 7 Oct 2024 00:20:52 +0200 Subject: [PATCH] show more output cells when space is available --- src/editor.rs | 23 +++++++++++++---------- src/marble_engine/board.rs | 2 +- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/editor.rs b/src/editor.rs index 1af0ef3..8d3e515 100644 --- a/src/editor.rs +++ b/src/editor.rs @@ -1,4 +1,4 @@ -use std::ops::Rem; +use std::{mem::transmute, ops::Rem}; use raylib::prelude::*; @@ -404,7 +404,7 @@ impl Editor { texture_option_button( d, Vector2 { - x: 320. + col as f32 * bound_offset - if col < 0 { 15. } else { 0. }, + x: 100. + col as f32 * bound_offset - if col < 0 { 10. } else { 0. }, y: footer_top + 5. + row as f32 * bound_offset, }, textures.get(texture), @@ -453,8 +453,12 @@ impl Editor { Tool::Gate, ); + let output_x = 370; + let output_cell_width = 43; + let output_cells = (d.get_screen_width() - output_x) as usize / 43; + let y = footer_top as i32 + 5; - if simple_button(d, 600, y + 70, 65, 15) { + if simple_button(d, output_x, y + 70, 65, 15) { self.output_as_text = !self.output_as_text } let output_mode_text = if self.output_as_text { @@ -462,11 +466,12 @@ impl Editor { } else { "show text" }; - d.draw_text(output_mode_text, 605, y + 72, 10, Color::WHITE); - let output_start = self.machine.output().len().saturating_sub(8); - let output_end = output_start + 8; + d.draw_text(output_mode_text, output_x + 5, y + 72, 10, Color::WHITE); + + let output_start = self.machine.output().len().saturating_sub(output_cells); + let output_end = output_start + output_cells; for (box_index, index) in (output_start..output_end).enumerate() { - let x = 600 + 43 * box_index as i32; + let x = output_x + output_cell_width * box_index as i32; let expected_byte = self.level.outputs().get(index); let real_byte = self.machine.output().get(index); @@ -534,9 +539,7 @@ impl Editor { } let pos = *pos; for n in 0..10 { - if d.is_key_pressed(unsafe { - std::mem::transmute(KeyboardKey::KEY_ZERO as u32 + n) - }) { + if d.is_key_pressed(unsafe { transmute::(b'0' as u32 + n) }) { self.set_tile(pos, Tile::Digit(n as u8)); } } diff --git a/src/marble_engine/board.rs b/src/marble_engine/board.rs index bf7aa4d..d3ee3f3 100644 --- a/src/marble_engine/board.rs +++ b/src/marble_engine/board.rs @@ -227,7 +227,7 @@ impl Board { if self.in_bounds((tx, ty).into()) { let tile = self.rows[ty][tx]; let texname = tile.texture(); - if texname == "" { + if texname.is_empty() { continue; } let texture = textures.get(&texname);