Set up a configuration UI #66

Merged
savanni merged 7 commits from kifu/configuration into main 2023-08-25 01:08:33 +00:00
3 changed files with 25 additions and 5 deletions
Showing only changes of commit cc3ad372e6 - Show all commits

1
Cargo.lock generated
View File

@ -1348,6 +1348,7 @@ dependencies = [
"gtk4",
"image",
"kifu-core",
"libadwaita",
"sgf",
"tokio",
]

View File

@ -9,6 +9,7 @@ screenplay = []
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
adw = { version = "0.4", package = "libadwaita", features = [ "v1_2" ] }
cairo-rs = { version = "0.17" }
gio = { version = "0.17" }
glib = { version = "0.17" }

View File

@ -1,3 +1,4 @@
use adw::prelude::AdwApplicationWindowExt;
use gtk::prelude::*;
use kifu_core::{CoreApp, CoreRequest, CoreResponse};
use kifu_gtk::{
@ -7,14 +8,14 @@ use kifu_gtk::{
};
use std::sync::{Arc, RwLock};
fn handle_response(api: CoreApi, window: gtk::ApplicationWindow, message: CoreResponse) {
fn handle_response(api: CoreApi, window: adw::ApplicationWindow, message: CoreResponse) {
let playing_field = Arc::new(RwLock::new(None));
match message {
CoreResponse::HomeView(view) => perftrace("HomeView", || {
let api = api.clone();
let home = Home::new(api, view);
window.set_child(Some(&home));
window.set_content(Some(&home));
}),
CoreResponse::PlayingFieldView(view) => perftrace("PlayingFieldView", || {
let api = api.clone();
@ -23,7 +24,7 @@ fn handle_response(api: CoreApi, window: gtk::ApplicationWindow, message: CoreRe
if playing_field.is_none() {
perftrace("creating a new playing field", || {
let field = PlayingField::new(api, view);
window.set_child(Some(&field));
window.set_content(Some(&field));
*playing_field = Some(field);
})
} else {
@ -65,10 +66,25 @@ fn main() {
}
});
let app = gtk::Application::builder()
let app = adw::Application::builder()
.application_id("com.luminescent-dreams.kifu-gtk")
.resource_base_path("/com/luminescent-dreams/kifu-gtk")
.build();
let action_config = gio::SimpleAction::new("show-config", None);
action_config.connect_activate(|_, _| {
println!("trigger the configuration menu");
});
app.add_action(&action_config);
app.connect_startup(|app| {
println!("connect_startup");
let menu_model = gio::Menu::new();
menu_model.append(Some("Quit"), None);
menu_model.append(Some("Configuration"), Some("show-config"));
app.set_menubar(Some(&menu_model));
});
app.connect_activate({
let runtime = runtime.clone();
move |app| {
@ -81,9 +97,11 @@ fn main() {
core: core.clone(),
};
let window = gtk::ApplicationWindow::new(app);
let window = adw::ApplicationWindow::new(app);
window.present();
window.set_show_menubar(true);
gtk_rx.attach(None, {
let api = api.clone();
move |message| {