More finder buffer work

This commit is contained in:
Greg Shuflin committed 2024-04-15 11:17:17 -07:00
1 parent 7ad0aa0530
commit 94b0029d8f
3 files changed
+31 -27

No files matched your search

+1 -1
View File
@@ -16,7 +16,7 @@ impl TextLines {
pub(crate) fn from_text(text: &str) -> Self {
let mut inner = Rope::new();
inner.insert(0, &text);
inner.insert(0, text);
Self { inner }
}
}
+12 -26
View File
@@ -11,13 +11,13 @@ use tracing::warn;
use crate::{
core::{
buffer::{Buffer, BufferId, TextBuffer},
buffer::{Buffer, BufferId, FinderBuffer, TextBuffer},
EditorCore,
},
tui::render::styles::{cursor_style, line_number_style},
};
use self::layout::global_layout;
use self::layout::{centered_rect, global_layout};
pub(crate) struct TerminalState {
#[allow(dead_code)]
@@ -60,9 +60,18 @@ impl TerminalState {
}
}
fn render_finder(&mut self, frame: &mut Frame, outer_rect: Rect, buffer: &FinderBuffer) {
let title = "FINDER";
//TODO
}
fn render_popup(&mut self, frame: &mut Frame, outer_rect: Rect, buffer: &TextBuffer) {
let title = buffer.title().unwrap_or("<no title>");
let inner_rect = centered_rect(50, 50, outer_rect);
frame.render_widget(Clear, inner_rect);
let popup_color = if buffer.writeable {
Color::Black
} else {
@@ -73,28 +82,6 @@ impl TerminalState {
.borders(Borders::ALL)
.bg(popup_color);
// helper function to create a centered rect using up certain percentage of the available rect `r`
// code from https://github.com/ratatui-org/ratatui/blob/main/examples/popup.rs
fn centered_rect(percent_x: u16, percent_y: u16, r: Rect) -> Rect {
let popup_layout = Layout::vertical([
Constraint::Percentage((100 - percent_y) / 2),
Constraint::Percentage(percent_y),
Constraint::Percentage((100 - percent_y) / 2),
])
.split(r);
Layout::horizontal([
Constraint::Percentage((100 - percent_x) / 2),
Constraint::Percentage(percent_x),
Constraint::Percentage((100 - percent_x) / 2),
])
.split(popup_layout[1])[1]
}
let inner_rect = centered_rect(50, 50, outer_rect);
frame.render_widget(Clear, inner_rect);
//frame.render_widget(block, inner_rect);
let start = 0;
let end = inner_rect.height as usize;
let raw_lines = buffer.visible_lines(start, end);
@@ -121,8 +108,7 @@ impl TerminalState {
match buf {
Some(Buffer::Text(floating)) => self.render_popup(frame, rect, floating),
Some(Buffer::Finder(finder)) => {
warn!("NOT DONE");
//self.render_popup(frame, rect, floating)
self.render_finder(frame, rect, finder)
}
None => {
warn!(id=?floating, "Buffer not found");
+18
View File
@@ -11,3 +11,21 @@ pub(super) fn global_layout(frame: &Frame) -> [Rect; 3] {
])
.areas(area)
}
// helper function to create a centered rect using up certain percentage of the available rect `r`
// code from https://github.com/ratatui-org/ratatui/blob/main/examples/popup.rs
pub(super) fn centered_rect(percent_x: u16, percent_y: u16, r: Rect) -> Rect {
let popup_layout = Layout::vertical([
Constraint::Percentage((100 - percent_y) / 2),
Constraint::Percentage(percent_y),
Constraint::Percentage((100 - percent_y) / 2),
])
.split(r);
Layout::horizontal([
Constraint::Percentage((100 - percent_x) / 2),
Constraint::Percentage(percent_x),
Constraint::Percentage((100 - percent_x) / 2),
])
.split(popup_layout[1])[1]
}