zed/crates/gpui/src/elements/empty.rs

83 lines
1.7 KiB
Rust
Raw Normal View History

use crate::{
geometry::{
rect::RectF,
vector::{vec2f, Vector2F},
},
json::{json, ToJson},
DebugContext,
};
use crate::{Element, Event, EventContext, LayoutContext, PaintContext, SizeConstraint};
2021-03-10 04:00:51 +00:00
pub struct Empty {
collapsed: bool,
}
2021-03-10 04:00:51 +00:00
impl Empty {
pub fn new() -> Self {
Self { collapsed: false }
}
pub fn collapsed(mut self) -> Self {
self.collapsed = true;
self
2021-03-10 04:00:51 +00:00
}
}
impl Element for Empty {
type LayoutState = ();
type PaintState = ();
2021-03-10 04:00:51 +00:00
fn layout(
&mut self,
constraint: SizeConstraint,
_: &mut LayoutContext,
) -> (Vector2F, Self::LayoutState) {
let x = if constraint.max.x().is_finite() && !self.collapsed {
constraint.max.x()
} else {
constraint.min.x()
};
let y = if constraint.max.y().is_finite() && !self.collapsed {
constraint.max.y()
} else {
constraint.min.y()
};
(vec2f(x, y), ())
2021-03-10 04:00:51 +00:00
}
fn paint(
&mut self,
_: RectF,
_: RectF,
_: &mut Self::LayoutState,
_: &mut PaintContext,
) -> Self::PaintState {
2021-03-10 04:00:51 +00:00
}
fn dispatch_event(
&mut self,
_: &Event,
_: RectF,
_: RectF,
_: &mut Self::LayoutState,
_: &mut Self::PaintState,
_: &mut EventContext,
) -> bool {
false
2021-03-10 04:00:51 +00:00
}
fn debug(
&self,
bounds: RectF,
_: &Self::LayoutState,
_: &Self::PaintState,
_: &DebugContext,
) -> serde_json::Value {
json!({
"type": "Empty",
"bounds": bounds.to_json(),
})
}
2021-03-10 04:00:51 +00:00
}