Add a basic rendering for a player card

This commit is contained in:
Savanni D'Gerinel 2023-03-22 10:59:44 -04:00
parent f23d7e9d7e
commit 68096ec743
7 changed files with 123 additions and 45 deletions

View File

@ -3,5 +3,6 @@ use std::time::Duration;
mod api;
pub use api::{CoreApp, Request, Response};
pub mod types;
mod types;
pub use types::Color;
pub mod ui;

View File

@ -1,2 +1,4 @@
pub mod playing_field;
pub mod types;
mod types;
pub use types::PlayerCardElement;

View File

@ -448,6 +448,7 @@ dependencies = [
"glib",
"gtk4",
"kifu-core",
"screenplay",
"tokio",
]
@ -662,6 +663,13 @@ version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd"
[[package]]
name = "screenplay"
version = "0.1.0"
dependencies = [
"gtk4",
]
[[package]]
name = "semver"
version = "1.0.17"

View File

@ -11,3 +11,4 @@ glib = { version = "0.17" }
gtk = { version = "0.6", package = "gtk4" }
kifu-core = { path = "../kifu-core" }
tokio = { version = "1.26", features = [ "full" ] }
screenplay = { path = "../../screenplay" }

View File

@ -0,0 +1,64 @@
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();
}

86
screenplay/Cargo.lock generated
View File

