add centered_rect
widget helper function
This commit is contained in:
parent
5161f3db75
commit
01c478c137
1 changed files with 10 additions and 1 deletions
|
@ -4,7 +4,7 @@ use joecalsend::ReceiveRequest;
|
|||
use log::LevelFilter;
|
||||
use ratatui::{
|
||||
buffer::Buffer,
|
||||
layout::{Constraint, Layout, Margin, Rect},
|
||||
layout::{Constraint, Flex, Layout, Margin, Rect},
|
||||
style::{Color, Style, Stylize},
|
||||
symbols::border,
|
||||
text::{Line, Text, ToLine},
|
||||
|
@ -362,3 +362,12 @@ impl Widget for NetworkInfoWidget {
|
|||
table.render(area, buf);
|
||||
}
|
||||
}
|
||||
|
||||
// helpers
|
||||
fn centered_rect(area: Rect, width_pct: u16, height_pct: u16) -> Rect {
|
||||
let horizontal = Layout::horizontal([Constraint::Percentage(width_pct)]).flex(Flex::Center);
|
||||
let vertical = Layout::vertical([Constraint::Percentage(height_pct)]).flex(Flex::Center);
|
||||
let [area] = vertical.areas(area);
|
||||
let [area] = horizontal.areas(area);
|
||||
area
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue