this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

editor pt2.1

alice dc762185 e3049526

+101 -1
+17
tic80_rust/Cargo.lock
··· 1497 1497 checksum = "19b30a45b0cd0bcca8037f3d0dc3421eaf95327a17cad11964fb8179b4fc4832" 1498 1498 1499 1499 [[package]] 1500 + name = "ropey" 1501 + version = "1.6.1" 1502 + source = "registry+https://github.com/rust-lang/crates.io-index" 1503 + checksum = "93411e420bcd1a75ddd1dc3caf18c23155eda2c090631a85af21ba19e97093b5" 1504 + dependencies = [ 1505 + "smallvec", 1506 + "str_indices", 1507 + ] 1508 + 1509 + [[package]] 1500 1510 name = "rtrb" 1501 1511 version = "0.3.2" 1502 1512 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 1679 1689 checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" 1680 1690 1681 1691 [[package]] 1692 + name = "str_indices" 1693 + version = "0.4.4" 1694 + source = "registry+https://github.com/rust-lang/crates.io-index" 1695 + checksum = "d08889ec5408683408db66ad89e0e1f93dff55c73a4ccc71c427d5b277ee47e6" 1696 + 1697 + [[package]] 1682 1698 name = "strength_reduce" 1683 1699 version = "0.2.4" 1684 1700 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 1751 1767 "parking_lot", 1752 1768 "pixels", 1753 1769 "realfft", 1770 + "ropey", 1754 1771 "rtrb", 1755 1772 "winit", 1756 1773 ]
+1
tic80_rust/Cargo.toml
··· 18 18 parking_lot = "0.12" 19 19 anyhow = "1" 20 20 realfft = "3" 21 + ropey = "1"
+82
tic80_rust/src/editor/code.rs
··· 1 + use ropey::Rope; 2 + 3 + #[derive(Copy, Clone, Debug)] 4 + pub struct Area { 5 + pub x: i32, 6 + pub y: i32, 7 + pub w: i32, 8 + pub h: i32, 9 + } 10 + 11 + pub struct CodeBuffer { 12 + rope: Rope, 13 + pub caret_line: usize, 14 + pub caret_col: usize, 15 + pub scroll_line: usize, 16 + pub scroll_col: usize, 17 + } 18 + 19 + impl CodeBuffer { 20 + #[must_use] 21 + pub fn from_text(text: &str) -> Self { 22 + Self { 23 + rope: Rope::from_str(text), 24 + caret_line: 0, 25 + caret_col: 0, 26 + scroll_line: 0, 27 + scroll_col: 0, 28 + } 29 + } 30 + 31 + pub fn line_count(&self) -> usize { 32 + self.rope.len_lines() 33 + } 34 + 35 + pub fn line_len(&self, line: usize) -> usize { 36 + if line >= self.rope.len_lines() { 37 + 0 38 + } else { 39 + self.rope.line(line).len_chars() 40 + } 41 + } 42 + 43 + pub fn move_left(&mut self) { 44 + if self.caret_col > 0 { 45 + self.caret_col -= 1; 46 + } else if self.caret_line > 0 { 47 + self.caret_line -= 1; 48 + self.caret_col = self.line_len(self.caret_line); 49 + } 50 + } 51 + 52 + pub fn move_right(&mut self) { 53 + let len = self.line_len(self.caret_line); 54 + if self.caret_col < len { 55 + self.caret_col += 1; 56 + } else if self.caret_line + 1 < self.line_count() { 57 + self.caret_line += 1; 58 + self.caret_col = 0; 59 + } 60 + } 61 + 62 + pub fn move_up(&mut self) { 63 + if self.caret_line > 0 { 64 + self.caret_line -= 1; 65 + let len = self.line_len(self.caret_line); 66 + if self.caret_col > len { 67 + self.caret_col = len; 68 + } 69 + } 70 + } 71 + 72 + pub fn move_down(&mut self) { 73 + if self.caret_line + 1 < self.line_count() { 74 + self.caret_line += 1; 75 + let len = self.line_len(self.caret_line); 76 + if self.caret_col > len { 77 + self.caret_col = len; 78 + } 79 + } 80 + } 81 + } 82 +
+1 -1
tic80_rust/src/editor/mod.rs
··· 1 1 pub mod ui; 2 - 2 + pub mod code;