Helper: create a centered rectangle using percentage dimensions.
(percent_x: u16, percent_y: u16, r: Rect)
| 153 | |
| 154 | // Helper: create a centered rectangle using percentage dimensions. |
| 155 | fn centered_rect(percent_x: u16, percent_y: u16, r: Rect) -> Rect { |
| 156 | let popup_layout = Layout::default() |
| 157 | .direction(Direction::Vertical) |
| 158 | .constraints( |
| 159 | [ |
| 160 | Constraint::Percentage((100 - percent_y) / 2), |
| 161 | Constraint::Percentage(percent_y), |
| 162 | Constraint::Percentage((100 - percent_y) / 2), |
| 163 | ] |
| 164 | .as_ref(), |
| 165 | ) |
| 166 | .split(r); |
| 167 | Layout::default() |
| 168 | .direction(Direction::Horizontal) |
| 169 | .constraints( |
| 170 | [ |
| 171 | Constraint::Percentage((100 - percent_x) / 2), |
| 172 | Constraint::Percentage(percent_x), |
| 173 | Constraint::Percentage((100 - percent_x) / 2), |
| 174 | ] |
| 175 | .as_ref(), |
| 176 | ) |
| 177 | .split(popup_layout[1])[1] |
| 178 | } |
| 179 | |
| 180 | #[cfg(test)] |
| 181 | mod tests { |