cargo fmt
This commit is contained in:
parent
8086928d43
commit
c334c587b5
|
@ -4,13 +4,23 @@ pub struct Card {
|
||||||
hieroglyph: Option<String>,
|
hieroglyph: Option<String>,
|
||||||
reading: Option<String>,
|
reading: Option<String>,
|
||||||
translation: Option<String>,
|
translation: Option<String>,
|
||||||
is_learning: Option<bool>
|
is_learning: Option<bool>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Card {
|
impl Card {
|
||||||
pub fn new(image_path: Option<String>, hieroglyph: Option<String>, reading: Option<String>, translation: Option<String>, is_learning: Option<bool>) -> Card {
|
pub fn new(
|
||||||
|
image_path: Option<String>,
|
||||||
|
hieroglyph: Option<String>,
|
||||||
|
reading: Option<String>,
|
||||||
|
translation: Option<String>,
|
||||||
|
is_learning: Option<bool>,
|
||||||
|
) -> Card {
|
||||||
Card {
|
Card {
|
||||||
image_path, hieroglyph, reading, translation, is_learning
|
image_path,
|
||||||
|
hieroglyph,
|
||||||
|
reading,
|
||||||
|
translation,
|
||||||
|
is_learning,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,5 +43,4 @@ impl Card {
|
||||||
pub fn is_learning(&self) -> Option<bool> {
|
pub fn is_learning(&self) -> Option<bool> {
|
||||||
self.is_learning.clone()
|
self.is_learning.clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
mod imp;
|
mod imp;
|
||||||
|
use crate::card::Card;
|
||||||
use glib::Object;
|
use glib::Object;
|
||||||
use gtk::glib;
|
use gtk::glib;
|
||||||
use crate::card::Card;
|
|
||||||
|
|
||||||
glib::wrapper! {
|
glib::wrapper! {
|
||||||
pub struct CardGObject(ObjectSubclass<imp::CardGObject>);
|
pub struct CardGObject(ObjectSubclass<imp::CardGObject>);
|
||||||
|
@ -10,17 +10,14 @@ glib::wrapper! {
|
||||||
impl CardGObject {
|
impl CardGObject {
|
||||||
pub fn new(c: Option<Card>) -> Self {
|
pub fn new(c: Option<Card>) -> Self {
|
||||||
match c {
|
match c {
|
||||||
Some(c) => {
|
Some(c) => Object::builder()
|
||||||
Object::builder()
|
|
||||||
.property("imagepath", c.image_path().unwrap())
|
.property("imagepath", c.image_path().unwrap())
|
||||||
.property("hieroglyph", c.hieroglyph().unwrap())
|
.property("hieroglyph", c.hieroglyph().unwrap())
|
||||||
.property("reading", c.reading().unwrap())
|
.property("reading", c.reading().unwrap())
|
||||||
.property("translation", c.translation().unwrap())
|
.property("translation", c.translation().unwrap())
|
||||||
.property("islearning", c.is_learning().unwrap())
|
.property("islearning", c.is_learning().unwrap())
|
||||||
.build()
|
.build(),
|
||||||
},
|
None => Object::builder().build(),
|
||||||
None => Object::builder().build()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
21
src/db.rs
21
src/db.rs
|
@ -20,11 +20,14 @@ pub fn init() {
|
||||||
};
|
};
|
||||||
|
|
||||||
match fs::create_dir_all(&program_home_path) {
|
match fs::create_dir_all(&program_home_path) {
|
||||||
Ok(_) => {},
|
Ok(_) => {}
|
||||||
Err(error) => match error.kind() {
|
Err(error) => match error.kind() {
|
||||||
ErrorKind::AlreadyExists => {},
|
ErrorKind::AlreadyExists => {}
|
||||||
_ => panic!("Could not create app home folder: {}", &program_home_path.to_str().unwrap())
|
_ => panic!(
|
||||||
}
|
"Could not create app home folder: {}",
|
||||||
|
&program_home_path.to_str().unwrap()
|
||||||
|
),
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut binding = PROGRAM_HOME_PATH.write().unwrap();
|
let mut binding = PROGRAM_HOME_PATH.write().unwrap();
|
||||||
|
@ -40,17 +43,21 @@ pub fn init() {
|
||||||
|
|
||||||
let connection = Connection::open(db_path).unwrap();
|
let connection = Connection::open(db_path).unwrap();
|
||||||
|
|
||||||
connection.execute("CREATE TABLE IF NOT EXISTS cards (
|
connection
|
||||||
|
.execute(
|
||||||
|
"CREATE TABLE IF NOT EXISTS cards (
|
||||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
imagename CHAR(64),
|
imagename CHAR(64),
|
||||||
hieroglyph VARCHAR(64),
|
hieroglyph VARCHAR(64),
|
||||||
reading VARCHAR(64),
|
reading VARCHAR(64),
|
||||||
translation VARCHAR(128),
|
translation VARCHAR(128),
|
||||||
is_learning BOOLEAN DEFAULT FALSE
|
is_learning BOOLEAN DEFAULT FALSE
|
||||||
)",()).unwrap();
|
)",
|
||||||
|
(),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub fn get_program_home_path() -> String {
|
pub fn get_program_home_path() -> String {
|
||||||
(*PROGRAM_HOME_PATH.read().unwrap()).clone()
|
(*PROGRAM_HOME_PATH.read().unwrap()).clone()
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use rusqlite::Connection;
|
|
||||||
use core::panic;
|
use core::panic;
|
||||||
|
use rusqlite::Connection;
|
||||||
use std::fs::{self, File};
|
use std::fs::{self, File};
|
||||||
use std::io::{ErrorKind, Write};
|
use std::io::{ErrorKind, Write};
|
||||||
|
|
||||||
|
@ -48,7 +48,7 @@ async fn download_dictionary(path: String) {
|
||||||
|
|
||||||
let mut file = match File::create(&path) {
|
let mut file = match File::create(&path) {
|
||||||
Err(e) => panic!("Could not create dictionary file. {}", e),
|
Err(e) => panic!("Could not create dictionary file. {}", e),
|
||||||
Ok(file) => file
|
Ok(file) => file,
|
||||||
};
|
};
|
||||||
let content = response.unwrap().bytes().await.unwrap();
|
let content = response.unwrap().bytes().await.unwrap();
|
||||||
file.write_all(&content).unwrap();
|
file.write_all(&content).unwrap();
|
||||||
|
@ -72,7 +72,7 @@ fn read_and_parse(path: &String) -> Vec<DictionaryEntry> {
|
||||||
_ => {
|
_ => {
|
||||||
println!("Unexpected error. Can't load dictionary. Assuming it's empty");
|
println!("Unexpected error. Can't load dictionary. Assuming it's empty");
|
||||||
return Vec::new();
|
return Vec::new();
|
||||||
},
|
}
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
#![windows_subsystem = "windows"]
|
#![windows_subsystem = "windows"]
|
||||||
|
|
||||||
|
mod card;
|
||||||
|
mod card_gobject;
|
||||||
mod db;
|
mod db;
|
||||||
|
mod dictionary;
|
||||||
mod game;
|
mod game;
|
||||||
mod ui;
|
mod ui;
|
||||||
mod widgets;
|
mod widgets;
|
||||||
mod dictionary;
|
|
||||||
mod card;
|
|
||||||
mod card_gobject;
|
|
||||||
|
|
||||||
use crate::ui::menu::MenuScene;
|
use crate::ui::menu::MenuScene;
|
||||||
|
|
||||||
|
@ -41,8 +41,6 @@ fn main() -> glib::ExitCode {
|
||||||
|
|
||||||
dictionary::import(&(get_program_home_path() + "/dictionary.txt")); // Read file, parse it, deduplicate and append to the database.
|
dictionary::import(&(get_program_home_path() + "/dictionary.txt")); // Read file, parse it, deduplicate and append to the database.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
let app: Application = Application::builder().application_id(APP_ID).build();
|
let app: Application = Application::builder().application_id(APP_ID).build();
|
||||||
|
|
||||||
app.connect_activate(build_ui);
|
app.connect_activate(build_ui);
|
||||||
|
|
|
@ -25,7 +25,8 @@ impl MemoryCardsGameScene {
|
||||||
"Correct|Incorrect: {}|{} ({:.2}%)",
|
"Correct|Incorrect: {}|{} ({:.2}%)",
|
||||||
self.imp().correct.borrow(),
|
self.imp().correct.borrow(),
|
||||||
self.imp().incorrect.borrow(),
|
self.imp().incorrect.borrow(),
|
||||||
100.0 * f64::from(*self.imp().correct.borrow() as i32) / f64::from((*self.imp().incorrect.borrow() + *self.imp().correct.borrow()) as i32)
|
100.0 * f64::from(*self.imp().correct.borrow() as i32)
|
||||||
|
/ f64::from((*self.imp().incorrect.borrow() + *self.imp().correct.borrow()) as i32)
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
pub mod edit;
|
pub mod edit;
|
||||||
pub mod game;
|
pub mod game;
|
||||||
pub mod setup;
|
|
||||||
pub mod new;
|
pub mod new;
|
||||||
|
pub mod setup;
|
||||||
|
|
|
@ -40,7 +40,6 @@ impl ObjectImpl for MemoryCardsNewScene {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
impl WidgetImpl for MemoryCardsNewScene {}
|
impl WidgetImpl for MemoryCardsNewScene {}
|
||||||
|
|
||||||
impl WindowImpl for MemoryCardsNewScene {}
|
impl WindowImpl for MemoryCardsNewScene {}
|
||||||
|
|
|
@ -2,7 +2,10 @@ mod imp;
|
||||||
|
|
||||||
use glib::Object;
|
use glib::Object;
|
||||||
use gtk::{
|
use gtk::{
|
||||||
gio, glib::{self, subclass::types::ObjectSubclassIsExt}, prelude::*, Application, Button, Entry, Picture
|
gio,
|
||||||
|
glib::{self, subclass::types::ObjectSubclassIsExt},
|
||||||
|
prelude::*,
|
||||||
|
Application, Button, Entry, Picture,
|
||||||
};
|
};
|
||||||
|
|
||||||
glib::wrapper! {
|
glib::wrapper! {
|
||||||
|
|
|
@ -1,7 +1,11 @@
|
||||||
mod imp;
|
mod imp;
|
||||||
|
|
||||||
use glib::Object;
|
use glib::Object;
|
||||||
use gtk::{gio, glib::{self, subclass::types::ObjectSubclassIsExt}, Application, Button};
|
use gtk::{
|
||||||
|
gio,
|
||||||
|
glib::{self, subclass::types::ObjectSubclassIsExt},
|
||||||
|
Application, Button,
|
||||||
|
};
|
||||||
|
|
||||||
glib::wrapper! {
|
glib::wrapper! {
|
||||||
pub struct MemoryCardsSetupScene(ObjectSubclass<imp::MemoryCardsSetupScene>)
|
pub struct MemoryCardsSetupScene(ObjectSubclass<imp::MemoryCardsSetupScene>)
|
||||||
|
|
|
@ -60,7 +60,6 @@ impl ObjectImpl for GuessingScene {
|
||||||
let answer_entry_binding = &self.answer_entry.get();
|
let answer_entry_binding = &self.answer_entry.get();
|
||||||
let stats_label_binding = &self.stats_label.get();
|
let stats_label_binding = &self.stats_label.get();
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
||||||
"Memory management when writing a gtk-rs app can be a bit tricky."
|
"Memory management when writing a gtk-rs app can be a bit tricky."
|
||||||
|
|
|
@ -2,11 +2,15 @@ mod imp;
|
||||||
|
|
||||||
use std::ops::Deref;
|
use std::ops::Deref;
|
||||||
|
|
||||||
use glib::Object;
|
|
||||||
use gtk::{gio::{self, prelude::*}, glib::{self, subclass::types::ObjectSubclassIsExt}, Application, Button};
|
|
||||||
use gtk::gio::Settings;
|
|
||||||
use rand::Rng;
|
|
||||||
use crate::{game::*, APP_ID};
|
use crate::{game::*, APP_ID};
|
||||||
|
use glib::Object;
|
||||||
|
use gtk::gio::Settings;
|
||||||
|
use gtk::{
|
||||||
|
gio::{self, prelude::*},
|
||||||
|
glib::{self, subclass::types::ObjectSubclassIsExt},
|
||||||
|
Application, Button,
|
||||||
|
};
|
||||||
|
use rand::Rng;
|
||||||
|
|
||||||
glib::wrapper! {
|
glib::wrapper! {
|
||||||
pub struct GuessingScene(ObjectSubclass<imp::GuessingScene>)
|
pub struct GuessingScene(ObjectSubclass<imp::GuessingScene>)
|
||||||
|
@ -66,9 +70,11 @@ impl GuessingScene {
|
||||||
&self.imp().question.borrow(),
|
&self.imp().question.borrow(),
|
||||||
);
|
);
|
||||||
|
|
||||||
let binding = generate_question_text(&self.imp().question.borrow(), self.imp().exact_kana.borrow().deref());
|
let binding = generate_question_text(
|
||||||
|
&self.imp().question.borrow(),
|
||||||
|
self.imp().exact_kana.borrow().deref(),
|
||||||
|
);
|
||||||
let text: &str = &(binding.as_str());
|
let text: &str = &(binding.as_str());
|
||||||
self.imp().question_label.set_label(text);
|
self.imp().question_label.set_label(text);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,11 @@
|
||||||
mod imp;
|
mod imp;
|
||||||
|
|
||||||
use glib::Object;
|
use glib::Object;
|
||||||
use gtk::{gio, glib::{self, subclass::types::ObjectSubclassIsExt}, Application, Button};
|
use gtk::{
|
||||||
|
gio,
|
||||||
|
glib::{self, subclass::types::ObjectSubclassIsExt},
|
||||||
|
Application, Button,
|
||||||
|
};
|
||||||
|
|
||||||
glib::wrapper! {
|
glib::wrapper! {
|
||||||
pub struct GuessingSetupScene(ObjectSubclass<imp::GuessingSetupScene>)
|
pub struct GuessingSetupScene(ObjectSubclass<imp::GuessingSetupScene>)
|
||||||
|
|
|
@ -1,7 +1,11 @@
|
||||||
mod imp;
|
mod imp;
|
||||||
|
|
||||||
use glib::Object;
|
use glib::Object;
|
||||||
use gtk::{gio, glib::{self, subclass::types::ObjectSubclassIsExt}, Application, Button};
|
use gtk::{
|
||||||
|
gio,
|
||||||
|
glib::{self, subclass::types::ObjectSubclassIsExt},
|
||||||
|
Application, Button,
|
||||||
|
};
|
||||||
|
|
||||||
glib::wrapper! {
|
glib::wrapper! {
|
||||||
pub struct MenuScene(ObjectSubclass<imp::MenuScene>)
|
pub struct MenuScene(ObjectSubclass<imp::MenuScene>)
|
||||||
|
@ -22,5 +26,4 @@ impl MenuScene {
|
||||||
pub fn get_memory_cards_button(&self) -> &Button {
|
pub fn get_memory_cards_button(&self) -> &Button {
|
||||||
self.imp().memory_cards.as_ref()
|
self.imp().memory_cards.as_ref()
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@ use std::cell::RefCell;
|
||||||
use glib::subclass::InitializingObject;
|
use glib::subclass::InitializingObject;
|
||||||
use glib::Properties;
|
use glib::Properties;
|
||||||
use gtk::subclass::prelude::*;
|
use gtk::subclass::prelude::*;
|
||||||
use gtk::{glib, prelude::*, BoxLayout, CompositeTemplate, Entry, Label, Image};
|
use gtk::{glib, prelude::*, BoxLayout, CompositeTemplate, Entry, Image, Label};
|
||||||
|
|
||||||
#[derive(CompositeTemplate, Properties, Default)]
|
#[derive(CompositeTemplate, Properties, Default)]
|
||||||
#[properties(wrapper_type = super::CardDisplay)]
|
#[properties(wrapper_type = super::CardDisplay)]
|
||||||
|
|
|
@ -1,9 +1,12 @@
|
||||||
mod imp;
|
mod imp;
|
||||||
|
|
||||||
|
|
||||||
use glib::Object;
|
use glib::Object;
|
||||||
use gtk::{gio, glib::{self, subclass::types::ObjectSubclassIsExt}, prelude::*, Entry, Image};
|
use gtk::{
|
||||||
|
gio,
|
||||||
|
glib::{self, subclass::types::ObjectSubclassIsExt},
|
||||||
|
prelude::*,
|
||||||
|
Entry, Image,
|
||||||
|
};
|
||||||
|
|
||||||
glib::wrapper! {
|
glib::wrapper! {
|
||||||
pub struct CardDisplay(ObjectSubclass<imp::CardDisplay>)
|
pub struct CardDisplay(ObjectSubclass<imp::CardDisplay>)
|
||||||
|
@ -13,7 +16,12 @@ glib::wrapper! {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CardDisplay {
|
impl CardDisplay {
|
||||||
pub fn new(image_path: &String, hieroglyph: &String, reading: Option<&String>, translation: &String) -> Self {
|
pub fn new(
|
||||||
|
image_path: &String,
|
||||||
|
hieroglyph: &String,
|
||||||
|
reading: Option<&String>,
|
||||||
|
translation: &String,
|
||||||
|
) -> Self {
|
||||||
Object::builder()
|
Object::builder()
|
||||||
.property("imagepath", image_path)
|
.property("imagepath", image_path)
|
||||||
.property("translation", translation)
|
.property("translation", translation)
|
||||||
|
|
|
@ -5,7 +5,6 @@ use glib::Properties;
|
||||||
use gtk::subclass::prelude::*;
|
use gtk::subclass::prelude::*;
|
||||||
use gtk::{glib, prelude::*, Button, CompositeTemplate, Image, Label, Switch};
|
use gtk::{glib, prelude::*, Button, CompositeTemplate, Image, Label, Switch};
|
||||||
|
|
||||||
|
|
||||||
#[derive(CompositeTemplate, Properties, Default)]
|
#[derive(CompositeTemplate, Properties, Default)]
|
||||||
#[properties(wrapper_type = super::CardEntry)]
|
#[properties(wrapper_type = super::CardEntry)]
|
||||||
#[template(resource = "/org/foxarmy/learn-hieroglyph/widgets/card_entry/template.ui.xml")]
|
#[template(resource = "/org/foxarmy/learn-hieroglyph/widgets/card_entry/template.ui.xml")]
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
pub mod labled_switch;
|
|
||||||
pub mod card_entry;
|
|
||||||
pub mod card_display;
|
pub mod card_display;
|
||||||
|
pub mod card_entry;
|
||||||
|
pub mod labled_switch;
|
||||||
|
|
Loading…
Reference in New Issue