orbtk
orbtk copied to clipboard
ctx.send_window_request(WindowRequest::Close); in fn message can not close window
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!
i run it on linux ,fedora 33 ,x86_64, kernel 5.10.12.
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.
Hello.
ctx.send_window_request()
is probably deprecated, please use the new message sending mechanism, the event_adapter.
@kivimango ,thanks for your response. by using event_adapter, i can not find out how to close window