├── .github └── workflows │ └── rust.yml ├── .gitignore ├── Cargo.lock ├── Cargo.toml ├── LICENSE ├── README.md ├── benches └── nerf.rs ├── examples ├── background.rs ├── button.rs ├── padding.rs ├── scaffold.rs ├── sized_box.rs └── text.rs ├── flake.nix ├── shell.nix └── src ├── app.rs ├── app ├── app_context.rs ├── assets.rs ├── assets │ └── text_assets.rs ├── event.rs └── event │ └── mouse_position.rs ├── drawing.rs ├── drawing ├── canvas.rs ├── canvas │ └── text.rs └── color.rs ├── geometry.rs ├── geometry ├── alignment.rs ├── decoration.rs ├── rect.rs ├── screen_side.rs └── size_requirements.rs ├── lib.rs ├── utils.rs ├── utils ├── nonable.rs └── type_level_list.rs ├── widget.rs └── widget ├── default_widgets ├── align.rs ├── background.rs ├── button.rs ├── center.rs ├── empty.rs ├── expanded.rs ├── mod.rs ├── padder.rs ├── scaffold.rs └── sized_box.rs ├── skia_widgets └── mod.rs ├── svg_widgets └── mod.rs └── text_widgets ├── mod.rs ├── text.rs ├── text └── text_overflow.rs ├── text_style.rs └── text_style └── font_family.rs /.github/workflows/rust.yml: -------------------------------------------------------------------------------- 1 | name: Rust 2 | 3 | on: 4 | push: 5 | branches: [ "main" ] 6 | pull_request: 7 | branches: [ "main" ] 8 | 9 | env: 10 | CARGO_TERM_COLOR: always 11 | 12 | jobs: 13 | build: 14 | 15 | runs-on: ubuntu-latest 16 | 17 | steps: 18 | - uses: actions/checkout@v3 19 | - name: Build 20 | run: cargo build --verbose 21 | - name: Run tests 22 | run: cargo test --verbose 23 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | .vscode/ 3 | .idea/ -------------------------------------------------------------------------------- /Cargo.lock: -------------------------------------------------------------------------------- 1 | # This file is automatically @generated by Cargo. 2 | # It is not intended for manual editing. 3 | version = 3 4 | 5 | [[package]] 6 | name = "ab_glyph" 7 | version = "0.2.21" 8 | source = "registry+https://github.com/rust-lang/crates.io-index" 9 | checksum = "5110f1c78cf582855d895ecd0746b653db010cec6d9f5575293f27934d980a39" 10 | dependencies = [ 11 | "ab_glyph_rasterizer", 12 | "owned_ttf_parser", 13 | ] 14 | 15 | [[package]] 16 | name = "ab_glyph_rasterizer" 17 | version = "0.1.8" 18 | source = "registry+https://github.com/rust-lang/crates.io-index" 19 | checksum = "c71b1793ee61086797f5c80b6efa2b8ffa6d5dd703f118545808a7f2e27f7046" 20 | 21 | [[package]] 22 | name = "adler" 23 | version = "1.0.2" 24 | source = "registry+https://github.com/rust-lang/crates.io-index" 25 | checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" 26 | 27 | [[package]] 28 | name = "ahash" 29 | version = "0.7.6" 30 | source = "registry+https://github.com/rust-lang/crates.io-index" 31 | checksum = "fcb51a0695d8f838b1ee009b3fbf66bda078cd64590202a864a8f3e8c4315c47" 32 | dependencies = [ 33 | "getrandom", 34 | "once_cell", 35 | "version_check", 36 | ] 37 | 38 | [[package]] 39 | name = "ahash" 40 | version = "0.8.11" 41 | source = "registry+https://github.com/rust-lang/crates.io-index" 42 | checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" 43 | dependencies = [ 44 | "cfg-if", 45 | "getrandom", 46 | "once_cell", 47 | "version_check", 48 | "zerocopy", 49 | ] 50 | 51 | [[package]] 52 | name = "aho-corasick" 53 | version = "1.0.2" 54 | source = "registry+https://github.com/rust-lang/crates.io-index" 55 | checksum = "43f6cb1bf222025340178f382c426f13757b2960e89779dfcb319c32542a5a41" 56 | dependencies = [ 57 | "memchr", 58 | ] 59 | 60 | [[package]] 61 | name = "aliasable" 62 | version = "0.1.3" 63 | source = "registry+https://github.com/rust-lang/crates.io-index" 64 | checksum = "250f629c0161ad8107cf89319e990051fae62832fd343083bea452d93e2205fd" 65 | 66 | [[package]] 67 | name = "android-activity" 68 | version = "0.6.0" 69 | source = "registry+https://github.com/rust-lang/crates.io-index" 70 | checksum = "ef6978589202a00cd7e118380c448a08b6ed394c3a8df3a430d0898e3a42d046" 71 | dependencies = [ 72 | "android-properties", 73 | "bitflags 2.5.0", 74 | "cc", 75 | "cesu8", 76 | "jni", 77 | "jni-sys", 78 | "libc", 79 | "log", 80 | "ndk", 81 | "ndk-context", 82 | "ndk-sys", 83 | "num_enum", 84 | "thiserror", 85 | ] 86 | 87 | [[package]] 88 | name = "android-properties" 89 | version = "0.2.2" 90 | source = "registry+https://github.com/rust-lang/crates.io-index" 91 | checksum = "fc7eb209b1518d6bb87b283c20095f5228ecda460da70b44f0802523dea6da04" 92 | 93 | [[package]] 94 | name = "arrayref" 95 | version = "0.3.7" 96 | source = "registry+https://github.com/rust-lang/crates.io-index" 97 | checksum = "6b4930d2cb77ce62f89ee5d5289b4ac049559b1c45539271f5ed4fdc7db34545" 98 | 99 | [[package]] 100 | name = "arrayvec" 101 | version = "0.7.4" 102 | source = "registry+https://github.com/rust-lang/crates.io-index" 103 | checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" 104 | 105 | [[package]] 106 | name = "as-raw-xcb-connection" 107 | version = "1.0.0" 108 | source = "registry+https://github.com/rust-lang/crates.io-index" 109 | checksum = "2d5f312b0a56c5cdf967c0aeb67f6289603354951683bc97ddc595ab974ba9aa" 110 | 111 | [[package]] 112 | name = "atomic-waker" 113 | version = "1.1.2" 114 | source = "registry+https://github.com/rust-lang/crates.io-index" 115 | checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" 116 | 117 | [[package]] 118 | name = "autocfg" 119 | version = "1.1.0" 120 | source = "registry+https://github.com/rust-lang/crates.io-index" 121 | checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" 122 | 123 | [[package]] 124 | name = "bitflags" 125 | version = "1.3.2" 126 | source = "registry+https://github.com/rust-lang/crates.io-index" 127 | checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" 128 | 129 | [[package]] 130 | name = "bitflags" 131 | version = "2.5.0" 132 | source = "registry+https://github.com/rust-lang/crates.io-index" 133 | checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" 134 | 135 | [[package]] 136 | name = "block2" 137 | version = "0.5.0" 138 | source = "registry+https://github.com/rust-lang/crates.io-index" 139 | checksum = "43ff7d91d3c1d568065b06c899777d1e48dcf76103a672a0adbc238a7f247f1e" 140 | dependencies = [ 141 | "objc2", 142 | ] 143 | 144 | [[package]] 145 | name = "bumpalo" 146 | version = "3.13.0" 147 | source = "registry+https://github.com/rust-lang/crates.io-index" 148 | checksum = "a3e2c3daef883ecc1b5d58c15adae93470a91d425f3532ba1695849656af3fc1" 149 | 150 | [[package]] 151 | name = "bytemuck" 152 | version = "1.13.1" 153 | source = "registry+https://github.com/rust-lang/crates.io-index" 154 | checksum = "17febce684fd15d89027105661fec94afb475cb995fbc59d2865198446ba2eea" 155 | dependencies = [ 156 | "bytemuck_derive", 157 | ] 158 | 159 | [[package]] 160 | name = "bytemuck_derive" 161 | version = "1.6.0" 162 | source = "registry+https://github.com/rust-lang/crates.io-index" 163 | checksum = "4da9a32f3fed317401fa3c862968128267c3106685286e15d5aaa3d7389c2f60" 164 | dependencies = [ 165 | "proc-macro2", 166 | "quote", 167 | "syn", 168 | ] 169 | 170 | [[package]] 171 | name = "bytes" 172 | version = "1.6.0" 173 | source = "registry+https://github.com/rust-lang/crates.io-index" 174 | checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" 175 | 176 | [[package]] 177 | name = "calloop" 178 | version = "0.12.4" 179 | source = "registry+https://github.com/rust-lang/crates.io-index" 180 | checksum = "fba7adb4dd5aa98e5553510223000e7148f621165ec5f9acd7113f6ca4995298" 181 | dependencies = [ 182 | "bitflags 2.5.0", 183 | "log", 184 | "polling", 185 | "rustix", 186 | "slab", 187 | "thiserror", 188 | ] 189 | 190 | [[package]] 191 | name = "calloop-wayland-source" 192 | version = "0.2.0" 193 | source = "registry+https://github.com/rust-lang/crates.io-index" 194 | checksum = "0f0ea9b9476c7fad82841a8dbb380e2eae480c21910feba80725b46931ed8f02" 195 | dependencies = [ 196 | "calloop", 197 | "rustix", 198 | "wayland-backend", 199 | "wayland-client", 200 | ] 201 | 202 | [[package]] 203 | name = "cc" 204 | version = "1.0.79" 205 | source = "registry+https://github.com/rust-lang/crates.io-index" 206 | checksum = "50d30906286121d95be3d479533b458f87493b30a4b5f79a607db8f5d11aa91f" 207 | dependencies = [ 208 | "jobserver", 209 | ] 210 | 211 | [[package]] 212 | name = "cesu8" 213 | version = "1.1.0" 214 | source = "registry+https://github.com/rust-lang/crates.io-index" 215 | checksum = "6d43a04d8753f35258c91f8ec639f792891f748a1edbd759cf1dcea3382ad83c" 216 | 217 | [[package]] 218 | name = "cfg-if" 219 | version = "1.0.0" 220 | source = "registry+https://github.com/rust-lang/crates.io-index" 221 | checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" 222 | 223 | [[package]] 224 | name = "cfg_aliases" 225 | version = "0.2.1" 226 | source = "registry+https://github.com/rust-lang/crates.io-index" 227 | checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724" 228 | 229 | [[package]] 230 | name = "combine" 231 | version = "4.6.7" 232 | source = "registry+https://github.com/rust-lang/crates.io-index" 233 | checksum = "ba5a308b75df32fe02788e748662718f03fde005016435c444eea572398219fd" 234 | dependencies = [ 235 | "bytes", 236 | "memchr", 237 | ] 238 | 239 | [[package]] 240 | name = "concurrent-queue" 241 | version = "2.5.0" 242 | source = "registry+https://github.com/rust-lang/crates.io-index" 243 | checksum = "4ca0197aee26d1ae37445ee532fefce43251d24cc7c166799f4d46817f1d3973" 244 | dependencies = [ 245 | "crossbeam-utils", 246 | ] 247 | 248 | [[package]] 249 | name = "core-foundation" 250 | version = "0.9.3" 251 | source = "registry+https://github.com/rust-lang/crates.io-index" 252 | checksum = "194a7a9e6de53fa55116934067c844d9d749312f75c6f6d0980e8c252f8c2146" 253 | dependencies = [ 254 | "core-foundation-sys", 255 | "libc", 256 | ] 257 | 258 | [[package]] 259 | name = "core-foundation-sys" 260 | version = "0.8.4" 261 | source = "registry+https://github.com/rust-lang/crates.io-index" 262 | checksum = "e496a50fda8aacccc86d7529e2c1e0892dbd0f898a6b5645b5561b89c3210efa" 263 | 264 | [[package]] 265 | name = "core-graphics" 266 | version = "0.23.1" 267 | source = "registry+https://github.com/rust-lang/crates.io-index" 268 | checksum = "970a29baf4110c26fedbc7f82107d42c23f7e88e404c4577ed73fe99ff85a212" 269 | dependencies = [ 270 | "bitflags 1.3.2", 271 | "core-foundation", 272 | "core-graphics-types", 273 | "foreign-types", 274 | "libc", 275 | ] 276 | 277 | [[package]] 278 | name = "core-graphics-types" 279 | version = "0.1.2" 280 | source = "registry+https://github.com/rust-lang/crates.io-index" 281 | checksum = "2bb142d41022986c1d8ff29103a1411c8a3dfad3552f87a4f8dc50d61d4f4e33" 282 | dependencies = [ 283 | "bitflags 1.3.2", 284 | "core-foundation", 285 | "libc", 286 | ] 287 | 288 | [[package]] 289 | name = "cosmic-text" 290 | version = "0.9.0" 291 | source = "registry+https://github.com/rust-lang/crates.io-index" 292 | checksum = "b0b68966c2543609f8d92f9d33ac3b719b2a67529b0c6c0b3e025637b477eef9" 293 | dependencies = [ 294 | "aliasable", 295 | "fontdb", 296 | "libm", 297 | "log", 298 | "rangemap", 299 | "rustybuzz", 300 | "swash", 301 | "sys-locale", 302 | "unicode-bidi", 303 | "unicode-linebreak", 304 | "unicode-script", 305 | "unicode-segmentation", 306 | ] 307 | 308 | [[package]] 309 | name = "crc32fast" 310 | version = "1.3.2" 311 | source = "registry+https://github.com/rust-lang/crates.io-index" 312 | checksum = "b540bd8bc810d3885c6ea91e2018302f68baba2129ab3e88f32389ee9370880d" 313 | dependencies = [ 314 | "cfg-if", 315 | ] 316 | 317 | [[package]] 318 | name = "crossbeam-utils" 319 | version = "0.8.16" 320 | source = "registry+https://github.com/rust-lang/crates.io-index" 321 | checksum = "5a22b2d63d4d1dc0b7f1b6b2747dd0088008a9be28b6ddf0b1e7d335e3037294" 322 | dependencies = [ 323 | "cfg-if", 324 | ] 325 | 326 | [[package]] 327 | name = "ctor" 328 | version = "0.2.8" 329 | source = "registry+https://github.com/rust-lang/crates.io-index" 330 | checksum = "edb49164822f3ee45b17acd4a208cfc1251410cf0cad9a833234c9890774dd9f" 331 | dependencies = [ 332 | "quote", 333 | "syn", 334 | ] 335 | 336 | [[package]] 337 | name = "cursor-icon" 338 | version = "1.1.0" 339 | source = "registry+https://github.com/rust-lang/crates.io-index" 340 | checksum = "96a6ac251f4a2aca6b3f91340350eab87ae57c3f127ffeb585e92bd336717991" 341 | 342 | [[package]] 343 | name = "dispatch" 344 | version = "0.2.0" 345 | source = "registry+https://github.com/rust-lang/crates.io-index" 346 | checksum = "bd0c93bb4b0c6d9b77f4435b0ae98c24d17f1c45b2ff844c6151a07256ca923b" 347 | 348 | [[package]] 349 | name = "dlib" 350 | version = "0.5.2" 351 | source = "registry+https://github.com/rust-lang/crates.io-index" 352 | checksum = "330c60081dcc4c72131f8eb70510f1ac07223e5d4163db481a04a0befcffa412" 353 | dependencies = [ 354 | "libloading", 355 | ] 356 | 357 | [[package]] 358 | name = "downcast-rs" 359 | version = "1.2.0" 360 | source = "registry+https://github.com/rust-lang/crates.io-index" 361 | checksum = "9ea835d29036a4087793836fa931b08837ad5e957da9e23886b29586fb9b6650" 362 | 363 | [[package]] 364 | name = "dpi" 365 | version = "0.1.1" 366 | source = "registry+https://github.com/rust-lang/crates.io-index" 367 | checksum = "f25c0e292a7ca6d6498557ff1df68f32c99850012b6ea401cf8daf771f22ff53" 368 | 369 | [[package]] 370 | name = "drm" 371 | version = "0.12.0" 372 | source = "registry+https://github.com/rust-lang/crates.io-index" 373 | checksum = "98888c4bbd601524c11a7ed63f814b8825f420514f78e96f752c437ae9cbb5d1" 374 | dependencies = [ 375 | "bitflags 2.5.0", 376 | "bytemuck", 377 | "drm-ffi", 378 | "drm-fourcc", 379 | "rustix", 380 | ] 381 | 382 | [[package]] 383 | name = "drm-ffi" 384 | version = "0.8.0" 385 | source = "registry+https://github.com/rust-lang/crates.io-index" 386 | checksum = "97c98727e48b7ccb4f4aea8cfe881e5b07f702d17b7875991881b41af7278d53" 387 | dependencies = [ 388 | "drm-sys", 389 | "rustix", 390 | ] 391 | 392 | [[package]] 393 | name = "drm-fourcc" 394 | version = "2.2.0" 395 | source = "registry+https://github.com/rust-lang/crates.io-index" 396 | checksum = "0aafbcdb8afc29c1a7ee5fbe53b5d62f4565b35a042a662ca9fecd0b54dae6f4" 397 | 398 | [[package]] 399 | name = "drm-sys" 400 | version = "0.7.0" 401 | source = "registry+https://github.com/rust-lang/crates.io-index" 402 | checksum = "fd39dde40b6e196c2e8763f23d119ddb1a8714534bf7d77fa97a65b0feda3986" 403 | dependencies = [ 404 | "libc", 405 | "linux-raw-sys 0.6.4", 406 | ] 407 | 408 | [[package]] 409 | name = "equivalent" 410 | version = "1.0.1" 411 | source = "registry+https://github.com/rust-lang/crates.io-index" 412 | checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" 413 | 414 | [[package]] 415 | name = "errno" 416 | version = "0.3.9" 417 | source = "registry+https://github.com/rust-lang/crates.io-index" 418 | checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" 419 | dependencies = [ 420 | "libc", 421 | "windows-sys 0.52.0", 422 | ] 423 | 424 | [[package]] 425 | name = "fastrand" 426 | version = "2.1.0" 427 | source = "registry+https://github.com/rust-lang/crates.io-index" 428 | checksum = "9fc0510504f03c51ada170672ac806f1f105a88aa97a5281117e1ddc3368e51a" 429 | 430 | [[package]] 431 | name = "fdeflate" 432 | version = "0.3.0" 433 | source = "registry+https://github.com/rust-lang/crates.io-index" 434 | checksum = "d329bdeac514ee06249dabc27877490f17f5d371ec693360768b838e19f3ae10" 435 | dependencies = [ 436 | "simd-adler32", 437 | ] 438 | 439 | [[package]] 440 | name = "flate2" 441 | version = "1.0.26" 442 | source = "registry+https://github.com/rust-lang/crates.io-index" 443 | checksum = "3b9429470923de8e8cbd4d2dc513535400b4b3fef0319fb5c4e1f520a7bef743" 444 | dependencies = [ 445 | "crc32fast", 446 | "miniz_oxide", 447 | ] 448 | 449 | [[package]] 450 | name = "fontdb" 451 | version = "0.14.1" 452 | source = "registry+https://github.com/rust-lang/crates.io-index" 453 | checksum = "af8d8cbea8f21307d7e84bca254772981296f058a1d36b461bf4d83a7499fc9e" 454 | dependencies = [ 455 | "log", 456 | "memmap2 0.6.2", 457 | "slotmap", 458 | "tinyvec", 459 | "ttf-parser", 460 | ] 461 | 462 | [[package]] 463 | name = "foreign-types" 464 | version = "0.5.0" 465 | source = "registry+https://github.com/rust-lang/crates.io-index" 466 | checksum = "d737d9aa519fb7b749cbc3b962edcf310a8dd1f4b67c91c4f83975dbdd17d965" 467 | dependencies = [ 468 | "foreign-types-macros", 469 | "foreign-types-shared", 470 | ] 471 | 472 | [[package]] 473 | name = "foreign-types-macros" 474 | version = "0.2.3" 475 | source = "registry+https://github.com/rust-lang/crates.io-index" 476 | checksum = "1a5c6c585bc94aaf2c7b51dd4c2ba22680844aba4c687be581871a6f518c5742" 477 | dependencies = [ 478 | "proc-macro2", 479 | "quote", 480 | "syn", 481 | ] 482 | 483 | [[package]] 484 | name = "foreign-types-shared" 485 | version = "0.3.1" 486 | source = "registry+https://github.com/rust-lang/crates.io-index" 487 | checksum = "aa9a19cbb55df58761df49b23516a86d432839add4af60fc256da840f66ed35b" 488 | 489 | [[package]] 490 | name = "gethostname" 491 | version = "0.4.3" 492 | source = "registry+https://github.com/rust-lang/crates.io-index" 493 | checksum = "0176e0459c2e4a1fe232f984bca6890e681076abb9934f6cea7c326f3fc47818" 494 | dependencies = [ 495 | "libc", 496 | "windows-targets 0.48.1", 497 | ] 498 | 499 | [[package]] 500 | name = "getrandom" 501 | version = "0.2.10" 502 | source = "registry+https://github.com/rust-lang/crates.io-index" 503 | checksum = "be4136b2a15dd319360be1c07d9933517ccf0be8f16bf62a3bee4f0d618df427" 504 | dependencies = [ 505 | "cfg-if", 506 | "libc", 507 | "wasi", 508 | ] 509 | 510 | [[package]] 511 | name = "hashbrown" 512 | version = "0.12.3" 513 | source = "registry+https://github.com/rust-lang/crates.io-index" 514 | checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" 515 | dependencies = [ 516 | "ahash 0.7.6", 517 | ] 518 | 519 | [[package]] 520 | name = "hashbrown" 521 | version = "0.14.0" 522 | source = "registry+https://github.com/rust-lang/crates.io-index" 523 | checksum = "2c6201b9ff9fd90a5a3bac2e56a830d0caa509576f0e503818ee82c181b3437a" 524 | 525 | [[package]] 526 | name = "hermit-abi" 527 | version = "0.3.9" 528 | source = "registry+https://github.com/rust-lang/crates.io-index" 529 | checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" 530 | 531 | [[package]] 532 | name = "indexmap" 533 | version = "2.0.0" 534 | source = "registry+https://github.com/rust-lang/crates.io-index" 535 | checksum = "d5477fe2230a79769d8dc68e0eabf5437907c0457a5614a9e8dddb67f65eb65d" 536 | dependencies = [ 537 | "equivalent", 538 | "hashbrown 0.14.0", 539 | ] 540 | 541 | [[package]] 542 | name = "jni" 543 | version = "0.21.1" 544 | source = "registry+https://github.com/rust-lang/crates.io-index" 545 | checksum = "1a87aa2bb7d2af34197c04845522473242e1aa17c12f4935d5856491a7fb8c97" 546 | dependencies = [ 547 | "cesu8", 548 | "cfg-if", 549 | "combine", 550 | "jni-sys", 551 | "log", 552 | "thiserror", 553 | "walkdir", 554 | "windows-sys 0.45.0", 555 | ] 556 | 557 | [[package]] 558 | name = "jni-sys" 559 | version = "0.3.0" 560 | source = "registry+https://github.com/rust-lang/crates.io-index" 561 | checksum = "8eaf4bc02d17cbdd7ff4c7438cafcdf7fb9a4613313ad11b4f8fefe7d3fa0130" 562 | 563 | [[package]] 564 | name = "jobserver" 565 | version = "0.1.26" 566 | source = "registry+https://github.com/rust-lang/crates.io-index" 567 | checksum = "936cfd212a0155903bcbc060e316fb6cc7cbf2e1907329391ebadc1fe0ce77c2" 568 | dependencies = [ 569 | "libc", 570 | ] 571 | 572 | [[package]] 573 | name = "js-sys" 574 | version = "0.3.64" 575 | source = "registry+https://github.com/rust-lang/crates.io-index" 576 | checksum = "c5f195fe497f702db0f318b07fdd68edb16955aed830df8363d837542f8f935a" 577 | dependencies = [ 578 | "wasm-bindgen", 579 | ] 580 | 581 | [[package]] 582 | name = "libc" 583 | version = "0.2.155" 584 | source = "registry+https://github.com/rust-lang/crates.io-index" 585 | checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" 586 | 587 | [[package]] 588 | name = "libloading" 589 | version = "0.8.0" 590 | source = "registry+https://github.com/rust-lang/crates.io-index" 591 | checksum = "d580318f95776505201b28cf98eb1fa5e4be3b689633ba6a3e6cd880ff22d8cb" 592 | dependencies = [ 593 | "cfg-if", 594 | "windows-sys 0.48.0", 595 | ] 596 | 597 | [[package]] 598 | name = "libm" 599 | version = "0.2.7" 600 | source = "registry+https://github.com/rust-lang/crates.io-index" 601 | checksum = "f7012b1bbb0719e1097c47611d3898568c546d597c2e74d66f6087edd5233ff4" 602 | 603 | [[package]] 604 | name = "libredox" 605 | version = "0.0.2" 606 | source = "registry+https://github.com/rust-lang/crates.io-index" 607 | checksum = "3af92c55d7d839293953fcd0fda5ecfe93297cfde6ffbdec13b41d99c0ba6607" 608 | dependencies = [ 609 | "bitflags 2.5.0", 610 | "libc", 611 | "redox_syscall 0.4.1", 612 | ] 613 | 614 | [[package]] 615 | name = "linux-raw-sys" 616 | version = "0.4.14" 617 | source = "registry+https://github.com/rust-lang/crates.io-index" 618 | checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" 619 | 620 | [[package]] 621 | name = "linux-raw-sys" 622 | version = "0.6.4" 623 | source = "registry+https://github.com/rust-lang/crates.io-index" 624 | checksum = "f0b5399f6804fbab912acbd8878ed3532d506b7c951b8f9f164ef90fef39e3f4" 625 | 626 | [[package]] 627 | name = "log" 628 | version = "0.4.19" 629 | source = "registry+https://github.com/rust-lang/crates.io-index" 630 | checksum = "b06a4cde4c0f271a446782e3eff8de789548ce57dbc8eca9292c27f4a42004b4" 631 | 632 | [[package]] 633 | name = "memchr" 634 | version = "2.5.0" 635 | source = "registry+https://github.com/rust-lang/crates.io-index" 636 | checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" 637 | 638 | [[package]] 639 | name = "memmap2" 640 | version = "0.6.2" 641 | source = "registry+https://github.com/rust-lang/crates.io-index" 642 | checksum = "6d28bba84adfe6646737845bc5ebbfa2c08424eb1c37e94a1fd2a82adb56a872" 643 | dependencies = [ 644 | "libc", 645 | ] 646 | 647 | [[package]] 648 | name = "memmap2" 649 | version = "0.9.4" 650 | source = "registry+https://github.com/rust-lang/crates.io-index" 651 | checksum = "fe751422e4a8caa417e13c3ea66452215d7d63e19e604f4980461212f3ae1322" 652 | dependencies = [ 653 | "libc", 654 | ] 655 | 656 | [[package]] 657 | name = "minimal-lexical" 658 | version = "0.2.1" 659 | source = "registry+https://github.com/rust-lang/crates.io-index" 660 | checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" 661 | 662 | [[package]] 663 | name = "miniz_oxide" 664 | version = "0.7.1" 665 | source = "registry+https://github.com/rust-lang/crates.io-index" 666 | checksum = "e7810e0be55b428ada41041c41f32c9f1a42817901b4ccf45fa3d4b6561e74c7" 667 | dependencies = [ 668 | "adler", 669 | "simd-adler32", 670 | ] 671 | 672 | [[package]] 673 | name = "ndk" 674 | version = "0.9.0" 675 | source = "registry+https://github.com/rust-lang/crates.io-index" 676 | checksum = "c3f42e7bbe13d351b6bead8286a43aac9534b82bd3cc43e47037f012ebfd62d4" 677 | dependencies = [ 678 | "bitflags 2.5.0", 679 | "jni-sys", 680 | "log", 681 | "ndk-sys", 682 | "num_enum", 683 | "raw-window-handle", 684 | "thiserror", 685 | ] 686 | 687 | [[package]] 688 | name = "ndk-context" 689 | version = "0.1.1" 690 | source = "registry+https://github.com/rust-lang/crates.io-index" 691 | checksum = "27b02d87554356db9e9a873add8782d4ea6e3e58ea071a9adb9a2e8ddb884a8b" 692 | 693 | [[package]] 694 | name = "ndk-sys" 695 | version = "0.6.0+11769913" 696 | source = "registry+https://github.com/rust-lang/crates.io-index" 697 | checksum = "ee6cda3051665f1fb8d9e08fc35c96d5a244fb1be711a03b71118828afc9a873" 698 | dependencies = [ 699 | "jni-sys", 700 | ] 701 | 702 | [[package]] 703 | name = "nerf" 704 | version = "0.2.0" 705 | dependencies = [ 706 | "cosmic-text", 707 | "softbuffer", 708 | "tiny-skia", 709 | "winit", 710 | ] 711 | 712 | [[package]] 713 | name = "nom" 714 | version = "7.1.3" 715 | source = "registry+https://github.com/rust-lang/crates.io-index" 716 | checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a" 717 | dependencies = [ 718 | "memchr", 719 | "minimal-lexical", 720 | ] 721 | 722 | [[package]] 723 | name = "num_enum" 724 | version = "0.7.2" 725 | source = "registry+https://github.com/rust-lang/crates.io-index" 726 | checksum = "02339744ee7253741199f897151b38e72257d13802d4ee837285cc2990a90845" 727 | dependencies = [ 728 | "num_enum_derive", 729 | ] 730 | 731 | [[package]] 732 | name = "num_enum_derive" 733 | version = "0.7.2" 734 | source = "registry+https://github.com/rust-lang/crates.io-index" 735 | checksum = "681030a937600a36906c185595136d26abfebb4aa9c65701cefcaf8578bb982b" 736 | dependencies = [ 737 | "proc-macro-crate", 738 | "proc-macro2", 739 | "quote", 740 | "syn", 741 | ] 742 | 743 | [[package]] 744 | name = "objc-sys" 745 | version = "0.3.3" 746 | source = "registry+https://github.com/rust-lang/crates.io-index" 747 | checksum = "da284c198fb9b7b0603f8635185e85fbd5b64ee154b1ed406d489077de2d6d60" 748 | 749 | [[package]] 750 | name = "objc2" 751 | version = "0.5.1" 752 | source = "registry+https://github.com/rust-lang/crates.io-index" 753 | checksum = "b4b25e1034d0e636cd84707ccdaa9f81243d399196b8a773946dcffec0401659" 754 | dependencies = [ 755 | "objc-sys", 756 | "objc2-encode", 757 | ] 758 | 759 | [[package]] 760 | name = "objc2-app-kit" 761 | version = "0.2.0" 762 | source = "registry+https://github.com/rust-lang/crates.io-index" 763 | checksum = "fb79768a710a9a1798848179edb186d1af7e8a8679f369e4b8d201dd2a034047" 764 | dependencies = [ 765 | "block2", 766 | "objc2", 767 | "objc2-core-data", 768 | "objc2-foundation", 769 | ] 770 | 771 | [[package]] 772 | name = "objc2-core-data" 773 | version = "0.2.0" 774 | source = "registry+https://github.com/rust-lang/crates.io-index" 775 | checksum = "6e092bc42eaf30a08844e6a076938c60751225ec81431ab89f5d1ccd9f958d6c" 776 | dependencies = [ 777 | "block2", 778 | "objc2", 779 | "objc2-foundation", 780 | ] 781 | 782 | [[package]] 783 | name = "objc2-encode" 784 | version = "4.0.1" 785 | source = "registry+https://github.com/rust-lang/crates.io-index" 786 | checksum = "88658da63e4cc2c8adb1262902cd6af51094df0488b760d6fd27194269c0950a" 787 | 788 | [[package]] 789 | name = "objc2-foundation" 790 | version = "0.2.0" 791 | source = "registry+https://github.com/rust-lang/crates.io-index" 792 | checksum = "cfaefe14254871ea16c7d88968c0ff14ba554712a20d76421eec52f0a7fb8904" 793 | dependencies = [ 794 | "block2", 795 | "dispatch", 796 | "objc2", 797 | ] 798 | 799 | [[package]] 800 | name = "objc2-quartz-core" 801 | version = "0.2.0" 802 | source = "registry+https://github.com/rust-lang/crates.io-index" 803 | checksum = "153140331e87b21327f0be072ac7108e67b43986f64098e937077b1eed6e3191" 804 | dependencies = [ 805 | "objc2", 806 | "objc2-foundation", 807 | ] 808 | 809 | [[package]] 810 | name = "once_cell" 811 | version = "1.19.0" 812 | source = "registry+https://github.com/rust-lang/crates.io-index" 813 | checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" 814 | 815 | [[package]] 816 | name = "orbclient" 817 | version = "0.3.47" 818 | source = "registry+https://github.com/rust-lang/crates.io-index" 819 | checksum = "52f0d54bde9774d3a51dcf281a5def240c71996bc6ca05d2c847ec8b2b216166" 820 | dependencies = [ 821 | "libredox", 822 | ] 823 | 824 | [[package]] 825 | name = "owned_ttf_parser" 826 | version = "0.19.0" 827 | source = "registry+https://github.com/rust-lang/crates.io-index" 828 | checksum = "706de7e2214113d63a8238d1910463cfce781129a6f263d13fdb09ff64355ba4" 829 | dependencies = [ 830 | "ttf-parser", 831 | ] 832 | 833 | [[package]] 834 | name = "percent-encoding" 835 | version = "2.3.0" 836 | source = "registry+https://github.com/rust-lang/crates.io-index" 837 | checksum = "9b2a4787296e9989611394c33f193f676704af1686e70b8f8033ab5ba9a35a94" 838 | 839 | [[package]] 840 | name = "pin-project" 841 | version = "1.1.5" 842 | source = "registry+https://github.com/rust-lang/crates.io-index" 843 | checksum = "b6bf43b791c5b9e34c3d182969b4abb522f9343702850a2e57f460d00d09b4b3" 844 | dependencies = [ 845 | "pin-project-internal", 846 | ] 847 | 848 | [[package]] 849 | name = "pin-project-internal" 850 | version = "1.1.5" 851 | source = "registry+https://github.com/rust-lang/crates.io-index" 852 | checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965" 853 | dependencies = [ 854 | "proc-macro2", 855 | "quote", 856 | "syn", 857 | ] 858 | 859 | [[package]] 860 | name = "pin-project-lite" 861 | version = "0.2.14" 862 | source = "registry+https://github.com/rust-lang/crates.io-index" 863 | checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" 864 | 865 | [[package]] 866 | name = "pkg-config" 867 | version = "0.3.27" 868 | source = "registry+https://github.com/rust-lang/crates.io-index" 869 | checksum = "26072860ba924cbfa98ea39c8c19b4dd6a4a25423dbdf219c1eca91aa0cf6964" 870 | 871 | [[package]] 872 | name = "png" 873 | version = "0.17.9" 874 | source = "registry+https://github.com/rust-lang/crates.io-index" 875 | checksum = "59871cc5b6cce7eaccca5a802b4173377a1c2ba90654246789a8fa2334426d11" 876 | dependencies = [ 877 | "bitflags 1.3.2", 878 | "crc32fast", 879 | "fdeflate", 880 | "flate2", 881 | "miniz_oxide", 882 | ] 883 | 884 | [[package]] 885 | name = "polling" 886 | version = "3.7.0" 887 | source = "registry+https://github.com/rust-lang/crates.io-index" 888 | checksum = "645493cf344456ef24219d02a768cf1fb92ddf8c92161679ae3d91b91a637be3" 889 | dependencies = [ 890 | "cfg-if", 891 | "concurrent-queue", 892 | "hermit-abi", 893 | "pin-project-lite", 894 | "rustix", 895 | "tracing", 896 | "windows-sys 0.52.0", 897 | ] 898 | 899 | [[package]] 900 | name = "proc-macro-crate" 901 | version = "1.3.1" 902 | source = "registry+https://github.com/rust-lang/crates.io-index" 903 | checksum = "7f4c021e1093a56626774e81216a4ce732a735e5bad4868a03f3ed65ca0c3919" 904 | dependencies = [ 905 | "once_cell", 906 | "toml_edit", 907 | ] 908 | 909 | [[package]] 910 | name = "proc-macro2" 911 | version = "1.0.64" 912 | source = "registry+https://github.com/rust-lang/crates.io-index" 913 | checksum = "78803b62cbf1f46fde80d7c0e803111524b9877184cfe7c3033659490ac7a7da" 914 | dependencies = [ 915 | "unicode-ident", 916 | ] 917 | 918 | [[package]] 919 | name = "quick-xml" 920 | version = "0.31.0" 921 | source = "registry+https://github.com/rust-lang/crates.io-index" 922 | checksum = "1004a344b30a54e2ee58d66a71b32d2db2feb0a31f9a2d302bf0536f15de2a33" 923 | dependencies = [ 924 | "memchr", 925 | ] 926 | 927 | [[package]] 928 | name = "quote" 929 | version = "1.0.29" 930 | source = "registry+https://github.com/rust-lang/crates.io-index" 931 | checksum = "573015e8ab27661678357f27dc26460738fd2b6c86e46f386fde94cb5d913105" 932 | dependencies = [ 933 | "proc-macro2", 934 | ] 935 | 936 | [[package]] 937 | name = "rangemap" 938 | version = "1.3.0" 939 | source = "registry+https://github.com/rust-lang/crates.io-index" 940 | checksum = "8b9283c6b06096b47afc7109834fdedab891175bb5241ee5d4f7d2546549f263" 941 | 942 | [[package]] 943 | name = "raw-window-handle" 944 | version = "0.6.2" 945 | source = "registry+https://github.com/rust-lang/crates.io-index" 946 | checksum = "20675572f6f24e9e76ef639bc5552774ed45f1c30e2951e1e99c59888861c539" 947 | 948 | [[package]] 949 | name = "redox_syscall" 950 | version = "0.4.1" 951 | source = "registry+https://github.com/rust-lang/crates.io-index" 952 | checksum = "4722d768eff46b75989dd134e5c353f0d6296e5aaa3132e776cbdb56be7731aa" 953 | dependencies = [ 954 | "bitflags 1.3.2", 955 | ] 956 | 957 | [[package]] 958 | name = "redox_syscall" 959 | version = "0.5.1" 960 | source = "registry+https://github.com/rust-lang/crates.io-index" 961 | checksum = "469052894dcb553421e483e4209ee581a45100d31b4018de03e5a7ad86374a7e" 962 | dependencies = [ 963 | "bitflags 2.5.0", 964 | ] 965 | 966 | [[package]] 967 | name = "regex" 968 | version = "1.9.1" 969 | source = "registry+https://github.com/rust-lang/crates.io-index" 970 | checksum = "b2eae68fc220f7cf2532e4494aded17545fce192d59cd996e0fe7887f4ceb575" 971 | dependencies = [ 972 | "aho-corasick", 973 | "memchr", 974 | "regex-automata", 975 | "regex-syntax", 976 | ] 977 | 978 | [[package]] 979 | name = "regex-automata" 980 | version = "0.3.3" 981 | source = "registry+https://github.com/rust-lang/crates.io-index" 982 | checksum = "39354c10dd07468c2e73926b23bb9c2caca74c5501e38a35da70406f1d923310" 983 | dependencies = [ 984 | "aho-corasick", 985 | "memchr", 986 | "regex-syntax", 987 | ] 988 | 989 | [[package]] 990 | name = "regex-syntax" 991 | version = "0.7.4" 992 | source = "registry+https://github.com/rust-lang/crates.io-index" 993 | checksum = "e5ea92a5b6195c6ef2a0295ea818b312502c6fc94dde986c5553242e18fd4ce2" 994 | 995 | [[package]] 996 | name = "rustix" 997 | version = "0.38.34" 998 | source = "registry+https://github.com/rust-lang/crates.io-index" 999 | checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" 1000 | dependencies = [ 1001 | "bitflags 2.5.0", 1002 | "errno", 1003 | "libc", 1004 | "linux-raw-sys 0.4.14", 1005 | "windows-sys 0.52.0", 1006 | ] 1007 | 1008 | [[package]] 1009 | name = "rustybuzz" 1010 | version = "0.8.0" 1011 | source = "registry+https://github.com/rust-lang/crates.io-index" 1012 | checksum = "82eea22c8f56965eeaf3a209b3d24508256c7b920fb3b6211b8ba0f7c0583250" 1013 | dependencies = [ 1014 | "bitflags 1.3.2", 1015 | "bytemuck", 1016 | "libm", 1017 | "smallvec", 1018 | "ttf-parser", 1019 | "unicode-bidi-mirroring", 1020 | "unicode-ccc", 1021 | "unicode-general-category", 1022 | "unicode-script", 1023 | ] 1024 | 1025 | [[package]] 1026 | name = "same-file" 1027 | version = "1.0.6" 1028 | source = "registry+https://github.com/rust-lang/crates.io-index" 1029 | checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" 1030 | dependencies = [ 1031 | "winapi-util", 1032 | ] 1033 | 1034 | [[package]] 1035 | name = "scoped-tls" 1036 | version = "1.0.1" 1037 | source = "registry+https://github.com/rust-lang/crates.io-index" 1038 | checksum = "e1cf6437eb19a8f4a6cc0f7dca544973b0b78843adbfeb3683d1a94a0024a294" 1039 | 1040 | [[package]] 1041 | name = "sctk-adwaita" 1042 | version = "0.9.0" 1043 | source = "registry+https://github.com/rust-lang/crates.io-index" 1044 | checksum = "7de61fa7334ee8ee1f5c3c58dcc414fb9361e7e8f5bff9d45f4d69eeb89a7169" 1045 | dependencies = [ 1046 | "ab_glyph", 1047 | "log", 1048 | "memmap2 0.9.4", 1049 | "smithay-client-toolkit", 1050 | "tiny-skia", 1051 | ] 1052 | 1053 | [[package]] 1054 | name = "serde" 1055 | version = "1.0.171" 1056 | source = "registry+https://github.com/rust-lang/crates.io-index" 1057 | checksum = "30e27d1e4fd7659406c492fd6cfaf2066ba8773de45ca75e855590f856dc34a9" 1058 | 1059 | [[package]] 1060 | name = "simd-adler32" 1061 | version = "0.3.5" 1062 | source = "registry+https://github.com/rust-lang/crates.io-index" 1063 | checksum = "238abfbb77c1915110ad968465608b68e869e0772622c9656714e73e5a1a522f" 1064 | 1065 | [[package]] 1066 | name = "slab" 1067 | version = "0.4.9" 1068 | source = "registry+https://github.com/rust-lang/crates.io-index" 1069 | checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" 1070 | dependencies = [ 1071 | "autocfg", 1072 | ] 1073 | 1074 | [[package]] 1075 | name = "slotmap" 1076 | version = "1.0.6" 1077 | source = "registry+https://github.com/rust-lang/crates.io-index" 1078 | checksum = "e1e08e261d0e8f5c43123b7adf3e4ca1690d655377ac93a03b2c9d3e98de1342" 1079 | dependencies = [ 1080 | "version_check", 1081 | ] 1082 | 1083 | [[package]] 1084 | name = "smallvec" 1085 | version = "1.11.0" 1086 | source = "registry+https://github.com/rust-lang/crates.io-index" 1087 | checksum = "62bb4feee49fdd9f707ef802e22365a35de4b7b299de4763d44bfea899442ff9" 1088 | 1089 | [[package]] 1090 | name = "smithay-client-toolkit" 1091 | version = "0.18.1" 1092 | source = "registry+https://github.com/rust-lang/crates.io-index" 1093 | checksum = "922fd3eeab3bd820d76537ce8f582b1cf951eceb5475c28500c7457d9d17f53a" 1094 | dependencies = [ 1095 | "bitflags 2.5.0", 1096 | "calloop", 1097 | "calloop-wayland-source", 1098 | "cursor-icon", 1099 | "libc", 1100 | "log", 1101 | "memmap2 0.9.4", 1102 | "rustix", 1103 | "thiserror", 1104 | "wayland-backend", 1105 | "wayland-client", 1106 | "wayland-csd-frame", 1107 | "wayland-cursor", 1108 | "wayland-protocols", 1109 | "wayland-protocols-wlr", 1110 | "wayland-scanner", 1111 | "xkeysym", 1112 | ] 1113 | 1114 | [[package]] 1115 | name = "smol_str" 1116 | version = "0.2.2" 1117 | source = "registry+https://github.com/rust-lang/crates.io-index" 1118 | checksum = "dd538fb6910ac1099850255cf94a94df6551fbdd602454387d0adb2d1ca6dead" 1119 | dependencies = [ 1120 | "serde", 1121 | ] 1122 | 1123 | [[package]] 1124 | name = "softbuffer" 1125 | version = "0.4.3" 1126 | source = "registry+https://github.com/rust-lang/crates.io-index" 1127 | checksum = "d09e57a5a6b300bf917329da0ff30a58737d83abb7b14f99a419c23e83007cb8" 1128 | dependencies = [ 1129 | "as-raw-xcb-connection", 1130 | "bytemuck", 1131 | "cfg_aliases", 1132 | "core-graphics", 1133 | "drm", 1134 | "fastrand", 1135 | "foreign-types", 1136 | "js-sys", 1137 | "log", 1138 | "memmap2 0.9.4", 1139 | "objc2", 1140 | "objc2-app-kit", 1141 | "objc2-foundation", 1142 | "objc2-quartz-core", 1143 | "raw-window-handle", 1144 | "redox_syscall 0.5.1", 1145 | "rustix", 1146 | "tiny-xlib", 1147 | "wasm-bindgen", 1148 | "wayland-backend", 1149 | "wayland-client", 1150 | "wayland-sys", 1151 | "web-sys", 1152 | "windows-sys 0.52.0", 1153 | "x11rb", 1154 | ] 1155 | 1156 | [[package]] 1157 | name = "strict-num" 1158 | version = "0.1.1" 1159 | source = "registry+https://github.com/rust-lang/crates.io-index" 1160 | checksum = "6637bab7722d379c8b41ba849228d680cc12d0a45ba1fa2b48f2a30577a06731" 1161 | 1162 | [[package]] 1163 | name = "swash" 1164 | version = "0.1.8" 1165 | source = "registry+https://github.com/rust-lang/crates.io-index" 1166 | checksum = "3b7c73c813353c347272919aa1af2885068b05e625e5532b43049e4f641ae77f" 1167 | dependencies = [ 1168 | "yazi", 1169 | "zeno", 1170 | ] 1171 | 1172 | [[package]] 1173 | name = "syn" 1174 | version = "2.0.32" 1175 | source = "registry+https://github.com/rust-lang/crates.io-index" 1176 | checksum = "239814284fd6f1a4ffe4ca893952cdd93c224b6a1571c9a9eadd670295c0c9e2" 1177 | dependencies = [ 1178 | "proc-macro2", 1179 | "quote", 1180 | "unicode-ident", 1181 | ] 1182 | 1183 | [[package]] 1184 | name = "sys-locale" 1185 | version = "0.3.0" 1186 | source = "registry+https://github.com/rust-lang/crates.io-index" 1187 | checksum = "ea0b9eefabb91675082b41eb94c3ecd91af7656caee3fb4961a07c0ec8c7ca6f" 1188 | dependencies = [ 1189 | "libc", 1190 | "windows-sys 0.45.0", 1191 | ] 1192 | 1193 | [[package]] 1194 | name = "thiserror" 1195 | version = "1.0.43" 1196 | source = "registry+https://github.com/rust-lang/crates.io-index" 1197 | checksum = "a35fc5b8971143ca348fa6df4f024d4d55264f3468c71ad1c2f365b0a4d58c42" 1198 | dependencies = [ 1199 | "thiserror-impl", 1200 | ] 1201 | 1202 | [[package]] 1203 | name = "thiserror-impl" 1204 | version = "1.0.43" 1205 | source = "registry+https://github.com/rust-lang/crates.io-index" 1206 | checksum = "463fe12d7993d3b327787537ce8dd4dfa058de32fc2b195ef3cde03dc4771e8f" 1207 | dependencies = [ 1208 | "proc-macro2", 1209 | "quote", 1210 | "syn", 1211 | ] 1212 | 1213 | [[package]] 1214 | name = "tiny-skia" 1215 | version = "0.11.1" 1216 | source = "registry+https://github.com/rust-lang/crates.io-index" 1217 | checksum = "f4e37fdc219ee3d551882d24dc5e4df5f72fd9723cbca1ffaa57f7348bf7a47d" 1218 | dependencies = [ 1219 | "arrayref", 1220 | "arrayvec", 1221 | "bytemuck", 1222 | "cfg-if", 1223 | "log", 1224 | "png", 1225 | "tiny-skia-path", 1226 | ] 1227 | 1228 | [[package]] 1229 | name = "tiny-skia-path" 1230 | version = "0.11.1" 1231 | source = "registry+https://github.com/rust-lang/crates.io-index" 1232 | checksum = "93a323d1de20dad9bc8b32daf57702c585ce76e80792d8151de1fc9dfc8d1ca7" 1233 | dependencies = [ 1234 | "arrayref", 1235 | "bytemuck", 1236 | "strict-num", 1237 | ] 1238 | 1239 | [[package]] 1240 | name = "tiny-xlib" 1241 | version = "0.2.2" 1242 | source = "registry+https://github.com/rust-lang/crates.io-index" 1243 | checksum = "d4098d49269baa034a8d1eae9bd63e9fa532148d772121dace3bcd6a6c98eb6d" 1244 | dependencies = [ 1245 | "as-raw-xcb-connection", 1246 | "ctor", 1247 | "libloading", 1248 | "tracing", 1249 | ] 1250 | 1251 | [[package]] 1252 | name = "tinyvec" 1253 | version = "1.6.0" 1254 | source = "registry+https://github.com/rust-lang/crates.io-index" 1255 | checksum = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50" 1256 | dependencies = [ 1257 | "tinyvec_macros", 1258 | ] 1259 | 1260 | [[package]] 1261 | name = "tinyvec_macros" 1262 | version = "0.1.1" 1263 | source = "registry+https://github.com/rust-lang/crates.io-index" 1264 | checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" 1265 | 1266 | [[package]] 1267 | name = "toml_datetime" 1268 | version = "0.6.3" 1269 | source = "registry+https://github.com/rust-lang/crates.io-index" 1270 | checksum = "7cda73e2f1397b1262d6dfdcef8aafae14d1de7748d66822d3bfeeb6d03e5e4b" 1271 | 1272 | [[package]] 1273 | name = "toml_edit" 1274 | version = "0.19.12" 1275 | source = "registry+https://github.com/rust-lang/crates.io-index" 1276 | checksum = "c500344a19072298cd05a7224b3c0c629348b78692bf48466c5238656e315a78" 1277 | dependencies = [ 1278 | "indexmap", 1279 | "toml_datetime", 1280 | "winnow", 1281 | ] 1282 | 1283 | [[package]] 1284 | name = "tracing" 1285 | version = "0.1.40" 1286 | source = "registry+https://github.com/rust-lang/crates.io-index" 1287 | checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" 1288 | dependencies = [ 1289 | "pin-project-lite", 1290 | "tracing-core", 1291 | ] 1292 | 1293 | [[package]] 1294 | name = "tracing-core" 1295 | version = "0.1.32" 1296 | source = "registry+https://github.com/rust-lang/crates.io-index" 1297 | checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" 1298 | 1299 | [[package]] 1300 | name = "ttf-parser" 1301 | version = "0.19.1" 1302 | source = "registry+https://github.com/rust-lang/crates.io-index" 1303 | checksum = "a464a4b34948a5f67fddd2b823c62d9d92e44be75058b99939eae6c5b6960b33" 1304 | 1305 | [[package]] 1306 | name = "unicode-bidi" 1307 | version = "0.3.13" 1308 | source = "registry+https://github.com/rust-lang/crates.io-index" 1309 | checksum = "92888ba5573ff080736b3648696b70cafad7d250551175acbaa4e0385b3e1460" 1310 | 1311 | [[package]] 1312 | name = "unicode-bidi-mirroring" 1313 | version = "0.1.0" 1314 | source = "registry+https://github.com/rust-lang/crates.io-index" 1315 | checksum = "56d12260fb92d52f9008be7e4bca09f584780eb2266dc8fecc6a192bec561694" 1316 | 1317 | [[package]] 1318 | name = "unicode-ccc" 1319 | version = "0.1.2" 1320 | source = "registry+https://github.com/rust-lang/crates.io-index" 1321 | checksum = "cc2520efa644f8268dce4dcd3050eaa7fc044fca03961e9998ac7e2e92b77cf1" 1322 | 1323 | [[package]] 1324 | name = "unicode-general-category" 1325 | version = "0.6.0" 1326 | source = "registry+https://github.com/rust-lang/crates.io-index" 1327 | checksum = "2281c8c1d221438e373249e065ca4989c4c36952c211ff21a0ee91c44a3869e7" 1328 | 1329 | [[package]] 1330 | name = "unicode-ident" 1331 | version = "1.0.10" 1332 | source = "registry+https://github.com/rust-lang/crates.io-index" 1333 | checksum = "22049a19f4a68748a168c0fc439f9516686aa045927ff767eca0a85101fb6e73" 1334 | 1335 | [[package]] 1336 | name = "unicode-linebreak" 1337 | version = "0.1.4" 1338 | source = "registry+https://github.com/rust-lang/crates.io-index" 1339 | checksum = "c5faade31a542b8b35855fff6e8def199853b2da8da256da52f52f1316ee3137" 1340 | dependencies = [ 1341 | "hashbrown 0.12.3", 1342 | "regex", 1343 | ] 1344 | 1345 | [[package]] 1346 | name = "unicode-script" 1347 | version = "0.5.5" 1348 | source = "registry+https://github.com/rust-lang/crates.io-index" 1349 | checksum = "7d817255e1bed6dfd4ca47258685d14d2bdcfbc64fdc9e3819bd5848057b8ecc" 1350 | 1351 | [[package]] 1352 | name = "unicode-segmentation" 1353 | version = "1.10.1" 1354 | source = "registry+https://github.com/rust-lang/crates.io-index" 1355 | checksum = "1dd624098567895118886609431a7c3b8f516e41d30e0643f03d94592a147e36" 1356 | 1357 | [[package]] 1358 | name = "version_check" 1359 | version = "0.9.4" 1360 | source = "registry+https://github.com/rust-lang/crates.io-index" 1361 | checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" 1362 | 1363 | [[package]] 1364 | name = "walkdir" 1365 | version = "2.3.3" 1366 | source = "registry+https://github.com/rust-lang/crates.io-index" 1367 | checksum = "36df944cda56c7d8d8b7496af378e6b16de9284591917d307c9b4d313c44e698" 1368 | dependencies = [ 1369 | "same-file", 1370 | "winapi-util", 1371 | ] 1372 | 1373 | [[package]] 1374 | name = "wasi" 1375 | version = "0.11.0+wasi-snapshot-preview1" 1376 | source = "registry+https://github.com/rust-lang/crates.io-index" 1377 | checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" 1378 | 1379 | [[package]] 1380 | name = "wasm-bindgen" 1381 | version = "0.2.87" 1382 | source = "registry+https://github.com/rust-lang/crates.io-index" 1383 | checksum = "7706a72ab36d8cb1f80ffbf0e071533974a60d0a308d01a5d0375bf60499a342" 1384 | dependencies = [ 1385 | "cfg-if", 1386 | "wasm-bindgen-macro", 1387 | ] 1388 | 1389 | [[package]] 1390 | name = "wasm-bindgen-backend" 1391 | version = "0.2.87" 1392 | source = "registry+https://github.com/rust-lang/crates.io-index" 1393 | checksum = "5ef2b6d3c510e9625e5fe6f509ab07d66a760f0885d858736483c32ed7809abd" 1394 | dependencies = [ 1395 | "bumpalo", 1396 | "log", 1397 | "once_cell", 1398 | "proc-macro2", 1399 | "quote", 1400 | "syn", 1401 | "wasm-bindgen-shared", 1402 | ] 1403 | 1404 | [[package]] 1405 | name = "wasm-bindgen-futures" 1406 | version = "0.4.37" 1407 | source = "registry+https://github.com/rust-lang/crates.io-index" 1408 | checksum = "c02dbc21516f9f1f04f187958890d7e6026df8d16540b7ad9492bc34a67cea03" 1409 | dependencies = [ 1410 | "cfg-if", 1411 | "js-sys", 1412 | "wasm-bindgen", 1413 | "web-sys", 1414 | ] 1415 | 1416 | [[package]] 1417 | name = "wasm-bindgen-macro" 1418 | version = "0.2.87" 1419 | source = "registry+https://github.com/rust-lang/crates.io-index" 1420 | checksum = "dee495e55982a3bd48105a7b947fd2a9b4a8ae3010041b9e0faab3f9cd028f1d" 1421 | dependencies = [ 1422 | "quote", 1423 | "wasm-bindgen-macro-support", 1424 | ] 1425 | 1426 | [[package]] 1427 | name = "wasm-bindgen-macro-support" 1428 | version = "0.2.87" 1429 | source = "registry+https://github.com/rust-lang/crates.io-index" 1430 | checksum = "54681b18a46765f095758388f2d0cf16eb8d4169b639ab575a8f5693af210c7b" 1431 | dependencies = [ 1432 | "proc-macro2", 1433 | "quote", 1434 | "syn", 1435 | "wasm-bindgen-backend", 1436 | "wasm-bindgen-shared", 1437 | ] 1438 | 1439 | [[package]] 1440 | name = "wasm-bindgen-shared" 1441 | version = "0.2.87" 1442 | source = "registry+https://github.com/rust-lang/crates.io-index" 1443 | checksum = "ca6ad05a4870b2bf5fe995117d3728437bd27d7cd5f06f13c17443ef369775a1" 1444 | 1445 | [[package]] 1446 | name = "wayland-backend" 1447 | version = "0.3.3" 1448 | source = "registry+https://github.com/rust-lang/crates.io-index" 1449 | checksum = "9d50fa61ce90d76474c87f5fc002828d81b32677340112b4ef08079a9d459a40" 1450 | dependencies = [ 1451 | "cc", 1452 | "downcast-rs", 1453 | "rustix", 1454 | "scoped-tls", 1455 | "smallvec", 1456 | "wayland-sys", 1457 | ] 1458 | 1459 | [[package]] 1460 | name = "wayland-client" 1461 | version = "0.31.2" 1462 | source = "registry+https://github.com/rust-lang/crates.io-index" 1463 | checksum = "82fb96ee935c2cea6668ccb470fb7771f6215d1691746c2d896b447a00ad3f1f" 1464 | dependencies = [ 1465 | "bitflags 2.5.0", 1466 | "rustix", 1467 | "wayland-backend", 1468 | "wayland-scanner", 1469 | ] 1470 | 1471 | [[package]] 1472 | name = "wayland-csd-frame" 1473 | version = "0.3.0" 1474 | source = "registry+https://github.com/rust-lang/crates.io-index" 1475 | checksum = "625c5029dbd43d25e6aa9615e88b829a5cad13b2819c4ae129fdbb7c31ab4c7e" 1476 | dependencies = [ 1477 | "bitflags 2.5.0", 1478 | "cursor-icon", 1479 | "wayland-backend", 1480 | ] 1481 | 1482 | [[package]] 1483 | name = "wayland-cursor" 1484 | version = "0.31.1" 1485 | source = "registry+https://github.com/rust-lang/crates.io-index" 1486 | checksum = "71ce5fa868dd13d11a0d04c5e2e65726d0897be8de247c0c5a65886e283231ba" 1487 | dependencies = [ 1488 | "rustix", 1489 | "wayland-client", 1490 | "xcursor", 1491 | ] 1492 | 1493 | [[package]] 1494 | name = "wayland-protocols" 1495 | version = "0.31.2" 1496 | source = "registry+https://github.com/rust-lang/crates.io-index" 1497 | checksum = "8f81f365b8b4a97f422ac0e8737c438024b5951734506b0e1d775c73030561f4" 1498 | dependencies = [ 1499 | "bitflags 2.5.0", 1500 | "wayland-backend", 1501 | "wayland-client", 1502 | "wayland-scanner", 1503 | ] 1504 | 1505 | [[package]] 1506 | name = "wayland-protocols-plasma" 1507 | version = "0.2.0" 1508 | source = "registry+https://github.com/rust-lang/crates.io-index" 1509 | checksum = "23803551115ff9ea9bce586860c5c5a971e360825a0309264102a9495a5ff479" 1510 | dependencies = [ 1511 | "bitflags 2.5.0", 1512 | "wayland-backend", 1513 | "wayland-client", 1514 | "wayland-protocols", 1515 | "wayland-scanner", 1516 | ] 1517 | 1518 | [[package]] 1519 | name = "wayland-protocols-wlr" 1520 | version = "0.2.0" 1521 | source = "registry+https://github.com/rust-lang/crates.io-index" 1522 | checksum = "ad1f61b76b6c2d8742e10f9ba5c3737f6530b4c243132c2a2ccc8aa96fe25cd6" 1523 | dependencies = [ 1524 | "bitflags 2.5.0", 1525 | "wayland-backend", 1526 | "wayland-client", 1527 | "wayland-protocols", 1528 | "wayland-scanner", 1529 | ] 1530 | 1531 | [[package]] 1532 | name = "wayland-scanner" 1533 | version = "0.31.1" 1534 | source = "registry+https://github.com/rust-lang/crates.io-index" 1535 | checksum = "63b3a62929287001986fb58c789dce9b67604a397c15c611ad9f747300b6c283" 1536 | dependencies = [ 1537 | "proc-macro2", 1538 | "quick-xml", 1539 | "quote", 1540 | ] 1541 | 1542 | [[package]] 1543 | name = "wayland-sys" 1544 | version = "0.31.1" 1545 | source = "registry+https://github.com/rust-lang/crates.io-index" 1546 | checksum = "15a0c8eaff5216d07f226cb7a549159267f3467b289d9a2e52fd3ef5aae2b7af" 1547 | dependencies = [ 1548 | "dlib", 1549 | "log", 1550 | "once_cell", 1551 | "pkg-config", 1552 | ] 1553 | 1554 | [[package]] 1555 | name = "web-sys" 1556 | version = "0.3.64" 1557 | source = "registry+https://github.com/rust-lang/crates.io-index" 1558 | checksum = "9b85cbef8c220a6abc02aefd892dfc0fc23afb1c6a426316ec33253a3877249b" 1559 | dependencies = [ 1560 | "js-sys", 1561 | "wasm-bindgen", 1562 | ] 1563 | 1564 | [[package]] 1565 | name = "web-time" 1566 | version = "1.1.0" 1567 | source = "registry+https://github.com/rust-lang/crates.io-index" 1568 | checksum = "5a6580f308b1fad9207618087a65c04e7a10bc77e02c8e84e9b00dd4b12fa0bb" 1569 | dependencies = [ 1570 | "js-sys", 1571 | "wasm-bindgen", 1572 | ] 1573 | 1574 | [[package]] 1575 | name = "winapi" 1576 | version = "0.3.9" 1577 | source = "registry+https://github.com/rust-lang/crates.io-index" 1578 | checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" 1579 | dependencies = [ 1580 | "winapi-i686-pc-windows-gnu", 1581 | "winapi-x86_64-pc-windows-gnu", 1582 | ] 1583 | 1584 | [[package]] 1585 | name = "winapi-i686-pc-windows-gnu" 1586 | version = "0.4.0" 1587 | source = "registry+https://github.com/rust-lang/crates.io-index" 1588 | checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" 1589 | 1590 | [[package]] 1591 | name = "winapi-util" 1592 | version = "0.1.5" 1593 | source = "registry+https://github.com/rust-lang/crates.io-index" 1594 | checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" 1595 | dependencies = [ 1596 | "winapi", 1597 | ] 1598 | 1599 | [[package]] 1600 | name = "winapi-x86_64-pc-windows-gnu" 1601 | version = "0.4.0" 1602 | source = "registry+https://github.com/rust-lang/crates.io-index" 1603 | checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" 1604 | 1605 | [[package]] 1606 | name = "windows-sys" 1607 | version = "0.45.0" 1608 | source = "registry+https://github.com/rust-lang/crates.io-index" 1609 | checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0" 1610 | dependencies = [ 1611 | "windows-targets 0.42.2", 1612 | ] 1613 | 1614 | [[package]] 1615 | name = "windows-sys" 1616 | version = "0.48.0" 1617 | source = "registry+https://github.com/rust-lang/crates.io-index" 1618 | checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" 1619 | dependencies = [ 1620 | "windows-targets 0.48.1", 1621 | ] 1622 | 1623 | [[package]] 1624 | name = "windows-sys" 1625 | version = "0.52.0" 1626 | source = "registry+https://github.com/rust-lang/crates.io-index" 1627 | checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" 1628 | dependencies = [ 1629 | "windows-targets 0.52.5", 1630 | ] 1631 | 1632 | [[package]] 1633 | name = "windows-targets" 1634 | version = "0.42.2" 1635 | source = "registry+https://github.com/rust-lang/crates.io-index" 1636 | checksum = "8e5180c00cd44c9b1c88adb3693291f1cd93605ded80c250a75d472756b4d071" 1637 | dependencies = [ 1638 | "windows_aarch64_gnullvm 0.42.2", 1639 | "windows_aarch64_msvc 0.42.2", 1640 | "windows_i686_gnu 0.42.2", 1641 | "windows_i686_msvc 0.42.2", 1642 | "windows_x86_64_gnu 0.42.2", 1643 | "windows_x86_64_gnullvm 0.42.2", 1644 | "windows_x86_64_msvc 0.42.2", 1645 | ] 1646 | 1647 | [[package]] 1648 | name = "windows-targets" 1649 | version = "0.48.1" 1650 | source = "registry+https://github.com/rust-lang/crates.io-index" 1651 | checksum = "05d4b17490f70499f20b9e791dcf6a299785ce8af4d709018206dc5b4953e95f" 1652 | dependencies = [ 1653 | "windows_aarch64_gnullvm 0.48.0", 1654 | "windows_aarch64_msvc 0.48.0", 1655 | "windows_i686_gnu 0.48.0", 1656 | "windows_i686_msvc 0.48.0", 1657 | "windows_x86_64_gnu 0.48.0", 1658 | "windows_x86_64_gnullvm 0.48.0", 1659 | "windows_x86_64_msvc 0.48.0", 1660 | ] 1661 | 1662 | [[package]] 1663 | name = "windows-targets" 1664 | version = "0.52.5" 1665 | source = "registry+https://github.com/rust-lang/crates.io-index" 1666 | checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" 1667 | dependencies = [ 1668 | "windows_aarch64_gnullvm 0.52.5", 1669 | "windows_aarch64_msvc 0.52.5", 1670 | "windows_i686_gnu 0.52.5", 1671 | "windows_i686_gnullvm", 1672 | "windows_i686_msvc 0.52.5", 1673 | "windows_x86_64_gnu 0.52.5", 1674 | "windows_x86_64_gnullvm 0.52.5", 1675 | "windows_x86_64_msvc 0.52.5", 1676 | ] 1677 | 1678 | [[package]] 1679 | name = "windows_aarch64_gnullvm" 1680 | version = "0.42.2" 1681 | source = "registry+https://github.com/rust-lang/crates.io-index" 1682 | checksum = "597a5118570b68bc08d8d59125332c54f1ba9d9adeedeef5b99b02ba2b0698f8" 1683 | 1684 | [[package]] 1685 | name = "windows_aarch64_gnullvm" 1686 | version = "0.48.0" 1687 | source = "registry+https://github.com/rust-lang/crates.io-index" 1688 | checksum = "91ae572e1b79dba883e0d315474df7305d12f569b400fcf90581b06062f7e1bc" 1689 | 1690 | [[package]] 1691 | name = "windows_aarch64_gnullvm" 1692 | version = "0.52.5" 1693 | source = "registry+https://github.com/rust-lang/crates.io-index" 1694 | checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" 1695 | 1696 | [[package]] 1697 | name = "windows_aarch64_msvc" 1698 | version = "0.42.2" 1699 | source = "registry+https://github.com/rust-lang/crates.io-index" 1700 | checksum = "e08e8864a60f06ef0d0ff4ba04124db8b0fb3be5776a5cd47641e942e58c4d43" 1701 | 1702 | [[package]] 1703 | name = "windows_aarch64_msvc" 1704 | version = "0.48.0" 1705 | source = "registry+https://github.com/rust-lang/crates.io-index" 1706 | checksum = "b2ef27e0d7bdfcfc7b868b317c1d32c641a6fe4629c171b8928c7b08d98d7cf3" 1707 | 1708 | [[package]] 1709 | name = "windows_aarch64_msvc" 1710 | version = "0.52.5" 1711 | source = "registry+https://github.com/rust-lang/crates.io-index" 1712 | checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" 1713 | 1714 | [[package]] 1715 | name = "windows_i686_gnu" 1716 | version = "0.42.2" 1717 | source = "registry+https://github.com/rust-lang/crates.io-index" 1718 | checksum = "c61d927d8da41da96a81f029489353e68739737d3beca43145c8afec9a31a84f" 1719 | 1720 | [[package]] 1721 | name = "windows_i686_gnu" 1722 | version = "0.48.0" 1723 | source = "registry+https://github.com/rust-lang/crates.io-index" 1724 | checksum = "622a1962a7db830d6fd0a69683c80a18fda201879f0f447f065a3b7467daa241" 1725 | 1726 | [[package]] 1727 | name = "windows_i686_gnu" 1728 | version = "0.52.5" 1729 | source = "registry+https://github.com/rust-lang/crates.io-index" 1730 | checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" 1731 | 1732 | [[package]] 1733 | name = "windows_i686_gnullvm" 1734 | version = "0.52.5" 1735 | source = "registry+https://github.com/rust-lang/crates.io-index" 1736 | checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" 1737 | 1738 | [[package]] 1739 | name = "windows_i686_msvc" 1740 | version = "0.42.2" 1741 | source = "registry+https://github.com/rust-lang/crates.io-index" 1742 | checksum = "44d840b6ec649f480a41c8d80f9c65108b92d89345dd94027bfe06ac444d1060" 1743 | 1744 | [[package]] 1745 | name = "windows_i686_msvc" 1746 | version = "0.48.0" 1747 | source = "registry+https://github.com/rust-lang/crates.io-index" 1748 | checksum = "4542c6e364ce21bf45d69fdd2a8e455fa38d316158cfd43b3ac1c5b1b19f8e00" 1749 | 1750 | [[package]] 1751 | name = "windows_i686_msvc" 1752 | version = "0.52.5" 1753 | source = "registry+https://github.com/rust-lang/crates.io-index" 1754 | checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" 1755 | 1756 | [[package]] 1757 | name = "windows_x86_64_gnu" 1758 | version = "0.42.2" 1759 | source = "registry+https://github.com/rust-lang/crates.io-index" 1760 | checksum = "8de912b8b8feb55c064867cf047dda097f92d51efad5b491dfb98f6bbb70cb36" 1761 | 1762 | [[package]] 1763 | name = "windows_x86_64_gnu" 1764 | version = "0.48.0" 1765 | source = "registry+https://github.com/rust-lang/crates.io-index" 1766 | checksum = "ca2b8a661f7628cbd23440e50b05d705db3686f894fc9580820623656af974b1" 1767 | 1768 | [[package]] 1769 | name = "windows_x86_64_gnu" 1770 | version = "0.52.5" 1771 | source = "registry+https://github.com/rust-lang/crates.io-index" 1772 | checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" 1773 | 1774 | [[package]] 1775 | name = "windows_x86_64_gnullvm" 1776 | version = "0.42.2" 1777 | source = "registry+https://github.com/rust-lang/crates.io-index" 1778 | checksum = "26d41b46a36d453748aedef1486d5c7a85db22e56aff34643984ea85514e94a3" 1779 | 1780 | [[package]] 1781 | name = "windows_x86_64_gnullvm" 1782 | version = "0.48.0" 1783 | source = "registry+https://github.com/rust-lang/crates.io-index" 1784 | checksum = "7896dbc1f41e08872e9d5e8f8baa8fdd2677f29468c4e156210174edc7f7b953" 1785 | 1786 | [[package]] 1787 | name = "windows_x86_64_gnullvm" 1788 | version = "0.52.5" 1789 | source = "registry+https://github.com/rust-lang/crates.io-index" 1790 | checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" 1791 | 1792 | [[package]] 1793 | name = "windows_x86_64_msvc" 1794 | version = "0.42.2" 1795 | source = "registry+https://github.com/rust-lang/crates.io-index" 1796 | checksum = "9aec5da331524158c6d1a4ac0ab1541149c0b9505fde06423b02f5ef0106b9f0" 1797 | 1798 | [[package]] 1799 | name = "windows_x86_64_msvc" 1800 | version = "0.48.0" 1801 | source = "registry+https://github.com/rust-lang/crates.io-index" 1802 | checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a" 1803 | 1804 | [[package]] 1805 | name = "windows_x86_64_msvc" 1806 | version = "0.52.5" 1807 | source = "registry+https://github.com/rust-lang/crates.io-index" 1808 | checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" 1809 | 1810 | [[package]] 1811 | name = "winit" 1812 | version = "0.30.0" 1813 | source = "registry+https://github.com/rust-lang/crates.io-index" 1814 | checksum = "ea9e6d5d66cbf702e0dd820302144f51b69a95acdc495dd98ca280ff206562b1" 1815 | dependencies = [ 1816 | "ahash 0.8.11", 1817 | "android-activity", 1818 | "atomic-waker", 1819 | "bitflags 2.5.0", 1820 | "bytemuck", 1821 | "calloop", 1822 | "cfg_aliases", 1823 | "concurrent-queue", 1824 | "core-foundation", 1825 | "core-graphics", 1826 | "cursor-icon", 1827 | "dpi", 1828 | "js-sys", 1829 | "libc", 1830 | "memmap2 0.9.4", 1831 | "ndk", 1832 | "objc2", 1833 | "objc2-app-kit", 1834 | "objc2-foundation", 1835 | "orbclient", 1836 | "percent-encoding", 1837 | "pin-project", 1838 | "raw-window-handle", 1839 | "redox_syscall 0.4.1", 1840 | "rustix", 1841 | "sctk-adwaita", 1842 | "smithay-client-toolkit", 1843 | "smol_str", 1844 | "tracing", 1845 | "unicode-segmentation", 1846 | "wasm-bindgen", 1847 | "wasm-bindgen-futures", 1848 | "wayland-backend", 1849 | "wayland-client", 1850 | "wayland-protocols", 1851 | "wayland-protocols-plasma", 1852 | "web-sys", 1853 | "web-time", 1854 | "windows-sys 0.52.0", 1855 | "x11-dl", 1856 | "x11rb", 1857 | "xkbcommon-dl", 1858 | ] 1859 | 1860 | [[package]] 1861 | name = "winnow" 1862 | version = "0.4.9" 1863 | source = "registry+https://github.com/rust-lang/crates.io-index" 1864 | checksum = "81a2094c43cc94775293eaa0e499fbc30048a6d824ac82c0351a8c0bf9112529" 1865 | dependencies = [ 1866 | "memchr", 1867 | ] 1868 | 1869 | [[package]] 1870 | name = "x11-dl" 1871 | version = "2.21.0" 1872 | source = "registry+https://github.com/rust-lang/crates.io-index" 1873 | checksum = "38735924fedd5314a6e548792904ed8c6de6636285cb9fec04d5b1db85c1516f" 1874 | dependencies = [ 1875 | "libc", 1876 | "once_cell", 1877 | "pkg-config", 1878 | ] 1879 | 1880 | [[package]] 1881 | name = "x11rb" 1882 | version = "0.13.1" 1883 | source = "registry+https://github.com/rust-lang/crates.io-index" 1884 | checksum = "5d91ffca73ee7f68ce055750bf9f6eca0780b8c85eff9bc046a3b0da41755e12" 1885 | dependencies = [ 1886 | "as-raw-xcb-connection", 1887 | "gethostname", 1888 | "libc", 1889 | "libloading", 1890 | "once_cell", 1891 | "rustix", 1892 | "x11rb-protocol", 1893 | ] 1894 | 1895 | [[package]] 1896 | name = "x11rb-protocol" 1897 | version = "0.13.1" 1898 | source = "registry+https://github.com/rust-lang/crates.io-index" 1899 | checksum = "ec107c4503ea0b4a98ef47356329af139c0a4f7750e621cf2973cd3385ebcb3d" 1900 | 1901 | [[package]] 1902 | name = "xcursor" 1903 | version = "0.3.4" 1904 | source = "registry+https://github.com/rust-lang/crates.io-index" 1905 | checksum = "463705a63313cd4301184381c5e8042f0a7e9b4bb63653f216311d4ae74690b7" 1906 | dependencies = [ 1907 | "nom", 1908 | ] 1909 | 1910 | [[package]] 1911 | name = "xkbcommon-dl" 1912 | version = "0.4.2" 1913 | source = "registry+https://github.com/rust-lang/crates.io-index" 1914 | checksum = "d039de8032a9a8856a6be89cea3e5d12fdd82306ab7c94d74e6deab2460651c5" 1915 | dependencies = [ 1916 | "bitflags 2.5.0", 1917 | "dlib", 1918 | "log", 1919 | "once_cell", 1920 | "xkeysym", 1921 | ] 1922 | 1923 | [[package]] 1924 | name = "xkeysym" 1925 | version = "0.2.0" 1926 | source = "registry+https://github.com/rust-lang/crates.io-index" 1927 | checksum = "054a8e68b76250b253f671d1268cb7f1ae089ec35e195b2efb2a4e9a836d0621" 1928 | 1929 | [[package]] 1930 | name = "yazi" 1931 | version = "0.1.6" 1932 | source = "registry+https://github.com/rust-lang/crates.io-index" 1933 | checksum = "c94451ac9513335b5e23d7a8a2b61a7102398b8cca5160829d313e84c9d98be1" 1934 | 1935 | [[package]] 1936 | name = "zeno" 1937 | version = "0.2.2" 1938 | source = "registry+https://github.com/rust-lang/crates.io-index" 1939 | checksum = "c110ba09c9b3a43edd4803d570df0da2414fed6e822e22b976a4e3ef50860701" 1940 | 1941 | [[package]] 1942 | name = "zerocopy" 1943 | version = "0.7.34" 1944 | source = "registry+https://github.com/rust-lang/crates.io-index" 1945 | checksum = "ae87e3fcd617500e5d106f0380cf7b77f3c6092aae37191433159dda23cfb087" 1946 | dependencies = [ 1947 | "zerocopy-derive", 1948 | ] 1949 | 1950 | [[package]] 1951 | name = "zerocopy-derive" 1952 | version = "0.7.34" 1953 | source = "registry+https://github.com/rust-lang/crates.io-index" 1954 | checksum = "15e934569e47891f7d9411f1a451d947a60e000ab3bd24fbb970f000387d1b3b" 1955 | dependencies = [ 1956 | "proc-macro2", 1957 | "quote", 1958 | "syn", 1959 | ] 1960 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "nerf" 3 | version = "0.2.0" 4 | edition = "2021" 5 | 6 | [dependencies] 7 | cosmic-text = { version = "0.9.0", optional = true } 8 | softbuffer = "0.4.3" 9 | tiny-skia = { version = "0.11.1", optional = true } 10 | winit = "0.30.0" 11 | 12 | [features] 13 | default = ["skia", "text"] 14 | skia = ["dep:tiny-skia"] 15 | svg = ["skia"] 16 | text = ["dep:cosmic-text"] 17 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright 2023 Virgile HENRY 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # NERF 2 | 3 | Nerf is (yet another) rust GUI lib. It is heavily inspired by Flutter, and is designed to build apps that could run on any plateforms, such as windows / linux / macOS, but also web, android, etc. 4 | 5 | It was created after seing how huge and complex other GUI libs were. The simple counter example with Iced is 8MB, and the whole repo is 60k lines of code. When I tried it out, the compile time was huge. The counter Nerf example is 5K lines of code (when I write this readme, this will increase in the future) and the executable is 2MB. 6 | 7 | I wanted something simple and straightforward. A lib that anyone could dive into, and understand how it works. 8 | 9 | ## Features 10 | 11 | For now, Nerf is in early development. Therefore, only a few types of widgets are currently supported. The main features are: 12 | 13 | - Widget tree system 14 | - Basic widget rendering 15 | - Text rendering 16 | 17 | ## Dependencies 18 | 19 | Nerf has a few dependencies, but most of them are optionnal and can be included with features. 20 | 21 | - winit: window creation and management, essential. 22 | - softbuffer: provides a 2D pixel buffer to draw on from the winit handle. 23 | - skia: draw engine. It is enabled by default, but can be disabled with the --no-default-features flag. When disabled, the most basic rendering operations have fallbacks, but they are much slower. It is recommanded to use skia, unless executable size should as small as possible. 24 | - cosmic-text: text rendering. This is disabled bu default, and any application that uses text rendering should add it. It does considerably increase the executable size. 25 | 26 | 27 | ## How to use 28 | 29 | ### Installation 30 | 31 | Nerf is not yet published on crates.io, so you have to clone the repo and reference it from your project. This can easily be done in the Toml file: 32 | 33 | ```toml 34 | [dependencies] 35 | nerf = { path = "path/to/nerf" } 36 | ``` 37 | 38 | ### Basic usage 39 | 40 | At it's core, nerf is not much more than a widget tree. The one important trait is the `Widget` trait, which defines a widget behaviour. The `Widget` trait has three methods: 41 | 42 | draw: 43 | ```rust 44 | fn draw(&self, canvas: &mut Canvas, rect: softbuffer::Rect); 45 | ``` 46 | The draw function is called whenever the application requests a redraw. There are usually to implementations: 47 | - some widgets will actually draw something on the canvas 48 | - others will recursively call the draw function on their children 49 | 50 | min_space_requirements: 51 | ```rust 52 | fn min_space_requirements(&self) -> (WidgetSizeRequirement, WidgetSizeRequirement); 53 | ``` 54 | This allows to have information on how widgets wished to be layout. This will allow the app to give them the required space, if available. It is important to note that this can not always be respected, and widgets should be able to handle smaller sizes. We can't stop the app user to make the window smaller than the minimum size of our widgets. 55 | 56 | handle_event: 57 | ```rust 58 | fn handle_event(&mut self, event: InputEvent, rect: softbuffer::Rect) -> EventResponse; 59 | ``` 60 | The handle event function is called whenever an event is received. It should be recursively called on all children. 61 | When a widget uses that event, they must notifiy the parent by returning a event response flags, such as the request redraw for example. 62 | 63 | With Nerf, the idea is that widets implement their logic and own their data. Any desired behaviour is made by creating a widget, and adding it to the widget tree. The widget tree is then passed to the application, which will handle the rendering and events. For instance, a connection page will allow the user to connect, while the connected page wille store the user info. Therefore, if an app need data anytime, the best place to store it is in a custom root widget. 64 | 65 | ### Example 66 | 67 | Let's implement the classic counter example (the full example is in examples/counter.rs). 68 | 69 | First, let's create a widget that will contain our data. 70 | 71 | ```rust 72 | struct Counter { 73 | // state of the widget 74 | count: u32, 75 | } 76 | ``` 77 | 78 | While we could implement manually the drawing, event handling of our counter, Nerf provides basic widgets that can be used. Our counter will therefore have two childs, a text widget to display the count, and a button to increment the count. 79 | 80 | ```rust 81 | struct Counter { 82 | // state of the widget 83 | count: u32, 84 | // the button that will throw callbacks 85 | button: Box, 86 | // the display text. We keep it here, to be able to reference and mofify it. 87 | text: Box, 88 | } 89 | ``` 90 | 91 | Here, the button is a dyn widget, because we don't care a lot about it. We kept the text's strong type to change it's value later. 92 | 93 | Now, let's implement the widget trait for our counter. 94 | 95 | ```rust 96 | impl Widget for Counter { 97 | [...] 98 | } 99 | ``` 100 | 101 | We'll start with the draw function. All we need to draw is the text. However, we'll add a background color to make it more visible. 102 | As we kept a reference to the text widget, we can't have it be a child of our background: widgets have a unique owner, and the text is either a child of our counter or a child of a background. We will draw our background behind the button, which is a widget that does not get drawn, and only have a behaviour. Therefore, we will draw the button and the text. 103 | 104 | ```rust 105 | fn draw(&self, canvas: &mut Canvas, rect: softbuffer::Rect) { 106 | self.button.draw(canvas, rect); 107 | self.text.draw(canvas, rect); 108 | } 109 | ``` 110 | 111 | See how simple this is ? The app will take care of the layout, and will provide us with the rect to draw in. More detail on this with the next function: 112 | 113 | ```rust 114 | fn min_space_requirements(&self) -> (WidgetSizeRequirement, WidgetSizeRequirement) { 115 | ( 116 | WidgetSizeRequirement::Fixed(unsafe {NonZeroU32::new_unchecked(200)}), 117 | WidgetSizeRequirement::Fixed(unsafe {NonZeroU32::new_unchecked(70)}), 118 | ) 119 | } 120 | ``` 121 | 122 | Let's specify what space requirements we want. We could use the space requirements of our children, but here let's just say we want a fixed size. when drawn, the app will give all the screen space to the root, and widgets will distribute that space to their children depending on their requirements and behaviour. For example, a sized box (or our counter button) request a fixed size, so when we will put this in a center widget, the center widget will receive the screen size, compare it with our own size, and give us the rect accordingly. 123 | 124 | Finally, let's handle the events. We want to handle the button click, and increment the counter. 125 | 126 | ```rust 127 | fn handle_event(&mut self, event: InputEvent, rect: softbuffer::Rect) -> EventResponse { 128 | 129 | let result = self.button.handle_event(event, rect); 130 | if result.contains(EventResponse::CALLBACK) { 131 | // in that case, increment the counnter and update the text. 132 | self.count += 1; 133 | self.text.set_text(self.count.to_string()) 134 | } 135 | 136 | let result = result | EventResponse::REDRAW_REQUEST | !EventResponse::CALLBACK; 137 | 138 | result 139 | } 140 | ``` 141 | 142 | If the button is pressed, it will return a callback flag. If we see this flag, we increment the counter and update the text. It is then important to return a draw request repsonse ourselves, to tell the app that we need to be redrawn. Here, we could simply return request redraw, but in more complex architectures, we might not now what events are thrown through our widgets. Also, it is worth noticing we removed the callback flag. This is left to the implementation type, but here as we consumed the event, I found it better to keep the information that our button triggered to ourselves. 143 | 144 | Finally, let's implement a constructor for our counter. 145 | 146 | ```rust 147 | pub fn new() -> Box { 148 | Box::new( 149 | Counter { 150 | count: 0, 151 | button: Background::new( 152 | Color::rgb(200, 255, 200), 153 | Button::new(Empty::expand()), 154 | ), 155 | text: Text::new( 156 | "0".to_string(), 157 | TextStyle::default() 158 | .sized(30.0) 159 | .styled(FontStyle::Italic) 160 | ), 161 | } 162 | ) 163 | } 164 | ``` 165 | 166 | Here, simply create a new counter with an initial state, assign the button and a text. You will notice the button is behind a background. This is why I kept it under a dyn widget: it is not important to know what it is, as we won't interact with it. The events will be redirected from the background to the button, and the button will throw a callback when pressed that we will also receive through the background. You could think of this as a "background button". In Nerf, widgets won't assume any behaviour, and will only be used for their sole purpose. therfore, a button will only be used to throw callbacks, and a background will only be used to draw a background. If we want to have a background button, we will create a button, and add a background to it, as demonstrated here. 167 | 168 | To avoid infinite size structs, most widgets are held in boxes in Nerf. It is however possible not to: our counter could have a straight text widget. But here, the app will expect a struct for the root, so our constructor returns a box. 169 | 170 | Finally, let's create our app. 171 | 172 | ```rust 173 | fn main() { 174 | let app = App::new( 175 | Align::new( 176 | Alignment::CENTER, 177 | Center::new(Counter::new()), 178 | ) 179 | ); 180 | 181 | // Run the app. 182 | app.run() 183 | } 184 | ``` 185 | 186 | Here, simply create an app, put the counter as the root, and start it. You can see I added a center for convenience. 187 | -------------------------------------------------------------------------------- /benches/nerf.rs: -------------------------------------------------------------------------------- 1 | use std::num::NonZeroU32; 2 | 3 | use nerf::*; 4 | 5 | use criterion::{ 6 | black_box, 7 | criterion_group, 8 | criterion_main, 9 | Criterion, 10 | }; 11 | 12 | fn compute_widget_sizes(c: &mut Criterion) { 13 | let root = black_box(Column::new( 14 | [ 15 | Row::new([ 16 | SizedBox::new(120, 80, Empty::expand()), Empty::expand(), 17 | SizedBox::new(240, 300, Empty::expand()), Empty::expand(), 18 | SizedBox::new(40, 100, Empty::expand()), Empty::expand(), 19 | SizedBox::new(10, 80, Empty::expand()), Empty::expand(), 20 | SizedBox::new(200, 5, Empty::expand()), Empty::expand(), 21 | ]), 22 | Row::new([ 23 | SizedBox::new(120, 80, Empty::expand()), Empty::expand(), 24 | SizedBox::new(240, 300, Empty::expand()), Empty::expand(), 25 | SizedBox::new(40, 100, Empty::expand()), Empty::expand(), 26 | SizedBox::new(10, 80, Empty::expand()), Empty::expand(), 27 | SizedBox::new(200, 5, Empty::expand()), Empty::expand(), 28 | ]), 29 | Row::new([ 30 | SizedBox::new(120, 80, Empty::expand()), Empty::expand(), 31 | SizedBox::new(240, 300, Empty::expand()), Empty::expand(), 32 | SizedBox::new(40, 100, Empty::expand()), Empty::expand(), 33 | SizedBox::new(10, 80, Empty::expand()), Empty::expand(), 34 | SizedBox::new(200, 5, Empty::expand()), Empty::expand(), 35 | ]), 36 | Row::new([ 37 | SizedBox::new(120, 80, Empty::expand()), Empty::expand(), 38 | SizedBox::new(240, 300, Empty::expand()), Empty::expand(), 39 | SizedBox::new(40, 100, Empty::expand()), Empty::expand(), 40 | SizedBox::new(10, 80, Empty::expand()), Empty::expand(), 41 | SizedBox::new(200, 5, Empty::expand()), Empty::expand(), 42 | ]), 43 | Row::new([ 44 | SizedBox::new(120, 80, Empty::expand()), Empty::expand(), 45 | SizedBox::new(240, 300, Empty::expand()), Empty::expand(), 46 | SizedBox::new(40, 100, Empty::expand()), Empty::expand(), 47 | SizedBox::new(10, 80, Empty::expand()), Empty::expand(), 48 | SizedBox::new(200, 5, Empty::expand()), Empty::expand(), 49 | ]), 50 | Row::new([ 51 | SizedBox::new(120, 80, Empty::expand()), Empty::expand(), 52 | SizedBox::new(240, 300, Empty::expand()), Empty::expand(), 53 | SizedBox::new(40, 100, Empty::expand()), Empty::expand(), 54 | SizedBox::new(10, 80, Empty::expand()), Empty::expand(), 55 | SizedBox::new(200, 5, Empty::expand()), Empty::expand(), 56 | ]), 57 | Row::new([ 58 | SizedBox::new(120, 80, Empty::expand()), Empty::expand(), 59 | SizedBox::new(240, 300, Empty::expand()), Empty::expand(), 60 | SizedBox::new(40, 100, Empty::expand()), Empty::expand(), 61 | SizedBox::new(10, 80, Empty::expand()), Empty::expand(), 62 | SizedBox::new(200, 5, Empty::expand()), Empty::expand(), 63 | ]), 64 | Row::new([ 65 | SizedBox::new(120, 80, Empty::expand()), Empty::expand(), 66 | SizedBox::new(240, 300, Empty::expand()), Empty::expand(), 67 | SizedBox::new(40, 100, Empty::expand()), Empty::expand(), 68 | SizedBox::new(10, 80, Empty::expand()), Empty::expand(), 69 | SizedBox::new(200, 5, Empty::expand()), Empty::expand(), 70 | ]), 71 | Row::new([ 72 | SizedBox::new(120, 80, Empty::expand()), Empty::expand(), 73 | SizedBox::new(240, 300, Empty::expand()), Empty::expand(), 74 | SizedBox::new(40, 100, Empty::expand()), Empty::expand(), 75 | SizedBox::new(10, 80, Empty::expand()), Empty::expand(), 76 | SizedBox::new(200, 5, Empty::expand()), Empty::expand(), 77 | ]), 78 | Row::new([ 79 | SizedBox::new(120, 80, Empty::expand()), Empty::expand(), 80 | SizedBox::new(240, 300, Empty::expand()), Empty::expand(), 81 | SizedBox::new(40, 100, Empty::expand()), Empty::expand(), 82 | SizedBox::new(10, 80, Empty::expand()), Empty::expand(), 83 | SizedBox::new(200, 5, Empty::expand()), Empty::expand(), 84 | ]), 85 | ] 86 | )); 87 | let rect = softbuffer::Rect { 88 | x: 0, 89 | y: 0, 90 | width: unsafe { NonZeroU32::new_unchecked(1920) }, 91 | height: unsafe { NonZeroU32::new_unchecked(1080) }, 92 | }; 93 | c.bench_function("Compute size for 100 widgets :", |b| { 94 | b.iter(|| { 95 | // this is SUPER UNSAFE: we are building a fake canvas to pass to the draw function. 96 | // however, the widgets won't actually draw anything, so it's fine. 97 | let fake_canvas = [0u8; 8]; 98 | let canvas = unsafe { std::mem::transmute(fake_canvas) }; 99 | black_box(root.draw(canvas, rect)); 100 | }) 101 | }); 102 | } 103 | 104 | 105 | 106 | criterion_group!( 107 | benches, 108 | compute_widget_sizes, 109 | ); 110 | 111 | criterion_main!(benches); 112 | -------------------------------------------------------------------------------- /examples/background.rs: -------------------------------------------------------------------------------- 1 | use nerf::*; 2 | 3 | 4 | 5 | fn main() { 6 | run_app::<(), _>(Background::new( 7 | Color::rgb(123, 175, 150), 8 | Empty::expand(), 9 | ), None).unwrap(); 10 | } 11 | 12 | -------------------------------------------------------------------------------- /examples/button.rs: -------------------------------------------------------------------------------- 1 | 2 | use std::fmt::Debug; 3 | 4 | use nerf::*; 5 | 6 | 7 | pub struct EventPrinter> { 8 | _m: core::marker::PhantomData, 9 | child: Child 10 | } 11 | 12 | impl> Widget for EventPrinter 13 | where Child::EventResponse: Debug 14 | { 15 | type EventResponse = Child::EventResponse; 16 | fn draw(&self, canvas: &mut Canvas, rect: Rect) { 17 | self.child.draw(canvas, rect) 18 | } 19 | fn min_space_requirements(&self) -> (WidgetSizeRequirement, WidgetSizeRequirement) { 20 | self.child.min_space_requirements() 21 | } 22 | fn handle_event(&mut self, event: &AppEvent, rect: nerf::Rect) -> Self::EventResponse { 23 | let response = self.child.handle_event(event, rect); 24 | if !response.is_none() { 25 | println!("Received response: {response:?}"); 26 | } 27 | response 28 | } 29 | } 30 | 31 | 32 | fn main() { 33 | run_app::<(), _>(Align::new( 34 | Alignment::CENTER, 35 | EventPrinter { 36 | _m: core::marker::PhantomData, 37 | child: Button::new( 38 | SizedBox::new( 39 | 200, 80, 40 | Background::new( 41 | Color::rgb(200, 220, 255), 42 | Empty::expand() 43 | ) 44 | ) 45 | ) 46 | } 47 | ), None).unwrap(); 48 | } 49 | -------------------------------------------------------------------------------- /examples/padding.rs: -------------------------------------------------------------------------------- 1 | use nerf::*; 2 | 3 | 4 | 5 | fn main() { 6 | run_app::<(), _>(Padder::new( 7 | PaddType::ALL, 8 | 20, 9 | Background::new( 10 | Color::rgb(220, 255, 230), 11 | Empty::expand(), 12 | ), 13 | ), None).unwrap(); 14 | } 15 | 16 | -------------------------------------------------------------------------------- /examples/scaffold.rs: -------------------------------------------------------------------------------- 1 | use nerf::*; 2 | 3 | 4 | 5 | fn main() { 6 | run_app::<(), _>(Scaffold::new( 7 | ScreenSide::Top, 8 | SizedBox::height( 9 | 100, 10 | Background::new( 11 | Color::rgb(0, 0, 255), 12 | Empty::expand(), 13 | ), 14 | ), 15 | Scaffold::new( 16 | ScreenSide::Left, 17 | SizedBox::width( 18 | 100, 19 | Background::new( 20 | Color::rgb(40, 40, 0), 21 | Empty::shrink())), 22 | Background::new( 23 | Color::rgb(200, 0, 100), 24 | Empty::expand() 25 | ) 26 | ) 27 | ), None).unwrap(); 28 | } 29 | 30 | -------------------------------------------------------------------------------- /examples/sized_box.rs: -------------------------------------------------------------------------------- 1 | use nerf::*; 2 | 3 | 4 | 5 | fn main() { 6 | run_app::<(), _>(Align::new( 7 | Alignment::CENTER, 8 | SizedBox::new( 9 | 400, 10 | 300, 11 | Background::new( 12 | Color::rgb(255, 0, 0), 13 | SizedBox::height( 14 | 50, 15 | Background::new( 16 | Color::rgb(0, 255, 0), 17 | Empty::shrink(), 18 | ) 19 | ), 20 | ) 21 | ) 22 | ), None).unwrap(); 23 | } 24 | 25 | -------------------------------------------------------------------------------- /examples/text.rs: -------------------------------------------------------------------------------- 1 | use nerf::*; 2 | 3 | 4 | 5 | fn main() { 6 | run_app(Align::new( 7 | Alignment::CENTER, 8 | Text::<()>::new( 9 | "HELLO,\nRust! 🦀".to_string(), 10 | TextStyle::default() 11 | .colored(Color::WHITE), 12 | ), 13 | ), None).unwrap(); 14 | } -------------------------------------------------------------------------------- /flake.nix: -------------------------------------------------------------------------------- 1 | { 2 | inputs = { 3 | flake-utils.url = "github:numtide/flake-utils"; 4 | nixpkgs.url = "github:nixos/nixpkgs?ref=release-21.11"; 5 | }; 6 | 7 | outputs = { 8 | self, 9 | nixpkgs, 10 | flake-utils, 11 | ... 12 | }: 13 | flake-utils.lib.eachDefaultSystem (system: 14 | let 15 | pkgs = import nixpkgs { inherit system; }; 16 | in with pkgs; rec { 17 | devShell = mkShell rec { 18 | buildInputs = [ 19 | libxkbcommon 20 | libGL 21 | 22 | # WINIT_UNIX_BACKEND=wayland 23 | wayland 24 | ]; 25 | LD_LIBRARY_PATH = "${lib.makeLibraryPath buildInputs}"; 26 | RUST_BACKTRACE=1; 27 | }; 28 | }); 29 | } -------------------------------------------------------------------------------- /shell.nix: -------------------------------------------------------------------------------- 1 | { pkgs ? import {} }: 2 | 3 | pkgs.mkShell { 4 | nativeBuildInputs = with pkgs; [ 5 | libxkbcommon 6 | libGL 7 | # WINIT_UNIX_BACKEND=wayland 8 | wayland 9 | ]; 10 | LD_LIBRARY_PATH="${pkgs.libxkbcommon}/lib:${pkgs.libGL}/lib:${pkgs.wayland}/lib"; 11 | } -------------------------------------------------------------------------------- /src/app.rs: -------------------------------------------------------------------------------- 1 | use std::num::NonZeroU32; 2 | 3 | use event::AppEvent; 4 | use winit::platform::wayland::WindowAttributesExtWayland; 5 | 6 | use crate::{widget::Widget, Canvas}; 7 | 8 | pub(crate) mod app_context; 9 | pub(crate) mod assets; 10 | pub(crate) mod event; 11 | 12 | enum GraphicState { 13 | Created { 14 | window: std::rc::Rc, 15 | _context: softbuffer::Context>, 16 | surface: softbuffer::Surface, std::rc::Rc>, 17 | }, 18 | ToBeCreated { 19 | window_attributes: winit::window::WindowAttributes 20 | }, 21 | Failed { 22 | error: winit::error::OsError, 23 | } 24 | } 25 | 26 | pub struct ApplicationData> { 27 | _m: core::marker::PhantomData, 28 | graphic_state: GraphicState, 29 | root: Root, 30 | assets: assets::Assets, 31 | } 32 | 33 | impl> winit::application::ApplicationHandler for ApplicationData { 34 | fn resumed(&mut self, event_loop: &winit::event_loop::ActiveEventLoop) { 35 | match &self.graphic_state { 36 | GraphicState::ToBeCreated { window_attributes } => match event_loop.create_window(window_attributes.clone()) { 37 | Ok(window) => { 38 | 39 | let window = std::rc::Rc::new(window); 40 | let context = softbuffer::Context::new(window.clone()).unwrap(); 41 | let surface = softbuffer::Surface::new(&context, window.clone()).unwrap(); 42 | 43 | self.graphic_state = GraphicState::Created { 44 | window, 45 | _context: context, 46 | surface 47 | } 48 | } 49 | Err(error) => { 50 | println!("Failed to create window: {error}"); 51 | self.graphic_state = GraphicState::Failed { error }; 52 | }, 53 | } 54 | GraphicState::Created { .. } => { 55 | // Maybe we have to recreate graphic events here ? 56 | println!("received resume event with graphic state created!") 57 | } 58 | GraphicState::Failed { error } => { 59 | // what to handle here ? 60 | println!("received resume event with a failed graphic state (error: {error})!") 61 | }, 62 | } 63 | } 64 | 65 | fn window_event(&mut self, event_loop: &winit::event_loop::ActiveEventLoop, _window_id: winit::window::WindowId, event: winit::event::WindowEvent) { 66 | match event { 67 | winit::event::WindowEvent::CloseRequested => event_loop.exit(), 68 | winit::event::WindowEvent::Resized(size) => match &mut self.graphic_state { 69 | GraphicState::Created { surface, window, .. } => { 70 | match (NonZeroU32::new(size.width), NonZeroU32::new(size.height)) { 71 | (Some(width), Some(height)) => { 72 | let _ = surface.resize(width, height); // todo handle error 73 | window.request_redraw() 74 | }, 75 | _ => {}, // window got resized to size 0, ignore. It wont be drawn anyway. 76 | } 77 | }, 78 | _ => {}, // window does not exist 79 | }, 80 | winit::event::WindowEvent::RedrawRequested => self.redraw(), 81 | other_event => match (&self.graphic_state, AppEvent::::try_from(other_event)) { 82 | (GraphicState::Created { window, .. }, Some(event)) => { 83 | let inner_size = window.inner_size(); 84 | let rect = crate::Rect { x: 0, y: 0, width: NonZeroU32::new(inner_size.width).unwrap(), height: NonZeroU32::new(inner_size.height).unwrap() }; 85 | let _ = self.root.handle_event(&event, rect); 86 | 87 | }, 88 | _ => {} 89 | } 90 | } 91 | } 92 | } 93 | 94 | impl> ApplicationData { 95 | pub fn redraw(&mut self) { 96 | match &mut self.graphic_state { 97 | GraphicState::Created { window, surface, .. } => { 98 | let inner_size = window.inner_size(); 99 | if (inner_size.width & inner_size.height) > 0 { 100 | let rect = crate::Rect { 101 | x: 0, y: 0, width: NonZeroU32::new(inner_size.width).unwrap(), height: NonZeroU32::new(inner_size.height).unwrap(), 102 | }; 103 | 104 | let mut canvas = Canvas::new( 105 | &mut self.assets, 106 | surface, 107 | inner_size.width, 108 | inner_size.height, 109 | ); 110 | 111 | self.root.draw(&mut canvas, rect); 112 | canvas.present().unwrap(); 113 | } 114 | }, 115 | _ => {}, 116 | } 117 | } 118 | } 119 | 120 | 121 | pub fn run_app>(root: Root, window_attrs: Option) -> Result<(), winit::error::EventLoopError> { 122 | 123 | let assets = assets::Assets::new(); 124 | let event_loop = winit::event_loop::EventLoop::with_user_event().build().unwrap(); 125 | 126 | let window_attributes = match window_attrs { 127 | Some(attrs) => attrs, 128 | None => winit::window::WindowAttributes::default() 129 | .with_name("Nerf", "Nerf"), 130 | }; 131 | 132 | let mut app = ApplicationData { 133 | _m: core::marker::PhantomData, 134 | graphic_state: GraphicState::ToBeCreated { window_attributes }, 135 | root, 136 | assets, 137 | }; 138 | 139 | event_loop.run_app(&mut app) 140 | } 141 | -------------------------------------------------------------------------------- /src/app/app_context.rs: -------------------------------------------------------------------------------- 1 | 2 | 3 | pub struct AppContext { 4 | 5 | } 6 | 7 | impl AppContext { 8 | pub fn new() -> Self { 9 | Self { 10 | 11 | } 12 | } 13 | } -------------------------------------------------------------------------------- /src/app/assets.rs: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | #[cfg(feature = "text")] 5 | pub(crate) mod text_assets; 6 | 7 | 8 | 9 | 10 | /// All assets that are used by the application. 11 | pub struct Assets { 12 | #[cfg(feature = "text")] 13 | text: self::text_assets::TextAssets, 14 | } 15 | 16 | impl Assets { 17 | pub fn new() -> Assets { 18 | Assets { 19 | #[cfg(feature = "text")] 20 | text: self::text_assets::TextAssets::new() 21 | } 22 | } 23 | 24 | #[cfg(feature = "text")] 25 | pub fn text(&self) -> &self::text_assets::TextAssets { 26 | &self.text 27 | } 28 | 29 | #[cfg(feature = "text")] 30 | pub fn text_mut(&mut self) -> &mut self::text_assets::TextAssets { 31 | &mut self.text 32 | } 33 | } -------------------------------------------------------------------------------- /src/app/assets/text_assets.rs: -------------------------------------------------------------------------------- 1 | 2 | 3 | pub struct TextAssets { 4 | font_system: cosmic_text::FontSystem, 5 | swash_cache: cosmic_text::SwashCache, 6 | } 7 | 8 | 9 | impl TextAssets { 10 | pub fn new() -> TextAssets { 11 | TextAssets { 12 | font_system: cosmic_text::FontSystem::new(), 13 | swash_cache: cosmic_text::SwashCache::new(), 14 | } 15 | } 16 | 17 | pub fn fonts_and_cache(&mut self) -> (&mut cosmic_text::FontSystem, &mut cosmic_text::SwashCache) { 18 | (&mut self.font_system, &mut self.swash_cache) 19 | } 20 | } -------------------------------------------------------------------------------- /src/app/event.rs: -------------------------------------------------------------------------------- 1 | 2 | // todo : better names for all of these. 3 | // todo : switch to custom event type ? 4 | 5 | use std::path::PathBuf; 6 | 7 | use winit::{event::{AxisId, ElementState, Ime, Modifiers, MouseButton, MouseScrollDelta, Touch, TouchPhase}, window::Theme}; 8 | 9 | use self::mouse_position::MousePosition; 10 | 11 | pub(crate) mod mouse_position; 12 | 13 | 14 | /// Input Event types supported by the application. 15 | /// This is a slightly modified subset of the winit window events. 16 | #[derive(Debug, Clone, PartialEq)] 17 | pub enum AppEvent { 18 | /// A file has been dropped into the window. 19 | /// 20 | /// When the user drops multiple files at once, this event will be emitted for each file 21 | /// separately. 22 | DroppedFile(PathBuf), 23 | 24 | /// A file is being hovered over the window. 25 | /// 26 | /// When the user hovers multiple files at once, this event will be emitted for each file 27 | /// separately. 28 | HoveredFile(PathBuf), 29 | 30 | /// A file was hovered, but has exited the window. 31 | /// 32 | /// There will be a single `HoveredFileCancelled` event triggered even if multiple files were 33 | /// hovered. 34 | HoveredFileCancelled, 35 | 36 | /// The window received a unicode character. 37 | /// 38 | /// See also the [`Ime`](Self::Ime) event for more complex character sequences. 39 | ReceivedCharacter(char), 40 | 41 | /// The window gained or lost focus. 42 | /// 43 | /// The parameter is true if the window has gained focus, and false if it has lost focus. 44 | Focused(bool), 45 | 46 | /// An event from the keyboard has been received. 47 | KeyboardInput { 48 | /// If `true`, the event was generated synthetically by winit 49 | /// in one of the following circumstances: 50 | /// 51 | /// * Synthetic key press events are generated for all keys pressed 52 | /// when a window gains focus. Likewise, synthetic key release events 53 | /// are generated for all keys pressed when a window goes out of focus. 54 | /// ***Currently, this is only functional on X11 and Windows*** 55 | /// 56 | /// Otherwise, this value is always `false`. 57 | is_synthetic: bool, 58 | }, 59 | 60 | /// The keyboard modifiers have changed. 61 | /// 62 | /// ## Platform-specific 63 | /// 64 | /// - **Web:** This API is currently unimplemented on the web. This isn't by design - it's an 65 | /// issue, and it should get fixed - but it's the current state of the API. 66 | ModifiersChanged(Modifiers), 67 | 68 | /// An event from an input method. 69 | /// 70 | /// **Note:** You have to explicitly enable this event using [`Window::set_ime_allowed`]. 71 | /// 72 | /// ## Platform-specific 73 | /// 74 | /// - **iOS / Android / Web / Orbital:** Unsupported. 75 | Ime(Ime), 76 | 77 | /// The cursor has moved on the window. 78 | CursorMoved { 79 | /// (x,y) coords in pixels relative to the top-left corner of the window. Because the range of this data is 80 | /// limited by the display area and it may have been transformed by the OS to implement effects such as cursor 81 | /// acceleration, it should not be used to implement non-cursor-like interactions such as 3D camera control. 82 | position: MousePosition, 83 | }, 84 | 85 | /// A mouse wheel movement or touchpad scroll occurred. 86 | MouseWheel { 87 | delta: MouseScrollDelta, 88 | phase: TouchPhase, 89 | }, 90 | 91 | /// An mouse button press has been received. 92 | MouseInput { 93 | state: ElementState, 94 | button: MouseButton, 95 | }, 96 | 97 | /// Touchpad magnification event with two-finger pinch gesture. 98 | /// 99 | /// Positive delta values indicate magnification (zooming in) and 100 | /// negative delta values indicate shrinking (zooming out). 101 | /// 102 | /// ## Platform-specific 103 | /// 104 | /// - Only available on **macOS**. 105 | TouchpadMagnify { 106 | delta: f64, 107 | phase: TouchPhase, 108 | }, 109 | 110 | /// Smart magnification event. 111 | /// 112 | /// On a Mac, smart magnification is triggered by a double tap with two fingers 113 | /// on the trackpad and is commonly used to zoom on a certain object 114 | /// (e.g. a paragraph of a PDF) or (sort of like a toggle) to reset any zoom. 115 | /// The gesture is also supported in Safari, Pages, etc. 116 | /// 117 | /// The event is general enough that its generating gesture is allowed to vary 118 | /// across platforms. It could also be generated by another device. 119 | /// 120 | /// Unfortunatly, neither [Windows](https://support.microsoft.com/en-us/windows/touch-gestures-for-windows-a9d28305-4818-a5df-4e2b-e5590f850741) 121 | /// nor [Wayland](https://wayland.freedesktop.org/libinput/doc/latest/gestures.html) 122 | /// support this gesture or any other gesture with the same effect. 123 | /// 124 | /// ## Platform-specific 125 | /// 126 | /// - Only available on **macOS 10.8** and later. 127 | SmartMagnify, 128 | 129 | /// Touchpad rotation event with two-finger rotation gesture. 130 | /// 131 | /// Positive delta values indicate rotation counterclockwise and 132 | /// negative delta values indicate rotation clockwise. 133 | /// 134 | /// ## Platform-specific 135 | /// 136 | /// - Only available on **macOS**. 137 | TouchpadRotate { 138 | delta: f32, 139 | phase: TouchPhase, 140 | }, 141 | 142 | /// Touchpad pressure event. 143 | /// 144 | /// At the moment, only supported on Apple forcetouch-capable macbooks. 145 | /// The parameters are: pressure level (value between 0 and 1 representing how hard the touchpad 146 | /// is being pressed) and stage (integer representing the click level). 147 | TouchpadPressure { 148 | pressure: f32, 149 | stage: i64, 150 | }, 151 | 152 | /// Motion on some analog axis. May report data redundant to other, more specific events. 153 | AxisMotion { 154 | axis: AxisId, 155 | value: f64, 156 | }, 157 | 158 | /// Touch event has been received 159 | /// 160 | /// ## Platform-specific 161 | /// 162 | /// - **macOS:** Unsupported. 163 | Touch(Touch), 164 | 165 | /// The system window theme has changed. 166 | /// 167 | /// Applications might wish to react to this to change the theme of the content of the window 168 | /// when the system changes the window theme. 169 | /// 170 | /// ## Platform-specific 171 | /// 172 | /// - **iOS / Android / X11 / Wayland / Orbital:** Unsupported. 173 | ThemeChanged(Theme), 174 | 175 | /// The window has been occluded (completely hidden from view). 176 | /// 177 | /// This is different to window visibility as it depends on whether the window is closed, 178 | /// minimised, set invisible, or fully occluded by another window. 179 | /// 180 | /// Platform-specific behavior: 181 | /// - **iOS / Android / Web / Wayland / Windows / Orbital:** Unsupported. 182 | Occluded(bool), 183 | 184 | /// Custom event. This is a generic type. 185 | Custom(CustomEvent), 186 | } 187 | 188 | impl AppEvent { 189 | pub fn try_from(raw_event: winit::event::WindowEvent) -> Option> { 190 | match raw_event { 191 | winit::event::WindowEvent::DroppedFile(path) => Some(AppEvent::DroppedFile(path)), 192 | winit::event::WindowEvent::HoveredFile(path) => Some(AppEvent::HoveredFile(path)), 193 | winit::event::WindowEvent::HoveredFileCancelled => Some(AppEvent::HoveredFileCancelled), 194 | winit::event::WindowEvent::Focused(focused) => Some(AppEvent::Focused(focused)), 195 | winit::event::WindowEvent::KeyboardInput { is_synthetic, .. } => Some(AppEvent::KeyboardInput { is_synthetic }), 196 | winit::event::WindowEvent::ModifiersChanged(modifiers) => Some(AppEvent::ModifiersChanged(modifiers)), 197 | winit::event::WindowEvent::Ime(ime) => Some(AppEvent::Ime(ime)), 198 | winit::event::WindowEvent::CursorMoved { position, .. } => Some(AppEvent::CursorMoved { position: MousePosition::from(position) }), 199 | winit::event::WindowEvent::CursorLeft { .. } => Some(AppEvent::CursorMoved { position: MousePosition::OutOfWindow }), 200 | winit::event::WindowEvent::MouseWheel { delta, phase, .. } => Some(AppEvent::MouseWheel { delta, phase }), 201 | winit::event::WindowEvent::MouseInput { state, button, .. } => Some(AppEvent::MouseInput { state, button }), 202 | winit::event::WindowEvent::AxisMotion { axis, value, .. } => Some(AppEvent::AxisMotion { axis, value }), 203 | winit::event::WindowEvent::Touch(touch) => Some(AppEvent::Touch(touch)), 204 | winit::event::WindowEvent::ThemeChanged(theme) => Some(AppEvent::ThemeChanged(theme)), 205 | winit::event::WindowEvent::Occluded(occluded) => Some(AppEvent::Occluded(occluded)), 206 | _ => None, 207 | } 208 | } 209 | } 210 | 211 | impl From for AppEvent { 212 | fn from(event: CustomEvent) -> Self { 213 | AppEvent::Custom(event) 214 | } 215 | } -------------------------------------------------------------------------------- /src/app/event/mouse_position.rs: -------------------------------------------------------------------------------- 1 | use winit::dpi::PhysicalPosition; 2 | 3 | 4 | 5 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] 6 | pub enum MousePosition { 7 | OutOfWindow, 8 | InWindow(u32, u32), 9 | } 10 | 11 | impl From> for MousePosition { 12 | fn from(value: PhysicalPosition) -> Self { 13 | // is this safe enough ? all values are integers, and we are sure they are positive. 14 | // it's unlikely we'll have any value bigger than u32::MAX. 15 | MousePosition::InWindow(value.x as u32, value.y as u32) 16 | } 17 | } 18 | 19 | impl MousePosition { 20 | pub fn is_in_rect(&self, rect: softbuffer::Rect) -> bool { 21 | match self { 22 | MousePosition::OutOfWindow => false, 23 | MousePosition::InWindow(x, y) => { 24 | x >= &rect.x && x < &(rect.x + rect.width.get()) && y >= &rect.y && y < &(rect.y + rect.height.get()) 25 | } 26 | } 27 | } 28 | } -------------------------------------------------------------------------------- /src/drawing.rs: -------------------------------------------------------------------------------- 1 | pub(crate) mod canvas; 2 | pub(crate) mod color; -------------------------------------------------------------------------------- /src/drawing/canvas.rs: -------------------------------------------------------------------------------- 1 | 2 | 3 | use crate::{Color, app::assets::Assets, BorderType}; 4 | 5 | /// If the text features is enabled, implements text drawing operations. 6 | #[cfg(feature = "text")] 7 | pub(crate) mod text; 8 | 9 | pub struct Canvas<'a> { 10 | assets: Option<&'a mut Assets>, 11 | buffer: softbuffer::Buffer<'a, std::rc::Rc, std::rc::Rc>, 12 | surface_width: u32, 13 | surface_height: u32, 14 | } 15 | 16 | /// A canvas is a buffer that can be drawn on. 17 | impl<'a> Canvas<'a> { 18 | pub fn new( 19 | assets: &'a mut Assets, 20 | surface: &'a mut softbuffer::Surface, std::rc::Rc>, 21 | surface_width: u32, 22 | surface_height: u32, 23 | ) -> Canvas<'a> { 24 | let buffer = surface.buffer_mut().unwrap(); 25 | Canvas { 26 | assets: Some(assets), 27 | buffer, 28 | surface_width, 29 | surface_height, 30 | } 31 | } 32 | 33 | pub fn buffer(self) -> softbuffer::Buffer<'a, std::rc::Rc, std::rc::Rc> { 34 | self.buffer 35 | } 36 | 37 | pub fn present(self) -> Result<(), softbuffer::SoftBufferError> { 38 | self.buffer.present() 39 | } 40 | 41 | 42 | } 43 | 44 | 45 | #[cfg(feature = "skia")] 46 | impl<'a> Canvas<'a> { 47 | 48 | fn softbuffer_to_skia_rect(rect: softbuffer::Rect) -> tiny_skia::Rect { 49 | tiny_skia::Rect::from_xywh( 50 | rect.x as f32, 51 | rect.y as f32, 52 | rect.width.get() as f32, 53 | rect.height.get() as f32, 54 | ).unwrap() 55 | } 56 | 57 | pub fn fill_rect(&mut self, rect: softbuffer::Rect, color: Color) { 58 | // todo : create a single skia pixmap with canvas creation, and reuse it. 59 | let slice = unsafe { 60 | std::slice::from_raw_parts_mut( 61 | self.buffer.as_mut_ptr() as *mut u8, 62 | (self.surface_height * self.surface_width * 4) as usize, 63 | ) 64 | }; 65 | let mut skia_pixmap = tiny_skia::PixmapMut::from_bytes( 66 | slice, 67 | self.surface_width, 68 | self.surface_height, 69 | ).unwrap(); 70 | skia_pixmap.fill_rect( 71 | Self::softbuffer_to_skia_rect(rect), 72 | &Color::into(color), 73 | tiny_skia::Transform::identity(), 74 | None, 75 | ); 76 | } 77 | 78 | pub fn fill_decorated( 79 | &mut self, 80 | rect: softbuffer::Rect, 81 | fill_color: Option, 82 | border_color: Option, 83 | border_type: BorderType, 84 | corner_radius: u32, 85 | border_width: u32, 86 | ) { 87 | let mut border_width = border_width; 88 | let slice = unsafe { 89 | std::slice::from_raw_parts_mut( 90 | self.buffer.as_mut_ptr() as *mut u8, 91 | (self.surface_height * self.surface_width * 4) as usize, 92 | ) 93 | }; 94 | let mut skia_pixmap = tiny_skia::PixmapMut::from_bytes( 95 | slice, 96 | self.surface_width, 97 | self.surface_height, 98 | ).unwrap(); 99 | // build the path ! 100 | let mut path = tiny_skia::PathBuilder::new(); 101 | border_type.build_path(&mut path, rect, &mut border_width, corner_radius); 102 | let path = path.finish().unwrap(); 103 | 104 | if let Some(color) = border_color { 105 | let paint = color.into(); 106 | let stroke = tiny_skia::Stroke { 107 | width: border_width as f32, 108 | ..Default::default() 109 | }; 110 | skia_pixmap.stroke_path(&path, &paint, &stroke, tiny_skia::Transform::identity(), None); 111 | } 112 | if let Some(color) = fill_color { 113 | let paint = color.into(); 114 | skia_pixmap.fill_path(&path, &paint, tiny_skia::FillRule::Winding, tiny_skia::Transform::identity(), None); 115 | } 116 | 117 | } 118 | 119 | 120 | 121 | 122 | } 123 | 124 | // If skia is not used (desabled features), we still support minimal drawing operations. 125 | #[cfg(not(feature = "skia"))] 126 | impl<'a> Canvas<'a> { 127 | 128 | pub fn draw_pixel(&mut self, x: u32, y: u32, color: u32){ 129 | // FIXME: broken because alpha not taken into consideration ! 130 | self.buffer[(y * self.surface_width + x) as usize] = color; 131 | } 132 | 133 | pub fn fill_rect(&mut self, rect: softbuffer::Rect, color: Color) { 134 | let color = color.value(); 135 | for y in rect.y..rect.y + rect.height.get() { 136 | for x in rect.x..rect.x + rect.width.get() { 137 | self.draw_pixel(x, y, color); 138 | } 139 | } 140 | } 141 | } 142 | 143 | -------------------------------------------------------------------------------- /src/drawing/canvas/text.rs: -------------------------------------------------------------------------------- 1 | use std::num::NonZeroU32; 2 | 3 | use crate::{Canvas, TextStyle}; 4 | 5 | 6 | 7 | 8 | impl<'a> Canvas<'a> { 9 | pub fn draw_text(&mut self, text: &str, rect: softbuffer::Rect, style: &TextStyle) { 10 | // Text metrics indicate the font size and line height of a buffer 11 | // note to myself : line height is the space between the top of the buffer and the baseline of the text, 12 | // then, it is also the space between the baseline of the text and the baseline of the next line. 13 | let metrics = cosmic_text::Metrics::new(style.size, style.size + style.additional_interline); 14 | // the option is a hack for now, because the draw closure requires another access to self. 15 | // this will decouple the assets from the canvas 16 | let assets = self.assets.take().unwrap(); 17 | let (font_system, swash_cache) = assets.text_mut().fonts_and_cache(); 18 | 19 | // A Buffer provides shaping and layout for a UTF-8 string, create one per text widget 20 | let mut buffer = cosmic_text::Buffer::new(font_system, metrics); 21 | 22 | // Borrow buffer together with the font system for more convenient method calls 23 | let mut buffer = buffer.borrow_with(font_system); 24 | 25 | // Set a size for the text buffer, in pixels 26 | buffer.set_size(rect.width.get() as f32, rect.height.get() as f32); 27 | buffer.set_wrap(style.overflow.into()); 28 | 29 | // Add some text! 30 | let attrs = cosmic_text::Attrs::new(); 31 | buffer.set_text(text, attrs, cosmic_text::Shaping::Basic); 32 | 33 | /* 34 | 35 | */ 36 | 37 | // Perform shaping as desired 38 | buffer.shape_until_scroll(); // todo what is this for ? works fine without 39 | 40 | // Draw the buffer (for performance, instead use SwashCache directly) 41 | // todo : improve perf using the above indication 42 | buffer.draw(swash_cache, style.color.into(), |x, y, w, h, color| { 43 | match (NonZeroU32::new(w), NonZeroU32::new(h), u32::try_from(x), u32::try_from(y)) { 44 | (Some(width), Some(height), Ok(x), Ok(y)) => { 45 | let rect_to_draw = softbuffer::Rect { x: rect.x + x, y: rect.y + y, width, height }; 46 | self.fill_rect(rect_to_draw, color.into()); 47 | }, 48 | _ => {}, 49 | } 50 | }); 51 | 52 | self.assets = Some(assets); 53 | } 54 | } -------------------------------------------------------------------------------- /src/drawing/color.rs: -------------------------------------------------------------------------------- 1 | 2 | #[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord)] 3 | pub struct Color { 4 | pub r: u8, 5 | pub g: u8, 6 | pub b: u8, 7 | pub a: u8, 8 | } 9 | 10 | impl Color { 11 | pub const fn rgb(r: u8, g: u8, b: u8) -> Self { 12 | Color { r, g, b, a: 255 } 13 | } 14 | 15 | pub const fn rgba(r: u8, g: u8, b: u8, a: u8) -> Self { 16 | Color { r, g, b, a } 17 | } 18 | 19 | pub fn value(self) -> u32 { 20 | (self.r as u32) << 16 | (self.g as u32) << 8 | (self.b as u32) 21 | } 22 | 23 | pub fn r(self) -> u8 { 24 | self.r 25 | } 26 | 27 | pub fn g(self) -> u8 { 28 | self.g 29 | } 30 | 31 | pub fn b(self) -> u8 { 32 | self.b 33 | } 34 | 35 | pub fn a(self) -> u8 { 36 | self.a 37 | } 38 | 39 | 40 | } 41 | 42 | // default values 43 | impl Color { 44 | pub const BLACK: Color = Color::rgb(0, 0, 0); 45 | pub const WHITE: Color = Color::rgb(u8::MAX, u8::MAX, u8::MAX); 46 | } 47 | 48 | 49 | #[cfg(feature = "skia")] 50 | impl<'a> Into> for Color { 51 | /// If the skia feature is enabled, this will convert the color into a skia paint. 52 | fn into(self) -> tiny_skia::Paint<'a> { 53 | let mut paint = tiny_skia::Paint::default(); 54 | // todo : colors seem to be inverted ? r and b are switched ? 55 | paint.set_color_rgba8(self.b, self.g, self.r, self.a); 56 | paint 57 | } 58 | } 59 | 60 | 61 | #[cfg(feature = "text")] 62 | impl Into for Color { 63 | /// If the text feature is enabled, this will convert the color into a text color. 64 | fn into(self) -> cosmic_text::Color { 65 | cosmic_text::Color::rgba(self.r, self.g, self.b, self.a) 66 | } 67 | } 68 | 69 | #[cfg(feature = "text")] 70 | impl From for Color { 71 | /// If the text feature is enabled, this will convert the text color into a color. 72 | fn from(value: cosmic_text::Color) -> Self { 73 | Color::rgba(value.r(), value.g(), value.b(), value.a()) 74 | } 75 | } -------------------------------------------------------------------------------- /src/geometry.rs: -------------------------------------------------------------------------------- 1 | 2 | 3 | pub(crate) mod alignment; 4 | pub(crate) mod decoration; 5 | pub(crate) mod rect; 6 | pub(crate) mod screen_side; 7 | pub(crate) mod size_requirements; 8 | 9 | 10 | -------------------------------------------------------------------------------- /src/geometry/alignment.rs: -------------------------------------------------------------------------------- 1 | 2 | 3 | pub enum HorizontalAlignment { 4 | Left, 5 | Center, 6 | Right, 7 | } 8 | 9 | pub enum VerticalAlignment { 10 | Top, 11 | Center, 12 | Bottom, 13 | } 14 | 15 | pub struct Alignment(HorizontalAlignment, VerticalAlignment); 16 | 17 | impl Alignment { 18 | pub const TOP_LEFT: Alignment = Alignment(HorizontalAlignment::Left, VerticalAlignment::Top); 19 | pub const TOP_CENTER: Alignment = Alignment(HorizontalAlignment::Center, VerticalAlignment::Top); 20 | pub const TOP_RIGHT: Alignment = Alignment(HorizontalAlignment::Right, VerticalAlignment::Top); 21 | pub const CENTER_LEFT: Alignment = Alignment(HorizontalAlignment::Left, VerticalAlignment::Center); 22 | pub const CENTER: Alignment = Alignment(HorizontalAlignment::Center, VerticalAlignment::Center); 23 | pub const CENTER_RIGHT: Alignment = Alignment(HorizontalAlignment::Right, VerticalAlignment::Center); 24 | pub const BOTTOM_LEFT: Alignment = Alignment(HorizontalAlignment::Left, VerticalAlignment::Bottom); 25 | pub const BOTTOM_CENTER: Alignment = Alignment(HorizontalAlignment::Center, VerticalAlignment::Bottom); 26 | pub const BOTTOM_RIGHT: Alignment = Alignment(HorizontalAlignment::Right, VerticalAlignment::Bottom); 27 | 28 | 29 | pub fn get_left_space(&self, available_space: u32) -> u32 { 30 | match self.0 { 31 | HorizontalAlignment::Left => 0, 32 | HorizontalAlignment::Center => available_space / 2, 33 | HorizontalAlignment::Right => available_space, 34 | } 35 | } 36 | 37 | pub fn get_top_space(&self, available_space: u32) -> u32 { 38 | match self.1 { 39 | VerticalAlignment::Top => 0, 40 | VerticalAlignment::Center => available_space / 2, 41 | VerticalAlignment::Bottom => available_space, 42 | } 43 | } 44 | } -------------------------------------------------------------------------------- /src/geometry/decoration.rs: -------------------------------------------------------------------------------- 1 | use tiny_skia::PathBuilder; 2 | 3 | 4 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] 5 | pub struct BorderType(u8); 6 | 7 | 8 | impl BorderType { 9 | pub const ROUND_NONE: BorderType = BorderType(0b0000_0000); 10 | pub const ROUND_TOP_LEFT: BorderType = BorderType(0b0000_0001); 11 | pub const ROUND_TOP_RIGHT: BorderType = BorderType(0b0000_0010); 12 | pub const ROUND_BOTTOM_RIGHT: BorderType = BorderType(0b0000_10100); 13 | pub const ROUND_BOTTOM_LEFT: BorderType = BorderType(0b0000_1000); 14 | pub const ROUND_TOP: BorderType = BorderType(0b0000_0011); 15 | pub const ROUND_BOTTOM: BorderType = BorderType(0b0000_1100); 16 | pub const ROUND_LEFT: BorderType = BorderType(0b0000_1001); 17 | pub const ROUND_RIGHT: BorderType = BorderType(0b0000_1001); 18 | pub const ROUND_ALL: BorderType = BorderType(0b0000_1111); 19 | } 20 | 21 | 22 | #[cfg(feature = "skia")] 23 | impl BorderType { 24 | pub fn build_path(&self, path: &mut PathBuilder, rect: softbuffer::Rect, border_width: &mut u32, radius: u32) { 25 | 26 | // radius can not be smaller than the border width, nor bigger than half the rect size 27 | let radius = radius.max(*border_width).min((rect.width.get() >> 1).min(rect.height.get() >> 1)); 28 | // the border width can not be bigger than half the rect size 29 | *border_width = (*border_width).min(rect.width.get() >> 1).min(rect.height.get() >> 1); 30 | 31 | let border_offset = *border_width >> 1; 32 | // top left corner 33 | if self.0 & 1 > 0 { 34 | path.move_to( 35 | (rect.x + border_offset) as f32, 36 | (rect.y + radius) as f32 37 | ); 38 | path.quad_to( 39 | (rect.x + border_offset) as f32, 40 | (rect.y + border_offset) as f32, 41 | (rect.x + radius) as f32, 42 | (rect.y + border_offset) as f32, 43 | ); 44 | } 45 | else { 46 | path.move_to( 47 | (rect.x + border_offset) as f32, 48 | (rect.y + border_offset) as f32 49 | ); 50 | } 51 | // top right corner 52 | if self.0 & (1 << 1) > 0 { 53 | path.line_to( 54 | (rect.x + rect.width.get() - radius) as f32, 55 | (rect.y + border_offset) as f32 56 | ); 57 | path.quad_to( 58 | (rect.x + rect.width.get() - border_offset) as f32, 59 | (rect.y + border_offset) as f32, 60 | (rect.x + rect.width.get() - border_offset) as f32, 61 | (rect.y + radius) as f32, 62 | ); 63 | } 64 | else { 65 | path.line_to( 66 | (rect.x + rect.width.get() - border_offset) as f32, 67 | (rect.y + border_offset) as f32 68 | ); 69 | } 70 | // bottom right corner 71 | if self.0 & (1 << 2) > 0 { 72 | path.line_to( 73 | (rect.x + rect.width.get() - border_offset) as f32, 74 | (rect.y + rect.height.get()) as f32 - radius as f32, 75 | ); 76 | path.quad_to( 77 | (rect.x + rect.width.get() - border_offset) as f32, 78 | (rect.y + rect.height.get() - border_offset) as f32, 79 | (rect.x + rect.width.get()) as f32 - radius as f32, 80 | (rect.y + rect.height.get() - border_offset) as f32, 81 | ); 82 | } 83 | else { 84 | path.line_to( 85 | (rect.x + rect.width.get() - border_offset) as f32, 86 | (rect.y + rect.height.get() - border_offset) as f32 87 | ); 88 | } 89 | // bottom left corner 90 | if self.0 & (1 << 3) > 0 { 91 | path.line_to( 92 | (rect.x + radius) as f32, 93 | (rect.y + rect.height.get() - border_offset) as f32, 94 | ); 95 | path.quad_to( 96 | (rect.x + border_offset) as f32, 97 | (rect.y + rect.height.get() - border_offset) as f32, 98 | (rect.x + border_offset) as f32, 99 | (rect.y + rect.height.get()) as f32 - radius as f32, 100 | ); 101 | } 102 | else { 103 | path.line_to( 104 | (rect.x + border_offset) as f32, 105 | (rect.y + rect.height.get() - border_offset) as f32 106 | ); 107 | } 108 | // close the path 109 | path.close(); 110 | 111 | } 112 | 113 | } 114 | 115 | 116 | impl std::ops::BitOr for BorderType { 117 | type Output = BorderType; 118 | 119 | fn bitor(self, rhs: Self) -> Self::Output { 120 | BorderType(self.0 | rhs.0) 121 | } 122 | } -------------------------------------------------------------------------------- /src/geometry/rect.rs: -------------------------------------------------------------------------------- 1 | use std::num::NonZeroU32; 2 | 3 | 4 | pub type Rect = softbuffer::Rect; 5 | 6 | pub struct NullableRect { 7 | pub x: u32, 8 | pub y: u32, 9 | pub width: u32, 10 | pub height: u32, 11 | } 12 | 13 | 14 | 15 | 16 | impl TryFrom for softbuffer::Rect { 17 | type Error = (); 18 | fn try_from(value: NullableRect) -> Result { 19 | match (NonZeroU32::new(value.width), NonZeroU32::new(value.height)) { 20 | (Some(width), Some(height)) => Ok(softbuffer::Rect { 21 | x: value.x, y: value.y, width, height 22 | }), 23 | _ => Err(()) 24 | } 25 | } 26 | } 27 | 28 | 29 | -------------------------------------------------------------------------------- /src/geometry/screen_side.rs: -------------------------------------------------------------------------------- 1 | 2 | 3 | pub enum ScreenSide { 4 | Top, 5 | Bottom, 6 | Left, 7 | Right, 8 | } -------------------------------------------------------------------------------- /src/geometry/size_requirements.rs: -------------------------------------------------------------------------------- 1 | use std::num::NonZeroU32; 2 | 3 | 4 | 5 | /// Size requirements a widget can have. 6 | /// Here, widgets have no minimum sizes, as the display size can be as small as possible. 7 | /// Widgets can require to have a fix size, or a maximum size. 8 | #[derive(Clone, Copy, PartialEq, Eq, Debug)] 9 | pub enum WidgetSizeRequirement { 10 | /// The widget request a fixed size. 11 | Fixed { 12 | size: NonZeroU32, 13 | }, 14 | /// The widget request a minimum size, but can be expanded. 15 | /// This requirement is a soft requirement, and can be ignored. 16 | /// However, in debug mode, size overflow will be checked. 17 | Min { 18 | min: NonZeroU32, 19 | flex: NonZeroU32, 20 | }, 21 | /// The widget request a maximum size, but can be reduced. 22 | Max { 23 | max: NonZeroU32, 24 | flex: NonZeroU32, 25 | }, 26 | /// The widget request a minimum and a maximum size. 27 | /// The min requirement is a soft requirement, and can be ignored. 28 | /// However, in debug mode, size overflow will be checked. 29 | MinMax { 30 | min: NonZeroU32, 31 | max: NonZeroU32, 32 | flex: NonZeroU32, 33 | }, 34 | /// The widget have no size constraints, and will fill up all the available space. 35 | /// The given value is the flex value, and tells how to distribute the remaining space. 36 | Flex { 37 | flex: NonZeroU32, 38 | }, 39 | /// The widget have no size constraints. 40 | /// In most use cases, this will tell that there is no widget. 41 | /// This is the same as a fixed size of 0, or a flex of 0. 42 | None, 43 | } 44 | 45 | impl std::ops::BitOr for WidgetSizeRequirement { 46 | type Output = Self; 47 | /// The bitor between two size requirements is as if they were next to eachother, and we are looking for a requirement that fits both. 48 | /// 49 | /// +---- Bit Or requirement ----> 50 | /// | +--------+ 51 | /// | | | 52 | /// | | | 53 | /// | +--------+ 54 | /// | +------------+ 55 | /// | | | 56 | /// | | | 57 | /// | +------------+ 58 | /// v 59 | fn bitor(self, rhs: Self) -> Self::Output { 60 | match (self, rhs) { 61 | // None 62 | (WidgetSizeRequirement::None, WidgetSizeRequirement::None) => WidgetSizeRequirement::None, 63 | (other, WidgetSizeRequirement::None) => other, 64 | (WidgetSizeRequirement::None, other) => other, 65 | // Fixed, other 66 | (WidgetSizeRequirement::Fixed { size: s1 }, WidgetSizeRequirement::Fixed { size: s2 }) => 67 | WidgetSizeRequirement::Fixed { size: s1.max(s2) }, 68 | (WidgetSizeRequirement::Fixed { size }, WidgetSizeRequirement::Flex { flex }) => 69 | WidgetSizeRequirement::Min { min: size, flex }, 70 | (WidgetSizeRequirement::Fixed { size }, WidgetSizeRequirement::Min { min, flex }) => 71 | WidgetSizeRequirement::Min { min: size.saturating_add(min.get()), flex }, 72 | (WidgetSizeRequirement::Fixed { size }, WidgetSizeRequirement::Max { max, flex }) => 73 | WidgetSizeRequirement::MinMax { min: size, max: max.saturating_add(size.get()), flex, }, 74 | (WidgetSizeRequirement::Fixed { size }, WidgetSizeRequirement::MinMax { min, max, flex }) => 75 | WidgetSizeRequirement::MinMax { min: min.saturating_add(size.get()), max: max.saturating_add(size.get()), flex }, 76 | // Flex, other 77 | (WidgetSizeRequirement::Flex { flex }, WidgetSizeRequirement::Fixed { size }) => 78 | WidgetSizeRequirement::Min { min: size, flex }, 79 | (WidgetSizeRequirement::Flex { flex: f1 }, WidgetSizeRequirement::Flex { flex: f2 }) => 80 | WidgetSizeRequirement::Flex { flex: f1.saturating_add(f2.get()) }, 81 | (WidgetSizeRequirement::Flex { flex: f1 }, WidgetSizeRequirement::Min { min, flex: f2 }) => 82 | WidgetSizeRequirement::Min { min, flex: f1.saturating_add(f2.get()) }, 83 | (WidgetSizeRequirement::Flex { flex: f1 }, WidgetSizeRequirement::Max { flex: f2, .. }) => 84 | WidgetSizeRequirement::Flex { flex: f1.saturating_add(f2.get()) }, 85 | (WidgetSizeRequirement::Flex { flex: f1 }, WidgetSizeRequirement::MinMax { min, flex: f2, .. }) => 86 | WidgetSizeRequirement::Min { min, flex: f1.saturating_add(f2.get())}, 87 | // Min, other 88 | (WidgetSizeRequirement::Min { min, flex }, WidgetSizeRequirement::Fixed { size }) => 89 | WidgetSizeRequirement::Min { min: min.saturating_add(size.get()), flex }, 90 | (WidgetSizeRequirement::Min { min, flex: f1 }, WidgetSizeRequirement::Flex { flex: f2 }) => 91 | WidgetSizeRequirement::Min { min, flex: f1.saturating_add(f2.get()) }, 92 | (WidgetSizeRequirement::Min { min: m1, flex: f1 }, WidgetSizeRequirement::Min { min: m2, flex: f2 }) => 93 | WidgetSizeRequirement::Min { min: m1.saturating_add(m2.get()), flex: f1.saturating_add(f2.get()) }, 94 | (WidgetSizeRequirement::Min { min, flex: f1 }, WidgetSizeRequirement::Max { flex: f2, .. }) => 95 | WidgetSizeRequirement::Min { min, flex: f1.saturating_add(f2.get()) }, 96 | (WidgetSizeRequirement::Min { min: m1, flex: f1 }, WidgetSizeRequirement::MinMax { min: m2, flex: f2, .. }) => 97 | WidgetSizeRequirement::Min { min: m1.saturating_add(m2.get()), flex: f1.saturating_add(f2.get()) }, 98 | // Max, other 99 | (WidgetSizeRequirement::Max { max, flex }, WidgetSizeRequirement::Fixed { size }) => 100 | WidgetSizeRequirement::Max { max: max.saturating_add(size.get()), flex }, 101 | (WidgetSizeRequirement::Max { flex: f1, .. }, WidgetSizeRequirement::Flex { flex: f2 }) => 102 | WidgetSizeRequirement::Flex { flex: f1.saturating_add(f2.get())}, 103 | (WidgetSizeRequirement::Max { flex: f1, .. }, WidgetSizeRequirement::Min { min, flex: f2 }) => 104 | WidgetSizeRequirement::Min { min, flex: f1.saturating_add(f2.get()) }, 105 | (WidgetSizeRequirement::Max { max: m1, flex: f1 }, WidgetSizeRequirement::Max { max: m2, flex: f2 }) => 106 | WidgetSizeRequirement::Max { max: m1.saturating_add(m2.get()), flex: f1.saturating_add(f2.get()) }, 107 | (WidgetSizeRequirement::Max { max: m1, flex: f1 }, WidgetSizeRequirement::MinMax { min, max: m2, flex: f2 }) => 108 | WidgetSizeRequirement::MinMax { min, max: m1.saturating_add(m2.get()), flex: f1.saturating_add(f2.get()) }, 109 | // MinMax, other 110 | (WidgetSizeRequirement::MinMax { min, max, flex }, WidgetSizeRequirement::Fixed { size }) => 111 | WidgetSizeRequirement::MinMax { min: min.saturating_add(size.get()), max: max.saturating_add(size.get()), flex }, 112 | (WidgetSizeRequirement::MinMax { min, flex: f1, .. }, WidgetSizeRequirement::Flex { flex: f2 }) => 113 | WidgetSizeRequirement::Min { min, flex: f1.saturating_add(f2.get()) }, 114 | (WidgetSizeRequirement::MinMax { min: m1, flex: f1, .. }, WidgetSizeRequirement::Min { min: m2, flex: f2 }) => 115 | WidgetSizeRequirement::Min { min: m1.saturating_add(m2.get()), flex: f1.saturating_add(f2.get()) }, 116 | (WidgetSizeRequirement::MinMax { min, max: m1, flex: f1 }, WidgetSizeRequirement::Max { max: m2, flex: f2 }) => 117 | WidgetSizeRequirement::MinMax { min, max: m1.saturating_add(m2.get()), flex: f1.saturating_add(f2.get()) }, 118 | (WidgetSizeRequirement::MinMax { min: mi1, max: ma1, flex: f1 }, WidgetSizeRequirement::MinMax { min: mi2, max: ma2, flex: f2 }) => 119 | WidgetSizeRequirement::MinMax { min: mi1.saturating_add(mi2.get()), max: ma1.saturating_add(ma2.get()), flex: f1.saturating_add(f2.get()) }, 120 | } 121 | } 122 | } 123 | 124 | impl std::ops::BitAnd for WidgetSizeRequirement { 125 | type Output = Self; 126 | /// The bitand between two size requirements is as if they were following each other, and we are looking for a requirement that fits the sum of them. 127 | /// 128 | /// +---- Bit And requirement ----> 129 | /// | +--------+ +------------+ 130 | /// | | | | | 131 | /// | | | | | 132 | /// | +--------+ +------------+ 133 | /// | 134 | /// v 135 | fn bitand(self, rhs: Self) -> Self::Output { 136 | match (self, rhs) { 137 | // None 138 | (WidgetSizeRequirement::None, WidgetSizeRequirement::None) => WidgetSizeRequirement::None, 139 | (other, WidgetSizeRequirement::None) => other, 140 | (WidgetSizeRequirement::None, other) => other, 141 | // Fixed, other 142 | (WidgetSizeRequirement::Fixed { size: s1 }, WidgetSizeRequirement::Fixed { size: s2 }) => 143 | WidgetSizeRequirement::Fixed { size: s1.saturating_add(s2.get()) }, 144 | (WidgetSizeRequirement::Fixed { size }, WidgetSizeRequirement::Flex { flex }) => 145 | WidgetSizeRequirement::Min { min: size, flex }, 146 | (WidgetSizeRequirement::Fixed { size }, WidgetSizeRequirement::Min { min, flex }) => 147 | WidgetSizeRequirement::Min { min: size.saturating_add(min.get()), flex }, 148 | (WidgetSizeRequirement::Fixed { size }, WidgetSizeRequirement::Max { max, flex }) => 149 | WidgetSizeRequirement::MinMax { min: size, max: max.saturating_add(size.get()), flex, }, 150 | (WidgetSizeRequirement::Fixed { size }, WidgetSizeRequirement::MinMax { min, max, flex }) => 151 | WidgetSizeRequirement::MinMax { min: min.saturating_add(size.get()), max: max.saturating_add(size.get()), flex }, 152 | // Flex, other 153 | (WidgetSizeRequirement::Flex { flex }, WidgetSizeRequirement::Fixed { size }) => 154 | WidgetSizeRequirement::Min { min: size, flex }, 155 | (WidgetSizeRequirement::Flex { flex: f1 }, WidgetSizeRequirement::Flex { flex: f2 }) => 156 | WidgetSizeRequirement::Flex { flex: f1.saturating_add(f2.get()) }, 157 | (WidgetSizeRequirement::Flex { flex: f1 }, WidgetSizeRequirement::Min { min, flex: f2 }) => 158 | WidgetSizeRequirement::Min { min, flex: f1.saturating_add(f2.get()) }, 159 | (WidgetSizeRequirement::Flex { flex: f1 }, WidgetSizeRequirement::Max { flex: f2, .. }) => 160 | WidgetSizeRequirement::Flex { flex: f1.saturating_add(f2.get()) }, 161 | (WidgetSizeRequirement::Flex { flex: f1 }, WidgetSizeRequirement::MinMax { min, flex: f2, .. }) => 162 | WidgetSizeRequirement::Min { min, flex: f1.saturating_add(f2.get())}, 163 | // Min, other 164 | (WidgetSizeRequirement::Min { min, flex }, WidgetSizeRequirement::Fixed { size }) => 165 | WidgetSizeRequirement::Min { min: min.saturating_add(size.get()), flex }, 166 | (WidgetSizeRequirement::Min { min, flex: f1 }, WidgetSizeRequirement::Flex { flex: f2 }) => 167 | WidgetSizeRequirement::Min { min, flex: f1.saturating_add(f2.get()) }, 168 | (WidgetSizeRequirement::Min { min: m1, flex: f1 }, WidgetSizeRequirement::Min { min: m2, flex: f2 }) => 169 | WidgetSizeRequirement::Min { min: m1.saturating_add(m2.get()), flex: f1.saturating_add(f2.get()) }, 170 | (WidgetSizeRequirement::Min { min, flex: f1 }, WidgetSizeRequirement::Max { flex: f2, .. }) => 171 | WidgetSizeRequirement::Min { min, flex: f1.saturating_add(f2.get()) }, 172 | (WidgetSizeRequirement::Min { min: m1, flex: f1 }, WidgetSizeRequirement::MinMax { min: m2, flex: f2, .. }) => 173 | WidgetSizeRequirement::Min { min: m1.saturating_add(m2.get()), flex: f1.saturating_add(f2.get()) }, 174 | // Max, other 175 | (WidgetSizeRequirement::Max { max, flex }, WidgetSizeRequirement::Fixed { size }) => 176 | WidgetSizeRequirement::Max { max: max.saturating_add(size.get()), flex }, 177 | (WidgetSizeRequirement::Max { flex: f1, .. }, WidgetSizeRequirement::Flex { flex: f2 }) => 178 | WidgetSizeRequirement::Flex { flex: f1.saturating_add(f2.get())}, 179 | (WidgetSizeRequirement::Max { flex: f1, .. }, WidgetSizeRequirement::Min { min, flex: f2 }) => 180 | WidgetSizeRequirement::Min { min, flex: f1.saturating_add(f2.get()) }, 181 | (WidgetSizeRequirement::Max { max: m1, flex: f1 }, WidgetSizeRequirement::Max { max: m2, flex: f2 }) => 182 | WidgetSizeRequirement::Max { max: m1.saturating_add(m2.get()), flex: f1.saturating_add(f2.get()) }, 183 | (WidgetSizeRequirement::Max { max: m1, flex: f1 }, WidgetSizeRequirement::MinMax { min, max: m2, flex: f2 }) => 184 | WidgetSizeRequirement::MinMax { min, max: m1.saturating_add(m2.get()), flex: f1.saturating_add(f2.get()) }, 185 | // MinMax, other 186 | (WidgetSizeRequirement::MinMax { min, max, flex }, WidgetSizeRequirement::Fixed { size }) => 187 | WidgetSizeRequirement::MinMax { min: min.saturating_add(size.get()), max: max.saturating_add(size.get()), flex }, 188 | (WidgetSizeRequirement::MinMax { min, flex: f1, .. }, WidgetSizeRequirement::Flex { flex: f2 }) => 189 | WidgetSizeRequirement::Min { min, flex: f1.saturating_add(f2.get()) }, 190 | (WidgetSizeRequirement::MinMax { min: m1, flex: f1, .. }, WidgetSizeRequirement::Min { min: m2, flex: f2 }) => 191 | WidgetSizeRequirement::Min { min: m1.saturating_add(m2.get()), flex: f1.saturating_add(f2.get()) }, 192 | (WidgetSizeRequirement::MinMax { min, max: m1, flex: f1 }, WidgetSizeRequirement::Max { max: m2, flex: f2 }) => 193 | WidgetSizeRequirement::MinMax { min, max: m1.saturating_add(m2.get()), flex: f1.saturating_add(f2.get()) }, 194 | (WidgetSizeRequirement::MinMax { min: mi1, max: ma1, flex: f1 }, WidgetSizeRequirement::MinMax { min: mi2, max: ma2, flex: f2 }) => 195 | WidgetSizeRequirement::MinMax { min: mi1.saturating_add(mi2.get()), max: ma1.saturating_add(ma2.get()), flex: f1.saturating_add(f2.get()) }, 196 | } 197 | } 198 | } 199 | 200 | impl core::ops::Add for WidgetSizeRequirement { 201 | type Output = Self; 202 | fn add(self, rhs: u32) -> Self::Output { 203 | match self { 204 | WidgetSizeRequirement::Fixed { size } => WidgetSizeRequirement::Fixed { size: size.saturating_add(rhs) }, 205 | WidgetSizeRequirement::Flex { flex } => match NonZeroU32::new(rhs) { 206 | Some(min) => WidgetSizeRequirement::Min { min, flex }, 207 | None => WidgetSizeRequirement::Flex { flex }, 208 | }, 209 | WidgetSizeRequirement::Max { max, flex } => match NonZeroU32::new(rhs) { 210 | Some(min) => WidgetSizeRequirement::MinMax { min, max: max.saturating_add(rhs), flex, }, 211 | None => WidgetSizeRequirement::Max { max, flex }, 212 | }, 213 | WidgetSizeRequirement::Min { min, flex } => 214 | WidgetSizeRequirement::Min { min: min.saturating_add(rhs), flex }, 215 | WidgetSizeRequirement::MinMax { min, max, flex } => 216 | WidgetSizeRequirement::MinMax { min: min.saturating_add(rhs), max: max.saturating_add(rhs), flex }, 217 | WidgetSizeRequirement::None => match NonZeroU32::new(rhs) { 218 | Some(min) => WidgetSizeRequirement::Fixed { size: min }, 219 | None => WidgetSizeRequirement::None, 220 | }, 221 | } 222 | } 223 | } 224 | 225 | impl core::ops::Mul for WidgetSizeRequirement { 226 | type Output = Self; 227 | fn mul(self, rhs: u32) -> Self::Output { 228 | match (NonZeroU32::new(rhs), self) { 229 | (Some(rhs), WidgetSizeRequirement::Fixed { size }) => WidgetSizeRequirement::Fixed { size: size.saturating_mul(rhs) }, 230 | (Some(rhs), WidgetSizeRequirement::Flex { flex }) => WidgetSizeRequirement::Flex { flex: flex.saturating_mul(rhs) }, 231 | (Some(rhs), WidgetSizeRequirement::Max { max, flex }) => WidgetSizeRequirement::Max { max: max.saturating_mul(rhs), flex: flex.saturating_mul(rhs) }, 232 | (Some(rhs), WidgetSizeRequirement::Min { min, flex }) => WidgetSizeRequirement::Min { min: min.saturating_mul(rhs), flex: flex.saturating_mul(rhs) }, 233 | (Some(rhs), WidgetSizeRequirement::MinMax { min, max, flex }) => WidgetSizeRequirement::MinMax { min: min.saturating_mul(rhs), max: max.saturating_mul(rhs), flex: flex.saturating_mul(rhs) }, 234 | (None, _) | (Some(_), WidgetSizeRequirement::None) => WidgetSizeRequirement::None, 235 | } 236 | } 237 | } 238 | 239 | impl WidgetSizeRequirement { 240 | /// Distribute a given available_space between multiple requirements. 241 | /// The algorithm will do it's best to respect all provided requirements, but it is sometimes impossible. 242 | /// todo: rework this whole thing, as it is super primitive for now. 243 | /// I'm convinced there is a nice mathy elegant way to do it, and I've started searching it. 244 | pub fn distribute_available_size(requirements: [WidgetSizeRequirement; N], available_space: NonZeroU32) -> [u32; N] { 245 | 246 | let mut results = [0; N]; 247 | 248 | // Step 1: get the number of min space required and flex components 249 | 250 | let (min_requirements, total_flex): (u32, u32) = requirements.iter().map(|req| match req { 251 | WidgetSizeRequirement::Fixed { size } => (size.get(), 0), 252 | WidgetSizeRequirement::Flex { flex } => (0, flex.get()), 253 | WidgetSizeRequirement::Max { flex, .. } => (0, flex.get(), ), 254 | WidgetSizeRequirement::Min { min, flex } => (min.get(), flex.get()), 255 | WidgetSizeRequirement::MinMax { min, flex, .. } => (min.get(), flex.get(), ), 256 | WidgetSizeRequirement::None => (0, 0), 257 | }).fold((0, 0), |(a1, b1), (a2, b2)| (a1 + a2, b1 + b2)); 258 | 259 | if min_requirements > available_space.get() { 260 | panic!("TODO: handle case where not enough space for min requirements! ({min_requirements} required, got {available_space})"); 261 | } 262 | 263 | // Step 2: distribute min requirements 264 | 265 | for (result, requirement) in results.iter_mut().zip(requirements.iter()) { 266 | match requirement { 267 | WidgetSizeRequirement::Fixed { size: min } | 268 | WidgetSizeRequirement::Min { min, .. } | 269 | WidgetSizeRequirement::MinMax { min, .. } => *result = min.get(), 270 | _ => {}, 271 | } 272 | } 273 | 274 | // Step 3: distribute flex space 275 | 276 | let mut available_flex_space = available_space.get() - min_requirements; 277 | let mut total_flex = total_flex; 278 | let mut progress_have_been_made = true; 279 | 280 | while progress_have_been_made { 281 | 282 | // we keep giving space as long as there is: 283 | // - space to give 284 | // - wigets than can accept more space (flex) 285 | // - changes that have been made last iteration 286 | 287 | progress_have_been_made = false; 288 | if available_flex_space == 0 { break; } 289 | let non_zero_total_flex = match NonZeroU32::new(total_flex) { 290 | None => break, 291 | Some(value) => value, 292 | }; 293 | 294 | 295 | // creates an iterator over the space we computed for each flex unit. 296 | // this iterator will repeat flex_val1 fv1 amount and flex_val2 fv2_amount 297 | // this way, we are sure to distribute all flex space, taking remainder of euclidian div into account. 298 | let mut flex_size_it = full_integer_div(available_flex_space, non_zero_total_flex); 299 | 300 | for (result, requirement) in results.iter_mut().zip(requirements) { 301 | match requirement { 302 | // for widgets with max property : 303 | // distribute flex, maxing to their max. 304 | // if we reach their max, remove their flex as part of the equation. 305 | WidgetSizeRequirement::Max { max, flex } | 306 | WidgetSizeRequirement::MinMax { max, flex, .. } => { 307 | if *result < max.get() { 308 | // get the amount of flex space from the iterator according to our flex value 309 | let consumed = flex_size_it.next_flex(flex); 310 | if consumed >= *result - max.get() { 311 | total_flex -= flex.get(); 312 | available_flex_space -= consumed; 313 | *result = max.get(); 314 | } 315 | else { 316 | available_flex_space -= consumed; 317 | *result += consumed; 318 | } 319 | progress_have_been_made = true; 320 | } 321 | }, 322 | // for purely flex widgets, 323 | WidgetSizeRequirement::Flex { flex } | 324 | WidgetSizeRequirement::Min { flex, .. } => { 325 | let consumed = flex_size_it.next_flex(flex); 326 | available_flex_space -= consumed; 327 | *result += consumed; 328 | progress_have_been_made = true; 329 | }, 330 | _ => {}, 331 | } 332 | } 333 | } 334 | 335 | results 336 | } 337 | } 338 | 339 | 340 | struct DividedAvailableFlexSpace { 341 | part_size: u32, 342 | big_part_count: u32, 343 | small_part_count: u32, 344 | } 345 | 346 | impl DividedAvailableFlexSpace { 347 | fn next_flex(&mut self, flex: NonZeroU32) -> u32 { 348 | let mut flex_to_take = flex.get(); 349 | let taken_from_big = self.big_part_count.min(flex_to_take); 350 | self.big_part_count -= taken_from_big; 351 | flex_to_take -= taken_from_big; 352 | let taken_from_small = self.small_part_count.min(flex_to_take); 353 | self.small_part_count -= taken_from_small; 354 | taken_from_big * (self.part_size + 1) + taken_from_small * self.part_size 355 | } 356 | } 357 | 358 | /// Integer division, splitting the remainer into part of the results. 359 | /// The returned value is in the form ((res1, amount1), (res2, amount2)) 360 | /// where the res1 is the quotient of the div, and 361 | /// - res1 * amount1 + res2 * amount2 = divedend, 362 | /// - res1 + 1 = res2 363 | /// - amount1 + amount 2 = divisor 364 | /// This basically performs an integer division, adding the remainder into part of the results 365 | /// This is usefull when splitting spaces onto widgets. 366 | fn full_integer_div(dividend: u32, divisor: NonZeroU32) -> DividedAvailableFlexSpace { 367 | let quotient = dividend / divisor.get(); 368 | let remainder = dividend % divisor.get(); 369 | DividedAvailableFlexSpace { 370 | part_size: quotient, 371 | big_part_count: remainder, 372 | small_part_count: divisor.get() - remainder, 373 | } 374 | } 375 | 376 | 377 | 378 | -------------------------------------------------------------------------------- /src/lib.rs: -------------------------------------------------------------------------------- 1 | 2 | 3 | pub(crate) mod app; 4 | pub(crate) mod drawing; 5 | pub(crate) mod geometry; 6 | pub(crate) mod widget; 7 | pub(crate) mod utils; 8 | 9 | // default app exports 10 | pub use app::{ 11 | run_app, 12 | event::AppEvent, 13 | app_context::AppContext, 14 | }; 15 | pub use drawing::{ 16 | canvas::Canvas, 17 | color::Color, 18 | }; 19 | pub use geometry::{ 20 | alignment::{ 21 | VerticalAlignment, 22 | HorizontalAlignment, 23 | Alignment, 24 | }, 25 | decoration::BorderType, 26 | rect::Rect, 27 | screen_side::ScreenSide, 28 | size_requirements::WidgetSizeRequirement, 29 | }; 30 | pub use utils::nonable::Nonable; 31 | // re-export winit 32 | pub use winit; 33 | // default widget exports 34 | pub use widget::{ 35 | Widget, 36 | default_widgets::{ 37 | align::Align, 38 | background::Background, 39 | button::Button, 40 | center::Center, 41 | empty::Empty, 42 | padder::{Padder, PaddType}, 43 | sized_box::SizedBox, 44 | scaffold::Scaffold, 45 | }, 46 | }; 47 | // conditional exports 48 | #[cfg(feature = "text")] 49 | pub use widget::text_widgets::{ 50 | text::Text, 51 | text_style::{ 52 | TextStyle, 53 | FontWeight, 54 | FontCharSpacing, 55 | FontStyle, 56 | font_family::FontFamily, 57 | }, 58 | }; 59 | -------------------------------------------------------------------------------- /src/utils.rs: -------------------------------------------------------------------------------- 1 | 2 | 3 | pub(crate) mod type_level_list; 4 | pub(crate) mod nonable; 5 | 6 | -------------------------------------------------------------------------------- /src/utils/nonable.rs: -------------------------------------------------------------------------------- 1 | 2 | 3 | pub trait Nonable { 4 | fn none() -> Self; 5 | fn is_none(&self) -> bool; 6 | } 7 | 8 | impl Nonable for () { 9 | fn none() -> Self { () } 10 | fn is_none(&self) -> bool { true } 11 | } 12 | 13 | impl Nonable for (A, B) { 14 | fn none() -> Self { 15 | (A::none(), B::none()) 16 | } 17 | fn is_none(&self) -> bool { 18 | self.0.is_none() && self.1.is_none() 19 | } 20 | } 21 | 22 | -------------------------------------------------------------------------------- /src/utils/type_level_list.rs: -------------------------------------------------------------------------------- 1 | use crate::Widget; 2 | 3 | 4 | 5 | 6 | pub trait WidgetList { 7 | const SIZE: usize; 8 | } 9 | 10 | pub struct Nil; 11 | 12 | impl WidgetList for Nil { 13 | const SIZE: usize = 0; 14 | } 15 | 16 | pub struct Cons, Rest: WidgetList>(core::marker::PhantomData<(W, Rest, UserEvent)>); 17 | 18 | impl, Rest: WidgetList> WidgetList for Cons { 19 | const SIZE: usize = Rest::SIZE + 1; 20 | } 21 | 22 | #[macro_export] 23 | macro_rules! widget_list { 24 | () => { 25 | Nil 26 | }; 27 | ($widget_type:ty) => { 28 | Cons::<$widget_type, Nil> 29 | }; 30 | ($widget_type:ty, $($rest:tt)*) => { 31 | Cons::<$widget_type, widget_list!($($rest)*)> 32 | }; 33 | } 34 | -------------------------------------------------------------------------------- /src/widget.rs: -------------------------------------------------------------------------------- 1 | use crate::{ 2 | app::event::AppEvent, drawing::canvas::Canvas, geometry::size_requirements::WidgetSizeRequirement, utils::nonable::Nonable, Rect 3 | }; 4 | 5 | 6 | pub(crate) mod default_widgets; 7 | #[cfg(feature = "skia")] 8 | pub(crate) mod skia_widgets; 9 | #[cfg(feature = "text")] 10 | pub(crate) mod text_widgets; 11 | #[cfg(feature = "svg")] 12 | pub(crate) mod svg_widgets; 13 | 14 | 15 | 16 | /// The widget trait. All widgets are stored as Box. 17 | /// This trait can be used to create custom widgets, that can be implemented from scratch or use a combination of existing widgets. 18 | pub trait Widget { 19 | type EventResponse: Nonable; 20 | /// Draw the widget on the canvas. The given rect is the area the widget should draw in, computed by its parent 21 | /// with it's size requirements. 22 | fn draw(&self, canvas: &mut Canvas, rect: Rect); 23 | /// Get the size requirements of this widget. 24 | /// If the widgets requests sized outside of the constraints, they will be given smaller sizes to be drawn in. 25 | fn min_space_requirements(&self) -> (WidgetSizeRequirement, WidgetSizeRequirement); 26 | /// Handles an event. Returns true if the event was handled, false otherwise. 27 | /// This will be called on the root, and need to be propagated down the Widget for each custom widget implementation, 28 | /// 29 | /// It is needed to recompute the widgets rect while doing so: events are called one after another, and there is no guarantee 30 | /// that draw will be called between each event. As events can change widget layouts, it is needed to recompute the rect 31 | /// to ensure that the next event is handled correctly. 32 | fn handle_event(&mut self, event: &AppEvent, rect: Rect) -> Self::EventResponse; 33 | } -------------------------------------------------------------------------------- /src/widget/default_widgets/align.rs: -------------------------------------------------------------------------------- 1 | use std::num::NonZeroU32; 2 | 3 | use crate::{ 4 | app::event::AppEvent, geometry::{ 5 | alignment::Alignment, 6 | size_requirements::WidgetSizeRequirement 7 | }, Rect, Widget 8 | }; 9 | 10 | 11 | 12 | /// The Align widget will take the same space as it's child. 13 | /// However, if we provide it with more space, it will align the child in the extra space, 14 | /// according the the alignment parameter. 15 | pub struct Align> { 16 | _m: core::marker::PhantomData, 17 | child: Child, 18 | alignment: Alignment, 19 | } 20 | 21 | impl> Align { 22 | pub fn new(alignment: Alignment, child: Child) -> Self { 23 | Align { 24 | _m: core::marker::PhantomData, 25 | child, 26 | alignment, 27 | } 28 | } 29 | 30 | fn get_child_and_remaining_size(child_requirement: WidgetSizeRequirement, available_size: NonZeroU32) -> (NonZeroU32, u32) { 31 | match child_requirement { 32 | // child can have any size, so we give it all the available space. 33 | WidgetSizeRequirement::None | 34 | WidgetSizeRequirement::Flex { .. } | 35 | WidgetSizeRequirement::Min { .. } => (available_size, 0), 36 | // child does not want to be bigger than a given size, 37 | // so we give it the minimum between the available space and the size it wants. 38 | WidgetSizeRequirement::Fixed { size: max, .. } | 39 | WidgetSizeRequirement::Max { max, .. } | 40 | WidgetSizeRequirement::MinMax { max, .. } => ( 41 | max.min(available_size), 42 | available_size.get().checked_sub(max.get()).unwrap_or(0) 43 | ), 44 | } 45 | } 46 | 47 | fn compute_child_rect(&self, from_rect: softbuffer::Rect) -> softbuffer::Rect { 48 | let (width_req, height_req) = self.child.min_space_requirements(); 49 | let (child_width, remaining_width) = Self::get_child_and_remaining_size(width_req, from_rect.width); 50 | let (child_height, remaining_height) = Self::get_child_and_remaining_size(height_req, from_rect.height); 51 | softbuffer::Rect { 52 | x: from_rect.x + self.alignment.get_left_space(remaining_width), 53 | y: from_rect.y + self.alignment.get_top_space(remaining_height), 54 | width: child_width, 55 | height: child_height, 56 | } 57 | } 58 | } 59 | 60 | impl> Widget for Align { 61 | type EventResponse = Child::EventResponse; 62 | fn draw(&self, canvas: &mut crate::drawing::canvas::Canvas, rect: Rect) { 63 | let child_rect = self.compute_child_rect(rect); 64 | self.child.draw(canvas, child_rect); 65 | } 66 | 67 | fn min_space_requirements(&self) -> (crate::geometry::size_requirements::WidgetSizeRequirement, crate::geometry::size_requirements::WidgetSizeRequirement) { 68 | self.child.min_space_requirements() 69 | } 70 | 71 | fn handle_event(&mut self, event: &AppEvent, rect: Rect) -> Self::EventResponse { 72 | let child_rect = self.compute_child_rect(rect); 73 | self.child.handle_event(event, child_rect) 74 | } 75 | } 76 | 77 | 78 | -------------------------------------------------------------------------------- /src/widget/default_widgets/background.rs: -------------------------------------------------------------------------------- 1 | use crate::{ 2 | app::event::AppEvent, drawing::{canvas::Canvas, color::Color}, geometry::size_requirements::WidgetSizeRequirement, Rect, Widget 3 | }; 4 | 5 | 6 | /// The background widget will draw a colored background behind its child. 7 | /// This is a drawing widget that is in the default widgets, because filling a rect have a non-skia backup. 8 | pub struct Background> { 9 | _m: core::marker::PhantomData, 10 | child: Child, 11 | color: Color, 12 | } 13 | 14 | impl> Background { 15 | pub fn new(color: Color, child: Child) -> Self { 16 | Background { 17 | _m: core::marker::PhantomData, 18 | child, 19 | color, 20 | } 21 | } 22 | 23 | pub fn set_color(&mut self, color: Color) { 24 | self.color = color; 25 | } 26 | } 27 | 28 | impl> Widget for Background { 29 | type EventResponse = Child::EventResponse; 30 | 31 | fn draw(&self, canvas: &mut Canvas, rect: Rect) { 32 | canvas.fill_rect(rect, self.color); 33 | self.child.draw(canvas, rect); 34 | } 35 | 36 | fn min_space_requirements(&self) -> (WidgetSizeRequirement, WidgetSizeRequirement) { 37 | self.child.min_space_requirements() 38 | } 39 | 40 | fn handle_event(&mut self, event: &AppEvent, rect: Rect) -> Self::EventResponse { 41 | self.child.handle_event(event, rect) 42 | } 43 | } -------------------------------------------------------------------------------- /src/widget/default_widgets/button.rs: -------------------------------------------------------------------------------- 1 | 2 | use crate::{ 3 | app::event::AppEvent, utils::nonable::Nonable, Rect, Widget 4 | }; 5 | 6 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] 7 | pub enum ButtonState { 8 | Idle, 9 | Hovered, 10 | Pressed, 11 | PressedLeft, 12 | } 13 | 14 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] 15 | pub enum ButtonResponse { 16 | None, 17 | Changed { 18 | prev: ButtonState, 19 | new: ButtonState, 20 | }, 21 | /// Special value for Changed where prev is pressed, new is hovered 22 | Clicked, 23 | } 24 | 25 | impl Nonable for ButtonResponse { 26 | fn none() -> Self { ButtonResponse::None } 27 | fn is_none(&self) -> bool { 28 | match self { 29 | ButtonResponse::None => true, 30 | _ => false, 31 | } 32 | } 33 | } 34 | 35 | pub struct Button> { 36 | _m: core::marker::PhantomData, 37 | child: Child, 38 | state: ButtonState, 39 | } 40 | 41 | 42 | impl> Button { 43 | pub fn new(child: Child) -> Self { 44 | Button { 45 | _m: core::marker::PhantomData, 46 | child, 47 | state: ButtonState::Idle, 48 | } 49 | } 50 | } 51 | 52 | impl> Widget for Button { 53 | type EventResponse = (ButtonResponse, Child::EventResponse); 54 | fn draw(&self, canvas: &mut crate::drawing::canvas::Canvas, rect: Rect) { 55 | self.child.draw(canvas, rect); 56 | } 57 | 58 | fn min_space_requirements(&self) -> (crate::geometry::size_requirements::WidgetSizeRequirement, crate::geometry::size_requirements::WidgetSizeRequirement) { 59 | self.child.min_space_requirements() 60 | } 61 | 62 | fn handle_event(&mut self, event: &AppEvent, rect: Rect) -> Self::EventResponse { 63 | let child_response = self.child.handle_event(event, rect); 64 | let own_response = match (event, self.state) { 65 | (AppEvent::CursorMoved { position }, ButtonState::Idle) => if position.is_in_rect(rect) { 66 | self.state = ButtonState::Hovered; 67 | ButtonResponse::Changed { prev: ButtonState::Idle, new: ButtonState::Hovered } 68 | } else { 69 | ButtonResponse::None 70 | }, 71 | (AppEvent::CursorMoved { position }, ButtonState::Hovered) => if position.is_in_rect(rect) { 72 | ButtonResponse::None 73 | } else { 74 | self.state = ButtonState::Idle; 75 | ButtonResponse::Changed { prev: ButtonState::Hovered, new: ButtonState::Idle } 76 | }, 77 | (AppEvent::CursorMoved { position }, ButtonState::Pressed) => if position.is_in_rect(rect) { 78 | ButtonResponse::None 79 | } else { 80 | self.state = ButtonState::PressedLeft; 81 | ButtonResponse::Changed { prev: ButtonState::Pressed, new: ButtonState::PressedLeft } 82 | }, 83 | (AppEvent::CursorMoved { position }, ButtonState::PressedLeft) => if position.is_in_rect(rect) { 84 | self.state = ButtonState::Pressed; 85 | ButtonResponse::Changed { prev: ButtonState::PressedLeft, new: ButtonState::Pressed } 86 | } else { 87 | ButtonResponse::None 88 | }, 89 | (AppEvent::MouseInput { state: winit::event::ElementState::Pressed, button: winit::event::MouseButton::Left }, ButtonState::Hovered) => { 90 | self.state = ButtonState::Pressed; 91 | ButtonResponse::Changed { prev: ButtonState::Hovered, new: ButtonState::Pressed } 92 | }, 93 | (AppEvent::MouseInput { state: winit::event::ElementState::Released, button: winit::event::MouseButton::Left }, ButtonState::Pressed) => { 94 | self.state = ButtonState::Hovered; 95 | ButtonResponse::Clicked 96 | }, 97 | (AppEvent::MouseInput { state: winit::event::ElementState::Released, button: winit::event::MouseButton::Left }, ButtonState::PressedLeft) => { 98 | self.state = ButtonState::Idle; 99 | ButtonResponse::Changed { prev: ButtonState::PressedLeft, new: ButtonState::Idle } 100 | }, 101 | _ => ButtonResponse::None 102 | }; 103 | 104 | (own_response, child_response) 105 | } 106 | } 107 | -------------------------------------------------------------------------------- /src/widget/default_widgets/center.rs: -------------------------------------------------------------------------------- 1 | use std::num::NonZeroU32; 2 | 3 | use crate::{ 4 | app::event::AppEvent, 5 | drawing::canvas::Canvas, 6 | geometry::size_requirements::WidgetSizeRequirement, 7 | Rect, 8 | Widget 9 | }; 10 | 11 | /// Centers it's children in the available space. 12 | /// If the children takes all available space, this widget is useless and will give all space to children. 13 | /// This widget is a shortcut for Align(Alignment::Center, child). 14 | pub struct Center> { 15 | _m: core::marker::PhantomData, 16 | child: Child, 17 | } 18 | 19 | impl> Center { 20 | pub fn new(child: Child) -> Self { 21 | Center { 22 | _m: core::marker::PhantomData, 23 | child, 24 | } 25 | } 26 | 27 | fn get_child_size_and_spacing(child_requirement: WidgetSizeRequirement, available_size: NonZeroU32) -> (NonZeroU32, u32) { 28 | match child_requirement { 29 | // child can have any size, so we give it all the available space. 30 | WidgetSizeRequirement::None | 31 | WidgetSizeRequirement::Flex { .. } | 32 | WidgetSizeRequirement::Min { .. } => (available_size, 0), 33 | // child does not want to be bigger than a given size, 34 | // so we give it the minimum between the available space and the size it wants. 35 | WidgetSizeRequirement::Fixed { size: max, .. } | 36 | WidgetSizeRequirement::Max { max, .. } | 37 | WidgetSizeRequirement::MinMax { max, .. } => ( 38 | max.min(available_size), 39 | available_size.get().checked_sub(max.get()).unwrap_or(0) / 2 40 | ), 41 | } 42 | } 43 | 44 | fn compute_child_rect(&self, from_rect: softbuffer::Rect) -> softbuffer::Rect { 45 | let ( 46 | width_requirement, 47 | height_requirement 48 | ) = self.child.min_space_requirements(); 49 | let (width, width_spacing) = Self::get_child_size_and_spacing(width_requirement, from_rect.width); 50 | let (height, height_spacing) = Self::get_child_size_and_spacing(height_requirement, from_rect.height); 51 | softbuffer::Rect { 52 | x: from_rect.x + width_spacing, 53 | y: from_rect.y + height_spacing, 54 | width, 55 | height, 56 | } 57 | } 58 | } 59 | 60 | impl> Widget for Center { 61 | type EventResponse = Child::EventResponse; 62 | fn draw(&self, buffer: &mut Canvas, rect: Rect) { 63 | let rect = self.compute_child_rect(rect); 64 | self.child.draw(buffer, rect); 65 | } 66 | 67 | fn min_space_requirements(&self) -> (WidgetSizeRequirement, WidgetSizeRequirement) { 68 | self.child.min_space_requirements() 69 | } 70 | 71 | fn handle_event(&mut self, event: &AppEvent, rect: Rect) -> Self::EventResponse { 72 | self.child.handle_event(event, self.compute_child_rect(rect)) 73 | } 74 | } -------------------------------------------------------------------------------- /src/widget/default_widgets/empty.rs: -------------------------------------------------------------------------------- 1 | use std::num::NonZeroU32; 2 | 3 | use crate::{ 4 | app::event::AppEvent, drawing::canvas::Canvas, geometry::size_requirements::WidgetSizeRequirement, Rect, Widget 5 | }; 6 | 7 | pub enum EmptyBehavior { 8 | /// The empty widget will take all the available space. 9 | Expand, 10 | /// The empty widget will take no space. 11 | Shrink, 12 | } 13 | 14 | /// This is an empty widget, used as a node in widget trees. 15 | pub struct Empty { 16 | behavior: EmptyBehavior, 17 | } 18 | 19 | impl Empty { 20 | pub fn shrink() -> Empty { 21 | Empty { 22 | behavior: EmptyBehavior::Shrink, 23 | } 24 | } 25 | 26 | pub fn expand() -> Empty { 27 | Empty { 28 | behavior: EmptyBehavior::Expand, 29 | } 30 | } 31 | } 32 | 33 | impl Widget for Empty { 34 | type EventResponse = (); 35 | 36 | fn draw(&self, _buffer: &mut Canvas, _rect: Rect) {} 37 | 38 | fn min_space_requirements(&self) -> (WidgetSizeRequirement, WidgetSizeRequirement) { 39 | match self.behavior { 40 | EmptyBehavior::Shrink => (WidgetSizeRequirement::None, WidgetSizeRequirement::None), 41 | EmptyBehavior::Expand => ( 42 | WidgetSizeRequirement::Flex { flex: unsafe { NonZeroU32::new_unchecked(1) } }, 43 | WidgetSizeRequirement::Flex { flex: unsafe { NonZeroU32::new_unchecked(1) } }, 44 | ), 45 | } 46 | } 47 | 48 | fn handle_event(&mut self, _: &AppEvent, _: Rect) -> Self::EventResponse { } 49 | } -------------------------------------------------------------------------------- /src/widget/default_widgets/expanded.rs: -------------------------------------------------------------------------------- 1 | use std::num::NonZeroU32; 2 | 3 | use crate::{ 4 | app::event::AppEvent, geometry::size_requirements::WidgetSizeRequirement, Rect, Widget 5 | }; 6 | 7 | 8 | 9 | 10 | 11 | pub struct Expanded> { 12 | _m: core::marker::PhantomData, 13 | flex: NonZeroU32, 14 | child: Child, 15 | } 16 | 17 | 18 | impl> Widget for Expanded { 19 | type EventResponse = Child::EventResponse; 20 | fn draw(&self, canvas: &mut crate::drawing::canvas::Canvas, rect: Rect) { 21 | self.child.draw(canvas, rect); 22 | } 23 | 24 | fn min_space_requirements(&self) -> (WidgetSizeRequirement, WidgetSizeRequirement) { 25 | ( 26 | WidgetSizeRequirement::Flex { flex: self.flex }, 27 | WidgetSizeRequirement::Flex { flex: self.flex }, 28 | ) 29 | } 30 | 31 | fn handle_event(&mut self, event: &AppEvent, rect: Rect) -> Self::EventResponse { 32 | self.child.handle_event(event, rect) 33 | } 34 | } 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /src/widget/default_widgets/mod.rs: -------------------------------------------------------------------------------- 1 | 2 | 3 | pub(crate) mod align; 4 | pub(crate) mod background; 5 | pub(crate) mod button; 6 | pub(crate) mod center; 7 | pub(crate) mod empty; 8 | pub(crate) mod expanded; 9 | pub(crate) mod padder; 10 | pub(crate) mod scaffold; 11 | pub(crate) mod sized_box; 12 | -------------------------------------------------------------------------------- /src/widget/default_widgets/padder.rs: -------------------------------------------------------------------------------- 1 | use std::num::NonZeroU32; 2 | 3 | use crate::{ 4 | app::event::AppEvent, geometry::size_requirements::WidgetSizeRequirement, Canvas, Rect, Widget, 5 | }; 6 | use crate::utils::nonable::Nonable; 7 | 8 | #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Debug)] 9 | pub struct PaddType(u8); 10 | 11 | impl PaddType { 12 | pub const TOP: PaddType = PaddType(0b0000_0001); 13 | pub const BOTTOM: PaddType = PaddType(0b0000_0010); 14 | pub const LEFT: PaddType = PaddType(0b0000_0100); 15 | pub const RIGHT: PaddType = PaddType(0b0000_1000); 16 | pub const VERTICAL: PaddType = PaddType(0b0000_0011); 17 | pub const HORIZONTAL: PaddType = PaddType(0b0000_1100); 18 | pub const ALL: PaddType = PaddType(0b0000_1111); 19 | pub const NONE: PaddType = PaddType(0b0000_0000); 20 | } 21 | 22 | impl std::ops::BitAnd for PaddType { 23 | type Output = Self; 24 | 25 | fn bitand(self, rhs: Self) -> Self::Output { 26 | PaddType(self.0 & rhs.0) 27 | } 28 | } 29 | 30 | impl std::ops::BitOr for PaddType { 31 | type Output = Self; 32 | 33 | fn bitor(self, rhs: Self) -> Self::Output { 34 | PaddType(self.0 | rhs.0) 35 | } 36 | } 37 | 38 | impl std::ops::Not for PaddType { 39 | type Output = Self; 40 | fn not(self) -> Self::Output { 41 | PaddType(!self.0) 42 | } 43 | } 44 | 45 | impl From for u32 { 46 | fn from(padd_type: PaddType) -> Self { 47 | u32::from(padd_type.0) 48 | } 49 | } 50 | 51 | /// The Padder widget will draw its child with a padding around it. 52 | /// The padding can be specified for each side of the child. The padding value is the same for all sides. 53 | /// If you want different padding values for each side, you can nest multiple Padder widgets. 54 | struct Padding { 55 | pub padd_type: PaddType, 56 | pub padd_amount: u32, 57 | } 58 | 59 | impl Padding { 60 | pub fn top(&self) -> u32 { 61 | (u32::from(self.padd_type & PaddType::TOP) >> 0) * self.padd_amount 62 | } 63 | 64 | pub fn bottom(&self) -> u32 { 65 | (u32::from(self.padd_type & PaddType::BOTTOM) >> 1) * self.padd_amount 66 | } 67 | 68 | pub fn left(&self) -> u32 { 69 | (u32::from(self.padd_type & PaddType::LEFT) >> 2) * self.padd_amount 70 | } 71 | 72 | pub fn right(&self) -> u32 { 73 | (u32::from(self.padd_type & PaddType::RIGHT) >> 3) * self.padd_amount 74 | } 75 | 76 | pub fn vertical(&self) -> u32 { 77 | self.top() + self.bottom() 78 | } 79 | 80 | pub fn horizontal(&self) -> u32 { 81 | self.left() + self.right() 82 | } 83 | } 84 | 85 | pub struct Padder> { 86 | _m: core::marker::PhantomData, 87 | child: Child, 88 | padding: Padding, 89 | } 90 | 91 | // todo : this whole section is terrible and needs rewrite 92 | impl> Padder { 93 | pub fn new(padd_type: PaddType, padd_amount: u32, child: Child) -> Self { 94 | Padder { 95 | _m: core::marker::PhantomData, 96 | child, 97 | padding: Padding { padd_type, padd_amount }, 98 | } 99 | } 100 | 101 | fn get_child_remaining_width(&self, available_space: NonZeroU32) -> u32 { 102 | available_space.get().checked_sub(self.padding.horizontal()).unwrap_or(0) 103 | } 104 | 105 | fn get_child_remaining_height(&self, available_space: NonZeroU32) -> u32 { 106 | available_space.get().max(self.padding.vertical()) - self.padding.vertical() 107 | } 108 | 109 | fn get_left_pad(&self, available_space: NonZeroU32, child_space: NonZeroU32) -> u32 { 110 | if self.padding.left() == 0 { 111 | return 0; 112 | } 113 | else { 114 | let padd_space = available_space.get() - child_space.get(); 115 | if self.padding.right() == 0 { 116 | padd_space 117 | } 118 | else { 119 | padd_space / 2 120 | } 121 | } 122 | } 123 | 124 | fn get_top_pad(&self, available_space: NonZeroU32, child_space: NonZeroU32) -> u32 { 125 | if self.padding.top() == 0 { 126 | return 0; 127 | } 128 | else { 129 | let padd_space = available_space.get() - child_space.get(); 130 | if self.padding.bottom() == 0 { 131 | padd_space 132 | } 133 | else { 134 | padd_space / 2 135 | } 136 | } 137 | } 138 | 139 | fn compute_child_rect(&self, from_rect: softbuffer::Rect) -> Option { 140 | let child_width = NonZeroU32::new(self.get_child_remaining_width(from_rect.width))?; 141 | let child_height = NonZeroU32::new(self.get_child_remaining_height(from_rect.height))?; 142 | let left_pad = self.get_left_pad(from_rect.width, child_width); 143 | let top_pad = self.get_top_pad(from_rect.height, child_height); 144 | Some(softbuffer::Rect { 145 | x: from_rect.x + left_pad, 146 | y: from_rect.y + top_pad, 147 | width: child_width, 148 | height: child_height, 149 | }) 150 | } 151 | } 152 | 153 | impl> Widget for Padder { 154 | type EventResponse = Child::EventResponse; 155 | fn draw(&self, buffer: &mut Canvas, rect: Rect) { 156 | match self.compute_child_rect(rect) { 157 | Some(rect) => self.child.draw(buffer, rect), 158 | None => {}, // no space left for child, don't draw at all 159 | }; 160 | } 161 | 162 | fn min_space_requirements(&self) -> (WidgetSizeRequirement, WidgetSizeRequirement) { 163 | let (child_width_requirement, child_height_requirement) = self.child.min_space_requirements(); 164 | ( 165 | child_width_requirement + self.padding.horizontal(), 166 | child_height_requirement + self.padding.vertical(), 167 | ) 168 | } 169 | 170 | fn handle_event(&mut self, event: &AppEvent, rect: Rect) -> Self::EventResponse { 171 | match self.compute_child_rect(rect) { 172 | Some(rect) => self.child.handle_event(event, rect), 173 | None => Self::EventResponse::none(), 174 | } 175 | } 176 | } -------------------------------------------------------------------------------- /src/widget/default_widgets/scaffold.rs: -------------------------------------------------------------------------------- 1 | use std::num::NonZeroU32; 2 | 3 | use crate::{ 4 | app::event::AppEvent, geometry::{ 5 | screen_side::ScreenSide, size_requirements::WidgetSizeRequirement 6 | }, Rect, Widget 7 | }; 8 | use crate::utils::nonable::Nonable; 9 | 10 | /// The Scaffold is a widget with an app bar and a child. 11 | /// The app bar can be on the top, bottom, left or right of the child. 12 | /// There are no assumptions about the app bar size, and if both appbar and child widget have flex requirements, 13 | /// they will be given equal amounts of space. If you want to fix the size of the appbar, you can wrap it in a SizedBox. 14 | pub struct Scaffold, Child: Widget> { 15 | _m: core::marker::PhantomData, 16 | appbar_side: ScreenSide, 17 | appbar: AppBar, 18 | child: Child, 19 | } 20 | 21 | impl, Child: Widget> Scaffold { 22 | pub fn new(appbar_side: ScreenSide, appbar: AppBar, child: Child) -> Self { 23 | Scaffold { 24 | _m: core::marker::PhantomData, 25 | appbar_side, 26 | appbar, 27 | child, 28 | } 29 | } 30 | 31 | /// returns the width and offset of the appbar, and the width and offset of the child. 32 | fn get_childs_width_and_offset(&self, available_space: NonZeroU32) -> ((u32, u32), (u32, u32)) { 33 | match self.appbar_side { 34 | ScreenSide::Top | ScreenSide::Bottom => ((available_space.get(), 0), (available_space.get(), 0)), 35 | ScreenSide::Left => { 36 | let [appbar_width, child_width] = WidgetSizeRequirement::distribute_available_size( 37 | [ 38 | self.appbar.min_space_requirements().0, 39 | self.child.min_space_requirements().0, 40 | ], 41 | available_space 42 | ); 43 | ((appbar_width, 0), (child_width, appbar_width)) 44 | }, 45 | ScreenSide::Right => { 46 | let [child_width, appbar_width] = WidgetSizeRequirement::distribute_available_size( 47 | [ 48 | self.child.min_space_requirements().0, 49 | self.appbar.min_space_requirements().0, 50 | ], 51 | available_space 52 | ); 53 | ((appbar_width, child_width), (child_width, 0)) 54 | }, 55 | } 56 | } 57 | 58 | /// returns the height and offset of the appbar, and the height and offset of the child. 59 | fn get_childs_height_and_offset(&self, available_space: NonZeroU32) -> ((u32, u32), (u32, u32)) { 60 | match self.appbar_side { 61 | ScreenSide::Left | ScreenSide::Right => ((available_space.get(), 0), (available_space.get(), 0)), 62 | ScreenSide::Top => { 63 | let [appbar_height, child_height] = WidgetSizeRequirement::distribute_available_size( 64 | [ 65 | self.appbar.min_space_requirements().1, 66 | self.child.min_space_requirements().1, 67 | ], 68 | available_space 69 | ); 70 | ((appbar_height, 0), (child_height, appbar_height)) 71 | }, 72 | ScreenSide::Bottom => { 73 | let [child_height, appbar_height] = WidgetSizeRequirement::distribute_available_size( 74 | [ 75 | self.child.min_space_requirements().1, 76 | self.appbar.min_space_requirements().1, 77 | ], 78 | available_space 79 | ); 80 | ((appbar_height, child_height), (child_height, 0)) 81 | }, 82 | } 83 | } 84 | 85 | 86 | 87 | } 88 | 89 | impl, Child: Widget> Widget for Scaffold { 90 | type EventResponse = (AppBar::EventResponse, Child::EventResponse); 91 | fn draw(&self, canvas: &mut crate::drawing::canvas::Canvas, rect: Rect) { 92 | let ((appbar_width, appbar_x_offset), (child_width, child_x_offset)) = self.get_childs_width_and_offset(rect.width); 93 | let ((appbar_height, appbar_y_offset), (child_height, child_y_offset)) = self.get_childs_height_and_offset(rect.height); 94 | match (NonZeroU32::new(appbar_width), NonZeroU32::new(appbar_height)) { 95 | (Some(width), Some(height)) => self.appbar.draw(canvas, softbuffer::Rect { 96 | x: rect.x + appbar_x_offset, 97 | y: rect.y + appbar_y_offset, 98 | width, 99 | height, 100 | }), 101 | _ => { 102 | #[cfg(debug_assertions)] 103 | println!("Unable to draw scaffold appbar: no space!") 104 | }, 105 | }; 106 | match (NonZeroU32::new(child_width), NonZeroU32::new(child_height)) { 107 | (Some(width), Some(height)) => self.child.draw(canvas, softbuffer::Rect { 108 | x: rect.x + child_x_offset, 109 | y: rect.y + child_y_offset, 110 | width, 111 | height, 112 | }), 113 | _ => { 114 | #[cfg(debug_assertions)] 115 | println!("Unable to draw scaffold child: no space!") 116 | }, 117 | }; 118 | } 119 | 120 | fn min_space_requirements(&self) -> (WidgetSizeRequirement, WidgetSizeRequirement) { 121 | let (appbar_width_req, appbar_height_req) = self.appbar.min_space_requirements(); 122 | let (child_width_req, child_height_req) = self.child.min_space_requirements(); 123 | match self.appbar_side { 124 | ScreenSide::Top | ScreenSide::Bottom => { 125 | ( 126 | appbar_width_req | child_width_req, 127 | appbar_height_req & child_height_req, 128 | ) 129 | }, 130 | ScreenSide::Left | ScreenSide::Right => { 131 | ( 132 | appbar_width_req & child_width_req, 133 | appbar_height_req | child_height_req, 134 | ) 135 | }, 136 | } 137 | } 138 | 139 | fn handle_event(&mut self, event: &AppEvent, rect: Rect) -> Self::EventResponse { 140 | // we can't or the function calls, as lazy eval may skip a event propagation. 141 | let ((appbar_width, appbar_x_offset), (child_width, child_x_offset)) = self.get_childs_width_and_offset(rect.width); 142 | let ((appbar_height, appbar_y_offset), (child_height, child_y_offset)) = self.get_childs_height_and_offset(rect.height); 143 | let app_bar_reponse = match (NonZeroU32::new(appbar_width), NonZeroU32::new(appbar_height)) { 144 | (Some(width), Some(height)) => self.appbar.handle_event(event, softbuffer::Rect { 145 | x: rect.x + appbar_x_offset, 146 | y: rect.y + appbar_y_offset, 147 | width, 148 | height, 149 | }), 150 | _ => AppBar::EventResponse::none(), // either width or height is 0, so we don't draw the appbar 151 | }; 152 | let child_response = match (NonZeroU32::new(child_width), NonZeroU32::new(child_height)) { 153 | (Some(width), Some(height)) => self.child.handle_event(event, softbuffer::Rect { 154 | x: rect.x + child_x_offset, 155 | y: rect.y + child_y_offset, 156 | width, 157 | height, 158 | }), 159 | _ => Child::EventResponse::none(), // either width or height is 0, so we don't draw the child 160 | }; 161 | (app_bar_reponse, child_response) 162 | } 163 | } 164 | -------------------------------------------------------------------------------- /src/widget/default_widgets/sized_box.rs: -------------------------------------------------------------------------------- 1 | use std::num::NonZeroU32; 2 | 3 | use crate::{ 4 | app::event::AppEvent, drawing::canvas::Canvas, geometry::size_requirements::WidgetSizeRequirement, Rect, Widget 5 | }; 6 | 7 | enum SizedBoxConstraints { 8 | Width(NonZeroU32), 9 | Height(NonZeroU32), 10 | Both(NonZeroU32, NonZeroU32), 11 | } 12 | 13 | /// The Sized box provide fixed size constraints to it's child. 14 | /// It can have vertical, horizontal or both constraints. 15 | /// It is NOT guaranteed that the child will have the provided size, if the parent does not have enough space. 16 | /// However, best efforts will be made to respect the constraints. 17 | pub struct SizedBox> { 18 | _m: core::marker::PhantomData, 19 | constraints: SizedBoxConstraints, 20 | child: Child, 21 | } 22 | 23 | impl> SizedBox { 24 | pub fn new(width: u32, height: u32, child: Child) -> Self { 25 | let width = NonZeroU32::new(width).expect("Width of a sized box must be non-zero"); 26 | let height = NonZeroU32::new(height).expect("Height of a sized box must be non-zero"); 27 | SizedBox { 28 | _m: core::marker::PhantomData, 29 | constraints: SizedBoxConstraints::Both(width, height), 30 | child, 31 | } 32 | } 33 | 34 | pub fn width(width: u32, child: Child) -> Self { 35 | let width = NonZeroU32::new(width).expect("Width of a sized box must be non-zero"); 36 | SizedBox { 37 | _m: core::marker::PhantomData, 38 | constraints: SizedBoxConstraints::Width(width), 39 | child, 40 | } 41 | } 42 | 43 | pub fn height(height: u32, child: Child) -> Self { 44 | let height = NonZeroU32::new(height).expect("Height of a sized box must be non-zero"); 45 | SizedBox { 46 | _m: core::marker::PhantomData, 47 | constraints: SizedBoxConstraints::Height(height), 48 | child, 49 | } 50 | } 51 | 52 | fn get_width(&self, available_space: NonZeroU32) -> NonZeroU32 { 53 | #[cfg(debug_assertions)] 54 | // in debug mode, don't use the min that are far more optimized (no branching) but allow overflow debug 55 | match &self.constraints { 56 | SizedBoxConstraints::Width(width) => if *width > available_space { 57 | println!("Overflow : SizedBox does not have enough horizontal space ({}) to meet its size constraints ({}).", available_space, width); 58 | available_space 59 | } else { *width }, 60 | SizedBoxConstraints::Height(_) => available_space, 61 | SizedBoxConstraints::Both(width, _) => if *width > available_space { 62 | println!("Overflow : SizedBox does not have enough horizontal space ({}) to meet its size constraints ({}).", available_space, width); 63 | available_space 64 | } else { *width }, 65 | } 66 | #[cfg(not(debug_assertions))] 67 | match &self.constraints { 68 | SizedBoxConstraints::Width(width) => available_space.min(*width), 69 | SizedBoxConstraints::Height(_) => available_space, 70 | SizedBoxConstraints::Both(width, _) => available_space.min(*width), 71 | } 72 | } 73 | 74 | fn get_height(&self, available_space: NonZeroU32) -> NonZeroU32 { 75 | #[cfg(debug_assertions)] 76 | // in debug mode, don't use the min that are far more optimized (no branching) but allow overflow debug 77 | match &self.constraints { 78 | SizedBoxConstraints::Width(_) => available_space, 79 | SizedBoxConstraints::Height(height) => if *height > available_space { 80 | println!("Overflow : SizedBox does not have enough vertical space ({}) to meet its size constraints ({}).", available_space, height); 81 | available_space 82 | } else { *height }, 83 | SizedBoxConstraints::Both(_, height) => if *height > available_space { 84 | println!("Overflow : SizedBox does not have enough vertical space ({}) to meet its size constraints ({}).", available_space, height); 85 | available_space 86 | } else { *height }, 87 | } 88 | #[cfg(not(debug_assertions))] 89 | match &self.constraints { 90 | SizedBoxConstraints::Width(_) => available_space, 91 | SizedBoxConstraints::Height(height) => available_space.min(*height), 92 | SizedBoxConstraints::Both(_, height) => available_space.min(*height), 93 | } 94 | } 95 | } 96 | 97 | impl> Widget for SizedBox { 98 | type EventResponse = Child::EventResponse; 99 | fn draw(&self, buffer: &mut Canvas, rect: Rect) { 100 | let rect = softbuffer::Rect { 101 | x: rect.x, 102 | y: rect.y, 103 | width: self.get_width(rect.width), 104 | height: self.get_height(rect.height), 105 | }; 106 | self.child.draw(buffer, rect); 107 | } 108 | 109 | fn min_space_requirements(&self) -> (WidgetSizeRequirement, WidgetSizeRequirement) { 110 | match self.constraints { 111 | SizedBoxConstraints::Both(width, height) => ( 112 | WidgetSizeRequirement::Fixed { size: width }, 113 | WidgetSizeRequirement::Fixed { size: height }, 114 | ), 115 | SizedBoxConstraints::Width(width) => ( 116 | WidgetSizeRequirement::Fixed { size: width }, 117 | self.child.min_space_requirements().1, 118 | ), 119 | SizedBoxConstraints::Height(height) => ( 120 | self.child.min_space_requirements().0, 121 | WidgetSizeRequirement::Fixed { size: height }, 122 | ), 123 | } 124 | } 125 | 126 | fn handle_event(&mut self, event: &AppEvent, rect: Rect) -> Self::EventResponse { 127 | self.child.handle_event(event, rect) 128 | } 129 | } -------------------------------------------------------------------------------- /src/widget/skia_widgets/mod.rs: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /src/widget/svg_widgets/mod.rs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VirgileHenry/nerf/0ca0754f5e5f6b2ac622e5a555189c4240b60556/src/widget/svg_widgets/mod.rs -------------------------------------------------------------------------------- /src/widget/text_widgets/mod.rs: -------------------------------------------------------------------------------- 1 | pub(crate) mod text; 2 | pub(crate) mod text_style; -------------------------------------------------------------------------------- /src/widget/text_widgets/text.rs: -------------------------------------------------------------------------------- 1 | use std::num::NonZeroU32; 2 | 3 | use crate::{ 4 | Widget, 5 | WidgetSizeRequirement, 6 | Canvas, 7 | TextStyle, 8 | Rect 9 | }; 10 | 11 | pub(crate) mod text_overflow; 12 | 13 | pub type TextAlign = cosmic_text::Align; 14 | 15 | pub struct Text { 16 | _m: core::marker::PhantomData, 17 | text: String, 18 | style: TextStyle, 19 | } 20 | 21 | impl Text { 22 | pub fn new(text: String, style: TextStyle) -> Self { 23 | Text { 24 | _m: core::marker::PhantomData, 25 | text, 26 | style, 27 | } 28 | } 29 | 30 | pub fn set_text(&mut self, text: String) { 31 | self.text = text; 32 | } 33 | } 34 | 35 | impl Widget for Text { 36 | type EventResponse = (); 37 | fn draw(&self, canvas: &mut Canvas, rect: Rect) { 38 | canvas.draw_text(&self.text, rect, &self.style); 39 | } 40 | 41 | fn min_space_requirements(&self) -> (WidgetSizeRequirement, WidgetSizeRequirement) { 42 | ( 43 | WidgetSizeRequirement::Flex { flex: unsafe { NonZeroU32::new_unchecked(1) } }, 44 | WidgetSizeRequirement::Flex { flex: unsafe { NonZeroU32::new_unchecked(1) } }, 45 | ) 46 | } 47 | 48 | fn handle_event(&mut self, _: &crate::app::event::AppEvent, _: Rect) -> Self::EventResponse { 49 | () 50 | } 51 | } -------------------------------------------------------------------------------- /src/widget/text_widgets/text/text_overflow.rs: -------------------------------------------------------------------------------- 1 | 2 | 3 | /// Describes how horizontal text overflows are handled. 4 | #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] 5 | pub enum TextOverflow { 6 | /// Clip the text at a pixel level 7 | ClipPixels, 8 | /// Clip the text at a character level 9 | ClipChar, 10 | /// Clip the text at a word level 11 | ClipWord, 12 | /// Replace the overflow with an ellipsis at a char level 13 | CharEllipsis, 14 | /// Replace the overflow with an ellipsis at a word level 15 | WordEllipsis, 16 | /// Put the overflow on a new line. This might cause vertical overflow, 17 | /// Which is clipped. 18 | NewLine, 19 | } 20 | 21 | impl Into for TextOverflow { 22 | fn into(self) -> cosmic_text::Wrap { 23 | match self { 24 | TextOverflow::ClipPixels => cosmic_text::Wrap::None, 25 | TextOverflow::ClipChar => cosmic_text::Wrap::Glyph, 26 | TextOverflow::ClipWord => cosmic_text::Wrap::Word, 27 | TextOverflow::CharEllipsis => cosmic_text::Wrap::Glyph, 28 | TextOverflow::WordEllipsis => cosmic_text::Wrap::Word, 29 | TextOverflow::NewLine => cosmic_text::Wrap::Word, 30 | } 31 | } 32 | } -------------------------------------------------------------------------------- /src/widget/text_widgets/text_style.rs: -------------------------------------------------------------------------------- 1 | use crate::Color; 2 | 3 | use self::font_family::FontFamily; 4 | 5 | use super::text::{text_overflow::TextOverflow, TextAlign}; 6 | 7 | pub(crate) mod font_family; 8 | 9 | pub type FontWeight = cosmic_text::Weight; 10 | pub type FontCharSpacing = cosmic_text::Stretch; 11 | pub type FontStyle = cosmic_text::Style; 12 | 13 | #[derive(Debug, Clone)] 14 | pub struct TextStyle { 15 | pub size: f32, 16 | pub additional_interline: f32, 17 | pub family: FontFamily, 18 | pub weight: FontWeight, 19 | pub spacing: FontCharSpacing, 20 | pub style: FontStyle, 21 | pub color: Color, 22 | pub overflow: TextOverflow, 23 | pub align: TextAlign, 24 | } 25 | 26 | impl TextStyle { 27 | pub fn sized(self, size: f32) -> TextStyle { 28 | TextStyle { 29 | size, 30 | ..self 31 | } 32 | } 33 | 34 | pub fn interlined(self, additional_interline: f32) -> TextStyle { 35 | TextStyle { 36 | additional_interline, 37 | ..self 38 | } 39 | } 40 | 41 | pub fn with_font(self, family: FontFamily) -> TextStyle { 42 | TextStyle { 43 | family, 44 | ..self 45 | } 46 | } 47 | 48 | pub fn weighted(self, weight: FontWeight) -> TextStyle { 49 | TextStyle { 50 | weight, 51 | ..self 52 | } 53 | } 54 | 55 | pub fn spaced(self, spacing: FontCharSpacing) -> TextStyle { 56 | TextStyle { 57 | spacing, 58 | ..self 59 | } 60 | } 61 | 62 | pub fn styled(self, style: FontStyle) -> TextStyle { 63 | TextStyle { 64 | style, 65 | ..self 66 | } 67 | } 68 | 69 | pub fn colored(self, color: Color) -> TextStyle { 70 | TextStyle { 71 | color, 72 | ..self 73 | } 74 | } 75 | 76 | pub fn with_overflow(self, overflow: TextOverflow) -> TextStyle { 77 | TextStyle { 78 | overflow, 79 | ..self 80 | } 81 | } 82 | 83 | pub fn aligned(self, align: TextAlign) -> TextStyle { 84 | TextStyle { 85 | align, 86 | ..self 87 | } 88 | } 89 | } 90 | 91 | impl<'a> Into> for &'a TextStyle { 92 | fn into(self) -> cosmic_text::Attrs<'a> { 93 | cosmic_text::Attrs::new() 94 | .family((&self.family).into()) 95 | .weight(self.weight) 96 | .stretch(self.spacing) 97 | .style(self.style) 98 | } 99 | } 100 | 101 | impl Default for TextStyle { 102 | fn default() -> Self { 103 | TextStyle { 104 | size: 14.0, 105 | additional_interline: 0.0, 106 | family: FontFamily::SansSerif, 107 | weight: FontWeight::NORMAL, 108 | spacing: FontCharSpacing::Normal, 109 | style: FontStyle::Normal, 110 | color: Color::BLACK, 111 | overflow: TextOverflow::ClipPixels, 112 | align: TextAlign::Left, 113 | } 114 | } 115 | } -------------------------------------------------------------------------------- /src/widget/text_widgets/text_style/font_family.rs: -------------------------------------------------------------------------------- 1 | 2 | #[derive(Debug, Clone)] 3 | pub enum FontFamily { 4 | Name(String), 5 | Serif, 6 | SansSerif, 7 | Monospace, 8 | Cursive, 9 | Fantasy, 10 | } 11 | 12 | impl<'a> Into> for &'a FontFamily { 13 | fn into(self) -> cosmic_text::Family<'a> { 14 | match self { 15 | FontFamily::Name(name) => cosmic_text::Family::Name(&name), 16 | FontFamily::Serif => cosmic_text::Family::Serif, 17 | FontFamily::SansSerif => cosmic_text::Family::SansSerif, 18 | FontFamily::Monospace => cosmic_text::Family::Monospace, 19 | FontFamily::Cursive => cosmic_text::Family::Cursive, 20 | FontFamily::Fantasy => cosmic_text::Family::Fantasy, 21 | } 22 | } 23 | } 24 | 25 | 26 | --------------------------------------------------------------------------------