Skip to repository content82 lines · 2.2 KB · rust
tenant.openagents/omega
No repository description is available.
OpenAgents Git authority 2026-07-28T03:41:24.198Z Public web read
NIP-34 coordinate
30617:7649603503856e5148d571eac2766b288a8ff1e9e35d380337a1d2b0015b4f92:omegaMaintainersHidden in public view
References2 branches · 1 tag
Read-only clone
git clone https://openagents.com/git/tenant.openagents/omega.gitBrowse files
mouse_pressure.rs
1#![cfg_attr(target_family = "wasm", no_main)]
2
3use gpui::{
4 App, Bounds, Context, MousePressureEvent, PressureStage, Window, WindowBounds, WindowOptions,
5 div, prelude::*, px, rgb, size,
6};
7use gpui_platform::application;
8
9struct MousePressureExample {
10 pressure_stage: PressureStage,
11 pressure_amount: f32,
12}
13
14impl Render for MousePressureExample {
15 fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
16 div()
17 .flex()
18 .flex_col()
19 .gap_3()
20 .bg(rgb(0x505050))
21 .size(px(500.0))
22 .justify_center()
23 .items_center()
24 .shadow_lg()
25 .border_1()
26 .border_color(rgb(0x0000ff))
27 .text_xl()
28 .text_color(rgb(0xffffff))
29 .child(format!("Pressure stage: {:?}", &self.pressure_stage))
30 .child(format!("Pressure amount: {:.2}", &self.pressure_amount))
31 .on_mouse_pressure(cx.listener(Self::on_mouse_pressure))
32 }
33}
34
35impl MousePressureExample {
36 fn on_mouse_pressure(
37 &mut self,
38 pressure_event: &MousePressureEvent,
39 _window: &mut Window,
40 cx: &mut Context<Self>,
41 ) {
42 self.pressure_amount = pressure_event.pressure;
43 self.pressure_stage = pressure_event.stage;
44
45 cx.notify();
46 }
47}
48
49fn run_example() {
50 application().run(|cx: &mut App| {
51 let bounds = Bounds::centered(None, size(px(500.), px(500.0)), cx);
52
53 cx.open_window(
54 WindowOptions {
55 window_bounds: Some(WindowBounds::Windowed(bounds)),
56 ..Default::default()
57 },
58 |_, cx| {
59 cx.new(|_| MousePressureExample {
60 pressure_stage: PressureStage::Zero,
61 pressure_amount: 0.0,
62 })
63 },
64 )
65 .unwrap();
66
67 cx.activate(true);
68 });
69}
70
71#[cfg(not(target_family = "wasm"))]
72fn main() {
73 run_example();
74}
75
76#[cfg(target_family = "wasm")]
77#[wasm_bindgen::prelude::wasm_bindgen(start)]
78pub fn start() {
79 gpui_platform::web_init();
80 run_example();
81}
82