some ux improvements

This commit is contained in:
leca 2024-05-13 23:59:21 +03:00
parent 33f81be159
commit 8207a76a2f
4 changed files with 78 additions and 54 deletions

View File

@ -125,7 +125,7 @@ fn build_ui(app: &Application) {
@strong app, @strong memory_cards_edit => move |_b: &Button| { @strong app, @strong memory_cards_edit => move |_b: &Button| {
switch_to(&app, AppWindow::MemoryCardsEditScene); switch_to(&app, AppWindow::MemoryCardsEditScene);
memory_cards_edit.imp().query_cards(None); memory_cards_edit.imp().query_cards(None);
memory_cards_edit.imp().update_state(); // memory_cards_edit.imp().update_state();
} }
), ),
); );
@ -147,6 +147,7 @@ fn build_ui(app: &Application) {
@strong app, @strong memory_cards_game => move |_b: &Button| { @strong app, @strong memory_cards_game => move |_b: &Button| {
switch_to(&app, AppWindow::MemoryCardsGameScene); switch_to(&app, AppWindow::MemoryCardsGameScene);
memory_cards_game.imp().update_card(); memory_cards_game.imp().update_card();
// memory_cards_game.imp().u
} }
), ),
); );

View File

@ -72,7 +72,7 @@ impl ObjectImpl for MemoryCardsEditScene {
})); }));
new_win.get_done_button().connect_closure("clicked", true, closure_local!(@strong binding => move |_w: &Button| { new_win.get_done_button().connect_closure("clicked", true, closure_local!(@strong binding => move |_w: &Button| {
binding.imp().query_cards(None); binding.imp().query_cards(None);
binding.imp().update_state(); binding.imp().build_factory();
})); }));
new_win.present(); new_win.present();
})); }));
@ -88,14 +88,15 @@ impl ObjectImpl for MemoryCardsEditScene {
} }
} }
); );
binding.imp().update_state(); // binding.imp().update_state();
})); }));
self.update_state(); self.query_cards(None);
self.build_factory();
} }
} }
impl MemoryCardsEditScene { impl MemoryCardsEditScene {
pub fn update_state(&self) { pub fn build_factory(&self) {
let model = ListStore::new::<CardGObject>(); let model = ListStore::new::<CardGObject>();
model.extend_from_slice(&self.displaying_cards.borrow()); model.extend_from_slice(&self.displaying_cards.borrow());
@ -137,7 +138,7 @@ impl MemoryCardsEditScene {
b.set_visible(false); b.set_visible(false);
gtk::glib::MainContext::default().spawn_local(new_card_setup(Rc::clone(&new_win))); gtk::glib::MainContext::default().spawn_local(new_card_setup(Rc::clone(&new_win)));
})); }));
new_win.get_done_button().connect_closure("clicked", true, closure_local!(@strong binding, @strong new_win as w, @strong card => move |_w: &Button| { new_win.get_done_button().connect_closure("clicked", true, closure_local!(@strong new_win as w, @strong card => move |_w: &Button| {
let conn = Connection::open(get_db_path()).unwrap(); let conn = Connection::open(get_db_path()).unwrap();
let hieroglyph = w.get_hieroglyph_input(); let hieroglyph = w.get_hieroglyph_input();
@ -166,7 +167,6 @@ impl MemoryCardsEditScene {
card.set_reading(reading); card.set_reading(reading);
card.set_translation(translation); card.set_translation(translation);
binding.imp().update_state();
w.close(); w.close();
})); }));
new_win.present(); new_win.present();
@ -191,7 +191,7 @@ impl MemoryCardsEditScene {
connection.execute("DELETE FROM cards WHERE hieroglyph = ?1", [&card.hieroglyph()]).unwrap(); connection.execute("DELETE FROM cards WHERE hieroglyph = ?1", [&card.hieroglyph()]).unwrap();
let position = self_binding.imp().displaying_cards.borrow().iter().position(|c| *c == card).unwrap(); let position = self_binding.imp().displaying_cards.borrow().iter().position(|c| *c == card).unwrap();
self_binding.imp().displaying_cards.borrow_mut().remove(position); self_binding.imp().displaying_cards.borrow_mut().remove(position);
self_binding.imp().update_state(); // self_binding.imp().update_state();
})); }));
card_gobject.bind_property("imagepath", card_object_to_display.get_image_widget(), "file").sync_create().build(); card_gobject.bind_property("imagepath", card_object_to_display.get_image_widget(), "file").sync_create().build();
@ -222,16 +222,12 @@ impl MemoryCardsEditScene {
let cards_iter = stmt let cards_iter = stmt
.query_map([], |row| { .query_map([], |row| {
let image_path: String = match row.get(0) {
Ok(path) => path,
Err(_) => String::from(""),
};
let c = Card::new( let c = Card::new(
Some(get_images_store_path() + &image_path), Some(get_images_store_path() + &row.get(0).unwrap_or(String::from(""))),
Some(row.get(1).unwrap()), Some(row.get(1).unwrap_or(String::from(""))),
Some(row.get(2).unwrap()), Some(row.get(2).unwrap_or(String::from(""))),
Some(row.get(3).unwrap()), Some(row.get(3).unwrap_or(String::from(""))),
Some(row.get(4).unwrap()), Some(row.get(4).unwrap_or(false)),
); );
let entry = CardGObject::new(Some(c)); let entry = CardGObject::new(Some(c));
Ok(entry) Ok(entry)
@ -261,7 +257,8 @@ async fn new_card_setup<W: IsA<gtk::Window>>(window: Rc<W>) {
); );
let path = RefCell::new(String::from("")); let path = RefCell::new(String::from(""));
dialog.run_async(clone!( @strong path, @strong w, @strong picture_widget => move |a, _b| { dialog.run_async(
clone!( @strong path, @strong w, @strong picture_widget => move |a, _b| {
let c = a.file().unwrap() let c = a.file().unwrap()
.path().unwrap() .path().unwrap()
.as_os_str().to_owned() .as_os_str().to_owned()
@ -295,13 +292,31 @@ async fn new_card_setup<W: IsA<gtk::Window>>(window: Rc<W>) {
fs::copy(&p, stored_image_path).expect("Error copying image to store"); fs::copy(&p, stored_image_path).expect("Error copying image to store");
let hieroglyph = w.get_hieroglyph_input(); let hieroglyph = w.get_hieroglyph_input();
let reading = w.get_reading_input();
let translation = w.get_translation_input();
let conn = Connection::open(get_db_path()).unwrap(); let conn = Connection::open(get_db_path()).unwrap();
conn.execute("UPDATE cards SET imagename = ?1 WHERE hieroglyph = ?2", (&new_filename, &hieroglyph)).unwrap(); conn.execute("INSERT OR REPLACE INTO cards ( id,
conn.execute("UPDATE cards SET is_learning = TRUE WHERE hieroglyph = ?1", [&hieroglyph]).unwrap(); imagename,
hieroglyph,
reading,
translation,
is_learning
) VALUES (
(SELECT id FROM cards WHERE hieroglyph = ?2),
?1,
?2,
?3,
?4,
(SELECT is_learning FROM cards WHERE hieroglyph = ?2 OR TRUE
)
)", (&new_filename, &hieroglyph, &reading, &translation)).unwrap();
w.close();
}),
);
}), }),
); );
}));
} }
impl WidgetImpl for MemoryCardsEditScene {} impl WidgetImpl for MemoryCardsEditScene {}

