While Dragging, trigger the Move/Enter event for widget under the mouse

13 views
Skip to first unread message

Webb Hinton

unread,
Jun 28, 2021, 6:40:22 PM6/28/21
to fltk.general

Is it possible to trigger a Move/Enter/Leave action on a widget whilst dragging a different widget? I'm working on a drag and drop system and I need some way to trigger callbacks on whatever is under the mouse while I'm dragging.

However it seems that while dragging, you can't trigger events on other widgets. If you start dragging the drag_button, then move over the move_over_button, then no events are triggered for the move_over_button. 

Code is in Rust with fltk-rs.

```

use fltk::{app::*, button::*, frame::*, enums::*, window::*, group::*, prelude::*, };


fn main() -> Result<(), Box<dyn std::error::Error>> {
    let app = App::default();
    let mut win = Window::new(200, 200, 500, 300, "Drag and Move ");
    let mut container= Pack::new(50,50,300,200,None);
    container.set_type(PackType::Horizontal);

    //while dragging this button
    let mut drag_button= Button::new(0,0,200,60,"Drag Me!");
    drag_button.handle(move|widg, ev|{
      match ev{
        Event::Drag=>{
            dbg!("im dragging from Drag Button");
            true
        }
        _=>false              
      }
    });
    //we want to trigger these events in this button
    let mut move_over_button= Button::new(200,0,200,60,"Then Move Over me");
    move_over_button.handle(move|widg, ev|{
      match ev{
        Event::Move=>{
            dbg!("I got moved over");
            true
        }
        Event::Enter=>{
            dbg!("I got entered over");
            true
        }
        _=>false              
      }
    });
    container.end();
    win.end();
    win.show();

    while app.wait() {}
    Ok(())
}

```

Mo_Al_

unread,
Jun 29, 2021, 11:01:58 AM6/29/21
to fltk.general
Just to update the list that this was answered here:
https://github.com/fltk-rs/fltk-rs/discussions/751
Reply all
Reply to author
Forward
0 new messages