mirror of
https://github.com/zed-industries/zed.git
synced 2025-01-24 19:10:24 +00:00
Fix Empty
sometimes returning an infinite size in layout
This commit also ensures that elements never report an infinite size by adding a debug assertion in the `Lifecycle` element.
This commit is contained in:
parent
1cb987d489
commit
5439213199
2 changed files with 19 additions and 2 deletions
|
@ -1,7 +1,10 @@
|
|||
use crate::geometry::{
|
||||
rect::RectF,
|
||||
vector::{vec2f, Vector2F},
|
||||
};
|
||||
use crate::{
|
||||
AfterLayoutContext, Element, Event, EventContext, LayoutContext, PaintContext, SizeConstraint,
|
||||
};
|
||||
use pathfinder_geometry::{rect::RectF, vector::Vector2F};
|
||||
|
||||
pub struct Empty;
|
||||
|
||||
|
@ -20,7 +23,18 @@ impl Element for Empty {
|
|||
constraint: SizeConstraint,
|
||||
_: &mut LayoutContext,
|
||||
) -> (Vector2F, Self::LayoutState) {
|
||||
(constraint.max, ())
|
||||
let x = if constraint.max.x().is_finite() {
|
||||
constraint.max.x()
|
||||
} else {
|
||||
constraint.min.x()
|
||||
};
|
||||
let y = if constraint.max.y().is_finite() {
|
||||
constraint.max.y()
|
||||
} else {
|
||||
constraint.min.y()
|
||||
};
|
||||
|
||||
(vec2f(x, y), ())
|
||||
}
|
||||
|
||||
fn after_layout(&mut self, _: Vector2F, _: &mut Self::LayoutState, _: &mut AfterLayoutContext) {
|
||||
|
|
|
@ -87,6 +87,9 @@ impl<T: Element> AnyElement for Lifecycle<T> {
|
|||
| Lifecycle::PostLayout { mut element, .. }
|
||||
| Lifecycle::PostPaint { mut element, .. } => {
|
||||
let (size, layout) = element.layout(constraint, ctx);
|
||||
debug_assert!(size.x().is_finite());
|
||||
debug_assert!(size.y().is_finite());
|
||||
|
||||
result = Some(size);
|
||||
Lifecycle::PostLayout {
|
||||
element,
|
||||
|
|
Loading…
Reference in a new issue