hover_position/
hover_position.rs1use gpui::{
2 App, Application, Bounds, Context, Window, WindowBounds, WindowOptions, div, prelude::*, px,
3 size,
4};
5use gpui_animation::{
6 animation::TransitionExt,
7 transition::{self},
8};
9
10struct Hover;
11
12impl Render for Hover {
13 fn render(&mut self, _window: &mut Window, _: &mut Context<Self>) -> impl IntoElement {
14 let linear = std::sync::Arc::new(transition::general::Linear);
15
16 div()
17 .id("Hoverable2")
18 .flex()
19 .flex_col()
20 .gap_3()
21 .size(px(500.0))
22 .justify_center()
23 .items_center()
24 .child(
25 div()
26 .id("Hoverable")
27 .child("Hover over rectangle")
28 .bg(gpui::white())
29 .text_color(gpui::red())
30 .flex()
31 .text_xl()
32 .h_10()
33 .justify_center()
34 .items_center(),
35 )
36 .child(
37 div().flex().gap_2().child(
38 div()
39 .id("Hoverable1")
40 .size_16()
41 .with_transition("Hoverable1")
42 .transition_on_hover(
43 std::time::Duration::from_millis(250),
44 linear.clone(),
45 |hovered, state| {
46 if *hovered {
47 state.size_32()
48 } else {
49 state.size_16()
50 }
51 },
52 )
53 .bg(gpui::red()),
54 ),
55 )
56 }
57}
58
59fn main() {
60 Application::new().run(|cx: &mut App| {
61 let bounds = Bounds::centered(None, size(px(500.), px(500.0)), cx);
62 cx.open_window(
63 WindowOptions {
64 window_bounds: Some(WindowBounds::Windowed(bounds)),
65 ..Default::default()
66 },
67 |_, cx| cx.new(|_| Hover),
68 )
69 .unwrap();
70 });
71}