feat(infobar): add a timer after which the infobar will be closed

This commit is contained in:
doryan 2024-07-27 23:28:35 +04:00
parent 33226ecae2
commit 01f65376d0

View File

@ -1,7 +1,5 @@
use glib::property::PropertyGet;
use gtk4 as gtk; use gtk4 as gtk;
use gtk4::prelude::WidgetExt; use std::{str::FromStr, sync::Arc, time::Duration};
use std::{str::FromStr, time::Duration};
use crate::{ use crate::{
event_handlers::button_event_handlers::BtnEventHandler, event_handlers::button_event_handlers::BtnEventHandler,
@ -68,10 +66,7 @@ pub fn signal_reducing_page(wrapper: &Box) {
let calculate_button = Button::builder().label("Расчитать").build(); let calculate_button = Button::builder().label("Расчитать").build();
// TODO: Make asynchronious auto-hide info bar. let info_bar: Arc<InfoBar> = Arc::new(InfoBar::get_instance());
let test = InfoBar::get_instance();
// let (tx, rx) = std::sync::mpsc::channel::<bool>();
EventHandler::new(calculate_button.clone(), move |_| { EventHandler::new(calculate_button.clone(), move |_| {
let mut values: [f64; 6] = [0f64; 6]; let mut values: [f64; 6] = [0f64; 6];
@ -91,23 +86,19 @@ pub fn signal_reducing_page(wrapper: &Box) {
if let Ok(value) = try_extract_value { if let Ok(value) = try_extract_value {
values[i] = value; values[i] = value;
} else { } else {
test.set_text_label(Some("Вы ввели некорректное значение поля.")); info_bar.set_text_label(Some("Вы ввели некорректное значение поля."));
test.set_reveal_child(true); info_bar.set_reveal_child(true);
// TODO: Make asynchronious auto-hide info bar.
// let transmitter = tx.clone();
//
// gio::spawn_blocking(move || {
// std::thread::sleep(Duration::from_secs(5));
// transmitter.send(false).unwrap();
// });
//
// test.set_reveal_child(rx.recv().unwrap());
println!("Вы ввели некорректное значение поля."); let info_bar_reference = info_bar.clone();
return;
gio::spawn_blocking(move || {
std::thread::sleep(Duration::from_secs(5));
info_bar_reference.set_reveal_child(false);
});
break;
} }
} }
println!("{:?}", values);
}) })
.on_click(); .on_click();