mirror of
https://github.com/zaphar/sheetsui.git
synced 2025-07-23 13:29:48 -04:00
fix: margins for small window sizes
This commit is contained in:
parent
2bc95a3ef3
commit
69b7fb5983
@ -1,3 +1,5 @@
|
|||||||
|
use std::cmp::{max, min};
|
||||||
|
|
||||||
use ratatui::{
|
use ratatui::{
|
||||||
self,
|
self,
|
||||||
layout::{Constraint, Layout, Rect},
|
layout::{Constraint, Layout, Rect},
|
||||||
@ -11,6 +13,7 @@ pub struct Dialog<'w> {
|
|||||||
title: &'w str,
|
title: &'w str,
|
||||||
bottom_title: &'w str,
|
bottom_title: &'w str,
|
||||||
scroll: (u16, u16),
|
scroll: (u16, u16),
|
||||||
|
// TODO(zaphar): Have a max margin?
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'w> Dialog<'w> {
|
impl<'w> Dialog<'w> {
|
||||||
@ -39,19 +42,23 @@ impl<'w> Widget for Dialog<'w> {
|
|||||||
Self: Sized,
|
Self: Sized,
|
||||||
{
|
{
|
||||||
// First find the center of the area.
|
// First find the center of the area.
|
||||||
let content_width = self.content.width();
|
let content_width = 120 + 2;
|
||||||
let content_height = self.content.height();
|
let content_height = (self.content.height() + 2) as u16;
|
||||||
let vertical_margin = if ((content_height as u16) + 2) <= area.height {
|
let vertical_margin = if content_height <= area.height {
|
||||||
area.height
|
area.height
|
||||||
.saturating_sub((content_height as u16) + 2)
|
.saturating_sub(content_height as u16)
|
||||||
.saturating_div(2)
|
.saturating_div(2)
|
||||||
} else {
|
} else {
|
||||||
area.height - 2
|
2
|
||||||
};
|
};
|
||||||
let horizontal_margin = area
|
let horizontal_margin = if content_width <= area.width {
|
||||||
|
area
|
||||||
.width
|
.width
|
||||||
.saturating_sub((content_width as u16) + 2)
|
.saturating_sub(content_width as u16)
|
||||||
.saturating_div(2);
|
.saturating_div(2)
|
||||||
|
} else {
|
||||||
|
2
|
||||||
|
};
|
||||||
let [_, dialog_vertical, _] = Layout::vertical(vec![
|
let [_, dialog_vertical, _] = Layout::vertical(vec![
|
||||||
Constraint::Length(vertical_margin),
|
Constraint::Length(vertical_margin),
|
||||||
Constraint::Fill(1),
|
Constraint::Fill(1),
|
||||||
|
@ -172,6 +172,7 @@ impl Markdown {
|
|||||||
match tag {
|
match tag {
|
||||||
TagEnd::Heading { .. } => {
|
TagEnd::Heading { .. } => {
|
||||||
lines.push(current_line);
|
lines.push(current_line);
|
||||||
|
lines.push(Line::default()); // Add empty line after heading
|
||||||
current_line = Line::default();
|
current_line = Line::default();
|
||||||
state_stack.pop();
|
state_stack.pop();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user