diff options
author | Akshay <[email protected]> | 2021-04-06 04:33:37 +0100 |
---|---|---|
committer | Akshay <[email protected]> | 2021-04-06 04:33:37 +0100 |
commit | 3f5b917c6ced370d940774b51ff89cec0d03c562 (patch) | |
tree | a43b39ca9c3e5384b0752b5f140c1eaf916b460c | |
parent | 931d256d62a1a20c8ba8a8b6726fb1d7167f1d68 (diff) |
draw grid and pixmap boundary separately
-rw-r--r-- | src/app.rs | 52 | ||||
-rw-r--r-- | src/command.rs | 26 | ||||
-rw-r--r-- | src/lisp/lex.rs | 4 | ||||
-rw-r--r-- | src/lisp/std.lisp | 2 |
4 files changed, 61 insertions, 23 deletions
@@ -336,14 +336,14 @@ impl<'ctx> AppState<'ctx> { | |||
336 | let (width, height) = (self.width(), self.height()); | 336 | let (width, height) = (self.width(), self.height()); |
337 | let canvas = &mut self.canvas; | 337 | let canvas = &mut self.canvas; |
338 | canvas.set_draw_color(self.grid.color); | 338 | canvas.set_draw_color(self.grid.color); |
339 | for i in 0..=width { | 339 | for i in 1..width { |
340 | let x = (i * cs) as i32; | 340 | let x = (i * cs) as i32; |
341 | let y = (height * cs) as i32; | 341 | let y = (height * cs) as i32; |
342 | let start = self.start + Point::new(x, 0); | 342 | let start = self.start + Point::new(x, 0); |
343 | let end = self.start + Point::new(x, y); | 343 | let end = self.start + Point::new(x, y); |
344 | canvas.draw_line(start, end).unwrap(); | 344 | canvas.draw_line(start, end).unwrap(); |
345 | } | 345 | } |
346 | for j in 0..=height { | 346 | for j in 1..height { |
347 | let x = (width * cs) as i32; | 347 | let x = (width * cs) as i32; |
348 | let y = (j * cs) as i32; | 348 | let y = (j * cs) as i32; |
349 | let start = self.start + Point::new(0, y); | 349 | let start = self.start + Point::new(0, y); |
@@ -560,17 +560,26 @@ impl<'ctx> AppState<'ctx> { | |||
560 | for (color, length) in utils::compress(scan) { | 560 | for (color, length) in utils::compress(scan) { |
561 | if color { | 561 | if color { |
562 | self.canvas | 562 | self.canvas |
563 | .fill_rect(Rect::new( | 563 | .fill_rect(rect!( |
564 | (pass as u32 * cs) as i32 + start.x(), | 564 | (pass as u32 * cs) as i32 + start.x(), |
565 | (line_nr as u32 * cs) as i32 + start.y(), | 565 | (line_nr as u32 * cs) as i32 + start.y(), |
566 | cs * length as u32, | 566 | cs * length as u32, |
567 | cs, | 567 | cs |
568 | )) | 568 | )) |
569 | .unwrap(); | 569 | .unwrap(); |
570 | } | 570 | } |
571 | pass += length; | 571 | pass += length; |
572 | } | 572 | } |
573 | } | 573 | } |
574 | self.canvas.set_draw_color(GRID_COLOR); | ||
575 | self.canvas | ||
576 | .draw_rect(rect!( | ||
577 | start.x(), | ||
578 | start.y(), | ||
579 | self.width() * cs, | ||
580 | self.height() * cs | ||
581 | )) | ||
582 | .unwrap(); | ||
574 | if grid_enabled { | 583 | if grid_enabled { |
575 | self.draw_grid(); | 584 | self.draw_grid(); |
576 | } | 585 | } |
@@ -884,19 +893,24 @@ impl<'ctx> AppState<'ctx> { | |||
884 | .push_str(&clipboard.clipboard_text().unwrap()); | 893 | .push_str(&clipboard.clipboard_text().unwrap()); |
885 | } | 894 | } |
886 | } | 895 | } |
887 | if let Event::KeyDown { | 896 | match event { |
888 | keycode: Some(k), | 897 | Event::KeyDown { |
889 | keymod, | 898 | keycode: Some(k), |
890 | .. | 899 | keymod, |
891 | } = event | 900 | .. |
892 | { | 901 | } => match k { |
893 | match k { | ||
894 | Keycode::Backspace => self.command_box.backspace(), | 902 | Keycode::Backspace => self.command_box.backspace(), |
895 | Keycode::Delete => self.command_box.delete(), | 903 | Keycode::Delete => self.command_box.delete(), |
896 | Keycode::Left => self.command_box.backward(), | 904 | Keycode::Left => self.command_box.backward(), |
897 | Keycode::Right => self.command_box.forward(), | 905 | Keycode::Right => self.command_box.forward(), |
898 | Keycode::Up => self.command_box.hist_prev(), | 906 | Keycode::Up => self.command_box.hist_prev(), |
899 | Keycode::Down => self.command_box.hist_next(), | 907 | Keycode::Down => self.command_box.hist_next(), |
908 | Keycode::Return => self.eval_command(), | ||
909 | Keycode::Escape => { | ||
910 | self.command_box.clear(); | ||
911 | self.message.text.clear(); | ||
912 | self.mode = Mode::Draw; | ||
913 | } | ||
900 | _ if keymod == Mod::LCTRLMOD => match k { | 914 | _ if keymod == Mod::LCTRLMOD => match k { |
901 | Keycode::A => self.command_box.cursor_start(), | 915 | Keycode::A => self.command_box.cursor_start(), |
902 | Keycode::E => self.command_box.cursor_end(), | 916 | Keycode::E => self.command_box.cursor_end(), |
@@ -906,16 +920,14 @@ impl<'ctx> AppState<'ctx> { | |||
906 | Keycode::U => self.command_box.delete_to_start(), | 920 | Keycode::U => self.command_box.delete_to_start(), |
907 | _ => (), | 921 | _ => (), |
908 | }, | 922 | }, |
909 | Keycode::Return => self.eval_command(), | 923 | // how does one handle alt keys |
910 | Keycode::Escape => { | 924 | // _ if keymod == Mod::LALTMOD => match k { |
911 | self.command_box.clear(); | 925 | // Keycode::B => self.command_box.cursor_back_word(), |
912 | self.message.text = format!(" "); | 926 | // Keycode::F => self.command_box.cursor_forward_word(), |
913 | self.mode = Mode::Draw; | 927 | // _ => (), |
914 | } | 928 | // }, |
915 | _ => (), | 929 | _ => (), |
916 | } | 930 | }, |
917 | } | ||
918 | match event { | ||
919 | Event::TextInput { text, .. } => { | 931 | Event::TextInput { text, .. } => { |
920 | self.command_box.push_str(&text[..]); | 932 | self.command_box.push_str(&text[..]); |
921 | } | 933 | } |
diff --git a/src/command.rs b/src/command.rs index f5a24c9..383389e 100644 --- a/src/command.rs +++ b/src/command.rs | |||
@@ -30,6 +30,32 @@ impl CommandBox { | |||
30 | self.cursor = 0; | 30 | self.cursor = 0; |
31 | } | 31 | } |
32 | 32 | ||
33 | pub fn cursor_back_word(&mut self) { | ||
34 | let mut prev_word_idx = 0; | ||
35 | { | ||
36 | let sl = &self.text[0..self.cursor]; | ||
37 | let idx = sl.rfind(|c: char| !c.is_alphanumeric() && c != '_'); | ||
38 | if let Some(i) = idx { | ||
39 | prev_word_idx = i; | ||
40 | } | ||
41 | } | ||
42 | self.cursor = prev_word_idx; | ||
43 | } | ||
44 | |||
45 | pub fn cursor_forward_word(&mut self) { | ||
46 | let mut next_word_idx = self.cursor; | ||
47 | { | ||
48 | if self.cursor != self.text.len() { | ||
49 | let sl = &self.text[self.cursor..]; | ||
50 | let idx = sl.find(|c: char| !c.is_alphanumeric() && c != '_'); | ||
51 | if let Some(i) = idx { | ||
52 | next_word_idx = i; | ||
53 | } | ||
54 | } | ||
55 | } | ||
56 | self.cursor = next_word_idx; | ||
57 | } | ||
58 | |||
33 | pub fn backward(&mut self) { | 59 | pub fn backward(&mut self) { |
34 | self.cursor = self.cursor.saturating_sub(1); | 60 | self.cursor = self.cursor.saturating_sub(1); |
35 | } | 61 | } |
diff --git a/src/lisp/lex.rs b/src/lisp/lex.rs index 5d3030b..2088421 100644 --- a/src/lisp/lex.rs +++ b/src/lisp/lex.rs | |||
@@ -120,8 +120,8 @@ impl<'a> Lexer<'a> { | |||
120 | while let Some((ind, chr)) = chars.next() { | 120 | while let Some((ind, chr)) = chars.next() { |
121 | let low = self.cur_pos; | 121 | let low = self.cur_pos; |
122 | let res = match chr { | 122 | let res = match chr { |
123 | '(' => Ok((1, Token::LeftParen)), | 123 | '(' | '[' => Ok((1, Token::LeftParen)), |
124 | ')' => Ok((1, Token::RightParen)), | 124 | ')' | ']' => Ok((1, Token::RightParen)), |
125 | '\'' => Ok((1, Token::Quote)), | 125 | '\'' => Ok((1, Token::Quote)), |
126 | '`' => Ok((1, Token::BackQuote)), | 126 | '`' => Ok((1, Token::BackQuote)), |
127 | ',' => match chars.next() { | 127 | ',' => match chars.next() { |
diff --git a/src/lisp/std.lisp b/src/lisp/std.lisp index 97c3984..2a042a0 100644 --- a/src/lisp/std.lisp +++ b/src/lisp/std.lisp | |||
@@ -47,7 +47,7 @@ | |||
47 | (define (product ls) (fold 1 * ls)) | 47 | (define (product ls) (fold 1 * ls)) |
48 | 48 | ||
49 | (define (enumerate start stop step) | 49 | (define (enumerate start stop step) |
50 | (if (> start stop) | 50 | (if (>= start stop) |
51 | '() | 51 | '() |
52 | (cons start | 52 | (cons start |
53 | (enumerate (+ start step) stop step)))) | 53 | (enumerate (+ start step) stop step)))) |