Add bg_color parameter to TextGrid constructor

This commit is contained in:
Andrew Hamilton 2026-07-24 12:41:29 +10:00
parent 771e7cbe8e
commit 6ec0fa497b
2 changed files with 9 additions and 4 deletions

View file

@ -50,7 +50,7 @@ pub struct TextGrid {
#[pymethods]
impl TextGrid {
#[new]
#[pyo3(signature = (rows, cols, title=None, font_path=None, color_font_path=None, on_key=None, appearance_changed=None, event_loop=None, on_close=None))]
#[pyo3(signature = (rows, cols, title=None, font_path=None, color_font_path=None, on_key=None, appearance_changed=None, event_loop=None, on_close=None, bg_color=None))]
fn new(
rows: u32,
cols: u32,
@ -61,7 +61,10 @@ impl TextGrid {
appearance_changed: Option<PyObject>,
event_loop: Option<PyObject>,
on_close: Option<PyObject>,
bg_color: Option<(u8, u8, u8)>,
) -> PyResult<Self> {
let bg = bg_color.map(|(r, g, b)| (r as f32 / 255.0, g as f32 / 255.0, b as f32 / 255.0))
.unwrap_or((0.0, 0.0, 0.0));
let needs_render = Arc::new(AtomicBool::new(true));
let notify_pair = Arc::new((Mutex::new(false), Condvar::new()));
let close_requested = Arc::new(AtomicBool::new(false));
@ -97,6 +100,7 @@ impl TextGrid {
ra,
event_loop,
on_close,
bg,
);
})
.map_err(|e| PyValueError::new_err(format!("failed to spawn render thread: {e}")))?;

View file

@ -53,6 +53,7 @@ pub fn start(
rows_atomic: Arc<AtomicU32>,
event_loop: Option<PyObject>,
on_close: Option<PyObject>,
bg_color: (f32, f32, f32),
) {
// ----- Font loading & cell metrics -----
let (font_set, scale) = font::load_font(font_path.as_deref());
@ -528,9 +529,9 @@ pub fn start(
resolve_target: None,
ops: wgpu::Operations {
load: wgpu::LoadOp::Clear(wgpu::Color {
r: 0.06,
g: 0.06,
b: 0.1,
r: bg_color.0 as f64,
g: bg_color.1 as f64,
b: bg_color.2 as f64,
a: 1.0,
}),
store: wgpu::StoreOp::Store,