mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Fix resize issue
This commit is contained in:
parent
aa676a4327
commit
752b2510ee
@ -20,7 +20,6 @@ use std::{
|
|||||||
};
|
};
|
||||||
use tui::{
|
use tui::{
|
||||||
backend::CrosstermBackend,
|
backend::CrosstermBackend,
|
||||||
layout::{Constraint, Direction, Layout},
|
|
||||||
text::Text,
|
text::Text,
|
||||||
widgets::{Block, Borders, Paragraph, Wrap},
|
widgets::{Block, Borders, Paragraph, Wrap},
|
||||||
Terminal,
|
Terminal,
|
||||||
@ -286,30 +285,32 @@ fn start_tui(mut sender: mpsc::Sender<Message>) {
|
|||||||
|
|
||||||
loop {
|
loop {
|
||||||
let _ = terminal.draw(|f| {
|
let _ = terminal.draw(|f| {
|
||||||
let chunks = Layout::default()
|
let mut log_rect = f.size();
|
||||||
.direction(Direction::Vertical)
|
log_rect.height -= 3;
|
||||||
.constraints([Constraint::Max(u16::MAX), Constraint::Max(3)].as_ref())
|
|
||||||
.split(f.size());
|
let mut input_rect = f.size();
|
||||||
|
input_rect.y = input_rect.height - 3;
|
||||||
|
input_rect.height = 3;
|
||||||
|
|
||||||
let block = Block::default().borders(Borders::ALL);
|
let block = Block::default().borders(Borders::ALL);
|
||||||
let size = block.inner(chunks[0]);
|
let size = block.inner(log_rect);
|
||||||
|
|
||||||
LOG.resize(size.height as usize);
|
LOG.resize(size.height as usize);
|
||||||
|
|
||||||
let logger = Paragraph::new(LOG.inner.lock().unwrap().clone())
|
let logger = Paragraph::new(LOG.inner.lock().unwrap().clone())
|
||||||
.block(block)
|
.block(block)
|
||||||
.wrap(Wrap { trim: false });
|
.wrap(Wrap { trim: false });
|
||||||
f.render_widget(logger, chunks[0]);
|
f.render_widget(logger, log_rect);
|
||||||
|
|
||||||
let text: Text = input.as_str().into();
|
let text: Text = input.as_str().into();
|
||||||
|
|
||||||
let block = Block::default().borders(Borders::ALL);
|
let block = Block::default().borders(Borders::ALL);
|
||||||
let size = block.inner(chunks[1]);
|
let size = block.inner(input_rect);
|
||||||
|
|
||||||
let x = (size.x + text.width() as u16).min(size.width);
|
let x = (size.x + text.width() as u16).min(size.width);
|
||||||
|
|
||||||
let input_field = Paragraph::new(text).block(block);
|
let input_field = Paragraph::new(text).block(block);
|
||||||
f.render_widget(input_field, chunks[1]);
|
f.render_widget(input_field, input_rect);
|
||||||
|
|
||||||
f.set_cursor(x, size.y);
|
f.set_cursor(x, size.y);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user