using Cell directly fixes fullscreen performance

This commit is contained in:
🪞👃🪞 2024-07-06 22:21:09 +03:00
parent d75600188e
commit 6724f3848d
3 changed files with 32 additions and 14 deletions

View file

@ -1,6 +1,6 @@
use crate::core::*; use crate::core::*;
pub(crate) use ratatui::prelude::*; pub(crate) use ratatui::prelude::*;
use ratatui::buffer::Cell; pub(crate) use ratatui::buffer::Cell;
use ratatui::widgets::WidgetRef; use ratatui::widgets::WidgetRef;
pub trait Blit { pub trait Blit {

View file

@ -1,9 +1,10 @@
mod focus; pub use self::focus::*; mod focus; pub use self::focus::*;
mod container; pub use self::container::*; mod container; pub use self::container::*;
mod scroll; pub use self::scroll::*; mod scroll; pub use self::scroll::*;
mod table; pub use self::table::*;
mod lozenge; pub use self::lozenge::*; mod lozenge; pub use self::lozenge::*;
pub mod table;
use crate::core::*; use crate::core::*;
pub trait Modal<T>: Device { pub trait Modal<T>: Device {

View file

@ -80,22 +80,39 @@ mod horizontal {
} }
} }
pub const KEYS_VERTICAL: [&'static str; 6] = [
"", "", "", "", "", "",
];
pub fn keys (buf: &mut Buffer, area: Rect, note0: usize, _notes: &[bool]) pub fn keys (buf: &mut Buffer, area: Rect, note0: usize, _notes: &[bool])
-> Usually<Rect> -> Usually<Rect>
{ {
let bw = Style::default().dim(); let dim = Style::default().dim();
let mut cell_bg = Cell::default();
cell_bg.set_char('░');
cell_bg.set_style(dim.black());
let mut cell_full = Cell::default();
cell_full.set_char('█');
cell_full.set_style(dim);
let mut cell_hi = Cell::default();
cell_hi.set_char('▀');
cell_hi.set_style(dim);
let mut cell_lo = Cell::default();
cell_lo.set_char('▄');
cell_lo.set_style(dim);
let keys = [&cell_lo, &cell_lo, &cell_full, &cell_hi, &cell_hi, &cell_hi];
let Rect { x, y, width, height } = area; let Rect { x, y, width, height } = area;
let height = height.min(128);
let h = height.saturating_sub(2); let h = height.saturating_sub(2);
for index in 0..h { for index in 0..h {
let y = y + h - index; let y = y + h - index;
let key = KEYS_VERTICAL[(index % 6) as usize]; *buf.get_mut(x + 1, y) = keys[(index % 6) as usize].clone();
key.blit(buf, x + 1, y, Some(bw)); *buf.get_mut(x + 2, y) = cell_full.clone();
"".blit(buf, x + 2, y, Some(bw)); for x in x+5..x+width-1 {
"".repeat(width.saturating_sub(6) as usize).blit(buf, x + 5, y, Some(bw.black())); *buf.get_mut(x, y) = cell_bg.clone();
}
let note_a = note0 + (index * 2) as usize; let note_a = note0 + (index * 2) as usize;
if note_a % 12 == 0 { if note_a % 12 == 0 {
let octave = format!("C{}", (note_a / 12) as i8 - 2); let octave = format!("C{}", (note_a / 12) as i8 - 2);
@ -130,6 +147,9 @@ mod horizontal {
let offset = 5; let offset = 5;
for x in x+offset..x+width-offset { for x in x+offset..x+width-offset {
let step = (time0 + (x-offset) as usize) * time_z; let step = (time0 + (x-offset) as usize) * time_z;
if step > phrase.length {
break
}
let next_step = (time0 + (x-offset) as usize + 1) * time_z; let next_step = (time0 + (x-offset) as usize + 1) * time_z;
if step % ppq == 0 { if step % ppq == 0 {
"|".blit(buf, x as u16, y, Some(Style::default().dim())); "|".blit(buf, x as u16, y, Some(Style::default().dim()));
@ -152,9 +172,6 @@ mod horizontal {
(false, false) => (if step % ppq == 0 { "|" } else { "·" }, bw), (false, false) => (if step % ppq == 0 { "|" } else { "·" }, bw),
}; };
let y = y + height.saturating_sub(index+2) as u16; let y = y + height.saturating_sub(index+2) as u16;
if step > phrase.length {
style = Style::default().gray()
}
character.blit(buf, x, y, Some(style)); character.blit(buf, x, y, Some(style));
} }
} }