Show a list of games in the library #64

Merged
savanni merged 9 commits from kifu/game-library into main 2023-08-20 17:02:14 +00:00
2 changed files with 24 additions and 17 deletions
Showing only changes of commit a584fb4de3 - Show all commits

View File

@ -13,8 +13,8 @@ fn handle_response(api: CoreApi, window: gtk::ApplicationWindow, message: CoreRe
CoreResponse::HomeView(view) => perftrace("HomeView", || {
let api = api.clone();
let new_game = Home::new(api, view);
window.set_child(Some(&new_game));
let home = Home::new(api, view);
window.set_child(Some(&home));
}),
CoreResponse::PlayingFieldView(view) => perftrace("PlayingFieldView", || {
let api = api.clone();

View File

@ -1,14 +1,11 @@
use crate::{ui::GamePreview, CoreApi};
use glib::{Object, Properties};
use crate::CoreApi;
use glib::Object;
use gtk::{glib, prelude::*, subclass::prelude::*};
use kifu_core::{
ui::{GamePreviewElement, HomeView, PlayerElement},
ui::{HomeView, PlayerElement},
CoreRequest, CreateGameRequest, HotseatPlayerRequest, PlayerInfoRequest,
};
use std::{
cell::{Cell, RefCell},
rc::Rc,
};
use std::{cell::RefCell, rc::Rc};
use super::GameDatabase;
@ -105,39 +102,49 @@ impl Default for HomePrivate {
impl ObjectSubclass for HomePrivate {
const NAME: &'static str = "Home";
type Type = Home;
type ParentType = gtk::Grid;
type ParentType = gtk::Box;
}
impl ObjectImpl for HomePrivate {}
impl WidgetImpl for HomePrivate {}
impl GridImpl for HomePrivate {}
impl BoxImpl for HomePrivate {}
glib::wrapper! {
pub struct Home(ObjectSubclass<HomePrivate>) @extends gtk::Grid, gtk::Widget;
pub struct Home(ObjectSubclass<HomePrivate>) @extends gtk::Box, gtk::Widget, @implements gtk::Orientable;
}
impl Home {
pub fn new(api: CoreApi, view: HomeView) -> Home {
let s: Self = Object::builder().build();
s.set_spacing(4);
s.set_homogeneous(false);
s.set_orientation(gtk::Orientation::Vertical);
let players = gtk::Box::builder()
.spacing(4)
.orientation(gtk::Orientation::Horizontal)
.build();
s.append(&players);
let black_player = PlayerDataEntry::new(view.black_player);
s.attach(&black_player, 1, 1, 1, 1);
players.append(&black_player);
*s.imp().black_player.borrow_mut() = Some(black_player.clone());
let white_player = PlayerDataEntry::new(view.white_player);
s.attach(&white_player, 2, 1, 1, 1);
players.append(&white_player);
*s.imp().white_player.borrow_mut() = Some(white_player.clone());
let new_game_button = gtk::Button::builder().label(&view.start_game.label).build();
s.attach(&new_game_button, 2, 2, 1, 1);
s.append(&new_game_button);
let library = GameDatabase::new();
let library_view = gtk::ScrolledWindow::builder()
.hscrollbar_policy(gtk::PolicyType::Never)
.min_content_width(360)
.vexpand(true)
.hexpand(true)
.child(&library)
.build();
s.attach(&library_view, 0, 3, 4, 2);
s.append(&library_view);
library.set_games(view.games);