orbtk icon indicating copy to clipboard operation
orbtk copied to clipboard

ctx.send_window_request(WindowRequest::Close); in fn message can not close window

Open E834159672 opened this issue 4 years ago • 4 comments

hello ,

i want to write a window like "scan qrcode to login", and then i modify from examples/messsage.rs.

the last step is : when user has finished scan code,i should close the window,but it not work in my code (ctx.send_window_request(WindowRequest::Close);).

if i move the mouse to the window, then i will close.

and Strangely,ctx.send_window_request(WindowRequest::Close); work well in examples/messsage.rs..

my code like this:

fn messages(
        &mut self,
        mut messages: MessageReader,
        _registry: &mut Registry,
        ctx: &mut Context,
    ) {
        println!("in messages:");

        for message in messages.read::<Message>() {
            match message {
                Message::UpdatetQRCodeImage(p) => {
                    println!("in messages: UpdateImage");
                    self.current_qrcode_path = p;
                    self.need_update_qrcode= true;

                    ctx.window().update_dirty(true);
                }
                Message::ScanCodeFinished => {
                    println!("in messages: ScanCodeFinished");
                    self.scan_result.store(true, Ordering::SeqCst);
                    ctx.send_window_request(WindowRequest::Close);
                    //ctx.window().update(true);
             
                }
            }
        }
    }

and full repo code is here:

https://github.com/E834159672/test-gui

any idea?

thanks!

E834159672 avatar Feb 02 '21 05:02 E834159672

i run it on linux ,fedora 33 ,x86_64, kernel 5.10.12.

E834159672 avatar Feb 02 '21 07:02 E834159672

i found a way to work around the problem:

after

ctx.send_window_request(WindowRequest::Close);

add these code:

let entity = ctx.widget().entity();
ctx.event_adapter().push_event(entity, WindowEvent::ActiveChanged(true));

but why , i does not know.

E834159672 avatar Feb 03 '21 03:02 E834159672

Hello.

ctx.send_window_request()

is probably deprecated, please use the new message sending mechanism, the event_adapter.

kivimango avatar Feb 03 '21 10:02 kivimango

@kivimango ,thanks for your response. by using event_adapter, i can not find out how to close window

E834159672 avatar Feb 04 '21 00:02 E834159672