diff --git a/src/io/graphics.rs b/src/io/graphics.rs index 7035df2693b534fc0022a6672ecabba7306d00e3..39ad71cf7856b63e1d672a4a2af99a7920beb6c4 100644 --- a/src/io/graphics.rs +++ b/src/io/graphics.rs @@ -14,17 +14,30 @@ impl Editor { /// Redraw the window pub fn redraw(&mut self) { // TODO: Only draw when relevant for the window + let (pos_x, pos_y) = self.pos(); + + let w = self.window.width(); + let h = self.window.height(); + + if self.buffers.current_buffer_info().scroll_y > 0 && pos_y <= self.buffers.current_buffer_info().scroll_y { + self.buffers.current_buffer_info_mut().scroll_y = pos_y - 1; + } + + let window_lines = (h as usize/16) - 2; + + if pos_y > self.buffers.current_buffer_info().scroll_y + window_lines { + self.buffers.current_buffer_info_mut().scroll_y = pos_y - window_lines; + } + let (scroll_x, scroll_y) = { let current_buffer = self.buffers.current_buffer_info(); (current_buffer.scroll_x, current_buffer.scroll_y) }; - let (pos_x, pos_y) = self.pos(); + // Redraw window self.window.set(Color::rgb(25, 25, 25)); - let w = self.window.width(); - if self.options.line_marker { self.window.rect(0, (pos_y - scroll_y) as i32 * 16, @@ -65,17 +78,17 @@ impl Editor { } else { (255, 255, 255) }; - + let c = if c == '\t' { ' ' } else { c }; if pos_x == x && pos_y == y { - self.window.char(8 * (x - scroll_x) as i32, - 16 * (y - scroll_y) as i32, + self.window.char(8 * (x as isize - scroll_x as isize) as i32, + 16 * (y as isize - scroll_y as isize) as i32, c, Color::rgb(color.0 / 3, color.1 / 3, color.2 / 3)); } else { - self.window.char(8 * (x - scroll_x) as i32, - 16 * (y - scroll_y) as i32, + self.window.char(8 * (x as isize - scroll_x as isize) as i32, + 16 * (y as isize - scroll_y as isize) as i32, c, Color::rgb(color.0, color.1, color.2)); } diff --git a/src/state/editor.rs b/src/state/editor.rs index bc148cc6ef64fd46e278f0f2f2870eb7654a4aa0..5fc98ca5eb6ce605eb08a7ee6b1eb10417f63cfd 100644 --- a/src/state/editor.rs +++ b/src/state/editor.rs @@ -10,6 +10,8 @@ use io::redraw::RedrawTask; #[cfg(feature = "orbital")] use orbclient::Window; +#[cfg(feature = "orbital")] +use orbclient::WindowFlag; use std::env::args; @@ -182,7 +184,7 @@ impl Editor { pub fn init() { #[cfg(feature = "orbital")] - let window = Window::new(-1, -1, 700, 500, &"Sodium").unwrap(); + let window = Window::new_flags(-1, -1, 700, 500, &"Sodium", &[WindowFlag::Resizable]).unwrap(); #[cfg(feature = "orbital")] let mut editor = Editor {