pub fn event_x_root() -> i32Expand description
Gets the x coordinate of the mouse in the screen
Examples found in repository?
examples/custom_popup.rs (line 102)
87fn main() {
88 let app = app::App::default();
89 let mut win = window::Window::default().with_size(400, 300);
90 let mut frame = frame::Frame::default()
91 .with_size(200, 100)
92 .with_label("Right click me!")
93 .center_of_parent();
94 frame.set_frame(FrameType::BorderFrame);
95 frame.set_color(Color::Red);
96 win.end();
97 win.show();
98 let mut menu = MyPopup::new(&["1st item", "2nd item", &format!("{:?}", frame.frame())]);
99 frame.handle(move |_, ev| match ev {
100 Event::Push => {
101 if app::event_mouse_button() == app::MouseButton::Right {
102 println!("{}", menu.popup(app::event_x_root(), app::event_y_root()));
103 true
104 } else {
105 false
106 }
107 }
108 _ => false,
109 });
110 app.run().unwrap();
111}More examples
examples/shapedwindow_taskbar.rs (line 68)
17fn main() {
18 let app = app::App::default();
19
20 // Act as the application in the taskbar (scroll to event handling)
21 let mut dock_win = window::Window::default()
22 .with_size(1, 1) // So we can place it at the center of the screen (needs a size >0 to be centered)
23 .with_label("TestApplication");
24 dock_win.set_center_screen();
25 dock_win.size_range(0, 0, 0, 0);
26 dock_win.make_resizable(false);
27
28 dock_win.show();
29 dock_win.end();
30
31 let mut win = window::Window::default()
32 .with_size(900, 500)
33 .with_label("TestApplication");
34 win.set_center_screen();
35 win.set_color(enums::Color::from_rgb(26, 25, 55));
36
37 let mut but = button::Button::default()
38 .with_label("Button")
39 .with_size(80, 80)
40 .center_of_parent();
41 but.set_frame(enums::FrameType::OFlatBox);
42 but.set_color(enums::Color::Cyan);
43 but.clear_visible_focus();
44 but.set_callback(|_| println!("Clicked"));
45
46 win.show();
47 win.end();
48
49 let win_shape = prep_shape(win.w(), win.h());
50
51 // Called after showing window
52 win.set_shape(Some(win_shape));
53
54 win.handle({
55 let mut x = 0;
56 let mut y = 0;
57 let mut dock_win = dock_win.clone();
58 move |wself, event| match event {
59 enums::Event::Push => {
60 let coords = app::event_coords();
61 x = coords.0;
62 y = coords.1;
63
64 true
65 }
66 enums::Event::Drag => {
67 wself.resize(
68 app::event_x_root() - x,
69 app::event_y_root() - y,
70 wself.w(),
71 wself.h(),
72 );
73
74 // Changing dock window position so it's close enough to the center of the application (not "visible" to user)
75 dock_win.resize(
76 wself.x() + (wself.w() / 2),
77 wself.y() + (wself.w() / 2),
78 dock_win.w(),
79 dock_win.h(),
80 );
81
82 true
83 }
84 enums::Event::Close => {
85 app.quit();
86
87 true
88 }
89 enums::Event::Hide => {
90 app.quit();
91
92 true
93 }
94 _ => false,
95 }
96 });
97
98 // Make main window appear when "opened" via Alt+Tab or Taskbar
99 dock_win.handle({
100 let mut win = win.clone();
101 move |_wself, event| match event {
102 enums::Event::Focus => {
103 let win_shape = prep_shape(win.w(), win.h());
104
105 win.show();
106 win.set_shape(Some(win_shape));
107
108 true
109 }
110 enums::Event::Hide => {
111 win.hide();
112
113 true
114 }
115 enums::Event::Close => {
116 app.quit();
117
118 true
119 }
120 _ => false,
121 }
122 });
123
124 app.run().unwrap();
125}