BlueGit

ict rusty-teams

Files

rusty-teams / vendor / gpui-base / tests / element_ext.rs

element_ext.rs

eef6c0a4 History
element_ext.rs 1020 B Download Raw
1use std::{cell::RefCell, rc::Rc};
2
3use gpui::{Context, IntoElement, Render, Styled as _, TestAppContext, Window, div, px};
4use gpui_base::ElementExt as _;
5
6struct PrepaintHarness {
7 captured: Rc<RefCell<Option<gpui::Bounds<gpui::Pixels>>>>,
8}
9
10impl Render for PrepaintHarness {
11 fn render(&mut self, _: &mut Window, _: &mut Context<Self>) -> impl IntoElement {
12 let captured = self.captured.clone();
13 div()
14 .size(px(80.))
15 .on_prepaint(move |bounds, _, _| *captured.borrow_mut() = Some(bounds))
16 }
17}
18
19#[gpui::test]
20fn prepaint_callback_observes_the_parent_bounds(cx: &mut TestAppContext) {
21 let captured = Rc::new(RefCell::new(None));
22 let result = captured.clone();
23 let (_, cx) = cx.add_window_view(move |_, _| PrepaintHarness { captured });
24
25 cx.update(|window, cx| window.draw(cx).clear(cx));
26
27 let bounds = result.borrow().expect("prepaint callback should run");
28 assert_eq!(bounds.size.width, px(80.));
29 assert_eq!(bounds.size.height, px(80.));
30}