Files
ratatrix/src/widgets/prerender.rs
Val Lorentz 1199dd7613 Cache the result of rendering backlog items
It's so much faster when getting lots of updates, especially with the
'Added client for' log storm at startup.
2023-11-04 22:16:33 +01:00

40 lines
1.2 KiB
Rust

/*
* Copyright (C) 2023 Valentin Lorentz
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
use std::sync::{Arc, Mutex};
/// Storage for the result of pre-computations by the UI, with interior mutability
#[derive(Clone)]
pub(crate) struct PrerenderInner {
pub(crate) key: u16, // width
pub(crate) value: PrerenderValue,
}
#[derive(Clone)]
pub(crate) enum PrerenderValue {
Rendered(ratatui::buffer::Buffer),
NotRendered(u64), // Height only. The widget was not rendered because off-screen.
}
#[derive(Clone)]
pub struct Prerender(pub(crate) Arc<Mutex<Option<PrerenderInner>>>);
impl Prerender {
pub fn new() -> Prerender {
Prerender(Arc::new(Mutex::new(None)))
}
}