handwritin: Grow and shrink the canvas without refreshing
This commit is contained in:
@ -105,20 +105,9 @@ struct MeshContext {
|
||||
|
||||
pub pixels_per_point: f32,
|
||||
|
||||
/// Canvas size in points
|
||||
pub size: Vec2,
|
||||
|
||||
pub stroke: Stroke,
|
||||
}
|
||||
|
||||
impl MeshContext {
|
||||
/// Calculate canvas size in pixels
|
||||
pub fn pixel_size(&self) -> [usize; 2] {
|
||||
let Vec2 { x, y } = self.size * self.pixels_per_point;
|
||||
[x, y].map(|f| f.ceil() as usize)
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Handwriting {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
@ -379,7 +368,6 @@ impl Handwriting {
|
||||
let new_context = MeshContext {
|
||||
ui_theme: ui.ctx().theme(),
|
||||
pixels_per_point: ui.pixels_per_point(),
|
||||
size: mesh_rect.size(),
|
||||
stroke: style.stroke,
|
||||
};
|
||||
|
||||
@ -388,6 +376,13 @@ impl Handwriting {
|
||||
self.e.refresh_texture = true;
|
||||
}
|
||||
|
||||
let [px_width, px_height] = {
|
||||
let Vec2 { x, y } = mesh_rect.size() * new_context.pixels_per_point;
|
||||
[x, y].map(|f| f.ceil() as usize)
|
||||
};
|
||||
|
||||
self.e.canvas_rasterizer.set_size(px_width, px_height);
|
||||
|
||||
if self.e.refresh_texture {
|
||||
// ...if we do, rasterize the entire texture from scratch
|
||||
self.refresh_texture(style, new_context);
|
||||
@ -457,11 +452,10 @@ impl Handwriting {
|
||||
// debug_assert!(vertex.pos.y.is_finite(), "{} must be finite", vertex.pos.y);
|
||||
//}
|
||||
|
||||
let [px_x, px_y] = mesh_context.pixel_size();
|
||||
let point_to_pixel = TSTransform::from_scaling(mesh_context.pixels_per_point);
|
||||
let triangles = mesh_triangles(&self.e.mesh);
|
||||
|
||||
self.e.canvas_rasterizer.clear_and_set_size(px_x, px_y);
|
||||
self.e.canvas_rasterizer.clear();
|
||||
self.e
|
||||
.canvas_rasterizer
|
||||
.rasterize(point_to_pixel, triangles);
|
||||
|
||||
Reference in New Issue
Block a user