@ -22,9 +22,9 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
[[package]]
name = "cairo-rs"
version = "0.16.7"
version = "0.17.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f3125b15ec28b84c238f6f476c6034016a5f6cc0221cb514ca46c532139fc97d"
checksum = "a8af54f5d48af1226928adc1f57edd22f5df1349e7da1fc96ae15cf43db0e871"
dependencies = [
"bitflags",
"cairo-sys-rs",
@ -36,9 +36,9 @@ dependencies = [
[[package]]
name = "cairo-sys-rs"
version = "0.16.3"
version = "0.17.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7c48f4af05fabdcfa9658178e1326efa061853f040ce7d72e33af6885196f421"
checksum = "f55382a01d30e5e53f185eee269124f5e21ab526595b872751278dfbb463594e"
dependencies = [
"glib-sys",
"libc",
@ -129,22 +129,23 @@ dependencies = [
[[package]]
name = "gdk-pixbuf"
version = "0.16.7"
version = "0.17.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c3578c60dee9d029ad86593ed88cb40f35c1b83360e12498d055022385dd9a05"
checksum = "b023fbe0c6b407bd3d9805d107d9800da3829dc5a676653210f1d5f16d7f59bf"
dependencies = [
"bitflags",
"gdk-pixbuf-sys",
"gio",
"glib",
"libc",
"once_cell",
]
[[package]]
name = "gdk-pixbuf-sys"
version = "0.16.3"
version = "0.17.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3092cf797a5f1210479ea38070d9ae8a5b8e9f8f1be9f32f4643c529c7d70016"
checksum = "7b41bd2b44ed49d99277d3925652a163038bd5ed943ec9809338ffb2f4391e3b"
dependencies = [
"gio-sys",
"glib-sys",
@ -155,9 +156,9 @@ dependencies = [
[[package]]
name = "gdk4"
version = "0.5.5"
version = "0.6.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bb2181330ebf9d091f8ea7fed6877f7adc92114128592e1fdaeb1da28e0d01e9"
checksum = "c3abf96408a26e3eddf881a7f893a1e111767137136e347745e8ea6ed12731ff"
dependencies = [
"bitflags",
"cairo-rs",
@ -171,9 +172,9 @@ dependencies = [
[[package]]
name = "gdk4-sys"
version = "0.5.5"
version = "0.6.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "de55cb49432901fe2b3534177fa06844665b9b0911d85d8601a8d8b88b7791db"
checksum = "1bc92aa1608c089c49393d014c38ac0390d01e4841e1fedaa75dbcef77aaed64"
dependencies = [
"cairo-sys-rs",
"gdk-pixbuf-sys",
@ -188,9 +189,9 @@ dependencies = [
[[package]]
name = "gio"
version = "0.16.7"
version = "0.17.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2a1c84b4534a290a29160ef5c6eff2a9c95833111472e824fc5cb78b513dd092"
checksum = "2261a3b4e922ec676d1c27ac466218c38cf5dcb49a759129e54bb5046e442125"
dependencies = [
"bitflags",
"futures-channel",
@ -208,9 +209,9 @@ dependencies = [
[[package]]
name = "gio-sys"
version = "0.16.3"
version = "0.17.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e9b693b8e39d042a95547fc258a7b07349b1f0b48f4b2fa3108ba3c51c0b5229"
checksum = "6b1d43b0d7968b48455244ecafe41192871257f5740aa6b095eb19db78e362a5"
dependencies = [
"glib-sys",
"gobject-sys",
@ -221,9 +222,9 @@ dependencies = [
[[package]]
name = "glib"
version = "0.16.7"
version = "0.17.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ddd4df61a866ed7259d6189b8bcb1464989a77f1d85d25d002279bbe9dd38b2f"
checksum = "cfb53061756195d76969292c2d2e329e01259276524a9bae6c9b73af62854773"
dependencies = [
"bitflags",
"futures-channel",
@ -236,6 +237,7 @@ dependencies = [
"glib-sys",
"gobject-sys",
"libc",
"memchr",
"once_cell",
"smallvec",
"thiserror",
@ -243,9 +245,9 @@ dependencies = [
[[package]]
name = "glib-macros"
version = "0.16.3"
version = "0.17.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e084807350b01348b6d9dbabb724d1a0bb987f47a2c85de200e98e12e30733bf"
checksum = "454924cafe58d9174dc32972261fe271d6cd3c10f5e9ff505522a28dcf601a40"
dependencies = [
"anyhow",
"heck",
@ -258,9 +260,9 @@ dependencies = [
[[package]]
name = "glib-sys"
version = "0.16.3"
version = "0.17.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c61a4f46316d06bfa33a7ac22df6f0524c8be58e3db2d9ca99ccb1f357b62a65"
checksum = "49f00ad0a1bf548e61adfff15d83430941d9e1bb620e334f779edd1c745680a5"
dependencies = [
"libc",
"system-deps",
@ -268,9 +270,9 @@ dependencies = [
[[package]]
name = "gobject-sys"
version = "0.16.3"
version = "0.17.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3520bb9c07ae2a12c7f2fbb24d4efc11231c8146a86956413fb1a79bb760a0f1"
checksum = "15e75b0000a64632b2d8ca3cf856af9308e3a970844f6e9659bd197f026793d0"
dependencies = [
"glib-sys",
"libc",
@ -279,9 +281,9 @@ dependencies = [
[[package]]
name = "graphene-rs"
version = "0.16.3"
version = "0.17.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "95ecb4d347e6d09820df3bdfd89a74a8eec07753a06bb92a3aac3ad31d04447b"
checksum = "21cf11565bb0e4dfc2f99d4775b6c329f0d40a2cff9c0066214d31a0e1b46256"
dependencies = [
"glib",
"graphene-sys",
@ -290,9 +292,9 @@ dependencies = [
[[package]]
name = "graphene-sys"
version = "0.16.3"
version = "0.17.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b9aa82337d3972b4eafdea71e607c23f47be6f27f749aab613f1ad8ddbe6dcd6"
checksum = "cf80a4849a8d9565410a8fec6fc3678e9c617f4ac7be182ca55ab75016e07af9"
dependencies = [
"glib-sys",
"libc",
@ -302,9 +304,9 @@ dependencies = [
[[package]]
name = "gsk4"
version = "0.5.5"
version = "0.6.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "591239f5c52ca803b222124ac9c47f230cd180cee9b114c4d672e4a94b74f491"
checksum = "6f01ef44fa7cac15e2da9978529383e6bee03e570ba5bf7036b4c10a15cc3a3c"
dependencies = [
"bitflags",
"cairo-rs",
@ -318,9 +320,9 @@ dependencies = [
[[package]]
name = "gsk4-sys"
version = "0.5.5"
version = "0.6.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "195a63f0be42529f98c3eb3bae0decfd0428ba2cc683b3e20ced88f340904ec5"
checksum = "c07a84fb4dcf1323d29435aa85e2f5f58bef564342bef06775ec7bd0da1f01b0"
dependencies = [
"cairo-sys-rs",
"gdk4-sys",
@ -334,9 +336,9 @@ dependencies = [
[[package]]
name = "gtk4"
version = "0.5.5"
version = "0.6.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fd89dba65def483a233dc4fdd3f3dab01576e3d83f80f6c9303ebe421661855e"
checksum = "1e30e124b5a605f6f5513db13958bfcd51d746607b20bc7bb718b33e303274ed"
dependencies = [
"bitflags",
"cairo-rs",
@ -357,9 +359,9 @@ dependencies = [
[[package]]
name = "gtk4-macros"
version = "0.5.5"
version = "0.6.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "832687a415d9d8bc11fe9c17dda1bf13ee262c41b995dd4df1d1cce33cead405"
checksum = "30e21acdeb9a02b8cba83e65afbb8aa45f977785e50f1113407024c6b6256988"
dependencies = [
"anyhow",
"proc-macro-crate",
@ -371,9 +373,9 @@ dependencies = [
[[package]]
name = "gtk4-sys"
version = "0.5.5"
version = "0.6.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e370564e3fdacff7cffc99f7366b6a4689feb44e819d3ccee598a9a215b71605"
checksum = "5f8283f707b07e019e76c7f2934bdd4180c277e08aa93f4c0d8dd07b7a34e22f"
dependencies = [
"cairo-sys-rs",
"gdk-pixbuf-sys",
@ -439,9 +441,9 @@ checksum = "b7e5500299e16ebb147ae15a00a942af264cf3688f47923b8fc2cd5858f23ad3"
[[package]]
name = "pango"
version = "0.16.5"
version = "0.17.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cdff66b271861037b89d028656184059e03b0b6ccb36003820be19f7200b1e94"
checksum = "52c280b82a881e4208afb3359a8e7fde27a1b272280981f1f34610bed5770d37"
dependencies = [
"bitflags",
"gio",
@ -453,9 +455,9 @@ dependencies = [
[[package]]
name = "pango-sys"
version = "0.16.3"
version = "0.17.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9e134909a9a293e04d2cc31928aa95679c5e4df954d0b85483159bd20d8f047f"
checksum = "4293d0f0b5525eb5c24734d30b0ed02cd02aa734f216883f376b54de49625de8"
dependencies = [
"glib-sys",
"gobject-sys",

View File

@ -7,4 +7,4 @@ license = "GPL-3.0-only"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
gtk = { version = "0.5", package = "gtk4" }
gtk = { version = "0.6", package = "gtk4" }