65 lines
1.8 KiB
Rust
65 lines
1.8 KiB
Rust
|
use glib::Object;
|
||
|
use gtk::{prelude::*, subclass::prelude::*};
|
||
|
use kifu_core::{ui::PlayerCardElement, Color};
|
||
|
use screenplay::{Screen, Screenplay};
|
||
|
use std::{cell::RefCell, rc::Rc};
|
||
|
|
||
|
#[derive(Default)]
|
||
|
pub struct PlayerCardPrivate {
|
||
|
player_name: gtk::Label,
|
||
|
clock: gtk::Label,
|
||
|
}
|
||
|
|
||
|
#[glib::object_subclass]
|
||
|
impl ObjectSubclass for PlayerCardPrivate {
|
||
|
const NAME: &'static str = "PlayerCard";
|
||
|
type Type = PlayerCard;
|
||
|
type ParentType = gtk::Box;
|
||
|
}
|
||
|
|
||
|
impl ObjectImpl for PlayerCardPrivate {}
|
||
|
impl WidgetImpl for PlayerCardPrivate {}
|
||
|
impl BoxImpl for PlayerCardPrivate {}
|
||
|
|
||
|
glib::wrapper! {
|
||
|
pub struct PlayerCard(ObjectSubclass<PlayerCardPrivate>) @extends gtk::Box, gtk::Widget, @implements gtk::Orientable;
|
||
|
}
|
||
|
|
||
|
impl PlayerCard {
|
||
|
pub fn new(element: PlayerCardElement) -> PlayerCard {
|
||
|
let s: Self = Object::builder().build();
|
||
|
s.set_orientation(gtk::Orientation::Vertical);
|
||
|
s.imp()
|
||
|
.player_name
|
||
|
.set_text(&format!("{} ({})", element.name, element.rank));
|
||
|
s.imp().clock.set_text(&element.clock);
|
||
|
|
||
|
s.append(&s.imp().player_name);
|
||
|
s.append(&s.imp().clock);
|
||
|
s
|
||
|
}
|
||
|
}
|
||
|
|
||
|
fn main() {
|
||
|
let app = gtk::Application::builder()
|
||
|
.application_id("com.luminescent-dreams.kifu-gtk.screenplay")
|
||
|
.build();
|
||
|
|
||
|
app.connect_activate(|app| {
|
||
|
let screens = vec![Screen {
|
||
|
title: "PlayerCard".to_owned(),
|
||
|
widget: PlayerCard::new(PlayerCardElement {
|
||
|
color: Color::Black,
|
||
|
name: "Opal".to_owned(),
|
||
|
rank: "10 kyu".to_owned(),
|
||
|
clock: "25:00".to_owned(),
|
||
|
})
|
||
|
.upcast::<gtk::Widget>(),
|
||
|
adjustments: vec![],
|
||
|
}];
|
||
|
let screenplay = Screenplay::new(&app, screens).unwrap();
|
||
|
});
|
||
|
|
||
|
app.run();
|
||
|
}
|