macro'd closure arguments

type-render
korin 3 years ago
parent 394f6d2fb8
commit 5402fedede
  1. 2
      src/editor_render.rs
  2. 39
      src/main.rs

@ -49,7 +49,7 @@ pub fn generate_glyph_data() -> (Vec<Glyph>, GlyphMetrics) {
let width_right_byte = contents[1];
let width_bytes = [width_left_byte, width_right_byte];
let width = u16::from_be_bytes(width_bytes);
println!("Left Byte: {width_left_byte}, Right Byte: {width_right_byte}, Byte Pair: {width}");
// println!("Left Byte: {width_left_byte}, Right Byte: {width_right_byte}, Byte Pair: {width}");
let gtable_prune = &contents[width as usize + 2 ..];

@ -16,7 +16,7 @@ static SCREEN_HEIGHT: u32 = 720;
static REFRESH_RATE: u32 = 50;
// TODO: Make this configurable
static UNDO_TIME: u32 = 500;
static UNDO_TIME: u32 = 250;
static UNDO_TIME_COUNT: u32 = (REFRESH_RATE as f32 * (UNDO_TIME as f32 / 1000.0)) as u32;
struct ModifierKeys {
@ -25,6 +25,7 @@ struct ModifierKeys {
shift: bool,
}
pub fn main() -> Result<(), String> {
let mut modifier_keys = ModifierKeys {alt: false, ctrl: false, shift: false};
@ -109,9 +110,14 @@ pub fn main() -> Result<(), String> {
Ok(())
};
// Easier way to please the borrow checker
macro_rules! draw {
() => {
draw(window_size, &buffer, cursor_position)?
};
}
draw(window_size, "", cursor_position)?;
draw!();
'mainloop: loop {
// TODO: Make this completely user-configurable instead of hardcoded
for event in sdl_context.event_pump()?.poll_iter() {
@ -119,7 +125,7 @@ pub fn main() -> Result<(), String> {
Event::Window { win_event, .. } => {
if let WindowEvent::Resized(w, h) = win_event {
window_size = (w as u32, h as u32);
draw(window_size, &buffer, cursor_position)?
draw!();
}
}
// ESC or SIGKILL
@ -172,7 +178,7 @@ pub fn main() -> Result<(), String> {
selection_anchor = None;
buffer.remove(cursor_position);
draw(window_size, &buffer, cursor_position)?
draw!();
}
},
@ -184,7 +190,7 @@ pub fn main() -> Result<(), String> {
let key = '\n';
buffer.insert(cursor_position, key);
cursor_position += 1;
draw(window_size, &buffer, cursor_position)?
draw!();
},
// HOME key
@ -192,7 +198,7 @@ pub fn main() -> Result<(), String> {
selection_anchor = None;
cursor_position = 0;
draw(window_size, &buffer, cursor_position)?
draw!();
},
// END key
@ -200,7 +206,7 @@ pub fn main() -> Result<(), String> {
selection_anchor = None;
cursor_position = buffer.len();
draw(window_size, &buffer, cursor_position)?
draw!();
},
// Left/Back arrow
@ -209,7 +215,7 @@ pub fn main() -> Result<(), String> {
cursor_position = usize::checked_sub(cursor_position, 1)
.unwrap_or(0);
draw(window_size, &buffer, cursor_position)?
draw!();
},
// Right/Forward arrow
@ -217,7 +223,7 @@ pub fn main() -> Result<(), String> {
selection_anchor = None;
cursor_position = (cursor_position + 1).min(buffer.len());
draw(window_size, &buffer, cursor_position)?
draw!();
},
// BACKSPACE key
@ -229,7 +235,7 @@ pub fn main() -> Result<(), String> {
buffer.remove(cursor_position - 1);
cursor_position -= 1;
draw(window_size, &buffer, cursor_position)?
draw!();
}
},
@ -247,7 +253,7 @@ pub fn main() -> Result<(), String> {
buffer = last_undo.0;
cursor_position = last_undo.1;
draw(window_size, &buffer, cursor_position)?
draw!();
}
},
@ -263,9 +269,8 @@ pub fn main() -> Result<(), String> {
cursor_position += 1;
undo_timer = UNDO_TIME_COUNT;
}
draw(window_size, &buffer, cursor_position)?
draw!();
},
// BACKSPACE key
@ -287,7 +292,7 @@ pub fn main() -> Result<(), String> {
buffer.remove(cursor_position - 1);
cursor_position -= 1;
draw(window_size, &buffer, cursor_position)?
draw!();
}
},
_ => (),
@ -303,7 +308,7 @@ pub fn main() -> Result<(), String> {
buffer = last_redo.0;
cursor_position = last_redo.1;
draw(window_size, &buffer, cursor_position)?
draw!();
}
},
@ -326,7 +331,7 @@ pub fn main() -> Result<(), String> {
buffer.insert(cursor_position, input_char);
cursor_position += 1;
draw(window_size, &buffer, cursor_position)?;
draw!();
},
_ => {}

Loading…
Cancel
Save