cargo fmt

This commit is contained in:
leca 2024-05-24 11:05:40 +03:00
parent 8086928d43
commit c334c587b5
20 changed files with 93 additions and 56 deletions

View File

@ -4,13 +4,23 @@ pub struct Card {
hieroglyph: Option<String>,
reading: Option<String>,
translation: Option<String>,
is_learning: Option<bool>
is_learning: Option<bool>,
}
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 {
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> {
self.is_learning.clone()
}
}

View File

@ -1,7 +1,7 @@
mod imp;
use crate::card::Card;
use glib::Object;
use gtk::glib;
use crate::card::Card;
glib::wrapper! {
pub struct CardGObject(ObjectSubclass<imp::CardGObject>);
@ -10,17 +10,14 @@ glib::wrapper! {
impl CardGObject {
pub fn new(c: Option<Card>) -> Self {
match c {
Some(c) => {
Object::builder()
Some(c) => Object::builder()
.property("imagepath", c.image_path().unwrap())
.property("hieroglyph", c.hieroglyph().unwrap())
.property("reading", c.reading().unwrap())
.property("translation", c.translation().unwrap())
.property("islearning", c.is_learning().unwrap())
.build()
},
None => Object::builder().build()
}
.build(),
None => Object::builder().build(),
}
}
}

View File

@ -20,11 +20,14 @@ pub fn init() {
};
match fs::create_dir_all(&program_home_path) {
Ok(_) => {},
Ok(_) => {}
Err(error) => match error.kind() {
ErrorKind::AlreadyExists => {},
_ => panic!("Could not create app home folder: {}", &program_home_path.to_str().unwrap())
}
ErrorKind::AlreadyExists => {}
_ => panic!(
"Could not create app home folder: {}",
&program_home_path.to_str().unwrap()
),
},
};
let mut binding = PROGRAM_HOME_PATH.write().unwrap();
@ -40,17 +43,21 @@ pub fn init() {
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,
imagename CHAR(64),
hieroglyph VARCHAR(64),
reading VARCHAR(64),
translation VARCHAR(128),
is_learning BOOLEAN DEFAULT FALSE
)",()).unwrap();
)",
(),
)
.unwrap();
}
pub fn get_program_home_path() -> String {
(*PROGRAM_HOME_PATH.read().unwrap()).clone()
}

View File

@ -1,5 +1,5 @@
use rusqlite::Connection;
use core::panic;
use rusqlite::Connection;
use std::fs::{self, File};
use std::io::{ErrorKind, Write};
@ -48,7 +48,7 @@ async fn download_dictionary(path: String) {
let mut file = match File::create(&path) {
Err(e) => panic!("Could not create dictionary file. {}", e),
Ok(file) => file
Ok(file) => file,
};
let content = response.unwrap().bytes().await.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");
return Vec::new();
},
}
},
};

View File

@ -1,12 +1,12 @@
#![windows_subsystem = "windows"]
mod card;
mod card_gobject;
mod db;
mod dictionary;
mod game;
mod ui;
mod widgets;
mod dictionary;
mod card;
mod card_gobject;
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.
let app: Application = Application::builder().application_id(APP_ID).build();
app.connect_activate(build_ui);

View File

@ -25,7 +25,8 @@ impl MemoryCardsGameScene {
"Correct|Incorrect: {}|{} ({:.2}%)",
self.imp().correct.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)
));
}

View File

@ -1,4 +1,4 @@
pub mod edit;
pub mod game;
pub mod setup;
pub mod new;
pub mod setup;

View File

@ -40,7 +40,6 @@ impl ObjectImpl for MemoryCardsNewScene {
}
}
impl WidgetImpl for MemoryCardsNewScene {}
impl WindowImpl for MemoryCardsNewScene {}

View File

@ -2,7 +2,10 @@ mod imp;
use glib::Object;
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! {

View File

@ -1,7 +1,11 @@
mod imp;
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! {
pub struct MemoryCardsSetupScene(ObjectSubclass<imp::MemoryCardsSetupScene>)

View File

@ -60,7 +60,6 @@ impl ObjectImpl for GuessingScene {
let answer_entry_binding = &self.answer_entry.get();
let stats_label_binding = &self.stats_label.get();
/*
"Memory management when writing a gtk-rs app can be a bit tricky."

View File

@ -2,11 +2,15 @@ mod imp;
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 glib::Object;
use gtk::gio::Settings;
use gtk::{
gio::{self, prelude::*},
glib::{self, subclass::types::ObjectSubclassIsExt},
Application, Button,
};
use rand::Rng;
glib::wrapper! {
pub struct GuessingScene(ObjectSubclass<imp::GuessingScene>)
@ -66,9 +70,11 @@ impl GuessingScene {
&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());
self.imp().question_label.set_label(text);
}
}

View File

@ -1,7 +1,11 @@
mod imp;
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! {
pub struct GuessingSetupScene(ObjectSubclass<imp::GuessingSetupScene>)

View File

@ -1,7 +1,11 @@
mod imp;
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! {
pub struct MenuScene(ObjectSubclass<imp::MenuScene>)
@ -22,5 +26,4 @@ impl MenuScene {
pub fn get_memory_cards_button(&self) -> &Button {
self.imp().memory_cards.as_ref()
}
}

View File

@ -3,7 +3,7 @@ use std::cell::RefCell;
use glib::subclass::InitializingObject;
use glib::Properties;
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)]
#[properties(wrapper_type = super::CardDisplay)]

View File

@ -1,9 +1,12 @@
mod imp;
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! {
pub struct CardDisplay(ObjectSubclass<imp::CardDisplay>)
@ -13,7 +16,12 @@ glib::wrapper! {
}
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()
.property("imagepath", image_path)
.property("translation", translation)

View File

@ -5,7 +5,6 @@ use glib::Properties;
use gtk::subclass::prelude::*;
use gtk::{glib, prelude::*, Button, CompositeTemplate, Image, Label, Switch};
#[derive(CompositeTemplate, Properties, Default)]
#[properties(wrapper_type = super::CardEntry)]
#[template(resource = "/org/foxarmy/learn-hieroglyph/widgets/card_entry/template.ui.xml")]

View File

@ -1,3 +1,3 @@
pub mod labled_switch;
pub mod card_entry;
pub mod card_display;
pub mod card_entry;
pub mod labled_switch;