tui: Constify functions, shrink Margin representation

This commit is contained in:
Blaž Hrastnik 2024-05-21 04:34:36 +09:00
parent e94735bbd3
commit dfcd814389
14 changed files with 102 additions and 112 deletions

View file

@ -532,8 +532,8 @@ impl Component for Completion {
surface.clear_with(doc_area, background);
if cx.editor.popup_border() {
use tui::widgets::{Block, Borders, Widget};
Widget::render(Block::default().borders(Borders::ALL), doc_area, surface);
use tui::widgets::{Block, Widget};
Widget::render(Block::bordered(), doc_area, surface);
}
markdown_doc.render(doc_area, surface, cx);

View file

@ -3,7 +3,7 @@ use helix_view::graphics::{Margin, Rect};
use helix_view::info::Info;
use tui::buffer::Buffer as Surface;
use tui::text::Text;
use tui::widgets::{Block, Borders, Paragraph, Widget};
use tui::widgets::{Block, Paragraph, Widget};
impl Component for Info {
fn render(&mut self, viewport: Rect, surface: &mut Surface, cx: &mut Context) {
@ -23,13 +23,12 @@ impl Component for Info {
));
surface.clear_with(area, popup_style);
let block = Block::default()
let block = Block::bordered()
.title(self.title.as_str())
.borders(Borders::ALL)
.border_style(popup_style);
let margin = Margin::horizontal(1);
let inner = block.inner(area).inner(&margin);
let inner = block.inner(area).inner(margin);
block.render(area, surface);
Paragraph::new(&Text::from(self.text.as_str()))

View file

@ -126,7 +126,7 @@ impl Component for SignatureHelp {
let (_, sig_text_height) = crate::ui::text::required_size(&sig_text, area.width);
let sig_text_area = area.clip_top(1).with_height(sig_text_height);
let sig_text_area = sig_text_area.inner(&margin).intersection(surface.area);
let sig_text_area = sig_text_area.inner(margin).intersection(surface.area);
let sig_text_para = Paragraph::new(&sig_text).wrap(Wrap { trim: false });
sig_text_para.render(sig_text_area, surface);
@ -153,7 +153,7 @@ impl Component for SignatureHelp {
let sig_doc_para = Paragraph::new(&sig_doc)
.wrap(Wrap { trim: false })
.scroll((cx.scroll.unwrap_or_default() as u16, 0));
sig_doc_para.render(sig_doc_area.inner(&margin), surface);
sig_doc_para.render(sig_doc_area.inner(margin), surface);
}
fn required_size(&mut self, viewport: (u16, u16)) -> Option<(u16, u16)> {

View file

@ -351,7 +351,7 @@ impl Component for Markdown {
.scroll((cx.scroll.unwrap_or_default() as u16, 0));
let margin = Margin::all(1);
par.render(area.inner(&margin), surface);
par.render(area.inner(margin), surface);
}
fn required_size(&mut self, viewport: (u16, u16)) -> Option<(u16, u16)> {

View file

@ -17,7 +17,7 @@ use tui::{
buffer::Buffer as Surface,
layout::Constraint,
text::{Span, Spans},
widgets::{Block, BorderType, Borders, Cell, Table},
widgets::{Block, BorderType, Cell, Table},
};
use tui::widgets::Widget;
@ -539,13 +539,12 @@ impl<T: Item + 'static> Picker<T> {
let background = cx.editor.theme.get("ui.background");
surface.clear_with(area, background);
// don't like this but the lifetime sucks
let block = Block::default().borders(Borders::ALL);
const BLOCK: Block<'_> = Block::bordered();
// calculate the inner area inside the box
let inner = block.inner(area);
let inner = BLOCK.inner(area);
block.render(area, surface);
BLOCK.render(area, surface);
// -- Render the input bar:
@ -690,15 +689,14 @@ impl<T: Item + 'static> Picker<T> {
let text = cx.editor.theme.get("ui.text");
surface.clear_with(area, background);
// don't like this but the lifetime sucks
let block = Block::default().borders(Borders::ALL);
const BLOCK: Block<'_> = Block::bordered();
// calculate the inner area inside the box
let inner = block.inner(area);
let inner = BLOCK.inner(area);
// 1 column gap on either side
let margin = Margin::horizontal(1);
let inner = inner.inner(&margin);
block.render(area, surface);
let inner = inner.inner(margin);
BLOCK.render(area, surface);
if let Some((path, range)) = self.current_file(cx.editor) {
let preview = self.get_preview(path, cx.editor);
@ -921,7 +919,7 @@ impl<T: Item + 'static + Send + Sync> Component for Picker<T> {
}
fn cursor(&self, area: Rect, editor: &Editor) -> (Option<Position>, CursorKind) {
let block = Block::default().borders(Borders::ALL);
let block = Block::bordered();
// calculate the inner area inside the box
let inner = block.inner(area);

View file

@ -5,7 +5,7 @@ use crate::{
};
use tui::{
buffer::Buffer as Surface,
widgets::{Block, Borders, Widget},
widgets::{Block, Widget},
};
use helix_core::Position;
@ -323,8 +323,8 @@ impl<T: Component> Component for Popup<T> {
let mut inner = area;
if render_borders {
inner = area.inner(&Margin::all(1));
Widget::render(Block::default().borders(Borders::ALL), area, surface);
inner = area.inner(Margin::all(1));
Widget::render(Block::bordered(), area, surface);
}
let border = usize::from(render_borders);

View file

@ -7,7 +7,7 @@ use helix_view::keyboard::KeyCode;
use std::sync::Arc;
use std::{borrow::Cow, ops::RangeFrom};
use tui::buffer::Buffer as Surface;
use tui::widgets::{Block, Borders, Widget};
use tui::widgets::{Block, Widget};
use helix_core::{
unicode::segmentation::GraphemeCursor, unicode::width::UnicodeWidthStr, Position,
@ -457,12 +457,11 @@ impl Prompt {
let background = theme.get("ui.help");
surface.clear_with(area, background);
let block = Block::default()
let block = Block::bordered()
// .title(self.title.as_str())
.borders(Borders::ALL)
.border_style(background);
let inner = block.inner(area).inner(&Margin::horizontal(1));
let inner = block.inner(area).inner(Margin::horizontal(1));
block.render(area, surface);
text.render(inner, surface, cx);