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