some shitty ui

This commit is contained in:
leca 2024-03-22 15:59:42 +03:00
parent 2854f41437
commit b77dea3cd1
1 changed files with 135 additions and 2 deletions

View File

@ -1,3 +1,136 @@
fn main() { mod game;
println!("Hello, world!");
use std::cell::RefCell;
use gtk::glib::clone;
use gtk::{prelude::*, EditableLabel, Label, Switch};
use gtk::{glib, Application, ApplicationWindow, Button, Box};
use crate::game::*;
const APP_ID: &str = "org.foxarmy.learn-hieroglyphs";
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()
}
fn build_menu(w: &RefCell<ApplicationWindow>) -> Box {
let romaji_to_kana = Button::builder()
.label("a->あ")
.margin_top(12)
.margin_end(48)
.build();
let kana_to_romaji = Button::builder()
.label("あ->a")
.margin_top(12)
.margin_end(12)
.margin_start(48)
.build();
let hiragana_switch: Switch = Switch::builder()
.name("enable hiragana")
.valign(gtk::Align::End)
.build();
let hiragana_label: Label = Label::builder()
.label("Enable hiragana")
.margin_start(12)
.build();
let katakana_switch: Switch = Switch::builder()
.name("enable katakana")
.build();
let katakana_label: Label = Label::builder()
.label("Enable katakana")
.margin_start(12)
.build();
let menu: Box = Box::builder()
.orientation(gtk::Orientation::Vertical)
.halign(gtk::Align::Center)
.build();
let kanas_buttons: Box = Box::builder()
.orientation(gtk::Orientation::Horizontal)
.build();
let kanas_settings: Box = Box::builder()
.orientation(gtk::Orientation::Vertical)
.valign(gtk::Align::Center)
.halign(gtk::Align::Center)
.build();
let hiragana_setting: Box = Box::builder()
.orientation(gtk::Orientation::Horizontal)
.valign(gtk::Align::Center)
.halign(gtk::Align::Center)
.build();
let katakana_setting: Box = Box::builder()
.orientation(gtk::Orientation::Horizontal)
.valign(gtk::Align::Center)
.halign(gtk::Align::Center)
.build();
kanas_buttons.append(&romaji_to_kana);
kanas_buttons.append(&kana_to_romaji);
hiragana_setting.append(&hiragana_switch);
hiragana_setting.append(&hiragana_label);
katakana_setting.append(&katakana_switch);
katakana_setting.append(&katakana_label);
kanas_settings.append(&hiragana_setting);
kanas_settings.append(&katakana_setting);
menu.append(&kanas_buttons);
menu.append(&kanas_settings);
kana_to_romaji.connect_clicked(clone!( @strong w => move |_button: &Button| {
w.borrow_mut().set_child(Some(&build_game(&w)));
}));
romaji_to_kana.connect_clicked(clone!( @strong w => move |_button: &Button| {
w.borrow_mut().set_child(Some(&build_game(&w)));
}));
menu
}
fn build_game(w: &RefCell<ApplicationWindow>) -> Box {
let game: Box = Box::builder()
.orientation(gtk::Orientation::Vertical)
.build();
let question_label: Label = Label::builder()
.label("placeholder")
.build();
let entry: EditableLabel = EditableLabel::builder()
.text("test")
.build();
game.append(&question_label);
game.append(&entry);
game
}
fn build_ui(app: &Application) {
let mut window: RefCell<ApplicationWindow> = RefCell::new(ApplicationWindow::builder()
.application(app)
.title("Test")
.default_height(920)
.default_width(480)
.build());
let menu = build_menu(&window);
window.get_mut().set_child(Some(&menu));
window.get_mut().present();
} }