From 0111f514a11fdda7db69ca0c99ad751194665d17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Ram=C3=B3n=20Jim=C3=A9nez?= Date: Mon, 8 Sep 2025 05:16:20 +0200 Subject: [PATCH] Use `winit` to obtain current `theme::Mode` --- Cargo.lock | 477 ++-------------------------- Cargo.toml | 7 +- core/Cargo.toml | 5 - core/src/theme.rs | 52 ++- devtools/src/lib.rs | 22 +- examples/arc/src/main.rs | 2 +- examples/bezier_tool/src/main.rs | 2 +- examples/ferris/src/main.rs | 2 +- examples/game_of_life/src/main.rs | 2 +- examples/layout/src/main.rs | 11 +- examples/multi_window/src/main.rs | 8 +- examples/qr_code/src/main.rs | 9 +- examples/styling/src/main.rs | 43 ++- examples/table/src/main.rs | 2 +- examples/tour/src/main.rs | 24 +- examples/vectorial_text/src/main.rs | 2 +- examples/visible_bounds/src/main.rs | 2 +- program/src/lib.rs | 28 +- src/application.rs | 34 +- src/application/timed.rs | 4 +- src/daemon.rs | 34 +- src/lib.rs | 2 +- widget/src/helpers.rs | 4 +- winit/src/lib.rs | 17 +- winit/src/window/state.rs | 15 +- 25 files changed, 208 insertions(+), 602 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b54ce648..a3be4ad7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -91,15 +91,6 @@ dependencies = [ "thiserror 1.0.69", ] -[[package]] -name = "android-build" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8cac4c64175d504608cf239756339c07f6384a476f97f20a7043f92920b0b8fd" -dependencies = [ - "windows-sys 0.52.0", -] - [[package]] name = "android-properties" version = "0.2.2" @@ -199,18 +190,6 @@ dependencies = [ "libloading", ] -[[package]] -name = "async-broadcast" -version = "0.7.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "435a87a52755b8f27fcf321ac4f04b2802e337c8c4872923137471ec39c37532" -dependencies = [ - "event-listener", - "event-listener-strategy", - "futures-core", - "pin-project-lite", -] - [[package]] name = "async-channel" version = "2.5.0" @@ -306,17 +285,6 @@ dependencies = [ "rustix 1.0.8", ] -[[package]] -name = "async-recursion" -version = "1.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b43422f69d8ff38f95f1b2bb76517c91589a924d1559a0e935d7c8ce0274c11" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - [[package]] name = "async-signal" version = "0.2.12" @@ -341,17 +309,6 @@ version = "4.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b75356056920673b02621b35afd0f7dda9306d03c79a30f5c56c44cf256e3de" -[[package]] -name = "async-trait" -version = "0.1.89" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9035ad2d096bed7955a320ee7e2230574d28fd3c3a0f186cbea1ff3c7eed5dbb" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - [[package]] name = "async-tungstenite" version = "0.25.1" @@ -545,15 +502,6 @@ dependencies = [ "objc2 0.5.2", ] -[[package]] -name = "block2" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "340d2f0bdb2a43c1d3cd40513185b2bd7def0aa1052f956455114bc98f82dcf2" -dependencies = [ - "objc2 0.6.2", -] - [[package]] name = "blocking" version = "1.6.2" @@ -831,7 +779,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9b7f4aaa047ba3c3630b080bb9860894732ff23e2aee290a418909aa6d5df38f" dependencies = [ "objc2 0.5.2", - "objc2-app-kit 0.2.2", + "objc2-app-kit", "objc2-foundation 0.2.2", ] @@ -1241,16 +1189,6 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bd0c93bb4b0c6d9b77f4435b0ae98c24d17f1c45b2ff844c6151a07256ca923b" -[[package]] -name = "dispatch2" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89a09f22a6c6069a18470eb92d2298acf25463f14256d24778e1230d789a2aec" -dependencies = [ - "bitflags 2.9.4", - "objc2 0.6.2", -] - [[package]] name = "displaydoc" version = "0.2.5" @@ -1362,33 +1300,6 @@ dependencies = [ "cfg-if", ] -[[package]] -name = "endi" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a3d8a32ae18130a3c84dd492d4215c3d913c3b07c6b63c2eb3eb7ff1101ab7bf" - -[[package]] -name = "enumflags2" -version = "0.7.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1027f7680c853e056ebcec683615fb6fbbc07dbaa13b4d5d9442b146ded4ecef" -dependencies = [ - "enumflags2_derive", - "serde", -] - -[[package]] -name = "enumflags2_derive" -version = "0.7.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "67c78a4d8fdf9953a5c9d458f9efe940fd97a0cab0941c075a813ac594733827" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - [[package]] name = "equator" version = "0.4.2" @@ -2182,12 +2093,6 @@ version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fc0fef456e4baa96da950455cd02c081ca953b141298e41db3fc7e36b1da849c" -[[package]] -name = "hex" -version = "0.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" - [[package]] name = "hexf-parse" version = "0.2.1" @@ -2432,7 +2337,6 @@ dependencies = [ "glam", "lilt", "log", - "mundy", "num-traits", "rustc-hash 2.1.1", "serde", @@ -3258,15 +3162,6 @@ dependencies = [ "libc", ] -[[package]] -name = "memoffset" -version = "0.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "488016bfae457b036d996092f6cb448677611ce4449e970ceaf42695203f218a" -dependencies = [ - "autocfg", -] - [[package]] name = "metal" version = "0.32.0" @@ -3376,31 +3271,6 @@ dependencies = [ "voronator", ] -[[package]] -name = "mundy" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f5f507e52285e981a349f7224e0ac7eaf014e1a9cce399471547c8dfbc018b79" -dependencies = [ - "android-build", - "async-io", - "cfg-if", - "dispatch", - "futures-channel", - "futures-lite", - "jni", - "ndk-context", - "objc2 0.6.2", - "objc2-app-kit 0.3.1", - "objc2-foundation 0.3.1", - "pin-project-lite", - "wasm-bindgen", - "wasm-bindgen-futures", - "web-sys", - "windows 0.61.3", - "zbus", -] - [[package]] name = "mutate_once" version = "0.1.2" @@ -3486,19 +3356,6 @@ version = "1.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "650eef8c711430f1a879fdd01d4745a7deea475becfb90269c06775983bbf086" -[[package]] -name = "nix" -version = "0.30.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "74523f3a35e05aba87a1d978330aef40f67b0304ac79c1c00b294c9830543db6" -dependencies = [ - "bitflags 2.9.4", - "cfg-if", - "cfg_aliases", - "libc", - "memoffset", -] - [[package]] name = "nom" version = "7.1.3" @@ -3674,32 +3531,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e4e89ad9e3d7d297152b17d39ed92cd50ca8063a89a9fa569046d41568891eff" dependencies = [ "bitflags 2.9.4", - "block2 0.5.1", + "block2", "libc", "objc2 0.5.2", - "objc2-core-data 0.2.2", - "objc2-core-image 0.2.2", + "objc2-core-data", + "objc2-core-image", "objc2-foundation 0.2.2", - "objc2-quartz-core 0.2.2", -] - -[[package]] -name = "objc2-app-kit" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6f29f568bec459b0ddff777cec4fe3fd8666d82d5a40ebd0ff7e66134f89bcc" -dependencies = [ - "bitflags 2.9.4", - "block2 0.6.1", - "libc", - "objc2 0.6.2", - "objc2-cloud-kit 0.3.1", - "objc2-core-data 0.3.1", - "objc2-core-foundation", - "objc2-core-graphics", - "objc2-core-image 0.3.1", - "objc2-foundation 0.3.1", - "objc2-quartz-core 0.3.1", + "objc2-quartz-core", ] [[package]] @@ -3709,30 +3547,19 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "74dd3b56391c7a0596a295029734d3c1c5e7e510a4cb30245f8221ccea96b009" dependencies = [ "bitflags 2.9.4", - "block2 0.5.1", + "block2", "objc2 0.5.2", "objc2-core-location", "objc2-foundation 0.2.2", ] -[[package]] -name = "objc2-cloud-kit" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "17614fdcd9b411e6ff1117dfb1d0150f908ba83a7df81b1f118005fe0a8ea15d" -dependencies = [ - "bitflags 2.9.4", - "objc2 0.6.2", - "objc2-foundation 0.3.1", -] - [[package]] name = "objc2-contacts" version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a5ff520e9c33812fd374d8deecef01d4a840e7b41862d849513de77e44aa4889" dependencies = [ - "block2 0.5.1", + "block2", "objc2 0.5.2", "objc2-foundation 0.2.2", ] @@ -3744,75 +3571,30 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "617fbf49e071c178c0b24c080767db52958f716d9eabdf0890523aeae54773ef" dependencies = [ "bitflags 2.9.4", - "block2 0.5.1", + "block2", "objc2 0.5.2", "objc2-foundation 0.2.2", ] -[[package]] -name = "objc2-core-data" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "291fbbf7d29287518e8686417cf7239c74700fd4b607623140a7d4a3c834329d" -dependencies = [ - "bitflags 2.9.4", - "objc2 0.6.2", - "objc2-foundation 0.3.1", -] - -[[package]] -name = "objc2-core-foundation" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1c10c2894a6fed806ade6027bcd50662746363a9589d3ec9d9bef30a4e4bc166" -dependencies = [ - "bitflags 2.9.4", - "dispatch2", - "objc2 0.6.2", -] - -[[package]] -name = "objc2-core-graphics" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "989c6c68c13021b5c2d6b71456ebb0f9dc78d752e86a98da7c716f4f9470f5a4" -dependencies = [ - "bitflags 2.9.4", - "dispatch2", - "objc2 0.6.2", - "objc2-core-foundation", - "objc2-io-surface", -] - [[package]] name = "objc2-core-image" version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "55260963a527c99f1819c4f8e3b47fe04f9650694ef348ffd2227e8196d34c80" dependencies = [ - "block2 0.5.1", + "block2", "objc2 0.5.2", "objc2-foundation 0.2.2", "objc2-metal", ] -[[package]] -name = "objc2-core-image" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "79b3dc0cc4386b6ccf21c157591b34a7f44c8e75b064f85502901ab2188c007e" -dependencies = [ - "objc2 0.6.2", - "objc2-foundation 0.3.1", -] - [[package]] name = "objc2-core-location" version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "000cfee34e683244f284252ee206a27953279d370e309649dc3ee317b37e5781" dependencies = [ - "block2 0.5.1", + "block2", "objc2 0.5.2", "objc2-contacts", "objc2-foundation 0.2.2", @@ -3831,7 +3613,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0ee638a5da3799329310ad4cfa62fbf045d5f56e3ef5ba4149e7452dcf89d5a8" dependencies = [ "bitflags 2.9.4", - "block2 0.5.1", + "block2", "dispatch", "libc", "objc2 0.5.2", @@ -3844,21 +3626,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "900831247d2fe1a09a683278e5384cfb8c80c79fe6b166f9d14bfdde0ea1b03c" dependencies = [ "bitflags 2.9.4", - "block2 0.6.1", - "libc", "objc2 0.6.2", - "objc2-core-foundation", -] - -[[package]] -name = "objc2-io-surface" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7282e9ac92529fa3457ce90ebb15f4ecbc383e8338060960760fa2cf75420c3c" -dependencies = [ - "bitflags 2.9.4", - "objc2 0.6.2", - "objc2-core-foundation", ] [[package]] @@ -3867,9 +3635,9 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a1a1ae721c5e35be65f01a03b6d2ac13a54cb4fa70d8a5da293d7b0020261398" dependencies = [ - "block2 0.5.1", + "block2", "objc2 0.5.2", - "objc2-app-kit 0.2.2", + "objc2-app-kit", "objc2-foundation 0.2.2", ] @@ -3880,7 +3648,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dd0cba1276f6023976a406a14ffa85e1fdd19df6b0f737b063b95f6c8c7aadd6" dependencies = [ "bitflags 2.9.4", - "block2 0.5.1", + "block2", "objc2 0.5.2", "objc2-foundation 0.2.2", ] @@ -3892,23 +3660,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e42bee7bff906b14b167da2bac5efe6b6a07e6f7c0a21a7308d40c960242dc7a" dependencies = [ "bitflags 2.9.4", - "block2 0.5.1", + "block2", "objc2 0.5.2", "objc2-foundation 0.2.2", "objc2-metal", ] -[[package]] -name = "objc2-quartz-core" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90ffb6a0cd5f182dc964334388560b12a57f7b74b3e2dec5e2722aa2dfb2ccd5" -dependencies = [ - "bitflags 2.9.4", - "objc2 0.6.2", - "objc2-foundation 0.3.1", -] - [[package]] name = "objc2-symbols" version = "0.2.2" @@ -3926,15 +3683,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b8bb46798b20cd6b91cbd113524c490f1686f4c4e8f49502431415f3512e2b6f" dependencies = [ "bitflags 2.9.4", - "block2 0.5.1", + "block2", "objc2 0.5.2", - "objc2-cloud-kit 0.2.2", - "objc2-core-data 0.2.2", - "objc2-core-image 0.2.2", + "objc2-cloud-kit", + "objc2-core-data", + "objc2-core-image", "objc2-core-location", "objc2-foundation 0.2.2", "objc2-link-presentation", - "objc2-quartz-core 0.2.2", + "objc2-quartz-core", "objc2-symbols", "objc2-uniform-type-identifiers", "objc2-user-notifications", @@ -3946,7 +3703,7 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "44fa5f9748dbfe1ca6c0b79ad20725a11eca7c2218bceb4b005cb1be26273bfe" dependencies = [ - "block2 0.5.1", + "block2", "objc2 0.5.2", "objc2-foundation 0.2.2", ] @@ -3958,7 +3715,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "76cfcbf642358e8689af64cee815d139339f3ed8ad05103ed5eaf73db8d84cb3" dependencies = [ "bitflags 2.9.4", - "block2 0.5.1", + "block2", "objc2 0.5.2", "objc2-core-location", "objc2-foundation 0.2.2", @@ -4095,16 +3852,6 @@ dependencies = [ "num-traits", ] -[[package]] -name = "ordered-stream" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9aa2b01e1d916879f73a53d01d1d6cee68adbb31d6d9177a8cfce093cced1d50" -dependencies = [ - "futures-core", - "pin-project-lite", -] - [[package]] name = "ouroboros" version = "0.18.5" @@ -5215,17 +4962,6 @@ dependencies = [ "serde", ] -[[package]] -name = "serde_repr" -version = "0.1.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "175ee3e80ae9982737ca543e96133087cbd9a485eecc3bc4de9c1a37b47ea59c" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - [[package]] name = "serde_spanned" version = "0.6.9" @@ -5479,7 +5215,7 @@ dependencies = [ "memmap2", "objc2 0.5.2", "objc2-foundation 0.2.2", - "objc2-quartz-core 0.2.2", + "objc2-quartz-core", "raw-window-handle 0.6.2", "redox_syscall 0.5.17", "rustix 0.38.44", @@ -6266,17 +6002,6 @@ version = "1.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1dccffe3ce07af9386bfd29e80c0ab1a8205a2fc34e4bcd40364df902cfa8f3f" -[[package]] -name = "uds_windows" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89daebc3e6fd160ac4aa9fc8b3bf71e1f74fbf92367ae71fb83a037e8bf164b9" -dependencies = [ - "memoffset", - "tempfile", - "winapi", -] - [[package]] name = "unicase" version = "2.8.1" @@ -7055,28 +6780,6 @@ dependencies = [ "windows-targets 0.52.6", ] -[[package]] -name = "windows" -version = "0.61.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9babd3a767a4c1aef6900409f85f5d53ce2544ccdfaa86dad48c91782c6d6893" -dependencies = [ - "windows-collections", - "windows-core 0.61.2", - "windows-future", - "windows-link 0.1.3", - "windows-numerics", -] - -[[package]] -name = "windows-collections" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3beeceb5e5cfd9eb1d76b381630e82c4241ccd0d27f1a39ed41b2760b255c5e8" -dependencies = [ - "windows-core 0.61.2", -] - [[package]] name = "windows-core" version = "0.57.0" @@ -7115,17 +6818,6 @@ dependencies = [ "windows-strings 0.4.2", ] -[[package]] -name = "windows-future" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc6a41e98427b19fe4b73c550f060b59fa592d7d686537eebf9385621bfbad8e" -dependencies = [ - "windows-core 0.61.2", - "windows-link 0.1.3", - "windows-threading", -] - [[package]] name = "windows-implement" version = "0.57.0" @@ -7204,16 +6896,6 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "45e46c0661abb7180e7b9c281db115305d49ca1709ab8242adf09666d2173c65" -[[package]] -name = "windows-numerics" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9150af68066c4c5c07ddc0ce30421554771e528bde427614c61038bc2c92c2b1" -dependencies = [ - "windows-core 0.61.2", - "windows-link 0.1.3", -] - [[package]] name = "windows-registry" version = "0.5.3" @@ -7388,15 +7070,6 @@ dependencies = [ "windows_x86_64_msvc 0.53.0", ] -[[package]] -name = "windows-threading" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b66463ad2e0ea3bbf808b7f1d371311c80e115c0b71d60efc142cafbcfb057a6" -dependencies = [ - "windows-link 0.1.3", -] - [[package]] name = "windows_aarch64_gnullvm" version = "0.42.2" @@ -7586,7 +7259,7 @@ dependencies = [ "android-activity", "atomic-waker", "bitflags 2.9.4", - "block2 0.5.1", + "block2", "bytemuck", "calloop", "cfg_aliases", @@ -7600,7 +7273,7 @@ dependencies = [ "memmap2", "ndk", "objc2 0.5.2", - "objc2-app-kit 0.2.2", + "objc2-app-kit", "objc2-foundation 0.2.2", "objc2-ui-kit", "orbclient", @@ -7763,66 +7436,6 @@ dependencies = [ "synstructure", ] -[[package]] -name = "zbus" -version = "5.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "67a073be99ace1adc48af593701c8015cd9817df372e14a1a6b0ee8f8bf043be" -dependencies = [ - "async-broadcast", - "async-executor", - "async-io", - "async-lock", - "async-process", - "async-recursion", - "async-task", - "async-trait", - "blocking", - "enumflags2", - "event-listener", - "futures-core", - "futures-lite", - "hex", - "nix", - "ordered-stream", - "serde", - "serde_repr", - "tracing", - "uds_windows", - "windows-sys 0.60.2", - "winnow", - "zbus_macros", - "zbus_names", - "zvariant", -] - -[[package]] -name = "zbus_macros" -version = "5.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0e80cd713a45a49859dcb648053f63265f4f2851b6420d47a958e5697c68b131" -dependencies = [ - "proc-macro-crate", - "proc-macro2", - "quote", - "syn", - "zbus_names", - "zvariant", - "zvariant_utils", -] - -[[package]] -name = "zbus_names" -version = "4.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7be68e64bf6ce8db94f63e72f0c7eb9a60d733f7e0499e628dfab0f84d6bcb97" -dependencies = [ - "serde", - "static_assertions", - "winnow", - "zvariant", -] - [[package]] name = "zeno" version = "0.3.3" @@ -7932,43 +7545,3 @@ checksum = "29ce2c8a9384ad323cf564b67da86e21d3cfdff87908bc1223ed5c99bc792713" dependencies = [ "zune-core", ] - -[[package]] -name = "zvariant" -version = "5.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "999dd3be73c52b1fccd109a4a81e4fcd20fab1d3599c8121b38d04e1419498db" -dependencies = [ - "endi", - "enumflags2", - "serde", - "winnow", - "zvariant_derive", - "zvariant_utils", -] - -[[package]] -name = "zvariant_derive" -version = "5.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6643fd0b26a46d226bd90d3f07c1b5321fe9bb7f04673cb37ac6d6883885b68e" -dependencies = [ - "proc-macro-crate", - "proc-macro2", - "quote", - "syn", - "zvariant_utils", -] - -[[package]] -name = "zvariant_utils" -version = "3.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c6949d142f89f6916deca2232cf26a8afacf2b9fdc35ce766105e104478be599" -dependencies = [ - "proc-macro2", - "quote", - "serde", - "syn", - "winnow", -] diff --git a/Cargo.toml b/Cargo.toml index c587c7d9..f68a5c96 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,7 +22,7 @@ all-features = true maintenance = { status = "actively-developed" } [features] -default = ["wgpu", "tiny-skia", "crisp", "web-colors", "auto-detect-theme", "thread-pool"] +default = ["wgpu", "tiny-skia", "crisp", "web-colors", "thread-pool"] # Enables the `wgpu` GPU-accelerated renderer backend wgpu = ["iced_renderer/wgpu", "iced_widget/wgpu"] # Enables the `tiny-skia` software renderer backend @@ -67,8 +67,6 @@ highlighter = ["iced_highlighter", "iced_widget/highlighter"] advanced = ["iced_core/advanced", "iced_widget/advanced"] # Embeds Fira Sans into the final application; useful for testing and Wasm builds fira-sans = ["iced_renderer/fira-sans"] -# Auto-detects light/dark mode for the built-in theme -auto-detect-theme = ["iced_core/auto-detect-theme"] # Enables basic text shaping by default basic-shaping = ["iced_core/basic-shaping"] # Enables advanced text shaping by default @@ -218,9 +216,6 @@ wgpu = "26.0" window_clipboard = "0.4.1" winit = { git = "https://github.com/iced-rs/winit.git", rev = "11414b6aa45699f038114e61b4ddf5102b2d3b4b" } -mundy.version = "0.2" -mundy.default-features = false - [workspace.lints.rust] rust_2018_idioms = { level = "deny", priority = -1 } missing_debug_implementations = "deny" diff --git a/core/Cargo.toml b/core/Cargo.toml index 2b875545..31296446 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -14,7 +14,6 @@ keywords.workspace = true workspace = true [features] -auto-detect-theme = ["dep:mundy"] advanced = [] crisp = [] basic-shaping = [] @@ -32,10 +31,6 @@ smol_str.workspace = true thiserror.workspace = true web-time.workspace = true -mundy.workspace = true -mundy.optional = true -mundy.features = ["async-io", "color-scheme"] - serde.workspace = true serde.optional = true serde.features = ["derive"] diff --git a/core/src/theme.rs b/core/src/theme.rs index c47f4e2f..3c0f51f9 100644 --- a/core/src/theme.rs +++ b/core/src/theme.rs @@ -166,36 +166,6 @@ impl Theme { } } -impl Default for Theme { - fn default() -> Self { - #[cfg(feature = "auto-detect-theme")] - { - use crate::time::Duration; - use std::sync::LazyLock; - - static DEFAULT: LazyLock = LazyLock::new(|| { - let color_scheme = mundy::Preferences::once_blocking( - mundy::Interest::ColorScheme, - Duration::from_millis(100), - ) - .map(|preferences| preferences.color_scheme) - .unwrap_or_default(); - - match color_scheme { - mundy::ColorScheme::Dark => Theme::Dark, - mundy::ColorScheme::Light - | mundy::ColorScheme::NoPreference => Theme::Light, - } - }); - - DEFAULT.clone() - } - - #[cfg(not(feature = "auto-detect-theme"))] - Theme::Light - } -} - impl fmt::Display for Theme { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { @@ -261,6 +231,18 @@ impl fmt::Display for Custom { } } +/// A theme mode, denoting the tone or brightness of a theme. +#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)] +pub enum Mode { + /// No specific tone. + #[default] + None, + /// A mode referring to themes with light tones. + Light, + /// A mode referring to themes with dark tones. + Dark, +} + /// The base style of a theme. #[derive(Debug, Clone, Copy, PartialEq)] pub struct Style { @@ -273,6 +255,9 @@ pub struct Style { /// The default blank style of a theme. pub trait Base { + /// Returns the default theme for the preferred [`Mode`]. + fn default(preference: Mode) -> Self; + /// Returns the default base [`Style`] of a theme. fn base(&self) -> Style; @@ -285,6 +270,13 @@ pub trait Base { } impl Base for Theme { + fn default(preference: Mode) -> Self { + match preference { + Mode::None | Mode::Light => Self::Light, + Mode::Dark => Self::Dark, + } + } + fn base(&self) -> Style { default(self) } diff --git a/devtools/src/lib.rs b/devtools/src/lib.rs index 09a2a67b..d8ef0729 100644 --- a/devtools/src/lib.rs +++ b/devtools/src/lib.rs @@ -12,7 +12,7 @@ mod time_machine; use crate::core::border; use crate::core::keyboard; -use crate::core::theme::{self, Base, Theme}; +use crate::core::theme::{self, Theme}; use crate::core::time::seconds; use crate::core::window; use crate::core::{Alignment::Center, Color, Element, Length::Fill}; @@ -90,7 +90,11 @@ where state.subscription(&self.program) } - fn theme(&self, state: &Self::State, window: window::Id) -> Self::Theme { + fn theme( + &self, + state: &Self::State, + window: window::Id, + ) -> Option { state.theme(&self.program, window) } @@ -307,14 +311,12 @@ where } }; - let theme = program.theme(state, window); - - let derive_theme = move || { + fn derive_theme(theme: &T) -> Theme { theme .palette() .map(|palette| Theme::custom("iced devtools", palette)) - .unwrap_or_default() - }; + .unwrap_or(Theme::Dark) + } let mode = match &self.mode { Mode::None => None, @@ -340,7 +342,7 @@ where } } .map(|mode| { - themer(derive_theme(), Element::from(mode).map(Event::Message)) + themer(derive_theme, Element::from(mode).map(Event::Message)) }); let notification = self @@ -359,7 +361,7 @@ where .push_maybe(mode.map(opaque)) .push_maybe(notification.map(|notification| { themer( - derive_theme(), + derive_theme, bottom_right(opaque( container(notification) .padding(10) @@ -389,7 +391,7 @@ where Subscription::batch([subscription, hotkeys, commands]) } - fn theme(&self, program: &P, window: window::Id) -> P::Theme { + fn theme(&self, program: &P, window: window::Id) -> Option { program.theme(self.state(), window) } diff --git a/examples/arc/src/main.rs b/examples/arc/src/main.rs index ce461ab6..6f801d97 100644 --- a/examples/arc/src/main.rs +++ b/examples/arc/src/main.rs @@ -10,7 +10,7 @@ use iced::{Element, Fill, Point, Rectangle, Renderer, Subscription, Theme}; pub fn main() -> iced::Result { iced::application(Arc::new, Arc::update, Arc::view) .subscription(Arc::subscription) - .theme(|_| Theme::Dark) + .theme(Theme::Dark) .run() } diff --git a/examples/bezier_tool/src/main.rs b/examples/bezier_tool/src/main.rs index 8b040755..9a525210 100644 --- a/examples/bezier_tool/src/main.rs +++ b/examples/bezier_tool/src/main.rs @@ -4,7 +4,7 @@ use iced::{Element, Theme}; pub fn main() -> iced::Result { iced::application(Example::default, Example::update, Example::view) - .theme(|_| Theme::CatppuccinMocha) + .theme(Theme::CatppuccinMocha) .run() } diff --git a/examples/ferris/src/main.rs b/examples/ferris/src/main.rs index add266b5..96b61813 100644 --- a/examples/ferris/src/main.rs +++ b/examples/ferris/src/main.rs @@ -11,7 +11,7 @@ use iced::{ pub fn main() -> iced::Result { iced::application(Image::default, Image::update, Image::view) .subscription(Image::subscription) - .theme(|_| Theme::TokyoNight) + .theme(Theme::TokyoNight) .run() } diff --git a/examples/game_of_life/src/main.rs b/examples/game_of_life/src/main.rs index e6cb4dab..d27ee62e 100644 --- a/examples/game_of_life/src/main.rs +++ b/examples/game_of_life/src/main.rs @@ -16,7 +16,7 @@ pub fn main() -> iced::Result { iced::application(GameOfLife::default, GameOfLife::update, GameOfLife::view) .subscription(GameOfLife::subscription) - .theme(|_| Theme::Dark) + .theme(Theme::Dark) .centered() .run() } diff --git a/examples/layout/src/main.rs b/examples/layout/src/main.rs index f3765d9d..b930bdb0 100644 --- a/examples/layout/src/main.rs +++ b/examples/layout/src/main.rs @@ -19,11 +19,11 @@ pub fn main() -> iced::Result { .run() } -#[derive(Default, Debug)] +#[derive(Debug, Default)] struct Layout { example: Example, explain: bool, - theme: Theme, + theme: Option, } #[derive(Debug, Clone)] @@ -51,7 +51,7 @@ impl Layout { self.explain = explain; } Message::ThemeSelected(theme) => { - self.theme = theme; + self.theme = Some(theme); } } } @@ -74,7 +74,8 @@ impl Layout { horizontal_space(), checkbox("Explain", self.explain) .on_toggle(Message::ExplainToggled), - pick_list(Theme::ALL, Some(&self.theme), Message::ThemeSelected), + pick_list(Theme::ALL, self.theme.as_ref(), Message::ThemeSelected) + .placeholder("Theme"), ] .spacing(20) .align_y(Center); @@ -116,7 +117,7 @@ impl Layout { .into() } - fn theme(&self) -> Theme { + fn theme(&self) -> Option { self.theme.clone() } } diff --git a/examples/multi_window/src/main.rs b/examples/multi_window/src/main.rs index cb5e6f43..d299648e 100644 --- a/examples/multi_window/src/main.rs +++ b/examples/multi_window/src/main.rs @@ -138,12 +138,8 @@ impl Example { } } - fn theme(&self, window: window::Id) -> Theme { - if let Some(window) = self.windows.get(&window) { - window.theme.clone() - } else { - Theme::default() - } + fn theme(&self, window: window::Id) -> Option { + Some(self.windows.get(&window)?.theme.clone()) } fn scale_factor(&self, window: window::Id) -> f32 { diff --git a/examples/qr_code/src/main.rs b/examples/qr_code/src/main.rs index 6b6989d0..fecc4abf 100644 --- a/examples/qr_code/src/main.rs +++ b/examples/qr_code/src/main.rs @@ -20,7 +20,7 @@ struct QRGenerator { data: String, qr_code: Option, total_size: Option, - theme: Theme, + theme: Option, } #[derive(Debug, Clone)] @@ -58,7 +58,7 @@ impl QRGenerator { self.total_size = Some(total_size); } Message::ThemeChanged(theme) => { - self.theme = theme; + self.theme = Some(theme); } } } @@ -78,7 +78,8 @@ impl QRGenerator { let choose_theme = row![ text("Theme:"), - pick_list(Theme::ALL, Some(&self.theme), Message::ThemeChanged,) + pick_list(Theme::ALL, self.theme.as_ref(), Message::ThemeChanged) + .placeholder("Theme") ] .spacing(10) .align_y(Center); @@ -107,7 +108,7 @@ impl QRGenerator { center(content).padding(20).into() } - fn theme(&self) -> Theme { + fn theme(&self) -> Option { self.theme.clone() } } diff --git a/examples/styling/src/main.rs b/examples/styling/src/main.rs index f28216f9..0117d2dc 100644 --- a/examples/styling/src/main.rs +++ b/examples/styling/src/main.rs @@ -15,7 +15,7 @@ pub fn main() -> iced::Result { #[derive(Default)] struct Styling { - theme: Theme, + theme: Option, input_value: String, slider_value: f32, checkbox_value: bool, @@ -38,7 +38,7 @@ impl Styling { fn update(&mut self, message: Message) { match message { Message::ThemeChanged(theme) => { - self.theme = theme; + self.theme = Some(theme); } Message::InputChanged(value) => self.input_value = value, Message::ButtonPressed => {} @@ -46,20 +46,20 @@ impl Styling { Message::CheckboxToggled(value) => self.checkbox_value = value, Message::TogglerToggled(value) => self.toggler_value = value, Message::PreviousTheme | Message::NextTheme => { - if let Some(current) = Theme::ALL - .iter() - .position(|candidate| &self.theme == candidate) - { - self.theme = if matches!(message, Message::NextTheme) { - Theme::ALL[(current + 1) % Theme::ALL.len()].clone() - } else if current == 0 { - Theme::ALL - .last() - .expect("Theme::ALL must not be empty") - .clone() - } else { - Theme::ALL[current - 1].clone() - }; + if let Some(current) = Theme::ALL.iter().position(|candidate| { + self.theme.as_ref() == Some(candidate) + }) { + self.theme = + Some(if matches!(message, Message::NextTheme) { + Theme::ALL[(current + 1) % Theme::ALL.len()].clone() + } else if current == 0 { + Theme::ALL + .last() + .expect("Theme::ALL must not be empty") + .clone() + } else { + Theme::ALL[current - 1].clone() + }); } } } @@ -68,8 +68,9 @@ impl Styling { fn view(&self) -> Element<'_, Message> { let choose_theme = column![ text("Theme:"), - pick_list(Theme::ALL, Some(&self.theme), Message::ThemeChanged) - .width(Fill), + pick_list(Theme::ALL, self.theme.as_ref(), Message::ThemeChanged) + .width(Fill) + .placeholder("System"), ] .spacing(10); @@ -190,7 +191,7 @@ impl Styling { }) } - fn theme(&self) -> Theme { + fn theme(&self) -> Option { self.theme.clone() } } @@ -210,9 +211,7 @@ mod tests { .cloned() .map(|theme| { let mut styling = Styling::default(); - styling.update(Message::ThemeChanged(theme)); - - let theme = styling.theme(); + styling.update(Message::ThemeChanged(theme.clone())); let mut ui = simulator(styling.view()); let snapshot = ui.snapshot(&theme)?; diff --git a/examples/table/src/main.rs b/examples/table/src/main.rs index 26a8e621..7a1d6be2 100644 --- a/examples/table/src/main.rs +++ b/examples/table/src/main.rs @@ -8,7 +8,7 @@ use iced::{Center, Element, Fill, Font, Right, Theme}; pub fn main() -> iced::Result { iced::application(Table::new, Table::update, Table::view) - .theme(|_| Theme::CatppuccinMocha) + .theme(Theme::CatppuccinMocha) .run() } diff --git a/examples/tour/src/main.rs b/examples/tour/src/main.rs index 5d009da6..56e14f06 100644 --- a/examples/tour/src/main.rs +++ b/examples/tour/src/main.rs @@ -1,11 +1,10 @@ -use iced::border; use iced::widget::{Button, Column, Container, Slider}; use iced::widget::{ button, center_x, center_y, checkbox, column, horizontal_space, image, radio, rich_text, row, scrollable, slider, span, text, text_input, toggler, vertical_space, }; -use iced::{Center, Color, Element, Fill, Font, Pixels, Theme}; +use iced::{Center, Color, Element, Fill, Font, Pixels, color}; pub fn main() -> iced::Result { #[cfg(target_arch = "wasm32")] @@ -201,7 +200,7 @@ impl Tour { Self::container("Welcome!") .push( "This is a simple tour meant to showcase a bunch of \ - widgets that can be easily implemented on top of Iced.", + widgets that come bundled in Iced.", ) .push( "Iced is a cross-platform GUI library for Rust focused on \ @@ -216,28 +215,19 @@ impl Tour { built on top of wgpu, a graphics library supporting Vulkan, \ Metal, DX11, and DX12.", ) - .push({ - let theme = Theme::default(); - let palette = theme.extended_palette(); - + .push( rich_text![ "Additionally, this tour can also run on WebAssembly ", "by leveraging ", span("trunk") - .color(palette.primary.base.color) - .background(palette.background.weakest.color) - .border( - border::rounded(2) - .width(1) - .color(palette.background.weak.color) - ) - .padding([0, 2]) + .color(color!(0x0000FF)) + .underline(true) .font(Font::MONOSPACE) .link(Message::OpenTrunk), "." ] - .on_link_click(std::convert::identity) - }) + .on_link_click(std::convert::identity), + ) .push( "You will need to interact with the UI in order to reach \ the end!", diff --git a/examples/vectorial_text/src/main.rs b/examples/vectorial_text/src/main.rs index d0ba91b9..78349696 100644 --- a/examples/vectorial_text/src/main.rs +++ b/examples/vectorial_text/src/main.rs @@ -11,7 +11,7 @@ pub fn main() -> iced::Result { VectorialText::update, VectorialText::view, ) - .theme(|_| Theme::Dark) + .theme(Theme::Dark) .run() } diff --git a/examples/visible_bounds/src/main.rs b/examples/visible_bounds/src/main.rs index 8e5e4a07..fa00a8fc 100644 --- a/examples/visible_bounds/src/main.rs +++ b/examples/visible_bounds/src/main.rs @@ -12,7 +12,7 @@ use iced::{ pub fn main() -> iced::Result { iced::application(Example::default, Example::update, Example::view) .subscription(Example::subscription) - .theme(|_| Theme::Dark) + .theme(Theme::Dark) .run() } diff --git a/program/src/lib.rs b/program/src/lib.rs index d479d2f8..3b516770 100644 --- a/program/src/lib.rs +++ b/program/src/lib.rs @@ -25,7 +25,7 @@ pub trait Program: Sized { type Message: Message + 'static; /// The theme of the program. - type Theme: Default + theme::Base; + type Theme: theme::Base; /// The renderer of the program. type Renderer: Renderer; @@ -86,8 +86,12 @@ pub trait Program: Sized { Subscription::none() } - fn theme(&self, _state: &Self::State, _window: window::Id) -> Self::Theme { - ::default() + fn theme( + &self, + _state: &Self::State, + _window: window::Id, + ) -> Option { + None } fn style(&self, _state: &Self::State, theme: &Self::Theme) -> theme::Style { @@ -152,7 +156,7 @@ pub fn with_title( &self, state: &Self::State, window: window::Id, - ) -> Self::Theme { + ) -> Option { self.program.theme(state, window) } @@ -238,7 +242,7 @@ pub fn with_subscription( &self, state: &Self::State, window: window::Id, - ) -> Self::Theme { + ) -> Option { self.program.theme(state, window) } @@ -264,7 +268,7 @@ pub fn with_subscription( /// Decorates a [`Program`] with the given theme function. pub fn with_theme( program: P, - f: impl Fn(&P::State, window::Id) -> P::Theme, + f: impl Fn(&P::State, window::Id) -> Option, ) -> impl Program { struct WithTheme { program: P, @@ -273,7 +277,7 @@ pub fn with_theme( impl Program for WithTheme where - F: Fn(&P::State, window::Id) -> P::Theme, + F: Fn(&P::State, window::Id) -> Option, { type State = P::State; type Message = P::Message; @@ -285,7 +289,7 @@ pub fn with_theme( &self, state: &Self::State, window: window::Id, - ) -> Self::Theme { + ) -> Option { (self.theme)(state, window) } @@ -407,7 +411,7 @@ pub fn with_style( &self, state: &Self::State, window: window::Id, - ) -> Self::Theme { + ) -> Option { self.program.theme(state, window) } @@ -478,7 +482,7 @@ pub fn with_scale_factor( &self, state: &Self::State, window: window::Id, - ) -> Self::Theme { + ) -> Option { self.program.theme(state, window) } @@ -561,7 +565,7 @@ pub fn with_executor( &self, state: &Self::State, window: window::Id, - ) -> Self::Theme { + ) -> Option { self.program.theme(state, window) } @@ -628,7 +632,7 @@ impl Instance

{ } /// Returns the current theme of the [`Instance`]. - pub fn theme(&self, window: window::Id) -> P::Theme { + pub fn theme(&self, window: window::Id) -> Option { self.program.theme(&self.state, window) } diff --git a/src/application.rs b/src/application.rs index d8f7862b..ef547cea 100644 --- a/src/application.rs +++ b/src/application.rs @@ -7,7 +7,7 @@ //! //! pub fn main() -> iced::Result { //! iced::application(u64::default, update, view) -//! .theme(|_| Theme::Dark) +//! .theme(Theme::Dark) //! .centered() //! .run() //! } @@ -35,7 +35,7 @@ use crate::shell; use crate::theme; use crate::window; use crate::{ - Element, Executor, Font, Result, Settings, Size, Subscription, Task, + Element, Executor, Font, Result, Settings, Size, Subscription, Task, Theme, }; use iced_debug as debug; @@ -82,7 +82,7 @@ pub fn application( where State: 'static, Message: program::Message + 'static, - Theme: Default + theme::Base, + Theme: theme::Base, Renderer: program::Renderer, { use std::marker::PhantomData; @@ -101,7 +101,7 @@ where for Instance where Message: program::Message + 'static, - Theme: Default + theme::Base, + Theme: theme::Base, Renderer: program::Renderer, Boot: self::Boot, Update: self::Update, @@ -355,13 +355,13 @@ impl Application

{ /// Sets the theme logic of the [`Application`]. pub fn theme( self, - f: impl Fn(&P::State) -> P::Theme, + f: impl ThemeFn, ) -> Application< impl Program, > { Application { raw: program::with_theme(self.raw, move |state, _window| { - debug::hot(|| f(state)) + debug::hot(|| f.theme(state)) }), settings: self.settings, window: self.window, @@ -529,3 +529,25 @@ where self(state).into() } } + +/// TODO +pub trait ThemeFn { + /// TODO + fn theme(&self, state: &State) -> Option; +} + +impl ThemeFn for Theme { + fn theme(&self, _state: &State) -> Option { + Some(self.clone()) + } +} + +impl ThemeFn for F +where + F: Fn(&State) -> T, + T: Into>, +{ + fn theme(&self, state: &State) -> Option { + (self)(state).into() + } +} diff --git a/src/application/timed.rs b/src/application/timed.rs index 3d158874..2aaf40f3 100644 --- a/src/application/timed.rs +++ b/src/application/timed.rs @@ -30,7 +30,7 @@ pub fn timed( where State: 'static, Message: program::Message + 'static, - Theme: Default + theme::Base + 'static, + Theme: theme::Base + 'static, Renderer: program::Renderer + 'static, { use std::marker::PhantomData; @@ -69,7 +69,7 @@ where > where Message: program::Message + 'static, - Theme: Default + theme::Base + 'static, + Theme: theme::Base + 'static, Renderer: program::Renderer + 'static, Boot: self::Boot, Update: self::Update, diff --git a/src/daemon.rs b/src/daemon.rs index 05d276c3..2a4451e0 100644 --- a/src/daemon.rs +++ b/src/daemon.rs @@ -4,7 +4,9 @@ use crate::program::{self, Program}; use crate::shell; use crate::theme; use crate::window; -use crate::{Element, Executor, Font, Result, Settings, Subscription, Task}; +use crate::{ + Element, Executor, Font, Result, Settings, Subscription, Task, Theme, +}; use iced_debug as debug; @@ -28,7 +30,7 @@ pub fn daemon( where State: 'static, Message: program::Message + 'static, - Theme: Default + theme::Base, + Theme: theme::Base, Renderer: program::Renderer, { use std::marker::PhantomData; @@ -47,7 +49,7 @@ where for Instance where Message: program::Message + 'static, - Theme: Default + theme::Base, + Theme: theme::Base, Renderer: program::Renderer, Boot: application::Boot, Update: application::Update, @@ -202,13 +204,13 @@ impl Daemon

{ /// Sets the theme logic of the [`Daemon`]. pub fn theme( self, - f: impl Fn(&P::State, window::Id) -> P::Theme, + f: impl ThemeFn, ) -> Daemon< impl Program, > { Daemon { raw: program::with_theme(self.raw, move |state, window| { - debug::hot(|| f(state, window)) + debug::hot(|| f.theme(state, window)) }), settings: self.settings, } @@ -314,3 +316,25 @@ where self(state, window).into() } } + +/// TODO +pub trait ThemeFn { + /// TODO + fn theme(&self, state: &State, window: window::Id) -> Option; +} + +impl ThemeFn for Theme { + fn theme(&self, _state: &State, _window: window::Id) -> Option { + Some(self.clone()) + } +} + +impl ThemeFn for F +where + F: Fn(&State, window::Id) -> T, + T: Into>, +{ + fn theme(&self, state: &State, window: window::Id) -> Option { + (self)(state, window).into() + } +} diff --git a/src/lib.rs b/src/lib.rs index a933d21f..b0b2bb8d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -698,7 +698,7 @@ pub fn run( where State: Default + 'static, Message: program::Message + 'static, - Theme: Default + theme::Base + 'static, + Theme: theme::Base + 'static, Renderer: program::Renderer + 'static, { application(State::default, update, view).run() diff --git a/widget/src/helpers.rs b/widget/src/helpers.rs index 3b1d0bbe..9e510685 100644 --- a/widget/src/helpers.rs +++ b/widget/src/helpers.rs @@ -2063,7 +2063,7 @@ where /// A widget that applies any `Theme` to its contents. pub fn themer<'a, Message, OldTheme, NewTheme, Renderer>( - new_theme: NewTheme, + to_theme: impl Fn(&OldTheme) -> NewTheme, content: impl Into>, ) -> Themer< 'a, @@ -2077,7 +2077,7 @@ where Renderer: core::Renderer, NewTheme: Clone, { - Themer::new(move |_| new_theme.clone(), content) + Themer::new(to_theme, content) } /// Creates a [`PaneGrid`] with the given [`pane_grid::State`] and view function. diff --git a/winit/src/lib.rs b/winit/src/lib.rs index 38d6f3c3..6f9cea56 100644 --- a/winit/src/lib.rs +++ b/winit/src/lib.rs @@ -595,14 +595,7 @@ async fn run_instance

( } } - debug::theme_changed(|| { - if window_manager.is_empty() { - theme::Base::palette(&program.theme(id)) - } else { - None - } - }); - + let is_first = window_manager.is_empty(); let window = window_manager.insert( id, window, @@ -613,6 +606,14 @@ async fn run_instance

( exit_on_close_request, ); + debug::theme_changed(|| { + if is_first { + theme::Base::palette(window.state.theme()) + } else { + None + } + }); + let logical_size = window.state.logical_size(); let _ = user_interfaces.insert( diff --git a/winit/src/window/state.rs b/winit/src/window/state.rs index c345a846..6adc2205 100644 --- a/winit/src/window/state.rs +++ b/winit/src/window/state.rs @@ -21,6 +21,7 @@ where cursor_position: Option>, modifiers: winit::keyboard::ModifiersState, theme: P::Theme, + theme_mode: theme::Mode, style: theme::Style, } @@ -52,7 +53,14 @@ where ) -> Self { let title = program.title(window_id); let scale_factor = program.scale_factor(window_id); - let theme = program.theme(window_id); + let theme_mode = match window.theme() { + None => theme::Mode::None, + Some(winit::window::Theme::Light) => theme::Mode::Light, + Some(winit::window::Theme::Dark) => theme::Mode::Dark, + }; + let theme = program + .theme(window_id) + .unwrap_or_else(|| ::default(theme_mode)); let style = program.style(&theme); let viewport = { @@ -72,6 +80,7 @@ where cursor_position: None, modifiers: winit::keyboard::ModifiersState::default(), theme, + theme_mode, style, } } @@ -216,7 +225,9 @@ where } // Update theme and appearance - self.theme = program.theme(window_id); + self.theme = program.theme(window_id).unwrap_or_else(|| { + ::default(self.theme_mode) + }); self.style = program.style(&self.theme); } }