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>
|
<property name="label_text">Enable romaji to kana?</property>
|
||||||
</object>
|
</object>
|
||||||
</child>
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkButton" id="start_button">
|
||||||
|
<property name="label">Start!</property>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
</object>
|
</object>
|
||||||
</child>
|
</child>
|
||||||
</template>
|
</template>
|
||||||
|
|
|
@ -37,13 +37,14 @@ impl ObjectImpl for LabledSwitch {
|
||||||
fn constructed(&self) {
|
fn constructed(&self) {
|
||||||
self.parent_constructed();
|
self.parent_constructed();
|
||||||
|
|
||||||
// let a = LayoutManager:: ;
|
|
||||||
|
|
||||||
// self.obj().set_layout_manager(a);
|
|
||||||
|
|
||||||
let l: &Label = self.label_obj.as_ref();
|
let l: &Label = self.label_obj.as_ref();
|
||||||
self.obj().bind_property("label_text", l, "label").sync_create().build();
|
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;
|
mod imp;
|
||||||
|
|
||||||
use glib::Object;
|
use glib::Object;
|
||||||
use gtk::{gio, glib};
|
use gtk::{gio, glib::{self, subclass::types::ObjectSubclassIsExt}, Label, Switch};
|
||||||
|
|
||||||
glib::wrapper! {
|
glib::wrapper! {
|
||||||
pub struct LabledSwitch(ObjectSubclass<imp::LabledSwitch>)
|
pub struct LabledSwitch(ObjectSubclass<imp::LabledSwitch>)
|
||||||
|
@ -14,4 +14,11 @@ impl LabledSwitch {
|
||||||
pub fn new(label: &String) -> Self {
|
pub fn new(label: &String) -> Self {
|
||||||
Object::builder().property("label_text", label).build()
|
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 @@
|
||||||
|
|
|
@ -2,14 +2,13 @@ use glib::subclass::InitializingObject;
|
||||||
use gtk::subclass::prelude::*;
|
use gtk::subclass::prelude::*;
|
||||||
use gtk::{glib, Button, CompositeTemplate};
|
use gtk::{glib, Button, CompositeTemplate};
|
||||||
|
|
||||||
|
|
||||||
#[derive(CompositeTemplate, Default)]
|
#[derive(CompositeTemplate, Default)]
|
||||||
#[template(resource = "/org/foxarmy/learn-hieroglyph/cards/settings/ui.xml")]
|
#[template(resource = "/org/foxarmy/learn-hieroglyph/cards/settings/ui.xml")]
|
||||||
pub struct MemoryCardsSetupScene {
|
pub struct MemoryCardsSetupScene {
|
||||||
#[template_child]
|
#[template_child]
|
||||||
pub edit_button: TemplateChild<Button>,
|
pub edit_button: TemplateChild<Button>,
|
||||||
#[template_child]
|
#[template_child]
|
||||||
pub start_button: TemplateChild<Button>
|
pub start_button: TemplateChild<Button>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[glib::object_subclass]
|
#[glib::object_subclass]
|
||||||
|
@ -29,9 +28,7 @@ impl ObjectSubclass for MemoryCardsSetupScene {
|
||||||
|
|
||||||
impl ObjectImpl for MemoryCardsSetupScene {
|
impl ObjectImpl for MemoryCardsSetupScene {
|
||||||
fn constructed(&self) {
|
fn constructed(&self) {
|
||||||
|
|
||||||
self.parent_constructed();
|
self.parent_constructed();
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,15 +3,14 @@ use std::ops::Deref;
|
||||||
|
|
||||||
use crate::{game::*, APP_ID};
|
use crate::{game::*, APP_ID};
|
||||||
|
|
||||||
use gtk::glib::clone;
|
|
||||||
use gtk::prelude::*;
|
|
||||||
use glib::subclass::InitializingObject;
|
use glib::subclass::InitializingObject;
|
||||||
use gtk::gio::Settings;
|
use gtk::gio::Settings;
|
||||||
|
use gtk::glib::clone;
|
||||||
|
use gtk::prelude::*;
|
||||||
use gtk::subclass::prelude::*;
|
use gtk::subclass::prelude::*;
|
||||||
use gtk::{glib, Label, Entry, CompositeTemplate};
|
use gtk::{glib, CompositeTemplate, Entry, Label};
|
||||||
use rand::Rng;
|
use rand::Rng;
|
||||||
|
|
||||||
|
|
||||||
#[derive(CompositeTemplate, Default)]
|
#[derive(CompositeTemplate, Default)]
|
||||||
#[template(resource = "/org/foxarmy/learn-hieroglyph/guessing/game/ui.xml")]
|
#[template(resource = "/org/foxarmy/learn-hieroglyph/guessing/game/ui.xml")]
|
||||||
pub struct GuessingScene {
|
pub struct GuessingScene {
|
||||||
|
@ -20,7 +19,7 @@ pub struct GuessingScene {
|
||||||
#[template_child]
|
#[template_child]
|
||||||
pub answer_entry: TemplateChild<Entry>,
|
pub answer_entry: TemplateChild<Entry>,
|
||||||
#[template_child]
|
#[template_child]
|
||||||
pub stats_label: TemplateChild<Label>
|
pub stats_label: TemplateChild<Label>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[glib::object_subclass]
|
#[glib::object_subclass]
|
||||||
|
@ -119,7 +118,6 @@ impl ObjectImpl for GuessingScene {
|
||||||
});
|
});
|
||||||
|
|
||||||
self.answer_entry.connect_activate(iteration);
|
self.answer_entry.connect_activate(iteration);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
pub mod setup;
|
|
||||||
pub mod game;
|
pub mod game;
|
||||||
|
pub mod setup;
|
||||||
|
|
|
@ -1,10 +1,13 @@
|
||||||
|
|
||||||
use crate::labled_switch::LabledSwitch;
|
use crate::labled_switch::LabledSwitch;
|
||||||
|
|
||||||
use glib::subclass::InitializingObject;
|
use crate::ui::guessing::game::GuessingScene;
|
||||||
use gtk::subclass::prelude::*;
|
use crate::APP_ID;
|
||||||
use gtk::{glib, CompositeTemplate};
|
|
||||||
|
|
||||||
|
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)]
|
#[derive(CompositeTemplate, Default)]
|
||||||
#[template(resource = "/org/foxarmy/learn-hieroglyph/guessing/setup/ui.xml")]
|
#[template(resource = "/org/foxarmy/learn-hieroglyph/guessing/setup/ui.xml")]
|
||||||
|
@ -17,6 +20,8 @@ pub struct GuessingSetupScene {
|
||||||
pub ktr_enable: TemplateChild<LabledSwitch>,
|
pub ktr_enable: TemplateChild<LabledSwitch>,
|
||||||
#[template_child]
|
#[template_child]
|
||||||
pub rtk_enable: TemplateChild<LabledSwitch>,
|
pub rtk_enable: TemplateChild<LabledSwitch>,
|
||||||
|
#[template_child]
|
||||||
|
pub start_button: TemplateChild<Button>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[glib::object_subclass]
|
#[glib::object_subclass]
|
||||||
|
@ -39,6 +44,41 @@ impl ObjectImpl for GuessingSetupScene {
|
||||||
self.parent_constructed();
|
self.parent_constructed();
|
||||||
|
|
||||||
//TODO: tie switches to settings and make "start" button
|
//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();
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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 glib::subclass::InitializingObject;
|
||||||
use gtk::glib::closure_local;
|
use gtk::glib::closure_local;
|
||||||
|
|
|
@ -1,24 +1,3 @@
|
||||||
pub mod menu;
|
|
||||||
pub mod guessing;
|
|
||||||
pub mod cards;
|
pub mod cards;
|
||||||
|
pub mod guessing;
|
||||||
// use crate::ui::menu::build_menu_scene;
|
pub mod menu;
|
||||||
|
|
||||||
// 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();
|
|
||||||
// }
|
|
||||||
|
|
Loading…
Reference in New Issue