Feat: optimizations
This commit is contained in:
@@ -30,6 +30,7 @@ pub mod transform;
|
||||
|
||||
use ratatui::style::Color;
|
||||
use std::cell::RefCell;
|
||||
use std::rc::Rc;
|
||||
|
||||
/// Entry in the theme registry: id, display label, and palette constructor.
|
||||
pub struct ThemeEntry {
|
||||
@@ -66,17 +67,17 @@ pub const THEMES: &[ThemeEntry] = &[
|
||||
];
|
||||
|
||||
thread_local! {
|
||||
static CURRENT_THEME: RefCell<ThemeColors> = RefCell::new(build::build(&(THEMES[0].palette)()));
|
||||
static CURRENT_THEME: RefCell<Rc<ThemeColors>> = RefCell::new(Rc::new(build::build(&(THEMES[0].palette)())));
|
||||
}
|
||||
|
||||
/// Return the current thread-local theme.
|
||||
pub fn get() -> ThemeColors {
|
||||
CURRENT_THEME.with(|t| t.borrow().clone())
|
||||
/// Return the current thread-local theme (cheap Rc clone, not a deep copy).
|
||||
pub fn get() -> Rc<ThemeColors> {
|
||||
CURRENT_THEME.with(|t| Rc::clone(&t.borrow()))
|
||||
}
|
||||
|
||||
/// Set the current thread-local theme.
|
||||
pub fn set(theme: ThemeColors) {
|
||||
CURRENT_THEME.with(|t| *t.borrow_mut() = theme);
|
||||
CURRENT_THEME.with(|t| *t.borrow_mut() = Rc::new(theme));
|
||||
}
|
||||
|
||||
/// Complete set of resolved colors for all UI components.
|
||||
|
||||
Reference in New Issue
Block a user