diff --git a/src/game.rs b/src/game.rs index 020b504..1803086 100644 --- a/src/game.rs +++ b/src/game.rs @@ -5,13 +5,23 @@ const CONSONANTS: usize = 11; const OBS: &str = ""; type KanaCharacters<'a> = [[&'a str; VOWELS]; CONSONANTS]; - +#[derive(Clone)] pub enum Kanas { Romaji, Hiragana, Katakana, } +impl std::fmt::Display for Kanas{ + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "{}", match self { + Kanas::Romaji => "Romaji", + Kanas::Hiragana => "Hiragana", + Kanas::Katakana => "Katakana" + }) + } +} + pub struct Hieroglyph { syllable: String, row: usize, @@ -109,7 +119,7 @@ fn get_characters_for_kana(k: &Kanas) -> KanaCharacters { } } -pub fn get_kana_pair_for_hieroglyph(k: Kanas, h: &Hieroglyph) -> Hieroglyph { +pub fn get_kana_pair_for_hieroglyph(k: &Kanas, h: &Hieroglyph) -> Hieroglyph { Hieroglyph { syllable: get_characters_for_kana(&k)[h.row][h.column].to_string(), row: h.row, diff --git a/src/main.rs b/src/main.rs index b2877dc..9f66bd4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,9 +3,9 @@ mod labled_switch; use gio::Settings; use std::cell::{Cell, RefCell}; -use gtk::glib::{clone, closure_local}; +use std::ops::Deref; use gtk::{gio, prelude::*, Button, Entry, Label}; -use gtk::{glib, Application, ApplicationWindow, Box}; +use gtk::{glib::clone, glib, Application, ApplicationWindow, Box}; use crate::game::*; use rand::prelude::*; @@ -14,12 +14,6 @@ const APP_ID: &str = "org.foxarmy.learn-hieroglyph"; fn main() -> glib::ExitCode { let app = Application::builder().application_id(APP_ID).build(); - let syllable = generate_random_hieroglyph(Kanas::Romaji); - let hiragana = get_kana_pair_for_hieroglyph(Kanas::Hiragana, &syllable); - let katakana = get_kana_pair_for_hieroglyph(Kanas::Katakana, &syllable); - - println!("{syllable} = {hiragana} = {katakana}"); - app.connect_activate(build_ui); app.run() @@ -150,7 +144,7 @@ fn generate_question_text(question: & Hieroglyph, exact_kana: &Kanas) -> String } -fn build_game(w: &RefCell) -> Box { +fn build_game(_w: &RefCell) -> Box { let game: Box = Box::builder() .orientation(gtk::Orientation::Vertical) .build(); @@ -160,33 +154,65 @@ fn build_game(w: &RefCell) -> Box { let entry: Entry = Entry::builder() .placeholder_text("Answer") .build(); - + let mut counter_label: RefCell