Fix layout
This commit is contained in:
@@ -3,6 +3,7 @@ use ratatui::style::Style;
|
||||
use ratatui::text::{Line, Span};
|
||||
use ratatui::widgets::Paragraph;
|
||||
use ratatui::Frame;
|
||||
#[cfg(not(feature = "desktop"))]
|
||||
use tui_big_text::{BigText, PixelSize};
|
||||
|
||||
use crate::state::ui::UiState;
|
||||
@@ -16,13 +17,21 @@ pub fn render(frame: &mut Frame, area: Rect, ui: &UiState) {
|
||||
let link_style = Style::new().fg(theme.title.link);
|
||||
let license_style = Style::new().fg(theme.title.license);
|
||||
|
||||
#[cfg(not(feature = "desktop"))]
|
||||
let big_title = BigText::builder()
|
||||
.pixel_size(PixelSize::Quadrant)
|
||||
.pixel_size(PixelSize::Full)
|
||||
.style(Style::new().fg(theme.title.big_title).bold())
|
||||
.lines(vec!["CAGIRE".into()])
|
||||
.centered()
|
||||
.build();
|
||||
|
||||
#[cfg(feature = "desktop")]
|
||||
let big_title = Paragraph::new(Line::from(Span::styled(
|
||||
"CAGIRE",
|
||||
Style::new().fg(theme.title.big_title).bold(),
|
||||
)))
|
||||
.alignment(Alignment::Center);
|
||||
|
||||
let version_style = Style::new().fg(theme.title.subtitle);
|
||||
|
||||
let subtitle_lines = vec![
|
||||
@@ -49,21 +58,43 @@ pub fn render(frame: &mut Frame, area: Rect, ui: &UiState) {
|
||||
)),
|
||||
];
|
||||
|
||||
let big_text_height = 4;
|
||||
#[cfg(not(feature = "desktop"))]
|
||||
let big_text_height = 8;
|
||||
#[cfg(feature = "desktop")]
|
||||
let big_text_height = 1;
|
||||
let min_title_width = 30;
|
||||
let subtitle_height = subtitle_lines.len() as u16;
|
||||
let total_height = big_text_height + subtitle_height;
|
||||
let vertical_padding = area.height.saturating_sub(total_height) / 2;
|
||||
|
||||
let [_, title_area, subtitle_area, _] = Layout::vertical([
|
||||
Constraint::Length(vertical_padding),
|
||||
Constraint::Length(big_text_height),
|
||||
Constraint::Length(subtitle_height),
|
||||
Constraint::Fill(1),
|
||||
])
|
||||
.areas(area);
|
||||
let show_big_title =
|
||||
area.height >= (big_text_height + subtitle_height) && area.width >= min_title_width;
|
||||
|
||||
frame.render_widget(big_title, title_area);
|
||||
if show_big_title {
|
||||
let total_height = big_text_height + subtitle_height;
|
||||
let vertical_padding = area.height.saturating_sub(total_height) / 2;
|
||||
|
||||
let subtitle = Paragraph::new(subtitle_lines).alignment(Alignment::Center);
|
||||
frame.render_widget(subtitle, subtitle_area);
|
||||
let [_, title_area, subtitle_area, _] = Layout::vertical([
|
||||
Constraint::Length(vertical_padding),
|
||||
Constraint::Length(big_text_height),
|
||||
Constraint::Length(subtitle_height),
|
||||
Constraint::Fill(1),
|
||||
])
|
||||
.areas(area);
|
||||
|
||||
frame.render_widget(big_title, title_area);
|
||||
|
||||
let subtitle = Paragraph::new(subtitle_lines).alignment(Alignment::Center);
|
||||
frame.render_widget(subtitle, subtitle_area);
|
||||
} else {
|
||||
let vertical_padding = area.height.saturating_sub(subtitle_height) / 2;
|
||||
|
||||
let [_, subtitle_area, _] = Layout::vertical([
|
||||
Constraint::Length(vertical_padding),
|
||||
Constraint::Length(subtitle_height),
|
||||
Constraint::Fill(1),
|
||||
])
|
||||
.areas(area);
|
||||
|
||||
let subtitle = Paragraph::new(subtitle_lines).alignment(Alignment::Center);
|
||||
frame.render_widget(subtitle, subtitle_area);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user