tlc: phase 18a — migrate 8 dialogs to render_popup
Same mechanical pattern as Phase 17 skin_dialog. Each dialog now
inherits the MC-matching rounded borders + drop shadow from the
shared terminal::popup::render_popup() shell:
filter_dialog, encoding_dialog, pattern_dialog, confirm_dialog,
overwrite_dialog, layout_dialog, panel_options, chattr_dialog
Changes per file:
- Remove import of Block, Borders, Clear
- Add import of centered_cols_rect, render_popup
- Replace inline geometry+Clear+Block with centered_cols_rect()
+ render_popup() call
- Title no longer needs manual styling (render_popup applies
[dialog] dtitle colors)
confirm_dialog also dropped its BorderType::Double variant (now
matches the rest of TLC's rounded look); removed its now-unused
local centered_rect helper.
Tests: 1112 passed (no regressions; same count as pre-Phase 18).
This commit is contained in:
@@ -17,12 +17,13 @@ use std::path::PathBuf;
|
||||
use ratatui::layout::{Constraint, Direction, Layout, Rect};
|
||||
use ratatui::style::{Modifier, Style};
|
||||
use ratatui::text::{Line, Span};
|
||||
use ratatui::widgets::{Block, Borders, Clear, Paragraph};
|
||||
use ratatui::widgets::Paragraph;
|
||||
use ratatui::Frame;
|
||||
|
||||
use crate::fs::{stat, FileType, Permissions};
|
||||
use crate::key::Key;
|
||||
use crate::terminal::color::Theme;
|
||||
use crate::terminal::popup::{centered_cols_rect, render_popup};
|
||||
|
||||
/// Result of a key press in the change-attributes dialog.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
@@ -143,25 +144,9 @@ impl ChattrDialog {
|
||||
|
||||
/// Render the dialog centered on `area`.
|
||||
pub fn render(&self, frame: &mut Frame, area: Rect, theme: &Theme) {
|
||||
let w = 64u16.min(area.width.saturating_sub(2));
|
||||
let h = 16u16.min(area.height.saturating_sub(2));
|
||||
let x = area.x + (area.width.saturating_sub(w)) / 2;
|
||||
let y = area.y + (area.height.saturating_sub(h)) / 2;
|
||||
let dlg = Rect::new(x, y, w, h);
|
||||
frame.render_widget(Clear, dlg);
|
||||
|
||||
let block = Block::default()
|
||||
.borders(Borders::ALL)
|
||||
.border_style(Style::default().fg(theme.title_fg))
|
||||
.title(Span::styled(
|
||||
format!(" File attributes: {} ", self.display_name),
|
||||
Style::default()
|
||||
.fg(theme.title_fg)
|
||||
.bg(theme.title_bg)
|
||||
.add_modifier(Modifier::BOLD),
|
||||
));
|
||||
let inner = block.inner(dlg);
|
||||
frame.render_widget(block, dlg);
|
||||
let dlg = centered_cols_rect(area, 64, 16);
|
||||
let title = format!("File attributes: {}", self.display_name);
|
||||
let inner = render_popup(frame, dlg, title.as_str(), theme);
|
||||
|
||||
let rows = Layout::default()
|
||||
.direction(Direction::Vertical)
|
||||
|
||||
@@ -5,9 +5,11 @@ use crate::terminal::color::Theme;
|
||||
use ratatui::layout::{Alignment, Constraint, Layout, Rect};
|
||||
use ratatui::style::{Modifier, Style};
|
||||
use ratatui::text::{Line, Span};
|
||||
use ratatui::widgets::{Block, BorderType, Borders, Clear, Paragraph};
|
||||
use ratatui::widgets::Paragraph;
|
||||
use ratatui::Frame;
|
||||
|
||||
use crate::terminal::popup::{centered_cols_rect, render_popup};
|
||||
|
||||
const TOGGLE_LABELS: &[(&str, &str)] = &[
|
||||
("Confirm delete", "Ask before deleting files"),
|
||||
("Confirm overwrite", "Ask before overwriting files"),
|
||||
@@ -130,23 +132,8 @@ impl ConfirmDialog {
|
||||
|
||||
/// Render the dialog.
|
||||
pub fn render(&self, frame: &mut Frame, area: Rect, theme: &Theme) {
|
||||
let popup = centered_rect(WIDTH, HEIGHT, area);
|
||||
frame.render_widget(Clear, popup);
|
||||
|
||||
let block = Block::default()
|
||||
.borders(Borders::ALL)
|
||||
.border_type(BorderType::Double)
|
||||
.border_style(Style::default().fg(theme.border))
|
||||
.title(Line::from(Span::styled(
|
||||
" Confirmation ",
|
||||
Style::default()
|
||||
.fg(theme.title_fg)
|
||||
.add_modifier(Modifier::BOLD),
|
||||
)))
|
||||
.style(Style::default().bg(theme.background));
|
||||
|
||||
let inner = block.inner(popup);
|
||||
frame.render_widget(block, popup);
|
||||
let popup = centered_cols_rect(area, WIDTH, HEIGHT);
|
||||
let inner = render_popup(frame, popup, "Confirmation", theme);
|
||||
|
||||
let chunks = Layout::vertical({
|
||||
let mut c: Vec<Constraint> =
|
||||
@@ -205,16 +192,6 @@ impl ConfirmDialog {
|
||||
}
|
||||
}
|
||||
|
||||
fn centered_rect(width: u16, height: u16, area: Rect) -> Rect {
|
||||
let x = area
|
||||
.x
|
||||
.saturating_add((area.width.saturating_sub(width)) / 2);
|
||||
let y = area
|
||||
.y
|
||||
.saturating_add((area.height.saturating_sub(height)) / 2);
|
||||
Rect::new(x, y, width.min(area.width), height.min(area.height))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
@@ -19,11 +19,12 @@
|
||||
use ratatui::layout::{Constraint, Direction, Layout, Rect};
|
||||
use ratatui::style::{Modifier, Style};
|
||||
use ratatui::text::{Line, Span};
|
||||
use ratatui::widgets::{Block, Borders, Clear, Paragraph};
|
||||
use ratatui::widgets::Paragraph;
|
||||
use ratatui::Frame;
|
||||
|
||||
use crate::key::Key;
|
||||
use crate::terminal::color::Theme;
|
||||
use crate::terminal::popup::{centered_cols_rect, render_popup};
|
||||
|
||||
/// The result of the layout dialog after a key event.
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
@@ -178,25 +179,8 @@ impl LayoutDialog {
|
||||
|
||||
/// Render the dialog centered on `area`.
|
||||
pub fn render(&self, frame: &mut Frame, area: Rect, theme: &Theme) {
|
||||
let w = 44u16.min(area.width.saturating_sub(2));
|
||||
let h = 12u16.min(area.height.saturating_sub(2));
|
||||
let x = area.x + (area.width - w) / 2;
|
||||
let y = area.y + (area.height - h) / 2;
|
||||
let dlg = Rect::new(x, y, w, h);
|
||||
frame.render_widget(Clear, dlg);
|
||||
|
||||
let block = Block::default()
|
||||
.borders(Borders::ALL)
|
||||
.border_style(Style::default().fg(theme.title_fg))
|
||||
.title(Span::styled(
|
||||
" Layout ",
|
||||
Style::default()
|
||||
.fg(theme.title_fg)
|
||||
.bg(theme.title_bg)
|
||||
.add_modifier(Modifier::BOLD),
|
||||
));
|
||||
let inner = block.inner(dlg);
|
||||
frame.render_widget(block, dlg);
|
||||
let dlg = centered_cols_rect(area, 44, 12);
|
||||
let inner = render_popup(frame, dlg, "Layout", theme);
|
||||
|
||||
let rows = Layout::default()
|
||||
.direction(Direction::Vertical)
|
||||
|
||||
@@ -7,11 +7,12 @@
|
||||
use ratatui::layout::{Alignment, Constraint, Direction, Layout, Rect};
|
||||
use ratatui::style::{Modifier, Style};
|
||||
use ratatui::text::{Line, Span};
|
||||
use ratatui::widgets::{Block, Borders, Clear, Paragraph};
|
||||
use ratatui::widgets::Paragraph;
|
||||
use ratatui::Frame;
|
||||
|
||||
use crate::key::Key;
|
||||
use crate::terminal::color::Theme;
|
||||
use crate::terminal::popup::{centered_cols_rect, render_popup};
|
||||
|
||||
/// Outcome of the overwrite dialog after a key press.
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
@@ -102,27 +103,9 @@ impl OverwriteDialog {
|
||||
/// Render the dialog centered on screen.
|
||||
pub fn render(&self, frame: &mut Frame, area: Rect, theme: &Theme) {
|
||||
let dialog_w = 60u16.min(area.width);
|
||||
let dialog_h = 9u16.min(area.height);
|
||||
let x = area.x + (area.width - dialog_w) / 2;
|
||||
let y = area.y + (area.height - dialog_h) / 2;
|
||||
let dlg_area = Rect::new(x, y, dialog_w, dialog_h);
|
||||
|
||||
frame.render_widget(Clear, dlg_area);
|
||||
|
||||
let title = if self.is_move { " Move - File exists " } else { " Copy - File exists " };
|
||||
let block = Block::default()
|
||||
.borders(Borders::ALL)
|
||||
.border_style(Style::default().fg(theme.warning))
|
||||
.title(Span::styled(
|
||||
title,
|
||||
Style::default()
|
||||
.fg(theme.title_fg)
|
||||
.bg(theme.title_bg)
|
||||
.add_modifier(Modifier::BOLD),
|
||||
));
|
||||
|
||||
let inner = block.inner(dlg_area);
|
||||
frame.render_widget(block, dlg_area);
|
||||
let dlg_area = centered_cols_rect(area, dialog_w, 9);
|
||||
let title = if self.is_move { "Move - File exists" } else { "Copy - File exists" };
|
||||
let inner = render_popup(frame, dlg_area, title, theme);
|
||||
|
||||
let chunks = Layout::default()
|
||||
.direction(Direction::Vertical)
|
||||
|
||||
@@ -19,11 +19,12 @@
|
||||
use ratatui::layout::{Constraint, Direction, Layout, Rect};
|
||||
use ratatui::style::{Modifier, Style};
|
||||
use ratatui::text::{Line, Span};
|
||||
use ratatui::widgets::{Block, Borders, Clear, Paragraph};
|
||||
use ratatui::widgets::Paragraph;
|
||||
use ratatui::Frame;
|
||||
|
||||
use crate::key::Key;
|
||||
use crate::terminal::color::Theme;
|
||||
use crate::terminal::popup::{centered_cols_rect, render_popup};
|
||||
|
||||
/// The result of the panel-options dialog after a key event.
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
@@ -178,25 +179,8 @@ impl PanelOptionsDialog {
|
||||
|
||||
/// Render the dialog centered on `area`.
|
||||
pub fn render(&self, frame: &mut Frame, area: Rect, theme: &Theme) {
|
||||
let w = 44u16.min(area.width.saturating_sub(2));
|
||||
let h = 12u16.min(area.height.saturating_sub(2));
|
||||
let x = area.x + (area.width - w) / 2;
|
||||
let y = area.y + (area.height - h) / 2;
|
||||
let dlg = Rect::new(x, y, w, h);
|
||||
frame.render_widget(Clear, dlg);
|
||||
|
||||
let block = Block::default()
|
||||
.borders(Borders::ALL)
|
||||
.border_style(Style::default().fg(theme.title_fg))
|
||||
.title(Span::styled(
|
||||
" Panel options ",
|
||||
Style::default()
|
||||
.fg(theme.title_fg)
|
||||
.bg(theme.title_bg)
|
||||
.add_modifier(Modifier::BOLD),
|
||||
));
|
||||
let inner = block.inner(dlg);
|
||||
frame.render_widget(block, dlg);
|
||||
let dlg = centered_cols_rect(area, 44, 12);
|
||||
let inner = render_popup(frame, dlg, "Panel options", theme);
|
||||
|
||||
let rows = Layout::default()
|
||||
.direction(Direction::Vertical)
|
||||
|
||||
Reference in New Issue
Block a user