guessing is completed
This commit is contained in:
parent
b01e248971
commit
3e4a55f33f
|
@ -25,6 +25,11 @@
|
|||
<property name="label_text">Enable romaji to kana?</property>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkButton" id="start_button">
|
||||
<property name="label">Start!</property>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</template>
|
||||
|
|
|
@ -37,13 +37,14 @@ impl ObjectImpl for LabledSwitch {
|
|||
fn constructed(&self) {
|
||||
self.parent_constructed();
|
||||
|
||||
// let a = LayoutManager:: ;
|
||||
|
||||
// self.obj().set_layout_manager(a);
|
||||
|
||||
let l: &Label = self.label_obj.as_ref();
|
||||
self.obj().bind_property("label_text", l, "label").sync_create().build();
|
||||
}
|
||||
|
||||
fn dispose(&self) {
|
||||
self.dispose_template();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
impl WidgetImpl for LabledSwitch {}
|
||||
impl WidgetImpl for LabledSwitch { }
|
|
@ -1,7 +1,7 @@
|
|||
mod imp;
|
||||
|
||||
use glib::Object;
|
||||
use gtk::{gio, glib};
|
||||
use gtk::{gio, glib::{self, subclass::types::ObjectSubclassIsExt}, Label, Switch};
|
||||
|
||||
glib::wrapper! {
|
||||
pub struct LabledSwitch(ObjectSubclass<imp::LabledSwitch>)
|
||||
|
@ -14,4 +14,11 @@ impl LabledSwitch {
|
|||
pub fn new(label: &String) -> Self {
|
||||
Object::builder().property("label_text", label).build()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_switch(&self) -> &Switch {
|
||||
self.imp().switch_obj.as_ref()
|
||||
}
|
||||
pub fn get_label(&self) -> &Label {
|
||||
self.imp().label_obj.as_ref()
|
||||
}
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
|
|
@ -0,0 +1 @@
|
|||
|
|
@ -1,3 +1,3 @@
|
|||
pub mod edit;
|
||||
pub mod game;
|
||||
pub mod setup;
|
||||
pub mod setup;
|
||||
|
|
|
@ -2,14 +2,13 @@ use glib::subclass::InitializingObject;
|
|||
use gtk::subclass::prelude::*;
|
||||
use gtk::{glib, Button, CompositeTemplate};
|
||||
|
||||
|
||||
#[derive(CompositeTemplate, Default)]
|
||||
#[template(resource = "/org/foxarmy/learn-hieroglyph/cards/settings/ui.xml")]
|
||||
pub struct MemoryCardsSetupScene {
|
||||
#[template_child]
|
||||
pub edit_button: TemplateChild<Button>,
|
||||
#[template_child]
|
||||
pub start_button: TemplateChild<Button>
|
||||
pub start_button: TemplateChild<Button>,
|
||||
}
|
||||
|
||||
#[glib::object_subclass]
|
||||
|
@ -29,9 +28,7 @@ impl ObjectSubclass for MemoryCardsSetupScene {
|
|||
|
||||
impl ObjectImpl for MemoryCardsSetupScene {
|
||||
fn constructed(&self) {
|
||||
|
||||
self.parent_constructed();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -39,4 +36,4 @@ impl WidgetImpl for MemoryCardsSetupScene {}
|
|||
|
||||
impl WindowImpl for MemoryCardsSetupScene {}
|
||||
|
||||
impl ApplicationWindowImpl for MemoryCardsSetupScene {}
|
||||
impl ApplicationWindowImpl for MemoryCardsSetupScene {}
|
||||
|
|
|
@ -3,15 +3,14 @@ use std::ops::Deref;
|
|||
|
||||
use crate::{game::*, APP_ID};
|
||||
|
||||
use gtk::glib::clone;
|
||||
use gtk::prelude::*;
|
||||
use glib::subclass::InitializingObject;
|
||||
use gtk::gio::Settings;
|
||||
use gtk::glib::clone;
|
||||
use gtk::prelude::*;
|
||||
use gtk::subclass::prelude::*;
|
||||
use gtk::{glib, Label, Entry, CompositeTemplate};
|
||||
use gtk::{glib, CompositeTemplate, Entry, Label};
|
||||
use rand::Rng;
|
||||
|
||||
|
||||
#[derive(CompositeTemplate, Default)]
|
||||
#[template(resource = "/org/foxarmy/learn-hieroglyph/guessing/game/ui.xml")]
|
||||
pub struct GuessingScene {
|
||||
|
@ -20,7 +19,7 @@ pub struct GuessingScene {
|
|||
#[template_child]
|
||||
pub answer_entry: TemplateChild<Entry>,
|
||||
#[template_child]
|
||||
pub stats_label: TemplateChild<Label>
|
||||
pub stats_label: TemplateChild<Label>,
|
||||
}
|
||||
|
||||
#[glib::object_subclass]
|
||||
|
@ -84,9 +83,9 @@ impl ObjectImpl for GuessingScene {
|
|||
let answer_entry_binding = &self.answer_entry.get();
|
||||
let stats_label_binding = &self.stats_label.get();
|
||||
|
||||
let iteration = clone!(@strong stats,
|
||||
@strong question_label_binding as question_label,
|
||||
@strong answer_entry_binding as answer_entry,
|
||||
let iteration = clone!(@strong stats,
|
||||
@strong question_label_binding as question_label,
|
||||
@strong answer_entry_binding as answer_entry,
|
||||
@strong stats_label_binding as stats_label => move |_entry: &Entry| {
|
||||
let answer: &String = &answer_entry.text().to_string();
|
||||
println!("{} <-> {}? = {}", answer, correct_answer.borrow().to_string(), *answer == correct_answer.borrow().to_string());
|
||||
|
@ -119,7 +118,6 @@ impl ObjectImpl for GuessingScene {
|
|||
});
|
||||
|
||||
self.answer_entry.connect_activate(iteration);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -127,4 +125,4 @@ impl WidgetImpl for GuessingScene {}
|
|||
|
||||
impl WindowImpl for GuessingScene {}
|
||||
|
||||
impl ApplicationWindowImpl for GuessingScene {}
|
||||
impl ApplicationWindowImpl for GuessingScene {}
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
pub mod game;
|
||||
pub mod setup;
|
||||
pub mod game;
|
|
@ -1,10 +1,13 @@
|
|||
|
||||
use crate::labled_switch::LabledSwitch;
|
||||
|
||||
use glib::subclass::InitializingObject;
|
||||
use gtk::subclass::prelude::*;
|
||||
use gtk::{glib, CompositeTemplate};
|
||||
use crate::ui::guessing::game::GuessingScene;
|
||||
use crate::APP_ID;
|
||||
|
||||
use gio::Settings;
|
||||
use glib::subclass::InitializingObject;
|
||||
use gtk::glib::closure_local;
|
||||
use gtk::subclass::prelude::*;
|
||||
use gtk::{gio, glib, prelude::*, Button, CompositeTemplate};
|
||||
|
||||
#[derive(CompositeTemplate, Default)]
|
||||
#[template(resource = "/org/foxarmy/learn-hieroglyph/guessing/setup/ui.xml")]
|
||||
|
@ -17,6 +20,8 @@ pub struct GuessingSetupScene {
|
|||
pub ktr_enable: TemplateChild<LabledSwitch>,
|
||||
#[template_child]
|
||||
pub rtk_enable: TemplateChild<LabledSwitch>,
|
||||
#[template_child]
|
||||
pub start_button: TemplateChild<Button>,
|
||||
}
|
||||
|
||||
#[glib::object_subclass]
|
||||
|
@ -39,6 +44,41 @@ impl ObjectImpl for GuessingSetupScene {
|
|||
self.parent_constructed();
|
||||
|
||||
//TODO: tie switches to settings and make "start" button
|
||||
|
||||
let settings: Settings = Settings::new(APP_ID);
|
||||
|
||||
let hiragana_enable_ref: &LabledSwitch = self.hiragana_enable.as_ref();
|
||||
let hiragana_enable_ref = hiragana_enable_ref.get_switch();
|
||||
settings
|
||||
.bind("is-hiragana-enabled", hiragana_enable_ref, "active")
|
||||
.build();
|
||||
|
||||
let katakana_enable_ref: &LabledSwitch = self.katakana_enable.as_ref();
|
||||
let katakana_enable_ref = katakana_enable_ref.get_switch();
|
||||
settings
|
||||
.bind("is-katakana-enabled", katakana_enable_ref, "active")
|
||||
.build();
|
||||
|
||||
let ktr_enable_ref: &LabledSwitch = self.ktr_enable.as_ref();
|
||||
let ktr_enable_ref = ktr_enable_ref.get_switch();
|
||||
settings
|
||||
.bind("is-ktr-enabled", ktr_enable_ref, "active")
|
||||
.build();
|
||||
|
||||
let rtk_enable_ref: &LabledSwitch = self.rtk_enable.as_ref();
|
||||
let rtk_enable_ref = rtk_enable_ref.get_switch();
|
||||
settings
|
||||
.bind("is-rtk-enabled", rtk_enable_ref, "active")
|
||||
.build();
|
||||
|
||||
let binding = self.obj();
|
||||
|
||||
self.start_button.connect_closure("clicked",
|
||||
false,
|
||||
closure_local!(@strong binding => move |_b: &Button| {
|
||||
let new_win: GuessingScene = GuessingScene::new(&binding.application().unwrap());
|
||||
new_win.present();
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -46,4 +86,4 @@ impl WidgetImpl for GuessingSetupScene {}
|
|||
|
||||
impl WindowImpl for GuessingSetupScene {}
|
||||
|
||||
impl ApplicationWindowImpl for GuessingSetupScene {}
|
||||
impl ApplicationWindowImpl for GuessingSetupScene {}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use crate::ui::{guessing::setup::GuessingSetupScene, cards::setup::MemoryCardsSetupScene};
|
||||
use crate::ui::{cards::setup::MemoryCardsSetupScene, guessing::setup::GuessingSetupScene};
|
||||
|
||||
use glib::subclass::InitializingObject;
|
||||
use gtk::glib::closure_local;
|
||||
|
|
|
@ -1,24 +1,3 @@
|
|||
pub mod menu;
|
||||
pub mod guessing;
|
||||
pub mod cards;
|
||||
|
||||
// use crate::ui::menu::build_menu_scene;
|
||||
|
||||
// use gtk::prelude::*;
|
||||
// use gtk::{Application, ApplicationWindow};
|
||||
// use std::cell::RefCell;
|
||||
|
||||
// pub fn build_ui(app: &Application) {
|
||||
// let mut window: RefCell<ApplicationWindow> = RefCell::new(
|
||||
// ApplicationWindow::builder()
|
||||
// .application(app)
|
||||
// .title("Test")
|
||||
// .build(),
|
||||
// );
|
||||
|
||||
// // let menu = build_menu_scene(&window);
|
||||
|
||||
// // window.get_mut().set_child(Some(&menu));
|
||||
|
||||
// window.get_mut().present();
|
||||
// }
|
||||
pub mod guessing;
|
||||
pub mod menu;
|
||||
|
|
Loading…
Reference in New Issue