Merge pull request #2964 from DKolter/issue_2961
Fix text damage calculation on tiny skia
This commit is contained in:
commit
8df8d9a0c1
1 changed files with 9 additions and 51 deletions
|
|
@ -73,74 +73,32 @@ pub enum Text {
|
||||||
impl Text {
|
impl Text {
|
||||||
/// Returns the visible bounds of the [`Text`].
|
/// Returns the visible bounds of the [`Text`].
|
||||||
pub fn visible_bounds(&self) -> Option<Rectangle> {
|
pub fn visible_bounds(&self) -> Option<Rectangle> {
|
||||||
let (bounds, align_x, align_y) = match self {
|
match self {
|
||||||
Text::Paragraph {
|
Text::Paragraph {
|
||||||
position,
|
position,
|
||||||
paragraph,
|
paragraph,
|
||||||
clip_bounds,
|
clip_bounds,
|
||||||
transformation,
|
transformation,
|
||||||
..
|
..
|
||||||
} => (
|
} => Rectangle::new(*position, paragraph.min_bounds)
|
||||||
Rectangle::new(*position, paragraph.min_bounds)
|
.intersection(clip_bounds)
|
||||||
.intersection(clip_bounds)
|
.map(|bounds| bounds * *transformation),
|
||||||
.map(|bounds| bounds * *transformation),
|
|
||||||
paragraph.align_x,
|
|
||||||
Some(paragraph.align_y),
|
|
||||||
),
|
|
||||||
Text::Editor {
|
Text::Editor {
|
||||||
editor,
|
editor,
|
||||||
position,
|
position,
|
||||||
clip_bounds,
|
clip_bounds,
|
||||||
transformation,
|
transformation,
|
||||||
..
|
..
|
||||||
} => (
|
} => Rectangle::new(*position, editor.bounds)
|
||||||
Rectangle::new(*position, editor.bounds)
|
.intersection(clip_bounds)
|
||||||
.intersection(clip_bounds)
|
.map(|bounds| bounds * *transformation),
|
||||||
.map(|bounds| bounds * *transformation),
|
|
||||||
Alignment::Default,
|
|
||||||
None,
|
|
||||||
),
|
|
||||||
Text::Cached {
|
Text::Cached {
|
||||||
bounds,
|
bounds,
|
||||||
clip_bounds,
|
clip_bounds,
|
||||||
align_x: horizontal_alignment,
|
|
||||||
align_y: vertical_alignment,
|
|
||||||
..
|
..
|
||||||
} => (
|
} => bounds.intersection(clip_bounds),
|
||||||
bounds.intersection(clip_bounds),
|
Text::Raw { raw, .. } => Some(raw.clip_bounds),
|
||||||
*horizontal_alignment,
|
|
||||||
Some(*vertical_alignment),
|
|
||||||
),
|
|
||||||
Text::Raw { raw, .. } => {
|
|
||||||
(Some(raw.clip_bounds), Alignment::Default, None)
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
let mut bounds = bounds?;
|
|
||||||
|
|
||||||
match align_x {
|
|
||||||
Alignment::Default | Alignment::Left | Alignment::Justified => {}
|
|
||||||
Alignment::Center => {
|
|
||||||
bounds.x -= bounds.width / 2.0;
|
|
||||||
}
|
|
||||||
Alignment::Right => {
|
|
||||||
bounds.x -= bounds.width;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(alignment) = align_y {
|
|
||||||
match alignment {
|
|
||||||
alignment::Vertical::Top => {}
|
|
||||||
alignment::Vertical::Center => {
|
|
||||||
bounds.y -= bounds.height / 2.0;
|
|
||||||
}
|
|
||||||
alignment::Vertical::Bottom => {
|
|
||||||
bounds.y -= bounds.height;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Some(bounds)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue