feat: upgrade to ratatui 0.30, use native APIs
This commit is contained in:
1 parent
e33d3673fb
commit
c70d247a2b
6 files changed
+871
-140
No files matched your search
@@ -3,7 +3,7 @@ use ratatui::{
|
||||
layout::{Alignment, Rect},
|
||||
style::{Color, Style},
|
||||
text::Line,
|
||||
widgets::{Block, BorderType, Borders, Clear, Widget},
|
||||
widgets::{Block, BorderType, Clear, Widget},
|
||||
};
|
||||
|
||||
pub struct PopupFrame<'a> {
|
||||
@@ -23,9 +23,8 @@ impl<'a> Widget for PopupFrame<'a> {
|
||||
buf.set_style(area, Style::default().bg(bg));
|
||||
}
|
||||
|
||||
let mut block = Block::default()
|
||||
let mut block = Block::bordered()
|
||||
.title_top(self.title)
|
||||
.borders(Borders::ALL)
|
||||
.border_type(BorderType::Rounded)
|
||||
.border_style(Style::default().fg(self.border_color));
|
||||
|
||||
|
||||
@@ -40,13 +40,10 @@ pub fn word_wrap_size(text: &str, max_inner_width: usize) -> (usize, usize) {
|
||||
}
|
||||
|
||||
pub fn centered_rect(frame: Rect, inner_w: usize, inner_h: usize) -> Rect {
|
||||
let popup_w = (inner_w + 2) as u16;
|
||||
let popup_h = (inner_h + 2) as u16;
|
||||
let popup_w = popup_w.min(frame.width.saturating_sub(4));
|
||||
let popup_h = popup_h.min(frame.height.saturating_sub(4));
|
||||
let x = (frame.width.saturating_sub(popup_w)) / 2;
|
||||
let y = (frame.height.saturating_sub(popup_h)) / 2;
|
||||
Rect { x, y, width: popup_w, height: popup_h }
|
||||
let popup_w = ((inner_w + 2) as u16).min(frame.width.saturating_sub(4));
|
||||
let popup_h = ((inner_h + 2) as u16).min(frame.height.saturating_sub(4));
|
||||
use ratatui::layout::Constraint;
|
||||
frame.centered(Constraint::Length(popup_w), Constraint::Length(popup_h))
|
||||
}
|
||||
|
||||
pub fn top_right_rect(frame: Rect, inner_w: usize, inner_h: usize) -> Rect {
|
||||
|
||||
@@ -184,34 +184,31 @@ pub fn take_result() -> Option<WizardParams> {
|
||||
}
|
||||
|
||||
pub fn popup_rect(frame_area: Rect) -> Rect {
|
||||
use ratatui::layout::Constraint;
|
||||
|
||||
let step = match WIZARD_STATE.lock() {
|
||||
Ok(s) => s.step.clone(),
|
||||
Err(_) => WizardStep::Name,
|
||||
};
|
||||
|
||||
let popup_w = frame_area.width / 2;
|
||||
let x = frame_area.width / 4;
|
||||
let w = Constraint::Percentage(50);
|
||||
|
||||
match step {
|
||||
WizardStep::Name => {
|
||||
let h = 6u16.min(frame_area.height.saturating_sub(4));
|
||||
let y = (frame_area.height.saturating_sub(h)) / 2;
|
||||
Rect { x, y, width: popup_w, height: h }
|
||||
frame_area.centered(w, Constraint::Length(h))
|
||||
}
|
||||
WizardStep::Version | WizardStep::LoaderVersion => {
|
||||
let h = (frame_area.height * 2 / 3).max(10).min(frame_area.height.saturating_sub(4));
|
||||
let y = (frame_area.height.saturating_sub(h)) / 2;
|
||||
Rect { x, y, width: popup_w, height: h }
|
||||
frame_area.centered(w, Constraint::Length(h))
|
||||
}
|
||||
WizardStep::Loader => {
|
||||
let h = 9u16.min(frame_area.height.saturating_sub(4));
|
||||
let y = (frame_area.height.saturating_sub(h)) / 2;
|
||||
Rect { x, y, width: popup_w, height: h }
|
||||
frame_area.centered(w, Constraint::Length(h))
|
||||
}
|
||||
WizardStep::Confirm => {
|
||||
let h = 8u16.min(frame_area.height.saturating_sub(4));
|
||||
let y = (frame_area.height.saturating_sub(h)) / 2;
|
||||
Rect { x, y, width: popup_w, height: h }
|
||||
frame_area.centered(w, Constraint::Length(h))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -250,7 +247,6 @@ fn handle_version_key(
|
||||
if state.version_search.active {
|
||||
match key_event.code {
|
||||
KeyCode::Esc => {
|
||||
state.version_search.active = false;
|
||||
state.version_search.deactivate();
|
||||
clamp_version_index(state);
|
||||
return;
|
||||
@@ -279,13 +275,7 @@ fn handle_version_key(
|
||||
|
||||
match key_event.code {
|
||||
KeyCode::Esc => {
|
||||
if state.version_search.active {
|
||||
state.version_search.active = false;
|
||||
state.version_search.deactivate();
|
||||
clamp_version_index(state);
|
||||
} else {
|
||||
close_popup(state, profiles_state);
|
||||
}
|
||||
close_popup(state, profiles_state);
|
||||
}
|
||||
KeyCode::Left | KeyCode::Char('h') if !state.version_search.active => {
|
||||
state.step = WizardStep::Loader;
|
||||
|
||||
Reference in new issue
Block a user