Compare commits
No commits in common. "main" and "2026.8.3" have entirely different histories.
5 changed files with 23 additions and 88 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
|
@ -1651,7 +1651,7 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "textgrid"
|
||||
version = "2026.8.5"
|
||||
version = "2026.8.3"
|
||||
dependencies = [
|
||||
"bytemuck",
|
||||
"glfw",
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "textgrid"
|
||||
version = "2026.8.5"
|
||||
version = "2026.8.3"
|
||||
edition = "2021"
|
||||
|
||||
[lib]
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ build-backend = "maturin"
|
|||
|
||||
[project]
|
||||
name = "textgrid"
|
||||
version = "2026.8.5"
|
||||
version = "2026.8.3"
|
||||
requires-python = ">=3.11"
|
||||
|
||||
[tool.maturin]
|
||||
|
|
|
|||
|
|
@ -181,7 +181,7 @@ pub fn compute_cell_metrics(font_data: &[u8], scale: f32) -> (u32, u32) {
|
|||
}
|
||||
|
||||
pub fn load_font(font_path: Option<&str>) -> (FontSet, f32) {
|
||||
let scale = 32.0 / 1.2;
|
||||
let scale = 32.0;
|
||||
match font_path {
|
||||
Some(path) => {
|
||||
let regular = read_font_data(path);
|
||||
|
|
|
|||
103
src/renderer.rs
103
src/renderer.rs
|
|
@ -1,7 +1,6 @@
|
|||
use std::sync::atomic::{AtomicBool, AtomicU32, Ordering};
|
||||
use std::sync::mpsc::Receiver;
|
||||
use std::sync::{Arc, Condvar, Mutex};
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
use bytemuck::{Pod, Zeroable};
|
||||
use pyo3::prelude::*;
|
||||
|
|
@ -79,24 +78,13 @@ pub fn start(
|
|||
w.set_size_polling(true);
|
||||
w.set_close_polling(true);
|
||||
w.set_key_polling(true);
|
||||
w.set_char_mods_polling(true);
|
||||
w.set_focus_polling(true);
|
||||
w.focus();
|
||||
let focus_deadline = Instant::now() + Duration::from_secs(2);
|
||||
while Instant::now() < focus_deadline && !w.is_focused() {
|
||||
glfw_ctx.poll_events();
|
||||
w.focus();
|
||||
std::thread::sleep(Duration::from_millis(10));
|
||||
}
|
||||
w.set_char_polling(true);
|
||||
let fb = w.get_framebuffer_size();
|
||||
fb_w = fb.0.max(1) as u32;
|
||||
fb_h = fb.1.max(1) as u32;
|
||||
(w, r)
|
||||
};
|
||||
|
||||
cols_atomic.store((fb_w / cell_w).max(1), Ordering::Release);
|
||||
rows_atomic.store((fb_h / cell_h).max(1), Ordering::Release);
|
||||
|
||||
// ----- wgpu -----
|
||||
let instance = wgpu::Instance::new(wgpu::InstanceDescriptor {
|
||||
backends: {
|
||||
|
|
@ -140,9 +128,7 @@ pub fn start(
|
|||
.expect("failed to create GPU device");
|
||||
|
||||
let caps = surface.get_capabilities(&adapter);
|
||||
let format = caps.formats.iter().copied()
|
||||
.find(|f| matches!(f, wgpu::TextureFormat::Bgra8Unorm | wgpu::TextureFormat::Rgba8Unorm))
|
||||
.unwrap_or(caps.formats[0]);
|
||||
let format = caps.formats[0];
|
||||
|
||||
let mut surface_config = wgpu::SurfaceConfiguration {
|
||||
usage: wgpu::TextureUsages::RENDER_ATTACHMENT,
|
||||
|
|
@ -306,12 +292,9 @@ pub fn start(
|
|||
});
|
||||
}
|
||||
}
|
||||
glfw::WindowEvent::CharModifiers(codepoint, mods) => {
|
||||
glfw::WindowEvent::Char(codepoint) => {
|
||||
if let Some(ref cb) = on_key {
|
||||
let mut s: String = codepoint.into();
|
||||
if mods.contains(glfw::Modifiers::Alt) && !s.is_empty() {
|
||||
s.insert(0, '\x1b');
|
||||
}
|
||||
let s: String = codepoint.into();
|
||||
Python::with_gil(|py| {
|
||||
let _ = cb.call1(py, (s,));
|
||||
});
|
||||
|
|
@ -413,74 +396,26 @@ pub fn start(
|
|||
Some(String::from('\x16'))
|
||||
}
|
||||
} else if mods.contains(glfw::Modifiers::Control) {
|
||||
match key {
|
||||
glfw::Key::Up => Some("\x1b[1;5A".into()),
|
||||
glfw::Key::Down => Some("\x1b[1;5B".into()),
|
||||
glfw::Key::Left => Some("\x1b[1;5D".into()),
|
||||
glfw::Key::Right => Some("\x1b[1;5C".into()),
|
||||
_ => {
|
||||
let code = key as i32;
|
||||
if (65..=90).contains(&code) {
|
||||
Some(String::from((code - 64) as u8 as char))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
let code = key as i32;
|
||||
if (65..=90).contains(&code) {
|
||||
Some(String::from((code - 64) as u8 as char))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
} else {
|
||||
let mod_num = if mods.contains(glfw::Modifiers::Shift)
|
||||
&& mods.contains(glfw::Modifiers::Alt)
|
||||
{ 4 }
|
||||
else if mods.contains(glfw::Modifiers::Alt) { 3 }
|
||||
else if mods.contains(glfw::Modifiers::Shift) { 2 }
|
||||
else { 1 };
|
||||
match key {
|
||||
glfw::Key::Up => if mod_num > 1 {
|
||||
Some(format!("\x1b[1;{}A", mod_num))
|
||||
} else { Some("\x1b[A".into()) },
|
||||
glfw::Key::Down => if mod_num > 1 {
|
||||
Some(format!("\x1b[1;{}B", mod_num))
|
||||
} else { Some("\x1b[B".into()) },
|
||||
glfw::Key::Left => if mod_num > 1 {
|
||||
Some(format!("\x1b[1;{}D", mod_num))
|
||||
} else { Some("\x1b[D".into()) },
|
||||
glfw::Key::Right => if mod_num > 1 {
|
||||
Some(format!("\x1b[1;{}C", mod_num))
|
||||
} else { Some("\x1b[C".into()) },
|
||||
glfw::Key::Home => if mod_num > 1 {
|
||||
Some(format!("\x1b[1;{}H", mod_num))
|
||||
} else { Some("\x1b[H".into()) },
|
||||
glfw::Key::End => if mod_num > 1 {
|
||||
Some(format!("\x1b[1;{}F", mod_num))
|
||||
} else { Some("\x1b[F".into()) },
|
||||
glfw::Key::PageUp => if mod_num > 1 {
|
||||
Some(format!("\x1b[5;{}~", mod_num))
|
||||
} else { Some("\x1b[5~".into()) },
|
||||
glfw::Key::PageDown => if mod_num > 1 {
|
||||
Some(format!("\x1b[6;{}~", mod_num))
|
||||
} else { Some("\x1b[6~".into()) },
|
||||
glfw::Key::Tab => if mods.contains(glfw::Modifiers::Shift) {
|
||||
Some("\x1b[Z".into())
|
||||
} else { Some("\t".into()) },
|
||||
glfw::Key::Backspace => if mods.contains(glfw::Modifiers::Alt) {
|
||||
Some("\x1b\x7f".into())
|
||||
} else { Some("\x7f".into()) },
|
||||
glfw::Key::Insert => Some("\x1b[2~".into()),
|
||||
glfw::Key::Delete => Some("\x1b[3~".into()),
|
||||
glfw::Key::F1 => Some("\x1bOP".into()),
|
||||
glfw::Key::F2 => Some("\x1bOQ".into()),
|
||||
glfw::Key::F3 => Some("\x1bOR".into()),
|
||||
glfw::Key::F4 => Some("\x1bOS".into()),
|
||||
glfw::Key::F5 => Some("\x1b[15~".into()),
|
||||
glfw::Key::F6 => Some("\x1b[17~".into()),
|
||||
glfw::Key::F7 => Some("\x1b[18~".into()),
|
||||
glfw::Key::F8 => Some("\x1b[19~".into()),
|
||||
glfw::Key::F9 => Some("\x1b[20~".into()),
|
||||
glfw::Key::F10 => Some("\x1b[21~".into()),
|
||||
glfw::Key::F11 => Some("\x1b[23~".into()),
|
||||
glfw::Key::F12 => Some("\x1b[24~".into()),
|
||||
glfw::Key::Enter => Some("\n".into()),
|
||||
glfw::Key::Escape => Some("\x1b".into()),
|
||||
glfw::Key::Backspace => Some("\x7f".into()),
|
||||
glfw::Key::Tab => Some("\t".into()),
|
||||
glfw::Key::Up => Some("\x1b[A".into()),
|
||||
glfw::Key::Down => Some("\x1b[B".into()),
|
||||
glfw::Key::Left => Some("\x1b[D".into()),
|
||||
glfw::Key::Right => Some("\x1b[C".into()),
|
||||
glfw::Key::Home => Some("\x1b[H".into()),
|
||||
glfw::Key::End => Some("\x1b[F".into()),
|
||||
glfw::Key::PageUp => Some("\x1b[5~".into()),
|
||||
glfw::Key::PageDown => Some("\x1b[6~".into()),
|
||||
_ => None,
|
||||
}
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue