A simple CPU rendered GUI IDE experience.
auto scrolling
| -rw-r--r-- | src/main.rs | 7 | ||||
| -rw-r--r-- | src/text.rs | 11 |
2 files changed, 12 insertions, 6 deletions
diff --git a/src/main.rs b/src/main.rs index c4be919..7ce16d3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -49,6 +49,7 @@ pub(crate) fn entry(event_loop: EventLoop<()>) { .with_event_handler( move |(window, _context), surface, event, elwt| { elwt.set_control_flow(ControlFlow::Wait); + let (c, r) = dsb::fit(&FONT,ppem,ls, (window.inner_size() .width as _,window.inner_size().height as _)); match event { Event::WindowEvent { window_id, @@ -78,7 +79,6 @@ pub(crate) fn entry(event_loop: EventLoop<()>) { if let (Some(width), Some(height)) = (NonZeroU32::new(size.width), NonZeroU32::new(size.height)) { - let (c, r) = dsb::fit(&FONT,ppem,ls, (size.width as _,size.height as _)); let now = Instant::now(); let mut cells = vec![Cell { style: Style { color: [36, 41, 54], bg: [204,202,194 ], flags:0 }, letter:None @@ -151,7 +151,6 @@ pub(crate) fn entry(event_loop: EventLoop<()>) { } => { if rows < 0.0 { let rows = rows.ceil().abs() as usize; - let (_, r) = dsb::fit(&FONT,ppem,ls, (window.inner_size() .width as _,window.inner_size().height as _)); text.vo = (text.vo + rows).min(text.l() - r); } else { let rows = rows.floor() as usize; @@ -166,7 +165,6 @@ pub(crate) fn entry(event_loop: EventLoop<()>) { use NamedKey::*; use Key::*; match event.logical_key { - Named(Space)=> text.insert(" "), Named(Backspace) => text.backspace(), @@ -176,8 +174,7 @@ pub(crate) fn entry(event_loop: EventLoop<()>) { Named(End) => text.end(), Named(ArrowRight)=> text.right(), Named(ArrowUp) => text.up(), - Named(ArrowDown) => text.down(), - + Named(ArrowDown) => text.down(r), Named(Enter)=> text.insert("\n"), Character(x) => { diff --git a/src/text.rs b/src/text.rs index 45b7efd..5e014d3 100644 --- a/src/text.rs +++ b/src/text.rs @@ -94,7 +94,7 @@ impl TextArea { self.setc(); } - pub fn down(&mut self) { + pub fn down(&mut self, r: usize) { let l = self.rope.try_char_to_line(self.cursor).unwrap_or(0); // next line size @@ -118,6 +118,11 @@ impl TextArea { .map(|_| 1) .unwrap_or(0) }; + if self.rope.char_to_line(self.cursor) + >= (self.vo + r).saturating_sub(5) + { + self.vo += 1; + } } pub fn up(&mut self) { @@ -131,6 +136,10 @@ impl TextArea { } else { s.len_chars() - 1 }; + if self.rope.char_to_line(self.cursor).saturating_sub(4) < self.vo + { + self.vo = self.vo.saturating_sub(1); + } } pub fn backspace(&mut self) { |