guessing is completed

This commit is contained in:
leca 2024-04-02 15:23:56 +03:00
parent b01e248971
commit 3e4a55f33f
12 changed files with 82 additions and 53 deletions

View File

@ -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>

View File

@ -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 { }

View File

@ -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()
}
}

View File

@ -0,0 +1 @@

View File

@ -0,0 +1 @@

View File

@ -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();
}
}

View File

@ -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]
@ -119,7 +118,6 @@ impl ObjectImpl for GuessingScene {
});
self.answer_entry.connect_activate(iteration);
}
}

View File

@ -1,2 +1,2 @@
pub mod setup;
pub mod game;
pub mod setup;

View File

@ -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();
}));
}
}

View File

@ -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;

View File

@ -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;