feat(editor): integrate TTF font into UiContext with draw_text helper

Add ttf_font field to UiContext with draw_text and ttf_text_width
helpers that use TTF when available, falling back to bitmap font.
Load system TTF font (arial/consola/malgun) in editor_demo on startup.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-03-26 14:14:05 +09:00
parent 58bce839fe
commit cccc54c438
2 changed files with 52 additions and 1 deletions

View File

@@ -227,9 +227,20 @@ impl ApplicationHandler for EditorDemoApp {
let window = VoltexWindow::new(event_loop, &config);
let gpu = GpuContext::new(window.handle.clone());
let ui = UiContext::new(gpu.config.width as f32, gpu.config.height as f32);
let mut ui = UiContext::new(gpu.config.width as f32, gpu.config.height as f32);
let ui_renderer = UiRenderer::new(&gpu.device, &gpu.queue, gpu.surface_format, &ui.font);
// Try to load TTF font
let ttf_data = std::fs::read("C:/Windows/Fonts/arial.ttf")
.or_else(|_| std::fs::read("C:/Windows/Fonts/consola.ttf"))
.or_else(|_| std::fs::read("C:/Windows/Fonts/malgun.ttf"))
.ok();
if let Some(data) = ttf_data {
if let Ok(font) = voltex_editor::TtfFont::new(&data, 14.0) {
ui.ttf_font = Some(font);
}
}
let dock = DockTree::new(
DockNode::split(
Axis::Horizontal, 0.25,