@@ -3404,14 +3404,16 @@ mod tests {
})
.unwrap();
let state = cx
- .update_window(window.into(), |_, cx| {
- element.compute_layout(
- Bounds {
- origin: point(px(500.), px(500.)),
- size: size(px(500.), px(500.)),
- },
- cx,
- )
+ .update_window(window.into(), |view, cx| {
+ cx.with_view_id(view.entity_id(), |cx| {
+ element.compute_layout(
+ Bounds {
+ origin: point(px(500.), px(500.)),
+ size: size(px(500.), px(500.)),
+ },
+ cx,
+ )
+ })
})
.unwrap();
@@ -3496,14 +3498,16 @@ mod tests {
});
let state = cx
- .update_window(window.into(), |_, cx| {
- element.compute_layout(
- Bounds {
- origin: point(px(500.), px(500.)),
- size: size(px(500.), px(500.)),
- },
- cx,
- )
+ .update_window(window.into(), |view, cx| {
+ cx.with_view_id(view.entity_id(), |cx| {
+ element.compute_layout(
+ Bounds {
+ origin: point(px(500.), px(500.)),
+ size: size(px(500.), px(500.)),
+ },
+ cx,
+ )
+ })
})
.unwrap();
assert_eq!(state.selections.len(), 1);
@@ -3558,14 +3562,16 @@ mod tests {
let mut element = EditorElement::new(&editor, style);
let state = cx
- .update_window(window.into(), |_, cx| {
- element.compute_layout(
- Bounds {
- origin: point(px(500.), px(500.)),
- size: size(px(500.), px(500.)),
- },
- cx,
- )
+ .update_window(window.into(), |view, cx| {
+ cx.with_view_id(view.entity_id(), |cx| {
+ element.compute_layout(
+ Bounds {
+ origin: point(px(500.), px(500.)),
+ size: size(px(500.), px(500.)),
+ },
+ cx,
+ )
+ })
})
.unwrap();
let size = state.position_map.size;
@@ -3582,8 +3588,8 @@ mod tests {
// Don't panic.
let bounds = Bounds::<Pixels>::new(Default::default(), size);
- cx.update_window(window.into(), |_, cx| {
- element.paint(bounds, &mut (), cx);
+ cx.update_window(window.into(), |view, cx| {
+ cx.paint_view(view.entity_id(), |cx| element.paint(bounds, &mut (), cx))
})
.unwrap()
}
@@ -2004,11 +2004,9 @@ impl<'a> WindowContext<'a> {
result
}
- pub(crate) fn with_view_id<R>(
- &mut self,
- view_id: EntityId,
- f: impl FnOnce(&mut Self) -> R,
- ) -> R {
+ /// Invoke the given function with the given view id present on the view stack.
+ /// This is a fairly low-level method used to layout views.
+ pub fn with_view_id<R>(&mut self, view_id: EntityId, f: impl FnOnce(&mut Self) -> R) -> R {
let text_system = self.text_system().clone();
text_system.with_view(view_id, || {
self.window.next_frame.view_stack.push(view_id);
@@ -2018,7 +2016,9 @@ impl<'a> WindowContext<'a> {
})
}
- pub(crate) fn paint_view<R>(&mut self, view_id: EntityId, f: impl FnOnce(&mut Self) -> R) -> R {
+ /// Invoke the given function with the given view id present on the view stack.
+ /// This is a fairly low-level method used to paint views.
+ pub fn paint_view<R>(&mut self, view_id: EntityId, f: impl FnOnce(&mut Self) -> R) -> R {
self.with_view_id(view_id, |cx| {
cx.window
.next_frame