Implement vertical split calculations.

imgbot
Blaž Hrastnik 4 years ago
parent d4b85ce18d
commit 5e73f83efa

@ -10,8 +10,9 @@
1 1
- [ ] selection mode - [ ] selection mode
- [x] % for whole doc selection - [x] % for whole doc selection
- [ ] vertical splits - [x] vertical splits
- [ ] input counts (30j) - [ ] input counts (30j)
- [ ] respect view fullscreen flag
- [ ] retain horiz when moving vertically - [ ] retain horiz when moving vertically
- [ ] update lsp on redo/undo - [ ] update lsp on redo/undo
- [ ] Implement marks (superset of Selection/Range) - [ ] Implement marks (superset of Selection/Range)

@ -42,8 +42,8 @@ impl EditorView {
viewport.x + OFFSET, viewport.x + OFFSET,
viewport.y, viewport.y,
viewport.width - OFFSET, viewport.width - OFFSET,
viewport.height - 2, viewport.height - 1,
); // - 2 for statusline and prompt ); // - 1 for statusline
self.render_buffer(view, area, surface, theme, is_focused); self.render_buffer(view, area, surface, theme, is_focused);
// clear with background color // clear with background color
@ -52,7 +52,7 @@ impl EditorView {
let area = Rect::new( let area = Rect::new(
viewport.x, viewport.x,
viewport.y + viewport.height - 2, viewport.y + viewport.height - 1,
viewport.width, viewport.width,
1, 1,
); );
@ -301,9 +301,8 @@ impl Component for EditorView {
fn handle_event(&mut self, event: Event, cx: &mut Context) -> EventResult { fn handle_event(&mut self, event: Event, cx: &mut Context) -> EventResult {
match event { match event {
Event::Resize(width, height) => { Event::Resize(width, height) => {
// TODO: simplistic ensure cursor in view for now // HAXX: offset the render area height by 1 to account for prompt/commandline
// TODO: loop over views cx.editor.tree.resize(Rect::new(0, 0, width, height - 1));
cx.editor.tree.resize(Rect::new(0, 0, width, height));
// TODO: restore view.ensure_cursor_in_view(); // TODO: restore view.ensure_cursor_in_view();
EventResult::Consumed(None) EventResult::Consumed(None)
} }
@ -353,10 +352,11 @@ impl Component for EditorView {
} }
} }
fn render(&self, area: Rect, surface: &mut Surface, cx: &mut Context) { fn render(&self, mut area: Rect, surface: &mut Surface, cx: &mut Context) {
// SAFETY: we cheat around the view_mut() borrow because it doesn't allow us to also borrow // SAFETY: we cheat around the view_mut() borrow because it doesn't allow us to also borrow
// theme. Theme is immutable mutating view won't disrupt theme_ref. // theme. Theme is immutable mutating view won't disrupt theme_ref.
let theme_ref = unsafe { &*(&cx.editor.theme as *const Theme) }; let theme_ref = unsafe { &*(&cx.editor.theme as *const Theme) };
for (view, is_focused) in cx.editor.tree.views() { for (view, is_focused) in cx.editor.tree.views() {
// TODO: use parent area // TODO: use parent area
self.render_view(view, view.area, surface, theme_ref, is_focused); self.render_view(view, view.area, surface, theme_ref, is_focused);

@ -15,10 +15,13 @@ pub struct Editor {
} }
impl Editor { impl Editor {
pub fn new(area: tui::layout::Rect) -> Self { pub fn new(mut area: tui::layout::Rect) -> Self {
let theme = Theme::default(); let theme = Theme::default();
let language_servers = helix_lsp::Registry::new(); let language_servers = helix_lsp::Registry::new();
// HAXX: offset the render area height by 1 to account for prompt/commandline
area.height -= 1;
Self { Self {
tree: Tree::new(area), tree: Tree::new(area),
should_close: false, should_close: false,

@ -156,7 +156,31 @@ impl Tree {
container.area = area; container.area = area;
match container.layout { match container.layout {
Layout::Vertical => unimplemented!(), Layout::Vertical => {
let len = container.children.len();
let height = area.height / len as u16;
let mut child_y = area.y;
for (i, child) in container.children.iter().enumerate() {
let mut area = Rect::new(
container.area.x,
child_y,
container.area.width,
height,
);
child_y += height;
// last child takes the remaining width because we can get uneven
// space from rounding
if i == len - 1 {
area.height = container.area.y + container.area.height - area.y;
}
self.stack.push((*child, area));
}
}
Layout::Horizontal => { Layout::Horizontal => {
let len = container.children.len(); let len = container.children.len();

@ -51,7 +51,7 @@ impl View {
/// Calculates the last visible line on screen /// Calculates the last visible line on screen
#[inline] #[inline]
pub fn last_line(&self) -> usize { pub fn last_line(&self) -> usize {
let viewport = Rect::new(6, 0, self.area.width, self.area.height - 2); // - 2 for statusline and prompt let viewport = Rect::new(6, 0, self.area.width, self.area.height - 1); // - 1 for statusline
std::cmp::min( std::cmp::min(
self.first_line + (viewport.height as usize), self.first_line + (viewport.height as usize),
self.doc.text().len_lines() - 1, self.doc.text().len_lines() - 1,

Loading…
Cancel
Save