fix: reset display size on render

This commit is contained in:
🪞👃🪞 2024-09-06 17:39:37 +03:00
parent eb122585d6
commit 4320e6f6b4
4 changed files with 12 additions and 20 deletions

View file

@ -104,6 +104,7 @@ impl Tui {
if engine.exited() { if engine.exited() {
break break
} }
engine.area = engine.backend.size().expect("get size failed");
state.render(&mut engine).expect("render failed"); state.render(&mut engine).expect("render failed");
engine.flip(); engine.flip();
} }

View file

@ -21,7 +21,6 @@ pub trait BorderStyle {
#[inline] #[inline]
fn draw_horizontal (&self, to: &mut Tui, style: Option<Style>) -> Usually<Rect> { fn draw_horizontal (&self, to: &mut Tui, style: Option<Style>) -> Usually<Rect> {
let area = to.area(); let area = to.area();
let buf = to.buffer();
let style = style.or_else(||self.style_horizontal()); let style = style.or_else(||self.style_horizontal());
for x in area.x..(area.x+area.width).saturating_sub(1) { for x in area.x..(area.x+area.width).saturating_sub(1) {
self.draw_north(to, x, area.y, style)?; self.draw_north(to, x, area.y, style)?;

View file

@ -51,29 +51,22 @@ impl<'a> Render<Tui> for Split<'a, Tui> {
impl<'a> Split<'a, Tui> { impl<'a> Split<'a, Tui> {
pub fn render_areas (&self, to: &mut Tui) -> Usually<(Rect, Vec<Rect>)> { pub fn render_areas (&self, to: &mut Tui) -> Usually<(Rect, Vec<Rect>)> {
//Ok((Rect::default(), vec![]))
let Rect { mut x, mut y, mut width, mut height } = to.area(); let Rect { mut x, mut y, mut width, mut height } = to.area();
let mut areas = vec![]; let mut areas = vec![];
for (index, item) in self.items.0.iter().enumerate() { for (index, item) in self.items.0.iter().enumerate() {
if width == 0 || height == 0 { if width == 0 || height == 0 {
break break
} }
if let Some(result) = item.render(to.with_area(x, y, width, height))? { let result = item.render(to.with_area(x, y, width, height))?.unwrap_or(Rect::default());
match self.direction { let Rect { width: w, height: h, .. } = result;
Direction::Down => { match self.direction {
y += result.height; Direction::Down => { y += h; height = height.saturating_sub(h); },
height = height.saturating_sub(result.height); Direction::Right => { x += w; width = width.saturating_sub(w); },
}, _ => unimplemented!()
Direction::Right => { };
x += result.width; areas.push(result);
width = width.saturating_sub(result.width); if self.focus == Some(index) {
}, Corners(Style::default().green().not_dim()).draw(to.with_rect(result))?;
_ => unimplemented!()
};
areas.push(result);
if self.focus == Some(index) {
Corners(Style::default().green().not_dim()).draw(to.with_rect(result))?;
}
} }
} }
Ok((to.area, areas)) Ok((to.area, areas))

View file

@ -1,8 +1,7 @@
/// Phrase editor. /// Phrase editor.
pub(crate) use tek_core::*; pub(crate) use tek_core::*;
pub(crate) use tek_core::ratatui::prelude::*; pub(crate) use tek_core::crossterm::event::KeyCode;
pub(crate) use tek_core::crossterm::event::{KeyCode, KeyModifiers};
pub(crate) use tek_core::midly::{num::u7, live::LiveEvent, MidiMessage}; pub(crate) use tek_core::midly::{num::u7, live::LiveEvent, MidiMessage};
pub(crate) use tek_core::jack::*; pub(crate) use tek_core::jack::*;
pub(crate) use std::sync::{Arc, RwLock}; pub(crate) use std::sync::{Arc, RwLock};