some renaming, creating GuessingSetup scene and LabledSwitch

This commit is contained in:
leca 2024-04-02 01:32:41 +03:00
parent e0ef46d0b8
commit 1da36b93d1
18 changed files with 146 additions and 70 deletions

View File

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<template class="GuessingSetupScene" parent="GtkApplicationWindow">
<property name="title">Guessing settings</property>
<child>
<object class="GtkBox" id="content">
<property name="orientation">vertical</property>
<child>
<object class="LabledSwitch" id="hiragana-enable">
<!-- <property name="label_text">Enable hiragana?</property> -->
</object>
</child>
</object>
</child>
</template>
</interface>

View File

@ -1,14 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<gresources>
<gresource prefix="/org/foxarmy/learn-hieroglyph/">
<file compressed="true" preprocess="xml-stripblanks">org.foxarmy.settings.gschema.xml</file>
<file compressed="true" preprocess="xml-stripblanks">menu/ui.xml</file>
<file compressed="true" preprocess="xml-stripblanks">guessing/game/ui.xml</file>
<!-- <file compressed="true" preprocess="xml-stripblanks">guessing/settings/ui.xml</file> -->
<file compressed="true" preprocess="xml-stripblanks">cards/settings/ui.xml</file>
<file compressed="true" preprocess="xml-stripblanks">guessing/setup/ui.xml</file>
<!-- <file compressed="true" preprocess="xml-stripblanks">cards/game/ui.xml</file> -->
<file compressed="true" preprocess="xml-stripblanks">cards/setup/ui.xml</file>
<file compressed="true" preprocess="xml-stripblanks">widgets/labled_switch/template.ui.xml</file>
</gresource>
</gresources>

View File

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<template class="LabledSwitch" parent="GtkWidget">
<!-- <property name="layout-managet">GtkBoxLayout</property> -->
<property name="label_text">Practice vocabulary with memory cards</property>
<child>
<object class="GtkSwitch" id="switch_obj">
</object>
</child>
<child>
<object class="GtkLabel" id="label_obj">
<property name="label">There's a question:</property>
</object>
</child>
</template>
</interface>

View File

@ -1,22 +1,44 @@
use gtk::glib;
use std::cell::RefCell;
use glib::subclass::InitializingObject;
use glib::Properties;
use gtk::subclass::prelude::*;
use gtk::{glib, prelude::*, CompositeTemplate, Label, Switch};
// Object holding the state
#[derive(Default)]
pub struct LabledSwitch;
#[derive(CompositeTemplate, Properties, Default)]
#[properties(wrapper_type = super::LabledSwitch)]
#[template(resource = "/org/foxarmy/learn-hieroglyph/widgets/labled_switch/template.ui.xml")]
pub struct LabledSwitch {
#[template_child]
pub switch_obj: TemplateChild<Switch>,
#[template_child]
pub label_obj: TemplateChild<Label>,
#[property(get, set)]
label_text: RefCell<String>,
}
// The central trait for subclassing a GObject
#[glib::object_subclass]
impl ObjectSubclass for LabledSwitch {
const NAME: &'static str = "LabledSwitch";
type Type = super::LabledSwitch;
type ParentType = gtk::Widget;
fn class_init(klass: &mut Self::Class) {
klass.bind_template();
}
impl ObjectImpl for LabledSwitch {}
fn instance_init(obj: &InitializingObject<Self>) {
obj.init_template();
}
}
impl ObjectImpl for LabledSwitch {
fn constructed(&self) {
self.parent_constructed();
let l: &Label = self.label_obj.as_ref();
self.obj().bind_property("label_text", l, "label").sync_create().build();
}
}
impl WidgetImpl for LabledSwitch {}
impl ButtonImpl for LabledSwitch {}
// impl IsSubclassable for LabledSwitch {}

View File

@ -1,45 +1,17 @@
// mod imp;
mod imp;
// use glib::Object;
// use gtk::glib;
use glib::Object;
use gtk::{gio, glib};
// glib::wrapper! {
// pub struct LabledSwitch(ObjectSubclass<imp::LabledSwitch>)
// @extends gtk::Widget,
// @implements gtk::Accessible, gtk::Actionable, gtk::Buildable, gtk::ConstraintTarget;
// }
glib::wrapper! {
pub struct LabledSwitch(ObjectSubclass<imp::LabledSwitch>)
@extends gtk::Widget,
@implements gio::ActionGroup, gio::ActionMap, gtk::Accessible, gtk::Buildable,
gtk::ConstraintTarget, gtk::Native, gtk::Root, gtk::ShortcutManager;
}
// impl LabledSwitch {
// pub fn new() -> Self {
// Object::builder().build()
// }
// pub fn with_label(label: &str) -> Self {
// Object::builder().property("label", label).build()
// }
// }
// // use gtk::{prelude::*, Box, Label, Switch};
// // pub fn build(text: &str) -> (Box, Switch, Label) {
// // let switch: Switch = Switch::builder()
// // .valign(gtk::Align::Start)
// // .halign(gtk::Align::Center)
// // .build();
// // let label: Label = Label::builder()
// // .valign(gtk::Align::End)
// // .halign(gtk::Align::BaselineCenter)
// // .label(text)
// // .build();
// // let container = Box::builder()
// // .orientation(gtk::Orientation::Horizontal)
// // .build();
// // container.append(&switch);
// // container.append(&label);
// // (container, switch, label)
// // }
impl LabledSwitch {
pub fn new(label: &String) -> Self {
Object::builder().property("label_text", label).build()
}
}

