From 44171393ef186cda8917c734e087a74d73f283ef Mon Sep 17 00:00:00 2001 From: Savanni D'Gerinel Date: Tue, 21 Mar 2023 09:44:52 -0400 Subject: [PATCH 1/3] Create the screenplay library This is a library that helps out with visualizing GTK scenes --- screenplay/Cargo.lock | 707 ++++++++++++++++++++++++++++++++++++++++++ screenplay/Cargo.toml | 10 + screenplay/src/lib.rs | 116 +++++++ 3 files changed, 833 insertions(+) create mode 100644 screenplay/Cargo.lock create mode 100644 screenplay/Cargo.toml create mode 100644 screenplay/src/lib.rs diff --git a/screenplay/Cargo.lock b/screenplay/Cargo.lock new file mode 100644 index 0000000..79ae3eb --- /dev/null +++ b/screenplay/Cargo.lock @@ -0,0 +1,707 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "anyhow" +version = "1.0.70" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7de8ce5e0f9f8d88245311066a578d72b7af3e7088f32783804676302df237e4" + +[[package]] +name = "autocfg" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" + +[[package]] +name = "bitflags" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" + +[[package]] +name = "cairo-rs" +version = "0.16.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3125b15ec28b84c238f6f476c6034016a5f6cc0221cb514ca46c532139fc97d" +dependencies = [ + "bitflags", + "cairo-sys-rs", + "glib", + "libc", + "once_cell", + "thiserror", +] + +[[package]] +name = "cairo-sys-rs" +version = "0.16.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7c48f4af05fabdcfa9658178e1326efa061853f040ce7d72e33af6885196f421" +dependencies = [ + "glib-sys", + "libc", + "system-deps", +] + +[[package]] +name = "cfg-expr" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b0357a6402b295ca3a86bc148e84df46c02e41f41fef186bda662557ef6328aa" +dependencies = [ + "smallvec", +] + +[[package]] +name = "field-offset" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a3cf3a800ff6e860c863ca6d4b16fd999db8b752819c1606884047b73e468535" +dependencies = [ + "memoffset", + "rustc_version", +] + +[[package]] +name = "futures-channel" +version = "0.3.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "164713a5a0dcc3e7b4b1ed7d3b433cabc18025386f9339346e8daf15963cf7ac" +dependencies = [ + "futures-core", +] + +[[package]] +name = "futures-core" +version = "0.3.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86d7a0c1aa76363dac491de0ee99faf6941128376f1cf96f07db7603b7de69dd" + +[[package]] +name = "futures-executor" +version = "0.3.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1997dd9df74cdac935c76252744c1ed5794fac083242ea4fe77ef3ed60ba0f83" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-io" +version = "0.3.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "89d422fa3cbe3b40dca574ab087abb5bc98258ea57eea3fd6f1fa7162c778b91" + +[[package]] +name = "futures-macro" +version = "0.3.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3eb14ed937631bd8b8b8977f2c198443447a8355b6e3ca599f38c975e5a963b6" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "futures-task" +version = "0.3.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd65540d33b37b16542a0438c12e6aeead10d4ac5d05bd3f805b8f35ab592879" + +[[package]] +name = "futures-util" +version = "0.3.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3ef6b17e481503ec85211fed8f39d1970f128935ca1f814cd32ac4a6842e84ab" +dependencies = [ + "futures-core", + "futures-macro", + "futures-task", + "pin-project-lite", + "pin-utils", + "slab", +] + +[[package]] +name = "gdk-pixbuf" +version = "0.16.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3578c60dee9d029ad86593ed88cb40f35c1b83360e12498d055022385dd9a05" +dependencies = [ + "bitflags", + "gdk-pixbuf-sys", + "gio", + "glib", + "libc", +] + +[[package]] +name = "gdk-pixbuf-sys" +version = "0.16.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3092cf797a5f1210479ea38070d9ae8a5b8e9f8f1be9f32f4643c529c7d70016" +dependencies = [ + "gio-sys", + "glib-sys", + "gobject-sys", + "libc", + "system-deps", +] + +[[package]] +name = "gdk4" +version = "0.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb2181330ebf9d091f8ea7fed6877f7adc92114128592e1fdaeb1da28e0d01e9" +dependencies = [ + "bitflags", + "cairo-rs", + "gdk-pixbuf", + "gdk4-sys", + "gio", + "glib", + "libc", + "pango", +] + +[[package]] +name = "gdk4-sys" +version = "0.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "de55cb49432901fe2b3534177fa06844665b9b0911d85d8601a8d8b88b7791db" +dependencies = [ + "cairo-sys-rs", + "gdk-pixbuf-sys", + "gio-sys", + "glib-sys", + "gobject-sys", + "libc", + "pango-sys", + "pkg-config", + "system-deps", +] + +[[package]] +name = "gio" +version = "0.16.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a1c84b4534a290a29160ef5c6eff2a9c95833111472e824fc5cb78b513dd092" +dependencies = [ + "bitflags", + "futures-channel", + "futures-core", + "futures-io", + "futures-util", + "gio-sys", + "glib", + "libc", + "once_cell", + "pin-project-lite", + "smallvec", + "thiserror", +] + +[[package]] +name = "gio-sys" +version = "0.16.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e9b693b8e39d042a95547fc258a7b07349b1f0b48f4b2fa3108ba3c51c0b5229" +dependencies = [ + "glib-sys", + "gobject-sys", + "libc", + "system-deps", + "winapi", +] + +[[package]] +name = "glib" +version = "0.16.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ddd4df61a866ed7259d6189b8bcb1464989a77f1d85d25d002279bbe9dd38b2f" +dependencies = [ + "bitflags", + "futures-channel", + "futures-core", + "futures-executor", + "futures-task", + "futures-util", + "gio-sys", + "glib-macros", + "glib-sys", + "gobject-sys", + "libc", + "once_cell", + "smallvec", + "thiserror", +] + +[[package]] +name = "glib-macros" +version = "0.16.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e084807350b01348b6d9dbabb724d1a0bb987f47a2c85de200e98e12e30733bf" +dependencies = [ + "anyhow", + "heck", + "proc-macro-crate", + "proc-macro-error", + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "glib-sys" +version = "0.16.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c61a4f46316d06bfa33a7ac22df6f0524c8be58e3db2d9ca99ccb1f357b62a65" +dependencies = [ + "libc", + "system-deps", +] + +[[package]] +name = "gobject-sys" +version = "0.16.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3520bb9c07ae2a12c7f2fbb24d4efc11231c8146a86956413fb1a79bb760a0f1" +dependencies = [ + "glib-sys", + "libc", + "system-deps", +] + +[[package]] +name = "graphene-rs" +version = "0.16.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95ecb4d347e6d09820df3bdfd89a74a8eec07753a06bb92a3aac3ad31d04447b" +dependencies = [ + "glib", + "graphene-sys", + "libc", +] + +[[package]] +name = "graphene-sys" +version = "0.16.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9aa82337d3972b4eafdea71e607c23f47be6f27f749aab613f1ad8ddbe6dcd6" +dependencies = [ + "glib-sys", + "libc", + "pkg-config", + "system-deps", +] + +[[package]] +name = "gsk4" +version = "0.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "591239f5c52ca803b222124ac9c47f230cd180cee9b114c4d672e4a94b74f491" +dependencies = [ + "bitflags", + "cairo-rs", + "gdk4", + "glib", + "graphene-rs", + "gsk4-sys", + "libc", + "pango", +] + +[[package]] +name = "gsk4-sys" +version = "0.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "195a63f0be42529f98c3eb3bae0decfd0428ba2cc683b3e20ced88f340904ec5" +dependencies = [ + "cairo-sys-rs", + "gdk4-sys", + "glib-sys", + "gobject-sys", + "graphene-sys", + "libc", + "pango-sys", + "system-deps", +] + +[[package]] +name = "gtk4" +version = "0.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd89dba65def483a233dc4fdd3f3dab01576e3d83f80f6c9303ebe421661855e" +dependencies = [ + "bitflags", + "cairo-rs", + "field-offset", + "futures-channel", + "gdk-pixbuf", + "gdk4", + "gio", + "glib", + "graphene-rs", + "gsk4", + "gtk4-macros", + "gtk4-sys", + "libc", + "once_cell", + "pango", +] + +[[package]] +name = "gtk4-macros" +version = "0.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "832687a415d9d8bc11fe9c17dda1bf13ee262c41b995dd4df1d1cce33cead405" +dependencies = [ + "anyhow", + "proc-macro-crate", + "proc-macro-error", + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "gtk4-sys" +version = "0.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e370564e3fdacff7cffc99f7366b6a4689feb44e819d3ccee598a9a215b71605" +dependencies = [ + "cairo-sys-rs", + "gdk-pixbuf-sys", + "gdk4-sys", + "gio-sys", + "glib-sys", + "gobject-sys", + "graphene-sys", + "gsk4-sys", + "libc", + "pango-sys", + "system-deps", +] + +[[package]] +name = "hashbrown" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" + +[[package]] +name = "heck" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" + +[[package]] +name = "indexmap" +version = "1.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1885e79c1fc4b10f0e172c475f458b7f7b93061064d98c3293e98c5ba0c8b399" +dependencies = [ + "autocfg", + "hashbrown", +] + +[[package]] +name = "libc" +version = "0.2.140" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "99227334921fae1a979cf0bfdfcc6b3e5ce376ef57e16fb6fb3ea2ed6095f80c" + +[[package]] +name = "memchr" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" + +[[package]] +name = "memoffset" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d61c719bcfbcf5d62b3a09efa6088de8c54bc0bfcd3ea7ae39fcc186108b8de1" +dependencies = [ + "autocfg", +] + +[[package]] +name = "once_cell" +version = "1.17.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b7e5500299e16ebb147ae15a00a942af264cf3688f47923b8fc2cd5858f23ad3" + +[[package]] +name = "pango" +version = "0.16.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cdff66b271861037b89d028656184059e03b0b6ccb36003820be19f7200b1e94" +dependencies = [ + "bitflags", + "gio", + "glib", + "libc", + "once_cell", + "pango-sys", +] + +[[package]] +name = "pango-sys" +version = "0.16.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e134909a9a293e04d2cc31928aa95679c5e4df954d0b85483159bd20d8f047f" +dependencies = [ + "glib-sys", + "gobject-sys", + "libc", + "system-deps", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e0a7ae3ac2f1173085d398531c705756c94a4c56843785df85a60c1a0afac116" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "pkg-config" +version = "0.3.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ac9a59f73473f1b8d852421e59e64809f025994837ef743615c6d0c5b305160" + +[[package]] +name = "proc-macro-crate" +version = "1.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f4c021e1093a56626774e81216a4ce732a735e5bad4868a03f3ed65ca0c3919" +dependencies = [ + "once_cell", + "toml_edit", +] + +[[package]] +name = "proc-macro-error" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" +dependencies = [ + "proc-macro-error-attr", + "proc-macro2", + "quote", + "syn 1.0.109", + "version_check", +] + +[[package]] +name = "proc-macro-error-attr" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" +dependencies = [ + "proc-macro2", + "quote", + "version_check", +] + +[[package]] +name = "proc-macro2" +version = "1.0.52" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d0e1ae9e836cc3beddd63db0df682593d7e2d3d891ae8c9083d2113e1744224" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4424af4bf778aae2051a77b60283332f386554255d722233d09fbfc7e30da2fc" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rustc_version" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366" +dependencies = [ + "semver", +] + +[[package]] +name = "screenplay" +version = "0.1.0" +dependencies = [ + "gtk4", +] + +[[package]] +name = "semver" +version = "1.0.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bebd363326d05ec3e2f532ab7660680f3b02130d780c299bca73469d521bc0ed" + +[[package]] +name = "serde" +version = "1.0.158" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "771d4d9c4163ee138805e12c710dd365e4f44be8be0503cb1bb9eb989425d9c9" + +[[package]] +name = "slab" +version = "0.4.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6528351c9bc8ab22353f9d776db39a20288e8d6c37ef8cfe3317cf875eecfc2d" +dependencies = [ + "autocfg", +] + +[[package]] +name = "smallvec" +version = "1.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0" + +[[package]] +name = "syn" +version = "1.0.109" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "syn" +version = "2.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c622ae390c9302e214c31013517c2061ecb2699935882c60a9b37f82f8625ae" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "system-deps" +version = "6.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2955b1fe31e1fa2fbd1976b71cc69a606d7d4da16f6de3333d0c92d51419aeff" +dependencies = [ + "cfg-expr", + "heck", + "pkg-config", + "toml", + "version-compare", +] + +[[package]] +name = "thiserror" +version = "1.0.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "978c9a314bd8dc99be594bc3c175faaa9794be04a5a5e153caba6915336cebac" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f9456a42c5b0d803c8cd86e73dd7cc9edd429499f37a3550d286d5e86720569f" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.4", +] + +[[package]] +name = "toml" +version = "0.5.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f4f7f0dd8d50a853a531c426359045b1998f04219d88799810762cd4ad314234" +dependencies = [ + "serde", +] + +[[package]] +name = "toml_datetime" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3ab8ed2edee10b50132aed5f331333428b011c99402b5a534154ed15746f9622" + +[[package]] +name = "toml_edit" +version = "0.19.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc18466501acd8ac6a3f615dd29a3438f8ca6bb3b19537138b3106e575621274" +dependencies = [ + "indexmap", + "toml_datetime", + "winnow", +] + +[[package]] +name = "unicode-ident" +version = "1.0.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e5464a87b239f13a63a501f2701565754bae92d243d4bb7eb12f6d57d2269bf4" + +[[package]] +name = "version-compare" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "579a42fc0b8e0c63b76519a339be31bed574929511fa53c1a3acae26eb258f29" + +[[package]] +name = "version_check" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + +[[package]] +name = "winnow" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23d020b441f92996c80d94ae9166e8501e59c7bb56121189dc9eab3bd8216966" +dependencies = [ + "memchr", +] diff --git a/screenplay/Cargo.toml b/screenplay/Cargo.toml new file mode 100644 index 0000000..adcf6a6 --- /dev/null +++ b/screenplay/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "screenplay" +version = "0.1.0" +edition = "2021" +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" } diff --git a/screenplay/src/lib.rs b/screenplay/src/lib.rs new file mode 100644 index 0000000..722831d --- /dev/null +++ b/screenplay/src/lib.rs @@ -0,0 +1,116 @@ +/* +Copyright 2023, Savanni D'Gerinel + +This file is part of Screenplay. + +Screenplay is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. + +Screenplay is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along with Lumeto. If not, see . +*/ + +use gtk::prelude::*; + +#[derive(Clone, Debug)] +pub enum Action { + SelectPage(usize), + Deselect, +} + +#[derive(Clone, Debug)] +pub struct Error; + +#[derive(Clone)] +pub struct Screen { + pub title: String, + pub widget: gtk::Widget, + pub adjustments: Vec, +} + +#[derive(Clone)] +pub struct Screenplay { + frame: gtk::Frame, + screens: Vec, +} + +impl Screenplay { + pub fn new(gtk_app: >k::Application, screens: Vec) -> Result { + let window = gtk::ApplicationWindow::new(gtk_app); + window.show(); + + let (sender, receiver) = gtk::glib::MainContext::channel(gtk::glib::PRIORITY_DEFAULT); + + let layout = gtk::Box::builder() + .orientation(gtk::Orientation::Horizontal) + .build(); + window.set_child(Some(&layout)); + + let listbox = gtk::ListBox::builder() + .activate_on_single_click(true) + .show_separators(true) + .focusable(false) + .build(); + + let frame = gtk::Frame::builder() + .height_request(500) + .width_request(500) + .build(); + + layout.append(&listbox); + layout.append(&frame); + + listbox.connect_row_activated(move |_, row| { + match row.index() { + -1 => sender.send(Action::Deselect), + idx => sender.send(Action::SelectPage(idx as usize)), + } + .unwrap() + }); + + screens.iter().for_each(|Screen { title, .. }| { + listbox.append( + >k::ListBoxRow::builder() + .child(>k::Label::new(Some(title.as_ref()))) + .build(), + ); + }); + + let storybook = Self { frame, screens }; + + { + let mut storybook = storybook.clone(); + receiver.attach(None, move |message| storybook.process_action(message)); + } + + Ok(storybook) + } + + fn process_action(&mut self, message: Action) -> Continue { + let nothing: Option<>k::Widget> = None; + match message { + Action::SelectPage(index) => match self.screens.get(index) { + Some(Screen { + widget, + adjustments, + .. + }) => { + let b = gtk::Box::new(gtk::Orientation::Vertical, 0); + let control_box = gtk::Box::new(gtk::Orientation::Vertical, 0); + b.append(widget); + b.append(&control_box); + + adjustments + .iter() + .for_each(|control| control_box.append(control)); + + self.frame.set_child(Some(&b)); + } + None => self.frame.set_child(nothing), + }, + Action::Deselect => self.frame.set_child(nothing), + } + + Continue(true) + } +} -- 2.44.1 From f23d7e9d7e6d0053ed7b2057dfc30314eceef17d Mon Sep 17 00:00:00 2001 From: Savanni D'Gerinel Date: Tue, 21 Mar 2023 09:56:24 -0400 Subject: [PATCH 2/3] Add some documentation --- screenplay/src/lib.rs | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/screenplay/src/lib.rs b/screenplay/src/lib.rs index 722831d..8ae46e7 100644 --- a/screenplay/src/lib.rs +++ b/screenplay/src/lib.rs @@ -10,24 +10,49 @@ Screenplay is distributed in the hope that it will be useful, but WITHOUT ANY WA You should have received a copy of the GNU General Public License along with Lumeto. If not, see . */ +/// Screenplay is a library that helps visualize GTK scenes. I got my inspiration from working with +/// Storybook and decided that I wanted a similar tool for GTK. +/// +/// With this library, you can write an application that loads up a bunch of different user +/// interfaces, and the library will put them on separate pages. Each UI can have as much or as +/// little behavior as you want. use gtk::prelude::*; #[derive(Clone, Debug)] -pub enum Action { +enum Action { SelectPage(usize), Deselect, } +/// Unused. In the near future, this will contain useful errors. #[derive(Clone, Debug)] pub struct Error; +/// A definition of a single Screen. The screen can be as much or as little as you want, but must +/// contain a title (for the page selector) and a widget to show the screen. #[derive(Clone)] pub struct Screen { + /// Title of the screen. This will only be rendered in the page selector. pub title: String, + + /// The screen itself. This can be anything that implements the gtk::Widget interface, and it + /// will be rendered in the main area of the window. pub widget: gtk::Widget, + + /// Unused today, however... + /// These will be rendered in an area of the window reserved for adjustments. They are meant to + /// be ways to provide variants to the current scene. You will need to attach behaviors. pub adjustments: Vec, } +/// Screenplay is an object that will render a gtk::ApplicationWindow. +/// +/// That window contains a sidebar which lists the names of all of the Screens that have been +/// provided to it. Selecting one of those will cause the application to render that screen and all +/// of its adjustments. +/// +/// It is highly likely that in the future this structure will be reformulated as a child of a GTK +/// ApplicationWindow. #[derive(Clone)] pub struct Screenplay { frame: gtk::Frame, @@ -35,6 +60,10 @@ pub struct Screenplay { } impl Screenplay { + /// Construct a new Screenplay. This will construct and render the ApplicationWindow as the + /// primary child of the Application. + /// + /// This function currently returns no errors, instead panicing if anything goes wrong. pub fn new(gtk_app: >k::Application, screens: Vec) -> Result { let window = gtk::ApplicationWindow::new(gtk_app); window.show(); @@ -86,6 +115,7 @@ impl Screenplay { Ok(storybook) } + /// Handle an application action. This generally means changing the current screen. fn process_action(&mut self, message: Action) -> Continue { let nothing: Option<>k::Widget> = None; match message { -- 2.44.1 From 68096ec743770edae984d9f81e3b252289d9562b Mon Sep 17 00:00:00 2001 From: Savanni D'Gerinel Date: Wed, 22 Mar 2023 10:59:44 -0400 Subject: [PATCH 3/3] Add a basic rendering for a player card --- kifu/kifu-core/src/lib.rs | 3 +- kifu/kifu-core/src/ui/mod.rs | 4 +- kifu/kifu-gtk/Cargo.lock | 8 +++ kifu/kifu-gtk/Cargo.toml | 1 + kifu/kifu-gtk/src/bin/screenplay.rs | 64 +++++++++++++++++++++ screenplay/Cargo.lock | 86 +++++++++++++++-------------- screenplay/Cargo.toml | 2 +- 7 files changed, 123 insertions(+), 45 deletions(-) create mode 100644 kifu/kifu-gtk/src/bin/screenplay.rs diff --git a/kifu/kifu-core/src/lib.rs b/kifu/kifu-core/src/lib.rs index c589b69..46f29ba 100644 --- a/kifu/kifu-core/src/lib.rs +++ b/kifu/kifu-core/src/lib.rs @@ -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; diff --git a/kifu/kifu-core/src/ui/mod.rs b/kifu/kifu-core/src/ui/mod.rs index 9fa1b9f..76ac480 100644 --- a/kifu/kifu-core/src/ui/mod.rs +++ b/kifu/kifu-core/src/ui/mod.rs @@ -1,2 +1,4 @@ pub mod playing_field; -pub mod types; + +mod types; +pub use types::PlayerCardElement; diff --git a/kifu/kifu-gtk/Cargo.lock b/kifu/kifu-gtk/Cargo.lock index 834dc4d..c2e0105 100644 --- a/kifu/kifu-gtk/Cargo.lock +++ b/kifu/kifu-gtk/Cargo.lock @@ -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" diff --git a/kifu/kifu-gtk/Cargo.toml b/kifu/kifu-gtk/Cargo.toml index 36c522e..0805e7f 100644 --- a/kifu/kifu-gtk/Cargo.toml +++ b/kifu/kifu-gtk/Cargo.toml @@ -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" } diff --git a/kifu/kifu-gtk/src/bin/screenplay.rs b/kifu/kifu-gtk/src/bin/screenplay.rs new file mode 100644 index 0000000..d2ac680 --- /dev/null +++ b/kifu/kifu-gtk/src/bin/screenplay.rs @@ -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) @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::(), + adjustments: vec![], + }]; + let screenplay = Screenplay::new(&app, screens).unwrap(); + }); + + app.run(); +} diff --git a/screenplay/Cargo.lock b/screenplay/Cargo.lock index 79ae3eb..b318edc 100644 --- a/screenplay/Cargo.lock +++ b/screenplay/Cargo.lock @@ -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", diff --git a/screenplay/Cargo.toml b/screenplay/Cargo.toml index adcf6a6..d71ab95 100644 --- a/screenplay/Cargo.toml +++ b/screenplay/Cargo.toml @@ -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" } -- 2.44.1