Render text properly while dragging and resizing the text Shape

This commit is contained in:
Elena Torro 2025-03-27 12:46:04 +01:00
parent ebf3730454
commit 33c3611345
4 changed files with 16 additions and 7 deletions

View file

@ -380,7 +380,10 @@ impl RenderState {
}
}
Type::Text(text_content) => {
text::render(self, text_content);
self.surfaces.apply_mut(&[SurfaceId::Fills], |s| {
s.canvas().concat(&matrix);
});
text::render(self, &shape, text_content);
}
_ => {
self.surfaces.apply_mut(
@ -594,6 +597,7 @@ impl RenderState {
}
let scale = self.get_scale();
let mut should_stop = false;
while !should_stop {
if let Some(current_tile) = self.current_tile {
if self.surfaces.has_cached_tile_surface(current_tile) {

View file

@ -1,13 +1,11 @@
use super::{RenderState, SurfaceId};
use super::{RenderState, Shape, SurfaceId};
use crate::shapes::TextContent;
pub fn render(render_state: &mut RenderState, text: &TextContent) {
let mut offset_y = 0.0;
pub fn render(render_state: &mut RenderState, shape: &Shape, text: &TextContent) {
for mut skia_paragraph in text.to_paragraphs(&render_state.fonts().font_collection()) {
skia_paragraph.layout(text.width());
skia_paragraph.layout(shape.width());
let xy = (text.x(), text.y() + offset_y);
let xy = (shape.selrect().x(), shape.selrect.y());
skia_paragraph.paint(render_state.surfaces.canvas(SurfaceId::Fills), xy);
offset_y += skia_paragraph.height();
}
}

View file

@ -575,6 +575,10 @@ impl Shape {
self.hidden
}
pub fn width(&self) -> f32 {
self.selrect.width()
}
pub fn visually_insignificant(&self, scale: f32) -> bool {
self.selrect.width() * scale < MIN_VISIBLE_SIZE
|| self.selrect.height() * scale < MIN_VISIBLE_SIZE

View file

@ -26,14 +26,17 @@ impl TextContent {
self.bounds = Rect::from_xywh(x, y, w, h);
}
#[allow(dead_code)]
pub fn width(&self) -> f32 {
self.bounds.width()
}
#[allow(dead_code)]
pub fn x(&self) -> f32 {
self.bounds.x()
}
#[allow(dead_code)]
pub fn y(&self) -> f32 {
self.bounds.y()
}