View File

@ -4,14 +4,12 @@ mod ui;
use crate::ui::menu::MenuScene;
use gio::Settings;
use gtk::{prelude::*, ApplicationWindow};
use gtk::{glib, Application, gio};
const APP_ID: &str = "org.foxarmy.learn-hieroglyph";
fn main() -> glib::ExitCode {
print!("cargo:rerun-if-changed=build.rs");
gio::resources_register_include!("compiled.gresource")
.expect("Cannot include gresources");
@ -19,17 +17,11 @@ fn main() -> glib::ExitCode {
app.connect_activate(test_ui);
app.run()
}
fn test_ui (app: &Application) {
let window: ApplicationWindow = MenuScene::new(app).into();
let settings = Settings::new(APP_ID);
println!("{}", settings.boolean("is-ktr-enabled"));
println!("{}", settings.boolean("is-ktr-enabled"));
window.present();
}

View File

@ -1,3 +1,3 @@
pub mod edit;
pub mod game;
pub mod settings;
pub mod setup;

View File

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

View File

@ -0,0 +1,41 @@
use crate::labled_switch::LabledSwitch;
use glib::subclass::InitializingObject;
use gtk::subclass::prelude::*;
use gtk::{glib, CompositeTemplate};
#[derive(CompositeTemplate, Default)]
#[template(resource = "/org/foxarmy/learn-hieroglyph/guessing/setup/ui.xml")]
pub struct GuessingSetupScene {
#[template_child]
pub question_label: TemplateChild<LabledSwitch>,
}
#[glib::object_subclass]
impl ObjectSubclass for GuessingSetupScene {
const NAME: &'static str = "GuessingSetupScene";
type Type = super::GuessingSetupScene;
type ParentType = gtk::ApplicationWindow;
fn class_init(klass: &mut Self::Class) {
klass.bind_template();
}
fn instance_init(obj: &InitializingObject<Self>) {
obj.init_template();
}
}
impl ObjectImpl for GuessingSetupScene {
fn constructed(&self) {
self.parent_constructed();
}
}
impl WidgetImpl for GuessingSetupScene {}
impl WindowImpl for GuessingSetupScene {}
impl ApplicationWindowImpl for GuessingSetupScene {}

View File

@ -0,0 +1,17 @@
mod imp;
use glib::Object;
use gtk::{gio, glib, Application};
glib::wrapper! {
pub struct GuessingSetupScene(ObjectSubclass<imp::GuessingSetupScene>)
@extends gtk::ApplicationWindow, gtk::Window, gtk::Widget,
@implements gio::ActionGroup, gio::ActionMap, gtk::Accessible, gtk::Buildable,
gtk::ConstraintTarget, gtk::Native, gtk::Root, gtk::ShortcutManager;
}
impl GuessingSetupScene {
pub fn new(app: &Application) -> Self {
Object::builder().property("application", app).build()
}
}

View File

@ -1,4 +1,4 @@
use crate::ui::{guessing::game::GuessingScene, cards::settings::MemoryCardsSetupScene};
use crate::ui::{guessing::setup::GuessingSetupScene, cards::setup::MemoryCardsSetupScene};
use glib::subclass::InitializingObject;
use gtk::glib::closure_local;
@ -41,7 +41,7 @@ impl ObjectImpl for MenuScene {
"clicked",
false,
closure_local!(@strong binding => move |_button: &Button| {
let new_win: GuessingScene = GuessingScene::new(&binding.application().unwrap());
let new_win: GuessingSetupScene = GuessingSetupScene::new(&binding.application().unwrap());
new_win.present();
}),
);

View File

@ -1,6 +1,6 @@
pub(crate) mod menu;
pub(crate) mod guessing;
mod cards;
pub mod menu;
pub mod guessing;
pub mod cards;
// use crate::ui::menu::build_menu_scene;