monorepo/kifu/gtk/src/ui/new_game.rs

65 lines
1.8 KiB
Rust
Raw Normal View History

2023-05-26 04:16:40 +00:00
use crate::CoreApi;
use glib::Object;
use gtk::{prelude::*, subclass::prelude::*};
use kifu_core::ui::{NewGameView, Player};
use std::{cell::RefCell, rc::Rc};
pub struct NewGamePrivate {
black_player: gtk::Label,
white_player: gtk::Label,
}
impl Default for NewGamePrivate {
fn default() -> Self {
Self {
black_player: gtk::Label::new(None),
white_player: gtk::Label::new(None),
}
}
}
#[glib::object_subclass]
impl ObjectSubclass for NewGamePrivate {
const NAME: &'static str = "NewGame";
type Type = NewGame;
type ParentType = gtk::Grid;
}
impl ObjectImpl for NewGamePrivate {}
impl WidgetImpl for NewGamePrivate {}
impl GridImpl for NewGamePrivate {}
glib::wrapper! {
pub struct NewGame(ObjectSubclass<NewGamePrivate>) @extends gtk::Grid, gtk::Widget;
}
impl NewGame {
pub fn new(_api: CoreApi, view: NewGameView) -> NewGame {
let s: Self = Object::builder().build();
match view.black_player {
Player::Hotseat(player) => {
if let Some(name) = player.name {
s.imp().black_player.set_text(name.as_ref());
}
}
Player::Remote(_) => s.imp().black_player.set_text("remote player"),
Player::Bot(_) => s.imp().black_player.set_text("bot player"),
}
s.attach(&s.imp().black_player, 1, 1, 1, 1);
match view.white_player {
Player::Hotseat(player) => {
if let Some(name) = player.name {
s.imp().white_player.set_text(name.as_ref());
}
}
Player::Remote(_) => s.imp().black_player.set_text("remote player"),
Player::Bot(_) => s.imp().black_player.set_text("bot player"),
}
s.attach(&s.imp().white_player, 2, 1, 1, 1);
s
}
}