View File

@ -81,6 +81,7 @@ impl MemoryCardsGameScene {
self.card_display.set_reading(card.reading()); self.card_display.set_reading(card.reading());
self.card_display.set_translation(card.translation()); self.card_display.set_translation(card.translation());
self.card_display.update_file_for_image(); self.card_display.update_file_for_image();
self.obj().hide_no_cards_msg();
} }
None => self.obj().show_no_cards_msg(), None => self.obj().show_no_cards_msg(),
} }
@ -98,7 +99,7 @@ fn generate_card() -> Option<CardDisplay> {
row.get(1).unwrap(), row.get(1).unwrap(),
row.get(2).unwrap(), row.get(2).unwrap(),
row.get(3).unwrap(), row.get(3).unwrap(),
None, Some(true),
)) ))
}) })
.unwrap(); .unwrap();
@ -111,17 +112,19 @@ fn generate_card() -> Option<CardDisplay> {
Some(card) => card, Some(card) => card,
None => return None, None => return None,
}; };
let generated_card = CardDisplay::new( let generated_card = CardDisplay::new(
&(get_images_store_path() &(get_images_store_path()
+ "/" + "/"
+ match &random_card.image_path() { + match &random_card.image_path() {
Some(path) => &path[..], Some(path) => path,
None => return None, None => return None,
}), }),
&random_card.hieroglyph().unwrap(), &random_card.hieroglyph().unwrap(),
Some(&random_card.reading().unwrap()), Some(&random_card.reading().unwrap()),
&random_card.translation().unwrap(), &random_card.translation().unwrap(),
); );
Some(generated_card) Some(generated_card)
} }

View File

@ -37,4 +37,9 @@ impl MemoryCardsGameScene {
self.imp().stats_label.set_visible(false); self.imp().stats_label.set_visible(false);
self.imp().no_cards_label.set_visible(true); self.imp().no_cards_label.set_visible(true);
} }
pub fn hide_no_cards_msg(&self) {
self.imp().card_display.set_visible(true);
self.imp().stats_label.set_visible(true);
self.imp().no_cards_label.set_visible(false);
}
} }