diff --git a/Cargo.lock b/Cargo.lock index 3885264..409f6bd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3,16 +3,25 @@ version = 4 [[package]] -name = "adler2" -version = "2.0.0" +name = "ahash" +version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "512761e0bb2578dd7380c6baaa0f4ce03e84f95e960231d1dec8bf4d7d6e2627" +checksum = "e8fd72866655d1904d6b0997d0b07ba561047d070fbe29de039031c641b61217" + +[[package]] +name = "aho-corasick" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" +dependencies = [ + "memchr", +] [[package]] name = "arrayvec" -version = "0.7.6" +version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50" +checksum = "23b62fc65de8e4e7f52534fb52b0f3ed04746ae267519eef2a83941e8085068b" [[package]] name = "autocfg" @@ -20,6 +29,29 @@ version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26" +[[package]] +name = "bindgen" +version = "0.69.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "271383c67ccabffb7381723dea0672a673f292304fcb45c01cc648c7a8d58088" +dependencies = [ + "bitflags 2.8.0", + "cexpr", + "clang-sys", + "itertools", + "lazy_static", + "lazycell", + "log", + "prettyplease", + "proc-macro2", + "quote", + "regex", + "rustc-hash", + "shlex", + "syn 2.0.98", + "which", +] + [[package]] name = "bitflags" version = "1.3.2" @@ -32,12 +64,6 @@ version = "2.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8f68f53c83ab957f72c32642f3868eec03eb974d1fb82e453128456482613d36" -[[package]] -name = "bumpalo" -version = "3.17.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1628fb46dfa0b37568d12e5edd512553eccf6a22a78e8bde00bb4aed84d5bdbf" - [[package]] name = "byteorder" version = "1.5.0" @@ -53,29 +79,52 @@ dependencies = [ "shlex", ] +[[package]] +name = "cexpr" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6fac387a98bb7c37292057cffc56d62ecb629900026402633ae9160df93a8766" +dependencies = [ + "nom", +] + +[[package]] +name = "cfg-if" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" + [[package]] name = "cfg-if" version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "clang-sys" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b023947811758c97c59bf9d1c188fd619ad4718dcaa767947df1cadb14f39f4" +dependencies = [ + "glob", + "libc", + "libloading", +] + [[package]] name = "clay-layout" version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f9a4b55b291637079fd64f1871ae87ff5996c05734d616f5f58f989636a3f2b" dependencies = [ "cc", ] [[package]] -name = "console_error_panic_hook" -version = "0.1.7" +name = "cmake" +version = "0.1.54" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a06aeb73f470f66dcdbf7223caeebb85984942f22f1adb2a088cf9668146bbbc" +checksum = "e7caa3f9de89ddbe2c607f4101924c5abec803763ae9534e4f4d7d8f84aa81f0" dependencies = [ - "cfg-if", - "wasm-bindgen", + "cc", ] [[package]] @@ -131,12 +180,25 @@ dependencies = [ ] [[package]] -name = "crc32fast" -version = "1.4.2" +name = "crossbeam-queue" +version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a97769d94ddab943e4510d138150169a2758b5ef3eb191a9ee688de3e23ef7b3" +checksum = "774ba60a54c213d409d5353bda12d49cd68d14e45036a285234c8d6f91f92570" dependencies = [ - "cfg-if", + "cfg-if 0.1.10", + "crossbeam-utils", + "maybe-uninit", +] + +[[package]] +name = "crossbeam-utils" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3c7c73a2d1e9fc0886a08b93e98eb643461230d5f1925e4036204d5f2e261a8" +dependencies = [ + "autocfg", + "cfg-if 0.1.10", + "lazy_static", ] [[package]] @@ -169,12 +231,6 @@ dependencies = [ "libloading", ] -[[package]] -name = "downcast-rs" -version = "1.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "75b325c5dbd37f80359721ad39aca5a29fb04c89279657cffdda8736d0c0b9d2" - [[package]] name = "dwrote" version = "0.11.2" @@ -187,6 +243,12 @@ dependencies = [ "wio", ] +[[package]] +name = "either" +version = "1.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0" + [[package]] name = "enum_dispatch" version = "0.3.13" @@ -196,7 +258,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn", + "syn 2.0.98", ] [[package]] @@ -209,40 +271,6 @@ dependencies = [ "windows-sys 0.59.0", ] -[[package]] -name = "euclid" -version = "0.22.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad9cdb4b747e485a12abb0e6566612956c7a1bafa3bdb8d682c5b6d403589e48" -dependencies = [ - "num-traits", -] - -[[package]] -name = "fastrand" -version = "2.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37909eebbb50d72f9059c3b6d82c0463f2ff062c9e95845c43a6c9c0355411be" - -[[package]] -name = "fdeflate" -version = "0.3.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e6853b52649d4ac5c0bd02320cddc5ba956bdb407c4b75a2c6b75bf51500f8c" -dependencies = [ - "simd-adler32", -] - -[[package]] -name = "flate2" -version = "1.0.35" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c936bfdafb507ebbf50b8074c54fa31c5be9a1e7e5f467dd659697041407d07c" -dependencies = [ - "crc32fast", - "miniz_oxide", -] - [[package]] name = "float-ord" version = "0.3.2" @@ -292,7 +320,7 @@ checksum = "1a5c6c585bc94aaf2c7b51dd4c2ba22680844aba4c687be581871a6f518c5742" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.98", ] [[package]] @@ -313,93 +341,10 @@ dependencies = [ ] [[package]] -name = "futures" -version = "0.3.31" +name = "fs_extra" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "65bc07b1a8bc7c85c5f2e110c476c7389b4554ba72af57d8445ea63a576b0876" -dependencies = [ - "futures-channel", - "futures-core", - "futures-executor", - "futures-io", - "futures-sink", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-channel" -version = "0.3.31" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2dff15bf788c671c1934e366d07e30c1814a8ef514e1af724a602e8a2fbe1b10" -dependencies = [ - "futures-core", - "futures-sink", -] - -[[package]] -name = "futures-core" -version = "0.3.31" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05f29059c0c2090612e8d742178b0580d2dc940c837851ad723096f87af6663e" - -[[package]] -name = "futures-executor" -version = "0.3.31" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e28d1d997f585e54aebc3f97d39e72338912123a67330d723fdbb564d646c9f" -dependencies = [ - "futures-core", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-io" -version = "0.3.31" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e5c1b78ca4aae1ac06c48a526a655760685149f0d465d21f37abfe57ce075c6" - -[[package]] -name = "futures-macro" -version = "0.3.31" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "162ee34ebcb7c64a8abebc059ce0fee27c2262618d7b60ed8faf72fef13c3650" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "futures-sink" -version = "0.3.31" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e575fab7d1e0dcb8d0c7bcf9a63ee213816ab51902e6d244a95819acacf1d4f7" - -[[package]] -name = "futures-task" -version = "0.3.31" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f90f7dce0722e95104fcb095585910c0977252f286e354b5e3bd38902cd99988" - -[[package]] -name = "futures-util" -version = "0.3.31" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9fa08315bb612088cc391249efdc3bc77536f16c91f6cf495e6fbe85b20a4a81" -dependencies = [ - "futures-channel", - "futures-core", - "futures-io", - "futures-macro", - "futures-sink", - "futures-task", - "memchr", - "pin-project-lite", - "pin-utils", - "slab", -] +checksum = "42703706b716c37f96a77aea830392ad231f44c9e9a67872fa5548707e11b11c" [[package]] name = "getrandom" @@ -407,49 +352,49 @@ version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "libc", - "wasi 0.11.0+wasi-snapshot-preview1", + "wasi", ] [[package]] -name = "getrandom" -version = "0.3.1" +name = "glob" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43a49c392881ce6d5c3b8cb70f98717b7c07aabbdff06687b9030dbfbe2725f8" +checksum = "a8d1add55171497b4705a648c6b583acafb01d58050a51727785f0b2c8e0a2b2" + +[[package]] +name = "hashbrown" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96282e96bfcd3da0d3aa9938bedf1e50df3269b6db08b4876d2da0bb1a0841cf" dependencies = [ - "cfg-if", - "libc", - "wasi 0.13.3+wasi-0.2.2", - "windows-targets 0.52.6", + "ahash", + "autocfg", ] [[package]] -name = "instant" -version = "0.1.13" +name = "hibitset" +version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e0242819d153cba4b4b05a5a8f2a7e9bbf97b6055b2a002b395c96b5ff3c0222" +checksum = "f3ede5cfa60c958e60330d65163adbc4211e15a2653ad80eb0cce878de120121" + +[[package]] +name = "home" +version = "0.5.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589533453244b0995c858700322199b2becb13b627df2851f64a2775d024abcf" dependencies = [ - "cfg-if", - "js-sys", - "wasm-bindgen", - "web-sys", + "windows-sys 0.59.0", ] [[package]] -name = "itoa" -version = "1.0.14" +name = "itertools" +version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d75a2a4b1b190afb6f5425f10f6a8f959d2ea0b9c2b1d79553551850539e4674" - -[[package]] -name = "js-sys" -version = "0.3.77" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1cfaf33c695fc6e08064efbc1f72ec937429614f25eef83af942d0e227c3a28f" +checksum = "ba291022dbbd398a455acf126c1e341954079855bc60dfdda641363bd6922569" dependencies = [ - "once_cell", - "wasm-bindgen", + "either", ] [[package]] @@ -458,6 +403,12 @@ version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" +[[package]] +name = "lazycell" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" + [[package]] name = "libc" version = "0.2.169" @@ -470,16 +421,10 @@ version = "0.8.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fc2f4eb4bc735547cfed7c0a4922cbd04a4655978c09b54f1f7b228750664c34" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "windows-targets 0.52.6", ] -[[package]] -name = "libm" -version = "0.2.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8355be11b20d696c8f18f6cc018c4e372165b1fa8126cef092399c9951984ffa" - [[package]] name = "libredox" version = "0.1.3" @@ -488,7 +433,6 @@ checksum = "c0ff37bd590ca25063e35af745c343cb7a0271906fb7b37e4813e8f79f00268d" dependencies = [ "bitflags 2.8.0", "libc", - "redox_syscall", ] [[package]] @@ -497,6 +441,16 @@ version = "0.4.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d26c52dbd32dccf2d10cac7725f8eae5296885fb5703b261f7d0a0739ec807ab" +[[package]] +name = "lock_api" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" +dependencies = [ + "autocfg", + "scopeguard", +] + [[package]] name = "log" version = "0.4.25" @@ -504,15 +458,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "04cbf5b083de1c7e0222a7a51dbfdba1cbe1c6ab0b15e29fff3f6c077fd9cd9f" [[package]] -name = "lyon_geom" -version = "1.0.6" +name = "maybe-uninit" +version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8af69edc087272df438b3ee436c4bb6d7c04aa8af665cfd398feae627dbd8570" -dependencies = [ - "arrayvec", - "euclid", - "num-traits", -] +checksum = "60302e4db3a61da70c0cb7991976248362f30319e88850c487b9b95bbf059e00" [[package]] name = "memchr" @@ -521,73 +470,25 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" [[package]] -name = "memoffset" -version = "0.6.5" +name = "minimal-lexical" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5aa361d4faea93603064a027415f07bd8e1d5c88c9fbf68bf56a285428fd79ce" -dependencies = [ - "autocfg", -] +checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" [[package]] -name = "minifb" -version = "0.28.0" +name = "mopa" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d1a093126f2ed9012fc0b146934c97eb0273e54983680a8bf5309b6b4a365b32" -dependencies = [ - "cc", - "console_error_panic_hook", - "dlib", - "futures", - "instant", - "js-sys", - "lazy_static", - "libc", - "orbclient", - "raw-window-handle", - "serde", - "serde_derive", - "tempfile", - "wasm-bindgen", - "wasm-bindgen-futures", - "wayland-client", - "wayland-cursor", - "wayland-protocols", - "web-sys", - "winapi", - "x11-dl", -] +checksum = "a785740271256c230f57462d3b83e52f998433a7062fc18f96d5999474a9f915" [[package]] -name = "miniz_oxide" -version = "0.8.4" +name = "nom" +version = "7.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b3b1c9bd4fe1f0f8b387f6eb9eb3b4a1aa26185e5750efb9140301703f62cd1b" +checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a" dependencies = [ - "adler2", - "simd-adler32", -] - -[[package]] -name = "nix" -version = "0.24.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa52e972a9a719cecb6864fb88568781eb706bac2cd1d4f04a648542dbf78069" -dependencies = [ - "bitflags 1.3.2", - "cfg-if", - "libc", - "memoffset", -] - -[[package]] -name = "num-traits" -version = "0.2.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" -dependencies = [ - "autocfg", - "libm", + "memchr", + "minimal-lexical", ] [[package]] @@ -603,8 +504,7 @@ dependencies = [ "clay-layout", "enum_dispatch", "font-kit", - "minifb", - "raqote", + "raylib", "test-case", ] @@ -615,15 +515,26 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d" [[package]] -name = "orbclient" -version = "0.3.48" +name = "parking_lot" +version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba0b26cec2e24f08ed8bb31519a9333140a6599b867dac464bb150bdb796fd43" +checksum = "f1bf18183cf54e8d6059647fc3063646a1801cf30896933ec2311622cc4b9a27" dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" +dependencies = [ + "cfg-if 1.0.0", "libc", - "libredox", - "sdl2", - "sdl2-sys", + "redox_syscall", + "smallvec", + "windows-targets 0.52.6", ] [[package]] @@ -645,18 +556,6 @@ dependencies = [ "rustc_version", ] -[[package]] -name = "pin-project-lite" -version = "0.2.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b3cff922bd51709b605d9ead9aa71031d81447142d828eb4a6eba76fe619f9b" - -[[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.31" @@ -664,16 +563,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2" [[package]] -name = "png" -version = "0.17.16" +name = "prettyplease" +version = "0.2.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "82151a2fc869e011c153adc57cf2789ccb8d9906ce52c0b39a6b5697749d7526" +checksum = "6924ced06e1f7dfe3fa48d57b9f74f55d8915f5036121bef647ef4b204895fac" dependencies = [ - "bitflags 1.3.2", - "crc32fast", - "fdeflate", - "flate2", - "miniz_oxide", + "proc-macro2", + "syn 2.0.98", ] [[package]] @@ -695,25 +591,31 @@ dependencies = [ ] [[package]] -name = "raqote" -version = "0.8.5" +name = "raylib" +version = "5.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "324990858d2a5df9ccd30b2e8b474030bd503297378a3fc0944c37af00eb8903" +checksum = "e2a7a6734329d7b872a418fe4cb08ca282eb66a6f4a3430bd4ee4e6a8cac6632" dependencies = [ - "euclid", - "font-kit", - "lyon_geom", - "pathfinder_geometry", - "png", - "sw-composite", - "typed-arena", + "cfg-if 1.0.0", + "lazy_static", + "libc", + "parking_lot", + "raylib-sys", + "specs", + "specs-derive", ] [[package]] -name = "raw-window-handle" -version = "0.6.2" +name = "raylib-sys" +version = "5.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "20675572f6f24e9e76ef639bc5552774ed45f1c30e2951e1e99c59888861c539" +checksum = "db5c6001cfaeec17210713227d11f3b1ba4b723bb12cff47d1b93c4060e10ad0" +dependencies = [ + "bindgen", + "cc", + "cmake", + "fs_extra", +] [[package]] name = "redox_syscall" @@ -730,11 +632,46 @@ version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ba009ff324d1fc1b900bd1fdb31564febe58a8ccc8a6fdbb93b543d33b13ca43" dependencies = [ - "getrandom 0.2.15", + "getrandom", "libredox", "thiserror", ] +[[package]] +name = "regex" +version = "1.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b544ef1b4eac5dc2db33ea63606ae9ffcfac26c1416a2806ae0bf5f56b201191" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "809e8dc61f6de73b46c85f4c96486310fe304c434cfa43669d7b40f711150908" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c" + +[[package]] +name = "rustc-hash" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" + [[package]] name = "rustc_version" version = "0.4.1" @@ -757,18 +694,6 @@ dependencies = [ "windows-sys 0.59.0", ] -[[package]] -name = "rustversion" -version = "1.0.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7c45b9784283f1b2e7fb61b42047c2fd678ef0960d4f6f1eba131594cc369d4" - -[[package]] -name = "ryu" -version = "1.0.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ea1a2d0a644769cc99faa24c3ad26b379b786fe7c36fd3c546254801650e6dd" - [[package]] name = "same-file" version = "1.0.6" @@ -779,33 +704,10 @@ dependencies = [ ] [[package]] -name = "scoped-tls" -version = "1.0.1" +name = "scopeguard" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e1cf6437eb19a8f4a6cc0f7dca544973b0b78843adbfeb3683d1a94a0024a294" - -[[package]] -name = "sdl2" -version = "0.35.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7959277b623f1fb9e04aea73686c3ca52f01b2145f8ea16f4ff30d8b7623b1a" -dependencies = [ - "bitflags 1.3.2", - "lazy_static", - "libc", - "sdl2-sys", -] - -[[package]] -name = "sdl2-sys" -version = "0.35.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3586be2cf6c0a8099a79a12b4084357aa9b3e0b0d7980e3b67aaf7a9d55f9f0" -dependencies = [ - "cfg-if", - "libc", - "version-compare", -] +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" [[package]] name = "semver" @@ -813,38 +715,6 @@ version = "1.0.25" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f79dfe2d285b0488816f30e700a7438c5a73d816b5b7d3ac72fbc48b0d185e03" -[[package]] -name = "serde" -version = "1.0.217" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "02fc4265df13d6fa1d00ecff087228cc0a2b5f3c0e87e258d8b94a156e984c70" -dependencies = [ - "serde_derive", -] - -[[package]] -name = "serde_derive" -version = "1.0.217" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a9bf7cf98d04a2b28aead066b7496853d4779c9cc183c440dbac457641e19a0" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "serde_json" -version = "1.0.138" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d434192e7da787e94a6ea7e9670b26a036d0ca41e0b7efb2676dd32bae872949" -dependencies = [ - "itoa", - "memchr", - "ryu", - "serde", -] - [[package]] name = "shlex" version = "1.3.0" @@ -852,19 +722,23 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" [[package]] -name = "simd-adler32" -version = "0.3.7" +name = "shred" +version = "0.10.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d66dc143e6b11c1eddc06d5c423cfc97062865baf299914ab64caa38182078fe" +checksum = "c5f08237e667ac94ad20f8878b5943d91a93ccb231428446c57c21c57779016d" +dependencies = [ + "arrayvec", + "hashbrown", + "mopa", + "smallvec", + "tynm", +] [[package]] -name = "slab" -version = "0.4.9" +name = "shrev" +version = "1.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" -dependencies = [ - "autocfg", -] +checksum = "a5ea33232fdcf1bf691ca33450e5a94dde13e1a8cbb8caabc5e4f9d761e10b1a" [[package]] name = "smallvec" @@ -873,10 +747,41 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" [[package]] -name = "sw-composite" -version = "0.7.16" +name = "specs" +version = "0.16.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ac8fb7895b4afa060ad731a32860db8755da3449a47e796d5ecf758db2671d4" +checksum = "fff28a29366aff703d5da8a7e2c8875dc8453ac1118f842cbc0fa70c7db51240" +dependencies = [ + "crossbeam-queue", + "hashbrown", + "hibitset", + "log", + "shred", + "shrev", + "tuple_utils", +] + +[[package]] +name = "specs-derive" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3e23e09360f3d2190fec4222cd9e19d3158d5da948c0d1ea362df617dd103511" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[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" @@ -889,20 +794,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "tempfile" -version = "3.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38c246215d7d24f48ae091a2902398798e05d978b24315d6efbc00ede9a8bb91" -dependencies = [ - "cfg-if", - "fastrand", - "getrandom 0.3.1", - "once_cell", - "rustix", - "windows-sys 0.59.0", -] - [[package]] name = "test-case" version = "3.3.1" @@ -918,10 +809,10 @@ version = "3.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "adcb7fd841cd518e279be3d5a3eb0636409487998a4aff22f3de87b81e88384f" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "proc-macro2", "quote", - "syn", + "syn 2.0.98", ] [[package]] @@ -932,7 +823,7 @@ checksum = "5c89e72a01ed4c579669add59014b9a524d609c0c88c6a585ce37485879f6ffb" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.98", "test-case-core", ] @@ -953,14 +844,23 @@ checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.98", ] [[package]] -name = "typed-arena" -version = "2.0.2" +name = "tuple_utils" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6af6ae20167a9ece4bcb41af5b80f8a1f1df981f6391189ce00fd257af04126a" +checksum = "44834418e2c5b16f47bedf35c28e148db099187dd5feee6367fb2525863af4f1" + +[[package]] +name = "tynm" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd30d05e69d1478e13fe3e7a853409cfec82cebc2cf9b8d613b3c6b0081781ed" +dependencies = [ + "nom", +] [[package]] name = "unicode-ident" @@ -968,12 +868,6 @@ version = "1.0.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a210d160f08b701c8721ba1c726c11662f877ea6b7094007e1ca9a1041945034" -[[package]] -name = "version-compare" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "579a42fc0b8e0c63b76519a339be31bed574929511fa53c1a3acae26eb258f29" - [[package]] name = "walkdir" version = "2.5.0" @@ -991,168 +885,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] -name = "wasi" -version = "0.13.3+wasi-0.2.2" +name = "which" +version = "4.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26816d2e1a4a36a2940b96c5296ce403917633dff8f3440e9b236ed6f6bacad2" +checksum = "87ba24419a2078cd2b0f2ede2691b6c66d8e47836da3b6db8265ebad47afbfc7" dependencies = [ - "wit-bindgen-rt", -] - -[[package]] -name = "wasm-bindgen" -version = "0.2.100" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1edc8929d7499fc4e8f0be2262a241556cfc54a0bea223790e71446f2aab1ef5" -dependencies = [ - "cfg-if", + "either", + "home", "once_cell", - "rustversion", - "serde", - "serde_json", - "wasm-bindgen-macro", -] - -[[package]] -name = "wasm-bindgen-backend" -version = "0.2.100" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2f0a0651a5c2bc21487bde11ee802ccaf4c51935d0d3d42a6101f98161700bc6" -dependencies = [ - "bumpalo", - "log", - "proc-macro2", - "quote", - "syn", - "wasm-bindgen-shared", -] - -[[package]] -name = "wasm-bindgen-futures" -version = "0.4.50" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "555d470ec0bc3bb57890405e5d4322cc9ea83cebb085523ced7be4144dac1e61" -dependencies = [ - "cfg-if", - "js-sys", - "once_cell", - "wasm-bindgen", - "web-sys", -] - -[[package]] -name = "wasm-bindgen-macro" -version = "0.2.100" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7fe63fc6d09ed3792bd0897b314f53de8e16568c2b3f7982f468c0bf9bd0b407" -dependencies = [ - "quote", - "wasm-bindgen-macro-support", -] - -[[package]] -name = "wasm-bindgen-macro-support" -version = "0.2.100" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ae87ea40c9f689fc23f209965b6fb8a99ad69aeeb0231408be24920604395de" -dependencies = [ - "proc-macro2", - "quote", - "syn", - "wasm-bindgen-backend", - "wasm-bindgen-shared", -] - -[[package]] -name = "wasm-bindgen-shared" -version = "0.2.100" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a05d73b933a847d6cccdda8f838a22ff101ad9bf93e33684f39c1f5f0eece3d" -dependencies = [ - "unicode-ident", -] - -[[package]] -name = "wayland-client" -version = "0.29.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f3b068c05a039c9f755f881dc50f01732214f5685e379829759088967c46715" -dependencies = [ - "bitflags 1.3.2", - "downcast-rs", - "libc", - "nix", - "scoped-tls", - "wayland-commons", - "wayland-scanner", - "wayland-sys", -] - -[[package]] -name = "wayland-commons" -version = "0.29.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8691f134d584a33a6606d9d717b95c4fa20065605f798a3f350d78dced02a902" -dependencies = [ - "nix", - "once_cell", - "smallvec", - "wayland-sys", -] - -[[package]] -name = "wayland-cursor" -version = "0.29.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6865c6b66f13d6257bef1cd40cbfe8ef2f150fb8ebbdb1e8e873455931377661" -dependencies = [ - "nix", - "wayland-client", - "xcursor", -] - -[[package]] -name = "wayland-protocols" -version = "0.29.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b950621f9354b322ee817a23474e479b34be96c2e909c14f7bc0100e9a970bc6" -dependencies = [ - "bitflags 1.3.2", - "wayland-client", - "wayland-commons", - "wayland-scanner", -] - -[[package]] -name = "wayland-scanner" -version = "0.29.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f4303d8fa22ab852f789e75a967f0a2cdc430a607751c0499bada3e451cbd53" -dependencies = [ - "proc-macro2", - "quote", - "xml-rs", -] - -[[package]] -name = "wayland-sys" -version = "0.29.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be12ce1a3c39ec7dba25594b97b42cb3195d54953ddb9d3d95a7c3902bc6e9d4" -dependencies = [ - "dlib", - "lazy_static", - "pkg-config", -] - -[[package]] -name = "web-sys" -version = "0.3.77" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "33b6dd2ef9186f1f2072e409e99cd22a975331a6b3591b12c764e0e55c60d5d2" -dependencies = [ - "js-sys", - "wasm-bindgen", + "rustix", ] [[package]] @@ -1334,38 +1075,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "wit-bindgen-rt" -version = "0.33.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3268f3d866458b787f390cf61f4bbb563b922d091359f9608842999eaee3943c" -dependencies = [ - "bitflags 2.8.0", -] - -[[package]] -name = "x11-dl" -version = "2.21.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38735924fedd5314a6e548792904ed8c6de6636285cb9fec04d5b1db85c1516f" -dependencies = [ - "libc", - "once_cell", - "pkg-config", -] - -[[package]] -name = "xcursor" -version = "0.3.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ef33da6b1660b4ddbfb3aef0ade110c8b8a781a3b6382fa5f2b5b040fd55f61" - -[[package]] -name = "xml-rs" -version = "0.8.25" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c5b940ebc25896e71dd073bad2dbaa2abfe97b0a391415e22ad1326d9c54e3c4" - [[package]] name = "yeslogic-fontconfig-sys" version = "6.0.0" diff --git a/Cargo.toml b/Cargo.toml index 578b6bc..dca49d3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,11 +4,11 @@ version = "0.1.0" edition = "2024" [dependencies] -clay-layout = "0.2.0" +# clay-layout = "0.2.0" +clay-layout = { path = "../clay-ui-rust" } enum_dispatch = "0.3.13" font-kit = "0.14.2" -minifb = "0.28.0" -raqote = "0.8.5" +raylib = { version = "5.0.2", features = ["wayland"] } test-case = "3.3.1" [lib] diff --git a/MononokiNerdFont-Regular.ttf b/MononokiNerdFont-Regular.ttf new file mode 100644 index 0000000..85c7a43 Binary files /dev/null and b/MononokiNerdFont-Regular.ttf differ diff --git a/flake.nix b/flake.nix index 6597cd3..8795512 100644 --- a/flake.nix +++ b/flake.nix @@ -9,48 +9,58 @@ }; }; - outputs = { - self, - nixpkgs, - rust-overlay, - }: let - # rust-overlay = import rust-overlay; - pkgs = - import nixpkgs - { - system = "x86_64-linux"; - overlays = [rust-overlay.overlays.default]; + outputs = + { self + , nixpkgs + , rust-overlay + , + }: + let + # rust-overlay = import rust-overlay; + pkgs = + import nixpkgs + { + system = "x86_64-linux"; + overlays = [ rust-overlay.overlays.default ]; + }; + in + { + devShells.x86_64-linux.default = pkgs.mkShell rec { + buildInputs = with pkgs; [ + rust-bin.nightly.latest.default + rust-analyzer + + expat + fontconfig + freetype + freetype.dev + libGL + pkg-config + xorg.libX11 + xorg.libXcursor + xorg.libXi + xorg.libXrandr + wayland + libxkbcommon + rust-cbindgen + cmake + glfw + clang + libclang + libllvm + nerd-fonts.mononoki + ]; + + LD_LIBRARY_PATH = + builtins.foldl' (a: b: "${a}:${b}/lib") "${pkgs.vulkan-loader}/lib" buildInputs; + + NIX_LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath buildInputs; + + shellHook = '' + export LD_LIBRARY_PATH=$NIX_LD_LIBRARY_PATH + export LIBCLANG_PATH="${pkgs.llvmPackages.libclang.lib}/lib"; + # export MONOSPACE_FONT="${pkgs.nerd-fonts.mononoki}/share/fonts/truetype/NerdFonts/Mononoki/MononokiNerdFont-Regular.ttf " + ''; }; - in { - devShells.x86_64-linux.default = pkgs.mkShell rec { - buildInputs = with pkgs; [ - rust-bin.nightly.latest.default - rust-analyzer - - expat - fontconfig - freetype - freetype.dev - libGL - pkg-config - xorg.libX11 - xorg.libXcursor - xorg.libXi - xorg.libXrandr - wayland - libxkbcommon - rust-cbindgen - ]; - - LD_LIBRARY_PATH = - builtins.foldl' (a: b: "${a}:${b}/lib") "${pkgs.vulkan-loader}/lib" buildInputs; - - # NIX_LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath buildInputs; - - shellHook = '' - # export LD_LIBRARY_PATH=$NIX_LD_LIBRARY_PATH - # export LIBCLANG_PATH="${pkgs.llvmPackages.libclang.lib}/lib"; - ''; }; - }; } diff --git a/src/app/bin.rs b/src/app/bin.rs index 30a3d0d..71df79c 100644 --- a/src/app/bin.rs +++ b/src/app/bin.rs @@ -1,140 +1,411 @@ -use std::{any::Any, cell::RefCell, rc::Rc}; - -use clay_layout::{ - Clay, - bindings::Clay_TextElementConfig, - elements::{ - CornerRadius, - rectangle::Rectangle, - text::{Text, TextElementConfig}, - }, - fixed, - id::Id, - layout::Layout, - math::Dimensions, +use std::{ + cell::RefCell, + collections::{HashMap, HashSet}, + rc::Rc, }; -use font_kit::{family_name::FamilyName, properties::Properties, source::SystemSource}; -use gui::GUI; -use minifb::{Window, WindowOptions}; -use raqote::{DrawOptions, DrawTarget, SolidSource}; +use clay_layout::{ + Declaration, + bindings::Clay_ResetMeasureTextCache, + fit, grow, + id::Id, + layout::{LayoutDirection, Padding}, + math::Dimensions, + render_commands::RenderCommandConfig, + text::{TextConfig, TextElementConfig}, +}; +use raylib::{ + RaylibHandle, RaylibThread, + color::Color, + ffi::Vector2, + prelude::{Font, RaylibDraw, RaylibDrawHandle, RaylibScissorModeExt}, + text::RaylibFont, +}; -mod gui; +struct FontStore { + font: String, + fonts: HashMap>, + fonts_to_be_loaded: HashSet, +} -fn main() { - let clay = Clay::new((800., 600.).into()); +impl FontStore { + const SIZE_PARAGRAPH: f32 = 20.; + const SIZE_HEADER: f32 = 30.; + const MOD_SUBTEXT: f32 = 0.5; - let mut window = Window::new("Raqote", 800, 40, WindowOptions { - borderless: true, - scale_mode: minifb::ScaleMode::Center, - resize: true, - ..Default::default() - }) - .unwrap(); - - let font = SystemSource::new() - .select_best_match(&[FamilyName::Monospace], &Properties::new()) - .unwrap() - .load() - .unwrap(); - - window.set_target_fps(60); - - let mut size = window.get_size(); - let mut dt = DrawTarget::new(size.0 as i32, size.1 as i32); - - clay.measure_text_function(|text, config| { - let config: Clay_TextElementConfig = unsafe { - *std::mem::transmute::(config) - }; - - Dimensions { - width: config.fontSize as f32, - height: config.fontSize as f32 * text.len() as f32, + pub fn new(name: impl Into) -> Self { + Self { + fonts: HashMap::new(), + font: name.into(), + fonts_to_be_loaded: HashSet::new(), } - }); + } - loop { - dt.clear(SolidSource::from_unpremultiplied_argb( - 0xff, 0xff, 0xff, 0xff, - )); - clay.begin(); - - // Adds a red rectangle with a corner radius of 5. - // The Layout makes the rectangle have a width and height of 50. - clay.with( - [ - Id::new("red_rectangle"), - Layout::new().width(fixed!(50.)).height(fixed!(50.)).end(), - Rectangle::new() - .color((0xFF, 0x00, 0x00).into()) - .corner_radius(CornerRadius::All(5.)) - .end(), - ], - |c| { - c.with( - [ - Id::new("test_text"), - Layout::new().end(), - Rectangle::new().color((0xFF, 0xFF, 0xFF).into()).end(), - // Text::new().color((0xFF, 0xFF, 0xFF).into()).end() - ], - |_| {}, - ); - }, - ); - - // Return the list of render commands of your layout - let render_commands = clay.end(); - - for command in render_commands { - // println!("Id of the element: {}", command.id); // Note: Ids are in fact numbers generated by Clay - // println!("Bounding box: {:?}", command.bounding_box); - // println!("Type and config: {:?}", command.config); - - match command.config { - clay_layout::render_commands::RenderCommandConfig::Rectangle(rectangle) => { - dt.fill_rect( - command.bounding_box.x, - command.bounding_box.y, - command.bounding_box.width, - command.bounding_box.height, - &raqote::Source::Solid(SolidSource { - r: (rectangle.color.r * 255.0) as u8, - g: (rectangle.color.g * 255.0) as u8, - b: (rectangle.color.b * 255.0) as u8, - a: (rectangle.color.a * 255.0) as u8, - }), - &DrawOptions::new(), - ); - } - clay_layout::render_commands::RenderCommandConfig::Border(border_container) => { - todo!() - } - clay_layout::render_commands::RenderCommandConfig::Text(_, text) => todo!(), - clay_layout::render_commands::RenderCommandConfig::Image(image) => todo!(), - clay_layout::render_commands::RenderCommandConfig::ScissorStart() => todo!(), - clay_layout::render_commands::RenderCommandConfig::ScissorEnd() => todo!(), - clay_layout::render_commands::RenderCommandConfig::Custom(custom) => todo!(), - clay_layout::render_commands::RenderCommandConfig::None() => {} - } - } - - if window.is_key_down(minifb::Key::Escape) { - break; - } - - let (width, height) = window.get_size(); - - if width as i32 != dt.width() || height as i32 != dt.height() { - dt = DrawTarget::new(width as i32, height as i32); - clay.layout_dimensions((width as f32, height as f32).into()); - size = (width, height); - // window.update(); + pub fn get(&mut self, size: i32) -> Option> { + let size = size.max(1); + if let Some(font) = self.fonts.get(&size) { + Some(font.clone()) } else { - window - .update_with_buffer(dt.get_data(), size.0, size.1) - .unwrap(); + self.fonts_to_be_loaded.insert(size); + None + } + } + + pub fn get_no_load(&self, size: i32) -> Option> { + if let Some(font) = self.fonts.get(&size) { + Some(font.clone()) + } else { + None + } + } + + pub fn load_fonts( + &mut self, + handle: &mut RaylibHandle, + thread: &RaylibThread, + ) -> Result<(), String> { + for size in self.fonts_to_be_loaded.clone() { + assert!(size != 0, "HOW IS THIS ZERO?"); + println!("Loading {} in {size}px", self.font); + let font = Rc::new(handle.load_font_ex(&thread, &self.font, size, None)?); + self.fonts.insert(size, font.clone()); + } + self.fonts_to_be_loaded.clear(); + Ok(()) + } + + pub fn text( + &mut self, + d: &mut RaylibDrawHandle, + text: &str, + x: f32, + y: f32, + size: f32, + letter_spacing: u16, + color: Option, + ) { + // Program crashes at size=0. + let size = if size == 0. { 0.1 } else { size }; + if let Some(font) = self.get(size as i32) { + d.draw_text_ex( + font.as_ref(), + text, + Vector2 { x, y }, + size, + letter_spacing.into(), + color.unwrap_or(Color::BLUE), + ); } } } + +#[inline] +fn clay2ray(c: clay_layout::color::Color) -> Color { + Color { + r: (c.r as f32 * 256.0) as u8, + g: (c.g as f32 * 256.0) as u8, + b: (c.b as f32 * 256.0) as u8, + a: (c.a as f32 * 256.0) as u8, + } +} + +fn main() -> Result<(), String> { + println!("Openbirch GUI"); + + let (mut rl, thread) = raylib::init() + .size(640, 480) + .title("Openbirch GUI") + .msaa_4x() + .resizable() + .build(); + let mut clay = clay_layout::Clay::new((640., 480.).into()); + // let font = match rl.load_font_ex(&thread, "MononokiNerdFont-Regular.ttf", 20, None) { + // Ok(font) => font, + // Err(err) => panic!("Failed to load font {}", err), + // }; + let font_store = Rc::new(RefCell::new(FontStore::new("MononokiNerdFont-Regular.ttf"))); + let font_store_math = Rc::new(RefCell::new(FontStore::new("xits-italic.ttf"))); + + { + font_store.borrow_mut().get(16); + } + + // stupid fucking 'static closures + let font_store_clone = font_store.clone(); + let font_store_math_clone = font_store.clone(); + + clay.set_measure_text_function(move |text, config| { + let mut text_size = clay_layout::math::Dimensions::new(0., 0.); + + let font_store = match config.font_id { + 0 => font_store_clone.clone(), + 1 => font_store_math_clone.clone(), + _ => panic!("Unknown font {}", config.font_id), + }; + + let font = if let Some(font) = font_store.borrow_mut().get(config.font_size.into()) { + font + } else { + println!("Font not cached. Returning: {:?}", text_size); + return text_size; + }; + + let size = font.measure_text(text, config.font_size.into(), config.letter_spacing.into()); + + text_size.width = size.x; + text_size.height = size.y; + + println!("Measurements: {:?}", text_size); + + text_size + }); + + rl.set_target_fps(30); + + let mut debug = false; + + while !rl.window_should_close() { + if rl.is_window_resized() { + let size = (rl.get_screen_width() as f32 - 200., rl.get_screen_height() as f32); + clay.layout_dimensions(size.into()); + println!("Resized window to {:?}", size); + } + + { + font_store.borrow_mut().load_fonts(&mut rl, &thread)?; + font_store_math.borrow_mut().load_fonts(&mut rl, &thread)?; + } + + if rl.is_key_pressed(raylib::ffi::KeyboardKey::KEY_D) { + debug = !debug; + clay.reset_measure_text_cache(); + clay.enable_debug_mode(debug); + println!("Toggled debug mode to {debug}"); + } + + clay.set_debug_highlight((0xff, 0x0, 0x0).into()); + + clay.begin(); + + clay.with( + Declaration::new() + .id(clay.id("body")) + .layout() + .width(grow!(0.)) + .height(grow!(0.)) + .direction(LayoutDirection::TopToBottom) + .padding(Padding::all(8)) + .child_gap(0) + .end() + .scroll(false, true), + |clay| { + for i in 0..0 { + clay.with( + Declaration::new() + .id(clay.id(i.to_string().as_str())) + .layout() + .width(grow!(0.)) + .height(fit!(0.)) + .padding(Padding::all(4)) + .end(), + |clay| { + clay.text( + "test", + TextConfig::new() + .color((0x0, 0x0, 0x0).into()) + .font_size(16) + .end(), + ) + }, + ); + } + }, + ); + + let render_commands = clay.end(); + + let mut d = rl.begin_drawing(&thread); + + d.clear_background(Color::WHITE); + + /* + for (int j = 0; j < renderCommands.length; j++) + { + Clay_RenderCommand *renderCommand = Clay_RenderCommandArray_Get(&renderCommands, j); + Clay_BoundingBox boundingBox = renderCommand->boundingBox; + switch (renderCommand->commandType) + { + case CLAY_RENDER_COMMAND_TYPE_TEXT: { + // Raylib uses standard C strings so isn't compatible with cheap slices, we need to clone the string to append null terminator + Clay_TextRenderData *textData = &renderCommand->renderData.text; + char *cloned = (char *)malloc(textData->stringContents.length + 1); + memcpy(cloned, textData->stringContents.chars, textData->stringContents.length); + cloned[textData->stringContents.length] = '\0'; + Font fontToUse = fonts[textData->fontId]; + DrawTextEx(fontToUse, cloned, (Vector2){boundingBox.x, boundingBox.y}, (float)textData->fontSize, (float)textData->letterSpacing, CLAY_COLOR_TO_RAYLIB_COLOR(textData->textColor)); + free(cloned); + break; + } + case CLAY_RENDER_COMMAND_TYPE_IMAGE: { + Texture2D imageTexture = *(Texture2D *)renderCommand->renderData.image.imageData; + Clay_Color tintColor = renderCommand->renderData.image.backgroundColor; + if (tintColor.r == 0 && tintColor.g == 0 && tintColor.b == 0 && tintColor.a == 0) { + tintColor = (Clay_Color) { 255, 255, 255, 255 }; + } + DrawTextureEx( + imageTexture, + (Vector2){boundingBox.x, boundingBox.y}, + 0, + boundingBox.width / (float)imageTexture.width, + CLAY_COLOR_TO_RAYLIB_COLOR(tintColor)); + break; + } + case CLAY_RENDER_COMMAND_TYPE_RECTANGLE: { + break; + } + case CLAY_RENDER_COMMAND_TYPE_CUSTOM: { + Clay_CustomRenderData *config = &renderCommand->renderData.custom; + CustomLayoutElement *customElement = (CustomLayoutElement *)config->customData; + if (!customElement) continue; + switch (customElement->type) { + case CUSTOM_LAYOUT_ELEMENT_TYPE_3D_MODEL: { + Clay_BoundingBox rootBox = renderCommands.internalArray[0].boundingBox; + float scaleValue = CLAY__MIN(CLAY__MIN(1, 768 / rootBox.height) * CLAY__MAX(1, rootBox.width / 1024), 1.5f); + Ray positionRay = GetScreenToWorldPointWithZDistance((Vector2) { renderCommand->boundingBox.x + renderCommand->boundingBox.width / 2, renderCommand->boundingBox.y + (renderCommand->boundingBox.height / 2) + 20 }, Raylib_camera, (int)roundf(rootBox.width), (int)roundf(rootBox.height), 140); + BeginMode3D(Raylib_camera); + DrawModel(customElement->customData.model.model, positionRay.position, customElement->customData.model.scale * scaleValue, WHITE); // Draw 3d model with texture + EndMode3D(); + break; + } + default: break; + } + break; + } + default: { + printf("Error: unhandled render command."); + exit(1); + } + } + } + */ + + for command in render_commands { + match command.config { + RenderCommandConfig::Rectangle(rectangle) => { + println!("RECT!!! {}: {:?}\n{:?}\n\n", command.id, command.bounding_box, rectangle); + + d.draw_rectangle_rounded( + raylib::ffi::Rectangle { + x: command.bounding_box.x, + y: command.bounding_box.y, + width: command.bounding_box.width, + height: command.bounding_box.height, + }, + rectangle.corner_radii.top_left, + 8, + clay2ray(rectangle.color), + ); + } + RenderCommandConfig::Text(text) => { + // println!("{:?}", text); + font_store.borrow_mut().text( + &mut d, + text.text, + command.bounding_box.x, + command.bounding_box.y, + text.font_size as f32, + text.letter_spacing, + Some(clay2ray(text.color)), + ); + } + + RenderCommandConfig::ScissorStart() => unsafe { + raylib::ffi::BeginScissorMode( + command.bounding_box.x as i32, + command.bounding_box.y as i32, + command.bounding_box.width as i32, + command.bounding_box.height as i32, + ); + }, + RenderCommandConfig::ScissorEnd() => unsafe { + raylib::ffi::EndScissorMode(); + }, + + RenderCommandConfig::Border(border) => { + // if (config->cornerRadius.topLeft > 0) { + // DrawRing((Vector2) { roundf(boundingBox.x + config->cornerRadius.topLeft), roundf(boundingBox.y + config->cornerRadius.topLeft) }, roundf(config->cornerRadius.topLeft - config->width.top), config->cornerRadius.topLeft, 180, 270, 10, CLAY_COLOR_TO_RAYLIB_COLOR(config->color)); + // } + // if (config->cornerRadius.topRight > 0) { + // DrawRing((Vector2) { roundf(boundingBox.x + boundingBox.width - config->cornerRadius.topRight), roundf(boundingBox.y + config->cornerRadius.topRight) }, roundf(config->cornerRadius.topRight - config->width.top), config->cornerRadius.topRight, 270, 360, 10, CLAY_COLOR_TO_RAYLIB_COLOR(config->color)); + // } + // if (config->cornerRadius.bottomLeft > 0) { + // DrawRing((Vector2) { roundf(boundingBox.x + config->cornerRadius.bottomLeft), roundf(boundingBox.y + boundingBox.height - config->cornerRadius.bottomLeft) }, roundf(config->cornerRadius.bottomLeft - config->width.top), config->cornerRadius.bottomLeft, 90, 180, 10, CLAY_COLOR_TO_RAYLIB_COLOR(config->color)); + // } + // if (config->cornerRadius.bottomRight > 0) { + // DrawRing((Vector2) { roundf(boundingBox.x + boundingBox.width - config->cornerRadius.bottomRight), roundf(boundingBox.y + boundingBox.height - config->cornerRadius.bottomRight) }, roundf(config->cornerRadius.bottomRight - config->width.bottom), config->cornerRadius.bottomRight, 0.1, 90, 10, CLAY_COLOR_TO_RAYLIB_COLOR(config->color)); + // } + // break; + // } + // Left border + if border.width.left > 0 { + d.draw_rectangle( + command.bounding_box.x as i32, + (command.bounding_box.y + border.corner_radii.top_left) as i32, + border.width.left as i32, + (command.bounding_box.height + - border.corner_radii.top_left + - border.corner_radii.bottom_left) + as i32, + clay2ray(border.color), + ); + } + // Right border + if border.width.right > 0 { + d.draw_rectangle( + (command.bounding_box.x + command.bounding_box.width + - border.width.right as f32) as i32, + (command.bounding_box.y + border.corner_radii.top_right) as i32, + border.width.right as i32, + (command.bounding_box.height + - border.corner_radii.top_right + - border.corner_radii.bottom_right) + as i32, + clay2ray(border.color), + ); + } + // Top border + if border.width.top > 0 { + d.draw_rectangle( + (command.bounding_box.x + border.corner_radii.top_left) as i32, + (command.bounding_box.y) as i32, + (command.bounding_box.width + - border.corner_radii.top_left + - border.corner_radii.top_right) as i32, + (border.width.top) as i32, + clay2ray(border.color), + ); + } + // Top border + if border.width.bottom > 0 { + d.draw_rectangle( + (command.bounding_box.x + border.corner_radii.bottom_left) as i32, + (command.bounding_box.y + command.bounding_box.height + - border.width.bottom as f32) as i32, + (command.bounding_box.width + - border.corner_radii.bottom_left + - border.corner_radii.bottom_right) + as i32, + border.width.bottom as i32, + clay2ray(border.color), + ); + } + } + + RenderCommandConfig::None() => {} + _ => panic!("Unimplemented {:#?}", command), + } + } + } + + Ok(()) +} diff --git a/xits-italic.otf b/xits-italic.otf new file mode 100644 index 0000000..0c9802a Binary files /dev/null and b/xits-italic.otf differ diff --git a/xits-italic.ttf b/xits-italic.ttf new file mode 100644 index 0000000..10b9987 Binary files /dev/null and b/xits-italic.ttf differ