Render popup
This commit is contained in:
1 parent
0a88196b85
commit
ec643e6edd
1 file changed
+31
-1
+31
-1
@@ -1,6 +1,9 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
use ratatui::{prelude::*, widgets::Paragraph};
|
||||
use ratatui::{
|
||||
prelude::*,
|
||||
widgets::{Block, Borders, Clear, Paragraph},
|
||||
};
|
||||
|
||||
use crate::core::{
|
||||
buffer::{BufferId, TextBuffer},
|
||||
@@ -55,6 +58,32 @@ impl TerminalState {
|
||||
self.render_command(frame, core, layout[2]);
|
||||
}
|
||||
|
||||
fn render_popup(&mut self, frame: &mut Frame, outer_rect: Rect, title: &str) {
|
||||
let block = Block::default().title(title).borders(Borders::ALL);
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
fn render_main_buffers(&mut self, frame: &mut Frame, rect: Rect, core: &EditorCore) {
|
||||
let cursor_style = cursor_style(&core);
|
||||
let line_number_style = line_number_style(&core);
|
||||
@@ -90,6 +119,7 @@ impl TerminalState {
|
||||
line_number_style,
|
||||
);
|
||||
frame.render_widget(Paragraph::new(text).white().on_black(), rect);
|
||||
self.render_popup(frame, rect, "yolo");
|
||||
}
|
||||
|
||||
fn single_buffer_lines<'a>(
|
||||
|
||||
Reference in new issue
Block a user