Keep extreme canvas zoom responsive

This commit is contained in:
Dandaedre 2026-11-19 11:31:50 +01:00
parent e228cc82bb
commit 3cdd303b45
6 changed files with 76 additions and 11 deletions

2
Cargo.lock generated
View File

@ -602,7 +602,7 @@ dependencies = [
[[package]]
name = "canvas-pilot"
version = "0.10.0-rc.16"
version = "0.10.0-rc.17"
dependencies = [
"base64 0.22.1",
"craft-dwg",

View File

@ -4,7 +4,7 @@ default-members = ["crates/canvas-pilot"]
resolver = "3"
[workspace.package]
version = "0.10.0-rc.16"
version = "0.10.0-rc.17"
edition = "2024"
license = "MIT"
repository = "https://proxy.dandaedre.com/gitea/idle-org/canvas-pilot"

View File

@ -5179,6 +5179,40 @@ mod tests {
app.crop_mask_key_input(ctx, &mut input);
ctx.run_ui(input, |ui| app.ui(ui))
}
#[test]
fn extreme_camera_zoom_keeps_canvas_text_out_of_the_font_atlas() {
let ctx = egui::Context::default();
let mut app = Editor {
zoom: 256.0,
..Default::default()
};
let output = frame(&mut app, &ctx, vec![]);
let text: Vec<_> = output
.shapes
.iter()
.filter_map(|shape| match &shape.shape {
egui::Shape::Text(text) => Some(text),
_ => None,
})
.collect();
assert!(!text.is_empty(), "ordinary UI text should still render");
assert!(text.iter().all(|text| {
text.galley
.job
.sections
.iter()
.all(|section| section.format.font_id.size <= MAX_CANVAS_TEXT_RASTER_PIXELS)
}));
assert!(!text.iter().any(|text| {
text.galley.text() == "Ideas worth sharing."
|| text
.galley
.text()
.starts_with("Illustrative reference artwork")
}));
assert_eq!(app.zoom, 256.0, "precision camera zoom remains available");
}
fn key(key: egui::Key) -> egui::Event {
egui::Event::Key {
key,

View File

@ -64,6 +64,17 @@ struct Ink {
scale: f32,
}
// egui rasterizes text into one shared font texture. Camera-scaled decorative text
// must not request multi-thousand-pixel glyphs and evict/corrupt ordinary UI text.
const MAX_CANVAS_TEXT_RASTER_PIXELS: f32 = 128.0;
fn bounded_canvas_font_size(ctx: &egui::Context, size: f32) -> Option<f32> {
(size.is_finite()
&& size > 0.0
&& size * ctx.pixels_per_point() <= MAX_CANVAS_TEXT_RASTER_PIXELS)
.then_some(size)
}
impl Ink {
fn new(ui: &egui::Ui, rect: Rect) -> Self {
Self {
@ -96,11 +107,15 @@ impl Ink {
}
fn text(&self, x: f32, y: f32, text: &str, size: f32, color: Color32) {
let size = size * self.scale;
let Some(size) = bounded_canvas_font_size(self.painter.ctx(), size) else {
return;
};
self.painter.text(
self.point(x, y),
Align2::LEFT_TOP,
text,
FontId::proportional(size * self.scale),
FontId::proportional(size),
color,
);
}
@ -154,13 +169,15 @@ fn screen_labels(ink: &Ink, output: [u32; 2]) {
12.0 * k,
palette.muted,
);
ink.painter.text(
ink.point(width, -SCREEN_LABEL_TOP * k),
Align2::RIGHT_TOP,
format!("{} × {} px", output[0], output[1]),
FontId::proportional(13.0 * k * ink.scale),
palette.muted,
);
if let Some(size) = bounded_canvas_font_size(ink.painter.ctx(), 13.0 * k * ink.scale) {
ink.painter.text(
ink.point(width, -SCREEN_LABEL_TOP * k),
Align2::RIGHT_TOP,
format!("{} × {} px", output[0], output[1]),
FontId::proportional(size),
palette.muted,
);
}
}
fn screen_artwork(ink: &Ink, title: &str, output: [u32; 2]) {
@ -203,10 +220,13 @@ fn screen_reference_hint(ink: &Ink, output: [u32; 2]) {
.painter
.with_clip_rect(ink.painter.clip_rect().intersect(rect));
let color = theme::palette(ink.painter.ctx()).muted;
let Some(font_size) = bounded_canvas_font_size(ink.painter.ctx(), 12.0 * ink.scale) else {
return;
};
let text = painter.layout(
"Illustrative reference artwork · Drag & drop an image or use Import > Reference image…"
.into(),
FontId::proportional(12.0 * ink.scale),
FontId::proportional(font_size),
color,
(size.x - 48.0).max(1.0) * ink.scale,
);

View File

@ -4,6 +4,13 @@
## Unreleased
### v0.10.0-rc.17
- Keep extreme scroll zoom responsive by omitting camera-scaled decorative canvas
text before it would request oversized glyphs from egui's shared font atlas.
Layer geometry, fixed-size layer labels, pixel guides and the existing 256× camera
range remain available for precise placement.
## v0.10.0-rc.16 — 2026-11-19
Published release candidate collecting the crop, preview, input adaptation and

View File

@ -16,6 +16,10 @@ Valid output presets and numeric resolution edits apply immediately; invalid dra
leave the output unchanged and are retained for correction.
The same window offers numeric camera zoom relative to fit-to-screen and a
**1:1 display pixels** action; camera changes never modify crop geometry.
Scroll zoom and the Zoom tool retain the full precision camera range. At extreme
zoom, decorative screen titles and reference-hint text are hidden before their
camera-scaled glyphs would slow the renderer; layers, handles, fixed-size layer
labels, pixel guides and placement remain visible and editable.
Select one layer and click its **Layer resolution** card to open **Layer properties**: