From 214b8002003b8caf2d501e9ff4a49999f14fab51 Mon Sep 17 00:00:00 2001 From: Anthony Ronning <101225832+AnthonyRonning@users.noreply.github.com> Date: Wed, 11 Nov 2026 12:12:52 -0800 Subject: [PATCH 01/19] Agent: move gpui to Zed c7bea343 Moves gpui and gpui_platform from Zed cc053a4a (Aug 7) to c7bea343 (Nov 4), about 230 upstream commits to the gpui crates. The element, style, list and accessibility APIs Maple builds on are unchanged; the changes here are what the new revision requires. - Keystrokes name their host: parse_with_os, unparse(os) and display(os), through a new keymap::host_os(). Keystroke::parse now rejects the secondary- alias the shortcut catalog uses. - KeyBinding::load takes the app instead of a keyboard mapper, so build_binding and shortcuts::prepare take cx. On Windows, bindings now pass through the platform keyboard mapper. - window.blur(cx); on_scroll_wheel and ScrollWheelEvent became on_scroll and ScrollEvent; expect_restart reports arguments too. - gpui's stack growth under deep element trees is now the opt-in `stacker` feature; keep it on. uuid's v7 feature is now ours to enable. - gpui reports hover when content moves under a still pointer and drops it on a key press. A menu row keeps its highlight across a key press, and the sidebar test asserts hover is never stale instead of always clear. - gpui wraps text by the Unicode line breaking rules. Markdown tables measure unbreakable runs with the same icu_segmenter call instead of a copy of the old word-character table. Lockfile: 45 new registry versions, each published at least seven days ago (crates.io created_at, checked Nov 11), pinned to the versions in Zed's own lockfile where the two differed. New git sources, all chosen by Zed's workspace: gfx-rs/wgpu cddb2f5d (wgpu 30), zed-industries/oo7 731c1215 (was crates.io 0.6.0) and zed-industries/scap b5c86ec5. taffy moves from 0.12.2 to 0.15.0. Co-Authored-By: Claude --- apps/maple-agent/Cargo.lock | 1483 ++++++----------- apps/maple-agent/app/Cargo.toml | 21 +- .../app/src/desktop/maintenance_tests.rs | 5 +- apps/maple-agent/app/src/keymap.rs | 38 +- apps/maple-agent/app/src/shortcuts.rs | 67 +- apps/maple-agent/app/src/ui/chat/mod.rs | 8 +- apps/maple-agent/app/src/ui/chat/sending.rs | 2 +- apps/maple-agent/app/src/ui/chat/sidebar.rs | 15 +- apps/maple-agent/app/src/ui/chat/tests.rs | 20 +- .../maple-agent/app/src/ui/chat/transcript.rs | 6 +- apps/maple-agent/app/src/ui/markdown/table.rs | 115 +- apps/maple-agent/app/src/ui/popup.rs | 9 +- apps/maple-agent/app/src/ui/settings.rs | 9 +- .../app/src/ui/settings/navigation.rs | 2 +- apps/maple-agent/app/src/ui/text_input.rs | 6 +- 15 files changed, 728 insertions(+), 1078 deletions(-) diff --git a/apps/maple-agent/Cargo.lock b/apps/maple-agent/Cargo.lock index 86788a6f4..2df1207b0 100644 --- a/apps/maple-agent/Cargo.lock +++ b/apps/maple-agent/Cargo.lock @@ -14,38 +14,18 @@ dependencies = [ [[package]] name = "accesskit_atspi_common" -version = "0.18.1" +version = "0.19.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e8c61bee90b42a772d39d06a740207dc71a4e780004ace1db8d99fb1baaa954" +checksum = "023da0e5097f46df7092d5280b02efb9bbf8d93298daeced42652463e357d636" dependencies = [ "accesskit", - "accesskit_consumer 0.36.0", + "accesskit_consumer", "atspi-common 0.13.0", "phf 0.13.1", "serde", "zvariant", ] -[[package]] -name = "accesskit_consumer" -version = "0.36.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25e0d7e25d06f4dc21d1774d67146e9e80d6789216cbd4d1e88185b0095dba60" -dependencies = [ - "accesskit", - "hashbrown 0.16.1", -] - -[[package]] -name = "accesskit_consumer" -version = "0.37.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f950720ce064757a1b629caad3a408e8d2c63bb01f29b8a3ff8daa331053ffeb" -dependencies = [ - "accesskit", - "hashbrown 0.16.1", -] - [[package]] name = "accesskit_consumer" version = "0.38.0" @@ -63,7 +43,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ce02dc63b43f0c9296af9ac946312a2dc8814427d7a64d2d600971dac55b6076" dependencies = [ "accesskit", - "accesskit_consumer 0.38.0", + "accesskit_consumer", "hashbrown 0.16.1", "objc2 0.5.2", "objc2-app-kit 0.2.2", @@ -72,9 +52,9 @@ dependencies = [ [[package]] name = "accesskit_unix" -version = "0.21.1" +version = "0.22.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b016ca8db0ea0ea2ceff29a9d6240391492d960716aa471967c00e8cc8cb197c" +checksum = "03e156ed3802e35eefe894ef2671bc6c889303d8a7e110b5e1b48f504b91362f" dependencies = [ "accesskit", "accesskit_atspi_common", @@ -90,12 +70,12 @@ dependencies = [ [[package]] name = "accesskit_windows" -version = "0.33.1" +version = "0.34.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "36e93ac7bf50b964f1cbb75f741629a4e950571baa1ef1274457ab5a80d9bcc2" +checksum = "106c2b961215864d1c2e703ee63269c25c4e80a577ffb2c1017b9c17dcdf83a1" dependencies = [ "accesskit", - "accesskit_consumer 0.37.0", + "accesskit_consumer", "hashbrown 0.16.1", "static_assertions", "windows 0.62.2", @@ -188,7 +168,7 @@ dependencies = [ "futures", "futures-concurrency", "rustc-hash 2.1.3", - "rustix 1.1.6", + "rustix", "schemars 1.2.2", "serde", "serde_json", @@ -220,7 +200,7 @@ dependencies = [ "serde", "serde_json", "serde_with", - "strum 0.28.0", + "strum", "tracing", ] @@ -266,6 +246,15 @@ dependencies = [ "equator", ] +[[package]] +name = "alloca" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e5a7d05ea6aea7e9e64d25b9156ba2fee3fdd659e34e41063cd2fc7cd020d7f4" +dependencies = [ + "cc", +] + [[package]] name = "allocator-api2" version = "0.2.21" @@ -303,6 +292,12 @@ dependencies = [ "libc", ] +[[package]] +name = "anes" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4b46cbb362ab8752921c97e041f5e366ee6297bd428a31275b9fcf1e380f7299" + [[package]] name = "anstream" version = "1.0.0" @@ -339,7 +334,7 @@ version = "1.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "40c48f72fd53cd289104fc64099abca73db4166ad86ea0b4341abe65af83dadc" dependencies = [ - "windows-sys 0.60.2", + "windows-sys 0.61.2", ] [[package]] @@ -350,7 +345,7 @@ checksum = "291e6a250ff86cd4a820112fb8898808a366d8f9f58ce16d1f538353ad55747d" dependencies = [ "anstyle", "once_cell_polyfill", - "windows-sys 0.60.2", + "windows-sys 0.61.2", ] [[package]] @@ -610,18 +605,6 @@ dependencies = [ "tokio", ] -[[package]] -name = "async-compression" -version = "0.4.43" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3976abdc8fe7d1133d43d304afd42abdf5bc3e1319d263d223bde07b5efc4be8" -dependencies = [ - "compression-codecs", - "compression-core", - "futures-io", - "pin-project-lite", -] - [[package]] name = "async-executor" version = "1.14.1" @@ -660,7 +643,7 @@ dependencies = [ "futures-lite", "parking", "polling", - "rustix 1.1.6", + "rustix", "slab", "windows-sys 0.61.2", ] @@ -702,7 +685,7 @@ dependencies = [ "cfg-if", "event-listener", "futures-lite", - "rustix 1.1.6", + "rustix", ] [[package]] @@ -728,7 +711,7 @@ dependencies = [ "cfg-if", "futures-core", "futures-io", - "rustix 1.1.6", + "rustix", "signal-hook-registry", "slab", "windows-sys 0.61.2", @@ -1088,23 +1071,14 @@ dependencies = [ ] [[package]] -name = "bindgen" -version = "0.71.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f58bf3d7db68cfbac37cfc485a8d711e87e064c3d0fe0435b92f7a407f9d6b3" +name = "bench_metrics" +version = "0.1.0" +source = "git+https://github.com/zed-industries/zed?rev=c7bea343838f42b4c14151393e41f0bbe033c95e#c7bea343838f42b4c14151393e41f0bbe033c95e" dependencies = [ - "bitflags 2.13.1", - "cexpr", - "clang-sys", - "itertools 0.13.0", - "log", - "prettyplease", - "proc-macro2", - "quote", - "regex", - "rustc-hash 2.1.3", - "shlex 1.3.0", - "syn 2.0.119", + "anyhow", + "criterion", + "libc", + "perf-event2", ] [[package]] @@ -1118,11 +1092,11 @@ dependencies = [ [[package]] name = "bit-set" -version = "0.9.1" +version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34ddef2995421ab6a5c779542c81ee77c115206f4ad9d5a8e05f4ff49716a3dd" +checksum = "56d87354e4229f54a44f7bf2435906a4656dba36026ab6eaca629a2c436a691c" dependencies = [ - "bit-vec 0.9.1", + "bit-vec 0.10.1", ] [[package]] @@ -1133,9 +1107,13 @@ checksum = "5e764a1d40d510daf35e07be9eb06e75770908c27d411ee6c92109c9840eaaf7" [[package]] name = "bit-vec" -version = "0.9.1" +version = "0.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b71798fca2c1fe1086445a7258a4bc81e6e49dcd24c8d0dd9a1e57395b603f51" +checksum = "5727b15fa97d4f4fee0a3b7c3d550ed0269f54329207b86388de918604e31269" +dependencies = [ + "borsh", + "serde", +] [[package]] name = "bit_field" @@ -1207,12 +1185,6 @@ dependencies = [ "cpufeatures 0.3.0", ] -[[package]] -name = "block" -version = "0.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0d8c1fef690941d3e7788d328517591fecc684c084084702d6ff1641e993699a" - [[package]] name = "block-buffer" version = "0.10.4" @@ -1292,10 +1264,24 @@ version = "1.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "553c5d846a6ba5150c65e3b1b8ec073bcf1abc20f9b7220de384a4443ea4e20a" dependencies = [ + "borsh-derive", "bytes", "cfg_aliases", ] +[[package]] +name = "borsh-derive" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12cdfe656708a01f89b451a7d36466e6fe6c414de0aa18fc54f864f6f9ca9f56" +dependencies = [ + "once_cell", + "proc-macro-crate", + "proc-macro2", + "quote", + "syn 3.0.4", +] + [[package]] name = "bs58" version = "0.5.1" @@ -1372,13 +1358,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fc652a48c352aef3ea3aed32080501cf3ef6ed5da78602a020c991775b0aff04" [[package]] -name = "bzip2" -version = "0.6.1" +name = "c-enum" +version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f3a53fac24f34a81bc9954b5d6cfce0c21e18ec6959f44f56e8e90e4bb7c346c" -dependencies = [ - "libbz2-rs-sys", -] +checksum = "cd17eb909a8c6a894926bfcc3400a4bb0e732f5a57d37b1f14e8b29e329bace8" [[package]] name = "calloop" @@ -1388,7 +1371,7 @@ checksum = "4dbf9978365bac10f54d1d4b04f7ce4427e51f71d61f2fe15e3fed5166474df7" dependencies = [ "bitflags 2.13.1", "polling", - "rustix 1.1.6", + "rustix", "slab", "tracing", ] @@ -1400,7 +1383,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "138efcf0940a02ebf0cc8d1eff41a1682a46b431630f4c52450d6265876021fa" dependencies = [ "calloop", - "rustix 1.1.6", + "rustix", "wayland-backend", "wayland-client", ] @@ -1437,6 +1420,12 @@ dependencies = [ "thiserror 2.0.20", ] +[[package]] +name = "cast" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "37b2a672a2cb129a2e41c10b1224bb368f9f37a2b16b612598138befd7b37eb5" + [[package]] name = "cbc" version = "0.1.2" @@ -1482,7 +1471,7 @@ dependencies = [ "find-msvc-tools", "jobserver", "libc", - "shlex 2.0.1", + "shlex", ] [[package]] @@ -1491,15 +1480,6 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6d43a04d8753f35258c91f8ec639f792891f748a1edbd759cf1dcea3382ad83c" -[[package]] -name = "cexpr" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6fac387a98bb7c37292057cffc56d62ecb629900026402633ae9160df93a8766" -dependencies = [ - "nom 7.1.3", -] - [[package]] name = "cfg-if" version = "1.0.4" @@ -1512,15 +1492,6 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f079e83a288787bcd14a6aea84cee5c87a67c5a3e660c30f557a3d24761b3527" -[[package]] -name = "cgl" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ced0551234e87afee12411d535648dd89d2e7f34c78b753395567aff3d447ff" -dependencies = [ - "libc", -] - [[package]] name = "chacha20" version = "0.9.1" @@ -1644,17 +1615,6 @@ dependencies = [ "inout 0.2.2", ] -[[package]] -name = "clang-sys" -version = "1.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "157a8ba7b480713b56f4c09fd13fc3e0a22a5dfab8097ba61cbc5feef950788a" -dependencies = [ - "glob", - "libc", - "libloading", -] - [[package]] name = "clap" version = "4.6.6" @@ -1746,66 +1706,6 @@ dependencies = [ "thiserror 2.0.20", ] -[[package]] -name = "cocoa" -version = "0.25.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6140449f97a6e97f9511815c5632d84c8aacf8ac271ad77c559218161a1373c" -dependencies = [ - "bitflags 1.3.2", - "block", - "cocoa-foundation 0.1.2", - "core-foundation 0.9.4", - "core-graphics 0.23.2", - "foreign-types 0.5.0", - "libc", - "objc", -] - -[[package]] -name = "cocoa" -version = "0.26.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f79398230a6e2c08f5c9760610eb6924b52aa9e7950a619602baba59dcbbdbb2" -dependencies = [ - "bitflags 2.13.1", - "block", - "cocoa-foundation 0.2.0", - "core-foundation 0.10.0", - "core-graphics 0.24.0", - "foreign-types 0.5.0", - "libc", - "objc", -] - -[[package]] -name = "cocoa-foundation" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c6234cbb2e4c785b456c0644748b1ac416dd045799740356f8363dfe00c93f7" -dependencies = [ - "bitflags 1.3.2", - "block", - "core-foundation 0.9.4", - "core-graphics-types 0.1.3", - "libc", - "objc", -] - -[[package]] -name = "cocoa-foundation" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e14045fb83be07b5acf1c0884b2180461635b433455fa35d1cd6f17f1450679d" -dependencies = [ - "bitflags 2.13.1", - "block", - "core-foundation 0.10.0", - "core-graphics-types 0.2.0", - "libc", - "objc", -] - [[package]] name = "codespan-reporting" version = "0.13.1" @@ -1820,7 +1720,7 @@ dependencies = [ [[package]] name = "collections" version = "0.1.0" -source = "git+https://github.com/zed-industries/zed?rev=cc053a4a6fa2fd0e8793201ed9099466af1be0b1#cc053a4a6fa2fd0e8793201ed9099466af1be0b1" +source = "git+https://github.com/zed-industries/zed?rev=c7bea343838f42b4c14151393e41f0bbe033c95e#c7bea343838f42b4c14151393e41f0bbe033c95e" dependencies = [ "gpui_util", "indexmap 2.14.0", @@ -1849,24 +1749,6 @@ dependencies = [ "memchr", ] -[[package]] -name = "compression-codecs" -version = "0.4.38" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce2548391e9c1929c21bf6aa2680af86fe4c1b33e6cea9ac1cfeec0bd11218cf" -dependencies = [ - "bzip2", - "compression-core", - "flate2", - "memchr", -] - -[[package]] -name = "compression-core" -version = "0.4.32" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cc14f565cf027a105f7a44ccf9e5b424348421a1d8952a8fc9d499d313107789" - [[package]] name = "concurrent-queue" version = "2.5.0" @@ -1978,19 +1860,6 @@ version = "0.8.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" -[[package]] -name = "core-graphics" -version = "0.23.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c07782be35f9e1140080c6b96f0d44b739e2278479f64e02fdab4e32dfd8b081" -dependencies = [ - "bitflags 1.3.2", - "core-foundation 0.9.4", - "core-graphics-types 0.1.3", - "foreign-types 0.5.0", - "libc", -] - [[package]] name = "core-graphics" version = "0.24.0" @@ -1999,35 +1868,11 @@ checksum = "fa95a34622365fa5bbf40b20b75dba8dfa8c94c734aea8ac9a5ca38af14316f1" dependencies = [ "bitflags 2.13.1", "core-foundation 0.10.0", - "core-graphics-types 0.2.0", - "foreign-types 0.5.0", - "libc", -] - -[[package]] -name = "core-graphics-helmer-fork" -version = "0.24.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32eb7c354ae9f6d437a6039099ce7ecd049337a8109b23d73e48e8ffba8e9cd5" -dependencies = [ - "bitflags 2.13.1", - "core-foundation 0.9.4", - "core-graphics-types 0.1.3", + "core-graphics-types", "foreign-types 0.5.0", "libc", ] -[[package]] -name = "core-graphics-types" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "45390e6114f68f718cc7a830514a96f903cccd70d02a8f6d9f643ac4ba45afaf" -dependencies = [ - "bitflags 1.3.2", - "core-foundation 0.9.4", - "libc", -] - [[package]] name = "core-graphics-types" version = "0.2.0" @@ -2039,19 +1884,6 @@ dependencies = [ "libc", ] -[[package]] -name = "core-graphics2" -version = "0.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4416167a69126e617f8d0a214af0e3c1dbdeffcb100ddf72dcd1a1ac9893c146" -dependencies = [ - "bitflags 2.13.1", - "block", - "cfg-if", - "core-foundation 0.10.0", - "libc", -] - [[package]] name = "core-text" version = "21.0.0" @@ -2059,24 +1891,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a593227b66cbd4007b2a050dfdd9e1d1318311409c8d600dc82ba1b15ca9c130" dependencies = [ "core-foundation 0.10.0", - "core-graphics 0.24.0", + "core-graphics", "foreign-types 0.5.0", "libc", ] [[package]] -name = "core-video" -version = "0.5.2" +name = "core_detect" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "139679cc63eb9504bdbe37e37874b0247136177655f0008588781e90863afa62" -dependencies = [ - "block", - "core-foundation 0.10.0", - "core-graphics2", - "io-surface", - "libc", - "metal", -] +checksum = "7f8f80099a98041a3d1622845c271458a2d73e688351bf3cb999266764b81d48" [[package]] name = "core_maths" @@ -2147,7 +1971,7 @@ dependencies = [ "jni 0.21.1", "js-sys", "libc", - "mach2", + "mach2 0.5.0", "ndk", "ndk-context", "num-derive", @@ -2198,6 +2022,41 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "criterion" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "950046b2aa2492f9a536f5f4f9a3de7b9e2476e575e05bd6c333371add4d98f3" +dependencies = [ + "alloca", + "anes", + "cast", + "ciborium", + "clap", + "criterion-plot", + "itertools 0.13.0", + "num-traits", + "oorandom", + "page_size", + "plotters", + "rayon", + "regex", + "serde", + "serde_json", + "tinytemplate", + "walkdir", +] + +[[package]] +name = "criterion-plot" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d8d80a2f4f5b554395e47b5d8305bc3d27813bacb73493eb1001e8f76dae29ea" +dependencies = [ + "cast", + "itertools 0.13.0", +] + [[package]] name = "critical-section" version = "1.2.0" @@ -2707,7 +2566,7 @@ dependencies = [ [[package]] name = "derive_refineable" version = "0.1.0" -source = "git+https://github.com/zed-industries/zed?rev=cc053a4a6fa2fd0e8793201ed9099466af1be0b1#cc053a4a6fa2fd0e8793201ed9099466af1be0b1" +source = "git+https://github.com/zed-industries/zed?rev=c7bea343838f42b4c14151393e41f0bbe033c95e#c7bea343838f42b4c14151393e41f0bbe033c95e" dependencies = [ "proc-macro2", "quote", @@ -2782,15 +2641,9 @@ dependencies = [ "libc", "option-ext", "redox_users 0.5.2", - "windows-sys 0.59.0", + "windows-sys 0.61.2", ] -[[package]] -name = "dispatch" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd0c93bb4b0c6d9b77f4435b0ae98c24d17f1c45b2ff844c6151a07256ca923b" - [[package]] name = "dispatch2" version = "0.3.1" @@ -3129,17 +2982,6 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f" -[[package]] -name = "erased-serde" -version = "0.4.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d2add8a07dd6a8d93ff627029c51de145e12686fbc36ecb298ac22e74cf02dec" -dependencies = [ - "serde", - "serde_core", - "typeid", -] - [[package]] name = "errno" version = "0.3.14" @@ -3147,7 +2989,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb" dependencies = [ "libc", - "windows-sys 0.52.0", + "windows-sys 0.61.2", ] [[package]] @@ -3281,9 +3123,6 @@ name = "fastrand" version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "da7c62ceae207dd37ea5b845da6a0696c799f85e97da1ab5b7910be3c1c80223" -dependencies = [ - "getrandom 0.4.3", -] [[package]] name = "fax" @@ -3465,7 +3304,6 @@ version = "0.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5e139bc46ca777eb5efaf62df0ab8cc5fd400866427e56c68b22e414e53bd3be" dependencies = [ - "fastrand", "futures-core", "futures-sink", "spin 0.9.9", @@ -3799,7 +3637,7 @@ dependencies = [ "libc", "log", "rustversion", - "windows-link 0.1.3", + "windows-link 0.2.1", "windows-result 0.4.1", ] @@ -3819,7 +3657,7 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1bd49230192a3797a9a4d6abe9b3eed6f7fa4c8a8a4947977c6f80025f92cbd8" dependencies = [ - "rustix 1.1.6", + "rustix", "windows-link 0.2.1", ] @@ -3934,9 +3772,9 @@ dependencies = [ [[package]] name = "glow" -version = "0.17.0" +version = "0.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "29038e1c483364cc6bb3cf78feee1816002e127c331a1eec55a4d202b9e1adb5" +checksum = "263218b0ba2b0715c3370fb04674f5f8aa331594b521c94ff0a8e4a8472d1386" dependencies = [ "js-sys", "slotmap", @@ -3978,54 +3816,23 @@ dependencies = [ "windows 0.62.2", ] -[[package]] -name = "gpu-descriptor" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b89c83349105e3732062a895becfc71a8f921bb71ecbbdd8ff99263e3b53a0ca" -dependencies = [ - "bitflags 2.13.1", - "gpu-descriptor-types", - "hashbrown 0.15.5", -] - -[[package]] -name = "gpu-descriptor-types" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fdf242682df893b86f33a73828fb09ca4b2d3bb6cc95249707fc684d27484b91" -dependencies = [ - "bitflags 2.13.1", -] - [[package]] name = "gpui" version = "0.2.2" -source = "git+https://github.com/zed-industries/zed?rev=cc053a4a6fa2fd0e8793201ed9099466af1be0b1#cc053a4a6fa2fd0e8793201ed9099466af1be0b1" +source = "git+https://github.com/zed-industries/zed?rev=c7bea343838f42b4c14151393e41f0bbe033c95e#c7bea343838f42b4c14151393e41f0bbe033c95e" dependencies = [ "accesskit", "anyhow", "async-channel", "async-task", "backtrace", - "bindgen", + "bench_metrics", "bitflags 2.13.1", - "block", - "cbindgen", "chrono", - "cocoa 0.26.0", - "cocoa-foundation 0.2.0", "collections", - "core-foundation 0.10.0", - "core-foundation-sys", - "core-graphics 0.24.0", - "core-text", - "core-video", - "ctor", "derive_more", "embed-resource", "etagere", - "foreign-types 0.5.0", "futures", "futures-concurrency", "getrandom 0.3.4", @@ -4034,19 +3841,18 @@ dependencies = [ "gpui_util", "heapless 0.9.3", "http_client", + "icu_segmenter", "image", "inventory", "itertools 0.14.0", + "libc", "log", "lyon", - "mach2", - "media", - "metal", "num_cpus", - "objc", + "objc2-core-foundation", + "objc2-core-video", "parking", "parking_lot", - "pathfinder_geometry", "pin-project", "pollster 0.4.0", "postage", @@ -4066,35 +3872,91 @@ dependencies = [ "smallvec", "spin 0.10.1", "stacksafe", - "strum 0.27.2", + "strum", "sum_tree", "taffy", "thiserror 2.0.20", - "tracing", "ttf-parser", + "unicode-segmentation", "url", "usvg", - "util_macros", "uuid", "waker-fn", "web-time", - "windows 0.61.3", - "zed-font-kit", + "windows 0.62.2", "zed-scap", - "ztracing", +] + +[[package]] +name = "gpui_apple" +version = "0.1.0" +source = "git+https://github.com/zed-industries/zed?rev=c7bea343838f42b4c14151393e41f0bbe033c95e#c7bea343838f42b4c14151393e41f0bbe033c95e" +dependencies = [ + "anyhow", + "async-task", + "block2 0.6.2", + "cbindgen", + "collections", + "core-foundation 0.10.0", + "core-foundation-sys", + "core-graphics", + "core-text", + "dispatch2", + "etagere", + "futures", + "gpui", + "gpui_util", + "image", + "libc", + "log", + "mach2 0.6.0", + "objc2 0.6.4", + "objc2-core-foundation", + "objc2-core-graphics", + "objc2-core-text", + "objc2-core-video", + "objc2-foundation 0.3.2", + "objc2-metal 0.3.2", + "objc2-quartz-core 0.3.2", + "objc2-security", + "parking_lot", + "pathfinder_geometry", + "smallvec", + "thiserror 2.0.20", + "zed-font-kit", +] + +[[package]] +name = "gpui_ios" +version = "0.1.0" +source = "git+https://github.com/zed-industries/zed?rev=c7bea343838f42b4c14151393e41f0bbe033c95e#c7bea343838f42b4c14151393e41f0bbe033c95e" +dependencies = [ + "anyhow", + "block2 0.6.2", + "futures", + "gpui", + "gpui_apple", + "log", + "objc2 0.6.4", + "objc2-core-foundation", + "objc2-foundation 0.3.2", + "objc2-quartz-core 0.3.2", + "objc2-ui-kit", + "parking_lot", + "raw-window-handle", + "uuid", ] [[package]] name = "gpui_linux" version = "0.1.0" -source = "git+https://github.com/zed-industries/zed?rev=cc053a4a6fa2fd0e8793201ed9099466af1be0b1#cc053a4a6fa2fd0e8793201ed9099466af1be0b1" +source = "git+https://github.com/zed-industries/zed?rev=c7bea343838f42b4c14151393e41f0bbe033c95e#c7bea343838f42b4c14151393e41f0bbe033c95e" dependencies = [ "accesskit", "accesskit_unix", "anyhow", "as-raw-xcb-connection", "ashpd", - "bitflags 2.13.1", "bytemuck", "calloop", "calloop-wayland-source", @@ -4105,22 +3967,16 @@ dependencies = [ "gpui_util", "gpui_wgpu", "http_client", - "image", - "itertools 0.14.0", "libc", "log", "notify-rust", "oo7", "open", "parking_lot", - "pathfinder_geometry", - "pollster 0.4.0", - "profiling", "raw-window-handle", "smallvec", "smol", - "strum 0.27.2", - "swash", + "strum", "url", "uuid", "wayland-backend", @@ -4129,7 +3985,6 @@ dependencies = [ "wayland-protocols", "wayland-protocols-plasma", "wayland-protocols-wlr", - "x11-clipboard", "x11rb", "xkbcommon 0.8.0", "zed-scap", @@ -4139,56 +3994,47 @@ dependencies = [ [[package]] name = "gpui_macos" version = "0.1.0" -source = "git+https://github.com/zed-industries/zed?rev=cc053a4a6fa2fd0e8793201ed9099466af1be0b1#cc053a4a6fa2fd0e8793201ed9099466af1be0b1" +source = "git+https://github.com/zed-industries/zed?rev=c7bea343838f42b4c14151393e41f0bbe033c95e#c7bea343838f42b4c14151393e41f0bbe033c95e" dependencies = [ "accesskit", "accesskit_macos", "anyhow", - "async-task", - "block", "block2 0.6.2", - "cbindgen", - "cocoa 0.26.0", "collections", "core-foundation 0.10.0", "core-foundation-sys", - "core-graphics 0.24.0", - "core-text", - "core-video", + "core-graphics", "ctor", - "derive_more", "dispatch2", - "etagere", "foreign-types 0.5.0", "futures", "gpui", + "gpui_apple", "gpui_util", "image", "itertools 0.14.0", - "libc", "log", - "mach2", - "media", - "metal", - "objc", "objc2 0.6.4", "objc2-app-kit 0.3.2", + "objc2-core-graphics", + "objc2-core-video", "objc2-foundation 0.3.2", + "objc2-quartz-core 0.3.2", + "objc2-uniform-type-identifiers", "objc2-user-notifications", "parking_lot", - "pathfinder_geometry", "raw-window-handle", + "scheduler", "semver", "smallvec", - "strum 0.27.2", + "strum", "uuid", - "zed-font-kit", ] [[package]] name = "gpui_macros" version = "0.1.0" -source = "git+https://github.com/zed-industries/zed?rev=cc053a4a6fa2fd0e8793201ed9099466af1be0b1#cc053a4a6fa2fd0e8793201ed9099466af1be0b1" +source = "git+https://github.com/zed-industries/zed?rev=c7bea343838f42b4c14151393e41f0bbe033c95e#c7bea343838f42b4c14151393e41f0bbe033c95e" dependencies = [ "heck 0.5.0", "proc-macro2", @@ -4199,10 +4045,12 @@ dependencies = [ [[package]] name = "gpui_platform" version = "0.1.0" -source = "git+https://github.com/zed-industries/zed?rev=cc053a4a6fa2fd0e8793201ed9099466af1be0b1#cc053a4a6fa2fd0e8793201ed9099466af1be0b1" +source = "git+https://github.com/zed-industries/zed?rev=c7bea343838f42b4c14151393e41f0bbe033c95e#c7bea343838f42b4c14151393e41f0bbe033c95e" dependencies = [ + "anyhow", "console_error_panic_hook", "gpui", + "gpui_ios", "gpui_linux", "gpui_macos", "gpui_web", @@ -4212,7 +4060,7 @@ dependencies = [ [[package]] name = "gpui_shared_string" version = "0.1.0" -source = "git+https://github.com/zed-industries/zed?rev=cc053a4a6fa2fd0e8793201ed9099466af1be0b1#cc053a4a6fa2fd0e8793201ed9099466af1be0b1" +source = "git+https://github.com/zed-industries/zed?rev=c7bea343838f42b4c14151393e41f0bbe033c95e#c7bea343838f42b4c14151393e41f0bbe033c95e" dependencies = [ "schemars 1.2.2", "serde", @@ -4222,7 +4070,7 @@ dependencies = [ [[package]] name = "gpui_util" version = "0.1.0" -source = "git+https://github.com/zed-industries/zed?rev=cc053a4a6fa2fd0e8793201ed9099466af1be0b1#cc053a4a6fa2fd0e8793201ed9099466af1be0b1" +source = "git+https://github.com/zed-industries/zed?rev=c7bea343838f42b4c14151393e41f0bbe033c95e#c7bea343838f42b4c14151393e41f0bbe033c95e" dependencies = [ "anyhow", "log", @@ -4232,9 +4080,10 @@ dependencies = [ [[package]] name = "gpui_web" version = "0.1.0" -source = "git+https://github.com/zed-industries/zed?rev=cc053a4a6fa2fd0e8793201ed9099466af1be0b1#cc053a4a6fa2fd0e8793201ed9099466af1be0b1" +source = "git+https://github.com/zed-industries/zed?rev=c7bea343838f42b4c14151393e41f0bbe033c95e#c7bea343838f42b4c14151393e41f0bbe033c95e" dependencies = [ "anyhow", + "async-channel", "console_error_panic_hook", "futures", "gpui", @@ -4244,6 +4093,11 @@ dependencies = [ "log", "parking_lot", "raw-window-handle", + "scheduler", + "smallvec", + "unicode-properties", + "unicode-script", + "unicode-segmentation", "uuid", "wasm-bindgen", "wasm-bindgen-futures", @@ -4255,7 +4109,7 @@ dependencies = [ [[package]] name = "gpui_wgpu" version = "0.1.0" -source = "git+https://github.com/zed-industries/zed?rev=cc053a4a6fa2fd0e8793201ed9099466af1be0b1#cc053a4a6fa2fd0e8793201ed9099466af1be0b1" +source = "git+https://github.com/zed-industries/zed?rev=c7bea343838f42b4c14151393e41f0bbe033c95e#c7bea343838f42b4c14151393e41f0bbe033c95e" dependencies = [ "anyhow", "bytemuck", @@ -4265,18 +4119,14 @@ dependencies = [ "gpui", "gpui_util", "itertools 0.14.0", - "js-sys", "log", "parking_lot", - "pollster 0.4.0", "profiling", "raw-window-handle", "smallvec", "swash", "unicode-bidi", "unicode-segmentation", - "wasm-bindgen", - "wasm-bindgen-futures", "web-sys", "wgpu", "zed-font-kit", @@ -4285,7 +4135,7 @@ dependencies = [ [[package]] name = "gpui_windows" version = "0.1.0" -source = "git+https://github.com/zed-industries/zed?rev=cc053a4a6fa2fd0e8793201ed9099466af1be0b1#cc053a4a6fa2fd0e8793201ed9099466af1be0b1" +source = "git+https://github.com/zed-industries/zed?rev=c7bea343838f42b4c14151393e41f0bbe033c95e#c7bea343838f42b4c14151393e41f0bbe033c95e" dependencies = [ "accesskit", "accesskit_windows", @@ -4302,20 +4152,15 @@ dependencies = [ "parking_lot", "rand 0.9.5", "raw-window-handle", + "scheduler", "smallvec", "uuid", - "windows 0.61.3", - "windows-core 0.61.2", - "windows-numerics 0.2.0", - "windows-registry 0.5.3", + "windows 0.62.2", + "windows-core 0.62.2", + "windows-numerics 0.3.1", + "windows-registry", ] -[[package]] -name = "grid" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b40ca9252762c466af32d0b1002e91e4e1bc5398f77455e55474deb466355ff5" - [[package]] name = "group" version = "0.14.0" @@ -4489,12 +4334,6 @@ version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" -[[package]] -name = "hexf-parse" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dfa686283ad6dd069f105e5ab091b04c62850d3e4cf5d67debad1933f55023df" - [[package]] name = "hkdf" version = "0.12.4" @@ -4537,15 +4376,6 @@ version = "1.1.13" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "66de62217b456dfbbba2bed965a134a4df57c48f0eac4c772018aee528e72244" -[[package]] -name = "home" -version = "0.5.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cc627f471c528ff0c4a49e1d5e60450c8f6461dd6d10ba9dcd3a61d3dff7728d" -dependencies = [ - "windows-sys 0.61.2", -] - [[package]] name = "hostname" version = "0.4.2" @@ -4593,12 +4423,10 @@ dependencies = [ [[package]] name = "http_client" version = "0.1.0" -source = "git+https://github.com/zed-industries/zed?rev=cc053a4a6fa2fd0e8793201ed9099466af1be0b1#cc053a4a6fa2fd0e8793201ed9099466af1be0b1" +source = "git+https://github.com/zed-industries/zed?rev=c7bea343838f42b4c14151393e41f0bbe033c95e#c7bea343838f42b4c14151393e41f0bbe033c95e" dependencies = [ "anyhow", - "async-compression", "bytes", - "derive_more", "futures", "http", "http-body", @@ -4693,7 +4521,7 @@ dependencies = [ "tokio", "tower-service", "tracing", - "windows-registry 0.6.1", + "windows-registry", ] [[package]] @@ -4722,12 +4550,13 @@ dependencies = [ [[package]] name = "icu_collections" -version = "2.1.1" +version = "2.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c6b649701667bbe825c3b7e6388cb521c23d88644678e83c0c4d0a621a34b43" +checksum = "fa68d21081c4a05d5a901a1c62add574c77048b6a1c67be3b50ce0b60d4ca513" dependencies = [ "displaydoc", "potential_utf", + "utf8_iter", "yoke", "zerofrom", "zerovec", @@ -4741,16 +4570,37 @@ checksum = "d56e28588da92eee5c3201a6eff33fabdd49b62269c8938d4ff050ce4d900deb" dependencies = [ "displaydoc", "litemap", + "serde", "tinystr", "writeable", "zerovec", ] +[[package]] +name = "icu_locale_fallback" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "251af8e57c9400e3eb58242fe5b8b1152b2a64fdf4cf632f923c38ccee6f2fa9" +dependencies = [ + "icu_locale_core", + "icu_locale_fallback_data", + "icu_provider", + "potential_utf", + "tinystr", + "zerovec", +] + +[[package]] +name = "icu_locale_fallback_data" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "decf2a22ec8fa68f1a0c1129a3f8583f8f8bc24e8b9ccbe98ead99f62a4dc3a8" + [[package]] name = "icu_normalizer" -version = "2.1.1" +version = "2.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f6c8828b67bf8908d82127b2054ea1b4427ff0230ee9141c54251934ab1b599" +checksum = "12f9cf5f235641ed274641dd81c3f28d870e276763d0797aeeab72317b1c646f" dependencies = [ "icu_collections", "icu_normalizer_data", @@ -4762,16 +4612,17 @@ dependencies = [ [[package]] name = "icu_normalizer_data" -version = "2.1.1" +version = "2.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7aedcccd01fc5fe81e6b489c15b247b8b0690feb23304303a9e560f37efc560a" +checksum = "1563da1ed3e0b3bf3d74c9b85917ac9c56464d2f57242270c09c9e752f8021a0" [[package]] name = "icu_properties" -version = "2.1.2" +version = "2.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "020bfc02fe870ec3a66d93e677ccca0562506e5872c650f893269e08615d74ec" +checksum = "7e7ca276ad3145661a65914e6daf131ca5120cd3dcee8f8f3214b8875184a148" dependencies = [ + "displaydoc", "icu_collections", "icu_locale_core", "icu_properties_data", @@ -4782,18 +4633,20 @@ dependencies = [ [[package]] name = "icu_properties_data" -version = "2.1.2" +version = "2.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "616c294cf8d725c6afcd8f55abc17c56464ef6211f9ed59cccffe534129c77af" +checksum = "e590f038c1464a96894fd6d10127e90a8be4509f56ff7ecef851b15cee0b7caa" [[package]] name = "icu_provider" -version = "2.3.1" +version = "2.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d27bbb9d3abbefac45d55f647c9de1d44aafcd1186eb91879afef17c396c3e73" +checksum = "92a7ed671a6aad807a8651a2e1782a6598fda9ce5185dd8158549e95a91c6428" dependencies = [ "displaydoc", "icu_locale_core", + "serde", + "stable_deref_trait", "writeable", "yoke", "zerofrom", @@ -4801,6 +4654,28 @@ dependencies = [ "zerovec", ] +[[package]] +name = "icu_segmenter" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "82d07aafccd67af15d02512a6adf5896fbc5ed00f2e99b471d2efa14016db3db" +dependencies = [ + "icu_collections", + "icu_locale_fallback", + "icu_provider", + "icu_segmenter_data", + "potential_utf", + "smallvec", + "utf8_iter", + "zerovec", +] + +[[package]] +name = "icu_segmenter_data" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae293c039020f9ec10710af98d29ce6aa2051486638b49c9a6409f3b4a9e98ad" + [[package]] name = "ident_case" version = "1.0.1" @@ -4997,18 +4872,6 @@ dependencies = [ "rustversion", ] -[[package]] -name = "io-surface" -version = "0.16.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "554b8c5d64ec09a3a520fe58e4d48a73e00ff32899cdcbe32a4877afd4968b8e" -dependencies = [ - "cgl", - "core-foundation 0.10.0", - "core-foundation-sys", - "leaky-cow", -] - [[package]] name = "ipconfig" version = "0.3.4" @@ -5017,7 +4880,7 @@ checksum = "4d40460c0ce33d6ce4b0630ad68ff63d6661961c48b6dba35e5a4d81cfb48222" dependencies = [ "socket2", "widestring", - "windows-registry 0.6.1", + "windows-registry", "windows-result 0.4.1", "windows-sys 0.61.2", ] @@ -5067,7 +4930,7 @@ dependencies = [ "rustls-pki-types", "serde", "smallvec", - "strum 0.28.0", + "strum", "time", "tokio", "tokio-stream", @@ -5113,7 +4976,7 @@ dependencies = [ "rand 0.10.2", "rustls", "simple-dns", - "strum 0.28.0", + "strum", "tokio", "tracing", "url", @@ -5179,7 +5042,7 @@ dependencies = [ "rustls-pki-types", "serde", "serde_bytes", - "strum 0.28.0", + "strum", "tokio", "tokio-rustls", "tokio-util", @@ -5437,7 +5300,7 @@ dependencies = [ "regex", "serde", "serde_json", - "strum 0.28.0", + "strum", "unicode-general-category", "uuid-simd", ] @@ -5580,33 +5443,12 @@ version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" -[[package]] -name = "leak" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd100e01f1154f2908dfa7d02219aeab25d0b9c7fa955164192e3245255a0c73" - -[[package]] -name = "leaky-cow" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "40a8225d44241fd324a8af2806ba635fc7c8a7e9a7de4d5cf3ef54e71f5926fc" -dependencies = [ - "leak", -] - [[package]] name = "lebe" version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7a79a3332a6609480d7d0c9eab957bca6b455b91bb84e66d19f5ff66294b85b8" -[[package]] -name = "libbz2-rs-sys" -version = "0.2.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34b357333733e8260735ba5894eb928c02ecc69c78715f01a8019e7fa7f2db4c" - [[package]] name = "libc" version = "0.2.189" @@ -5678,12 +5520,6 @@ version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7e57c38c1e860fd37c604281cdfb1dd2216977fd76a50f85ba2f388ef3219616" -[[package]] -name = "linux-raw-sys" -version = "0.4.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d26c52dbd32dccf2d10cac7725f8eae5296885fb5703b261f7d0a0739ec807ab" - [[package]] name = "linux-raw-sys" version = "0.12.1" @@ -5718,7 +5554,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f9f8bd3e56ce4dfc153cf470fffbfa98c7620958b312ca5c3a4b8d5181fd13c6" dependencies = [ "serde_core", - "value-bag", ] [[package]] @@ -5839,6 +5674,28 @@ dependencies = [ "libc", ] +[[package]] +name = "mach2" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dae608c151f68243f2b000364e1f7b186d9c29845f7d2d85bd31b9ad77ad552b" + +[[package]] +name = "macro_rules_attribute" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b3ae8f6d608c795738406608304d30a2dfbdc8e58e44f7ba43236da5208ded3c" +dependencies = [ + "macro_rules_attribute-proc_macro", + "pastey 0.2.3", +] + +[[package]] +name = "macro_rules_attribute-proc_macro" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc04a4c58212d57930a24bf47d3fa87485264a3a054e9c10e042eb373573ad3c" + [[package]] name = "malloc_buf" version = "0.0.6" @@ -5928,6 +5785,7 @@ dependencies = [ "hyper", "hyper-util", "iana-time-zone", + "icu_segmenter", "image", "iroh", "libc", @@ -6124,21 +5982,6 @@ dependencies = [ "digest 0.10.7", ] -[[package]] -name = "media" -version = "0.1.0" -source = "git+https://github.com/zed-industries/zed?rev=cc053a4a6fa2fd0e8793201ed9099466af1be0b1#cc053a4a6fa2fd0e8793201ed9099466af1be0b1" -dependencies = [ - "anyhow", - "bindgen", - "core-foundation 0.10.0", - "core-video", - "ctor", - "foreign-types 0.5.0", - "metal", - "objc", -] - [[package]] name = "memchr" version = "2.8.3" @@ -6172,21 +6015,6 @@ dependencies = [ "autocfg", ] -[[package]] -name = "metal" -version = "0.33.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c7047791b5bc903b8cd963014b355f71dc9864a9a0b727057676c1dcae5cbc15" -dependencies = [ - "bitflags 2.13.1", - "block", - "core-graphics-types 0.2.0", - "foreign-types 0.5.0", - "log", - "objc", - "paste", -] - [[package]] name = "meval" version = "0.2.0" @@ -6277,7 +6105,7 @@ dependencies = [ "objc2-foundation 0.3.2", "png 0.18.1", "thiserror 2.0.20", - "windows-sys 0.60.2", + "windows-sys 0.61.2", ] [[package]] @@ -6360,22 +6188,21 @@ dependencies = [ [[package]] name = "naga" -version = "29.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2bf919621e7975acb27d881bae2fb993e0d45c8e0446e85e6272971e00dc8df" +version = "30.0.0" +source = "git+https://github.com/gfx-rs/wgpu?rev=cddb2f5d80dc0009b2ef6767635140cacf90a007#cddb2f5d80dc0009b2ef6767635140cacf90a007" dependencies = [ "arrayvec", - "bit-set 0.9.1", + "bit-set 0.11.1", "bitflags 2.13.1", "cfg-if", "cfg_aliases", "codespan-reporting", "half", - "hashbrown 0.16.1", - "hexf-parse", + "hashbrown 0.17.1", "indexmap 2.14.0", "libm", "log", + "naga-types", "num-traits", "once_cell", "rustc-hash 1.1.0", @@ -6384,6 +6211,17 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "naga-types" +version = "30.0.0" +source = "git+https://github.com/gfx-rs/wgpu?rev=cddb2f5d80dc0009b2ef6767635140cacf90a007#cddb2f5d80dc0009b2ef6767635140cacf90a007" +dependencies = [ + "hashbrown 0.17.1", + "indexmap 2.14.0", + "rustc-hash 1.1.0", + "thiserror 2.0.20", +] + [[package]] name = "native-tls" version = "0.2.18" @@ -6787,7 +6625,7 @@ version = "0.50.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7957b9740744892f114936ab4a57b3f487491bbeafaf8083688b16841a4240e5" dependencies = [ - "windows-sys 0.59.0", + "windows-sys 0.61.2", ] [[package]] @@ -6962,18 +6800,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "915b1b472bc21c53464d6c8461c9d3af805ba1ef837e1cac254428f4a77177b1" dependencies = [ "malloc_buf", - "objc_exception", -] - -[[package]] -name = "objc-foundation" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1add1b659e36c9607c7aab864a76c7a4c2760cd0cd2e120f3fb8b952c7e22bf9" -dependencies = [ - "block", - "objc", - "objc_id", ] [[package]] @@ -7036,6 +6862,7 @@ dependencies = [ "objc2-core-video", "objc2-foundation 0.3.2", "objc2-quartz-core 0.3.2", + "objc2-uniform-type-identifiers", ] [[package]] @@ -7201,6 +7028,7 @@ dependencies = [ "objc2-core-foundation", "objc2-core-graphics", "objc2-io-surface", + "objc2-metal 0.3.2", ] [[package]] @@ -7279,6 +7107,7 @@ checksum = "a0125f776a10d00af4152d74616409f0d4a2053a6f57fa5b7d6aa2854ac04794" dependencies = [ "bitflags 2.13.1", "block2 0.6.2", + "dispatch2", "objc2 0.6.4", "objc2-foundation 0.3.2", ] @@ -7305,6 +7134,7 @@ dependencies = [ "bitflags 2.13.1", "objc2 0.6.4", "objc2-core-foundation", + "objc2-core-graphics", "objc2-foundation 0.3.2", "objc2-metal 0.3.2", ] @@ -7366,34 +7196,25 @@ dependencies = [ ] [[package]] -name = "objc2-user-notifications" +name = "objc2-uniform-type-identifiers" version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9df9128cbbfef73cda168416ccf7f837b62737d748333bfe9ab71c245d76613e" +checksum = "7902ac02859fc1f7045f8b598c63f1ae0cc7efeaa06a9bc9f3d9a3c955974fa4" dependencies = [ - "bitflags 2.13.1", - "block2 0.6.2", "objc2 0.6.4", - "objc2-core-location", "objc2-foundation 0.3.2", ] [[package]] -name = "objc_exception" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad970fb455818ad6cba4c122ad012fae53ae8b4795f86378bce65e4f6bab2ca4" -dependencies = [ - "cc", -] - -[[package]] -name = "objc_id" -version = "0.1.1" +name = "objc2-user-notifications" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c92d4ddb4bd7b50d730c215ff871754d0da6b2178849f8a2a2ab69712d0c073b" +checksum = "9df9128cbbfef73cda168416ccf7f837b62737d748333bfe9ab71c245d76613e" dependencies = [ - "objc", + "bitflags 2.13.1", + "block2 0.6.2", + "objc2 0.6.4", + "objc2-foundation 0.3.2", ] [[package]] @@ -7438,8 +7259,7 @@ checksum = "384b8ab6d37215f3c5301a95a4accb5d64aa607f1fcb26a11b5303878451b4fe" [[package]] name = "oo7" version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78f2bfed90f1618b4b48dcad9307f25e14ae894e2949642c87c351601d62cebd" +source = "git+https://github.com/zed-industries/oo7?rev=731c1215edb6905876c6137ab300428c7b8d7c13#731c1215edb6905876c6137ab300428c7b8d7c13" dependencies = [ "aes 0.8.4", "ashpd", @@ -7470,6 +7290,12 @@ dependencies = [ "zvariant", ] +[[package]] +name = "oorandom" +version = "11.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d6790f58c7ff633d8771f42965289203411a5e5c68388703c06e14f24770b41e" + [[package]] name = "opaque-debug" version = "0.3.1" @@ -7570,7 +7396,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7d8fae84b431384b68627d0f9b3b1245fcf9f46f6c0e3dc902e9dce64edd1967" dependencies = [ "libc", - "windows-sys 0.45.0", + "windows-sys 0.61.2", ] [[package]] @@ -7591,6 +7417,16 @@ dependencies = [ "primeorder", ] +[[package]] +name = "page_size" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "30d5b2194ed13191c1999ae0704b7839fb18384fa22e49b57eeaa97d79ce40da" +dependencies = [ + "libc", + "winapi", +] + [[package]] name = "pake-cpace" version = "0.1.0" @@ -7714,13 +7550,38 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9b4f627cb1b25917193a259e49bdad08f671f8d9708acfd5fe0a8c1455d87220" [[package]] -name = "perf" -version = "0.1.0" -source = "git+https://github.com/zed-industries/zed?rev=cc053a4a6fa2fd0e8793201ed9099466af1be0b1#cc053a4a6fa2fd0e8793201ed9099466af1be0b1" +name = "perf-event-data" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "575828d9d7d205188048eb1508560607a03d21eafdbba47b8cade1736c1c28e1" dependencies = [ - "collections", - "serde", - "serde_json", + "bitflags 2.13.1", + "c-enum", + "perf-event-open-sys2", +] + +[[package]] +name = "perf-event-open-sys2" +version = "5.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9c25955321465255e437600b54296983fab1feac2cd0c38958adeb26dbae49e" +dependencies = [ + "libc", + "memoffset 0.9.1", +] + +[[package]] +name = "perf-event2" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0939b8fad77dfaeb29ebbd35faaeaadbf833167f30975f1b8993bbba09ea0a0f" +dependencies = [ + "bitflags 2.13.1", + "c-enum", + "libc", + "memmap2", + "perf-event-data", + "perf-event-open-sys2", ] [[package]] @@ -8016,7 +7877,7 @@ dependencies = [ "block2 0.5.1", "clipboard-rs", "core-foundation 0.10.0", - "core-graphics 0.24.0", + "core-graphics", "cua-driver-contract", "cua-driver-core", "cursor-overlay", @@ -8030,7 +7891,7 @@ dependencies = [ "objc2-foundation 0.2.2", "objc2-quartz-core 0.2.2", "pip-preview", - "screencapturekit 8.0.1", + "screencapturekit", "security-framework", "serde", "serde_json", @@ -8083,6 +7944,34 @@ dependencies = [ "time", ] +[[package]] +name = "plotters" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5aeb6f403d7a4911efb1e33402027fc44f29b5bf6def3effcc22d7bb75f2b747" +dependencies = [ + "num-traits", + "plotters-backend", + "plotters-svg", + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "plotters-backend" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df42e13c12958a16b3f7f4386b9ab1f3e7933914ecea48da7139435263a4172a" + +[[package]] +name = "plotters-svg" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "51bae2ac328883f7acdfea3d66a7c35751187f870bc81f94563733a154d7a670" +dependencies = [ + "plotters-backend", +] + [[package]] name = "png" version = "0.17.16" @@ -8119,7 +8008,7 @@ dependencies = [ "concurrent-queue", "hermit-abi", "pin-project-lite", - "rustix 1.1.6", + "rustix", "windows-sys 0.61.2", ] @@ -8203,8 +8092,6 @@ checksum = "af3fb618632874fb76937c2361a7f22afd393c982a2165595407edc75b06d3c1" dependencies = [ "atomic", "crossbeam-queue", - "futures", - "log", "parking_lot", "pin-project", "pollster 0.2.5", @@ -8243,6 +8130,8 @@ version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d83eb9bc6d8e5cf568e7a1101d60ee05e81ed50ea106026f3d18deeb046d7661" dependencies = [ + "serde_core", + "writeable", "zerovec", ] @@ -8267,16 +8156,6 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e8cf8e6a8aa66ce33f63993ffc4ea4271eb5b0530a9002db8455ea6050c77bfa" -[[package]] -name = "prettyplease" -version = "0.2.37" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "479ca8adacdd7ce8f1fb39ce9ecccbfe93a3f1344b3d0d97f20bc0196208f62b" -dependencies = [ - "proc-macro2", - "syn 2.0.119", -] - [[package]] name = "primefield" version = "0.14.0" @@ -8313,28 +8192,6 @@ dependencies = [ "toml_edit 0.25.13+spec-1.1.0", ] -[[package]] -name = "proc-macro-error-attr2" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96de42df36bb9bba5542fe9f1a054b8cc87e172759a1868aa05c1f3acc89dfc5" -dependencies = [ - "proc-macro2", - "quote", -] - -[[package]] -name = "proc-macro-error2" -version = "2.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "11ec05c52be0a07b08061f7dd003e7d7092e0472bc731b4af7bb1ef876109802" -dependencies = [ - "proc-macro-error-attr2", - "proc-macro2", - "quote", - "syn 2.0.119", -] - [[package]] name = "proc-macro-hack" version = "0.5.20+deprecated" @@ -8384,16 +8241,18 @@ dependencies = [ [[package]] name = "proptest" -version = "1.10.0" -source = "git+https://github.com/proptest-rs/proptest?rev=3dca198a8fef1b32e3a66f1e1897c955b4dc5b5b#3dca198a8fef1b32e3a66f1e1897c955b4dc5b5b" +version = "1.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8530004ccb15eae51c7e40009fbe317f341f804db54dc033eec1c50be28cfa0" dependencies = [ - "bit-set 0.8.0", - "bit-vec 0.8.0", + "bit-set 0.11.1", + "bit-vec 0.10.1", "bitflags 2.13.1", + "chacha20 0.10.2", + "core_detect", "num-traits", "proptest-macro", - "rand 0.9.5", - "rand_chacha 0.9.0", + "rand 0.10.2", "rand_xorshift", "regex-syntax", "rusty-fork", @@ -8403,13 +8262,14 @@ dependencies = [ [[package]] name = "proptest-macro" -version = "0.5.0" -source = "git+https://github.com/proptest-rs/proptest?rev=3dca198a8fef1b32e3a66f1e1897c955b4dc5b5b#3dca198a8fef1b32e3a66f1e1897c955b4dc5b5b" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e99782ea31698c2206c6887c1220d2f594b291c26cb9ec5b6d7cf175320bc212" dependencies = [ "convert_case 0.11.0", "proc-macro2", "quote", - "syn 2.0.119", + "syn 3.0.4", ] [[package]] @@ -8555,7 +8415,7 @@ dependencies = [ "once_cell", "socket2", "tracing", - "windows-sys 0.52.0", + "windows-sys 0.61.2", ] [[package]] @@ -8672,11 +8532,11 @@ dependencies = [ [[package]] name = "rand_xorshift" -version = "0.4.0" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "513962919efc330f829edb2535844d1b912b0fbe2ca165d613e4e8788bb05a5a" +checksum = "60aa6af80be32871323012e02e6e65f8a7cc7890931ae421d217ad8fe0df2ccf" dependencies = [ - "rand_core 0.9.5", + "rand_core 0.10.1", ] [[package]] @@ -8904,7 +8764,7 @@ dependencies = [ [[package]] name = "refineable" version = "0.1.0" -source = "git+https://github.com/zed-industries/zed?rev=cc053a4a6fa2fd0e8793201ed9099466af1be0b1#cc053a4a6fa2fd0e8793201ed9099466af1be0b1" +source = "git+https://github.com/zed-industries/zed?rev=c7bea343838f42b4c14151393e41f0bbe033c95e#c7bea343838f42b4c14151393e41f0bbe033c95e" dependencies = [ "derive_refineable", ] @@ -8980,7 +8840,7 @@ dependencies = [ "enumflags2", "futures-util", "log", - "rustix 1.1.6", + "rustix", "tokio", ] @@ -9294,19 +9154,6 @@ dependencies = [ "nom 7.1.3", ] -[[package]] -name = "rustix" -version = "0.38.44" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fdb5bc1ae2baa591800df16c9ca78619bf65c0488b41b96ccec5d11220d8c154" -dependencies = [ - "bitflags 2.13.1", - "errno", - "libc", - "linux-raw-sys 0.4.15", - "windows-sys 0.59.0", -] - [[package]] name = "rustix" version = "1.1.6" @@ -9316,8 +9163,8 @@ dependencies = [ "bitflags 2.13.1", "errno", "libc", - "linux-raw-sys 0.12.1", - "windows-sys 0.52.0", + "linux-raw-sys", + "windows-sys 0.61.2", ] [[package]] @@ -9376,7 +9223,7 @@ dependencies = [ "security-framework", "security-framework-sys", "webpki-root-certs", - "windows-sys 0.52.0", + "windows-sys 0.61.2", ] [[package]] @@ -9460,7 +9307,7 @@ dependencies = [ [[package]] name = "scheduler" version = "0.1.0" -source = "git+https://github.com/zed-industries/zed?rev=cc053a4a6fa2fd0e8793201ed9099466af1be0b1#cc053a4a6fa2fd0e8793201ed9099466af1be0b1" +source = "git+https://github.com/zed-industries/zed?rev=c7bea343838f42b4c14151393e41f0bbe033c95e#c7bea343838f42b4c14151393e41f0bbe033c95e" dependencies = [ "async-task", "backtrace", @@ -9469,6 +9316,7 @@ dependencies = [ "futures", "parking_lot", "rand 0.9.5", + "wasm_thread", "web-time", ] @@ -9522,15 +9370,6 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" -[[package]] -name = "screencapturekit" -version = "0.2.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a5eeeb57ac94960cfe5ff4c402be6585ae4c8d29a2cf41b276048c2e849d64e" -dependencies = [ - "screencapturekit-sys", -] - [[package]] name = "screencapturekit" version = "8.0.1" @@ -9541,20 +9380,6 @@ dependencies = [ "apple-metal", ] -[[package]] -name = "screencapturekit-sys" -version = "0.2.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22411b57f7d49e7fe08025198813ee6fd65e1ee5eff4ebc7880c12c82bde4c60" -dependencies = [ - "block", - "dispatch", - "objc", - "objc-foundation", - "objc_id", - "once_cell", -] - [[package]] name = "scroll" version = "0.12.0" @@ -9716,15 +9541,6 @@ dependencies = [ "syn 3.0.4", ] -[[package]] -name = "serde_fmt" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e497af288b3b95d067a23a4f749f2861121ffcb2f6d8379310dcda040c345ed" -dependencies = [ - "serde_core", -] - [[package]] name = "serde_json" version = "1.0.151" @@ -9914,12 +9730,6 @@ version = "1.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dc6fe69c597f9c37bfeeeeeb33da3530379845f10be461a66d16d03eca2ded77" -[[package]] -name = "shlex" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" - [[package]] name = "shlex" version = "2.0.1" @@ -10086,7 +9896,6 @@ version = "0.3.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4aaa7368fcf4852a4c2dd92df0cace6a71f2091ca0a23391ce7f3a31833f1523" dependencies = [ - "borsh", "serde_core", ] @@ -10097,7 +9906,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c3d1e2c7f27f8d4cb10542a02c49005dbd6e93095799d6f3be745fae9f8fedd4" dependencies = [ "libc", - "windows-sys 0.60.2", + "windows-sys 0.61.2", ] [[package]] @@ -10226,9 +10035,9 @@ dependencies = [ [[package]] name = "stacksafe" -version = "0.1.4" +version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d9c1172965d317e87ddb6d364a040d958b40a1db82b6ef97da26253a8b3d090" +checksum = "95f9c34983ac74195c710c473db6fdf1085f64a47dbaa0090d1bea03be70da66" dependencies = [ "stacker", "stacksafe-macro", @@ -10236,13 +10045,13 @@ dependencies = [ [[package]] name = "stacksafe-macro" -version = "0.1.4" +version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "172175341049678163e979d9107ca3508046d4d2a7c6682bee46ac541b17db69" +checksum = "6feeae42a2d6b0dcb8aeb2f08d9e48cdac600239cf8a20fc59f9e252e86bdfe1" dependencies = [ - "proc-macro-error2", + "proc-macro2", "quote", - "syn 2.0.119", + "syn 3.0.4", ] [[package]] @@ -10280,34 +10089,13 @@ version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" -[[package]] -name = "strum" -version = "0.27.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af23d6f6c1a224baef9d3f61e287d2761385a5b88fdab4eb4c6f11aeb54c4bcf" -dependencies = [ - "strum_macros 0.27.2", -] - [[package]] name = "strum" version = "0.28.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9628de9b8791db39ceda2b119bbe13134770b56c138ec1d3af810d045c04f9bd" dependencies = [ - "strum_macros 0.28.0", -] - -[[package]] -name = "strum_macros" -version = "0.27.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7695ce3845ea4b33927c055a39dc438a45b059f7c1b3d91d38d10355fb8cbca7" -dependencies = [ - "heck 0.5.0", - "proc-macro2", - "quote", - "syn 2.0.119", + "strum_macros", ] [[package]] @@ -10331,94 +10119,14 @@ checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" [[package]] name = "sum_tree" version = "0.1.0" -source = "git+https://github.com/zed-industries/zed?rev=cc053a4a6fa2fd0e8793201ed9099466af1be0b1#cc053a4a6fa2fd0e8793201ed9099466af1be0b1" +source = "git+https://github.com/zed-industries/zed?rev=c7bea343838f42b4c14151393e41f0bbe033c95e#c7bea343838f42b4c14151393e41f0bbe033c95e" dependencies = [ "heapless 0.9.3", - "log", "rayon", "tracing", "ztracing", ] -[[package]] -name = "sval" -version = "2.21.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec4a2a7d92fa86fcc6222e4c3845f8486cff899d9db32480b26c91a5dbf2e22d" - -[[package]] -name = "sval_buffer" -version = "2.21.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f4324db9ac500c609d659b752edf9c8abbf2233f8afd61a503fd6f88ed625032" -dependencies = [ - "sval", - "sval_ref", - "zerocopy", -] - -[[package]] -name = "sval_dynamic" -version = "2.21.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4046add0eecf55e680b9e207edf5fc7737b18a1d950db363d97e7f1b2d7c629c" -dependencies = [ - "sval", -] - -[[package]] -name = "sval_fmt" -version = "2.21.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "911a3486b5984a0a4f25edefcf2c2dba23654c29f63e75493b671d338bf24243" -dependencies = [ - "itoa", - "ryu", - "sval", -] - -[[package]] -name = "sval_json" -version = "2.21.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da53aae7c737b5b5f1be4bcb0ff20e057bf6b2ee4e9d025560075c5830d09f95" -dependencies = [ - "itoa", - "ryu", - "sval", -] - -[[package]] -name = "sval_nested" -version = "2.21.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "df24df43cbdc4bb8c9f5ed19d0d57dc8f60a1a4259cdce52d597fe774ad3a71f" -dependencies = [ - "sval", - "sval_buffer", - "sval_ref", -] - -[[package]] -name = "sval_ref" -version = "2.21.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2bebc17f0f1fad060e57b778728d41ef87627e9111a6365d7463472cb58fc1b3" -dependencies = [ - "sval", -] - -[[package]] -name = "sval_serde" -version = "2.21.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f26fe3f6a68b40e6c8d654ea48c00e4316272fddf68c80493714c1b034ae70b" -dependencies = [ - "serde_core", - "sval", - "sval_nested", -] - [[package]] name = "svg_fmt" version = "0.4.5" @@ -10605,26 +10313,13 @@ dependencies = [ [[package]] name = "taffy" -version = "0.12.2" +version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "340a09581f29809fc0df82a3955501dc7f2a21f887e5d1c13dbe288fe1c0bef4" +checksum = "3c8480887e8803986d96a7173729565520d4bbb721ad6b7ad6941a22897207aa" dependencies = [ - "arrayvec", - "grid", "serde", "slotmap", -] - -[[package]] -name = "tao-core-video-sys" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "271450eb289cb4d8d0720c6ce70c72c8c858c93dd61fc625881616752e6b98f6" -dependencies = [ - "cfg-if", - "core-foundation-sys", - "libc", - "objc", + "smallvec", ] [[package]] @@ -10673,8 +10368,8 @@ dependencies = [ "fastrand", "getrandom 0.4.3", "once_cell", - "rustix 1.1.6", - "windows-sys 0.52.0", + "rustix", + "windows-sys 0.61.2", ] [[package]] @@ -10835,6 +10530,16 @@ dependencies = [ "zerovec", ] +[[package]] +name = "tinytemplate" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "be4d6b5f19ff7664e8c98d03e2139cb510db9b0a60b55f8e8709b689d939b6bc" +dependencies = [ + "serde", + "serde_json", +] + [[package]] name = "tinyvec" version = "1.12.0" @@ -11182,7 +10887,7 @@ dependencies = [ "once_cell", "png 0.18.1", "thiserror 2.0.20", - "windows-sys 0.60.2", + "windows-sys 0.61.2", ] [[package]] @@ -11239,12 +10944,6 @@ dependencies = [ "rustc-hash 2.1.3", ] -[[package]] -name = "typeid" -version = "1.0.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc7d623258602320d5c55d1bc22793b57daff0ec7efc270ea7d55ce1d5f5471c" - [[package]] name = "typenum" version = "1.20.1" @@ -11259,7 +10958,7 @@ checksum = "f2f6fb2847f6742cd76af783a2a2c49e9375d0a111c7bef6f71cd9e738c72d6e" dependencies = [ "memoffset 0.9.1", "tempfile", - "windows-sys 0.60.2", + "windows-sys 0.61.2", ] [[package]] @@ -11364,9 +11063,9 @@ dependencies = [ [[package]] name = "unicode-properties" -version = "0.1.4" +version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7df058c713841ad818f1dc5d3fd88063241cc61f49f5fbea4b951e8cf5a8d71d" +checksum = "e70f2a8b45122e719eb623c01822704c4e0907e7e426a05927e1a1cfff5b75d0" [[package]] name = "unicode-script" @@ -11608,16 +11307,6 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" -[[package]] -name = "util_macros" -version = "0.1.0" -source = "git+https://github.com/zed-industries/zed?rev=cc053a4a6fa2fd0e8793201ed9099466af1be0b1#cc053a4a6fa2fd0e8793201ed9099466af1be0b1" -dependencies = [ - "perf", - "quote", - "syn 2.0.119", -] - [[package]] name = "uuid" version = "1.25.0" @@ -11659,42 +11348,6 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ba73ea9cf16a25df0c8caa16c51acb937d5712a8429db78a3ee29d5dcacd3a65" -[[package]] -name = "value-bag" -version = "1.13.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "068e763e8279de7ab94b6afebded2cb701678af094feb1c12ccb061b4783c1be" -dependencies = [ - "value-bag-serde1", - "value-bag-sval2", -] - -[[package]] -name = "value-bag-serde1" -version = "1.13.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "417d6197dd0ee696783d6be4276ac6ea74b985e00024c85ccfb37aff4f2bed82" -dependencies = [ - "erased-serde", - "serde_core", - "serde_fmt", -] - -[[package]] -name = "value-bag-sval2" -version = "1.13.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c61f7251ecde2c9ed431bbe0659853e7991753447447bbf1ae59d8b31c578d4e" -dependencies = [ - "sval", - "sval_buffer", - "sval_dynamic", - "sval_fmt", - "sval_json", - "sval_ref", - "sval_serde", -] - [[package]] name = "vcpkg" version = "0.2.15" @@ -11882,7 +11535,8 @@ checksum = "38a91b4eaddff87b1cd1074985e3713da4af2c49742d1b356b2c01670a67a078" dependencies = [ "cc", "downcast-rs", - "rustix 1.1.6", + "log", + "rustix", "scoped-tls", "smallvec", "wayland-sys", @@ -11895,7 +11549,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e3c36a0f861ad76d0901f2800b46321410d9f73f2ea88aac0650d86c32688073" dependencies = [ "bitflags 2.13.1", - "rustix 1.1.6", + "rustix", "wayland-backend", "wayland-scanner", ] @@ -11906,7 +11560,7 @@ version = "0.31.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4a52d18780be9b1314328a3de5f930b73d2200112e3849ca6cb11822793fb34d" dependencies = [ - "rustix 1.1.6", + "rustix", "wayland-client", "xcursor", ] @@ -12043,9 +11697,8 @@ checksum = "a28ac98ddc8b9274cb41bb4d9d4d5c425b6020c50c46f25559911905610b4a88" [[package]] name = "wgpu" -version = "29.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "76e8840e1ba2881d4cbb18d2147627a56af426ff064c0401eb0c8410c6325d07" +version = "30.0.0" +source = "git+https://github.com/gfx-rs/wgpu?rev=cddb2f5d80dc0009b2ef6767635140cacf90a007#cddb2f5d80dc0009b2ef6767635140cacf90a007" dependencies = [ "arrayvec", "bitflags 2.13.1", @@ -12053,12 +11706,10 @@ dependencies = [ "cfg-if", "cfg_aliases", "document-features", - "hashbrown 0.16.1", + "hashbrown 0.17.1", "js-sys", "log", "naga", - "parking_lot", - "portable-atomic", "profiling", "raw-window-handle", "smallvec", @@ -12068,89 +11719,94 @@ dependencies = [ "web-sys", "wgpu-core", "wgpu-hal", + "wgpu-sync", "wgpu-types", ] [[package]] name = "wgpu-core" -version = "29.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2f519832254e56965a9940c4af57dcb75f702b6f6fa4a0b172f685395843a4d7" +version = "30.0.0" +source = "git+https://github.com/gfx-rs/wgpu?rev=cddb2f5d80dc0009b2ef6767635140cacf90a007#cddb2f5d80dc0009b2ef6767635140cacf90a007" dependencies = [ "arrayvec", - "bit-set 0.9.1", - "bit-vec 0.9.1", + "bit-set 0.11.1", + "bit-vec 0.10.1", "bitflags 2.13.1", "bytemuck", "cfg_aliases", "document-features", - "hashbrown 0.16.1", + "hashbrown 0.17.1", "indexmap 2.14.0", "log", "naga", - "once_cell", - "parking_lot", - "portable-atomic", + "naga-types", + "num-traits", "profiling", "raw-window-handle", "rustc-hash 1.1.0", + "scopeguard", "smallvec", "thiserror 2.0.20", "wgpu-core-deps-apple", "wgpu-core-deps-emscripten", + "wgpu-core-deps-linux-android-bsd", "wgpu-core-deps-wasm", - "wgpu-core-deps-windows-linux-android", + "wgpu-core-deps-windows", "wgpu-hal", "wgpu-naga-bridge", + "wgpu-sync", "wgpu-types", ] [[package]] name = "wgpu-core-deps-apple" -version = "29.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f5e39e26c4c0e07589e67d18546cf79ff45383659fc72fca4dd293358a0347f3" +version = "30.0.0" +source = "git+https://github.com/gfx-rs/wgpu?rev=cddb2f5d80dc0009b2ef6767635140cacf90a007#cddb2f5d80dc0009b2ef6767635140cacf90a007" dependencies = [ "wgpu-hal", ] [[package]] name = "wgpu-core-deps-emscripten" -version = "29.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01e09be551dc939498bdd5f6b2c66e55ab275dad25825267a08605a80fc9f0af" +version = "30.0.0" +source = "git+https://github.com/gfx-rs/wgpu?rev=cddb2f5d80dc0009b2ef6767635140cacf90a007#cddb2f5d80dc0009b2ef6767635140cacf90a007" +dependencies = [ + "wgpu-hal", +] + +[[package]] +name = "wgpu-core-deps-linux-android-bsd" +version = "30.0.0" +source = "git+https://github.com/gfx-rs/wgpu?rev=cddb2f5d80dc0009b2ef6767635140cacf90a007#cddb2f5d80dc0009b2ef6767635140cacf90a007" dependencies = [ "wgpu-hal", ] [[package]] name = "wgpu-core-deps-wasm" -version = "29.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af1fb1798be2a912497d4c224f72d39bb0cb34af50e8bcc29865bc339c943059" +version = "30.0.0" +source = "git+https://github.com/gfx-rs/wgpu?rev=cddb2f5d80dc0009b2ef6767635140cacf90a007#cddb2f5d80dc0009b2ef6767635140cacf90a007" dependencies = [ "wgpu-hal", ] [[package]] -name = "wgpu-core-deps-windows-linux-android" -version = "29.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e592c1bbef6ad047647ae6e666ebd8cee7a32bb4544d9700ec96cbf73230257" +name = "wgpu-core-deps-windows" +version = "30.0.0" +source = "git+https://github.com/gfx-rs/wgpu?rev=cddb2f5d80dc0009b2ef6767635140cacf90a007#cddb2f5d80dc0009b2ef6767635140cacf90a007" dependencies = [ "wgpu-hal", ] [[package]] name = "wgpu-hal" -version = "29.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97ace1c17727311c22a46e4e3faf56ea6de81af99dcc839bdfb54857b94d448d" +version = "30.0.0" +source = "git+https://github.com/gfx-rs/wgpu?rev=cddb2f5d80dc0009b2ef6767635140cacf90a007#cddb2f5d80dc0009b2ef6767635140cacf90a007" dependencies = [ "android_system_properties", "arrayvec", "ash", - "bit-set 0.9.1", + "bit-set 0.11.1", "bitflags 2.13.1", "block2 0.6.2", "bytemuck", @@ -12159,36 +11815,35 @@ dependencies = [ "glow", "glutin_wgl_sys", "gpu-allocator", - "gpu-descriptor", - "hashbrown 0.16.1", + "hashbrown 0.17.1", "js-sys", "khronos-egl", "libc", "libloading", "log", "naga", + "naga-types", "ndk-sys", "objc2 0.6.4", "objc2-core-foundation", + "objc2-core-graphics", "objc2-foundation 0.3.2", "objc2-metal 0.3.2", "objc2-quartz-core 0.3.2", - "once_cell", "ordered-float", - "parking_lot", - "portable-atomic", - "portable-atomic-util", "profiling", "range-alloc", "raw-window-handle", "raw-window-metal", "renderdoc-sys", "smallvec", + "static_assertions", "thiserror 2.0.20", "wasm-bindgen", "wayland-sys", "web-sys", "wgpu-naga-bridge", + "wgpu-sync", "wgpu-types", "windows 0.62.2", "windows-core 0.62.2", @@ -12197,38 +11852,49 @@ dependencies = [ [[package]] name = "wgpu-naga-bridge" -version = "29.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95226013f547544b223281cd16a4fb549aa9dcb562adbda0faae4c73ffbbc161" +version = "30.0.0" +source = "git+https://github.com/gfx-rs/wgpu?rev=cddb2f5d80dc0009b2ef6767635140cacf90a007#cddb2f5d80dc0009b2ef6767635140cacf90a007" dependencies = [ "naga", "wgpu-types", ] +[[package]] +name = "wgpu-sync" +version = "30.0.0" +source = "git+https://github.com/gfx-rs/wgpu?rev=cddb2f5d80dc0009b2ef6767635140cacf90a007#cddb2f5d80dc0009b2ef6767635140cacf90a007" +dependencies = [ + "cfg-if", + "lock_api", + "once_cell", + "parking_lot", + "portable-atomic", + "portable-atomic-util", +] + [[package]] name = "wgpu-types" -version = "29.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "84bf84cd9ca8ca45e2b223a3868f1adf9bfc0c66aeac212e76ee7e40fdadf8f5" +version = "30.0.0" +source = "git+https://github.com/gfx-rs/wgpu?rev=cddb2f5d80dc0009b2ef6767635140cacf90a007#cddb2f5d80dc0009b2ef6767635140cacf90a007" dependencies = [ "bitflags 2.13.1", "bytemuck", "js-sys", "log", + "macro_rules_attribute", + "naga-types", "raw-window-handle", + "static_assertions", "web-sys", ] [[package]] name = "which" -version = "6.0.3" +version = "8.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4ee928febd44d98f2f459a4a79bd4d928591333a494a10a868418ac1b39cf1f" +checksum = "bae2f2b2b816647a1cab1acc91f5bd20812d53cb344382635ec2181940c8034f" dependencies = [ - "either", - "home", - "rustix 0.38.44", - "winsafe", + "libc", ] [[package]] @@ -12259,7 +11925,7 @@ version = "0.1.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22" dependencies = [ - "windows-sys 0.48.0", + "windows-sys 0.61.2", ] [[package]] @@ -12562,17 +12228,6 @@ dependencies = [ "windows-link 0.2.1", ] -[[package]] -name = "windows-registry" -version = "0.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b8a9ed28765efc97bbc954883f4e6796c33a06546ebafacbabee9696967499e" -dependencies = [ - "windows-link 0.1.3", - "windows-result 0.3.4", - "windows-strings 0.4.2", -] - [[package]] name = "windows-registry" version = "0.6.1" @@ -13018,12 +12673,6 @@ dependencies = [ "windows-sys 0.59.0", ] -[[package]] -name = "winsafe" -version = "0.0.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d135d17ab770252ad95e9a872d365cf3090e3be864a34ab46f48555993efc904" - [[package]] name = "wio" version = "0.2.2" @@ -13048,7 +12697,7 @@ dependencies = [ "libc", "log", "os_pipe", - "rustix 1.1.6", + "rustix", "thiserror 2.0.20", "tree_magic_mini", "wayland-backend", @@ -13128,16 +12777,6 @@ dependencies = [ "pkg-config", ] -[[package]] -name = "x11-clipboard" -version = "0.9.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "662d74b3d77e396b8e5beb00b9cad6a9eccf40b2ef68cc858784b14c41d535a3" -dependencies = [ - "libc", - "x11rb", -] - [[package]] name = "x11rb" version = "0.13.2" @@ -13147,7 +12786,7 @@ dependencies = [ "as-raw-xcb-connection", "gethostname", "libc", - "rustix 1.1.6", + "rustix", "x11rb-protocol", "xcursor", ] @@ -13194,7 +12833,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "32e45ad4206f6d2479085147f02bc2ef834ac85886624a23575ae137c8aa8156" dependencies = [ "libc", - "rustix 1.1.6", + "rustix", ] [[package]] @@ -13346,7 +12985,7 @@ dependencies = [ "hex", "libc", "ordered-stream", - "rustix 1.1.6", + "rustix", "serde", "serde_repr", "tokio", @@ -13450,7 +13089,7 @@ dependencies = [ "bitflags 2.13.1", "byteorder", "core-foundation 0.10.0", - "core-graphics 0.24.0", + "core-graphics", "core-text", "dirs 6.0.0", "dwrote", @@ -13469,18 +13108,12 @@ dependencies = [ [[package]] name = "zed-scap" version = "0.0.8-zed" -source = "git+https://github.com/zed-industries/scap?rev=4afea48c3b002197176fb19cd0f9b180dd36eaac#4afea48c3b002197176fb19cd0f9b180dd36eaac" +source = "git+https://github.com/zed-industries/scap?rev=b5c86ec58dd4b6b7732bf6ac8be03d6b1f190a82#b5c86ec58dd4b6b7732bf6ac8be03d6b1f190a82" dependencies = [ "anyhow", - "cocoa 0.25.0", - "core-graphics-helmer-fork", "log", - "objc", "rand 0.8.7", - "screencapturekit 0.2.8", - "screencapturekit-sys", "sysinfo", - "tao-core-video-sys", "windows 0.61.3", "windows-capture", "x11", @@ -13577,6 +13210,7 @@ dependencies = [ "displaydoc", "yoke", "zerofrom", + "zerovec", ] [[package]] @@ -13602,17 +13236,6 @@ dependencies = [ "syn 3.0.4", ] -[[package]] -name = "zlog" -version = "0.1.0" -source = "git+https://github.com/zed-industries/zed?rev=cc053a4a6fa2fd0e8793201ed9099466af1be0b1#cc053a4a6fa2fd0e8793201ed9099466af1be0b1" -dependencies = [ - "anyhow", - "chrono", - "collections", - "log", -] - [[package]] name = "zmij" version = "1.0.23" @@ -13650,18 +13273,16 @@ dependencies = [ [[package]] name = "ztracing" version = "0.1.0" -source = "git+https://github.com/zed-industries/zed?rev=cc053a4a6fa2fd0e8793201ed9099466af1be0b1#cc053a4a6fa2fd0e8793201ed9099466af1be0b1" +source = "git+https://github.com/zed-industries/zed?rev=c7bea343838f42b4c14151393e41f0bbe033c95e#c7bea343838f42b4c14151393e41f0bbe033c95e" dependencies = [ "tracing", - "tracing-subscriber", - "zlog", "ztracing_macro", ] [[package]] name = "ztracing_macro" version = "0.1.0" -source = "git+https://github.com/zed-industries/zed?rev=cc053a4a6fa2fd0e8793201ed9099466af1be0b1#cc053a4a6fa2fd0e8793201ed9099466af1be0b1" +source = "git+https://github.com/zed-industries/zed?rev=c7bea343838f42b4c14151393e41f0bbe033c95e#c7bea343838f42b4c14151393e41f0bbe033c95e" [[package]] name = "zune-core" diff --git a/apps/maple-agent/app/Cargo.toml b/apps/maple-agent/app/Cargo.toml index 442951240..39666ca18 100644 --- a/apps/maple-agent/app/Cargo.toml +++ b/apps/maple-agent/app/Cargo.toml @@ -19,6 +19,7 @@ desktop = [ "dep:fluent-templates", "dep:sys-locale", "dep:gpui", + "dep:icu_segmenter", "dep:gpui-platform", "dep:image", "dep:unicode-segmentation", @@ -48,15 +49,21 @@ dirs = "6" maple-agent = { path = "../crates/maple-agent", default-features = false } maple-billing = { path = "../crates/maple-billing" } maple-agent-updater = { path = "../crates/maple-agent-updater" } -# gpui is pinned to the Zed commit that gpui-libghostty (the embedded -# terminal Ben is preparing) builds against, so the two agree on one gpui -# once the terminal lands. crates.io 0.2.2 is older than this commit. -gpui = { version = "0.2.2", git = "https://github.com/zed-industries/zed", rev = "cc053a4a6fa2fd0e8793201ed9099466af1be0b1", optional = true } +# gpui is pinned to one Zed commit; crates.io 0.2.2 is older than it. +# gpui-libghostty (the embedded terminal Ben is preparing) binds to the +# application's gpui but is tested against cc053a4a, so build its bindings +# against this revision before the terminal lands. +# `stacker` keeps gpui growing the stack under deep element trees, which it +# did unconditionally before this revision. +gpui = { version = "0.2.2", git = "https://github.com/zed-industries/zed", rev = "c7bea343838f42b4c14151393e41f0bbe033c95e", features = ["stacker"], optional = true } # The application factory for that gpui revision; it lives one crate over. # `font-kit` selects the native text system on macOS; without it this gpui # revision draws no text at all. -gpui-platform = { package = "gpui_platform", version = "0.1.0", git = "https://github.com/zed-industries/zed", rev = "cc053a4a6fa2fd0e8793201ed9099466af1be0b1", features = ["font-kit", "wayland", "x11"], optional = true } +gpui-platform = { package = "gpui_platform", version = "0.1.0", git = "https://github.com/zed-industries/zed", rev = "c7bea343838f42b4c14151393e41f0bbe033c95e", features = ["font-kit", "wayland", "x11"], optional = true } image = { version = "0.25", default-features = false, features = ["png", "jpeg", "webp"], optional = true } +# The line breaker gpui wraps text with, at gpui's version, so markdown +# tables measure unbreakable runs by the same rule. +icu_segmenter = { version = "2.3.0", default-features = false, features = ["compiled_data"], optional = true } base64 = "0.22" httparse = "1" rand = "0.8.6" @@ -70,7 +77,7 @@ log = { workspace = true } env_logger = "0.11" webbrowser = "1" maple-sdk = { workspace = true } -uuid = { version = "1", features = ["v4"] } +uuid = { version = "1", features = ["v4", "v7"] } unicode-segmentation = { version = "1", optional = true } pulldown-cmark = { version = "0.13.6", default-features = false, optional = true } cpal = { version = "0.17", optional = true } @@ -127,7 +134,7 @@ tempfile = "3" parking_lot = "0.12" # The gpui test harness. Keep this out of [dependencies]: with test-support on, # App::shutdown skips the on_app_quit futures and logs a timeout on every quit. -gpui = { version = "0.2.2", git = "https://github.com/zed-industries/zed", rev = "cc053a4a6fa2fd0e8793201ed9099466af1be0b1", features = ["test-support"] } +gpui = { version = "0.2.2", git = "https://github.com/zed-industries/zed", rev = "c7bea343838f42b4c14151393e41f0bbe033c95e", features = ["test-support"] } [build-dependencies] embed-resource = "=3.0.11" diff --git a/apps/maple-agent/app/src/desktop/maintenance_tests.rs b/apps/maple-agent/app/src/desktop/maintenance_tests.rs index eb7a168a7..5113648d3 100644 --- a/apps/maple-agent/app/src/desktop/maintenance_tests.rs +++ b/apps/maple-agent/app/src/desktop/maintenance_tests.rs @@ -886,7 +886,10 @@ fn committed_restart_retry_quit_and_close_do_not_contact_the_retired_host( let mut restarted = cx.expect_restart(); cx.update(|cx| restart_installed_update(path.clone(), cx)); #[cfg(not(target_os = "windows"))] - assert_eq!(restarted.try_recv().unwrap(), Some(Some(path.clone()))); + assert_eq!( + restarted.try_recv().unwrap(), + Some((Some(path.clone()), Vec::new())) + ); #[cfg(target_os = "windows")] { // Windows uses the verified stable bootstrap, never GPUI restart. diff --git a/apps/maple-agent/app/src/keymap.rs b/apps/maple-agent/app/src/keymap.rs index 798c1d634..050105266 100644 --- a/apps/maple-agent/app/src/keymap.rs +++ b/apps/maple-agent/app/src/keymap.rs @@ -5,7 +5,7 @@ use std::rc::Rc; -use gpui::{Action, App, DummyKeyboardMapper, KeyBinding, KeyBindingContextPredicate}; +use gpui::{Action, App, KeyBinding, KeyBindingContextPredicate}; use crate::{ desktop::{Hide, HideOthers, QuitApp}, @@ -342,6 +342,16 @@ impl HostOs { } } +/// The operating system this build runs on, for gpui's keystroke parsing +/// and display, which name the host explicitly. +pub(crate) fn host_os() -> gpui::OperatingSystem { + match HostOs::current() { + HostOs::Macos => gpui::OperatingSystem::Mac, + HostOs::Linux => gpui::OperatingSystem::Linux, + HostOs::Windows => gpui::OperatingSystem::Windows, + } +} + pub(crate) fn catalog() -> Vec { catalog_for(HostOs::current()) } @@ -1914,13 +1924,17 @@ fn add_vim_mode_slots(slots: &mut Vec, mode: &'static str, context pub(crate) fn bootstrap(cx: &mut App) { let bindings = catalog() .into_iter() - .map(|slot| build_binding(&slot, slot.default_sequence)) + .map(|slot| build_binding(&slot, slot.default_sequence, cx)) .collect::, _>>() .expect("the compiled-in shortcut catalog must always be valid"); install(bindings, cx); } -pub(crate) fn build_binding(slot: &ShortcutSlot, sequence: &str) -> Result { +pub(crate) fn build_binding( + slot: &ShortcutSlot, + sequence: &str, + cx: &App, +) -> Result { let predicate = slot .context .map(KeyBindingContextPredicate::parse) @@ -1933,15 +1947,7 @@ pub(crate) fn build_binding(slot: &ShortcutSlot, sequence: &str) -> Result>(); @@ -2017,7 +2025,7 @@ mod tests { assert!(windows.iter().all(|slot| slot.id != id), "{id} off Windows"); } for slot in &mac { - build_binding(slot, slot.default_sequence) + cx.update(|cx| build_binding(slot, slot.default_sequence, cx)) .unwrap_or_else(|error| panic!("macOS shortcut '{}' is invalid: {error}", slot.id)); } for (id, mac_sequence, other_sequence) in [ diff --git a/apps/maple-agent/app/src/shortcuts.rs b/apps/maple-agent/app/src/shortcuts.rs index 4c2fbd952..f7d056772 100644 --- a/apps/maple-agent/app/src/shortcuts.rs +++ b/apps/maple-agent/app/src/shortcuts.rs @@ -9,7 +9,7 @@ use gpui::{App, KeyBinding, Keystroke}; use crate::ui::{application_vim, text_input::vim_actions}; -use crate::keymap::{RENAMED_SLOT_IDS, RETIRED_SLOT_IDS, build_binding, catalog, install}; +use crate::keymap::{RENAMED_SLOT_IDS, RETIRED_SLOT_IDS, build_binding, catalog, host_os, install}; pub(crate) type ShortcutOverrides = BTreeMap>; @@ -92,10 +92,10 @@ impl ShortcutRuntime { /// if a hand-edited/old setting is invalid. Startup must always retain a /// complete map, including ordinary TextInput bindings. pub(crate) fn bootstrap(overrides: &ShortcutOverrides, cx: &mut App) -> Self { - let (prepared, last_error) = match prepare(overrides) { + let (prepared, last_error) = match prepare(overrides, cx) { Ok(prepared) => (prepared, None), Err(error) => ( - prepare(&ShortcutOverrides::new()) + prepare(&ShortcutOverrides::new(), cx) .expect("the compiled-in shortcut catalog must always be valid"), Some(error), ), @@ -128,7 +128,7 @@ impl ShortcutRuntime { overrides: &ShortcutOverrides, cx: &mut App, ) -> Result<(), String> { - let prepared = match prepare(overrides) { + let prepared = match prepare(overrides, cx) { Ok(prepared) => prepared, Err(error) => { self.snapshot.last_error = Some(error.clone()); @@ -179,7 +179,10 @@ pub(super) struct PreparedShortcuts { pub(super) compatibility_warning: Option, } -pub(super) fn prepare(overrides: &ShortcutOverrides) -> Result { +pub(super) fn prepare( + overrides: &ShortcutOverrides, + cx: &App, +) -> Result { let catalog = catalog(); let known_ids = catalog.iter().map(|slot| slot.id).collect::>(); let unknown = overrides @@ -219,7 +222,7 @@ pub(super) fn prepare(overrides: &ShortcutOverrides) -> Result Result { pub(super) fn parse_sequence(sequence: &str) -> Result, String> { let strokes = sequence .split_whitespace() - .map(Keystroke::parse) + .map(|stroke| Keystroke::parse_with_os(stroke, host_os())) .collect::, _>>() .map_err(|error| error.to_string())?; if strokes.is_empty() { @@ -272,7 +275,7 @@ pub(super) fn validate_sequence_for_context( if captures_ancestor_text_entry && strokes.first().is_some_and(Keystroke::is_ime_in_progress) { return Err(format!( "shortcut '{slot_id}' starts with the text-producing key '{}', which would intercept typing in text fields", - strokes[0].unparse() + strokes[0].unparse(host_os()) )); } Ok(()) @@ -529,7 +532,7 @@ mod tests { use gpui::{ Action, AppContext, Context, Entity, Focusable, IntoElement, KeyBindingContextPredicate, - Keystroke, ParentElement, Render, Styled, Window, div, px, + ParentElement, Render, Styled, Window, div, px, }; struct InputHost { @@ -542,9 +545,11 @@ mod tests { } } - #[test] - fn shipped_catalog_prepares_without_customization_conflicts() { - let prepared = prepare(&ShortcutOverrides::new()).unwrap(); + #[gpui::test] + fn shipped_catalog_prepares_without_customization_conflicts(cx: &mut gpui::TestAppContext) { + let prepared = cx + .update(|cx| prepare(&ShortcutOverrides::new(), cx)) + .unwrap(); assert_eq!(prepared.bindings.len(), crate::keymap::catalog().len()); assert!( prepared.rows.iter().all(|row| row.conflicts.is_empty()), @@ -552,11 +557,11 @@ mod tests { ); } - #[test] - fn overrides_saved_under_a_renamed_slot_still_apply() { + #[gpui::test] + fn overrides_saved_under_a_renamed_slot_still_apply(cx: &mut gpui::TestAppContext) { let mut overrides = ShortcutOverrides::new(); overrides.insert("project_menu.next".into(), Some("ctrl-n".into())); - let prepared = prepare(&overrides).unwrap(); + let prepared = cx.update(|cx| prepare(&overrides, cx)).unwrap(); assert_eq!(prepared.compatibility_warning, None); let row = prepared .rows @@ -576,12 +581,12 @@ mod tests { /// A build that removed a slot must not warn about the override a user /// saved for it; the next edit drops the stale key. - #[test] - fn an_override_for_a_retired_slot_is_dropped_quietly() { + #[gpui::test] + fn an_override_for_a_retired_slot_is_dropped_quietly(cx: &mut gpui::TestAppContext) { let mut overrides = ShortcutOverrides::new(); overrides.insert("chat.allow_permission".into(), None); overrides.insert("chat.new_task".into(), Some("secondary-shift-n".into())); - let prepared = prepare(&overrides).unwrap(); + let prepared = cx.update(|cx| prepare(&overrides, cx)).unwrap(); assert_eq!(prepared.compatibility_warning, None); assert!( prepared @@ -647,9 +652,13 @@ mod tests { ); } - #[test] - fn user_shadowing_is_reported_without_flagging_shipped_context_layers() { - let defaults = prepare(&ShortcutOverrides::new()).unwrap(); + #[gpui::test] + fn user_shadowing_is_reported_without_flagging_shipped_context_layers( + cx: &mut gpui::TestAppContext, + ) { + let defaults = cx + .update(|cx| prepare(&ShortcutOverrides::new(), cx)) + .unwrap(); assert!(defaults.rows.iter().all(|row| row.conflicts.is_empty())); assert_eq!( @@ -670,7 +679,7 @@ mod tests { let mut overrides = ShortcutOverrides::new(); overrides.insert("chat.new_task".into(), Some("secondary-q".into())); - let prepared = prepare(&overrides).unwrap(); + let prepared = cx.update(|cx| prepare(&overrides, cx)).unwrap(); let modified = prepared .rows .iter() @@ -896,9 +905,11 @@ mod tests { }); } - #[test] - fn ancestor_shortcuts_reject_text_producing_first_strokes() { - let defaults = prepare(&ShortcutOverrides::new()).unwrap(); + #[gpui::test] + fn ancestor_shortcuts_reject_text_producing_first_strokes(cx: &mut gpui::TestAppContext) { + let defaults = cx + .update(|cx| prepare(&ShortcutOverrides::new(), cx)) + .unwrap(); let snapshot = ShortcutSnapshot { generation: 1, rows: defaults.rows, @@ -922,7 +933,7 @@ mod tests { let mut unsafe_override = ShortcutOverrides::new(); unsafe_override.insert("chat.toggle_sidebar".into(), Some("g s".into())); - assert!(prepare(&unsafe_override).is_err()); + assert!(cx.update(|cx| prepare(&unsafe_override, cx)).is_err()); // Focus-owned contexts may intentionally consume bare keys. Keep this // open-ended so later contexts that explicitly exclude TextInput, such @@ -998,7 +1009,7 @@ mod tests { binding .keystrokes() .iter() - .map(|stroke| stroke.inner().unparse()) + .map(|stroke| stroke.inner().unparse(host_os())) .collect::>() .join(" ") }) @@ -1009,7 +1020,7 @@ mod tests { parse_sequence(sequence) .unwrap() .iter() - .map(Keystroke::unparse) + .map(|stroke| stroke.unparse(host_os())) .collect::>() .join(" ") } diff --git a/apps/maple-agent/app/src/ui/chat/mod.rs b/apps/maple-agent/app/src/ui/chat/mod.rs index 1149b51b5..27f82ae87 100644 --- a/apps/maple-agent/app/src/ui/chat/mod.rs +++ b/apps/maple-agent/app/src/ui/chat/mod.rs @@ -259,7 +259,7 @@ fn question_key_label(index: usize, window: &Window) -> SharedString { binding .keystrokes() .iter() - .map(ToString::to_string) + .map(|stroke| stroke.display(crate::keymap::host_os()).to_string()) .collect::>() .join(" ") }) @@ -7310,7 +7310,7 @@ impl Render for ChatScreen { .min_w_0() // Whatever the pointer is over, a wheel that nothing there // takes scrolls the transcript. - .on_scroll_wheel(cx.listener(Self::scroll_transcript_from_pane)) + .on_scroll(cx.listener(Self::scroll_transcript_from_pane)) .child(self.render_transcript(window, cx)) .children(self.render_send_preview()) .when( @@ -7374,7 +7374,7 @@ impl Render for ChatScreen { // The composer, its cards and the palette keep their // own wheel; the space beside them scrolls the // transcript. - .on_scroll_wheel(|_, _, cx| cx.stop_propagation()) + .on_scroll(|_, _, cx| cx.stop_propagation()) .children(self.render_btw_card(cx)) .children(self.render_subagents_card(cx)) .children(self.render_plan_card(cx)) @@ -7447,7 +7447,7 @@ impl Render for ChatScreen { // The header is the window's title bar; a wheel // over it scrolls nothing. self.render_header(sidebar_expansion, window, cx) - .on_scroll_wheel(|_, _, cx| cx.stop_propagation()), + .on_scroll(|_, _, cx| cx.stop_propagation()), ) .child( div() diff --git a/apps/maple-agent/app/src/ui/chat/sending.rs b/apps/maple-agent/app/src/ui/chat/sending.rs index eebd3bcb5..3ba74b570 100644 --- a/apps/maple-agent/app/src/ui/chat/sending.rs +++ b/apps/maple-agent/app/src/ui/chat/sending.rs @@ -321,7 +321,7 @@ impl ChatScreen { .overflow_y_scroll() // A long message scrolls inside its bubble; the // pane must not scroll the transcript as well. - .on_scroll_wheel(|_, _, cx| cx.stop_propagation()) + .on_scroll(|_, _, cx| cx.stop_propagation()) .px_4() .py_2() .rounded(theme::RADIUS_MD) diff --git a/apps/maple-agent/app/src/ui/chat/sidebar.rs b/apps/maple-agent/app/src/ui/chat/sidebar.rs index c42c6c77f..abc9a4430 100644 --- a/apps/maple-agent/app/src/ui/chat/sidebar.rs +++ b/apps/maple-agent/app/src/ui/chat/sidebar.rs @@ -3106,7 +3106,7 @@ impl Sidebar { } this.search_pointer_dismissal_pending = true; if this.search_input_focused(window, cx) { - window.blur(); + window.blur(cx); } })) .flex() @@ -3562,6 +3562,19 @@ impl Sidebar { self.hovered_entry.is_none() && self.hovered_section.is_none() } + /// Hover is never left on a row the pointer is no longer over: it is + /// clear, or it names the row drawn under `pointer`. + #[cfg(test)] + pub(super) fn hover_is_current_for_test(&self, pointer: gpui::Point) -> bool { + match self.hovered_entry { + None => self.hovered_section.is_none(), + Some(entry) => self + .list + .bounds_for_item(entry) + .is_some_and(|bounds| bounds.contains(&pointer)), + } + } + fn section_hovered(&self, section: SidebarHoverSection) -> bool { self.hovered_section == Some(section) || (section == SidebarHoverSection::Projects diff --git a/apps/maple-agent/app/src/ui/chat/tests.rs b/apps/maple-agent/app/src/ui/chat/tests.rs index 70fad5e66..ad81c79dd 100644 --- a/apps/maple-agent/app/src/ui/chat/tests.rs +++ b/apps/maple-agent/app/src/ui/chat/tests.rs @@ -7429,7 +7429,7 @@ mod state_tests { cx.simulate_mouse_move(wheel_at, None, gpui::Modifiers::default()); cx.run_until_parked(); let before = sidebar.update(cx, |sidebar, _| sidebar.list().logical_scroll_top()); - cx.simulate_event(gpui::ScrollWheelEvent { + cx.simulate_event(gpui::ScrollEvent { // Outside the panel so the wheel event reaches the list. position: wheel_at, delta: gpui::ScrollDelta::Pixels(gpui::point(px(0.), px(0.))), @@ -7545,8 +7545,10 @@ mod state_tests { } } - /// Wheel scroll and programmatic reveals clear hover without relying - /// on a pointer move to repair the virtualized list's old hover. + /// Wheel scroll and programmatic reveals never leave hover on a row + /// that moved away from the pointer, without a pointer move to repair + /// it: hover is clear, or gpui has moved it to the row now under the + /// pointer. #[gpui::test] fn test_section_chevrons_clear_on_stationary_scrolls(cx: &mut TestAppContext) { use crate::ui::chat::navigation::SidebarTarget; @@ -7579,7 +7581,7 @@ mod state_tests { sidebar.list().logical_scroll_top() }); match scroll { - "wheel" => cx.simulate_event(gpui::ScrollWheelEvent { + "wheel" => cx.simulate_event(gpui::ScrollEvent { position: pointer, delta: gpui::ScrollDelta::Pixels(gpui::point(px(0.), px(-20.))), ..Default::default() @@ -7604,8 +7606,8 @@ mod state_tests { "{scroll} moved the list" ); assert!( - sidebar.section_hover_is_clear_for_test(), - "{scroll} clears both fields" + sidebar.hover_is_current_for_test(pointer), + "{scroll} leaves no stale hover" ); }); } @@ -11314,7 +11316,7 @@ mod state_tests { }); // The list scrolls: a wheel moves the logical top down the rows. let center = cx.update(|window, _cx| window.bounds().center()); - cx.simulate_event(gpui::ScrollWheelEvent { + cx.simulate_event(gpui::ScrollEvent { position: center, delta: gpui::ScrollDelta::Pixels(gpui::point(px(0.), px(-300.))), ..Default::default() @@ -11377,7 +11379,7 @@ mod state_tests { } fn wheel_at(cx: &mut gpui::VisualTestContext, x: f32, y: f32, delta: gpui::ScrollDelta) { - cx.simulate_event(gpui::ScrollWheelEvent { + cx.simulate_event(gpui::ScrollEvent { position: gpui::point(px(x), px(y)), delta, ..Default::default() @@ -11738,7 +11740,7 @@ mod state_tests { ); let wheel_up = |cx: &mut gpui::VisualTestContext| { - cx.simulate_event(gpui::ScrollWheelEvent { + cx.simulate_event(gpui::ScrollEvent { position: center, delta: gpui::ScrollDelta::Pixels(gpui::point(px(0.), px(100.))), ..Default::default() diff --git a/apps/maple-agent/app/src/ui/chat/transcript.rs b/apps/maple-agent/app/src/ui/chat/transcript.rs index 5cee01d8d..6f29ecae0 100644 --- a/apps/maple-agent/app/src/ui/chat/transcript.rs +++ b/apps/maple-agent/app/src/ui/chat/transcript.rs @@ -220,7 +220,7 @@ impl ChatScreen { // not scroll it a second time. div() .size_full() - .on_scroll_wheel(|_, _, cx| cx.stop_propagation()) + .on_scroll(|_, _, cx| cx.stop_propagation()) .child(list), ), ) @@ -276,7 +276,7 @@ impl ChatScreen { /// the bottom, and the rows on screen reported for paging and images. pub(super) fn scroll_transcript_from_pane( &mut self, - event: &gpui::ScrollWheelEvent, + event: &gpui::ScrollEvent, _window: &mut Window, cx: &mut Context, ) { @@ -1800,7 +1800,7 @@ pub(super) fn render_question_card( .debug_selector(|| "question-card".to_string()) // Like the composer, the card keeps its own wheel; the space // beside it scrolls the transcript. - .on_scroll_wheel(|_, _, cx| cx.stop_propagation()) + .on_scroll(|_, _, cx| cx.stop_propagation()) .my_3() .w_full() .rounded(theme::RADIUS_MD) diff --git a/apps/maple-agent/app/src/ui/markdown/table.rs b/apps/maple-agent/app/src/ui/markdown/table.rs index 9b7095f85..c0611c82f 100644 --- a/apps/maple-agent/app/src/ui/markdown/table.rs +++ b/apps/maple-agent/app/src/ui/markdown/table.rs @@ -140,15 +140,9 @@ fn measure_columns( .runs .iter() .flat_map(|run| run.glyphs.iter()) - .map(|glyph| { - let ch = text - .get(glyph.index..) - .and_then(|rest| rest.chars().next()) - .unwrap_or('\0'); - (ch, glyph.position.x) - }); + .map(|glyph| (glyph.index, glyph.position.x)); column.max = column.max.max(layout.width); - column.min = column.min.max(longest_segment(glyphs, layout.width)); + column.min = column.min.max(longest_segment(text, glyphs, layout.width)); } } } @@ -183,74 +177,46 @@ fn cell_runs(base: &TextStyle, cell: &TableCell) -> Vec { } /// The widest stretch of a shaped line that wrapping keeps together, from -/// the glyphs' characters and x positions and the line's width. gpui -/// breaks before a word that follows a space and before any character -/// that is not part of a word, never inside a run of word characters -/// unless nothing else fits; a segment therefore runs from one such -/// break opportunity to the next and includes the space that trails it. -fn longest_segment(glyphs: impl IntoIterator, width: Pixels) -> Pixels { +/// the line's text, its glyphs' byte offsets and x positions, and its +/// width. gpui wraps only where the Unicode line breaking rules allow and +/// never ahead of the line's first visible character, so a segment runs +/// from one such opportunity to the next and includes the space that +/// trails it. The opportunities come from the call gpui's own +/// `LineWrapper::break_indices` makes, which is not public; a rule that +/// allowed more breaks than gpui's would let a word split. +fn longest_segment( + text: &str, + glyphs: impl IntoIterator, + width: Pixels, +) -> Pixels { + let mut breaks = icu_segmenter::LineSegmenter::new_for_non_complex_scripts(Default::default()) + .segment_str(text) + .peekable(); let mut longest = px(0.); let mut segment_start = px(0.); let mut seen_ink = false; - let mut prev = '\0'; - for (ch, x) in glyphs { - let opportunity = if is_word_char(ch) { - prev == ' ' && seen_ink - } else { - ch != ' ' && seen_ink - }; - if opportunity { + for (index, x) in glyphs { + // An opportunity inside a ligature falls to the glyph after it, + // which only makes the segment longer. + let mut opportunity = false; + while breaks.next_if(|at| *at <= index).is_some() { + opportunity = true; + } + if opportunity && seen_ink { longest = longest.max(x - segment_start); segment_start = x; } - if ch != ' ' { + if text + .get(index..) + .and_then(|rest| rest.chars().next()) + .is_some_and(|ch| ch != ' ') + { seen_ink = true; } - prev = ch; } longest.max(width - segment_start) } -/// The characters gpui's line wrapper keeps together in a word (its -/// `LineWrapper::is_word_char` at the pinned revision, which is not -/// public). A character missing here becomes a break opportunity to us -/// but not to gpui, which could let a word split, so keep the list at -/// least as wide as gpui's. -fn is_word_char(c: char) -> bool { - c.is_ascii_alphanumeric() - // Latin-1 Supplement, Latin Extended-A and -B. - || matches!(c, '\u{00C0}'..='\u{024F}') - // Cyrillic. - || matches!(c, '\u{0400}'..='\u{04FF}') - // Latin Extended Additional and combining diacritical marks. - || matches!(c, '\u{1E00}'..='\u{1EFF}') - || matches!(c, '\u{0300}'..='\u{036F}') - // Bengali. - || matches!(c, '\u{0980}'..='\u{09FF}') - // Punctuation that stays attached to a word. - || matches!( - c, - '-' | '_' - | '.' - | '\'' - | '’' - | '‘' - | '$' - | '%' - | '@' - | '#' - | '^' - | '~' - | ',' - | '=' - | ':' - | ';' - | '⋯' - ) - // Non-breaking glue. - || matches!(c, '\u{202F}' | '\u{00A0}' | '\u{2011}') -} - /// What every cell of one column tells the flex row, border-box. #[derive(Clone, Copy, Debug, PartialEq)] struct ColumnWidths { @@ -526,15 +492,20 @@ mod tests { use crate::ui::markdown; use gpui::{Context, Render, TestAppContext, VisualTestContext, size}; - fn glyphs(text: &str, advance: f32) -> Vec<(char, Pixels)> { - text.chars() + /// One glyph per character, each `advance` wide. + fn glyphs(text: &str, advance: f32) -> Vec<(usize, Pixels)> { + text.char_indices() .enumerate() - .map(|(ix, ch)| (ch, px(ix as f32 * advance))) + .map(|(ix, (offset, _))| (offset, px(ix as f32 * advance))) .collect() } fn segment(text: &str) -> Pixels { - longest_segment(glyphs(text, 10.), px(text.chars().count() as f32 * 10.)) + longest_segment( + text, + glyphs(text, 10.), + px(text.chars().count() as f32 * 10.), + ) } #[test] @@ -550,13 +521,15 @@ mod tests { } #[test] - fn punctuation_that_is_not_part_of_a_word_is_a_break_opportunity() { - // Before `/`: "src" and "/main.rs"; `.` stays inside the word. - assert_eq!(segment("src/main.rs"), px(80.)); + fn breaks_follow_the_unicode_line_breaking_rules() { + // After `/`: "src/" and "main.rs"; `.` stays inside the word. + assert_eq!(segment("src/main.rs"), px(70.)); // A hash of word characters never breaks. assert_eq!(segment("5d2f3b62d733"), px(120.)); // Trailing punctuation stays with its word. assert_eq!(segment("done, then"), px(60.)); + // Brackets hold what they wrap: nothing breaks around `(` or `)`. + assert_eq!(segment("f(x) y"), px(50.)); } #[test] diff --git a/apps/maple-agent/app/src/ui/popup.rs b/apps/maple-agent/app/src/ui/popup.rs index b5dbc5ade..246f6b6b7 100644 --- a/apps/maple-agent/app/src/ui/popup.rs +++ b/apps/maple-agent/app/src/ui/popup.rs @@ -415,7 +415,7 @@ impl Popup { if held { match target.and_then(|target| target.upgrade()) { Some(target) => window.focus(&target, cx), - None => window.blur(), + None => window.blur(cx), } } } @@ -1360,7 +1360,12 @@ fn item_row( .ok(); })); } - } else if popup.highlighted.as_ref() == Some(&hovered_id) { + } else if popup.highlighted.as_ref() == Some(&hovered_id) + // gpui also reports a row as no longer hovered when a key is + // pressed over it. The pointer has not left, so the row + // keeps the highlight the keyboard now works from. + && !window.last_input_was_keyboard() + { popup.hover = None; if !expanded { popup.highlight(None, cx); diff --git a/apps/maple-agent/app/src/ui/settings.rs b/apps/maple-agent/app/src/ui/settings.rs index fc76077cc..155c21b41 100644 --- a/apps/maple-agent/app/src/ui/settings.rs +++ b/apps/maple-agent/app/src/ui/settings.rs @@ -4141,7 +4141,14 @@ fn shortcut_conflict_label(conflict: &ShortcutConflict) -> String { fn portable_keystroke_token(keystroke: &gpui::Keystroke) -> String { let mut parts = Vec::with_capacity(6); - if keystroke.modifiers.secondary() { + // The secondary key of this build's host: Command on macOS, Control + // elsewhere. gpui's own `secondary` now needs the running app to ask. + let secondary = if cfg!(target_os = "macos") { + keystroke.modifiers.platform + } else { + keystroke.modifiers.control + }; + if secondary { parts.push("secondary".to_string()); } if keystroke.modifiers.control && cfg!(target_os = "macos") { diff --git a/apps/maple-agent/app/src/ui/settings/navigation.rs b/apps/maple-agent/app/src/ui/settings/navigation.rs index 0f69afbea..57749425e 100644 --- a/apps/maple-agent/app/src/ui/settings/navigation.rs +++ b/apps/maple-agent/app/src/ui/settings/navigation.rs @@ -1446,7 +1446,7 @@ mod tests { .expect("settings content"); let range = settings.update(cx, |this, _| this.pane_scroll.max_offset().y); assert!(range > px(0.), "General overflows its content area"); - cx.simulate_event(gpui::ScrollWheelEvent { + cx.simulate_event(gpui::ScrollEvent { // In the pane's gutter, so no row takes the wheel. position: gpui::point(content.left() + px(8.), content.center().y), delta: gpui::ScrollDelta::Pixels(gpui::point(px(0.), px(-200.))), diff --git a/apps/maple-agent/app/src/ui/text_input.rs b/apps/maple-agent/app/src/ui/text_input.rs index bb3047eea..ee56d7548 100644 --- a/apps/maple-agent/app/src/ui/text_input.rs +++ b/apps/maple-agent/app/src/ui/text_input.rs @@ -2006,7 +2006,7 @@ impl TextInput { /// wheel over a short input still reaches the surface behind it. fn on_scroll_wheel( &mut self, - event: &gpui::ScrollWheelEvent, + event: &gpui::ScrollEvent, _window: &mut Window, cx: &mut Context, ) { @@ -3380,7 +3380,7 @@ impl Render for TextInput { .on_mouse_up_out(gpui::MouseButton::Left, cx.listener(Self::on_mouse_up)) .on_mouse_move(cx.listener(Self::on_mouse_move)) .when(self.multiline, |el| { - el.on_scroll_wheel(cx.listener(Self::on_scroll_wheel)) + el.on_scroll(cx.listener(Self::on_scroll_wheel)) }) .w_full() .when(self.multiline && self.fill_height, |el| el.h_full()) @@ -3649,7 +3649,7 @@ mod tests { // A wheel over the input moves the view up and stays put: prepaint // must not snap back to the cursor without a new edit. - cx.simulate_event(gpui::ScrollWheelEvent { + cx.simulate_event(gpui::ScrollEvent { position: point(px(150.), px(10.)), delta: gpui::ScrollDelta::Pixels(gpui::point(px(0.), px(50.))), ..Default::default() From b27807c75c9f1705fc68ec12a831e05a544ba997 Mon Sep 17 00:00:00 2001 From: Anthony Ronning <101225832+AnthonyRonning@users.noreply.github.com> Date: Wed, 11 Nov 2026 12:33:17 -0800 Subject: [PATCH 02/19] Agent: drop the terminal experiment from the gpui pin note The pin no longer has to match gpui-libghostty; that experiment was dropped. Co-Authored-By: Claude --- apps/maple-agent/app/Cargo.toml | 3 --- 1 file changed, 3 deletions(-) diff --git a/apps/maple-agent/app/Cargo.toml b/apps/maple-agent/app/Cargo.toml index 39666ca18..406a2b210 100644 --- a/apps/maple-agent/app/Cargo.toml +++ b/apps/maple-agent/app/Cargo.toml @@ -50,9 +50,6 @@ maple-agent = { path = "../crates/maple-agent", default-features = false } maple-billing = { path = "../crates/maple-billing" } maple-agent-updater = { path = "../crates/maple-agent-updater" } # gpui is pinned to one Zed commit; crates.io 0.2.2 is older than it. -# gpui-libghostty (the embedded terminal Ben is preparing) binds to the -# application's gpui but is tested against cc053a4a, so build its bindings -# against this revision before the terminal lands. # `stacker` keeps gpui growing the stack under deep element trees, which it # did unconditionally before this revision. gpui = { version = "0.2.2", git = "https://github.com/zed-industries/zed", rev = "c7bea343838f42b4c14151393e41f0bbe033c95e", features = ["stacker"], optional = true } From f34a561b0a77bf910233e114e2389e86e9f59f02 Mon Sep 17 00:00:00 2001 From: Anthony Ronning <101225832+AnthonyRonning@users.noreply.github.com> Date: Wed, 11 Nov 2026 12:46:46 -0800 Subject: [PATCH 03/19] Agent: draw gpui's frame times with MAPLE_FRAME_STATS The newer gpui can paint how long each frame took to build and paint over the window. Turn its profiler on, as Zed does, and show that overlay in the main window when MAPLE_FRAME_STATS is set; `full` adds percentiles over the last 1000 frames. The performance check gains a step that uses it, so "smooth" can be a number. One new registry dependency, hdrhistogram 7.5.4, the version in Zed's lockfile, published well over seven days ago. Co-Authored-By: Claude --- apps/maple-agent/Cargo.lock | 11 +++++++++++ apps/maple-agent/app/Cargo.toml | 6 ++++-- apps/maple-agent/app/src/desktop.rs | 16 +++++++++++++++- apps/maple-agent/docs/performance-check.md | 7 +++++++ 4 files changed, 37 insertions(+), 3 deletions(-) diff --git a/apps/maple-agent/Cargo.lock b/apps/maple-agent/Cargo.lock index 2df1207b0..83875df37 100644 --- a/apps/maple-agent/Cargo.lock +++ b/apps/maple-agent/Cargo.lock @@ -3839,6 +3839,7 @@ dependencies = [ "gpui_macros", "gpui_shared_string", "gpui_util", + "hdrhistogram", "heapless 0.9.3", "http_client", "icu_segmenter", @@ -4286,6 +4287,16 @@ dependencies = [ "hashbrown 0.17.1", ] +[[package]] +name = "hdrhistogram" +version = "7.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "765c9198f173dd59ce26ff9f95ef0aafd0a0fe01fb9d72841bc5066a4c06511d" +dependencies = [ + "byteorder", + "num-traits", +] + [[package]] name = "heapless" version = "0.7.17" diff --git a/apps/maple-agent/app/Cargo.toml b/apps/maple-agent/app/Cargo.toml index 406a2b210..da1f6b937 100644 --- a/apps/maple-agent/app/Cargo.toml +++ b/apps/maple-agent/app/Cargo.toml @@ -51,8 +51,10 @@ maple-billing = { path = "../crates/maple-billing" } maple-agent-updater = { path = "../crates/maple-agent-updater" } # gpui is pinned to one Zed commit; crates.io 0.2.2 is older than it. # `stacker` keeps gpui growing the stack under deep element trees, which it -# did unconditionally before this revision. -gpui = { version = "0.2.2", git = "https://github.com/zed-industries/zed", rev = "c7bea343838f42b4c14151393e41f0bbe033c95e", features = ["stacker"], optional = true } +# did unconditionally before this revision. `profiler` keeps gpui's frame +# timings, which `MAPLE_FRAME_STATS` draws over the window; Zed ships with +# both on. +gpui = { version = "0.2.2", git = "https://github.com/zed-industries/zed", rev = "c7bea343838f42b4c14151393e41f0bbe033c95e", features = ["stacker", "profiler"], optional = true } # The application factory for that gpui revision; it lives one crate over. # `font-kit` selects the native text system on macOS; without it this gpui # revision draws no text at all. diff --git a/apps/maple-agent/app/src/desktop.rs b/apps/maple-agent/app/src/desktop.rs index c97b9ec1f..eb45f4d28 100644 --- a/apps/maple-agent/app/src/desktop.rs +++ b/apps/maple-agent/app/src/desktop.rs @@ -2963,6 +2963,19 @@ enum QuitPromptKind { UnknownActivity, Failed(UiText), } +/// Draw gpui's frame-time overlay over `window` when `MAPLE_FRAME_STATS` is +/// set: `full` for the detailed panel, any other value for frame time +/// alone. A developer aid for judging what a change costs per frame; it +/// paints straight into the scene, so showing it asks for no extra frames. +fn show_frame_stats(window: &mut Window) { + let mode = match std::env::var("MAPLE_FRAME_STATS").as_deref() { + Err(_) | Ok("" | "0") => return, + Ok("full") => gpui::DebugFrameOverlayMode::Full, + Ok(_) => gpui::DebugFrameOverlayMode::Minimal, + }; + window.set_debug_frame_overlay_mode(mode); +} + struct QuitPrompt { kind: QuitPromptKind, closing: bool, @@ -3967,7 +3980,8 @@ pub fn run() { let root_settings = startup_settings.clone(); let root_updater = updater.clone(); let window = cx - .open_window(main_window_options(window_placement), move |_, cx| { + .open_window(main_window_options(window_placement), move |window, cx| { + show_frame_stats(window); cx.new(move |cx| MapleApp { backend: root_backend, screen: Screen::Restoring, diff --git a/apps/maple-agent/docs/performance-check.md b/apps/maple-agent/docs/performance-check.md index 6357fd0c5..1570729c8 100644 --- a/apps/maple-agent/docs/performance-check.md +++ b/apps/maple-agent/docs/performance-check.md @@ -18,6 +18,13 @@ machine before and after a change to the Agent's runtime, and compare. whether the transcript scrolls smoothly. Then read the memory in KB with `ps -o rss= -p "$pid"`. +3. To put numbers on "smoothly", start any build with `MAPLE_FRAME_STATS=1`. + gpui then draws the time each frame took to build and paint in a corner + of the main window; `MAPLE_FRAME_STATS=full` adds percentiles over the + last 1000 frames. A frame has 16.7 ms at 60 Hz and 8.3 ms at 120 Hz. + Compare the same interaction before and after a change: a long answer + streaming, a hover sweep down the sidebar, the composer expanding. + | Date | Build | Machine | Window open | Memory after a long answer | Streaming | |---|---|---|---|---|---| | 2026-10-07 | `93a235d2` | Apple M3 Max virtual machine, macOS 27.0.1 | 729 ms | 187 MB | Smooth | From acdad798acfdbcef63a87e6434fc890bff17b4d4 Mon Sep 17 00:00:00 2001 From: Matthew Ball <13823657+matthewrball@users.noreply.github.com> Date: Wed, 11 Nov 2026 12:54:44 -0800 Subject: [PATCH 04/19] Agent: add purposeful motion across chat, composer, menus and settings Matt's motion work from #1515, squashed at a587cdaf and carried onto the newer gpui with no change in behaviour. His branch stays as it is. It adds short, interruptible motion across the app: messages arrive instead of appearing, the composer travels between the empty state and the thread, hover and controls ease, menus open from their trigger, dialogs rise in and Settings sections fade. The rules and tokens are in docs/motion.md, and ui/motion.rs implements them. Changes from his head: - Two merge conflicts with the gpui bump, resolved to his side (the cards above the composer, the send preview). - gpui's rename of on_scroll_wheel to on_scroll in the code he added. - Four test fixtures gained the session summary's thinking_level field, which master added after his branch. Co-Authored-By: Claude --- apps/maple-agent/CLAUDE.md | 13 + apps/maple-agent/app/src/desktop.rs | 95 +- apps/maple-agent/app/src/ui/chat/composer.rs | 722 +++++++- apps/maple-agent/app/src/ui/chat/computers.rs | 10 + apps/maple-agent/app/src/ui/chat/dialogs.rs | 12 +- apps/maple-agent/app/src/ui/chat/feedback.rs | 6 +- apps/maple-agent/app/src/ui/chat/mod.rs | 506 ++++-- .../app/src/ui/chat/project_folder.rs | 16 +- apps/maple-agent/app/src/ui/chat/queue.rs | 25 +- apps/maple-agent/app/src/ui/chat/sending.rs | 226 ++- apps/maple-agent/app/src/ui/chat/sidebar.rs | 443 ++++- .../app/src/ui/chat/sidebar_computers.rs | 36 +- apps/maple-agent/app/src/ui/chat/speech.rs | 11 +- apps/maple-agent/app/src/ui/chat/tests.rs | 4 + .../maple-agent/app/src/ui/chat/transcript.rs | 1299 +++++++++++++- apps/maple-agent/app/src/ui/login.rs | 4 +- apps/maple-agent/app/src/ui/motion.rs | 1596 ++++++++++++++++- apps/maple-agent/app/src/ui/plan_gate.rs | 19 +- apps/maple-agent/app/src/ui/popup.rs | 272 ++- apps/maple-agent/app/src/ui/settings.rs | 106 +- .../app/src/ui/settings/api_credits.rs | 74 +- apps/maple-agent/app/src/ui/text_input.rs | 360 +++- apps/maple-agent/app/src/ui/titlebar.rs | 12 +- .../app/src/ui/update_confirmation.rs | 39 +- apps/maple-agent/app/src/ui/widgets.rs | 388 ++-- apps/maple-agent/docs/brand.md | 4 +- apps/maple-agent/docs/motion.md | 128 ++ 27 files changed, 5657 insertions(+), 769 deletions(-) create mode 100644 apps/maple-agent/docs/motion.md diff --git a/apps/maple-agent/CLAUDE.md b/apps/maple-agent/CLAUDE.md index a4c5c5458..af5880640 100644 --- a/apps/maple-agent/CLAUDE.md +++ b/apps/maple-agent/CLAUDE.md @@ -118,6 +118,19 @@ popup before a nested one). The popup handles the rest: A text field inside a menu that goes away calls `Popup::refocus`, so the menu keeps the keyboard. Menu keys live in the keymap's `Menu` context. +## Motion + +Animate through `ui/motion.rs` only; [motion](docs/motion.md) holds the +tokens and rules. Motion never delays input, retargets from the value on +screen, closes menus and dialogs at once, and settles immediately under +reduced motion. Streaming text, typing, and keyboard navigation do not +animate. Rows inside `gpui::list` time their entrance from view state, not +element state, so they never replay when scrolled back into view. Never put +opacity on an ancestor of a cached view: its replayed paint keeps the +opacity of its first frame. Paint a cover over it instead, as `swap_in` +does, unless its bounds or content mask change on every frame of the fade +and again at rest, as in the sidebar collapse. + ## Accessibility GPUI only reports elements with both an id and a role, and it builds the tree diff --git a/apps/maple-agent/app/src/desktop.rs b/apps/maple-agent/app/src/desktop.rs index eb45f4d28..e01349fdc 100644 --- a/apps/maple-agent/app/src/desktop.rs +++ b/apps/maple-agent/app/src/desktop.rs @@ -2383,6 +2383,20 @@ impl Render for MapleApp { cx.refresh_windows(); } let titlebar = self.titlebar.clone(); + // The screen fades in when it changes kind; the first screen and a + // screen that only re-renders draw at once. + let screen_kind = if self.updater.restart_path().is_some() { + "restart" + } else { + match &self.screen { + Screen::Restoring => "restoring", + Screen::StoreGate(_) => "store-gate", + Screen::Login(_) => "login", + Screen::Chat(_) => "chat", + Screen::Settings(_) => "settings", + Screen::PlanGate(_) => "plan-gate", + } + }; let root = div() .relative() .size_full() @@ -2397,7 +2411,7 @@ impl Render for MapleApp { // on transcript/composer via `typography::chat_reading`. .text_sm() .child(titlebar) - .child( + .child(ui::motion::swap_in( div() .flex_1() .min_h_0() @@ -2442,7 +2456,10 @@ impl Render for MapleApp { Screen::PlanGate(gate) => gate.clone().into_any_element(), } }), - ); + "maple-screen", + screen_kind, + gpui::rgb(ui::theme::bg_app()), + )); #[cfg(target_os = "linux")] let root = root.children(self.restart_confirmation.clone()); root @@ -5337,6 +5354,80 @@ mod tests { assert!(return_to_window(true, cx)); } + /// Settings and back brings the chat's sidebar back with its task rows. + /// The screen fade covers the whole window, so a regression there would + /// show as a sidebar whose rows never return. + #[gpui::test] + fn settings_and_back_keeps_the_sidebar_task_rows(cx: &mut gpui::TestAppContext) { + struct Host(Entity); + impl Render for Host { + fn render(&mut self, _: &mut Window, _: &mut Context) -> impl IntoElement { + div().size_full().child(self.0.clone()) + } + } + let settings = crate::settings::SETTINGS_IO_LOCK.lock(); + let app = project_shell_locked(cx, &settings); + let chat = app.read_with(cx, |app, _| app.local_chat.clone().expect("local chat")); + chat.update(cx, |chat, cx| { + chat.seed_sessions_for_test( + vec![maple_agent::agent::AgentSessionSummary { + web_enabled: true, + permission_mode: Default::default(), + state: maple_agent::agent::AgentTaskState::Active, + acp: false, + id: "s1".into(), + title: "First task".into(), + project_root: "/same/project".into(), + created_ms: 0, + updated_ms: 0, + message_count: 1, + model: None, + thinking_level: None, + }], + cx, + ) + }); + let (_, cx) = cx.add_window_view(|_, _| Host(app.clone())); + cx.simulate_resize(size(px(1100.), px(850.))); + cx.run_until_parked(); + assert!( + cx.debug_bounds("session-s1").is_some(), + "the task row shows" + ); + + app.update(cx, |app, cx| app.show_settings(Section::General, cx)); + cx.run_until_parked(); + assert!( + cx.debug_bounds("session-s1").is_none(), + "Settings replaces the chat" + ); + let snapshot = app.read_with(cx, |app, cx| match &app.screen { + Screen::Settings(screen) => screen.read(cx).settings_snapshot(), + _ => panic!("expected Settings"), + }); + let start = std::time::Instant::now(); + ui::motion::set_test_now(Some(start)); + app.update(cx, |app, cx| app.close_settings(snapshot, cx)); + cx.run_until_parked(); + // Let the screen fade and anything the sidebar eases settle. + for step in 1..=4 { + ui::motion::set_test_now(Some(start + ui::motion::PANEL * step)); + cx.update(|window, cx| { + window.simulate_next_frame(cx); + }); + cx.run_until_parked(); + } + // A cached view replays its last paint without recording debug + // bounds, so draw every view afresh before looking for the row. + cx.update(|_, cx| cx.refresh_windows()); + cx.run_until_parked(); + assert!( + cx.debug_bounds("session-s1").is_some(), + "the task row is back after Settings" + ); + ui::motion::set_test_now(None); + } + #[gpui::test] fn a_free_guest_gets_its_account_id_in_the_gate(cx: &mut gpui::TestAppContext) { let settings = crate::settings::SETTINGS_IO_LOCK.lock(); diff --git a/apps/maple-agent/app/src/ui/chat/composer.rs b/apps/maple-agent/app/src/ui/chat/composer.rs index 21528030a..5cddd0ad4 100644 --- a/apps/maple-agent/app/src/ui/chat/composer.rs +++ b/apps/maple-agent/app/src/ui/chat/composer.rs @@ -88,6 +88,57 @@ fn mode_note(mode: AgentPermissionMode) -> &'static str { } } +/// Heights the composer expand/shrink transition eases between, recorded +/// as each frame is laid out so the next one can start from the screen. +#[derive(Clone, Copy, Default)] +pub(super) struct ComposerFrame { + /// The composer region: cards, composer box, palette, padding. + pub(super) region: Option, + /// The region's top in the window, so the composer can glide from + /// there when the empty state gives way to a conversation, or back. + pub(super) top: Option, + /// The height the region takes when expanded. + pub(super) room: Option, + /// The empty state's title and privacy line at rest, which fold away + /// while the composer expands there. + pub(super) title: Option, + pub(super) privacy: Option, +} + +/// Stores a measured element's bounds in a [`ComposerFrame`]. +pub(super) type Record = fn(&mut ComposerFrame, gpui::Bounds, &Window); + +/// A paint-free canvas over its parent that hands the parent's bounds to +/// `record` at prepaint, for the next frame's composer transition. +pub(super) fn measure( + frame: &std::rc::Rc>, + record: Record, +) -> impl IntoElement { + let frame = frame.clone(); + gpui::canvas( + move |bounds, window, _| { + let mut measured = frame.get(); + record(&mut measured, bounds, window); + frame.set(measured); + }, + |_, _, _, _| {}, + ) + .absolute() + .inset_0() +} + +/// The composer region, painted gliding from window y `from` toward its +/// place while `glide` runs (see [`ChatScreen::composer_glide_frame`]). +pub(super) fn glide( + region: impl IntoElement, + glide: Option<(gpui::Pixels, f32)>, +) -> gpui::AnyElement { + match glide { + Some((from, progress)) => motion::glide_from(region, from, progress).into_any_element(), + None => region.into_any_element(), + } +} + impl ChatScreen { pub(super) fn render_header( &self, @@ -197,8 +248,9 @@ impl ChatScreen { .w(px(14.)) .h(px(14.)) .debug_selector(|| "navigation-loading-slot".to_string()) + // A task that opens quickly never flashes the spinner. .when( - self.loading_session.is_some() || self.root_selecting || self.booting, + self.loading_spinner_due() || self.root_selecting || self.booting, |slot| slot.child(spinner("navigation-loading", px(14.), theme::text_muted())), ), ) @@ -273,10 +325,10 @@ impl ChatScreen { /// `button` as the opener of `popup`, with `menu` attached below or /// above it while the popup is open. - fn with_menu( + fn with_menu( &self, popup: ChatPopup, - button: gpui::Stateful
, + button: E, placement: Placement, window: &mut Window, cx: &mut Context, @@ -447,11 +499,15 @@ impl ChatScreen { .items_center() .justify_center() .rounded(theme::RADIUS_LG) - .hover(|style| { - style - .bg(gpui::rgb(theme::accent_container())) - .cursor_pointer() + .map(|element| { + let rest: gpui::Hsla = gpui::transparent_black(); + crate::ui::motion::hover_background( + element, + rest, + gpui::rgb(theme::bg_sidebar_pill()), + ) }) + .hover(|style| style.cursor_pointer()) .active(|style| style.bg(gpui::rgb(theme::bg_sidebar_pill()))) .when(self.attachment_picking, |el| el.opacity(0.5)) .tooltip(widgets::tooltip(tr("chat-attach"), None)) @@ -472,11 +528,23 @@ impl ChatScreen { .justify_center() .rounded(theme::RADIUS_LG) .when(recording, |el| el.bg(gpui::rgb(theme::status_error()))) - .hover(|style| { - style - .bg(gpui::rgb(theme::accent_container())) - .cursor_pointer() + .map(|element| { + let rest: gpui::Hsla = if recording { + gpui::rgb(theme::status_error()).into() + } else { + gpui::transparent_black() + }; + crate::ui::motion::hover_background( + element, + rest, + gpui::rgb(if recording { + theme::status_error() + } else { + theme::bg_sidebar_pill() + }), + ) }) + .hover(|style| style.cursor_pointer()) .when(transcribing, |el| el.opacity(0.5)) .tooltip(widgets::tooltip( if recording { @@ -823,11 +891,19 @@ impl ChatScreen { .when(is_selected, |row| { row.bg(gpui::rgb(theme::bg_sidebar_row_selected())) }) - .hover(|style| { - style - .bg(gpui::rgb(theme::bg_sidebar_row_hover())) - .cursor_pointer() + .map(|element| { + let rest: gpui::Hsla = if is_selected { + gpui::rgb(theme::bg_sidebar_row_selected()).into() + } else { + gpui::transparent_black() + }; + crate::ui::motion::hover_background( + element, + rest, + gpui::rgb(theme::bg_sidebar_row_hover()), + ) }) + .hover(|style| style.cursor_pointer()) .on_click(move |_event, _window, cx: &mut gpui::App| { chat.update(cx, |chat, cx| chat.complete_slash_command(&name, cx)) .ok(); @@ -993,7 +1069,14 @@ impl ChatScreen { .cursor_pointer() .text_sm() .text_color(gpui::rgb(theme::text_muted())) - .hover(|style| style.bg(gpui::rgb(theme::bg_elevated()))) + .map(|element| { + let rest: gpui::Hsla = gpui::transparent_black(); + crate::ui::motion::hover_background( + element, + rest, + gpui::rgb(theme::bg_elevated()), + ) + }) .on_click(cx.listener(|this, _event, _window, cx| { this.close_side_thread(cx); })) @@ -1139,7 +1222,10 @@ impl ChatScreen { .px_3() .py_2() .cursor_pointer() - .hover(|style| style.bg(gpui::rgb(theme::bg_elevated()))) + .map(|element| { + let rest: gpui::Hsla = gpui::transparent_black(); + crate::ui::motion::hover_background(element, rest, gpui::rgb(theme::bg_elevated())) + }) .on_click(cx.listener(|this, _event, _window, cx| { this.toggle_plan_collapsed(cx); })) @@ -1231,6 +1317,83 @@ impl ChatScreen { (row, false) } + /// While the composer eases between the height of its text and + /// expanded: how far toward expanded it is, and the region's height + /// for this frame, from heights measured last frame. `None` at rest; + /// once a transition lands the field goes back to its resting fill. + pub(super) fn composer_resize_frame( + &mut self, + window: &mut Window, + cx: &mut Context, + ) -> Option<(f32, gpui::Pixels)> { + let transition = self.composer_resize?; + let now = motion::now(); + let frame = self.composer_frame.get(); + let sample = (!cx.reduce_motion() && transition.is_moving(now)) + .then(|| { + let progress = transition.value(now); + // The field fills the box throughout, so the box at the + // height of its text is the region less the field's spare + // height. Its row is never shorter than the expand button + // beside it (`size_6`). + let (drawn, text) = self.composer.as_ref()?.read(cx).drawn_and_text_height()?; + let row = text.max(window.rem_size() * 1.5); + let natural = frame.region? - (drawn - row).max(gpui::px(0.)); + let room = frame.room?; + Some((progress, natural + (room - natural) * progress)) + }) + .flatten(); + if sample.is_some() { + window.request_animation_frame(); + return sample; + } + self.composer_resize = None; + let expanded = self.composer_expanded; + if let Some(composer) = self.composer.clone() { + composer.update(cx, |input, cx| input.set_fill_height(expanded, cx)); + } + None + } + + /// When the empty state gives way to a conversation (the first message, + /// or opening a task) or back (New Task), the composer glides from where + /// it was last drawn to its new place over [`motion::PANEL`]. Returns + /// the window y it starts from and how far along it is; `None` at rest, + /// on the first frame, and under reduced motion. + pub(super) fn composer_glide_frame( + &mut self, + empty: bool, + window: &mut Window, + cx: &mut Context, + ) -> Option<(gpui::Pixels, f32)> { + let now = motion::now(); + let reduced = cx.reduce_motion(); + if self.composer_was_empty.is_some_and(|was| was != empty) { + self.composer_glide = self + .composer_frame + .get() + .top + .filter(|_| !reduced) + .map(|from| (from, now)); + } + self.composer_was_empty = Some(empty); + let glide = self.composer_glide.and_then(|(from, started)| { + let progress = motion::progress(started, motion::PANEL, now, reduced); + (progress < 1.).then_some((from, progress)) + }); + if glide.is_some() { + window.request_animation_frame(); + } else { + self.composer_glide = None; + } + glide + } + + /// The composer box lays out expanded: at rest there, or on the way. + pub(super) fn composer_fills(&self) -> bool { + self.composer_expanded || self.composer_resize.is_some() + } + /// The selected task's latest turn ended out of usage and nothing has /// gone out since. A window that does not hold the tail (paged back /// into history, or with live rows past its budget) cannot tell. @@ -1349,6 +1512,29 @@ impl ChatScreen { .then(|| self.render_usage_tray(cx)); let queue_chips = self.render_queue(cx); let expanded = self.composer_expanded; + // Layout follows the box while it eases; the icon and tooltip + // name the state it is heading to. + let fills = self.composer_fills(); + // Send ↔ Stop and the send fill's enabled state ease over TOGGLE. + let (send_stop, send_ready) = { + let now = motion::now(); + let reduced = cx.reduce_motion(); + let step = |tween: &mut motion::Tween, on: bool| { + tween.step( + if on { 1. } else { 0. }, + motion::TOGGLE, + motion::ease_out_cubic, + now, + reduced, + ) + }; + let (stop, stop_moving) = step(&mut self.send_stop, show_stop); + let (ready, ready_moving) = step(&mut self.send_ready, can_send); + if stop_moving || ready_moving { + window.request_animation_frame(); + } + (stop, ready) + }; let composer = self.composer.clone(); let vim_badge = composer .as_ref() @@ -1410,7 +1596,7 @@ impl ChatScreen { .flex_col() .relative() .debug_selector(|| "composer-box".to_string()) - .when(expanded, |container| container.flex_1().min_h_0()) + .when(fills, |container| container.flex_1().min_h_0()) .rounded(theme::RADIUS_XL) .bg(gpui::rgb(theme::bg_app())) .border_1() @@ -1464,7 +1650,7 @@ impl ChatScreen { container.child(div().flex().flex_wrap().gap_2().px_4().pt_4().children( drafts.iter().map(|attachment| { let id = attachment.id; - div() + let chip = div() .relative() .max_w(px(260.)) .h_16() @@ -1533,7 +1719,15 @@ impl ChatScreen { this.remove_attachment(id, cx); })) .child(icon("x", px(10.), theme::text_primary())), - ) + ); + // A file joining the draft settles in; removing + // one is immediate. + motion::slide_in( + chip, + ("draft-attachment", id as usize), + motion::ENTER, + gpui::point(px(0.), motion::RISE), + ) }), )) }) @@ -1544,47 +1738,53 @@ impl ChatScreen { .px_4() .pt_4() .pb_2() - .when(expanded, |row| row.flex_1().min_h_0()) + .when(fills, |row| row.flex_1().min_h_0()) .child( crate::ui::typography::chat_reading(div()) .flex_1() .min_w_0() - .when(expanded, |cell| cell.h_full()) + .when(fills, |cell| cell.h_full()) .text_color(gpui::rgb(theme::text_primary())) // The first send remains visibly editable until // task creation settles; keep its real focus path. .children(composer), ) - .child( + .child({ + let label = if expanded { + tr("chat-shrink-composer") + } else { + tr("chat-expand-composer") + }; div() .id("composer-expand") + .role(gpui::Role::Button) + .aria_label(label.clone()) .size_6() .flex() .items_center() .justify_center() .rounded(theme::RADIUS_SM) - .hover(|style| { - style - .bg(gpui::rgb(theme::accent_container())) - .cursor_pointer() + .map(|element| { + let rest: gpui::Hsla = gpui::transparent_black(); + crate::ui::motion::hover_background( + element, + rest, + gpui::rgb(theme::bg_sidebar_pill()), + ) }) - .tooltip(widgets::tooltip( - if expanded { - tr("chat-shrink-composer") - } else { - tr("chat-expand-composer") - }, - None, - )) + .hover(|style| style.cursor_pointer()) + .tooltip(widgets::tooltip(label, None)) .on_click(cx.listener(|this, _event, _window, cx| { this.toggle_composer_expanded(cx); })) - .child(icon( - if expanded { "minimize-2" } else { "maximize-2" }, + .child(motion::icon_swap( + "composer-expand-icon", + expanded, + ["maximize-2", "minimize-2"], px(14.), theme::text_muted(), - )), - ), + )) + }), ) .child( div() @@ -1639,52 +1839,76 @@ impl ChatScreen { } else { tr("chat-send") }; + // The fills cross-fade and the arrow scales while + // the handler, role and label switch at once. + let send_layer = (send_stop < 1.).then(|| { + div() + .absolute() + .inset_0() + .flex() + .items_center() + .justify_center() + .rounded_full() + .bg(gpui::linear_gradient( + 180., + gpui::linear_color_stop(gpui::rgb(theme::send_top()), 0.), + gpui::linear_color_stop(gpui::rgb(theme::send_bottom()), 1.), + )) + .opacity((0.4 + 0.6 * send_ready) * (1. - send_stop)) + .child(if disabled { + spinner("send-booting", px(16.), theme::on_accent()) + } else { + let scale = 1. - 0.4 * send_stop; + icon("arrow-up", px(16.), theme::on_accent()) + .with_transformation(gpui::Transformation::scale( + gpui::size(scale, scale), + )) + .into_any_element() + }) + }); + let stop_layer = (send_stop > 0.).then(|| { + div() + .absolute() + .inset_0() + .flex() + .items_center() + .justify_center() + .rounded_full() + .bg(gpui::rgb(theme::status_error())) + .opacity(send_stop) + .child( + div() + .size_3() + .rounded(theme::RADIUS_SM) + .bg(gpui::rgb(theme::bg_app())), + ) + }); div() .id(button_id) .debug_selector(move || button_id.to_string()) .role(gpui::Role::Button) .aria_label(button_label.clone()) + .relative() .flex_none() .size_8() - .flex() - .items_center() - .justify_center() .rounded_full() + .children(send_layer) + .children(stop_layer) .when(show_stop, |el| { - el.bg(gpui::rgb(theme::status_error())) - .hover(|style| style.opacity(0.85).cursor_pointer()) + el.hover(|style| style.opacity(0.85).cursor_pointer()) .active(|style| style.opacity(0.7)) .tooltip(widgets::tooltip(tr("chat-stop-run"), None)) .on_click(cx.listener(|this, _event, _window, cx| { this.stop(cx); })) - .child( - div() - .size_3() - .rounded(theme::RADIUS_SM) - .bg(gpui::rgb(theme::bg_app())), - ) }) - .when(!show_stop, |el| { - el.bg(gpui::linear_gradient( - 180., - gpui::linear_color_stop(gpui::rgb(theme::send_top()), 0.), - gpui::linear_color_stop(gpui::rgb(theme::send_bottom()), 1.), - )) - .when(!can_send, |el| el.opacity(0.4)) - .when(can_send, |el| { - el.hover(|style| style.opacity(0.9).cursor_pointer()) - .active(|style| style.opacity(0.75)) - .tooltip(widgets::tooltip(button_label.clone(), Some("↵"))) - .on_click(cx.listener(|this, _event, _window, cx| { - this.send_inner(cx); - })) - }) - .child(if disabled { - spinner("send-booting", px(16.), theme::on_accent()) - } else { - icon("arrow-up", px(16.), theme::on_accent()).into_any_element() - }) + .when(!show_stop && can_send, |el| { + el.hover(|style| style.opacity(0.9).cursor_pointer()) + .active(|style| style.opacity(0.75)) + .tooltip(widgets::tooltip(button_label.clone(), Some("↵"))) + .on_click(cx.listener(|this, _event, _window, cx| { + this.send_inner(cx); + })) }) }), ); @@ -1696,7 +1920,10 @@ impl ChatScreen { .flex() .flex_col() .gap_2() - .when(expanded, |container| container.flex_1().min_h_0()) + // The picker row comes with the box, so the pair fills the + // region for as long as the box does: expanded, and on the way + // there and back, not only once expanded. + .when(fills, |container| container.flex_1().min_h_0()) .child(self.render_project_context(window, cx).flex_none()) .child(composer_box) } @@ -1764,7 +1991,7 @@ fn chip( detail: Option<(SharedString, gpui::Hsla, usize)>, chevron: bool, active: bool, -) -> gpui::Stateful
{ +) -> crate::ui::motion::HoverBackground { let label = label.into(); let shrinks = detail.is_some(); chip_frame(id, leading, label.clone(), active) @@ -1802,7 +2029,7 @@ fn project_chip( computer: Option, project: SharedString, active: bool, -) -> gpui::Stateful
{ +) -> crate::ui::motion::HoverBackground { let name = computer .as_ref() .map_or_else(|| project.clone(), |computer| computer.caption.clone()); @@ -1853,7 +2080,7 @@ fn chip_frame( leading: Option<&'static str>, name: SharedString, active: bool, -) -> gpui::Stateful
{ +) -> crate::ui::motion::HoverBackground { let color = chip_color(active); div() .id(id) @@ -1871,11 +2098,15 @@ fn chip_frame( .font_weight(gpui::FontWeight::MEDIUM) .text_color(gpui::rgb(color)) .when(active, |el| el.bg(gpui::rgb(theme::bg_sidebar_pill()))) - .hover(|style| { - style - .bg(gpui::rgb(theme::bg_sidebar_pill())) - .cursor_pointer() + .map(|element| { + let rest: gpui::Hsla = if active { + gpui::rgb(theme::bg_sidebar_pill()).into() + } else { + gpui::transparent_black() + }; + crate::ui::motion::hover_background(element, rest, gpui::rgb(theme::bg_sidebar_pill())) }) + .hover(|style| style.cursor_pointer()) .active(|style| style.bg(gpui::rgb(theme::bg_sidebar_row_selected()))) .children(leading.map(|name| icon(name, px(16.), color))) } @@ -1981,3 +2212,338 @@ fn group_heading(group: &maple_sdk::CatalogGroup) -> SharedString { _ => group.label.clone().into(), } } + +#[cfg(test)] +mod resize_tests { + use super::*; + use gpui::{Entity, TestAppContext, VisualTestContext}; + use maple_agent::agent::AgentTimelineItem; + use std::time::{Duration, Instant}; + + struct Host { + chat: Entity, + } + + impl Render for Host { + fn render(&mut self, _window: &mut Window, _cx: &mut Context) -> impl IntoElement { + div() + .w(px(1200.)) + .h(px(800.)) + .flex() + .flex_col() + .child(self.chat.clone()) + } + } + + /// A chat whose transcript holds `rows` messages and follows its + /// tail; none shows the empty state. + fn chat_window( + cx: &mut TestAppContext, + rows: usize, + ) -> (Entity, &mut VisualTestContext) { + cx.executor().allow_parking(); + let backend = { + let _guard = crate::settings::SETTINGS_IO_LOCK.lock(); + Arc::new( + crate::backend::AgentBackend::for_test("http://127.0.0.1:9".into(), String::new()) + .expect("backend"), + ) + }; + let chat = cx.new(|cx| { + let _guard = crate::settings::SETTINGS_IO_LOCK.lock(); + let mut chat = ChatScreen::new_without_start(backend, "user".to_string(), cx); + chat.selected_session = Some("s1".to_string()); + chat.booting = false; + chat.trust_prompts = false; + chat.sidebar_collapsed = true; + chat.sidebar + .update(cx, |sidebar, _| sidebar.reset_persisted_for_test()); + chat.replace_timeline( + (0..rows) + .map(|index| AgentTimelineItem { + label: None, + persisted: None, + live: None, + truncated: None, + revision: 0, + id: format!("m{index}"), + item_type: "message".to_string(), + role: None, + title: None, + text: Some(format!("Message {index}\n\n{}", "lorem ipsum ".repeat(30))), + status: None, + input: None, + output: None, + created_ms: 0, + merge: "replace".to_string(), + }) + .collect(), + ); + chat + }); + let (_host, cx) = cx.add_window_view(|_window, _cx| Host { chat: chat.clone() }); + cx.simulate_resize(gpui::size(px(1200.), px(800.))); + cx.run_until_parked(); + (chat, cx) + } + + fn composer_height(cx: &mut VisualTestContext) -> gpui::Pixels { + cx.debug_bounds("composer-box") + .expect("composer") + .size + .height + } + + /// Space between the newest transcript row and the composer: constant + /// while the transcript keeps its tail on screen. + fn tail_gap(cx: &mut VisualTestContext) -> gpui::Pixels { + let newest = cx + .debug_bounds("timeline-row-m39") + .expect("the newest row is on screen"); + cx.debug_bounds("composer-box").expect("composer").top() - newest.bottom() + } + + fn toggle(chat: &Entity, cx: &mut VisualTestContext) { + chat.update(cx, |chat, cx| chat.toggle_composer_expanded(cx)); + cx.run_until_parked(); + } + + fn frame_at(at: Instant, cx: &mut VisualTestContext) { + motion::set_test_now(Some(at)); + cx.update(|window, app| window.simulate_next_frame(app)); + cx.run_until_parked(); + } + + #[gpui::test] + fn expanding_the_composer_eases_reverses_and_keeps_the_tail(cx: &mut TestAppContext) { + let start = Instant::now(); + motion::set_test_now(Some(start)); + cx.update(|cx| cx.set_reduce_motion(false)); + let (chat, cx) = chat_window(cx, 40); + let rest = composer_height(cx); + let pinned = tail_gap(cx); + + toggle(&chat, cx); + assert_eq!( + composer_height(cx), + rest, + "starts from the height on screen" + ); + frame_at(start + motion::PANEL - Duration::from_millis(1), cx); + let landing = composer_height(cx); + assert_eq!(tail_gap(cx), pinned, "the transcript keeps its tail"); + frame_at(start + motion::PANEL, cx); + let expanded = composer_height(cx); + assert!(expanded > rest * 2., "expanded: {expanded:?}"); + assert!( + (expanded - landing).abs() < px(1.), + "lands on the resting layout: {landing:?} then {expanded:?}" + ); + assert_eq!(tail_gap(cx), pinned, "the transcript keeps its tail"); + + // Shrink, then expand again halfway down. + let shrink = start + motion::PANEL * 2; + motion::set_test_now(Some(shrink)); + toggle(&chat, cx); + frame_at(shrink + motion::PANEL / 2, cx); + let partway = composer_height(cx); + assert!(partway > rest && partway < expanded, "partway: {partway:?}"); + assert_eq!(tail_gap(cx), pinned, "the tail stays put mid-flight"); + toggle(&chat, cx); + assert_eq!( + composer_height(cx), + partway, + "a reversal starts where it is" + ); + frame_at(shrink + motion::PANEL / 2 + Duration::from_millis(30), cx); + assert!(composer_height(cx) > partway, "heading back up"); + frame_at(shrink + motion::PANEL * 2, cx); + assert_eq!(composer_height(cx), expanded); + assert!(chat.read_with(cx, |chat, _| chat.composer_resize.is_none())); + + // Reduced motion switches at once. + cx.update(|_window, app| app.set_reduce_motion(true)); + toggle(&chat, cx); + assert_eq!(composer_height(cx), rest); + assert_eq!(tail_gap(cx), pinned); + motion::set_test_now(None); + } + + #[gpui::test] + fn expanding_from_the_empty_state_folds_the_hero_without_a_jump(cx: &mut TestAppContext) { + let start = Instant::now(); + motion::set_test_now(Some(start)); + cx.update(|cx| cx.set_reduce_motion(false)); + let (chat, cx) = chat_window(cx, 0); + let rest = cx.debug_bounds("composer-box").expect("composer"); + + toggle(&chat, cx); + assert_eq!( + cx.debug_bounds("composer-box"), + Some(rest), + "the heading and the note are still there on the first frame" + ); + frame_at(start + motion::PANEL / 2, cx); + let partway = composer_height(cx); + assert!(partway > rest.size.height, "partway: {partway:?}"); + frame_at(start + motion::PANEL - Duration::from_millis(1), cx); + let landing = cx.debug_bounds("composer-box").expect("composer"); + frame_at(start + motion::PANEL, cx); + let expanded = cx.debug_bounds("composer-box").expect("composer"); + assert!( + (expanded.top() - landing.top()).abs() < px(1.), + "{landing:?} {expanded:?}" + ); + assert!( + (expanded.size.height - landing.size.height).abs() < px(1.), + "{landing:?} {expanded:?}" + ); + + let shrink = start + motion::PANEL * 2; + motion::set_test_now(Some(shrink)); + toggle(&chat, cx); + assert_eq!(cx.debug_bounds("composer-box"), Some(expanded)); + // On the way back the heading rides above the composer at its full + // size: the folding box never cuts it against the composer's edge. + for step in 1..8 { + frame_at(shrink + motion::PANEL * step / 8, cx); + let composer = cx.debug_bounds("composer-box").expect("composer"); + let title = cx + .debug_bounds("empty-title") + .expect("the heading draws on the way back"); + assert!( + title.bottom() <= composer.top(), + "the heading stays clear of the composer: {title:?} {composer:?}" + ); + } + frame_at(shrink + motion::PANEL - Duration::from_millis(1), cx); + let landing = cx.debug_bounds("composer-box").expect("composer"); + frame_at(shrink + motion::PANEL, cx); + assert!( + (rest.top() - landing.top()).abs() < px(1.), + "{landing:?} {rest:?}" + ); + assert_eq!(cx.debug_bounds("composer-box"), Some(rest)); + motion::set_test_now(None); + } + + /// A new task has no session yet. Shrinking its expanded composer starts + /// from the expanded box and eases down to rest, so nothing around it + /// jumps, whatever the composer brings along for a new task. + #[gpui::test] + fn a_new_task_shrinks_its_composer_from_where_it_was(cx: &mut TestAppContext) { + let start = Instant::now(); + motion::set_test_now(Some(start)); + cx.update(|cx| cx.set_reduce_motion(false)); + let (chat, cx) = chat_window(cx, 0); + chat.update(cx, |chat, cx| { + chat.selected_session = None; + cx.notify(); + }); + cx.run_until_parked(); + let rest = cx.debug_bounds("composer-box").expect("composer"); + toggle(&chat, cx); + frame_at(start + motion::PANEL * 2, cx); + let expanded = cx.debug_bounds("composer-box").expect("composer"); + assert!( + expanded.size.height > rest.size.height, + "{rest:?} {expanded:?}" + ); + + let shrink = start + motion::PANEL * 3; + motion::set_test_now(Some(shrink)); + toggle(&chat, cx); + assert_eq!( + cx.debug_bounds("composer-box"), + Some(expanded), + "shrinking starts from the expanded box" + ); + let mut heights = vec![expanded.size.height]; + for step in 1..8 { + frame_at(shrink + motion::PANEL * step / 8, cx); + heights.push(composer_height(cx)); + } + assert!( + heights.windows(2).all(|pair| pair[1] <= pair[0]), + "it only shrinks: {heights:?}" + ); + assert!( + heights[1] > rest.size.height, + "it eases rather than snapping to rest: {heights:?}" + ); + frame_at(shrink + motion::PANEL * 2, cx); + assert_eq!( + cx.debug_bounds("composer-box"), + Some(rest), + "it lands at rest" + ); + motion::set_test_now(None); + } + + /// The first message carries the composer from the empty state down to + /// the foot of the conversation: it starts where it was drawn, moves + /// only down, lands exactly at rest, and then asks for no frames. New + /// Task under reduced motion puts it straight back. + #[gpui::test] + fn leaving_the_empty_state_glides_the_composer_down(cx: &mut TestAppContext) { + let start = Instant::now(); + motion::set_test_now(Some(start)); + cx.update(|cx| cx.set_reduce_motion(false)); + let (chat, cx) = chat_window(cx, 0); + let hero = cx.debug_bounds("composer-box").expect("composer"); + + let message = |chat: &mut ChatScreen| { + chat.replace_timeline(vec![AgentTimelineItem { + label: None, + persisted: None, + live: None, + truncated: None, + revision: 0, + id: "m0".to_string(), + item_type: "message".to_string(), + role: None, + title: None, + text: Some("Hello".to_string()), + status: None, + input: None, + output: None, + created_ms: 0, + merge: "replace".to_string(), + }]); + }; + chat.update(cx, |chat, cx| { + message(chat); + cx.notify(); + }); + cx.run_until_parked(); + let first = cx.debug_bounds("composer-box").expect("composer"); + assert!( + (first.top() - hero.top()).abs() < px(1.), + "starts where it was drawn: {hero:?} {first:?}" + ); + let mut last = first.top(); + for step in 1..=12 { + frame_at(start + motion::PANEL * step / 12, cx); + let top = cx.debug_bounds("composer-box").expect("composer").top(); + assert!(top >= last, "only moves down: {last:?} then {top:?}"); + last = top; + } + frame_at(start + motion::PANEL * 2, cx); + let rest = cx.debug_bounds("composer-box").expect("composer"); + assert!(rest.top() > hero.top() + px(100.), "{hero:?} {rest:?}"); + assert_eq!(cx.update(|window, app| window.simulate_next_frame(app)), 0); + + cx.update(|_, cx| cx.set_reduce_motion(true)); + chat.update(cx, |chat, cx| { + chat.replace_timeline(Vec::new()); + cx.notify(); + }); + cx.run_until_parked(); + let back = cx.debug_bounds("composer-box").expect("composer"); + assert!( + (back.top() - hero.top()).abs() < px(1.), + "reduced motion lands at once: {hero:?} {back:?}" + ); + motion::set_test_now(None); + } +} diff --git a/apps/maple-agent/app/src/ui/chat/computers.rs b/apps/maple-agent/app/src/ui/chat/computers.rs index b3342b2e7..dbe501441 100644 --- a/apps/maple-agent/app/src/ui/chat/computers.rs +++ b/apps/maple-agent/app/src/ui/chat/computers.rs @@ -257,6 +257,16 @@ impl ChatScreen { } } + #[cfg(test)] + pub(crate) fn seed_sessions_for_test( + &mut self, + sessions: Vec, + cx: &mut Context, + ) { + self.sessions = sessions; + self.sync_sidebar(cx); + } + pub(crate) fn finish_project_rename( &mut self, target: ProjectTarget, diff --git a/apps/maple-agent/app/src/ui/chat/dialogs.rs b/apps/maple-agent/app/src/ui/chat/dialogs.rs index 9c3bf818d..433390004 100644 --- a/apps/maple-agent/app/src/ui/chat/dialogs.rs +++ b/apps/maple-agent/app/src/ui/chat/dialogs.rs @@ -134,11 +134,11 @@ impl ChatScreen { .top_0() .left_0() .occlude() - .bg(theme::scrim()) .flex() .items_center() .justify_center() - .child( + .child(widgets::dialog_scrim()) + .child(widgets::dialog_card( div() .id("trust-card") .role(gpui::Role::Dialog) @@ -219,7 +219,7 @@ impl ChatScreen { ), ), ), - ) + )) } /// Ask before a project leaves the sidebar. @@ -323,7 +323,6 @@ impl ChatScreen { .top_0() .left_0() .occlude() - .bg(theme::scrim()) .flex() .items_center() .justify_center() @@ -331,7 +330,8 @@ impl ChatScreen { this.confirm = None; cx.notify(); })) - .child( + .child(widgets::dialog_scrim()) + .child(widgets::dialog_card( div() .id("confirm-card") .role(gpui::Role::Dialog) @@ -407,7 +407,7 @@ impl ChatScreen { }), )), ), - ) + )) } /// Drop the selection and everything the composer shows for it: the diff --git a/apps/maple-agent/app/src/ui/chat/feedback.rs b/apps/maple-agent/app/src/ui/chat/feedback.rs index bc4323b97..629573139 100644 --- a/apps/maple-agent/app/src/ui/chat/feedback.rs +++ b/apps/maple-agent/app/src/ui/chat/feedback.rs @@ -224,12 +224,12 @@ impl ChatScreen { .absolute() .inset_0() .occlude() - .bg(theme::scrim()) .flex() .items_center() .justify_center() .on_mouse_down(gpui::MouseButton::Left, |_, _, cx| cx.stop_propagation()) - .child( + .child(widgets::dialog_scrim()) + .child(widgets::dialog_card( div() .id("feedback-form") .role(gpui::Role::Dialog) @@ -346,7 +346,7 @@ impl ChatScreen { ), ), ), - ), + )), ) } } diff --git a/apps/maple-agent/app/src/ui/chat/mod.rs b/apps/maple-agent/app/src/ui/chat/mod.rs index 27f82ae87..2f3ff5ca8 100644 --- a/apps/maple-agent/app/src/ui/chat/mod.rs +++ b/apps/maple-agent/app/src/ui/chat/mod.rs @@ -119,25 +119,7 @@ struct QueueEdit { pub(crate) const SIDEBAR_WIDTH: gpui::Pixels = px(300.); /// Width of the rail that stands in for the sidebar while it is collapsed. const SIDEBAR_RAIL_WIDTH: gpui::Pixels = px(48.); -const SIDEBAR_TRANSITION_DURATION: std::time::Duration = std::time::Duration::from_millis(200); - -/// One reversible transition. Sampling the current position when retargeting -/// avoids jumping back to an endpoint on a second press. -struct SidebarTransition { - from: f32, - to: f32, - started: std::time::Instant, - duration: std::time::Duration, -} -impl SidebarTransition { - fn value(&self, now: std::time::Instant) -> f32 { - let elapsed = now.saturating_duration_since(self.started).as_secs_f32(); - let t = (elapsed / self.duration.as_secs_f32()).clamp(0., 1.); - let eased = 1. - (1. - t).powi(3); - self.from + (self.to - self.from) * eased - } -} /// Where the header's toolbar starts, from the window's left edge, as the /// sidebar goes from collapsed (0) to expanded (1). Beside traffic lights /// it stays put at `titlebar::TRAFFIC_LIGHT_TOOLBAR_LEFT`, which Settings' @@ -240,6 +222,9 @@ struct TranscriptCtx<'a> { /// One-based position of the row and the row count, for /// assistive technology ("message 4 of 17"). position: (usize, usize), + /// How far the row's just-opened details are through fading in; 1 at + /// rest. + reveal: f32, } /// Text-to-speech progress for one message. @@ -726,7 +711,8 @@ pub struct ChatScreen { watched_git_dir: Option, /// Sidebar hidden; a toggle in the main pane brings it back. sidebar_collapsed: bool, - sidebar_transition: Option, + /// Collapse (0) or expand (1) under way; `None` at rest. + sidebar_transition: Option, /// Files staged for the next message. draft_attachments: Vec, unresolved_sends: HashMap, @@ -762,6 +748,21 @@ pub struct ChatScreen { mcp_enabled_count: usize, /// Composer fills the pane (fullscreen editing). composer_expanded: bool, + /// How far the composer is from the height of its text (0) toward + /// expanded (1) while it eases between them; `None` at rest. + composer_resize: Option, + /// Heights that transition eases between, measured last frame. + composer_frame: std::rc::Rc>, + /// Whether the last frame drew the empty state; `None` before the + /// first frame, which never glides. + composer_was_empty: Option, + /// The window y the composer region glides from, and since when, after + /// the empty state gives way to a conversation or back. + composer_glide: Option<(gpui::Pixels, std::time::Instant)>, + /// Send (0) or Stop (1) on the composer's main control. + send_stop: motion::Tween, + /// The send fill, disabled (0) or ready (1). + send_ready: motion::Tween, /// Latest todo list from the selected task, pinned above the composer /// while any entry is unfinished. A finished list stays in the /// transcript. @@ -834,6 +835,12 @@ pub struct ChatScreen { /// True from send until the first agent item of the run arrives; shows /// the waiting indicator under the transcript. awaiting_first_token: bool, + /// Live row entrances and reveals in the transcript, kept here so a + /// row scrolled away and back never replays them. + row_motion: transcript::RowMotion, + /// When the task in `loading_session` started opening, for the header + /// spinner's delay. + loading_since: Option, /// Item ids whose tool card or thinking row was clicked; membership /// inverts the `tool_details` default for that item. toggled_tools: HashSet, @@ -941,6 +948,9 @@ struct HostRecovery { /// How often a stale snapshot is fetched again before it is applied. const LOAD_RETRIES: u8 = 2; +/// How long a task may take to open before the header shows a spinner; +/// a faster open never flashes one. +const LOADING_SPINNER_DELAY: std::time::Duration = std::time::Duration::from_millis(300); /// Finished run ids remembered for a late send acknowledgement. const FINISHED_RUNS_KEPT: usize = 64; @@ -1189,7 +1199,7 @@ impl ChatScreen { if self.sidebar_collapsed == collapsed { return; } - let now = std::time::Instant::now(); + let now = crate::ui::motion::now(); let from = self .sidebar_transition .as_ref() @@ -1198,13 +1208,17 @@ impl ChatScreen { let to = if collapsed { 0. } else { 1. }; self.sidebar_collapsed = collapsed; let distance = (to - from).abs(); - self.sidebar_transition = - (!cx.reduce_motion() && distance > f32::EPSILON).then(|| SidebarTransition { - from, + self.sidebar_transition = (!cx.reduce_motion() && distance > f32::EPSILON).then(|| { + let mut transition = crate::ui::motion::Tween::new(from); + transition.set( to, - started: now, - duration: SIDEBAR_TRANSITION_DURATION.mul_f32(distance), - }); + crate::ui::motion::PANEL.mul_f32(distance), + crate::ui::motion::ease_out_cubic, + now, + false, + ); + transition + }); if self.popup.is_open(&ChatPopup::Settings) { self.popup.close(cx); } @@ -1220,9 +1234,9 @@ impl ChatScreen { if cx.reduce_motion() { self.sidebar_transition = None; } - let now = std::time::Instant::now(); + let now = crate::ui::motion::now(); if let Some(transition) = &self.sidebar_transition { - if now.saturating_duration_since(transition.started) < transition.duration { + if transition.is_moving(now) { window.request_animation_frame(); return transition.value(now); } @@ -1630,6 +1644,12 @@ impl ChatScreen { session_mcp: Vec::new(), mcp_enabled_count: 0, composer_expanded: false, + composer_resize: None, + composer_frame: std::rc::Rc::default(), + composer_was_empty: None, + composer_glide: None, + send_stop: motion::Tween::new(0.), + send_ready: motion::Tween::new(0.), permission_mode: settings.new_task_permission_mode.unwrap_or_default(), new_task_permission_mode: settings.new_task_permission_mode.unwrap_or_default(), markdown_cache: MarkdownCache::default(), @@ -1658,6 +1678,8 @@ impl ChatScreen { selection: None, transcript_focus: None, awaiting_first_token: false, + row_motion: transcript::RowMotion::default(), + loading_since: None, toggled_tools: HashSet::new(), question_selected: HashMap::new(), question_step: 0, @@ -3254,6 +3276,8 @@ impl ChatScreen { if matches!(mode, LoadMode::Select) && !self.is_selected(session_id) { if self.loading_session.as_deref() != Some(session_id) { self.loading_timeline.clear(); + self.loading_since = Some(motion::now()); + self.schedule_loading_spinner(cx); } self.loading_session = Some(session_id.to_string()); self.loading_generation = self.selection_generation; @@ -3351,6 +3375,10 @@ impl ChatScreen { let live_has_more = detail.live_has_more; match mode { LoadMode::Select => { + // Another task's transcript fades in when it lands; + // the task restored at launch (`apply_bootstrap`) + // does not. + let switching = !this.is_selected(&detail.session.id); let root = detail.session.project_root.clone(); let needs_recent_touch = this .project_root @@ -3358,6 +3386,9 @@ impl ChatScreen { .is_none_or(|current| current == &root); this.upsert_session(detail.session.clone(), cx); this.set_active_session(detail.session, detail.timeline, summaries, cx); + if switching { + this.row_motion.switch_task(motion::now()); + } // A different existing root is persisted by set_active_session; // explicit opens in the same root also count as recent use. // Recency alone changes no listing, so no root reload. @@ -3396,6 +3427,31 @@ impl ChatScreen { } } + /// Repaint once an open has taken `LOADING_SPINNER_DELAY`, so a slow + /// open shows the header spinner. + fn schedule_loading_spinner(&self, cx: &mut Context) { + cx.spawn(async move |entity, cx| { + cx.background_executor().timer(LOADING_SPINNER_DELAY).await; + entity + .update(cx, |this, cx| { + if this.loading_session.is_some() { + cx.notify(); + } + }) + .ok(); + }) + .detach(); + } + + /// Whether the header shows the spinner of a task being opened: only + /// once the open has taken `LOADING_SPINNER_DELAY`. + pub(super) fn loading_spinner_due(&self) -> bool { + self.loading_session.is_some() + && self.loading_since.is_none_or(|since| { + motion::now().saturating_duration_since(since) >= LOADING_SPINNER_DELAY + }) + } + /// Install a new timeline and reset every per-item structure that is /// keyed by its contents. fn replace_timeline(&mut self, timeline: Vec) { @@ -3406,6 +3462,7 @@ impl ChatScreen { .application_vim_enabled .then(|| self.navigable_timeline_ids()); self.local_error_text.clear(); + self.row_motion.clear_rows(); self.timeline = timeline.into_iter().map(paging::normalize).collect(); self.pages.weights.clear(); self.bound_transcript_window(true); @@ -4251,10 +4308,36 @@ impl ChatScreen { } fn toggle_composer_expanded(&mut self, cx: &mut Context) { + let now = motion::now(); + let from = self + .composer_resize + .map(|transition| transition.value(now)) + .unwrap_or(if self.composer_expanded { 1. } else { 0. }); self.composer_expanded = !self.composer_expanded; let expanded = self.composer_expanded; + let to = if expanded { 1. } else { 0. }; + let distance = (to - from).abs(); + // Eases between heights measured on screen, so it needs a frame + // drawn first; reduced motion switches at once. + let frame = self.composer_frame.get(); + let measured = frame.region.is_some() && frame.room.is_some(); + self.composer_resize = + (!cx.reduce_motion() && measured && distance > f32::EPSILON).then(|| { + let mut transition = motion::Tween::new(from); + transition.set( + to, + motion::PANEL.mul_f32(distance), + motion::ease_out_cubic, + now, + false, + ); + transition + }); + // The field fills the box while it moves, so typed text stays put + // and the box's text height can be read off the field. + let fill = self.composer_fills(); if let Some(composer) = self.composer.clone() { - composer.update(cx, |input, cx| input.set_fill_height(expanded, cx)); + composer.update(cx, |input, cx| input.set_fill_height(fill, cx)); } cx.notify(); } @@ -4448,16 +4531,27 @@ impl ChatScreen { !disconnected(notice) })?; self.schedule_notice_dismiss(notice.clone(), cx); - Some(div().child(motion::fade_in( + let text = notice.resolve(); + // Keyed by what it says, so a different notice that replaces this + // one enters again. + let identity = { + use std::hash::{Hash, Hasher}; + let mut hasher = std::collections::hash_map::DefaultHasher::new(); + text.hash(&mut hasher); + hasher.finish() + }; + Some(div().child(motion::slide_in( widgets::notice( "notice-close", - notice.resolve(), + text, cx.listener(|this, _event, _window, cx| { this.notice = None; cx.notify(); }), ), - "notice-reveal", + ("notice-reveal", identity), + motion::ENTER, + gpui::point(px(0.), motion::RISE), ))) } @@ -4854,6 +4948,8 @@ impl ChatScreen { } else { self.toggled_tools.insert(item_id.to_string()); } + let open = self.tool_details != self.toggled_tools.contains(item_id); + self.row_motion.disclose(item_id, open, motion::now()); // Resolve the row now: an index baked into the card at render // time goes stale once history reloads or items are inserted. if let Some(&(index, _)) = self.timeline_index.get(item_id) { @@ -5609,6 +5705,14 @@ impl ChatScreen { if let Some(session) = self.selected_session.clone() { let id = item.id.clone(); if self.apply_timeline_item(&session, item).is_some() { + // A failed send's message and status leave the slot under + // the transcript as its error arrives: the error opens from + // all of that space, so nothing above it jumps. + if self.row_motion.slot_on_screen && !self.waiting_slot_shown() { + self.row_motion.slot_on_screen = false; + let space = self.row_motion.slot_height(); + self.row_motion.open_from_more(&id, space); + } self.local_error_text.insert(id, presentation); } } @@ -6137,6 +6241,7 @@ impl ChatScreen { self.timeline[index].id = item.id.clone(); self.timeline_index.insert(item.id.clone(), (index, 0)); self.rekey_summary(&old, &item.id); + self.row_motion.rekey(&old, &item.id); } if let Some((index, _)) = self.timeline_index.get(&item.id) && let (Some(old), Some(new)) = (&self.timeline[*index].persisted, &item.persisted) @@ -6225,6 +6330,11 @@ impl ChatScreen { None => { let index = self.timeline.len(); self.timeline_index.insert(item.id.clone(), (index, 0)); + self.row_motion.arrive( + &item.id, + motion::now(), + self.list_state.is_following_tail(), + ); self.timeline.push(item); self.list_state.splice(index..index, 1); index @@ -6281,6 +6391,12 @@ impl ChatScreen { true } + /// Whether the slot under the transcript shows something: the message + /// being sent or the waiting dots. + fn waiting_slot_shown(&self) -> bool { + self.has_send_feedback() || (self.awaiting_first_token && self.is_run_active()) + } + /// One timeline item arrived for the selected session. fn apply_incoming_item( &mut self, @@ -6295,11 +6411,21 @@ impl ChatScreen { // work; the summary checks read the stored item after the merge. let completed = item.status.as_deref() == Some("completed"); let is_tool = matches!(item.item_type.as_str(), "tool" | "toolCall"); + let new_row = !self.timeline_index.contains_key(&item.id); self.load_attachment_images_for(&item, cx); let plan = plan_entries(&item); let Some(index) = self.apply_timeline_item(session_id, item) else { return; }; + // The waiting row (or the sent message's status) leaves the slot + // under the transcript as this row arrives: the row opens from that + // height, so nothing above it jumps. + if new_row && self.row_motion.slot_on_screen && !self.waiting_slot_shown() { + self.row_motion.slot_on_screen = false; + let id = self.timeline[index].id.clone(); + self.row_motion + .open_from_more(&id, transcript::WAITING_ROW_HEIGHT); + } if self .sidebar_plan .as_ref() @@ -6339,6 +6465,15 @@ impl ChatScreen { self.refresh_context_usage(cx); } } + + /// Pushes that crossed a reconnect rebuild the transcript; they do not + /// enter like live rows. + fn replay_after_reconnect(&mut self, events: Vec, cx: &mut Context) { + self.row_motion.set_quiet(true); + self.handle_service_events(events, cx); + self.row_motion.set_quiet(false); + } + pub fn handle_service_events( &mut self, events: Vec, @@ -6536,7 +6671,7 @@ impl ChatScreen { } } this.refresh_sessions(cx); - this.handle_service_events(events, cx); + this.replay_after_reconnect(events, cx); this.host_recovery.unavailable = false; this.runtime_error_reason = None; this.runtime_error = None; @@ -7035,8 +7170,9 @@ impl ChatScreen { } AgentRunEvent::Error(item) => { if self.is_selected(session_id) { - self.load_attachment_images_for(&item, cx); - self.apply_timeline_item(session_id, item); + // Like any reply, an error ends the wait: the waiting + // row leaves and the error opens from its space. + self.apply_incoming_item(session_id, item, cx); } else { self.bump_timeline_revision(session_id); return false; @@ -7298,9 +7434,15 @@ impl Render for ChatScreen { .clone() .map(|status| self.render_trust_prompt(&status, cx)); let empty = self.shows_empty_state(); + let composer_glide = self.composer_glide_frame(empty, window, cx); let sidebar_expansion = self.sidebar_expansion(window, cx); + let rise = gpui::point(px(0.), motion::RISE); + let composer_resize = self.composer_resize_frame(window, cx); let main = if empty { - self.render_empty_state(window, cx) + // No slot under a transcript here; rows opening from it start at + // 0, and the next slot to appear comes with a send. + self.row_motion.show_empty_state(); + self.render_empty_state(composer_resize, composer_glide, window, cx) } else { div() .flex() @@ -7312,24 +7454,13 @@ impl Render for ChatScreen { // takes scrolls the transcript. .on_scroll(cx.listener(Self::scroll_transcript_from_pane)) .child(self.render_transcript(window, cx)) - .children(self.render_send_preview()) - .when( - self.awaiting_first_token && self.is_run_active() && !self.has_send_feedback(), - |main| { - // Same gutter as transcript text so the dots line up - main.child( - div() - .w_full() - .max_w(CONTENT_WIDTH) - .mx_auto() - .px_6() - .child(render_waiting_indicator()), - ) - }, - ) + .children(self.render_under_transcript(window, cx)) .when_some(self.current_question(), |container, question| { let input = self.pending_question_input.clone(); let step = self.question_step; + let enter = gpui::ElementId::Name( + format!("question-card-enter-{}", question.request_id).into(), + ); // Each option shows the key bound to it right now. One // keymap lookup per option on show; a card has a handful. let key_labels = question @@ -7342,21 +7473,28 @@ impl Render for ChatScreen { .collect::>() }) .unwrap_or_default(); - // Same column and gutter as the composer under it. - container.child(div().w_full().max_w(CONTENT_WIDTH).mx_auto().px_6().child( - render_question_card( - question, - step, - self.question_collapsed, - input, - &self.question_selected, - &key_labels, - &self.messages, - cx, + // Same column and gutter as the composer under it. Like + // the cards above the composer, a new question rises in + // and leaves at once. + container.child(motion::slide_in( + div().w_full().max_w(CONTENT_WIDTH).mx_auto().px_6().child( + render_question_card( + question, + step, + self.question_collapsed, + input, + &self.question_selected, + &key_labels, + &self.messages, + cx, + ), ), + enter, + motion::ENTER, + rise, )) }) - .child( + .child(composer::glide( div() .relative() .w_full() @@ -7364,24 +7502,53 @@ impl Render for ChatScreen { .mx_auto() .px_6() .pb_4() - .when(self.composer_expanded, |wrap| { - wrap.flex_none() + .map(|wrap| match composer_resize { + // Easing between its text's height and expanded. + Some((_, height)) => { + wrap.flex_none().h(height).min_h_0().flex().flex_col() + } + None if self.composer_expanded => wrap + .flex_none() .h(gpui::relative(0.7)) .min_h_0() .flex() - .flex_col() + .flex_col(), + None => wrap, }) // The composer, its cards and the palette keep their // own wheel; the space beside them scrolls the // transcript. .on_scroll(|_, _, cx| cx.stop_propagation()) - .children(self.render_btw_card(cx)) - .children(self.render_subagents_card(cx)) - .children(self.render_plan_card(cx)) + // Cards above the composer rise in when they appear + // and leave at once. + .children(self.render_btw_card(cx).map(|card| { + motion::slide_in(card, "btw-card-enter", motion::ENTER, rise) + })) + .children(self.render_subagents_card(cx).map(|card| { + motion::slide_in(card, "subagents-card-enter", motion::ENTER, rise) + })) + .children(self.render_plan_card(cx).map(|card| { + motion::slide_in(card, "plan-card-enter", motion::ENTER, rise) + })) .child(self.render_composer(window, cx)) .children(self.render_slash_palette(cx)) - .children(self.render_persistence_failure(cx)), - ) + .children(self.render_persistence_failure(cx)) + .child(composer::measure( + &self.composer_frame, + |frame, bounds, _| { + frame.region = Some(bounds.size.height); + frame.top = Some(bounds.origin.y); + }, + )), + composer_glide, + )) + // Expanded, the composer region takes 70% of this column. + .child(composer::measure( + &self.composer_frame, + |frame, bounds, _| { + frame.room = Some(bounds.size.height * 0.7); + }, + )) }; div() .key_context(self.application_vim_context()) @@ -7651,13 +7818,21 @@ impl ChatScreen { ) }) .child(div().flex_1()) - .child( - icon("chevron-down", px(12.), theme::text_muted()).when(!open, |icon| { - icon.with_transformation(gpui::Transformation::rotate(gpui::radians( - std::f32::consts::PI, - ))) - }), - ) + .child(motion::animated( + "settings-menu-chevron", + if open { 1. } else { 0. }, + motion::TOGGLE, + motion::ease_out_cubic, + |open| { + // Points up at the menu above while closed, and + // turns down once it is open. + icon("chevron-down", px(12.), theme::text_muted()) + .with_transformation(gpui::Transformation::rotate(gpui::radians( + std::f32::consts::PI * (1. - open), + ))) + .into_any_element() + }, + )) }); let button = self .popup @@ -7974,11 +8149,15 @@ impl ChatScreen { .pl(mark_padding) .rounded(theme::RADIUS_SM) .focus_visible(widgets::focus_ring) - .hover(|style| { - style - .bg(gpui::rgb(theme::bg_sidebar_row_hover())) - .cursor_pointer() + .map(|element| { + let rest: gpui::Hsla = gpui::transparent_black(); + crate::ui::motion::hover_background( + element, + rest, + gpui::rgb(theme::bg_sidebar_row_hover()), + ) }) + .hover(|style| style.cursor_pointer()) .active(|style| style.bg(gpui::rgb(theme::bg_sidebar_row_selected()))) // Inside a drag region: a press here is a click, not a drag. .on_mouse_down(gpui::MouseButton::Left, |_event, _window, cx| { @@ -8018,8 +8197,93 @@ impl ChatScreen { /// Hero layout for a task with no messages: display heading, composer, /// and privacy note centered in the pane (mirrors EmptyAgentState). - fn render_empty_state(&mut self, window: &mut Window, cx: &mut Context) -> Div { + /// Expanded, the composer fills the pane; while it eases there and + /// back (`composer_resize`), the heading and the note fold away and + /// fade with it so the column never jumps. `composer_glide` carries + /// the composer up from the foot of a conversation. + fn render_empty_state( + &mut self, + composer_resize: Option<(f32, gpui::Pixels)>, + composer_glide: Option<(gpui::Pixels, f32)>, + window: &mut Window, + cx: &mut Context, + ) -> Div { let expanded = self.composer_expanded; + let fills = self.composer_fills(); + let hero = match composer_resize { + Some((progress, _)) => 1. - progress, + None if expanded => 0., + None => 1., + }; + let measured = self.composer_frame.get(); + // At rest a block records its height. On the way it is drawn at + // `hero` of that height while its content keeps its full size, held + // against the composer (the heading at the block's foot, the note at + // its head) and fading, never clipped: text rides with the composer + // instead of being cut by the folding box. The content keeps + // recording its height, so a block first drawn mid-fold folds from + // the next frame. Each block carries the spacing beside it as its + // content's margin (padding would not fold), so nothing is left + // behind. + let fold = + |content: Div, rest: Option, foot: bool, record: composer::Record| { + let content = content + .relative() + .child(composer::measure(&self.composer_frame, record)); + if composer_resize.is_some() { + // Squared, so text nearing the pane's edge, where the + // pane clips it, is already faint. + let content = content.absolute().left_0().right_0().opacity(hero * hero); + div() + .relative() + .w_full() + .flex_none() + .h(rest.unwrap_or_default() * hero) + .child(if foot { + content.bottom_0() + } else { + content.top_0() + }) + } else { + content + } + }; + let title = (hero > 0.).then(|| { + fold( + div().w_full().flex().flex_col().items_center().child( + div() + .debug_selector(|| "empty-title".to_string()) + // Its own space and the gap to the composer. + .mb_12() + .font_family(crate::assets::FONT_DISPLAY) + .text_size(px(36.)) + .line_height(px(48.)) + .text_color(gpui::rgb(theme::display_text())) + .child(tr("chat-empty-title")), + ), + measured.title, + true, + |frame, bounds, _| frame.title = Some(bounds.size.height), + ) + }); + let privacy = (hero > 0.).then(|| { + fold( + div().w_full().flex().justify_center().child( + div() + .mt_6() + .flex() + .items_center() + .gap_1() + .text_xs() + .text_color(gpui::rgb(theme::text_muted())) + .child(icon("lock", px(12.), theme::text_muted())) + .child(tr("chat-empty-private")), + ), + measured.privacy, + false, + |frame, bounds, _| frame.privacy = Some(bounds.size.height), + ) + }); let body = div() .flex() .flex_col() @@ -8029,7 +8293,18 @@ impl ChatScreen { .items_center() .justify_center() .px_6() - .when(expanded, |pane| pane.py_6()) + .when(fills, |pane| pane.py_6()) + // The folding heading rides above its shrinking box; in a short + // pane it would reach past the pane's top edge and draw faintly + // over the title bar, so the pane clips while the composer moves. + .when(composer_resize.is_some(), |pane| pane.overflow_hidden()) + // Expanded, the composer region takes the pane less its padding. + .child(composer::measure( + &self.composer_frame, + |frame, bounds, window| { + frame.room = Some(bounds.size.height - window.rem_size() * 3.); + }, + )) .child( div() .w_full() @@ -8038,48 +8313,45 @@ impl ChatScreen { .flex() .flex_col() .items_center() - .gap_6() - .when(expanded, |column| column.h_full().min_h_0()) - .when(!expanded, |column| { - column.child( - div() - .mb_6() - .font_family(crate::assets::FONT_DISPLAY) - .text_size(px(36.)) - .line_height(px(48.)) - .text_color(gpui::rgb(theme::display_text())) - .child(tr("chat-empty-title")), - ) - }) - .child( + .when(fills, |column| column.h_full().min_h_0().justify_center()) + .children(title) + .child(composer::glide( div() .relative() .w_full() - .when(expanded, |wrap| wrap.flex_1().min_h_0().flex().flex_col()) + .map(|wrap| match composer_resize { + // Grows into the free space up to this + // frame's height. + Some((_, height)) => { + wrap.flex_1().min_h_0().max_h(height).flex().flex_col() + } + None if expanded => wrap.flex_1().min_h_0().flex().flex_col(), + None => wrap, + }) .child(self.render_composer(window, cx)) - .children(self.render_slash_palette(cx)), - ) + .children(self.render_slash_palette(cx)) + .child(composer::measure( + &self.composer_frame, + |frame, bounds, _| { + frame.region = Some(bounds.size.height); + frame.top = Some(bounds.origin.y); + }, + )), + composer_glide, + )) .when( self.awaiting_first_token && self.is_run_active(), - |column| column.child(render_waiting_indicator()), + |column| column.child(div().mt_6().child(render_waiting_indicator())), ) - .when(!expanded, |column| { - column.child( - div() - .flex() - .items_center() - .gap_1() - .text_xs() - .text_color(gpui::rgb(theme::text_muted())) - .child(icon("lock", px(12.), theme::text_muted())) - .child(tr("chat-empty-private")), - ) - }) + .children(privacy) .when_some(self.runtime_error.clone(), |column, error| { - column.child(widgets::banner(widgets::Tone::Error, error)) + column.child(widgets::banner(widgets::Tone::Error, error).mt_6()) }) - .children(self.render_persistence_failure(cx)) - .children(self.render_notice(cx)), + .children( + self.render_persistence_failure(cx) + .map(|failure| failure.mt_6()), + ) + .children(self.render_notice(cx).map(|notice| notice.mt_6())), ); div() .flex() diff --git a/apps/maple-agent/app/src/ui/chat/project_folder.rs b/apps/maple-agent/app/src/ui/chat/project_folder.rs index e1e53c7be..f291efe6c 100644 --- a/apps/maple-agent/app/src/ui/chat/project_folder.rs +++ b/apps/maple-agent/app/src/ui/chat/project_folder.rs @@ -591,7 +591,15 @@ impl ProjectFolderDialog { .when(self.highlighted == Some(index), |row| { row.bg(gpui::rgb(theme::bg_sidebar_row_selected())) }) - .hover(|row| row.bg(theme::overlay_hover()).cursor_pointer()) + .map(|element| { + let rest: gpui::Hsla = if self.highlighted == Some(index) { + gpui::rgb(theme::bg_sidebar_row_selected()).into() + } else { + gpui::transparent_black() + }; + crate::ui::motion::hover_background(element, rest, theme::overlay_hover()) + }) + .hover(|row| row.cursor_pointer()) .on_click(cx.listener(move |this, _, window, cx| { window.focus(&this.focus(Control::List, cx), cx); this.enter_folder(index, cx); @@ -636,11 +644,11 @@ impl Render for ProjectFolderDialog { .inset_0() .size_full() .occlude() - .bg(theme::scrim()) .flex() .items_center() .justify_center() - .child( + .child(widgets::dialog_scrim()) + .child(widgets::dialog_card( div() .id("project-folder-dialog") .debug_selector(|| "project-folder-dialog".into()) @@ -951,7 +959,7 @@ impl Render for ProjectFolderDialog { ), ), ), - ) + )) } } diff --git a/apps/maple-agent/app/src/ui/chat/queue.rs b/apps/maple-agent/app/src/ui/chat/queue.rs index 4b4523a2b..e9bd5474b 100644 --- a/apps/maple-agent/app/src/ui/chat/queue.rs +++ b/apps/maple-agent/app/src/ui/chat/queue.rs @@ -4,7 +4,7 @@ use gpui::{ Context, Div, InteractiveElement, ParentElement, SharedString, StatefulInteractiveElement, - Styled, div, prelude::FluentBuilder, px, + Styled, div, point, prelude::FluentBuilder, px, }; use maple_agent::agent::AgentQueuedMessage; @@ -12,6 +12,7 @@ use super::{COMPOSER_PLACEHOLDER, ChatScreen, QUEUE_EDIT_PLACEHOLDER, QueueEdit} use crate::backend::QueuedMessageRequest; use crate::ui::i18n::{UiText, tr}; use crate::ui::icons::icon; +use crate::ui::motion; use crate::ui::task::Failure as UiFailure; use crate::ui::theme; @@ -329,13 +330,15 @@ impl ChatScreen { .justify_center() .rounded(theme::RADIUS_SM) .when(busy, |button| button.opacity(0.5)) - .when(!busy, |button| { - button.hover(|style| { - style - .bg(gpui::rgb(theme::bg_sidebar_row_hover())) - .cursor_pointer() - }) + .map(|button| { + crate::ui::motion::hover_background( + button, + gpui::transparent_black(), + gpui::rgb(theme::bg_sidebar_row_hover()), + ) }) + .when(busy, |button| button.highlighted(false)) + .when(!busy, |button| button.hover(|style| style.cursor_pointer())) .child(icon(icon_name, px(12.), theme::text_secondary())) }; Some( @@ -367,7 +370,10 @@ impl ChatScreen { } else { self.queue_previews.get(index).cloned().unwrap_or_default() }; - div() + // A chip rises in when its message is queued and + // leaves at once. + let chip_id = SharedString::from(format!("queue-chip-{}", item.queue_id)); + let chip = div() .flex() .items_center() .gap_2() @@ -445,7 +451,8 @@ impl ChatScreen { }, )), ) - }) + }); + motion::slide_in(chip, chip_id, motion::ENTER, point(px(0.), motion::RISE)) })), ) } diff --git a/apps/maple-agent/app/src/ui/chat/sending.rs b/apps/maple-agent/app/src/ui/chat/sending.rs index 3ba74b570..4cedbc338 100644 --- a/apps/maple-agent/app/src/ui/chat/sending.rs +++ b/apps/maple-agent/app/src/ui/chat/sending.rs @@ -13,6 +13,8 @@ pub(super) struct SendPreview { baseline_user_rows: HashSet, snapshot_projected: bool, phase: SendPhase, + /// When the preview was made: its bubble's entrance starts here. + shown: std::time::Instant, } struct PreviewAttachment { @@ -52,6 +54,7 @@ impl SendPreview { baseline_user_rows: HashSet::new(), snapshot_projected: false, phase: SendPhase::Admitting, + shown: motion::now(), } } @@ -184,6 +187,7 @@ impl ChatScreen { let Some(run) = run.filter(|_| is_user_message(item)) else { return; }; + let mut handed_off = false; for preview in self .sending_previews .values_mut() @@ -201,10 +205,17 @@ impl ChatScreen { { continue; } + let showing = preview.body_visible(); if preview.projected_runs.len() < 8 || preview.acknowledged_run.as_deref() == Some(run) { preview.projected_runs.insert(run.to_owned()); } + handed_off |= showing && !preview.body_visible(); + } + // The row takes the place of the message already on screen; it + // must not enter a second time. + if handed_off { + self.row_motion.hand_off(item.id.clone()); } self.sending_previews .retain(|_, preview| !preview.settled()); @@ -289,104 +300,129 @@ impl ChatScreen { .retain(|_, preview| !preview.settled()); } - pub(super) fn render_send_preview(&self) -> Option> { + /// The message being sent, under the transcript. Its bubble rises in + /// from the moment it shows; the status line under it fades in once, + /// in the slot the waiting dots use, so the real row that takes over + /// lands where the bubble was. + pub(super) fn render_send_preview( + &self, + window: &mut Window, + cx: &gpui::App, + ) -> Option> { + self.row_motion.preview_body.set(None); let preview = self.current_send_preview()?; - Some( - div() - .id("pending-send") - .debug_selector(|| "pending-send".to_string()) - .role(gpui::Role::Status) - .aria_label(if self.send_pending() { - tr("chat-sending-message") - } else { - tr("chat-waiting-response") - }) - .flex_none() - .w_full() - .max_w(CONTENT_WIDTH) - .mx_auto() - .px_6() - .pb_2() - .flex() - .flex_col() - .items_end() - .gap_1() - .when(preview.body_visible(), |row| { - row.child( - crate::ui::typography::chat_reading(div()) - .id("pending-send-body") - .debug_selector(|| "pending-send-body".to_string()) - .max_w(gpui::relative(0.75)) - .max_h(px(180.)) - .overflow_y_scroll() - // A long message scrolls inside its bubble; the - // pane must not scroll the transcript as well. - .on_scroll(|_, _, cx| cx.stop_propagation()) - .px_4() - .py_2() - .rounded(theme::RADIUS_MD) - .bg(gpui::rgb(theme::bg_user_bubble())) - .border_1() - .border_color(gpui::rgb(theme::user_bubble_border())) - .text_color(gpui::rgb(theme::text_primary())) - .when(!preview.attachments.is_empty(), |body| { - body.child(div().flex().flex_wrap().gap_2().mb_1().children( - preview.attachments.iter().map(|attachment| { - match &attachment.image { - Some(image) => div().child( - gpui::img(gpui::ImageSource::Image(image.clone())) - .size_16() - .rounded(theme::RADIUS_SM), - ), - None => div() - .flex() - .flex_col() - .text_xs() - .gap_1() - .child(attachment.name.clone()) - .child( - div() - .text_color(gpui::rgb(theme::text_muted())) - .child( - attachments::cached_attachment_detail( - &attachment.mime, - attachment.size, - &self.messages, - ), - ), + let body_visible = preview.body_visible(); + let entrance = motion::progress( + preview.shown, + motion::ENTER, + motion::now(), + cx.reduce_motion(), + ); + if body_visible && entrance < 1. { + window.request_animation_frame(); + } + let body_bounds = self.row_motion.preview_body.clone(); + let row = div() + .on_children_prepainted(move |bounds, _, _| { + body_bounds.set(bounds.first().copied().filter(|_| body_visible)); + }) + .id("pending-send") + .debug_selector(|| "pending-send".to_string()) + .role(gpui::Role::Status) + .aria_label(if self.send_pending() { + tr("chat-sending-message") + } else { + tr("chat-waiting-response") + }) + .flex_none() + .w_full() + .max_w(CONTENT_WIDTH) + .mx_auto() + .px_6() + .flex() + .flex_col() + .items_end() + .gap(transcript::PREVIEW_GAP) + .when(body_visible, |row| { + let body = crate::ui::typography::chat_reading(div()) + .id("pending-send-body") + .debug_selector(|| "pending-send-body".to_string()) + .max_w(gpui::relative(0.75)) + .max_h(px(180.)) + .overflow_y_scroll() + // A long message scrolls inside its bubble; the + // pane must not scroll the transcript as well. + .on_scroll(|_, _, cx| cx.stop_propagation()) + .px_4() + .py_2() + .rounded(theme::RADIUS_MD) + .bg(gpui::rgb(theme::bg_user_bubble())) + .border_1() + .border_color(gpui::rgb(theme::user_bubble_border())) + .text_color(gpui::rgb(theme::text_primary())) + .when(!preview.attachments.is_empty(), |body| { + body.child(div().flex().flex_wrap().gap_2().mb_1().children( + preview.attachments.iter().map(|attachment| { + match &attachment.image { + Some(image) => div().child( + gpui::img(gpui::ImageSource::Image(image.clone())) + .size_16() + .rounded(theme::RADIUS_SM), + ), + None => div() + .flex() + .flex_col() + .text_xs() + .gap_1() + .child(attachment.name.clone()) + .child( + div().text_color(gpui::rgb(theme::text_muted())).child( + attachments::cached_attachment_detail( + &attachment.mime, + attachment.size, + &self.messages, ), - } - }), - )) - }) - .child(preview.text.clone()), - ) - }) - .child( - div() - .flex() - .items_center() - .gap_1() - .text_xs() - .text_color(gpui::rgb(theme::text_muted())) - .child(spinner( - "pending-send-spinner", - px(12.), - theme::text_muted(), + ), + ), + } + }), )) - .child( - self.selected_upload() - .map(|(_, upload)| upload.label.clone()) - .unwrap_or_else(|| { - if self.send_pending() { - UiText::key("chat-sending") - } else { - UiText::key("chat-waiting-response-progress") - } - }), - ), - ), - ) + }) + .child(preview.text.clone()); + row.child(if entrance < 1. { + motion::arrive(body, entrance).into_any_element() + } else { + body.into_any_element() + }) + }) + .child(motion::fade_in( + div() + .debug_selector(|| "pending-send-status".to_string()) + .h(transcript::WAITING_ROW_HEIGHT) + .flex() + .items_center() + .gap_1() + .text_xs() + .text_color(gpui::rgb(theme::text_muted())) + .child(spinner( + "pending-send-spinner", + px(12.), + theme::text_muted(), + )) + .child( + self.selected_upload() + .map(|(_, upload)| upload.label.clone()) + .unwrap_or_else(|| { + if self.send_pending() { + UiText::key("chat-sending") + } else { + UiText::key("chat-waiting-response-progress") + } + }), + ), + "pending-send-status-reveal", + )); + Some(row) } } diff --git a/apps/maple-agent/app/src/ui/chat/sidebar.rs b/apps/maple-agent/app/src/ui/chat/sidebar.rs index abc9a4430..ba523c648 100644 --- a/apps/maple-agent/app/src/ui/chat/sidebar.rs +++ b/apps/maple-agent/app/src/ui/chat/sidebar.rs @@ -3136,11 +3136,15 @@ impl Sidebar { .items_center() .justify_center() .rounded(theme::RADIUS_SM) - .hover(|style| { - style - .bg(gpui::rgb(theme::bg_sidebar_row_selected())) - .cursor_pointer() + .map(|element| { + let rest: gpui::Hsla = gpui::transparent_black(); + crate::ui::motion::hover_background( + element, + rest, + gpui::rgb(theme::bg_sidebar_row_selected()), + ) }) + .hover(|style| style.cursor_pointer()) .tooltip(widgets::tooltip_for_action( tr("chat-clear-search"), &super::ChatEscape, @@ -3231,9 +3235,8 @@ impl Sidebar { .font_weight(gpui::FontWeight::SEMIBOLD) }) .hover(|style| { - style - .bg(gpui::rgb(theme::bg_sidebar_row_hover())) - .cursor_pointer() + // Pointer feedback stays immediate while the background eases. + style.cursor_pointer() }) .active(|style| style.bg(gpui::rgb(theme::bg_sidebar_row_selected()))) .tooltip(widgets::tooltip_for_action(label.clone(), action)) @@ -3246,6 +3249,13 @@ impl Sidebar { }) .child(icon(name, px(16.), color)) .child(label) + .map(|element| { + crate::ui::motion::hover_background( + element, + gpui::transparent_black(), + gpui::rgb(theme::bg_sidebar_row_hover()), + ) + }) .into_any_element() } Some(SidebarEntry::ProjectsHeader) => self.render_projects_header(window, cx), @@ -3288,11 +3298,15 @@ impl Sidebar { .px_2() .py_1() .rounded(ROW_RADIUS) - .hover(|style| { - style - .bg(gpui::rgb(theme::bg_sidebar_row_hover())) - .cursor_pointer() + .map(|element| { + let rest: gpui::Hsla = gpui::transparent_black(); + crate::ui::motion::hover_background( + element, + rest, + gpui::rgb(theme::bg_sidebar_row_hover()), + ) }) + .hover(|style| style.cursor_pointer()) .on_click(cx.listener(move |this, _event, _window, cx| { this.toggle_section_expanded(section, cx); this.hover_heading(SidebarEntry::SectionLabel(section), cx); @@ -3373,11 +3387,15 @@ impl Sidebar { .px_2() .h(px(34.)) .rounded(ROW_RADIUS) - .hover(|style| { - style - .bg(gpui::rgb(theme::bg_sidebar_row_hover())) - .cursor_pointer() + .map(|element| { + let rest: gpui::Hsla = gpui::transparent_black(); + crate::ui::motion::hover_background( + element, + rest, + gpui::rgb(theme::bg_sidebar_row_hover()), + ) }) + .hover(|style| style.cursor_pointer()) .on_click(cx.listener(|this, _event, _window, cx| { this.toggle_archived_visibility(cx); this.hover_heading(SidebarEntry::ArchivedHeader, cx); @@ -3549,14 +3567,20 @@ impl Sidebar { fn set_hovered_entry(&mut self, entry: Option, cx: &mut Context) { self.hover_scroll_top = self.list.logical_scroll_top(); + let header_was_hovered = self.projects_header_hovered(); self.hovered_entry = entry; let section = entry.and_then(|entry| self.entry_sections.get(entry).copied().flatten()); - if self.hovered_section != section { + if self.hovered_section != section || header_was_hovered != self.projects_header_hovered() { self.hovered_section = section; cx.notify(); } } + fn projects_header_hovered(&self) -> bool { + self.hovered_entry.and_then(|ix| self.entries.get(ix)) + == Some(&SidebarEntry::ProjectsHeader) + } + #[cfg(test)] pub(super) fn section_hover_is_clear_for_test(&self) -> bool { self.hovered_entry.is_none() && self.hovered_section.is_none() @@ -3589,27 +3613,33 @@ impl Sidebar { id: &'static str, section: SidebarHoverSection, ) -> AnyElement { + let visible = !expanded || self.section_hovered(section); let chevron = div() .id((id, 0_u64)) .flex_none() .size(px(14.)) .flex() .items_center() - .opacity(if !expanded || self.section_hovered(section) { - 1. - } else { - 0. - }) - .child(icon( - if expanded { - "chevron-down" - } else { - "chevron-right" - }, + .child(motion::chevron( + "chevron", + expanded, px(14.), theme::text_secondary(), )); - chevron.into_any_element() + if section == SidebarHoverSection::Projects { + crate::ui::motion::hover_background( + chevron, + gpui::transparent_black(), + gpui::transparent_black(), + ) + .highlighted(false) + .revealed(visible) + .into_any_element() + } else { + chevron + .opacity(if visible { 1. } else { 0. }) + .into_any_element() + } } /// The Projects header: its label folds the list under it, and its @@ -3713,16 +3743,15 @@ impl Sidebar { .into_any_element() } - fn view_button(&self, open: bool) -> gpui::Stateful
{ + fn view_button(&self, open: bool) -> crate::ui::motion::HoverBackground { header_button("view-options", "list-filter", tr("chat-view-options"), open) + .revealed(open) .debug_selector(|| "view-options".into()) .tab_index(5) .focus_visible(|style| widgets::focus_ring(style.opacity(1.))) .on_key_down(ChatScreen::sidebar_button_key_down) .when(!open, |button| { - button - .opacity(0.) - .group_hover("projects-header-actions", |style| style.opacity(1.)) + button.revealed(self.projects_header_hovered()) }) } @@ -3817,7 +3846,7 @@ impl Sidebar { } /// Add project stays visible until there is a project to browse. - fn new_project_button(&self, open: bool) -> gpui::Stateful
{ + fn new_project_button(&self, open: bool) -> crate::ui::motion::HoverBackground { header_button( "new-project", "folder-plus", @@ -3825,11 +3854,7 @@ impl Sidebar { open, ) .debug_selector(|| "new-project".to_owned()) - .when(!open && !self.project_roots.is_empty(), |button| { - button - .opacity(0.) - .group_hover("projects-header-actions", |style| style.opacity(1.)) - }) + .revealed(open || self.project_roots.is_empty() || self.projects_header_hovered()) } fn new_project_computer_menu(&self) -> Menu { @@ -3943,14 +3968,18 @@ impl Sidebar { .when(menu_open, |row| { row.bg(gpui::rgb(theme::bg_sidebar_row_hover())) }) - .when(hover, |row| { - row.hover(|style| { - if self.dragging { - style - } else { - style.bg(gpui::rgb(theme::bg_sidebar_row_hover())) - } - }) + .map(|row| { + let rest = if menu_open { + gpui::rgb(theme::bg_sidebar_row_hover()).into() + } else { + gpui::transparent_black() + }; + crate::ui::motion::hover_background( + row, + rest, + gpui::rgb(theme::bg_sidebar_row_hover()), + ) + .when(!hover || self.dragging, |row| row.highlighted(false)) }) .on_click(cx.listener(move |this, _event, _window, cx| { if !this.collapsed_projects.remove(&toggle_target) { @@ -3973,8 +4002,10 @@ impl Sidebar { }), ) }) - .child(icon( - if expanded { "folder-open" } else { "folder" }, + .child(motion::icon_swap( + "folder-icon", + expanded, + ["folder", "folder-open"], FOLDER_ICON_SIZE, theme::text_secondary(), )) @@ -4251,7 +4282,7 @@ impl Sidebar { application_selected: bool, window: &mut Window, cx: &mut Context, - ) -> gpui::Stateful
{ + ) -> crate::ui::motion::HoverBackground { let SidebarTaskEntry { session: index, pinned: is_pinned, @@ -4308,8 +4339,17 @@ impl Sidebar { .text_color(gpui::rgb(theme::text_sidebar())) // A row being renamed is a text field: no hover highlight and // no hover actions over it, so the edit is plain to see. - .when(!renaming && !self.dragging, |el| { - el.hover(|style| style.bg(gpui::rgb(hover_bg)).cursor_pointer()) + .map(|row| { + let rest = if is_selected { + gpui::rgb(theme::bg_sidebar_row_selected()).into() + } else { + gpui::transparent_black() + }; + crate::ui::motion::hover_background(row, rest, gpui::rgb(hover_bg)) + .when(renaming || self.dragging, |row| row.highlighted(false)) + .when(!renaming && !self.dragging, |row| { + row.hover(|style| style.cursor_pointer()) + }) }) .on_click(cx.listener(move |_this, _event, _window, cx| { cx.emit(SidebarEvent::Select(session_id.to_string())); @@ -4353,11 +4393,15 @@ impl Sidebar { .items_center() .justify_center() .rounded(theme::RADIUS_SM) - .hover(|style| { - style - .bg(gpui::rgb(theme::bg_sidebar_row_selected())) - .cursor_pointer() + .map(|element| { + let rest: gpui::Hsla = gpui::transparent_black(); + crate::ui::motion::hover_background( + element, + rest, + gpui::rgb(theme::bg_sidebar_row_selected()), + ) }) + .hover(|style| style.cursor_pointer()) .tooltip(widgets::tooltip(tr("chat-unpin"), None)) .on_click(cx.listener(move |this, _event, _window, cx| { cx.stop_propagation(); @@ -4553,29 +4597,57 @@ const RUNNING_BREATH: Duration = Duration::from_millis(1600); /// any number of running rows cost one repaint per interval; `spinner_id` /// is prebuilt so render allocates nothing. Every state sits centered in /// one box the size of the largest, so the center stays put as states -/// change. +/// change, and one state cross-fades into the next over +/// [`motion::TOGGLE`]. The box is keyed by `spinner_id`, which names the +/// task, so an indicator that first appears (a list that loads, a row that +/// scrolls in) shows its state at once. fn activity_indicator(spinner_id: &SharedString, activity: SessionActivity) -> AnyElement { - let dot = |color: u32| { - div() - .size(px(8.)) - .rounded_full() - .bg(gpui::rgb(color)) - .into_any_element() + let layer = |name: &'static str, state: SessionActivity| { + let spinner_id = spinner_id.clone(); + motion::animated( + name, + if activity == state { 1. } else { 0. }, + motion::TOGGLE, + motion::ease_out_cubic, + move |shown| { + if shown <= 0. { + return div().into_any_element(); + } + let dot = |color: u32| { + div() + .size(px(8.)) + .rounded_full() + .bg(gpui::rgb(color)) + .into_any_element() + }; + div() + .absolute() + .inset_0() + .flex() + .items_center() + .justify_center() + .opacity(shown) + .child(match state { + SessionActivity::NeedsYou => dot(theme::accent()), + SessionActivity::Running => running_ring(spinner_id.clone()), + SessionActivity::Failed => { + icon("circle-alert", px(13.), theme::status_error()).into_any_element() + } + SessionActivity::CompletedUnread => dot(theme::status_success()), + }) + .into_any_element() + }, + ) }; div() + .id(spinner_id.clone()) + .relative() .size(px(13.)) .flex_none() - .flex() - .items_center() - .justify_center() - .child(match activity { - SessionActivity::NeedsYou => dot(theme::accent()), - SessionActivity::Running => running_ring(spinner_id.clone()), - SessionActivity::Failed => { - icon("circle-alert", px(13.), theme::status_error()).into_any_element() - } - SessionActivity::CompletedUnread => dot(theme::status_success()), - }) + .child(layer("needs-you", SessionActivity::NeedsYou)) + .child(layer("running", SessionActivity::Running)) + .child(layer("failed", SessionActivity::Failed)) + .child(layer("completed", SessionActivity::CompletedUnread)) .into_any_element() } @@ -4625,7 +4697,7 @@ pub(super) fn row_action( icon_name: &'static str, label: impl Into, on_click: impl Fn(&gpui::ClickEvent, &mut Window, &mut gpui::App) + 'static, -) -> gpui::Stateful
{ +) -> crate::ui::motion::HoverBackground { let label = label.into(); row_button(id, group, icon_name, label.clone()) .tooltip(widgets::tooltip(label, None)) @@ -4639,7 +4711,7 @@ fn row_menu_button( group: &SharedString, label: impl Into, open: bool, -) -> gpui::Stateful
{ +) -> crate::ui::motion::HoverBackground { let label = label.into(); row_button(id, group, "ellipsis", label).when(open, |button| { button @@ -4655,7 +4727,7 @@ fn header_button( icon_name: &'static str, label: impl Into, open: bool, -) -> gpui::Stateful
{ +) -> crate::ui::motion::HoverBackground { let label = label.into(); div() .id(id) @@ -4667,11 +4739,15 @@ fn header_button( .items_center() .justify_center() .rounded(theme::RADIUS_SM) - .hover(|style| { - style - .bg(gpui::rgb(theme::bg_sidebar_row_hover())) - .cursor_pointer() + .map(|element| { + let rest: gpui::Hsla = gpui::transparent_black(); + crate::ui::motion::hover_background( + element, + rest, + gpui::rgb(theme::bg_sidebar_row_hover()), + ) }) + .hover(|style| style.cursor_pointer()) .when(open, |button| { button.bg(gpui::rgb(theme::bg_sidebar_row_selected())) }) @@ -4687,7 +4763,7 @@ fn row_button( group: &SharedString, icon_name: &'static str, label: impl Into, -) -> gpui::Stateful
{ +) -> crate::ui::motion::HoverBackground { let label = label.into(); div() .debug_selector(|| id.to_string()) @@ -4702,11 +4778,15 @@ fn row_button( .rounded(theme::RADIUS_SM) .opacity(0.) .group_hover(group.clone(), |style| style.opacity(1.)) - .hover(|style| { - style - .bg(gpui::rgb(theme::bg_sidebar_row_selected())) - .cursor_pointer() + .map(|element| { + let rest: gpui::Hsla = gpui::transparent_black(); + crate::ui::motion::hover_background( + element, + rest, + gpui::rgb(theme::bg_sidebar_row_selected()), + ) }) + .hover(|style| style.cursor_pointer()) .active(|style| style.bg(gpui::rgb(theme::border()))) .child(icon(icon_name, px(14.), theme::text_secondary())) } @@ -4771,6 +4851,199 @@ pub(super) fn remote_root_display_name(root: &str) -> String { mod tests { use super::remote_root_display_name; + #[gpui::test] + fn projects_header_reveal_tracks_its_buttons_and_keeps_view_menu_open( + cx: &mut gpui::TestAppContext, + ) { + use super::*; + let _settings = crate::settings::SETTINGS_IO_LOCK.lock(); + cx.executor().allow_parking(); + cx.update(|cx| cx.set_reduce_motion(true)); + let backend = + Arc::new(AgentBackend::for_test("http://127.0.0.1:9".into(), String::new()).unwrap()); + let chat = cx.new(|cx| ChatScreen::new_without_start(backend, "user".into(), cx)); + let sidebar = chat.update(cx, |chat, _| chat.sidebar.clone()); + sidebar.update(cx, |sidebar, cx| { + sidebar.reset_persisted_for_test(); + sidebar.view.group = SidebarGroup::List; + sidebar.set_sessions( + (1..=100) + .map(|ix| AgentSessionSummary { + id: format!("s{ix}"), + title: format!("Task {ix}"), + project_root: "/tmp/proj".into(), + created_ms: 0, + updated_ms: 100 - ix, + message_count: 1, + model: None, + thinking_level: None, + web_enabled: true, + permission_mode: Default::default(), + state: AgentTaskState::Active, + acp: false, + }) + .collect(), + cx, + ); + }); + struct Host(Entity); + impl Render for Host { + fn render(&mut self, _: &mut Window, _: &mut Context) -> impl IntoElement { + div() + .w(px(300.)) + .h(px(400.)) + .flex() + .flex_col() + .child(self.0.clone()) + } + } + let (_host, cx) = cx.add_window_view(|_, _| Host(sidebar.clone())); + cx.simulate_resize(gpui::size(px(600.), px(400.))); + cx.run_until_parked(); + let outside = gpui::point(px(500.), px(350.)); + cx.simulate_mouse_move(outside, None, gpui::Modifiers::default()); + let header = cx.debug_bounds("projects-header").unwrap(); + let view = cx.debug_bounds("view-options").unwrap(); + let add = cx.debug_bounds("new-project").unwrap(); + assert!(!sidebar.update(cx, |sidebar, _| sidebar.projects_header_hovered())); + + for position in [header.center(), view.center(), add.center()] { + cx.simulate_mouse_move(position, None, gpui::Modifiers::default()); + assert!(sidebar.update(cx, |sidebar, _| sidebar.projects_header_hovered())); + assert_eq!(cx.debug_bounds("projects-header"), Some(header)); + assert_eq!(cx.debug_bounds("view-options"), Some(view)); + assert_eq!(cx.debug_bounds("new-project"), Some(add)); + } + let task = cx.debug_bounds("session-s1").unwrap(); + cx.simulate_mouse_move(task.center(), None, gpui::Modifiers::default()); + assert!(sidebar.update(cx, |sidebar, _| { + sidebar.section_hovered(SidebarHoverSection::Projects) + })); + assert!( + !sidebar.update(cx, |sidebar, _| sidebar.projects_header_hovered()), + "hovering a task in the Projects section must not reveal header actions" + ); + cx.simulate_mouse_move(outside, None, gpui::Modifiers::default()); + assert!(!sidebar.update(cx, |sidebar, _| sidebar.projects_header_hovered())); + assert_eq!(cx.debug_bounds("view-options"), Some(view)); + assert_eq!(cx.debug_bounds("new-project"), Some(add)); + + cx.simulate_mouse_move(header.center(), None, gpui::Modifiers::default()); + assert!(sidebar.update(cx, |sidebar, _| sidebar.projects_header_hovered())); + cx.simulate_event(gpui::ScrollEvent { + position: header.center(), + delta: gpui::ScrollDelta::Pixels(gpui::point(px(0.), px(-1600.))), + ..Default::default() + }); + cx.run_until_parked(); + assert!(cx.debug_bounds("projects-header").is_none()); + assert!(!sidebar.update(cx, |sidebar, _| sidebar.projects_header_hovered())); + cx.simulate_mouse_move(outside, None, gpui::Modifiers::default()); + sidebar.update(cx, |sidebar, cx| { + sidebar.list.scroll_to(gpui::ListOffset::default()); + cx.notify(); + }); + cx.run_until_parked(); + assert_eq!(cx.debug_bounds("projects-header"), Some(header)); + assert_eq!(cx.debug_bounds("view-options"), Some(view)); + assert_eq!(cx.debug_bounds("new-project"), Some(add)); + assert!(!sidebar.update(cx, |sidebar, _| sidebar.projects_header_hovered())); + + cx.simulate_mouse_move(header.center(), None, gpui::Modifiers::default()); + cx.simulate_mouse_move(view.center(), None, gpui::Modifiers::default()); + cx.simulate_click(view.center(), gpui::Modifiers::default()); + assert!(sidebar.update(cx, |sidebar, _| sidebar.popup.is_open(&SidebarPopup::View))); + assert!(cx.debug_bounds("sidebar-group").is_some()); + cx.simulate_mouse_move(outside, None, gpui::Modifiers::default()); + assert!(!sidebar.update(cx, |sidebar, _| sidebar.projects_header_hovered())); + assert!(sidebar.update(cx, |sidebar, _| sidebar.popup.is_open(&SidebarPopup::View))); + assert!(cx.debug_bounds("sidebar-group").is_some()); + assert_eq!(cx.debug_bounds("view-options"), Some(view)); + } + + /// A task's status cross-fades inside the cached sidebar: the change + /// asks for frames until it settles, then the sidebar goes idle. A + /// status already there when the list first draws does not animate. + #[gpui::test] + fn task_status_cross_fades_in_the_cached_sidebar_and_settles(cx: &mut gpui::TestAppContext) { + use super::*; + let _settings = crate::settings::SETTINGS_IO_LOCK.lock(); + cx.executor().allow_parking(); + let start = std::time::Instant::now(); + motion::set_test_now(Some(start)); + cx.update(|cx| cx.set_reduce_motion(false)); + let backend = + Arc::new(AgentBackend::for_test("http://127.0.0.1:9".into(), String::new()).unwrap()); + let chat = cx.new(|cx| ChatScreen::new_without_start(backend, "user".into(), cx)); + let sidebar = chat.update(cx, |chat, _| chat.sidebar.clone()); + let activity = |waiting: bool| { + let ids = HashSet::from(["s1".to_string()]); + if waiting { + TaskActivity { + waiting: ids, + ..TaskActivity::default() + } + } else { + TaskActivity { + unread: ids, + ..TaskActivity::default() + } + } + }; + sidebar.update(cx, |sidebar, cx| { + sidebar.reset_persisted_for_test(); + sidebar.view.group = SidebarGroup::List; + sidebar.set_sessions( + (1..=3) + .map(|ix| AgentSessionSummary { + id: format!("s{ix}"), + title: format!("Task {ix}"), + project_root: "/tmp/proj".into(), + created_ms: 0, + updated_ms: 100 - ix, + message_count: 1, + model: None, + thinking_level: None, + web_enabled: true, + permission_mode: Default::default(), + state: AgentTaskState::Active, + acp: false, + }) + .collect(), + cx, + ); + sidebar.set_activity(activity(true), cx); + }); + struct Host(Entity); + impl Render for Host { + fn render(&mut self, _: &mut Window, _: &mut Context) -> impl IntoElement { + div().size_full().child( + self.0 + .clone() + .cached(gpui::StyleRefinement::default().w(px(300.)).h(px(400.))), + ) + } + } + let (_host, cx) = cx.add_window_view(|_, _| Host(sidebar.clone())); + cx.simulate_resize(gpui::size(px(600.), px(400.))); + cx.run_until_parked(); + let frames = |cx: &mut gpui::VisualTestContext| { + cx.update(|window, cx| window.simulate_next_frame(cx)) + }; + assert!(cx.debug_bounds("session-s1").is_some()); + assert_eq!(frames(cx), 0, "a status at first draw does not animate"); + + sidebar.update(cx, |sidebar, cx| sidebar.set_activity(activity(false), cx)); + cx.run_until_parked(); + assert!(frames(cx) > 0, "the new status fades in"); + cx.run_until_parked(); + motion::set_test_now(Some(start + motion::TOGGLE)); + frames(cx); + cx.run_until_parked(); + assert_eq!(frames(cx), 0, "settled, the cached sidebar goes idle"); + motion::set_test_now(None); + } + #[gpui::test] fn collapsed_and_empty_projects_keep_the_expanded_task_gap(cx: &mut gpui::TestAppContext) { use super::*; diff --git a/apps/maple-agent/app/src/ui/chat/sidebar_computers.rs b/apps/maple-agent/app/src/ui/chat/sidebar_computers.rs index 4ce323c46..eabba6b83 100644 --- a/apps/maple-agent/app/src/ui/chat/sidebar_computers.rs +++ b/apps/maple-agent/app/src/ui/chat/sidebar_computers.rs @@ -2424,8 +2424,15 @@ impl Sidebar { row.aria_active_descendant() .bg(gpui::rgb(theme::bg_sidebar_row_hover())) }) - .when(!loading, |row| { - row.hover(|s| s.cursor_pointer().bg(gpui::rgb(hover_bg))) + .map(|row| { + let rest = if selected { + gpui::rgb(theme::bg_sidebar_row_hover()).into() + } else { + gpui::transparent_black() + }; + crate::ui::motion::hover_background(row, rest, gpui::rgb(hover_bg)) + .when(loading, |row| row.highlighted(false)) + .when(!loading, |row| row.hover(|style| style.cursor_pointer())) }) .on_click(cx.listener(move |this, _, _, cx| { if !loading { @@ -2474,12 +2481,16 @@ impl Sidebar { row.aria_active_descendant() .bg(gpui::rgb(theme::bg_sidebar_row_hover())) }) - .hover(move |s| { - if dragging || renaming { - s + .map(|row| { + let rest = if selected { + gpui::rgb(theme::bg_sidebar_row_hover()).into() } else { - s.bg(gpui::rgb(hover_bg)).cursor_pointer() - } + gpui::transparent_black() + }; + let still = dragging || renaming; + crate::ui::motion::hover_background(row, rest, gpui::rgb(hover_bg)) + .when(still, |row| row.highlighted(false)) + .when(!still, |row| row.hover(|style| style.cursor_pointer())) }) .on_click(cx.listener(move |_, _, _, cx| { cx.emit(SidebarEvent::Navigate(request.clone())) @@ -2586,12 +2597,11 @@ impl Sidebar { .gap_1() .text_xs() .text_color(gpui::rgb(theme::text_secondary())) - .hover(move |s| { - if dragging { - s - } else { - s.bg(gpui::rgb(hover_bg)).cursor_pointer() - } + .map(|row| { + let rest = gpui::transparent_black(); + crate::ui::motion::hover_background(row, rest, gpui::rgb(hover_bg)) + .when(dragging, |row| row.highlighted(false)) + .when(!dragging, |row| row.hover(|style| style.cursor_pointer())) }) .on_click(cx.listener(move |this, _, _, cx| { if !this.toggle_computer_group(&request, cx) { diff --git a/apps/maple-agent/app/src/ui/chat/speech.rs b/apps/maple-agent/app/src/ui/chat/speech.rs index cb682c8a2..cbf43e4da 100644 --- a/apps/maple-agent/app/src/ui/chat/speech.rs +++ b/apps/maple-agent/app/src/ui/chat/speech.rs @@ -4,8 +4,8 @@ use std::sync::Arc; use gpui::{ - Context, Div, InteractiveElement, IntoElement, ParentElement, SharedString, - StatefulInteractiveElement, Styled, div, px, + Context, InteractiveElement, IntoElement, ParentElement, SharedString, + StatefulInteractiveElement, Styled, div, prelude::FluentBuilder, px, }; use crate::ui::i18n::{UiText, tr}; @@ -224,7 +224,7 @@ pub(super) fn speak_message_button( text: SharedString, speech: Option<&SpeechState>, chat: gpui::WeakEntity, -) -> gpui::Stateful
{ +) -> crate::ui::motion::HoverBackground { let item_id = item_id.to_string(); let (glyph, label) = match speech { None => ( @@ -257,9 +257,12 @@ pub(super) fn speak_message_button( .text_color(gpui::rgb(theme::text_muted())) .opacity(if active { 1. } else { 0. }) .group_hover(group.clone(), |style| style.opacity(1.)) + .map(|element| { + let rest: gpui::Hsla = gpui::transparent_black(); + crate::ui::motion::hover_background(element, rest, gpui::rgb(theme::bg_elevated())) + }) .hover(|style| { style - .bg(gpui::rgb(theme::bg_elevated())) .text_color(gpui::rgb(theme::text_secondary())) .cursor_pointer() }) diff --git a/apps/maple-agent/app/src/ui/chat/tests.rs b/apps/maple-agent/app/src/ui/chat/tests.rs index ad81c79dd..98ff2fca7 100644 --- a/apps/maple-agent/app/src/ui/chat/tests.rs +++ b/apps/maple-agent/app/src/ui/chat/tests.rs @@ -9185,6 +9185,7 @@ mod state_tests { /// A press on an item still reaches the intended action. #[gpui::test] fn test_a_press_on_a_menu_item_reaches_the_item(cx: &mut TestAppContext) { + cx.update(|cx| cx.set_reduce_motion(true)); let (chat, cx) = chat_window(cx, |this, cx| { this.sessions = vec![ summary("s1", "One"), @@ -12653,6 +12654,7 @@ mod state_tests { #[gpui::test] fn test_composer_menu_floats_above_the_composer(cx: &mut TestAppContext) { cx.executor().allow_parking(); + cx.update(|cx| cx.set_reduce_motion(true)); struct ChatHost { chat: Entity, } @@ -14682,6 +14684,8 @@ mod state_tests { #[gpui::test] fn pending_first_send_renders_at_the_conversation_position(cx: &mut TestAppContext) { + // Asserts the preview's settled place, not its entrance. + cx.update(|cx| cx.set_reduce_motion(true)); let (chat, cx) = chat_window(cx, |this, cx| { this.selected_session = None; this.draft = true; diff --git a/apps/maple-agent/app/src/ui/chat/transcript.rs b/apps/maple-agent/app/src/ui/chat/transcript.rs index 6f29ecae0..89b4fd7ad 100644 --- a/apps/maple-agent/app/src/ui/chat/transcript.rs +++ b/apps/maple-agent/app/src/ui/chat/transcript.rs @@ -2,10 +2,13 @@ //! shared `TranscriptCtx` caches; nothing here parses or derives on a //! frame. +use std::cell::{Cell, RefCell}; use std::collections::HashMap; +use std::rc::Rc; use std::sync::Arc; +use std::time::Instant; -use gpui::{Div, Entity, IntoElement, SharedString, Window, div, prelude::*, px}; +use gpui::{Bounds, Div, Entity, IntoElement, Pixels, SharedString, Window, div, prelude::*, px}; use maple_agent::agent::{ AgentPermissionReason, AgentTimelineItem, EXTERNAL_AGENT_ACTIVITY_KEY, ExternalAgentActivity, ExternalAgentRef, USAGE_LIMIT_MESSAGE, @@ -40,6 +43,14 @@ impl ChatScreen { self.list_state .reset_with_uniform_height(count, super::TRANSCRIPT_ROW_ESTIMATE); } + // Entrances read one clock for the whole frame and ask for the next + // frame only while one is still running. + let now = motion::now(); + let reduced = cx.reduce_motion(); + if self.row_motion.settle(now, reduced) { + window.request_animation_frame(); + } + let switch_reveal = self.row_motion.switch_progress(now, reduced); let show_jump = count > 0 && !self.list_state.is_following_tail(); let tool_details = self.tool_details; let entity = cx.entity().downgrade(); @@ -57,6 +68,12 @@ impl ChatScreen { return div().into_any_element(); }; let chat = chat_entity.read(cx); + // A row that arrived live enters, timed from view state so + // scrolling it away and back never replays the entrance. + let entrance = chat + .timeline + .get(ix) + .and_then(|item| chat.row_motion.entrance(&item.id, now, reduced)); let row = match chat.timeline.get(ix) { Some(item) => { let render_ctx = RenderCtx { @@ -79,6 +96,7 @@ impl ChatScreen { speech: chat.speech.as_ref(), speech_available: chat.audio_caps.speech, position: (ix + 1, chat.timeline.len()), + reveal: chat.row_motion.disclosure(&item.id, now, reduced), }; let expanded = tool_details != chat.toggled_tools.contains(&item.id); let revision = chat @@ -139,7 +157,7 @@ impl ChatScreen { // measured for overdraw are not, and a focused row kept alive // off screen lands outside the mask. let painted_rows = painted_rows.clone(); - div() + let row = div() .child(row) .on_children_prepainted(move |bounds, window, _cx| { let view = window.content_mask().bounds; @@ -152,8 +170,31 @@ impl ChatScreen { None => (ix, ix + 1), })); } - }) - .into_any_element() + }); + match entrance { + None => row.into_any_element(), + // Scrolled up: paint offset and opacity only, so nothing + // on screen moves. + Some(Entrance { + progress, + grow: None, + .. + }) => motion::arrive(row, progress).into_any_element(), + // At the tail: the row opens to its height and the rows + // above glide up with it. + Some(Entrance { + progress, + grow: Some(grow), + natural, + }) => grow_in( + row, + progress, + grow, + natural, + chat.row_motion.heights.clone(), + chat.timeline[ix].id.clone(), + ), + } }) .size_full(); div() @@ -215,6 +256,10 @@ impl ChatScreen { .mx_auto() .px_6() .pb_4() + // Another task's transcript fades in when it lands. + .when(switch_reveal < 1., |rows| { + rows.opacity(motion::ease_out_quint(switch_reveal)) + }) .child( // The list's own wheel scrolls it; the pane's must // not scroll it a second time. @@ -338,6 +383,388 @@ impl ChatScreen { "jump-to-latest-reveal", )) } + + /// The slot under the transcript: the message being sent with its + /// status line, or the waiting dots, both `WAITING_ROW_HEIGHT` tall so + /// one taking over from the other moves nothing. + /// + /// It sits outside the list, so its height is taken from the list's + /// viewport. When it appears, or its content grows, it opens over + /// `ENTER` instead of all at once, and the transcript above glides up. + /// Its content stays pinned to its bottom while the top is clipped. It + /// shrinks at once: the row taking its place opens from the space it + /// leaves. + pub(super) fn render_under_transcript( + &mut self, + window: &mut Window, + cx: &mut Context, + ) -> Option { + let appeared = !self.row_motion.slot_on_screen; + let snap = std::mem::take(&mut self.row_motion.slot_snap); + let preview = self.render_send_preview(window, cx); + let dots = self.awaiting_first_token && self.is_run_active() && !self.has_send_feedback(); + let slot = &mut self.row_motion; + slot.slot_on_screen = preview.is_some() || dots; + if !slot.slot_on_screen { + slot.slot_open = None; + slot.slot_natural.set(None); + slot.slot_shown.set(px(0.)); + return None; + } + let now = motion::now(); + let reduced = cx.reduce_motion(); + // Measured last frame; `None` on the frame it appears. + let natural = slot.slot_natural.get().map(f32::from); + if reduced { + slot.slot_open = None; + } else if appeared { + // A send opens it; a task switch or history load shows it at + // once. + slot.slot_open = (!snap).then(|| motion::Tween::new(0.)); + slot.slot_since = Some(now); + } + let cap = match (&mut slot.slot_open, natural) { + (None, None) => None, + (None, Some(natural)) => { + if !reduced { + slot.slot_open = Some(motion::Tween::new(natural)); + } + None + } + // Closed on its first frame while its content is measured. + (Some(open), None) => { + window.request_animation_frame(); + Some(px(open.value(now))) + } + (Some(open), Some(natural)) => { + // Shrinking follows the content at once; growing opens. + // The first opening runs from when the slot appeared, not + // from the frame its content was first measured. + if natural < open.value(now) { + *open = motion::Tween::new(natural); + } + let start = match slot.slot_since.take() { + Some(since) if open.target() == 0. => since, + _ => now, + }; + open.set( + natural, + motion::ENTER, + motion::ease_out_cubic, + start, + reduced, + ); + if open.is_moving(now) { + window.request_animation_frame(); + } + Some(px(open.value(now))) + } + }; + let natural_height = slot.slot_natural.clone(); + let shown_height = slot.slot_shown.clone(); + let content = div() + .flex_none() + .w_full() + .flex() + .flex_col() + .children(preview) + .when(dots, |content| { + // Same gutter as transcript text so the dots line up. + content.child( + div() + .w_full() + .max_w(CONTENT_WIDTH) + .mx_auto() + .px_6() + .child(render_waiting_indicator()), + ) + }); + Some( + div() + .flex_none() + .w_full() + .flex() + .flex_col() + .justify_end() + .overflow_hidden() + .when_some(cap, |slot, cap| slot.max_h(cap)) + .child(content) + .on_children_prepainted(move |bounds, _, _| { + if let Some(content) = bounds.first() { + let height = content.size.height; + natural_height.set(Some(height)); + shown_height.set(cap.map_or(height, |cap| height.min(cap))); + } + }) + .into_any_element(), + ) + } +} + +/// Height of the row under the transcript that shows the waiting dots or, +/// while a message is being sent, its status line. Both take the same +/// slot so one replacing the other moves nothing. +pub(super) const WAITING_ROW_HEIGHT: Pixels = px(36.); + +/// Space between the message being sent and its status line: the +/// transcript's bottom padding, so the real row lands where the preview +/// was. +pub(super) const PREVIEW_GAP: Pixels = px(16.); + +/// Entrances in the transcript, timed from view state. A `gpui::list` +/// drops a row's element state when it scrolls away, so an entrance kept +/// there would replay; these start times outlive the elements, and a +/// finished one is pruned, so a row animates once. +#[derive(Default)] +pub(super) struct RowMotion { + /// Rows that arrived live in the task on screen, by item id. + arrived: HashMap, + /// Natural heights of rows growing into place, measured as they + /// paint; a row's first frame has none and opens from its start. + pub(super) heights: Rc>>, + /// Rows whose details the user just opened, by item id. + disclosed: HashMap, + /// When another task's transcript landed. + switched: Option, + /// The user row that takes over from the send preview on screen, + /// where the preview's bubble was, and how tall the slot under the + /// transcript was then. + handed_off: Option<(String, Option>, Pixels)>, + /// Where the send preview's bubble painted last frame, if it showed. + pub(super) preview_body: Rc>>>, + /// Rows apply without an entrance (events replayed on reconnect). + quiet: bool, + /// The slot under the transcript (waiting dots or the sent message's + /// status) showed last frame. + pub(super) slot_on_screen: bool, + /// The slot's height cap while it opens and after, so it grows rather + /// than appearing at full height; `None` draws it at its natural height. + slot_open: Option, + /// The slot's natural height and the height it drew, last frame. + slot_natural: Rc>>, + slot_shown: Rc>, + /// The next slot to appear shows at once: it came with a task switch + /// or a history load, not a send. + slot_snap: bool, + /// When the slot last appeared, for its first opening. + slot_since: Option, +} + +#[derive(Clone, Copy)] +struct Arrival { + at: Instant, + grow: Option, +} + +/// How a row that arrived at the followed tail opens. +#[derive(Clone, Copy, Debug, PartialEq)] +pub(super) struct Grow { + /// Height it opens from: 0, or the space a vanished preview or + /// waiting row left, so the rows above stay put on the first frame. + pub(super) from: Pixels, + /// Window y its content starts at (the preview's bubble), easing to + /// its own place; such a row is already visible and does not fade. + pub(super) glide_from: Option, +} + +/// A row's entrance at one moment. +pub(super) struct Entrance { + pub(super) progress: f32, + pub(super) grow: Option, + pub(super) natural: Option, +} + +impl RowMotion { + /// A row was added live; history, paging and snapshots never call this. + /// `at_tail`: the list follows its tail, so the row grows into place; + /// otherwise it only fades and rises. + pub(super) fn arrive(&mut self, id: &str, now: Instant, at_tail: bool) { + let handed_off = self.handed_off.take(); + if self.quiet { + return; + } + let grow = match handed_off { + // The preview's bubble becomes this row: it opens from the + // space the bubble left (all of the slot but the status line + // that stays) and glides from where the bubble was. + Some((handed, body, slot)) if handed == id => { + let Some(body) = body.filter(|_| at_tail) else { + return; + }; + Some(Grow { + from: (slot - WAITING_ROW_HEIGHT).max(px(0.)), + glide_from: Some(body.origin.y), + }) + } + _ => at_tail.then_some(Grow { + from: px(0.), + glide_from: None, + }), + }; + self.arrived + .insert(id.to_owned(), Arrival { at: now, grow }); + } + + /// The row `id` also takes the place of `height` that left the space + /// under the transcript (the waiting row or the preview's status). + pub(super) fn open_from_more(&mut self, id: &str, height: Pixels) { + if let Some(Arrival { + grow: Some(grow), .. + }) = self.arrived.get_mut(id) + { + grow.from += height; + } + } + + /// The slot's height on screen last frame. + pub(super) fn slot_height(&self) -> Pixels { + self.slot_shown.get() + } + + /// The next row with `id` replaces the send preview on screen. + pub(super) fn hand_off(&mut self, id: String) { + self.handed_off = Some((id, self.preview_body.get(), self.slot_shown.get())); + } + + /// Apply rows without an entrance until called again with `false`. + pub(super) fn set_quiet(&mut self, quiet: bool) { + self.quiet = quiet; + } + + /// A live row took its persisted id; its entrance carries on. + pub(super) fn rekey(&mut self, old: &str, new: &str) { + if let Some(arrival) = self.arrived.remove(old) { + self.arrived.insert(new.to_owned(), arrival); + } + if let Some(at) = self.disclosed.remove(old) { + self.disclosed.insert(new.to_owned(), at); + } + let mut heights = self.heights.borrow_mut(); + if let Some(height) = heights.remove(old) { + heights.insert(new.to_owned(), height); + } + } + + /// The user opened or closed a row's details. Closing is immediate. + pub(super) fn disclose(&mut self, id: &str, open: bool, now: Instant) { + if open { + self.disclosed.insert(id.to_owned(), now); + } else { + self.disclosed.remove(id); + } + } + + /// Another task's transcript landed. + pub(super) fn switch_task(&mut self, now: Instant) { + self.switched = Some(now); + } + + /// A new transcript replaced every row; none of them is arriving. + pub(super) fn clear_rows(&mut self) { + self.arrived.clear(); + self.heights.borrow_mut().clear(); + self.disclosed.clear(); + self.handed_off = None; + self.slot_snap = true; + } + + /// The empty state shows: nothing sits under a transcript, and the next + /// slot to appear comes with a send, so it opens. + pub(super) fn show_empty_state(&mut self) { + self.slot_on_screen = false; + self.slot_snap = false; + } + + /// The row's entrance, or `None` for a row that did not arrive live or + /// has settled. + pub(super) fn entrance(&self, id: &str, now: Instant, reduced: bool) -> Option { + let arrival = self.arrived.get(id)?; + let progress = motion::progress(arrival.at, motion::ENTER, now, reduced); + (progress < 1.).then(|| Entrance { + progress, + grow: arrival.grow, + natural: arrival + .grow + .and_then(|_| self.heights.borrow().get(id).copied()), + }) + } + + /// Progress of the row's entrance; 1 when it has none. + #[cfg(test)] + pub(super) fn arrival(&self, id: &str, now: Instant, reduced: bool) -> f32 { + self.entrance(id, now, reduced) + .map_or(1., |entrance| entrance.progress) + } + + /// Progress of the fade of details the user just opened. + pub(super) fn disclosure(&self, id: &str, now: Instant, reduced: bool) -> f32 { + self.disclosed + .get(id) + .map_or(1., |at| motion::progress(*at, motion::REVEAL, now, reduced)) + } + + /// Progress of the fade of a task's transcript after a switch. + pub(super) fn switch_progress(&self, now: Instant, reduced: bool) -> f32 { + self.switched + .map_or(1., |at| motion::progress(at, motion::REVEAL, now, reduced)) + } + + /// Drop what has finished; true while something still moves, so the + /// caller asks for another frame. + pub(super) fn settle(&mut self, now: Instant, reduced: bool) -> bool { + if reduced { + self.arrived.clear(); + self.heights.borrow_mut().clear(); + self.disclosed.clear(); + self.switched = None; + return false; + } + let running = |at: &Instant, duration| now.saturating_duration_since(*at) < duration; + self.arrived + .retain(|_, arrival| running(&arrival.at, motion::ENTER)); + self.heights + .borrow_mut() + .retain(|id, _| self.arrived.contains_key(id)); + self.disclosed.retain(|_, at| running(at, motion::REVEAL)); + self.switched = self.switched.filter(|at| running(at, motion::REVEAL)); + !self.arrived.is_empty() || !self.disclosed.is_empty() || self.switched.is_some() + } +} + +/// A row opening at the tail: its box eases from `grow.from` to its +/// natural height, clipped, so the rows above glide up rather than jump. +/// Its natural height is measured from the unclipped content each frame, +/// so a reply streaming in meanwhile still ends at its true height. +fn grow_in( + row: Div, + progress: f32, + grow: Grow, + natural: Option, + heights: Rc>>, + id: String, +) -> gpui::AnyElement { + let eased = motion::ease_out_cubic(progress); + let height = natural.map_or(grow.from, |natural| { + grow.from + (natural - grow.from) * eased + }); + let content = div().absolute().top_0().left_0().right_0().child(row); + let content = match grow.glide_from { + Some(from_y) => motion::glide_from(content, from_y, progress).into_any_element(), + None => content + .opacity(motion::ease_out_quint(progress)) + .into_any_element(), + }; + div() + .relative() + .h(height) + .overflow_hidden() + .child(content) + .on_children_prepainted(move |bounds, _, _| { + if let Some(content) = bounds.first() { + heights.borrow_mut().insert(id.clone(), content.size.height); + } + }) + .into_any_element() } pub(super) fn render_timeline_item( @@ -471,7 +898,7 @@ fn copy_message_button( group: &SharedString, text: SharedString, view: Option, -) -> gpui::Stateful
{ +) -> crate::ui::motion::HoverBackground { widgets::copy_button( SharedString::from(format!("copy-message-{item_id}")), text, @@ -749,12 +1176,9 @@ fn render_thinking( }) .ok(); }) - .child(icon( - if expanded { - "chevron-down" - } else { - "chevron-right" - }, + .child(motion::chevron( + SharedString::from(format!("thinking-chevron-{}", item.id)), + expanded, px(14.), theme::text_muted(), )) @@ -779,7 +1203,7 @@ fn render_thinking( if !expanded { return card; } - card.child( + card.child(revealed( typography::chat_reading(div()) .text_color(gpui::rgb(theme::text_secondary())) .child(markdown::render_with( @@ -788,7 +1212,18 @@ fn render_thinking( .get(&item.id, MarkdownKind::Body, revision, &text), transcript.render, )), - ) + transcript.reveal, + )) +} + +/// Details the user just opened fade in; `reveal` is how far along they +/// are. Their height is there at once, so the list measures it once. +fn revealed(details: E, reveal: f32) -> E { + if reveal < 1. { + details.opacity(motion::ease_out_quint(reveal)) + } else { + details + } } fn tool_status_style(status: Option<&str>) -> (SharedString, u32) { @@ -800,6 +1235,42 @@ fn tool_status_style(status: Option<&str>) -> (SharedString, u32) { } } +/// A tool card's spinner and status label. When the call finishes on +/// screen the running state goes at once and the outcome fades in over +/// [`motion::TOGGLE`]: two labels drawn over each other would read as +/// one garbled word. A card that mounts finished (history, a row scrolled +/// back) shows its state at once. +fn tool_status(item_id: &str, running: bool, label: SharedString, color: u32) -> motion::Animated { + let spinner_id = SharedString::from(format!("tool-spinner-{item_id}")); + motion::animated( + SharedString::from(format!("tool-status-{item_id}")), + if running { 0. } else { 1. }, + motion::TOGGLE, + motion::ease_out_cubic, + move |done| { + div() + .flex() + .items_center() + .gap_2() + .opacity(if running { 1. - done } else { done }) + .when(running, |state| { + state.child(spinner_with_id( + spinner_id.clone(), + px(12.), + theme::accent(), + )) + }) + .child( + div() + .text_xs() + .text_color(gpui::rgb(color)) + .child(label.clone()), + ) + .into_any_element() + }, + ) +} + /// True when the tool call input has the given top-level key. pub(super) fn has_tool_input(item: &AgentTimelineItem, key: &str) -> bool { item.input @@ -963,24 +1434,22 @@ fn render_finished_plan( .text_color(gpui::rgb(theme::text_muted())) .child(count), ) - .child(icon( - if details { - "chevron-down" - } else { - "chevron-right" - }, + .child(motion::chevron( + SharedString::from(format!("plan-chevron-{}", item.id)), + details, px(14.), theme::text_muted(), )), ); if details { - card = card.child( + card = card.child(revealed( div() .flex() .flex_col() .gap_1() .children(plan.iter().map(render_plan_row)), - ); + transcript.reveal, + )); } Some(div().child(card)) } @@ -1217,7 +1686,7 @@ fn render_tool_with_diff( ); } // The diff is content: swallow clicks so selecting it does not toggle. - card.child( + card.child(revealed( div() .id(gpui::SharedString::from(format!("tool-diff-{}", item.id))) .on_click( @@ -1226,7 +1695,8 @@ fn render_tool_with_diff( }, ) .child(diff), - ) + transcript.reveal, + )) } /// Title shown before the model summary arrives: just the tool label from @@ -1329,25 +1799,10 @@ fn render_tool( .debug_selector(|| "tool-title".to_string()) .child(title), ) - .when(running, |header| { - header.child(spinner_with_id( - SharedString::from(format!("tool-spinner-{}", item.id)), - px(12.), - theme::accent(), - )) - }) - .child( - div() - .text_xs() - .text_color(gpui::rgb(status_color)) - .child(label), - ) - .child(icon( - if details { - "chevron-down" - } else { - "chevron-right" - }, + .child(tool_status(&item.id, running, label, status_color)) + .child(motion::chevron( + SharedString::from(format!("tool-chevron-{}", item.id)), + details, px(14.), theme::text_muted(), )), @@ -1359,8 +1814,9 @@ fn render_tool( } let derived = transcript.derived.get(item, revision); if let Some(activity) = &derived.external_agent { - return div().child(card.child(render_external_agent_activity( - item, revision, activity, transcript, + return div().child(card.child(revealed( + render_external_agent_activity(item, revision, activity, transcript), + transcript.reveal, ))); } // A click anywhere on the card, payload included, toggles it. @@ -1397,7 +1853,7 @@ fn render_tool( )), ); } - div().child(card.child(payload)) + div().child(card.child(revealed(payload, transcript.reveal))) } /// Keep a card's output out of the shared selection, which would treat its @@ -1849,12 +2305,9 @@ pub(super) fn render_question_card( .on_click(cx.listener(|this, _event, _window, cx| { this.toggle_question_collapsed(cx); })) - .child(lead().child(icon( - if collapsed { - "chevron-right" - } else { - "chevron-down" - }, + .child(lead().child(motion::chevron( + "question-card-chevron", + !collapsed, px(14.), theme::text_secondary(), ))) @@ -1977,6 +2430,13 @@ pub(super) fn render_question_card( .child(option.description.clone()), ) }); + // A single choice answers on the click, so the only row it + // marks is the one the keyboard is on. + let marked = if entry.multi_select { + is_cursor + } else { + is_picked + }; let row = div() .id(gpui::SharedString::from(format!( "question-option-{question_index}-{option_index}" @@ -1990,21 +2450,22 @@ pub(super) fn render_question_card( .px_1p5() .py_1() .rounded(theme::RADIUS_SM) - // A single choice answers on the click, so the only row it - // marks is the one the keyboard is on. - .when( - if entry.multi_select { - is_cursor + .when(marked, |row| { + row.bg(gpui::rgb(theme::bg_sidebar_row_hover())) + }) + .map(|element| { + let rest: gpui::Hsla = if marked { + gpui::rgb(theme::bg_sidebar_row_hover()).into() } else { - is_picked - }, - |row| row.bg(gpui::rgb(theme::bg_sidebar_row_hover())), - ) - .hover(|style| { - style - .bg(gpui::rgb(theme::bg_sidebar_row_hover())) - .cursor_pointer() + gpui::transparent_black() + }; + crate::ui::motion::hover_background( + element, + rest, + gpui::rgb(theme::bg_sidebar_row_hover()), + ) }) + .hover(|style| style.cursor_pointer()) .on_click({ cx.listener(move |this, _event, _window, cx| { this.toggle_question_option(question_index, option_index, cx); @@ -2137,7 +2598,8 @@ pub(super) fn render_question_card( .child(gpui::text!(tr("chat-skip"))) .child(widgets::keycap("esc")), ); - let footer_button = |button: gpui::Stateful
| button.flex_none().px_3().py_1().text_xs(); + let footer_button = + |button: motion::HoverBackground| button.flex_none().px_3().py_1().text_xs(); if permission.is_some() { // Deny and Allow once sit here at every width, never beside the call. for (option_index, button) in [ @@ -2173,10 +2635,11 @@ pub(super) fn render_question_card( /// Pulsing dots shown between send and the first streamed content. They /// breathe on the shared low-rate clock, so waiting costs the same as a -/// spinner rather than a full-rate animation. -pub(super) fn render_waiting_indicator() -> gpui::Stateful
{ +/// spinner rather than a full-rate animation. They fade in when they +/// appear and leave at once when the reply arrives. +pub(super) fn render_waiting_indicator() -> impl IntoElement { const CYCLE: std::time::Duration = std::time::Duration::from_millis(1400); - div() + let indicator = div() .id("waiting-indicator") .role(gpui::Role::Status) .aria_label(tr("chat-thinking-label")) @@ -2184,7 +2647,8 @@ pub(super) fn render_waiting_indicator() -> gpui::Stateful
{ .items_center() .gap_2() .px_4() - .py_2() + // The send preview's status line takes the same slot. + .h(WAITING_ROW_HEIGHT) .child(motion::ticker("waiting-dots", CYCLE, |phase| { let mut row = div().flex().items_center().gap_1p5(); for index in 0..3 { @@ -2204,5 +2668,700 @@ pub(super) fn render_waiting_indicator() -> gpui::Stateful
{ .text_sm() .text_color(gpui::rgb(theme::text_muted())) .child(tr("chat-thinking-label")), - ) + ); + motion::fade_in(indicator, "waiting-indicator-reveal") +} + +#[cfg(test)] +mod motion_tests { + use std::time::{Duration, Instant}; + + use gpui::{Bounds, Context, Pixels, TestAppContext}; + + use super::WAITING_ROW_HEIGHT; + + use crate::ui::chat::*; + use crate::ui::motion; + + fn item(id: &str, item_type: &str, text: Option<&str>) -> AgentTimelineItem { + AgentTimelineItem { + label: None, + persisted: None, + live: None, + truncated: None, + revision: 0, + id: id.to_string(), + item_type: item_type.to_string(), + role: None, + title: None, + text: text.map(str::to_string), + status: None, + input: None, + output: None, + created_ms: 0, + merge: "replace".to_string(), + } + } + + fn user_item(id: &str, text: &str) -> AgentTimelineItem { + AgentTimelineItem { + role: Some("user".to_string()), + ..item(id, "message", Some(text)) + } + } + + fn screen(cx: &mut TestAppContext) -> Entity { + cx.executor().allow_parking(); + cx.new(|cx| { + let _guard = crate::settings::SETTINGS_IO_LOCK.lock(); + let backend = std::sync::Arc::new( + crate::backend::AgentBackend::for_test( + "http://127.0.0.1:9".to_string(), + String::new(), + ) + .expect("backend"), + ); + let mut chat = ChatScreen::new_inner_for_test(backend, "user".to_string(), cx); + chat.selected_session = Some("s1".to_string()); + chat + }) + } + + /// Pins the motion clock for one test and returns it to the real + /// clock when the test ends, pass or fail. + struct Clock(Instant); + + impl Clock { + fn start() -> Self { + let start = Instant::now(); + motion::set_test_now(Some(start)); + Self(start) + } + + fn at(&self, offset: Duration) -> Instant { + motion::set_test_now(Some(self.0 + offset)); + self.0 + offset + } + } + + impl Drop for Clock { + fn drop(&mut self) { + motion::set_test_now(None); + } + } + + /// Whether any transcript entrance still asks for frames at `now`. + fn in_flight( + chat: &Entity, + now: Instant, + cx: &mut gpui::VisualTestContext, + ) -> bool { + chat.update(cx, |chat, _| chat.row_motion.settle(now, false)) + } + + /// The chat pane's middle: the transcript and the slot under it. + struct PaneHost { + chat: Entity, + } + + impl Render for PaneHost { + fn render(&mut self, window: &mut Window, cx: &mut Context) -> impl IntoElement { + let pane = self.chat.update(cx, |chat, cx| { + let transcript = chat.render_transcript(window, cx); + let under = chat.render_under_transcript(window, cx); + div() + .size_full() + .flex() + .flex_col() + .child(transcript) + .children(under) + }); + div().w(px(1200.)).h(px(800.)).flex().flex_col().child(pane) + } + } + + fn pane( + cx: &mut TestAppContext, + rows: usize, + ) -> (Entity, &mut gpui::VisualTestContext) { + let chat = screen(cx); + chat.update(cx, |chat, _| { + chat.replace_timeline( + (0..rows) + .map(|index| item(&format!("h{index}"), "message", Some("Earlier row"))) + .collect(), + ); + }); + let (_host, cx) = cx.add_window_view(|_, _| PaneHost { chat: chat.clone() }); + cx.simulate_resize(gpui::size(px(1200.), px(800.))); + cx.run_until_parked(); + (chat, cx) + } + + fn redraw(chat: &Entity, cx: &mut gpui::VisualTestContext) { + chat.update(cx, |_, cx| cx.notify()); + cx.run_until_parked(); + } + + fn bounds(cx: &mut gpui::VisualTestContext, selector: &'static str) -> Bounds { + cx.debug_bounds(selector) + .unwrap_or_else(|| panic!("{selector} painted")) + } + + /// Samples each selector's top at 60 fps through one entrance that + /// began at `start`. + fn tops_through_entrance( + chat: &Entity, + clock: &Clock, + start: Duration, + selectors: &[&'static str], + cx: &mut gpui::VisualTestContext, + ) -> Vec> { + let mut tops = vec![Vec::new(); selectors.len()]; + let mut at = Duration::ZERO; + while at <= motion::ENTER + Duration::from_millis(16) { + clock.at(start + at); + redraw(chat, cx); + for (selector, tops) in selectors.iter().zip(&mut tops) { + tops.push(bounds(cx, selector).origin.y); + } + at += Duration::from_millis(16); + } + tops + } + + /// Every frame-to-frame move stays within what the easing allows: no + /// single-frame jump. + fn assert_glides(tops: &[Pixels], label: &str) { + let total = (tops[0] - tops[tops.len() - 1]).abs(); + // ease_out_cubic is steepest at its start: 3x the mean speed, or + // 16 ms * 3 / 180 ms of the distance per frame. + let limit = total * 0.3 + px(1.); + for pair in tops.windows(2) { + assert!( + (pair[1] - pair[0]).abs() <= limit, + "{label} jumped {:?} in one frame (limit {limit:?}): {tops:?}", + pair[1] - pair[0] + ); + } + } + + #[gpui::test] + fn a_row_arriving_while_scrolled_up_rises_without_a_layout_change(cx: &mut TestAppContext) { + let clock = Clock::start(); + let (chat, cx) = pane(cx, 3); + assert!(!in_flight(&chat, clock.0, cx), "history arrives at rest"); + chat.update(cx, |chat, cx| { + chat.list_state.pause_following_tail(); + chat.apply_incoming_item("s1", item("live", "message", Some("Hello")), cx); + }); + redraw(&chat, cx); + let entering = bounds(cx, "timeline-row-live"); + + let midway = clock.at(motion::ENTER / 2); + let progress = chat.update(cx, |chat, _| chat.row_motion.arrival("live", midway, false)); + assert!( + progress > 0. && progress < 1., + "mid-entrance, got {progress}" + ); + assert!(in_flight(&chat, midway, cx), "frames continue mid-entrance"); + + let done = clock.at(motion::ENTER); + redraw(&chat, cx); + let settled = bounds(cx, "timeline-row-live"); + assert_eq!(entering.size, settled.size, "the rise never changes layout"); + assert_eq!(entering.origin.y - settled.origin.y, motion::RISE); + assert!(!in_flight(&chat, done, cx), "frames stop once it settles"); + + // Scrolled away and back, the row is drawn at rest: no replay. + chat.update(cx, |chat, _| { + chat.list_state.scroll_to(gpui::ListOffset { + item_ix: 0, + offset_in_item: px(0.), + }); + }); + redraw(&chat, cx); + chat.update(cx, |chat, _| chat.list_state.scroll_to_end()); + redraw(&chat, cx); + assert_eq!(cx.debug_bounds("timeline-row-live"), Some(settled)); + assert!(!in_flight(&chat, done, cx)); + } + + #[gpui::test] + fn a_tail_row_grows_into_place_and_older_rows_glide(cx: &mut TestAppContext) { + let clock = Clock::start(); + let (chat, cx) = pane(cx, 30); + let before = bounds(cx, "timeline-row-h29"); + chat.update(cx, |chat, cx| { + chat.apply_incoming_item( + "s1", + item("live", "message", Some("Hello\n\nA second paragraph")), + cx, + ); + }); + let tops = tops_through_entrance(&chat, &clock, Duration::ZERO, &["timeline-row-h29"], cx) + .remove(0); + assert!( + (tops[0] - before.origin.y).abs() <= px(1.), + "older rows hold still on the arrival frame: {before:?} then {tops:?}" + ); + assert!( + tops[tops.len() - 1] < before.origin.y, + "older rows made room" + ); + assert!( + tops.windows(2).all(|pair| pair[1] <= pair[0]), + "older rows only rise: {tops:?}" + ); + assert_glides(&tops, "an older row"); + assert!(!in_flight(&chat, clock.at(motion::ENTER), cx)); + + // The settled layout is the one without motion. + let older = bounds(cx, "timeline-row-h29"); + let live = bounds(cx, "timeline-row-live"); + chat.update(cx, |chat, _| { + let rows = chat.timeline.clone(); + chat.replace_timeline(rows); + }); + redraw(&chat, cx); + assert_eq!(bounds(cx, "timeline-row-h29"), older); + assert_eq!(bounds(cx, "timeline-row-live"), live); + } + + #[gpui::test] + fn a_reply_streaming_while_it_opens_ends_at_its_true_height(cx: &mut TestAppContext) { + let clock = Clock::start(); + let (chat, cx) = pane(cx, 30); + chat.update(cx, |chat, cx| { + chat.apply_incoming_item("s1", item("reply", "message", Some("Answer:")), cx); + }); + redraw(&chat, cx); + clock.at(motion::ENTER / 3); + redraw(&chat, cx); + chat.update(cx, |chat, cx| { + chat.apply_incoming_item( + "s1", + AgentTimelineItem { + merge: "append".to_string(), + text: Some("\n\nMore lines\n\nAnd more".to_string()), + ..item("reply", "message", None) + }, + cx, + ); + }); + for step in [motion::ENTER / 2, motion::ENTER * 3 / 4, motion::ENTER] { + clock.at(step); + redraw(&chat, cx); + } + let older = bounds(cx, "timeline-row-h29"); + let reply = bounds(cx, "timeline-row-reply"); + chat.update(cx, |chat, _| { + let rows = chat.timeline.clone(); + chat.replace_timeline(rows); + }); + redraw(&chat, cx); + assert_eq!(bounds(cx, "timeline-row-h29"), older); + assert_eq!(bounds(cx, "timeline-row-reply"), reply); + } + + #[gpui::test] + fn the_sent_bubble_rises_in_and_its_status_does_not(cx: &mut TestAppContext) { + let clock = Clock::start(); + let (chat, cx) = pane(cx, 3); + chat.update(cx, |chat, _| { + let preview = sending::SendPreview::new(Some("s1".into()), "hello", &[]) + .capture_timeline(&chat.timeline); + chat.sending_previews.insert("send-1".into(), preview); + }); + redraw(&chat, cx); + let entering = bounds(cx, "pending-send-body"); + let status = bounds(cx, "pending-send-status"); + clock.at(motion::ENTER); + redraw(&chat, cx); + let settled = bounds(cx, "pending-send-body"); + assert_eq!(entering.origin.y - settled.origin.y, motion::RISE); + assert_eq!(entering.size, settled.size); + assert_eq!( + bounds(cx, "pending-send-status"), + status, + "the status line has no offset of its own or its parent's" + ); + assert_eq!(status.size.height, WAITING_ROW_HEIGHT); + } + + #[gpui::test] + fn sending_opens_the_slot_so_older_rows_glide_up(cx: &mut TestAppContext) { + let clock = Clock::start(); + let (chat, cx) = pane(cx, 30); + let before = bounds(cx, "timeline-row-h29"); + chat.update(cx, |chat, _| { + let preview = sending::SendPreview::new(Some("s1".into()), "hello", &[]) + .capture_timeline(&chat.timeline); + chat.sending_previews.insert("send-1".into(), preview); + }); + let tops = tops_through_entrance(&chat, &clock, Duration::ZERO, &["timeline-row-h29"], cx) + .remove(0); + assert!( + (tops[0] - before.origin.y).abs() <= px(1.), + "older rows hold still on the send frame: {before:?} then {tops:?}" + ); + assert!(tops[tops.len() - 1] < before.origin.y, "the slot made room"); + assert!( + tops.windows(2).all(|pair| pair[1] <= pair[0]), + "older rows only rise: {tops:?}" + ); + assert_glides(&tops, "an older row"); + let older = bounds(cx, "timeline-row-h29"); + let bubble = bounds(cx, "pending-send-body"); + let status = bounds(cx, "pending-send-status"); + + // The settled layout is the one without motion. + cx.update(|_, cx| cx.set_reduce_motion(true)); + redraw(&chat, cx); + assert_eq!(bounds(cx, "timeline-row-h29"), older); + assert_eq!(bounds(cx, "pending-send-body"), bubble); + assert_eq!(bounds(cx, "pending-send-status"), status); + } + + #[gpui::test] + fn the_first_send_in_an_empty_task_opens_its_slot(cx: &mut TestAppContext) { + // The whole screen, so the empty state draws in place of the + // transcript until the first send. + struct ScreenHost { + chat: Entity, + } + impl Render for ScreenHost { + fn render(&mut self, _: &mut Window, _: &mut Context) -> impl IntoElement { + div().size_full().flex().flex_col().child(self.chat.clone()) + } + } + let clock = Clock::start(); + let chat = screen(cx); + // A new task: a blank transcript replaced the last one. + chat.update(cx, |chat, _| chat.replace_timeline(Vec::new())); + let (_host, cx) = cx.add_window_view(|_, _| ScreenHost { chat: chat.clone() }); + cx.simulate_resize(gpui::size(px(1200.), px(800.))); + cx.run_until_parked(); + assert!(chat.read_with(cx, |chat, _| chat.shows_empty_state())); + chat.update(cx, |chat, _| { + let preview = sending::SendPreview::new(Some("s1".into()), "hello", &[]) + .capture_timeline(&chat.timeline); + chat.sending_previews.insert("send-1".into(), preview); + }); + redraw(&chat, cx); + let shown = |chat: &Entity, cx: &mut gpui::VisualTestContext| { + chat.read_with(cx, |chat, _| chat.row_motion.slot_shown.get()) + }; + let sent = shown(&chat, cx); + clock.at(motion::ENTER * 2); + redraw(&chat, cx); + let open = shown(&chat, cx); + assert!(open > px(0.), "the slot shows its status"); + assert!( + sent < open, + "the send opens the slot rather than showing it at full height: {sent:?} then {open:?}" + ); + } + + /// The newest history row's top before `land`, and through the entrance + /// of the row it adds, once the slot under the transcript is open. + fn older_row_through_error( + chat: &Entity, + clock: &Clock, + land: impl FnOnce(&mut ChatScreen, &mut Context), + cx: &mut gpui::VisualTestContext, + ) -> (Pixels, Vec) { + // The slot appears, then opens over ENTER. + redraw(chat, cx); + let start = motion::ENTER * 2; + clock.at(start); + redraw(chat, cx); + assert!( + chat.read_with(cx, |chat, _| chat.row_motion.slot_shown.get()) > px(0.), + "the slot is open before the error" + ); + let before = bounds(cx, "timeline-row-h29").origin.y; + chat.update(cx, land); + let tops = tops_through_entrance(chat, clock, start, &["timeline-row-h29"], cx).remove(0); + (before, tops) + } + + #[gpui::test] + fn a_run_error_takes_the_waiting_rows_place(cx: &mut TestAppContext) { + let clock = Clock::start(); + let (chat, cx) = pane(cx, 30); + // A run is going and nothing has come back yet: the waiting dots show. + chat.update(cx, |chat, _| { + chat.active_runs.insert("s1".into(), "run-1".into()); + chat.awaiting_first_token = true; + }); + let (before, tops) = older_row_through_error( + &chat, + &clock, + |chat, cx| { + for event in [ + maple_agent::agent::AgentRunEvent::Error(item( + "failed", + "error", + Some("The model is unavailable."), + )), + maple_agent::agent::AgentRunEvent::Finished( + maple_agent::agent::AgentRunTerminal::Completed, + ), + ] { + chat.handle_service_event( + AgentServiceEvent::Run { + session_id: "s1".into(), + run_id: "run-1".into(), + event, + }, + cx, + ); + } + }, + cx, + ); + assert!( + (tops[0] - before).abs() <= px(1.), + "older rows hold still as the error replaces the dots: {before:?} then {tops:?}" + ); + assert_glides(&tops, "an older row"); + } + + #[gpui::test] + fn a_failed_send_reports_its_error_in_the_slots_place(cx: &mut TestAppContext) { + let clock = Clock::start(); + let (chat, cx) = pane(cx, 30); + chat.update(cx, |chat, _| { + let preview = sending::SendPreview::new(Some("s1".into()), "hello", &[]) + .capture_timeline(&chat.timeline); + chat.sending_previews.insert("send-1".into(), preview); + chat.awaiting_first_token = true; + }); + let (before, tops) = older_row_through_error( + &chat, + &clock, + |chat, cx| { + let backend = chat.backend.clone(); + chat.finish_send( + "send-1".into(), + UnresolvedSend { + backend, + outcome: None, + session: "s1".into(), + text: "hello".into(), + attachments: vec![], + from_composer: false, + }, + Err(UiFailure::Local( + "chat-upload-cancelled-unsent", + "Upload cancelled. No message was sent.", + )), + cx, + ); + }, + cx, + ); + assert!( + chat.read_with(cx, |chat, _| chat + .timeline + .iter() + .any(|row| row.item_type == "error")), + "the failure shows as an error row" + ); + assert!( + (tops[0] - before).abs() <= px(1.), + "older rows hold still as the error replaces the bubble: {before:?} then {tops:?}" + ); + assert_glides(&tops, "an older row"); + } + + #[gpui::test] + fn the_real_row_takes_over_from_the_bubble_without_a_jump(cx: &mut TestAppContext) { + let clock = Clock::start(); + let (chat, cx) = pane(cx, 30); + chat.update(cx, |chat, _| { + let preview = sending::SendPreview::new(Some("s1".into()), "hello", &[]) + .capture_timeline(&chat.timeline); + chat.sending_previews.insert("send-1".into(), preview); + }); + redraw(&chat, cx); + let start = motion::ENTER * 2; + clock.at(start); + redraw(&chat, cx); + let bubble = bounds(cx, "pending-send-body"); + let older = bounds(cx, "timeline-row-h29"); + let status = bounds(cx, "pending-send-status"); + + chat.update(cx, |chat, cx| { + chat.handle_service_event( + AgentServiceEvent::TimelineItem { + session_id: "s1".into(), + run_id: Some("run-1".into()), + item: user_item("mine", "hello"), + }, + cx, + ); + }); + let tops = tops_through_entrance( + &chat, + &clock, + start, + &[ + "timeline-row-mine", + "timeline-row-h29", + "pending-send-status", + ], + cx, + ); + assert!(cx.debug_bounds("pending-send-body").is_none(), "handed off"); + assert!( + (tops[0][0] - bubble.origin.y).abs() <= px(1.), + "the row starts where the bubble was: {bubble:?} then {:?}", + tops[0] + ); + assert!( + (tops[1][0] - older.origin.y).abs() <= px(1.), + "older rows hold still on the handoff frame: {older:?} then {:?}", + tops[1] + ); + assert!( + tops[2].iter().all(|top| *top == status.origin.y), + "the status line keeps its slot: {:?}", + tops[2] + ); + assert_glides(&tops[0], "the handed-off row"); + assert_glides(&tops[1], "an older row"); + } + + #[gpui::test] + fn history_task_switches_paging_and_reconnects_do_not_animate(cx: &mut TestAppContext) { + let clock = Clock::start(); + let chat = screen(cx); + chat.update(cx, |chat, cx| { + let now = clock.0; + // A history load. + chat.replace_timeline(vec![ + user_item("u1", "hi"), + item("a1", "message", Some("yo")), + ]); + assert_eq!(chat.row_motion.arrival("a1", now, false), 1.); + // Another task's snapshot replaces a row that was still entering. + chat.apply_incoming_item("s1", item("a2", "message", Some("more")), cx); + assert!(chat.row_motion.arrival("a2", now, false) < 1.); + chat.set_active_session( + AgentSessionSummary { + web_enabled: true, + permission_mode: Default::default(), + state: maple_agent::agent::AgentTaskState::Active, + acp: false, + id: "s2".to_string(), + title: "Other".to_string(), + project_root: "/tmp/proj".to_string(), + created_ms: 0, + updated_ms: 0, + message_count: 1, + model: None, + thinking_level: None, + }, + vec![ + item("a2", "message", Some("more")), + item("b1", "message", None), + ], + HashMap::new(), + cx, + ); + assert_eq!(chat.row_motion.arrival("a2", now, false), 1.); + assert_eq!(chat.row_motion.arrival("b1", now, false), 1.); + // A forward history page is open: live rows wait for a reload. + chat.pages.after = true; + chat.apply_incoming_item("s2", item("paged", "message", Some("x")), cx); + assert_eq!(chat.row_motion.arrival("paged", now, false), 1.); + chat.pages.after = false; + // Pushes replayed after a reconnect rebuild the transcript. + chat.replay_after_reconnect( + vec![AgentServiceEvent::TimelineItem { + session_id: "s2".into(), + run_id: None, + item: item("replayed", "message", Some("x")), + }], + cx, + ); + assert!( + chat.timeline.iter().any(|row| row.id == "replayed"), + "the replayed push landed" + ); + assert_eq!(chat.row_motion.arrival("replayed", now, false), 1.); + assert!(!chat.row_motion.settle(now, false)); + // Reduced motion: a live row is at rest at once. + chat.apply_incoming_item("s2", item("live", "message", Some("x")), cx); + assert_eq!(chat.row_motion.arrival("live", now, true), 1.); + assert!(!chat.row_motion.settle(now, true)); + }); + } + + #[gpui::test] + fn streaming_into_a_row_does_not_restart_its_entrance(cx: &mut TestAppContext) { + let clock = Clock::start(); + let chat = screen(cx); + let chunk = || AgentTimelineItem { + merge: "append".to_string(), + text: Some(" more".to_string()), + ..item("reply", "message", None) + }; + chat.update(cx, |chat, cx| { + chat.apply_incoming_item("s1", item("reply", "message", Some("Hi")), cx); + let midway = clock.at(motion::ENTER / 2); + let before = chat.row_motion.arrival("reply", midway, false); + chat.apply_incoming_item("s1", chunk(), cx); + assert_eq!(chat.row_motion.arrival("reply", midway, false), before); + let done = clock.at(motion::ENTER); + assert!(!chat.row_motion.settle(done, false)); + chat.apply_incoming_item("s1", chunk(), cx); + assert_eq!(chat.timeline[0].text.as_deref(), Some("Hi more more")); + assert_eq!(chat.row_motion.arrival("reply", done, false), 1.); + assert!(!chat.row_motion.settle(done, false)); + }); + } + + #[gpui::test] + fn the_row_replacing_the_send_preview_does_not_enter_again(cx: &mut TestAppContext) { + let clock = Clock::start(); + let chat = screen(cx); + chat.update(cx, |chat, cx| { + let preview = sending::SendPreview::new(Some("s1".into()), "hello", &[]) + .capture_timeline(&chat.timeline); + chat.sending_previews.insert("send-1".into(), preview); + assert!(chat.has_send_feedback()); + let projected = |id: &str, run: &str| AgentServiceEvent::TimelineItem { + session_id: "s1".into(), + run_id: Some(run.into()), + item: user_item(id, "hello"), + }; + chat.handle_service_event(projected("mine", "run-1"), cx); + assert_eq!(chat.timeline.len(), 1); + assert_eq!(chat.row_motion.arrival("mine", clock.0, false), 1.); + // A message sent from another computer has no preview here. + chat.handle_service_event(projected("theirs", "run-2"), cx); + assert!(chat.row_motion.arrival("theirs", clock.0, false) < 1.); + }); + } + + #[gpui::test] + fn opening_a_task_shows_the_spinner_only_after_a_moment(cx: &mut TestAppContext) { + let clock = Clock::start(); + let chat = screen(cx); + chat.update(cx, |chat, cx| { + chat.select_session("s2", cx); + assert_eq!(chat.loading_session.as_deref(), Some("s2")); + assert!(!chat.loading_spinner_due()); + clock.at(super::super::LOADING_SPINNER_DELAY - Duration::from_millis(1)); + assert!(!chat.loading_spinner_due()); + clock.at(super::super::LOADING_SPINNER_DELAY); + assert!(chat.loading_spinner_due()); + // Clicking the same task again keeps the open's start time. + chat.select_session("s2", cx); + assert!(chat.loading_spinner_due()); + }); + } } diff --git a/apps/maple-agent/app/src/ui/login.rs b/apps/maple-agent/app/src/ui/login.rs index ee4e5cf91..5f2ac153a 100644 --- a/apps/maple-agent/app/src/ui/login.rs +++ b/apps/maple-agent/app/src/ui/login.rs @@ -626,7 +626,7 @@ impl Render for LoginScreen { } } -fn submit_button(busy: bool, cx: &mut Context) -> gpui::Stateful
{ +fn submit_button(busy: bool, cx: &mut Context) -> crate::ui::motion::HoverBackground { widgets::primary_button("login-submit") .w_full() .mt_1() @@ -652,7 +652,7 @@ fn oauth_button( provider: OAuthProvider, busy: bool, cx: &mut Context, -) -> gpui::Stateful
{ +) -> crate::ui::motion::HoverBackground { widgets::secondary_button(gpui::SharedString::from(format!( "oauth-{}", provider.label().to_lowercase() diff --git a/apps/maple-agent/app/src/ui/motion.rs b/apps/maple-agent/app/src/ui/motion.rs index 86c277557..bac31d401 100644 --- a/apps/maple-agent/app/src/ui/motion.rs +++ b/apps/maple-agent/app/src/ui/motion.rs @@ -1,18 +1,23 @@ -//! Motion primitives that keep the frame rate low. +//! Motion primitives. The rules and tokens are in `docs/motion.md`. //! -//! gpui's own animation element asks for a frame on every display tick, -//! and each frame re-renders the whole window. Two patterns keep motion -//! cheap: +//! Every animated frame re-renders the window, so motion here is short +//! and asks for frames only while something moves: //! //! - Looping effects (spinners, pulsing dots) run through [`ticker`]: a //! shared phase clock plus one coalesced repaint per view per interval, //! at a rate the eye still reads as continuous (`LOOP_FPS`). -//! - One-shot effects (a popup fading in) use [`fade_in`], which wraps -//! gpui's oneshot `with_animation`: it requests frames only until the -//! animation ends, then the window goes idle again. +//! - One-shot entrances ([`fade_in`], [`rise_in`], [`slide_in`]) wrap +//! gpui's oneshot `with_animation`: they request frames until they end, +//! then the window goes idle again. A new element id replays them. +//! - Reversible state changes keep a [`Tween`], which retargets from the +//! value on screen: in view state for transitions a view owns (the +//! sidebar, the composer), or in element state through [`animated`] and +//! [`hover_background`] for render code that owns none. //! -//! Nothing here animates hover or press: gpui has no style transitions, -//! and a stepped scale change on hover reads as flicker. +//! Everything settles at its end state under reduced motion. gpui cannot +//! transform a `div`, so movement is a paint offset ([`Shifted`]) that +//! leaves layout alone; only SVG icons scale or rotate. Press feedback +//! stays immediate. use std::cell::RefCell; use std::collections::HashSet; @@ -21,15 +26,166 @@ use std::time::{Duration, Instant}; use gpui::{ AnimationElement, AnimationExt, AnyElement, App, Bounds, Element, ElementId, EntityId, - GlobalElementId, InspectorElementId, IntoElement, LayoutId, Pixels, Styled, Window, + GlobalElementId, InspectorElementId, IntoElement, LayoutId, ParentElement, Pixels, Point, + Styled, Window, px, }; /// Frames per second a looping effect asks for. Twelve to fifteen steps a /// second still read as motion at a fraction of the display rate. pub const LOOP_FPS: u32 = 15; -/// Duration of a one-shot reveal. +/// Pointer hover: background and opacity only, the same both ways. +pub const HOVER: Duration = Duration::from_millis(120); +/// Menus, popovers, tooltips, notices, and content that replaces other +/// content (a Settings section, another task). pub const REVEAL: Duration = Duration::from_millis(140); +/// A control changing state in place: switches, chevrons, icon swaps. +pub const TOGGLE: Duration = Duration::from_millis(150); +/// Content arriving: live transcript rows, cards, dialogs. +pub const ENTER: Duration = Duration::from_millis(180); +/// Panels changing size: the sidebar and the expanded composer. +pub const PANEL: Duration = Duration::from_millis(200); +/// How far arriving content travels before it settles. +pub const RISE: Pixels = px(6.); + +/// Time for a box to grow or shrink by `distance`: about 500 px a second, +/// so one line of text takes the shortest time and a large jump [`PANEL`]. +pub fn resize_duration(distance: Pixels) -> Duration { + let millis = (distance.as_f32().abs() * 2.).clamp(120., PANEL.as_millis() as f32); + Duration::from_millis(millis as u64) +} + +/// Entrances and fades: a fast start and a long settle. +pub fn ease_out_quint(t: f32) -> f32 { + 1. - (1. - t).powi(5) +} + +/// Movement and size: gentler than [`ease_out_quint`], so a moving edge +/// stays readable. +pub fn ease_out_cubic(t: f32) -> f32 { + 1. - (1. - t).powi(3) +} + +/// Hover, which reverses often: the same curve both ways. +pub fn smoothstep(t: f32) -> f32 { + t * t * (3. - 2. * t) +} + +#[cfg(test)] +thread_local! { + static TEST_NOW: std::cell::Cell> = const { std::cell::Cell::new(None) }; +} + +/// The clock transitions read. Tests pin it with [`set_test_now`], since +/// the test executor's clock does not advance `Instant`. +pub fn now() -> Instant { + #[cfg(test)] + if let Some(now) = TEST_NOW.with(std::cell::Cell::get) { + return now; + } + Instant::now() +} + +/// Pin [`now`] on this thread; `None` returns it to the real clock. +#[cfg(test)] +pub fn set_test_now(now: Option) { + TEST_NOW.with(|cell| cell.set(now)); +} + +/// One reversible value. Retargeting starts from the value on screen, so +/// a second click never jumps back to an endpoint or restarts. +#[derive(Clone, Copy, Debug)] +pub struct Tween { + from: f32, + to: f32, + started: Instant, + duration: Duration, + easing: fn(f32) -> f32, +} + +impl Tween { + /// At rest at `value`. + pub fn new(value: f32) -> Self { + Self { + from: value, + to: value, + started: epoch(), + duration: Duration::ZERO, + easing: ease_out_cubic, + } + } + + /// Where the value is heading. + pub fn target(&self) -> f32 { + self.to + } + + /// The value to draw at `now`. + pub fn value(&self, now: Instant) -> f32 { + let elapsed = now.saturating_duration_since(self.started); + if elapsed >= self.duration { + return self.to; + } + let t = elapsed.as_secs_f32() / self.duration.as_secs_f32(); + self.from + (self.to - self.from) * (self.easing)(t) + } + + /// Whether the value still changes after `now`. + pub fn is_moving(&self, now: Instant) -> bool { + now.saturating_duration_since(self.started) < self.duration + } + + /// Head for `to` over `duration` from wherever the value is now. + /// Reduced motion settles at once. + pub fn set( + &mut self, + to: f32, + duration: Duration, + easing: fn(f32) -> f32, + now: Instant, + reduced: bool, + ) { + if reduced || duration.is_zero() { + *self = Self::new(to); + } else if to != self.to { + *self = Self { + from: self.value(now), + to, + started: now, + duration, + easing, + }; + } + } + + /// [`Tween::set`], then the value to draw now and whether another + /// frame is needed. Reduced motion also settles a transition already + /// under way. + pub fn step( + &mut self, + to: f32, + duration: Duration, + easing: fn(f32) -> f32, + now: Instant, + reduced: bool, + ) -> (f32, bool) { + self.set(to, duration, easing, now, reduced); + if reduced { + *self = Self::new(self.to); + } + (self.value(now), self.is_moving(now)) + } +} + +/// How far an entrance that began at `started` is through `duration`, in +/// `[0, 1]`. For entrances timed by view state rather than element state, +/// such as transcript rows that can scroll away and back. +pub fn progress(started: Instant, duration: Duration, now: Instant, reduced: bool) -> f32 { + if reduced || duration.is_zero() { + return 1.; + } + (now.saturating_duration_since(started).as_secs_f32() / duration.as_secs_f32()).min(1.) +} /// Phase clock every looping effect reads, so they all stay in step and /// their frame timers line up. @@ -181,32 +337,1432 @@ where { element.with_animation( id, - gpui::Animation::new(REVEAL).with_easing(gpui::ease_out_quint()), + gpui::Animation::new(REVEAL).with_easing(ease_out_quint), |element, delta| element.opacity(delta), ) } -/// Fade in and slide up a few pixels, for panels that open above their -/// anchor. Same one-shot cost profile as [`fade_in`]. -pub fn rise_in(element: E, id: impl Into) -> AnimationElement +/// Fade in and settle up from [`RISE`] below, for panels that open above +/// their anchor. Same one-shot cost profile as [`fade_in`]. +pub fn rise_in(element: E, id: impl Into) -> AnimationElement> where E: IntoElement + Styled + 'static, { - element.with_animation( + slide_in(element, id, REVEAL, gpui::point(px(0.), RISE)) +} + +/// Fade in over `duration` while moving from `from`, an offset from the +/// resting position, to rest. Layout uses the resting position throughout; +/// the hitbox moves with the paint (see [`shifted`]). +pub fn slide_in( + element: E, + id: impl Into, + duration: Duration, + from: Point, +) -> AnimationElement> +where + E: IntoElement + Styled + 'static, +{ + shifted(element).with_animation( id, - gpui::Animation::new(REVEAL).with_easing(gpui::ease_out_quint()), - |element, delta| { + gpui::Animation::new(duration).with_easing(ease_out_quint), + move |element, delta| { + let remaining = 1. - delta; element .opacity(delta) - .mt(gpui::px(6. * (1. - delta))) - .mb(gpui::px(-6. * (1. - delta))) + .offset(gpui::point(from.x * remaining, from.y * remaining)) + }, + ) +} + +/// Draw content `progress` of the way through its entrance (see +/// [`progress`]): faded and [`RISE`] low at 0, at rest at 1. +pub fn arrive(element: E, progress: f32) -> Shifted +where + E: IntoElement + Styled + 'static, +{ + let eased = ease_out_quint(progress.clamp(0., 1.)); + shifted(element) + .opacity(eased) + .offset(gpui::point(px(0.), RISE * (1. - eased))) +} + +/// Paint an element away from where layout put it, hitbox included, +/// without moving anything else: gpui's stand-in for a CSS translate. +pub fn shifted(element: E) -> Shifted { + Shifted { + element: Some(element), + offset: Point::default(), + } +} + +pub struct Shifted { + element: Option, + offset: Point, +} + +impl Shifted { + /// Rounded to whole pixels, so shifted text stays crisp. + pub fn offset(mut self, offset: Point) -> Self { + self.offset = gpui::point(offset.x.round(), offset.y.round()); + self + } +} + +impl Styled for Shifted { + fn style(&mut self) -> &mut gpui::StyleRefinement { + self.element + .as_mut() + .expect("a shifted element is styled before layout") + .style() + } +} + +impl IntoElement for Shifted { + type Element = Self; + + fn into_element(self) -> Self { + self + } +} + +impl Element for Shifted { + type RequestLayoutState = AnyElement; + type PrepaintState = (); + + fn id(&self) -> Option { + None + } + + fn source_location(&self) -> Option<&'static core::panic::Location<'static>> { + None + } + + fn request_layout( + &mut self, + _id: Option<&GlobalElementId>, + _inspector_id: Option<&InspectorElementId>, + window: &mut Window, + cx: &mut App, + ) -> (LayoutId, AnyElement) { + let mut element = self + .element + .take() + .expect("a shifted element is laid out once") + .into_any_element(); + (element.request_layout(window, cx), element) + } + + fn prepaint( + &mut self, + _id: Option<&GlobalElementId>, + _inspector_id: Option<&InspectorElementId>, + _bounds: Bounds, + element: &mut AnyElement, + window: &mut Window, + cx: &mut App, + ) { + window.with_element_offset(self.offset, |window| element.prepaint(window, cx)); + } + + fn paint( + &mut self, + _id: Option<&GlobalElementId>, + _inspector_id: Option<&InspectorElementId>, + _bounds: Bounds, + element: &mut AnyElement, + _: &mut (), + window: &mut Window, + cx: &mut App, + ) { + element.paint(window, cx); + } +} + +/// Paint an element starting at window y `from_y` and easing (ease-out +/// cubic, by `progress`) to where layout put it: a layout-free move from +/// where something was drawn last frame to its new place. The offset is +/// worked out from the element's own bounds as it prepaints, so the first +/// frame is already in the right place. +pub fn glide_from(element: impl IntoElement, from_y: Pixels, progress: f32) -> GlideFrom { + GlideFrom { + element: Some(element.into_any_element()), + from_y, + progress, + } +} + +pub struct GlideFrom { + element: Option, + from_y: Pixels, + progress: f32, +} + +impl IntoElement for GlideFrom { + type Element = Self; + + fn into_element(self) -> Self { + self + } +} + +impl Element for GlideFrom { + type RequestLayoutState = AnyElement; + type PrepaintState = (); + + fn id(&self) -> Option { + None + } + + fn source_location(&self) -> Option<&'static core::panic::Location<'static>> { + None + } + + fn request_layout( + &mut self, + _id: Option<&GlobalElementId>, + _inspector_id: Option<&InspectorElementId>, + window: &mut Window, + cx: &mut App, + ) -> (LayoutId, AnyElement) { + let mut element = self + .element + .take() + .expect("a gliding element is laid out once"); + (element.request_layout(window, cx), element) + } + + fn prepaint( + &mut self, + _id: Option<&GlobalElementId>, + _inspector_id: Option<&InspectorElementId>, + bounds: Bounds, + element: &mut AnyElement, + window: &mut Window, + cx: &mut App, + ) { + let remaining = 1. - ease_out_cubic(self.progress.clamp(0., 1.)); + let offset = gpui::point( + px(0.), + ((self.from_y - bounds.origin.y) * remaining).round(), + ); + window.with_element_offset(offset, |window| element.prepaint(window, cx)); + } + + fn paint( + &mut self, + _id: Option<&GlobalElementId>, + _inspector_id: Option<&InspectorElementId>, + _bounds: Bounds, + element: &mut AnyElement, + _: &mut (), + window: &mut Window, + cx: &mut App, + ) { + element.paint(window, cx); + } +} + +/// An element rebuilt each frame from a value that eases toward `target` +/// and retargets from wherever it is. The value lives in element state +/// under `id`, so render code needs no view state. It starts at `target`, +/// so nothing animates on mount. `build` runs at layout time; keep it +/// cheap. +pub fn animated( + id: impl Into, + target: f32, + duration: Duration, + easing: fn(f32) -> f32, + build: impl Fn(f32) -> AnyElement + 'static, +) -> Animated { + Animated { + id: id.into(), + target, + duration, + easing, + build: Box::new(build), + } +} + +pub struct Animated { + id: ElementId, + target: f32, + duration: Duration, + easing: fn(f32) -> f32, + build: Box AnyElement>, +} + +// Keyed apart from other element state that may share the id. +struct AnimatedValue(Tween); + +impl IntoElement for Animated { + type Element = Self; + + fn into_element(self) -> Self { + self + } +} + +impl Element for Animated { + type RequestLayoutState = AnyElement; + type PrepaintState = (); + + fn id(&self) -> Option { + Some(self.id.clone()) + } + + fn source_location(&self) -> Option<&'static core::panic::Location<'static>> { + None + } + + fn request_layout( + &mut self, + id: Option<&GlobalElementId>, + _inspector_id: Option<&InspectorElementId>, + window: &mut Window, + cx: &mut App, + ) -> (LayoutId, AnyElement) { + let now = now(); + let reduced = cx.reduce_motion(); + let (value, moving) = window.with_element_state( + id.expect("animated elements have an id"), + |state: Option, _| { + let mut state = state.unwrap_or_else(|| AnimatedValue(Tween::new(self.target))); + let frame = state + .0 + .step(self.target, self.duration, self.easing, now, reduced); + (frame, state) + }, + ); + if moving { + window.request_animation_frame(); + } + let mut element = (self.build)(value); + (element.request_layout(window, cx), element) + } + + fn prepaint( + &mut self, + _id: Option<&GlobalElementId>, + _inspector_id: Option<&InspectorElementId>, + _bounds: Bounds, + element: &mut AnyElement, + window: &mut Window, + cx: &mut App, + ) { + element.prepaint(window, cx); + } + + fn paint( + &mut self, + _id: Option<&GlobalElementId>, + _inspector_id: Option<&InspectorElementId>, + _bounds: Bounds, + element: &mut AnyElement, + _: &mut (), + window: &mut Window, + cx: &mut App, + ) { + element.paint(window, cx); + } +} + +/// Two icons sharing one `size` slot: the one `second` selects scales up +/// and fades in while the other scales down and out, over [`TOGGLE`]. +/// Use it where an icon names the state its control toggles (expand and +/// shrink, send and stop). +pub fn icon_swap( + id: impl Into, + second: bool, + icons: [&'static str; 2], + size: Pixels, + color: u32, +) -> gpui::Div { + let id = std::sync::Arc::new(id.into()); + let layer = + |index: usize| { + let name = icons[index]; + let shown = (index == 1) == second; + animated( + ElementId::NamedChild( + id.clone(), + if index == 0 { "first" } else { "second" }.into(), + ), + if shown { 1. } else { 0. }, + TOGGLE, + ease_out_cubic, + move |shown| { + let scale = 0.6 + 0.4 * shown; + gpui::div() + .absolute() + .inset_0() + .flex() + .items_center() + .justify_center() + .opacity(shown) + .child(super::icons::icon(name, size, color).with_transformation( + gpui::Transformation::scale(gpui::size(scale, scale)), + )) + .into_any_element() + }, + ) + }; + gpui::div() + .relative() + .flex_none() + .size(size) + .child(layer(0)) + .child(layer(1)) +} + +/// A disclosure chevron that points right when closed and turns down when +/// `open`, over [`TOGGLE`]. +pub fn chevron(id: impl Into, open: bool, size: Pixels, color: u32) -> Animated { + animated( + id, + if open { 1. } else { 0. }, + TOGGLE, + ease_out_cubic, + move |turn| { + super::icons::icon("chevron-right", size, color) + .with_transformation(gpui::Transformation::rotate(gpui::radians( + turn * std::f32::consts::FRAC_PI_2, + ))) + .into_any_element() }, ) } +/// Content that opens in place under what sits above it, such as the field +/// a choice reveals: its box eases between nothing and the content's height +/// over [`PANEL`] while the content fades with it, so what sits below +/// glides instead of jumping. It folds away the same way, turns back from +/// the height on screen, and settles at once under reduced motion. Nothing +/// animates on mount. Keep passing the content while it folds; once folded +/// it draws nothing. `id` must be stable across frames. +pub fn unfold(id: impl Into, open: bool, content: impl IntoElement) -> Unfold { + Unfold { + id: id.into(), + open, + content: Some(content.into_any_element()), + } +} + +pub struct Unfold { + id: ElementId, + open: bool, + content: Option, +} + +// How far open the content is, and its height when last laid out. +struct Unfolded { + open: Tween, + natural: std::rc::Rc>>, +} + +impl IntoElement for Unfold { + type Element = Self; + + fn into_element(self) -> Self { + self + } +} + +impl Element for Unfold { + type RequestLayoutState = AnyElement; + type PrepaintState = (); + + fn id(&self) -> Option { + Some(self.id.clone()) + } + + fn source_location(&self) -> Option<&'static core::panic::Location<'static>> { + None + } + + fn request_layout( + &mut self, + id: Option<&GlobalElementId>, + _inspector_id: Option<&InspectorElementId>, + window: &mut Window, + cx: &mut App, + ) -> (LayoutId, AnyElement) { + let now = now(); + let reduced = cx.reduce_motion(); + let target = if self.open { 1. } else { 0. }; + let (shown, moving, natural) = window.with_element_state( + id.expect("unfolding content has an id"), + |state: Option, _| { + let mut state = state.unwrap_or_else(|| Unfolded { + open: Tween::new(target), + natural: Default::default(), + }); + let (shown, moving) = state.open.step(target, PANEL, ease_out_cubic, now, reduced); + ((shown, moving, state.natural.clone()), state) + }, + ); + if moving { + window.request_animation_frame(); + } + let content = self + .content + .take() + .expect("unfolding content is laid out once"); + let mut element = if shown <= 0. && !moving { + // Folded: nothing to draw or measure. + gpui::div().into_any_element() + } else { + let measured = natural.clone(); + let frame = gpui::div() + .relative() + .on_children_prepainted(move |bounds, _, _| { + if let Some(body) = bounds.first() { + measured.set(Some(body.size.height)); + } + }); + let body = gpui::div().child(content); + if moving { + // Laid out at its full height above a box that clips it, so + // its height is known from the first frame it shows. + frame + .h(natural.get().unwrap_or_default() * shown) + .overflow_hidden() + .child(body.absolute().top_0().left_0().right_0().opacity(shown)) + .into_any_element() + } else { + frame.child(body).into_any_element() + } + }; + (element.request_layout(window, cx), element) + } + + fn prepaint( + &mut self, + _id: Option<&GlobalElementId>, + _inspector_id: Option<&InspectorElementId>, + _bounds: Bounds, + element: &mut AnyElement, + window: &mut Window, + cx: &mut App, + ) { + element.prepaint(window, cx); + } + + fn paint( + &mut self, + _id: Option<&GlobalElementId>, + _inspector_id: Option<&InspectorElementId>, + _bounds: Bounds, + element: &mut AnyElement, + _: &mut (), + window: &mut Window, + cx: &mut App, + ) { + element.paint(window, cx); + } +} + /// A sine pulse in `[low, high]` offset by `shift` cycles, for dots that /// breathe out of step with each other. pub fn pulse(phase: f32, shift: f32, low: f32, high: f32) -> f32 { let wave = ((phase + shift) * std::f32::consts::TAU).sin() * 0.5 + 0.5; low + (high - low) * wave } + +// Background and visibility on one control are separate values with +// separate targets under the same element id. +struct HoverPlate(Tween); +struct Reveal(Tween); + +/// The color `amount` of the way from `from` to `to`. Premultiplied RGB +/// avoids a dark flash when fading from transparent. +pub fn mix(from: gpui::Hsla, to: gpui::Hsla, amount: f32) -> gpui::Hsla { + if amount <= 0. { + return from; + } + if amount >= 1. { + return to; + } + let from = gpui::Rgba::from(from); + let to = gpui::Rgba::from(to); + let alpha = from.a + (to.a - from.a) * amount; + let channel = |a: f32, b: f32| { + if alpha == 0. { + 0. + } else { + (a * from.a * (1. - amount) + b * to.a * amount) / alpha + } + }; + gpui::Rgba { + r: channel(from.r, to.r), + g: channel(from.g, to.g), + b: channel(from.b, to.b), + a: alpha, + } + .into() +} + +/// Animate a control's background without changing its layout, identity, +/// handlers, tooltip, or accessibility node. Keep native `.hover()` for +/// non-background styles and native `.active()` for immediate press feedback. +pub fn hover_background( + element: gpui::Stateful, + rest: impl Into, + hover: impl Into, +) -> HoverBackground { + HoverBackground { + element, + rest: rest.into(), + hover: hover.into(), + highlighted: None, + revealed: None, + instant: false, + #[cfg(test)] + observed: None, + #[cfg(test)] + observed_opacity: None, + #[cfg(test)] + test_now: None, + } +} + +pub struct HoverBackground { + element: gpui::Stateful, + rest: gpui::Hsla, + hover: gpui::Hsla, + highlighted: Option, + revealed: Option, + instant: bool, + #[cfg(test)] + observed: Option>>, + #[cfg(test)] + observed_opacity: Option>>, + #[cfg(test)] + test_now: Option, +} + +impl HoverBackground { + /// Override the resting background, including selected or open states. + pub fn bg(mut self, color: impl Into) -> Self { + self.rest = color.into(); + self.element.style().background = Some(self.rest.into()); + self + } + + /// Menus share one highlight between pointer and keyboard navigation. + /// Use that existing state instead of maintaining a second hover target. + pub fn highlighted(mut self, highlighted: bool) -> Self { + self.highlighted = Some(highlighted); + self + } + + /// Fade visibility in place, keeping the control's hitbox and layout. + /// Native focus styles can still reveal a keyboard target immediately. + pub fn revealed(mut self, visible: bool) -> Self { + self.revealed = Some(visible); + self + } + + /// Settle at once instead of easing, for a highlight the keyboard + /// moved: arrow keys inside a menu must not trail behind. + pub fn instant(mut self, instant: bool) -> Self { + self.instant = instant; + self + } +} + +impl Styled for HoverBackground { + fn style(&mut self) -> &mut gpui::StyleRefinement { + self.element.style() + } +} +impl gpui::InteractiveElement for HoverBackground { + fn interactivity(&mut self) -> &mut gpui::Interactivity { + gpui::InteractiveElement::interactivity(&mut self.element) + } +} +impl gpui::StatefulInteractiveElement for HoverBackground {} +impl gpui::ParentElement for HoverBackground { + fn extend(&mut self, elements: impl IntoIterator) { + gpui::ParentElement::extend(&mut self.element, elements); + } +} +impl IntoElement for HoverBackground { + type Element = Self; + fn into_element(self) -> Self { + self + } +} + +impl Element for HoverBackground { + type RequestLayoutState = as Element>::RequestLayoutState; + type PrepaintState = as Element>::PrepaintState; + fn id(&self) -> Option { + self.element.id() + } + fn source_location(&self) -> Option<&'static core::panic::Location<'static>> { + self.element.source_location() + } + fn a11y_role(&self) -> Option { + self.element.a11y_role() + } + fn write_a11y_info(&self, node: &mut gpui::accesskit::Node) { + self.element.write_a11y_info(node); + } + fn a11y_synthetic_children( + &mut self, + state: &mut Self::PrepaintState, + builder: &mut gpui::A11ySubtreeBuilder, + ) { + self.element.a11y_synthetic_children(state, builder); + } + fn request_layout( + &mut self, + id: Option<&GlobalElementId>, + inspector: Option<&InspectorElementId>, + window: &mut Window, + cx: &mut App, + ) -> (LayoutId, Self::RequestLayoutState) { + self.element.request_layout(id, inspector, window, cx) + } + fn prepaint( + &mut self, + id: Option<&GlobalElementId>, + inspector: Option<&InspectorElementId>, + bounds: Bounds, + layout: &mut Self::RequestLayoutState, + window: &mut Window, + cx: &mut App, + ) -> Self::PrepaintState { + self.element + .prepaint(id, inspector, bounds, layout, window, cx) + } + fn paint( + &mut self, + id: Option<&GlobalElementId>, + inspector: Option<&InspectorElementId>, + bounds: Bounds, + layout: &mut Self::RequestLayoutState, + hitbox: &mut Self::PrepaintState, + window: &mut Window, + cx: &mut App, + ) { + let hovered = self.highlighted.unwrap_or_else(|| { + hitbox + .as_ref() + .is_some_and(|hitbox| hitbox.is_hovered(window)) + && !cx.has_active_drag() + }); + let now = now(); + #[cfg(test)] + let now = self.test_now.unwrap_or(now); + let reduced = cx.reduce_motion() || self.instant; + let (amount, animating) = window.with_element_state( + id.expect("hover controls have an id"), + |state: Option, _| { + let mut state = state.unwrap_or_else(|| HoverPlate(Tween::new(0.))); + let frame = state.0.step( + if hovered { 1. } else { 0. }, + HOVER, + smoothstep, + now, + reduced, + ); + (frame, state) + }, + ); + self.element.style().background = Some(mix(self.rest, self.hover, amount).into()); + let reveal_animating = if let Some(visible) = self.revealed { + let target = if visible { 1. } else { 0. }; + let (opacity, animating) = window.with_element_state( + id.expect("revealed controls have an id"), + |state: Option, _| { + // An initially visible control should not fade in on mount. + let mut state = state.unwrap_or_else(|| Reveal(Tween::new(target))); + let frame = state.0.step(target, HOVER, smoothstep, now, reduced); + (frame, state) + }, + ); + self.element.style().opacity = Some(opacity); + animating + } else { + false + }; + if animating || reveal_animating { + window.request_animation_frame(); + } + if self.highlighted.is_none() + && let Some(hitbox) = hitbox.clone() + { + let view = window.current_view(); + window.on_mouse_event(move |_: &gpui::MouseMoveEvent, phase, window, cx| { + if phase == gpui::DispatchPhase::Capture && hitbox.is_hovered(window) != hovered { + cx.notify(view); + } + }); + } + self.element + .paint(id, inspector, bounds, layout, hitbox, window, cx); + #[cfg(test)] + if let Some(observed) = &self.observed { + use gpui::InteractiveElement; + *observed.borrow_mut() = self + .element + .interactivity() + .compute_style(id, hitbox.as_ref(), window, cx) + .background + .unwrap_or_default(); + } + #[cfg(test)] + if let Some(observed) = &self.observed_opacity { + use gpui::InteractiveElement; + observed.set( + self.element + .interactivity() + .compute_style(id, hitbox.as_ref(), window, cx) + .opacity + .unwrap_or(1.), + ); + } + } +} + +// ---- Content swaps -------------------------------------------------------- + +/// Content that replaces other content in one place, such as the window's +/// screen or a Settings section: whenever `key` changes, the new content +/// fades in over [`REVEAL`]. Its first appearance does not fade, so a +/// first paint is never held back. `id` must be stable across frames. +/// +/// The content itself always paints at full opacity; a `cover` in the +/// color behind it, painted over its bounds, fades out instead. gpui +/// replays a cached view's last paint, opacity included, so fading an +/// ancestor of one (the sidebar) would leave it stuck at its first, nearly +/// transparent frame. +pub fn swap_in( + element: E, + id: impl Into, + key: impl Into, + cover: impl Into, +) -> Swap +where + E: IntoElement + 'static, +{ + Swap { + id: id.into(), + key: key.into(), + cover: cover.into(), + element: Some(element), + } +} + +pub struct Swap { + id: ElementId, + key: ElementId, + cover: gpui::Hsla, + element: Option, +} + +// The key last drawn, and when content under a new key arrived. +struct Swapped { + key: ElementId, + started: Option, +} + +impl IntoElement for Swap { + type Element = Self; + + fn into_element(self) -> Self { + self + } +} + +impl Element for Swap { + // The content, and how much of it shows through the cover. + type RequestLayoutState = (AnyElement, f32); + type PrepaintState = (); + + fn id(&self) -> Option { + Some(self.id.clone()) + } + + fn source_location(&self) -> Option<&'static core::panic::Location<'static>> { + None + } + + fn request_layout( + &mut self, + id: Option<&GlobalElementId>, + _inspector_id: Option<&InspectorElementId>, + window: &mut Window, + cx: &mut App, + ) -> (LayoutId, (AnyElement, f32)) { + let now = now(); + let reduced = cx.reduce_motion(); + let key = &self.key; + let shown = window.with_element_state( + id.expect("swaps have an id"), + |state: Option, _| { + let mut state = state.unwrap_or_else(|| Swapped { + key: key.clone(), + started: None, + }); + if &state.key != key { + state.key = key.clone(); + state.started = Some(now); + } + let shown = state.started.map_or(1., |started| { + ease_out_quint(progress(started, REVEAL, now, reduced)) + }); + if shown >= 1. { + state.started = None; + } + (shown, state) + }, + ); + if shown < 1. { + window.request_animation_frame(); + } + let mut element = self + .element + .take() + .expect("a swap is laid out once") + .into_any_element(); + (element.request_layout(window, cx), (element, shown)) + } + + fn prepaint( + &mut self, + _id: Option<&GlobalElementId>, + _inspector_id: Option<&InspectorElementId>, + _bounds: Bounds, + (element, _): &mut (AnyElement, f32), + window: &mut Window, + cx: &mut App, + ) { + element.prepaint(window, cx); + } + + fn paint( + &mut self, + _id: Option<&GlobalElementId>, + _inspector_id: Option<&InspectorElementId>, + bounds: Bounds, + (element, shown): &mut (AnyElement, f32), + _: &mut (), + window: &mut Window, + cx: &mut App, + ) { + element.paint(window, cx); + if *shown < 1. { + let mut cover = self.cover; + cover.a *= 1. - *shown; + window.paint_quad(gpui::fill(bounds, cover)); + } + } +} + +#[cfg(test)] +mod hover_tests { + use super::*; + fn hover(tween: &mut Tween, hovered: bool, now: Instant, reduced: bool) -> (f32, bool) { + tween.step( + if hovered { 1. } else { 0. }, + HOVER, + smoothstep, + now, + reduced, + ) + } + + #[test] + fn hover_reverses_from_the_displayed_value_and_settles() { + let now = Instant::now(); + let mut transition = Tween::new(0.); + assert_eq!(hover(&mut transition, false, now, false), (0., false)); + assert_eq!(hover(&mut transition, true, now, false), (0., true)); + let halfway = now + HOVER / 2; + assert_eq!(hover(&mut transition, true, halfway, false), (0.5, true)); + assert_eq!(hover(&mut transition, false, halfway, false), (0.5, true)); + assert_eq!( + hover(&mut transition, false, halfway + HOVER, false), + (0., false) + ); + assert_eq!( + hover(&mut transition, false, halfway + HOVER * 2, false), + (0., false) + ); + } + #[test] + fn reduced_motion_settles_an_interrupted_hover_immediately() { + let now = Instant::now(); + let mut transition = Tween::new(0.); + hover(&mut transition, true, now, false); + assert_eq!( + hover(&mut transition, true, now + HOVER / 4, true), + (1., false) + ); + assert_eq!( + hover(&mut transition, false, now + HOVER / 2, true), + (0., false) + ); + } + + #[test] + fn hover_eases_symmetrically_without_darkening_transparent_colors() { + let now = Instant::now(); + let mut transition = Tween::new(0.); + hover(&mut transition, true, now, false); + let early = transition.value(now + HOVER / 4); + let late = transition.value(now + HOVER * 3 / 4); + assert!(early < 0.25 && late > 0.75); + assert!((early + late - 1.).abs() <= 2. * f32::EPSILON); + let white = gpui::hsla(0., 0., 1., 1.); + let middle = gpui::Rgba::from(mix(gpui::transparent_black(), white, 0.5)); + assert_eq!(middle.r, 1.); + assert_eq!(middle.g, 1.); + assert_eq!(middle.b, 1.); + assert_eq!(middle.a, 0.5); + } + + #[gpui::test] + fn reveal_fades_reverses_and_preserves_focus_and_geometry(cx: &mut gpui::TestAppContext) { + use gpui::{div, prelude::*, px}; + use std::{cell::Cell, rc::Rc}; + struct Host { + visible: bool, + now: Instant, + focus: gpui::FocusHandle, + observed: Rc>, + } + impl gpui::Render for Host { + fn render(&mut self, _: &mut Window, _: &mut gpui::Context) -> impl IntoElement { + let mut button = super::super::widgets::secondary_button("reveal-test") + .debug_selector(|| "reveal-test".into()) + .track_focus(&self.focus) + .focus_visible(|style| style.opacity(1.)) + .highlighted(false) + .revealed(self.visible) + .child("Action"); + button.observed_opacity = Some(self.observed.clone()); + button.test_now = Some(self.now); + div().size_full().p(px(20.)).child(button) + } + } + let observed = Rc::new(Cell::new(0.)); + cx.update(|cx| cx.set_reduce_motion(false)); + let (host, cx) = cx.add_window_view(|_, cx| Host { + visible: true, + now: Instant::now(), + focus: cx.focus_handle(), + observed: observed.clone(), + }); + cx.run_until_parked(); + let bounds = cx.debug_bounds("reveal-test").unwrap(); + assert_eq!( + observed.get(), + 1., + "visible controls do not fade in on mount" + ); + let set_visible = |visible, cx: &mut gpui::VisualTestContext| { + host.update(cx, |host, cx| { + host.visible = visible; + cx.notify(); + }); + cx.run_until_parked(); + }; + let frame_after = |duration, cx: &mut gpui::VisualTestContext| { + host.update(cx, |host, cx| { + host.now += duration; + cx.notify(); + }); + cx.update(|window, cx| { + window.simulate_next_frame(cx); + }); + cx.run_until_parked(); + }; + set_visible(false, cx); + assert!(observed.get() > 0., "hide must not snap off"); + frame_after(HOVER / 4, cx); + assert!(observed.get() > 0. && observed.get() < 1.); + set_visible(true, cx); + assert!( + observed.get() > 0. && observed.get() < 1., + "reverse in place" + ); + frame_after(HOVER, cx); + assert_eq!(observed.get(), 1.); + set_visible(false, cx); + frame_after(HOVER, cx); + assert_eq!(observed.get(), 0.); + set_visible(true, cx); + assert!(observed.get() < 1., "show must not snap on"); + frame_after(HOVER, cx); + assert_eq!(observed.get(), 1.); + assert_eq!(cx.debug_bounds("reveal-test").unwrap(), bounds); + assert_eq!(cx.update(|window, cx| window.simulate_next_frame(cx)), 0); + + cx.update(|_, cx| cx.set_reduce_motion(true)); + set_visible(false, cx); + assert_eq!(observed.get(), 0.); + set_visible(true, cx); + assert_eq!(observed.get(), 1.); + set_visible(false, cx); + let focus = host.update(cx, |host, _| host.focus.clone()); + cx.simulate_keystrokes("tab"); + cx.update(|window, cx| focus.focus(window, cx)); + cx.run_until_parked(); + assert_eq!(observed.get(), 1., "keyboard focus reveals immediately"); + assert_eq!(cx.update(|window, cx| window.simulate_next_frame(cx)), 0); + } + + #[gpui::test] + fn shared_button_preserves_hover_click_and_pressed_feedback(cx: &mut gpui::TestAppContext) { + use gpui::{Modifiers, MouseButton, div, prelude::*, px}; + use std::rc::Rc; + struct Host { + observed: Rc>, + clicks: Rc>, + hovered: Rc>, + } + impl gpui::Render for Host { + fn render(&mut self, _: &mut Window, _: &mut gpui::Context) -> impl IntoElement { + let clicks = self.clicks.clone(); + let hovered = self.hovered.clone(); + let mut button = super::super::widgets::secondary_button("hover-test") + .debug_selector(|| "hover-test".into()) + .on_hover(move |value, _, _| hovered.set(*value)) + .on_click(move |_, _, _| clicks.set(clicks.get() + 1)) + .child("Action"); + button.observed = Some(self.observed.clone()); + div().size_full().child(button) + } + } + let observed = Rc::new(RefCell::new(gpui::Fill::default())); + let clicks = Rc::new(std::cell::Cell::new(0)); + let hovered = Rc::new(std::cell::Cell::new(false)); + cx.update(|cx| cx.set_reduce_motion(true)); + let (_, cx) = cx.add_window_view(|_, _| Host { + observed: observed.clone(), + clicks: clicks.clone(), + hovered: hovered.clone(), + }); + cx.run_until_parked(); + let bounds = cx.debug_bounds("hover-test").unwrap(); + cx.simulate_mouse_move(bounds.center(), None, Modifiers::default()); + assert!(hovered.get()); + assert_eq!( + *observed.borrow(), + gpui::Fill::from(gpui::rgb(super::super::theme::bg_sidebar_row_selected())) + ); + cx.simulate_mouse_down(bounds.center(), MouseButton::Left, Modifiers::default()); + assert_eq!( + *observed.borrow(), + gpui::Fill::from(gpui::rgb(super::super::theme::border())) + ); + cx.simulate_mouse_up(bounds.center(), MouseButton::Left, Modifiers::default()); + assert_eq!(clicks.get(), 1); + cx.simulate_mouse_move( + gpui::point(bounds.right() + px(20.), bounds.bottom() + px(20.)), + None, + Modifiers::default(), + ); + assert!(!hovered.get()); + assert_eq!( + *observed.borrow(), + gpui::Fill::from(gpui::rgb(super::super::theme::bg_sidebar_pill())) + ); + assert_eq!(cx.update(|window, cx| window.simulate_next_frame(cx)), 0); + } + + #[gpui::test] + fn cached_child_hover_animates_reverses_and_goes_idle(cx: &mut gpui::TestAppContext) { + use gpui::{Modifiers, div, prelude::*}; + use std::{cell::Cell, rc::Rc}; + struct Control { + observed: Rc>, + renders: Rc>, + } + impl gpui::Render for Control { + fn render(&mut self, _: &mut Window, _: &mut gpui::Context) -> impl IntoElement { + self.renders.set(self.renders.get() + 1); + let mut button = super::super::widgets::secondary_button("cached-hover") + .debug_selector(|| "cached-hover".into()) + .child("Action"); + button.observed = Some(self.observed.clone()); + div().size_full().child(button) + } + } + struct Host { + control: gpui::Entity, + } + impl gpui::Render for Host { + fn render(&mut self, _: &mut Window, _: &mut gpui::Context) -> impl IntoElement { + div().size_full().child( + self.control.clone().cached( + gpui::StyleRefinement::default() + .w(gpui::px(200.)) + .h(gpui::px(80.)), + ), + ) + } + } + let observed = Rc::new(RefCell::new(gpui::Fill::default())); + let child_renders = Rc::new(Cell::new(0)); + cx.update(|cx| cx.set_reduce_motion(false)); + let (_, cx) = cx.add_window_view(|_, cx| Host { + control: cx.new(|_| Control { + observed: observed.clone(), + renders: child_renders.clone(), + }), + }); + cx.run_until_parked(); + let rest = gpui::Fill::from(gpui::rgb(super::super::theme::bg_sidebar_pill())); + let hover = gpui::Fill::from(gpui::rgb(super::super::theme::bg_sidebar_row_selected())); + let bounds = cx.debug_bounds("cached-hover").unwrap(); + let outside = gpui::point( + bounds.right() + gpui::px(20.), + bounds.bottom() + gpui::px(20.), + ); + cx.simulate_mouse_move(outside, None, Modifiers::default()); + let child_count = child_renders.get(); + cx.simulate_mouse_move(bounds.center(), None, Modifiers::default()); + assert!(cx.update(|window, cx| window.simulate_next_frame(cx)) > 0); + cx.run_until_parked(); + // The primitive uses real monotonic time; the test executor's clock + // does not advance Instant. One bounded wait samples an in-flight fade. + std::thread::sleep(HOVER / 4); + cx.update(|window, cx| { + window.simulate_next_frame(cx); + }); + cx.run_until_parked(); + assert_ne!(*observed.borrow(), rest); + cx.simulate_mouse_move(outside, None, Modifiers::default()); + assert_ne!(*observed.borrow(), rest, "leaving must not snap to rest"); + assert!(cx.update(|window, cx| window.simulate_next_frame(cx)) > 0); + cx.run_until_parked(); + std::thread::sleep(HOVER + Duration::from_millis(20)); + cx.update(|window, cx| { + window.simulate_next_frame(cx); + }); + cx.run_until_parked(); + assert_eq!(*observed.borrow(), rest); + assert_eq!(cx.update(|window, cx| window.simulate_next_frame(cx)), 0); + cx.simulate_mouse_move(bounds.center(), None, Modifiers::default()); + std::thread::sleep(HOVER + Duration::from_millis(20)); + cx.update(|window, cx| { + window.simulate_next_frame(cx); + }); + cx.run_until_parked(); + assert_eq!(*observed.borrow(), hover); + assert_eq!(cx.update(|window, cx| window.simulate_next_frame(cx)), 0); + assert!(child_renders.get() > child_count); + } +} + +#[cfg(test)] +mod primitive_tests { + use super::*; + use gpui::{VisualTestContext, div, prelude::*}; + use std::{cell::Cell, rc::Rc}; + + struct Host { + open: bool, + shift: Pixels, + seen: Rc>, + } + + impl gpui::Render for Host { + fn render(&mut self, _: &mut Window, _: &mut gpui::Context) -> impl IntoElement { + let seen = self.seen.clone(); + div() + .size_full() + .flex() + .flex_col() + .child(animated( + "value", + if self.open { 1. } else { 0. }, + PANEL, + ease_out_cubic, + move |value| { + seen.set(value); + div().size(px(10.)).into_any_element() + }, + )) + .child( + shifted( + div() + .debug_selector(|| "shifted".into()) + .w(px(40.)) + .h(px(20.)), + ) + .offset(gpui::point(px(0.), self.shift)), + ) + .child( + div() + .debug_selector(|| "below".into()) + .w(px(40.)) + .h(px(20.)), + ) + } + } + + fn host( + cx: &mut gpui::TestAppContext, + ) -> (gpui::Entity, &mut VisualTestContext, Rc>) { + let seen = Rc::new(Cell::new(-1.)); + cx.update(|cx| cx.set_reduce_motion(false)); + let (host, cx) = cx.add_window_view(|_, _| Host { + open: false, + shift: px(0.), + seen: seen.clone(), + }); + cx.run_until_parked(); + (host, cx, seen) + } + + #[gpui::test] + fn animated_values_start_at_rest_reverse_from_the_screen_and_settle( + cx: &mut gpui::TestAppContext, + ) { + let start = Instant::now(); + set_test_now(Some(start)); + let (host, cx, seen) = host(cx); + assert_eq!(seen.get(), 0., "nothing animates on mount"); + assert_eq!(cx.update(|window, cx| window.simulate_next_frame(cx)), 0); + + let draw = |at: Instant, open: bool, cx: &mut VisualTestContext| { + set_test_now(Some(at)); + host.update(cx, |host, cx| { + host.open = open; + cx.notify(); + }); + cx.run_until_parked(); + }; + draw(start, true, cx); + assert_eq!(seen.get(), 0.); + draw(start + PANEL / 2, true, cx); + let halfway = seen.get(); + assert!(halfway > 0.5 && halfway < 1., "eases out: {halfway}"); + draw(start + PANEL / 2, false, cx); + assert_eq!( + seen.get(), + halfway, + "reversing starts from the value on screen" + ); + draw(start + PANEL / 2 + PANEL / 4, false, cx); + assert!(seen.get() > 0. && seen.get() < halfway); + draw(start + PANEL * 2, false, cx); + assert_eq!(seen.get(), 0.); + // The frame requested while it moved still runs once. + cx.update(|window, cx| { + window.simulate_next_frame(cx); + }); + cx.run_until_parked(); + assert_eq!(seen.get(), 0.); + assert_eq!( + cx.update(|window, cx| window.simulate_next_frame(cx)), + 0, + "a settled value asks for no frames" + ); + + cx.update(|_, cx| cx.set_reduce_motion(true)); + draw(start + PANEL * 2, true, cx); + assert_eq!(seen.get(), 1., "reduced motion settles at once"); + assert_eq!(cx.update(|window, cx| window.simulate_next_frame(cx)), 0); + set_test_now(None); + } + + #[gpui::test] + fn shifted_content_moves_without_moving_its_neighbors(cx: &mut gpui::TestAppContext) { + let (host, cx, _) = host(cx); + let shifted = cx.debug_bounds("shifted").unwrap(); + let below = cx.debug_bounds("below").unwrap(); + host.update(cx, |host, cx| { + host.shift = px(5.6); + cx.notify(); + }); + cx.run_until_parked(); + let moved = cx.debug_bounds("shifted").unwrap(); + assert_eq!(moved.origin.y, shifted.origin.y + px(6.), "whole pixels"); + assert_eq!(moved.size, shifted.size); + assert_eq!(cx.debug_bounds("below").unwrap(), below); + } + + struct UnfoldHost { + open: bool, + } + + impl gpui::Render for UnfoldHost { + fn render(&mut self, _: &mut Window, _: &mut gpui::Context) -> impl IntoElement { + div() + .size_full() + .flex() + .flex_col() + .child(unfold( + "unfold", + self.open, + div().debug_selector(|| "unfolded".into()).h(px(60.)), + )) + .child(div().debug_selector(|| "after".into()).h(px(20.))) + } + } + + #[gpui::test] + fn unfolding_content_pushes_what_follows_and_folds_back_from_the_screen( + cx: &mut gpui::TestAppContext, + ) { + let start = Instant::now(); + set_test_now(Some(start)); + cx.update(|cx| cx.set_reduce_motion(false)); + let (host, cx) = cx.add_window_view(|_, _| UnfoldHost { open: false }); + cx.run_until_parked(); + let top = |cx: &mut VisualTestContext| cx.debug_bounds("after").unwrap().origin.y; + let rest = top(cx); + assert!( + cx.debug_bounds("unfolded").is_none(), + "folded, it draws nothing" + ); + + let draw = |at: Instant, open: bool, cx: &mut VisualTestContext| { + set_test_now(Some(at)); + host.update(cx, |host, cx| { + host.open = open; + cx.notify(); + }); + cx.run_until_parked(); + }; + draw(start, true, cx); + assert_eq!(top(cx), rest, "it opens from nothing"); + draw(start + PANEL / 2, true, cx); + let halfway = top(cx) - rest; + assert!( + halfway > px(30.) && halfway < px(60.), + "eases out: {halfway:?}" + ); + draw(start + PANEL / 2, false, cx); + assert_eq!( + top(cx) - rest, + halfway, + "folding starts from the height on screen" + ); + draw(start + PANEL * 2, false, cx); + assert_eq!(top(cx), rest); + assert!(cx.debug_bounds("unfolded").is_none()); + // The frame requested while it moved still runs once. + cx.update(|window, cx| { + window.simulate_next_frame(cx); + }); + cx.run_until_parked(); + assert_eq!( + cx.update(|window, cx| window.simulate_next_frame(cx)), + 0, + "folded content asks for no frames" + ); + + cx.update(|_, cx| cx.set_reduce_motion(true)); + draw(start + PANEL * 2, true, cx); + assert_eq!(top(cx) - rest, px(60.), "reduced motion opens at once"); + set_test_now(None); + } +} diff --git a/apps/maple-agent/app/src/ui/plan_gate.rs b/apps/maple-agent/app/src/ui/plan_gate.rs index faf379508..790faa7cb 100644 --- a/apps/maple-agent/app/src/ui/plan_gate.rs +++ b/apps/maple-agent/app/src/ui/plan_gate.rs @@ -123,15 +123,16 @@ impl Render for PlanGate { } let busy = self.checking || self.signing_out; let width = (window.viewport_size().width - px(48.)).clamp(px(0.), px(500.)); - let button = - |button: gpui::Stateful, selector: &'static str, label: SharedString| { - button - .debug_selector(move || selector.to_string()) - .aria_label(label.clone()) - .py_1p5() - .when(busy, |button| button.opacity(0.6)) - .child(label) - }; + let button = |button: crate::ui::motion::HoverBackground, + selector: &'static str, + label: SharedString| { + button + .debug_selector(move || selector.to_string()) + .aria_label(label.clone()) + .py_1p5() + .when(busy, |button| button.opacity(0.6)) + .child(label) + }; div() .relative() .flex_1() diff --git a/apps/maple-agent/app/src/ui/popup.rs b/apps/maple-agent/app/src/ui/popup.rs index 246f6b6b7..7d0784bfa 100644 --- a/apps/maple-agent/app/src/ui/popup.rs +++ b/apps/maple-agent/app/src/ui/popup.rs @@ -73,6 +73,8 @@ gpui::actions!( /// Space kept between a trigger and the menu it opens. const GAP: Pixels = px(4.); +/// How far a menu travels as it opens, settling away from its trigger. +const SLIDE: Pixels = px(4.); /// Closest a menu comes to the window edge. const WINDOW_MARGIN: Pixels = px(8.); @@ -178,6 +180,11 @@ pub(crate) struct Popup { /// menu is open (a status that loads late) do not move it to another /// item. highlighted: Option, + /// The keyboard moved the highlight last, so it moves at once; the + /// pointer's highlight eases like any hover. + keyboard: bool, + /// Counts openings, so each opening replays the entrance. + opened: u64, focus: FocusHandle, /// Focus moves in on the next render, once the panel is in the tree. focus_pending: bool, @@ -205,6 +212,8 @@ impl Popup { get, open: None, highlighted: None, + keyboard: false, + opened: 0, focus: cx.focus_handle(), focus_pending: false, focus_out: None, @@ -262,6 +271,7 @@ impl Popup { *self.hover_opener.get_mut() = None; if self.open.as_ref() != Some(&key) { self.scroll.set_offset(point(px(0.), px(0.))); + self.opened += 1; } self.open = Some(key); self.reveal.set(if item.is_some() { @@ -269,6 +279,7 @@ impl Popup { } else { Reveal::Done }); + self.keyboard = item.is_some(); self.highlighted = item; self.focus_pending = true; cx.notify(); @@ -429,13 +440,13 @@ impl Popup { /// closed trigger stays an ordinary button: it shows its pressed state, /// and any other open popup still sees the press and closes. Commands /// and keys that open a menu call [`Self::open`] instead. - pub(crate) fn trigger( + pub(crate) fn trigger( &self, key: K, - button: Stateful
, + button: E, cx: &mut Context, toggle: impl Fn(&mut V, &mut Window, &mut Context) + 'static, - ) -> Stateful
{ + ) -> E { let open = self.is_open(&key); let get = self.get; button @@ -581,7 +592,7 @@ impl Popup { initial: initial(&item.label), child: children.len(), }); - children.push(item_row(item, highlighted, get, cx)); + children.push(item_row(item, highlighted, self.keyboard, get, cx)); } Entry::Header(text) => children.push( div() @@ -762,7 +773,11 @@ impl Popup { .size_full(), ); Float { - panel: Some(motion::fade_in(panel, "popup-reveal").into_any_element()), + id: ElementId::NamedChild( + std::sync::Arc::new(id), + SharedString::from(format!("opened-{}", self.opened)), + ), + panel: Some(panel), placement, priority, } @@ -815,16 +830,18 @@ pub(crate) enum Placement { impl Placement { /// The top-left corner of a panel of `size` in a window of `window` - /// size. The panel goes on its preferred side of the trigger (or of the - /// point) when it fits there, on the other side when only that one has - /// room, and otherwise on the roomier side, pushed inside the window. + /// size, and the offset from there it opens from: [`SLIDE`] toward the + /// trigger, so it settles away from it. The panel goes on its preferred + /// side of the trigger (or of the point) when it fits there, on the + /// other side when only that one has room, and otherwise on the roomier + /// side, pushed inside the window. fn origin( self, trigger: Bounds, size: Size, window: Size, margin: Pixels, - ) -> Point { + ) -> (Point, Point) { let (anchor, prefer_below, prefer_start, gap) = match self { Placement::BelowStart => (trigger, true, true, GAP), Placement::BelowEnd => (trigger, true, false, GAP), @@ -855,7 +872,8 @@ impl Placement { let y = y.min(window.height - margin - size.height).max(margin); // Whole pixels, rounding away from the trigger to keep the gap. let y = if below { y.ceil() } else { y.floor() }; - point(x.round(), y) + let from = point(px(0.), if below { -SLIDE } else { SLIDE }); + (point(x.round(), y), from) } } @@ -864,10 +882,11 @@ fn beside( size: Size, window: Size, margin: Pixels, -) -> Point { +) -> (Point, Point) { let room_right = window.width - margin - trigger.right() - GAP; let room_left = trigger.left() - GAP - margin; - let x = if first_side(true, size.width, room_right, room_left) { + let right = first_side(true, size.width, room_right, room_left); + let x = if right { trigger.right() + GAP } else { trigger.left() - GAP - size.width @@ -877,7 +896,8 @@ fn beside( .top() .min(window.height - margin - size.height) .max(margin); - point(x.round(), y.round()) + let from = point(if right { -SLIDE } else { SLIDE }, px(0.)); + (point(x.round(), y.round()), from) } /// Whether a panel `length` long goes on the first of two sides, which @@ -897,13 +917,23 @@ fn first_side(prefer_first: bool, length: Pixels, first: Pixels, second: Pixels) /// Draws a menu panel above everything, where [`Placement::origin`] puts /// it. Beside a trigger, this element covers the `relative` box around the /// trigger and takes that box's bounds. The panel is measured before it is -/// placed, so it lands on the right side in its first frame. +/// placed, so it lands on the right side in its first frame, and it opens +/// from that side: it fades in while settling [`SLIDE`] away from the +/// trigger. `id` is new for each opening, so the entrance replays when one +/// menu replaces another. A menu opened from the keyboard (the window's +/// last input was a key) appears at once; a pointer opening, including one +/// that starts on the current choice, plays the entrance. struct Float { - panel: Option, + id: ElementId, + panel: Option
, placement: Placement, priority: usize, } +/// When the panel under a [`Float`] id first drew, and whether the +/// keyboard opened it, which skips the entrance. +struct Opened(std::time::Instant, bool); + impl IntoElement for Float { type Element = Self; @@ -917,7 +947,7 @@ impl Element for Float { type PrepaintState = (); fn id(&self) -> Option { - None + Some(self.id.clone()) } fn source_location(&self) -> Option<&'static std::panic::Location<'static>> { @@ -943,22 +973,47 @@ impl Element for Float { fn prepaint( &mut self, - _: Option<&GlobalElementId>, + id: Option<&GlobalElementId>, _: Option<&InspectorElementId>, bounds: Bounds, _: &mut (), window: &mut Window, cx: &mut App, ) { - let Some(mut panel) = self.panel.take() else { + let Some(panel) = self.panel.take() else { return; }; + // Opacity does not reach into a deferred draw, so the entrance is + // drawn here, on the panel itself. + let now = motion::now(); + let keyboard = window.last_input_was_keyboard(); + let (started, instant) = window.with_element_state( + id.expect("a float has an id"), + |state: Option, _| { + let opened = state.unwrap_or(Opened(now, keyboard)); + ((opened.0, opened.1), opened) + }, + ); + let shown = motion::ease_out_quint(motion::progress( + started, + motion::REVEAL, + now, + cx.reduce_motion() || instant, + )); + let mut panel = if shown < 1. { + window.request_animation_frame(); + panel.opacity(shown).into_any_element() + } else { + panel.into_any_element() + }; let size = panel.layout_as_root(AvailableSpace::min_size(), window, cx); let margin = window_margin(window); - let origin = self + let (origin, from) = self .placement .origin(bounds, size, window.viewport_size(), margin); - window.defer_draw(panel, origin, self.priority, None); + let rest = 1. - shown; + let offset = point((from.x * rest).round(), (from.y * rest).round()); + window.defer_draw(panel, origin + offset, self.priority, None); } fn paint( @@ -1261,6 +1316,7 @@ fn initial(text: &str) -> Option { fn item_row( item: MenuItem, highlighted: bool, + keyboard: bool, get: fn(&mut V) -> &mut Popup, cx: &mut Context, ) -> AnyElement { @@ -1309,10 +1365,7 @@ fn item_row( }; row.aria_toggled(if on { Toggled::True } else { Toggled::False }) }) - .when(highlighted, |row| { - row.aria_active_descendant() - .bg(gpui::rgb(theme::bg_sidebar_row_hover())) - }) + .when(highlighted, |row| row.aria_active_descendant()) .flex() .items_center() .gap_2() @@ -1331,6 +1384,7 @@ fn item_row( close(view, window, cx); } let popup = get(view); + popup.keyboard = false; if *hovered { popup.hover = None; popup.highlight(enabled.then(|| hovered_id.clone()), cx); @@ -1452,10 +1506,18 @@ fn item_row( .children(submenu.panel) }) .relative(); - match style { - Some(style) => style(row_element).into_any_element(), - None => row_element.into_any_element(), - } + let row_element = match style { + Some(style) => style(row_element), + None => row_element, + }; + crate::ui::motion::hover_background( + row_element, + gpui::transparent_black(), + gpui::rgb(theme::bg_sidebar_row_hover()), + ) + .highlighted(highlighted) + .instant(keyboard) + .into_any_element() } #[derive(Clone, Copy)] @@ -1491,6 +1553,7 @@ fn step( let candidate = &picks[at as usize]; if candidate.enabled { popup.scroll.scroll_to_item(candidate.child); + popup.keyboard = true; popup.highlight(Some(candidate.id.clone()), cx); return; } @@ -1549,6 +1612,7 @@ fn type_ahead( .find(|&row| picks[row].enabled && typed.is_some() && picks[row].initial == typed); if let Some(row) = found { popup.scroll.scroll_to_item(picks[row].child); + popup.keyboard = true; popup.highlight(Some(picks[row].id.clone()), cx); } } @@ -2161,6 +2225,138 @@ mod tests { assert_eq!(open(&host, cx), None); } + /// A menu opens from its trigger: below one it settles down, above + /// one it settles up, and once there it asks for no more frames. A + /// menu that replaces another opens the same way, and reduced motion + /// draws it in place. + #[gpui::test] + fn a_menu_slides_in_away_from_its_trigger(cx: &mut TestAppContext) { + let start = std::time::Instant::now(); + motion::set_test_now(Some(start)); + let (_host, cx) = setup(cx); + cx.update(|_, cx| cx.set_reduce_motion(false)); + let frames = + |cx: &mut VisualTestContext| cx.update(|window, cx| window.simulate_next_frame(cx)); + let frame_at = |at: std::time::Instant, cx: &mut VisualTestContext| { + motion::set_test_now(Some(at)); + cx.update(|window, cx| { + window.simulate_next_frame(cx); + }); + cx.run_until_parked(); + }; + let top = |menu: &'static str, cx: &mut VisualTestContext| { + cx.debug_bounds(menu).expect("menu").top() + }; + + click(cx, "b-trigger"); + let arriving = top("menu-b", cx); + frame_at(start + motion::REVEAL, cx); + assert_eq!( + top("menu-b", cx) - arriving, + SLIDE, + "below, it settles down" + ); + assert_eq!(frames(cx), 0, "an open menu at rest asks for no frames"); + + click(cx, "a-trigger"); + let arriving = top("menu-a", cx); + frame_at(start + motion::REVEAL * 2, cx); + let rest = top("menu-a", cx); + assert_eq!(rest - arriving, SLIDE, "the next menu opens the same way"); + + click(cx, "low-trigger"); + let arriving = top("menu-low", cx); + frame_at(start + motion::REVEAL * 3, cx); + assert_eq!( + arriving - top("menu-low", cx), + SLIDE, + "above, it settles up" + ); + assert_eq!(frames(cx), 0); + + click(cx, "low-trigger"); + cx.update(|_, cx| cx.set_reduce_motion(true)); + click(cx, "a-trigger"); + assert_eq!(top("menu-a", cx), rest, "reduced motion opens at rest"); + assert_eq!(frames(cx), 0); + motion::set_test_now(None); + } + + /// Arrow keys move the highlight on the frame they arrive; the + /// pointer's highlight eases in like any hover. + #[gpui::test] + fn the_keyboard_moves_the_highlight_at_once(cx: &mut TestAppContext) { + let start = std::time::Instant::now(); + motion::set_test_now(Some(start)); + let (host, cx) = setup(cx); + cx.update(|_, cx| cx.set_reduce_motion(false)); + let frames = + |cx: &mut VisualTestContext| cx.update(|window, cx| window.simulate_next_frame(cx)); + host.update(cx, |host, cx| host.popup.open(Which::A, cx)); + cx.run_until_parked(); + motion::set_test_now(Some(start + motion::REVEAL)); + frames(cx); + cx.run_until_parked(); + assert_eq!(frames(cx), 0, "the menu has arrived"); + + cx.simulate_keystrokes("down"); + assert_eq!(highlighted(&host, cx), Some("a-one".into())); + assert_eq!( + frames(cx), + 0, + "a highlight the keyboard moved does not ease" + ); + cx.simulate_keystrokes("down"); + assert_eq!(frames(cx), 0); + let row = cx.debug_bounds("a-three").expect("row"); + cx.simulate_mouse_move(row.center(), None, Modifiers::default()); + assert_eq!(highlighted(&host, cx), Some("a-three".into())); + assert!(frames(cx) > 0, "the pointer's highlight eases"); + motion::set_test_now(None); + } + + /// The input that opened a menu decides its entrance. With the pointer + /// it slides in, even when its owner starts it on the current choice + /// the way Settings dropdowns do (`open_highlighted`); from the + /// keyboard it is drawn at rest on its first frame. + #[gpui::test] + fn only_pointer_openings_play_the_menu_entrance(cx: &mut TestAppContext) { + let start = std::time::Instant::now(); + motion::set_test_now(Some(start)); + let (host, cx) = setup(cx); + cx.update(|_, cx| cx.set_reduce_motion(false)); + let top = |cx: &mut VisualTestContext| cx.debug_bounds("menu-a").expect("menu").top(); + click(cx, "a-trigger"); + motion::set_test_now(Some(start + motion::REVEAL)); + cx.update(|window, cx| { + window.simulate_next_frame(cx); + }); + cx.run_until_parked(); + let rest = top(cx); + click(cx, "a-trigger"); + + // The pointer was last; a click handler opens on the current row. + let away = cx.debug_bounds("b-trigger").expect("trigger").center(); + cx.simulate_mouse_move(away, None, Modifiers::default()); + host.update(cx, |host, cx| { + host.popup.open_highlighted(Which::A, "a-one", cx) + }); + cx.run_until_parked(); + assert_eq!(rest - top(cx), SLIDE, "a pointer opening slides in"); + host.update(cx, |host, cx| { + host.popup.close(cx); + }); + cx.run_until_parked(); + + cx.simulate_keystrokes("escape"); + host.update(cx, |host, cx| { + host.popup.open_highlighted(Which::A, "a-one", cx) + }); + cx.run_until_parked(); + assert_eq!(top(cx), rest, "a keyboard opening is drawn at rest"); + motion::set_test_now(None); + } + #[gpui::test] fn a_menu_opened_on_a_row_shows_that_row(cx: &mut TestAppContext) { let (host, cx) = setup(cx); @@ -2185,6 +2381,7 @@ mod tests { #[gpui::test] fn a_menu_larger_than_the_window_fits_inside_it(cx: &mut TestAppContext) { let (host, cx) = setup(cx); + cx.update(|_, cx| cx.set_reduce_motion(true)); // Narrower and shorter than menu A. let window = size(px(140.), px(100.)); cx.simulate_resize(window); @@ -2218,8 +2415,9 @@ mod tests { let window = size(px(800.), px(600.)); let panel = size(px(200.), px(300.)); let trigger = |x: f32, y: f32| Bounds::new(point(px(x), px(y)), size(px(80.), px(20.))); - let origin = - |placement: Placement, trigger| placement.origin(trigger, panel, window, WINDOW_MARGIN); + let origin = |placement: Placement, trigger| { + placement.origin(trigger, panel, window, WINDOW_MARGIN).0 + }; // Room below: below, 4 px down, left edges shared. assert_eq!( origin(Placement::BelowStart, trigger(100., 100.)), @@ -2242,12 +2440,14 @@ mod tests { ); // Room on neither side: the roomier side, inside the window. assert_eq!( - Placement::BelowStart.origin( - trigger(100., 250.), - size(px(200.), px(560.)), - window, - WINDOW_MARGIN - ), + Placement::BelowStart + .origin( + trigger(100., 250.), + size(px(200.), px(560.)), + window, + WINDOW_MARGIN + ) + .0, point(px(100.), px(32.)) ); // A right-click near the bottom right corner opens up and left. diff --git a/apps/maple-agent/app/src/ui/settings.rs b/apps/maple-agent/app/src/ui/settings.rs index 155c21b41..95f469030 100644 --- a/apps/maple-agent/app/src/ui/settings.rs +++ b/apps/maple-agent/app/src/ui/settings.rs @@ -1986,7 +1986,12 @@ impl Render for SettingsScreen { .flex_1() .min_h_0() .bg(gpui::rgb(theme::bg_app())) - .child(self.render_pane(window, cx)) + .child(crate::ui::motion::swap_in( + self.render_pane(window, cx), + "settings-pane-swap", + self.section.id(), + gpui::rgb(theme::bg_app()), + )) .child(crate::ui::scrollbar::scrollbar( "settings-scrollbar", self.pane_scroll.clone(), @@ -2002,7 +2007,11 @@ impl Render for SettingsScreen { } impl SettingsScreen { - fn render_nav_item(&self, section: Section, cx: &mut Context) -> gpui::Stateful
{ + fn render_nav_item( + &self, + section: Section, + cx: &mut Context, + ) -> crate::ui::motion::HoverBackground { let selected = self.section == section; let application_selected = self.application_vim_selects_section(section); let icon_color = if selected { @@ -2045,7 +2054,7 @@ impl SettingsScreen { .when(application_selected, |row| { row.border_l_2().border_color(gpui::rgb(theme::accent())) }) - .hover(|style| style.bg(gpui::rgb(theme::bg_elevated())).cursor_pointer()) + .hover(|style| style.cursor_pointer()) .on_click(cx.listener(move |this, _event, _window, cx| { this.select_section(section, cx); })) @@ -2074,7 +2083,12 @@ impl SettingsScreen { ) }); } - row + let rest = gpui::rgb(if selected { + theme::bg_elevated() + } else { + theme::bg_sidebar() + }); + crate::ui::motion::hover_background(row, rest, gpui::rgb(theme::bg_elevated())) } /// The task sidebar's column, from the window's top edge. Back sits @@ -2133,7 +2147,7 @@ impl SettingsScreen { /// Back to the task screen: an arrow like the task screen's toolbar /// buttons, named by its tooltip. - fn render_back(&self, cx: &mut Context) -> gpui::Stateful
{ + fn render_back(&self, cx: &mut Context) -> crate::ui::motion::HoverBackground { widgets::icon_button( "settings-back", "arrow-left", @@ -3365,8 +3379,10 @@ impl SettingsScreen { }) }; let transport_segment = |id: &'static str, label: gpui::SharedString, active: bool| { + let selected: gpui::Hsla = gpui::rgb(theme::bg_sidebar_row_hover()).into(); div() .id(id) + .relative() .px_3() .py_1() .rounded(theme::RADIUS_SM) @@ -3376,12 +3392,34 @@ impl SettingsScreen { } else { theme::text_secondary() })) - .when(active, |el| el.bg(gpui::rgb(theme::bg_sidebar_row_hover()))) - .hover(|style| { - style - .bg(gpui::rgb(theme::bg_sidebar_row_hover())) - .cursor_pointer() + .map(|element| { + crate::ui::motion::hover_background( + element, + gpui::transparent_black(), + selected, + ) }) + .hover(|style| style.cursor_pointer()) + // The selected fill, over the hover plate, eases between + // segments. + .child(crate::ui::motion::animated( + "selected", + if active { 1. } else { 0. }, + crate::ui::motion::TOGGLE, + crate::ui::motion::ease_out_cubic, + move |active| { + div() + .absolute() + .inset_0() + .rounded(theme::RADIUS_SM) + .bg(crate::ui::motion::mix( + gpui::transparent_black(), + selected, + active, + )) + .into_any_element() + }, + )) .child(label) }; div() @@ -3894,34 +3932,58 @@ fn is_cua_driver(id: &str) -> bool { id == "cua-driver" } -/// Small on/off pill used in list rows. +/// Small on/off pill used in list rows. Its fill and label color ease +/// between on and off. fn pill_button( id: String, label: gpui::SharedString, on: bool, handler: impl Fn(&gpui::ClickEvent, &mut Window, &mut App) + 'static, ) -> gpui::Stateful
{ + use crate::ui::motion; + let target = if on { 1. } else { 0. }; + let off_fill: gpui::Hsla = gpui::rgb(theme::bg_sidebar_card()).into(); + let on_fill: gpui::Hsla = gpui::rgb(theme::bg_default_button()).into(); + let off_text: gpui::Hsla = gpui::rgb(theme::text_secondary()).into(); + let on_text: gpui::Hsla = gpui::rgb(theme::text_on_default_button()).into(); div() .id(gpui::SharedString::from(id)) + .relative() .px_2p5() .py_1() .rounded_full() .text_xs() .font_weight(gpui::FontWeight::MEDIUM) - .bg(gpui::rgb(if on { - theme::bg_default_button() - } else { - theme::bg_sidebar_card() - })) - .text_color(gpui::rgb(if on { - theme::text_on_default_button() - } else { - theme::text_secondary() - })) .hover(|style| style.opacity(0.85).cursor_pointer()) .active(|style| style.opacity(0.7)) .on_click(handler) - .child(label) + .child(motion::animated( + "pill-fill", + target, + motion::TOGGLE, + motion::ease_out_cubic, + move |on| { + div() + .absolute() + .inset_0() + .rounded_full() + .bg(motion::mix(off_fill, on_fill, on)) + .into_any_element() + }, + )) + .child(motion::animated( + "pill-label", + target, + motion::TOGGLE, + motion::ease_out_cubic, + move |on| { + div() + .relative() + .text_color(motion::mix(off_text, on_text, on)) + .child(label.clone()) + .into_any_element() + }, + )) } /// Whether a key press presses the focused control, as a click does. diff --git a/apps/maple-agent/app/src/ui/settings/api_credits.rs b/apps/maple-agent/app/src/ui/settings/api_credits.rs index dddec817e..7b76c2ac0 100644 --- a/apps/maple-agent/app/src/ui/settings/api_credits.rs +++ b/apps/maple-agent/app/src/ui/settings/api_credits.rs @@ -404,6 +404,42 @@ impl SettingsScreen { cx, ), )); + let custom = credits.choice == CreditChoice::Custom; + let hint = match &credits.custom_credits { + None => None, + Some(Ok(amount)) => Some(( + self.messages + .get( + "settings-credits-cost", + [ + ("credits", (format_count(*amount as i64)).to_string().into()), + ("dollars", (amount / CREDITS_PER_DOLLAR).to_string().into()), + ], + ) + .to_string(), + theme::text_secondary(), + )), + Some(Err(error)) => Some(( + credit_error(*error).resolve().to_string(), + theme::status_error(), + )), + }; + // The custom amount's field unfolds under the packages when it is + // chosen and folds away when another package is, so the buttons + // below glide rather than jump. Its top padding stands in for the + // card's gap, which would otherwise jump on its own. + let custom_field = div() + .pt_3() + .flex() + .flex_col() + .gap_1() + .child(self.application_target( + target(CreditsTarget::CustomAmount), + widgets::input_frame().child(credits.custom.clone()), + )) + .when_some(hint, |column, (hint, color)| { + column.child(div().text_xs().text_color(gpui::rgb(color)).child(hint)) + }); let mut purchase = widgets::card_row() .flex() .flex_col() @@ -415,41 +451,17 @@ impl SettingsScreen { .text_color(gpui::rgb(theme::text_primary())) .child(tr("settings-api-credits-buy-credits")), ) - .child(packages); - if credits.choice == CreditChoice::Custom { - let hint = match &credits.custom_credits { - None => None, - Some(Ok(amount)) => Some(( - self.messages - .get( - "settings-credits-cost", - [ - ("credits", (format_count(*amount as i64)).to_string().into()), - ("dollars", (amount / CREDITS_PER_DOLLAR).to_string().into()), - ], - ) - .to_string(), - theme::text_secondary(), - )), - Some(Err(error)) => Some(( - credit_error(*error).resolve().to_string(), - theme::status_error(), - )), - }; - purchase = purchase.child( + .child( div() .flex() .flex_col() - .gap_1() - .child(self.application_target( - target(CreditsTarget::CustomAmount), - widgets::input_frame().child(credits.custom.clone()), - )) - .when_some(hint, |column, (hint, color)| { - column.child(div().text_xs().text_color(gpui::rgb(color)).child(hint)) - }), + .child(packages) + .child(crate::ui::motion::unfold( + "credits-custom-amount", + custom, + custom_field, + )), ); - } let ready = credits.purchasing.is_none() && credits.selected_credits().is_ok(); let guest = self.guest_account(); diff --git a/apps/maple-agent/app/src/ui/text_input.rs b/apps/maple-agent/app/src/ui/text_input.rs index ee56d7548..74d91aafd 100644 --- a/apps/maple-agent/app/src/ui/text_input.rs +++ b/apps/maple-agent/app/src/ui/text_input.rs @@ -11,7 +11,7 @@ pub mod vim; pub(crate) mod vim_actions; use super::popup::{Menu, MenuItem, Placement, Popup}; -use super::{application_vim, spell, theme}; +use super::{application_vim, motion, spell, theme}; use std::collections::VecDeque; use std::ops::Range; use std::sync::Arc; @@ -134,6 +134,9 @@ pub struct TextInput { /// layout does not re-shape unchanged text every frame, and a chat /// face/size change does not keep a stale row count. measure_cache: Option<(SharedString, Pixels, Font, Pixels, Pixels, usize)>, + /// Drawn height of a multi-line input that sizes to its text, eased + /// between row counts (see [`Growth`]). + growth: Option, /// Shaped lines from the last prepaint with the inputs they came /// from; reused while nothing that affects shaping has changed. shape_cache: Option, @@ -286,6 +289,7 @@ impl TextInput { fill_height: false, max_lines: 8, measure_cache: None, + growth: None, shape_cache: None, is_selecting: false, popup: Popup::new(|this| &mut this.popup, cx), @@ -430,10 +434,72 @@ impl TextInput { pub fn set_fill_height(&mut self, fill: bool, cx: &mut Context) { if self.fill_height != fill { self.fill_height = fill; + // Back to sizing by the text: start from its height rather + // than easing from the rows before the fill. + self.growth = None; cx.notify(); } } + /// The field's height as drawn last frame, and the height its text + /// needs (one to `max_lines` rows). They differ while it fills its + /// parent; the expanded composer eases back to the text's height. + pub fn drawn_and_text_height(&self) -> Option<(Pixels, Pixels)> { + let (layout, bounds) = (self.last_layout.as_ref()?, self.last_bounds.as_ref()?); + let text = layout + .height() + .min(layout.line_height * self.max_lines as f32); + Some((bounds.size.height, text)) + } + + /// The height to draw for `rows` measured at `width` in `font`. A + /// new row count under the same measure comes from the text, so the + /// box eases to it from the height on screen; a new width or font + /// (a window resize, the sidebar sliding, a chat font change), the + /// first layout, and reduced motion snap. + fn grow( + &mut self, + rows: usize, + width: Pixels, + font: &Font, + font_size: Pixels, + line_height: Pixels, + reduced: bool, + ) -> Pixels { + let target = (line_height * rows as f32).as_f32(); + match &mut self.growth { + Some(growth) + if growth.width == width + && growth.font == *font + && growth.font_size == font_size + && growth.line_height == line_height => + { + let now = motion::now(); + let distance = px(target - growth.height.value(now)); + let (height, _) = growth.height.step( + target, + motion::resize_duration(distance), + motion::ease_out_cubic, + now, + reduced, + ); + growth.drawn = height; + px(height) + } + _ => { + self.growth = Some(Growth { + height: motion::Tween::new(target), + drawn: target, + width, + font: font.clone(), + font_size, + line_height, + }); + px(target) + } + } + } + pub fn on_enter( mut self, handler: impl Fn(String, &mut Window, &mut Context) + 'static, @@ -2526,6 +2592,22 @@ fn snap_to_char_boundary(text: &str, offset: usize) -> usize { offset } +/// The drawn height of a multi-line input that sizes to its text, and +/// the measure it eases under. Rows that change at the same width and +/// font came from the text and ease; anything else snaps. +struct Growth { + /// Height in pixels, heading for `rows * line_height`. + height: motion::Tween, + /// The height layout drew this frame. While it differs from the + /// target, prepaint asks for another frame and lays the text out for + /// the target. + drawn: f32, + width: Pixels, + font: Font, + font_size: Pixels, + line_height: Pixels, +} + /// Everything `shape_text` was given last time, and what it returned. /// A cursor move or a blink must not re-shape the text: prepaint runs /// on every notify, and shaping is the expensive part of it. @@ -2749,8 +2831,12 @@ impl Element for TextElement { style.min_size.height = window.line_height().into(); return (window.request_layout(style, [], cx), ()); } - // Grow with the wrapped content, one to `max_lines` rows. + // Grow with the wrapped content, one to `max_lines` rows. Layout + // runs the measure outside this element's text style, so take the + // style the text paints in now. let entity = self.input.clone(); + let text_style = window.text_style(); + let line_height = window.line_height(); let layout = window.request_measured_layout(style, move |known, available, window, cx| { let input = entity.read(cx); let text = if input.content.is_empty() { @@ -2758,54 +2844,74 @@ impl Element for TextElement { } else { input.display_text() }; - let line_height = window.line_height(); let width = known.width.or(match available.width { gpui::AvailableSpace::Definite(width) => Some(width), _ => None, }); let cache_width = width.unwrap_or(px(0.)); - let style = window.text_style(); + let style = &text_style; let font_size = style.font_size.to_pixels(window.rem_size()); let font = style.font(); - if let Some(( - cached_text, - cached_width, - cached_font, - cached_font_size, - cached_line_height, - rows, - )) = input.measure_cache.as_ref() - && *cached_text == text - && *cached_width == cache_width - && *cached_font == font - && *cached_font_size == font_size - && *cached_line_height == line_height - { - return size(cache_width, line_height * *rows as f32); - } - let run = TextRun { - len: text.len(), - font: font.clone(), - color: style.color, - background_color: None, - underline: None, - strikethrough: None, + let cached = input + .measure_cache + .as_ref() + .filter( + |( + cached_text, + cached_width, + cached_font, + cached_font_size, + cached_line_height, + _, + )| { + *cached_text == text + && *cached_width == cache_width + && *cached_font == font + && *cached_font_size == font_size + && *cached_line_height == line_height + }, + ) + .map(|cache| cache.5); + let rows = match cached { + Some(rows) => rows, + None => { + let run = TextRun { + len: text.len(), + font: font.clone(), + color: style.color, + background_color: None, + underline: None, + strikethrough: None, + }; + let rows = window + .text_system() + .shape_text(text.clone(), font_size, &[run], width, None) + .map(|lines| { + lines + .iter() + .map(|line| line.wrap_boundaries().len() + 1) + .sum::() + }) + .unwrap_or(1) + .clamp(1, input.max_lines); + let font = font.clone(); + entity.update(cx, |input, _| { + input.measure_cache = + Some((text, cache_width, font, font_size, line_height, rows)); + }); + rows + } }; - let rows = window - .text_system() - .shape_text(text.clone(), font_size, &[run], width, None) - .map(|lines| { - lines - .iter() - .map(|line| line.wrap_boundaries().len() + 1) - .sum::() - }) - .unwrap_or(1) - .clamp(1, input.max_lines); - entity.update(cx, |input, _| { - input.measure_cache = Some((text, cache_width, font, font_size, line_height, rows)); + // An intrinsic-size probe has no width to wrap at; it is not + // the box being drawn, so it leaves the eased height alone. + let Some(width) = width else { + return size(cache_width, line_height * rows as f32); + }; + let reduced = cx.reduce_motion(); + let height = entity.update(cx, |input, _| { + input.grow(rows, width, &font, font_size, line_height, reduced) }); - size(cache_width, line_height * rows as f32) + size(width, height) }); (layout, ()) } @@ -2896,6 +3002,19 @@ impl Element for TextElement { let last_scroll_x = input.scroll_x; let last_scroll_y = input.scroll_y; let keep_cursor_visible = input.keep_cursor_visible; + // While the box eases toward a new row count, lay the text out + // for the height it is heading to and let the box clip the rest, + // so following the cursor never scrolls on the way. + let easing_to = input + .growth + .as_ref() + .filter(|growth| { + multiline && !input.fill_height && growth.drawn != growth.height.target() + }) + .map(|growth| px(growth.height.target())); + if easing_to.is_some() { + window.request_animation_frame(); + } let wrap_width = multiline.then_some(bounds.size.width); // Reuse last frame's shaping when its inputs are unchanged. Lines // are Arc-backed, so the clone is a refcount per line. @@ -2966,7 +3085,7 @@ impl Element for TextElement { // cursor after an edit or a cursor move, keep a wheel scroll put, // and clamp when the content shrinks. let scroll_y = if multiline { - let viewport = bounds.size.height; + let viewport = easing_to.unwrap_or(bounds.size.height); let max_scroll = (layout.height() - viewport).max(px(0.)); let mut sy = last_scroll_y.min(max_scroll).max(px(0.)); if keep_cursor_visible { @@ -3674,6 +3793,163 @@ mod tests { ); } + /// A column like the composer's, so a multi-line field sizes to its + /// text at `width`. + struct GrowHost { + input: Entity, + width: Pixels, + } + + impl Render for GrowHost { + fn render(&mut self, _window: &mut Window, _cx: &mut Context) -> impl IntoElement { + div() + .w(self.width) + .h(px(400.)) + .flex() + .flex_col() + .child(self.input.clone()) + } + } + + /// A multi-line field holding `text`, drawn with the clock at `start`. + fn growing_field<'a>( + cx: &'a mut TestAppContext, + text: &str, + start: std::time::Instant, + ) -> ( + Entity, + Entity, + &'a mut gpui::VisualTestContext, + ) { + cx.executor().allow_parking(); + cx.update(|cx| cx.set_reduce_motion(false)); + motion::set_test_now(Some(start)); + let input = cx.new(|cx| TextInput::new("", cx).multiline(8)); + input.update(cx, |input, cx| input.set_text(text, cx)); + let (host, cx) = cx.add_window_view(|_window, _cx| GrowHost { + input: input.clone(), + width: px(300.), + }); + cx.run_until_parked(); + (input, host, cx) + } + + fn drawn_height(input: &Entity, cx: &mut gpui::VisualTestContext) -> Pixels { + cx.update(|_window, app| input.read(app).last_bounds.expect("drawn").size.height) + } + + fn line_height(input: &Entity, cx: &mut gpui::VisualTestContext) -> Pixels { + cx.update(|_window, app| { + input + .read(app) + .growth + .as_ref() + .expect("measured") + .line_height + }) + } + + fn set_text_drawn(input: &Entity, text: &str, cx: &mut gpui::VisualTestContext) { + cx.update(|_window, app| input.update(app, |input, cx| input.set_text(text, cx))); + cx.run_until_parked(); + } + + /// Deliver the next frame with the clock at `at`; how many frame + /// requests it answered. + fn frame_at(at: std::time::Instant, cx: &mut gpui::VisualTestContext) -> usize { + motion::set_test_now(Some(at)); + let requests = cx.update(|window, app| window.simulate_next_frame(app)); + cx.run_until_parked(); + requests + } + + #[gpui::test] + fn a_growing_field_eases_to_its_new_rows_and_settles(cx: &mut TestAppContext) { + let start = std::time::Instant::now(); + let (input, _host, cx) = growing_field(cx, "one", start); + let row = line_height(&input, cx); + assert_eq!(drawn_height(&input, cx), row, "the first layout snaps"); + + set_text_drawn(&input, "one\ntwo\nthree", cx); + assert_eq!( + drawn_height(&input, cx), + row, + "new rows ease in from the height on screen" + ); + let duration = motion::resize_duration(row * 2.); + assert!( + frame_at(start + duration / 3, cx) > 0, + "moving asks for frames" + ); + let partway = drawn_height(&input, cx); + assert!(partway > row && partway < row * 3., "partway: {partway:?}"); + assert_eq!( + cx.update(|_window, app| input.read(app).scroll_y), + px(0.), + "the text is laid out for the height it heads to, so the cursor \ + on the third row does not scroll it" + ); + + frame_at(start + duration, cx); + assert_eq!(drawn_height(&input, cx), row * 3.); + assert_eq!( + frame_at(start + duration * 2, cx), + 0, + "settled asks for none" + ); + motion::set_test_now(None); + } + + #[gpui::test] + fn a_growing_field_turns_back_from_the_height_on_screen(cx: &mut TestAppContext) { + let start = std::time::Instant::now(); + let (input, _host, cx) = growing_field(cx, "one", start); + let row = line_height(&input, cx); + + set_text_drawn(&input, "1\n2\n3\n4\n5", cx); + let half = motion::resize_duration(row * 4.) / 2; + frame_at(start + half, cx); + let partway = drawn_height(&input, cx); + assert!(partway > row && partway < row * 5., "partway: {partway:?}"); + + // Clearing after a send while it still grows. + set_text_drawn(&input, "", cx); + assert_eq!(drawn_height(&input, cx), partway, "no jump on reversal"); + frame_at(start + half + std::time::Duration::from_millis(40), cx); + let back = drawn_height(&input, cx); + assert!(back < partway && back > row, "heading back: {back:?}"); + + frame_at(start + motion::PANEL * 4, cx); + assert_eq!(drawn_height(&input, cx), row); + assert_eq!(frame_at(start + motion::PANEL * 5, cx), 0); + motion::set_test_now(None); + } + + #[gpui::test] + fn a_growing_field_snaps_to_a_new_width_and_under_reduced_motion(cx: &mut TestAppContext) { + let start = std::time::Instant::now(); + let (input, host, cx) = growing_field(cx, &"word ".repeat(20), start); + let row = line_height(&input, cx); + let wide = drawn_height(&input, cx); + + // A window resize or the sidebar sliding rewraps the text. + host.update(cx, |host, cx| { + host.width = px(150.); + cx.notify(); + }); + cx.run_until_parked(); + let narrow = drawn_height(&input, cx); + assert!(narrow > wide, "narrower wraps to more rows"); + assert_eq!(frame_at(start, cx), 0, "a width change snaps"); + assert_eq!(drawn_height(&input, cx), narrow); + + cx.update(|_window, app| app.set_reduce_motion(true)); + set_text_drawn(&input, "one", cx); + assert_eq!(drawn_height(&input, cx), row, "reduced motion snaps"); + assert_eq!(frame_at(start, cx), 0); + motion::set_test_now(None); + } + #[gpui::test] fn test_cursor_moves_never_leave_the_content(cx: &mut TestAppContext) { cx.executor().allow_parking(); diff --git a/apps/maple-agent/app/src/ui/titlebar.rs b/apps/maple-agent/app/src/ui/titlebar.rs index f493557fd..274aad7ff 100644 --- a/apps/maple-agent/app/src/ui/titlebar.rs +++ b/apps/maple-agent/app/src/ui/titlebar.rs @@ -210,11 +210,15 @@ fn control( .bg(gpui::rgb(theme::bg_title_control())) .text_xs() .text_color(gpui::rgb(theme::text_primary())) - .hover(|style| { - style - .bg(gpui::rgb(theme::bg_title_control_hover())) - .cursor_pointer() + .map(|element| { + let rest: gpui::Hsla = gpui::rgb(theme::bg_title_control()).into(); + crate::ui::motion::hover_background( + element, + rest, + gpui::rgb(theme::bg_title_control_hover()), + ) }) + .hover(|style| style.cursor_pointer()) .on_mouse_down(gpui::MouseButton::Left, { let action = std::rc::Rc::new(action); move |_event, window, cx| { diff --git a/apps/maple-agent/app/src/ui/update_confirmation.rs b/apps/maple-agent/app/src/ui/update_confirmation.rs index c077a03b3..7f36cedf4 100644 --- a/apps/maple-agent/app/src/ui/update_confirmation.rs +++ b/apps/maple-agent/app/src/ui/update_confirmation.rs @@ -86,11 +86,11 @@ impl Render for UpdateConfirmation { .inset_0() .size_full() .occlude() - .bg(theme::scrim()) .flex() .items_center() .justify_center() - .child( + .child(widgets::dialog_scrim()) + .child(widgets::dialog_card( div() .id("update-confirmation") .debug_selector(|| "update-confirmation".to_string()) @@ -177,7 +177,7 @@ impl Render for UpdateConfirmation { })), ), ), - ) + )) .into_any_element() } } @@ -342,6 +342,39 @@ mod tests { assert_eq!(answer.try_recv().unwrap(), 1); } + /// The card rises into place as the dialog opens (the test executor + /// draws its first frames well inside the entrance), at rest under + /// reduced motion, and leaves on the frame that answers it. + #[gpui::test] + fn the_dialog_rises_in_and_leaves_at_once(cx: &mut gpui::TestAppContext) { + cx.update(|cx| cx.set_reduce_motion(false)); + let (_host, mut answer, cx) = show(cx); + cx.run_until_parked(); + let arriving = cx.debug_bounds("update-confirmation").unwrap(); + cx.update(|_, cx| cx.set_reduce_motion(true)); + cx.run_until_parked(); + let rest = cx.debug_bounds("update-confirmation").unwrap(); + let rise = arriving.top() - rest.top(); + assert!( + px(0.) < rise && rise <= px(8.), + "the card rises from up to 8 px below: {arriving:?} -> {rest:?}" + ); + assert_eq!(arriving.size, rest.size); + // Frames the entrance asked for before reduced motion came on. + cx.update(|window, cx| { + window.simulate_next_frame(cx); + }); + cx.run_until_parked(); + assert_eq!(cx.update(|window, cx| window.simulate_next_frame(cx)), 0); + + cx.simulate_keystrokes("escape"); + assert_eq!(answer.try_recv().unwrap(), 0); + assert!( + cx.debug_bounds("update-confirmation").is_none(), + "the dialog leaves on the frame it closes" + ); + } + #[gpui::test] fn dropping_the_updater_confirmation_cancels_without_an_answer(cx: &mut gpui::TestAppContext) { let (host, mut answer, cx) = show(cx); diff --git a/apps/maple-agent/app/src/ui/widgets.rs b/apps/maple-agent/app/src/ui/widgets.rs index 40192a9e7..84a6ffe6c 100644 --- a/apps/maple-agent/app/src/ui/widgets.rs +++ b/apps/maple-agent/app/src/ui/widgets.rs @@ -1,9 +1,8 @@ //! Shared chrome for the gpui screens: popup panels, buttons, switches, //! tooltips, card rows, input frames, and banners. //! -//! Every helper returns a bare `div()` builder, so it costs the same as -//! the inline chain it replaces: no allocation, no parsing, nothing -//! cached. Callers keep their own ids, children, and click handlers. +//! Helpers preserve the div builder API and callers keep their ids, children, +//! and click handlers. Hover backgrounds share a short reversible transition. //! //! Shapes follow the brand kit: buttons are pills, small controls use //! `theme::RADIUS_SM`, popups and inputs `theme::RADIUS_MD`, cards @@ -20,6 +19,7 @@ use gpui::{ }; use super::icons::icon; +use super::motion::{self, HoverBackground, hover_background}; use super::theme; /// How long an icon-only control waits before showing its tooltip. Icons @@ -105,39 +105,43 @@ pub fn navigate_mark(color: u32) -> gpui::Svg { } /// Accessible default/primary action button: high-contrast neutral inverted pill. -pub fn default_button(id: impl Into) -> Stateful
{ - pill(id) - .bg(gpui::rgb(theme::bg_default_button())) - .text_color(gpui::rgb(theme::text_on_default_button())) - .hover(|style| { - style - .bg(gpui::rgb(theme::bg_default_button_hover())) - .cursor_pointer() - }) - .active(|style| press_depth(style.bg(gpui::rgb(theme::bg_default_button_active())))) +pub fn default_button(id: impl Into) -> HoverBackground { + hover_background( + pill(id) + .bg(gpui::rgb(theme::bg_default_button())) + .text_color(gpui::rgb(theme::text_on_default_button())) + .hover(|style| style.cursor_pointer()) + .active(|style| press_depth(style.bg(gpui::rgb(theme::bg_default_button_active())))), + gpui::rgb(theme::bg_default_button()), + gpui::rgb(theme::bg_default_button_hover()), + ) } /// Legacy accent-filled action button; new and Settings surfaces use /// [`default_button`] for WCAG contrast until legacy callers migrate globally. -pub fn primary_button(id: impl Into) -> Stateful
{ - pill(id) - .bg(gpui::rgb(theme::accent())) - .text_color(gpui::rgb(theme::on_accent())) - .hover(|style| style.bg(gpui::rgb(theme::accent_hover())).cursor_pointer()) - .active(|style| press_depth(style.bg(gpui::rgb(theme::send_bottom())))) +pub fn primary_button(id: impl Into) -> HoverBackground { + hover_background( + pill(id) + .bg(gpui::rgb(theme::accent())) + .text_color(gpui::rgb(theme::on_accent())) + .hover(|style| style.cursor_pointer()) + .active(|style| press_depth(style.bg(gpui::rgb(theme::send_bottom())))), + gpui::rgb(theme::accent()), + gpui::rgb(theme::accent_hover()), + ) } /// Neutral pill for the second action beside a [`primary_button`] /// (Cancel, Back, alternate sign-in): a pebble fill that darkens on hover. -pub fn secondary_button(id: impl Into) -> Stateful
{ - pill(id) - .bg(gpui::rgb(theme::bg_sidebar_pill())) - .text_color(gpui::rgb(theme::text_primary())) - .hover(|style| { - style - .bg(gpui::rgb(theme::bg_sidebar_row_selected())) - .cursor_pointer() - }) - .active(|style| press_depth(style.bg(gpui::rgb(theme::border())))) +pub fn secondary_button(id: impl Into) -> HoverBackground { + hover_background( + pill(id) + .bg(gpui::rgb(theme::bg_sidebar_pill())) + .text_color(gpui::rgb(theme::text_primary())) + .hover(|style| style.cursor_pointer()) + .active(|style| press_depth(style.bg(gpui::rgb(theme::border())))), + gpui::rgb(theme::bg_sidebar_pill()), + gpui::rgb(theme::bg_sidebar_row_selected()), + ) } /// A key named beside the control it works: one fixed height, so a row of @@ -165,25 +169,32 @@ pub fn keycap(label: impl Into) -> Div { /// Text-only button for low-emphasis actions: no fill, no border, and /// the label brightens on hover. -pub fn ghost_button(id: impl Into) -> Stateful
{ - pill(id) - .text_color(gpui::rgb(theme::text_secondary())) - .hover(|style| { - style - .text_color(gpui::rgb(theme::text_primary())) - .bg(theme::overlay_hover()) - .cursor_pointer() - }) - .active(|style| style.bg(gpui::rgb(theme::bg_sidebar_pill()))) +pub fn ghost_button(id: impl Into) -> HoverBackground { + hover_background( + pill(id) + .text_color(gpui::rgb(theme::text_secondary())) + .hover(|style| { + style + .text_color(gpui::rgb(theme::text_primary())) + .cursor_pointer() + }) + .active(|style| style.bg(gpui::rgb(theme::bg_sidebar_pill()))), + gpui::transparent_black(), + theme::overlay_hover(), + ) } /// Destructive pill (Remove, Deny): error fill with a light label. -pub fn danger_button(id: impl Into) -> Stateful
{ - pill(id) - .bg(gpui::rgb(theme::status_error())) - .text_color(gpui::rgb(theme::on_accent())) - .hover(|style| style.opacity(0.9).cursor_pointer()) - .active(|style| press_depth(style.opacity(0.85))) +pub fn danger_button(id: impl Into) -> HoverBackground { + let error: Hsla = gpui::rgb(theme::status_error()).into(); + hover_background( + pill(id) + .text_color(gpui::rgb(theme::on_accent())) + .hover(|style| style.cursor_pointer()) + .active(|style| press_depth(style.opacity(0.85))), + error, + gpui::hsla(error.h, error.s, error.l, 0.9), + ) } /// A destructive action at rest: outlined in the error color, filled only @@ -209,7 +220,7 @@ pub fn icon_button( label: impl Into, size: Pixels, color: u32, -) -> Stateful
{ +) -> HoverBackground { let label = label.into(); icon_button_base(id, name, label.clone(), size, color).tooltip(tooltip(label, None)) } @@ -224,7 +235,7 @@ pub fn icon_button_for_action( size: Pixels, color: u32, action: &dyn Action, -) -> Stateful
{ +) -> HoverBackground { let label = label.into(); icon_button_base(id, name, label.clone(), size, color) .tooltip(tooltip_for_action(label, action)) @@ -236,26 +247,26 @@ fn icon_button_base( label: impl Into, size: Pixels, color: u32, -) -> Stateful
{ - div() - .id(id) - .role(Role::Button) - .aria_label(label) - .flex_none() - .size_7() - .flex() - .items_center() - .justify_center() - .rounded(theme::RADIUS_SM) - .focus_visible(focus_ring) - .hover(|style| { - style - .bg(gpui::rgb(theme::bg_sidebar_row_hover())) - .cursor_pointer() - }) - .active(|style| style.bg(gpui::rgb(theme::bg_sidebar_row_selected()))) - .tooltip_show_delay(ICON_TOOLTIP_DELAY) - .child(icon(name, size, color)) +) -> HoverBackground { + hover_background( + div() + .id(id) + .role(Role::Button) + .aria_label(label) + .flex_none() + .size_7() + .flex() + .items_center() + .justify_center() + .rounded(theme::RADIUS_SM) + .focus_visible(focus_ring) + .hover(|style| style.cursor_pointer()) + .active(|style| style.bg(gpui::rgb(theme::bg_sidebar_row_selected()))) + .tooltip_show_delay(ICON_TOOLTIP_DELAY) + .child(icon(name, size, color)), + gpui::transparent_black(), + gpui::rgb(theme::bg_sidebar_row_hover()), + ) } /// On/off switch: a pill track with a knob that sits right when `on`. @@ -277,12 +288,17 @@ pub fn switch(id: impl Into, on: bool) -> Stateful
{ /// A labeled checkbox row. The caller supplies its tab index and click/key /// handlers, so mouse and keyboard activation share the same state change. +/// The box's fill cross-fades and the check scales in over +/// [`motion::TOGGLE`]. pub fn checkbox( id: impl Into, checked: bool, label: impl Into, ) -> Stateful
{ let label = label.into(); + let unchecked_border: Hsla = gpui::rgb(theme::text_muted()).into(); + let unchecked_fill: Hsla = gpui::rgb(theme::bg_input()).into(); + let accent = accent(); div() .id(id) .role(Role::CheckBox) @@ -302,56 +318,81 @@ pub fn checkbox( .focus_visible(focus_ring) .hover(|style| style.cursor_pointer()) .active(|style| style.opacity(0.85)) - .child( - div() - .flex_none() - .size(px(18.)) - .rounded(px(4.)) - .border_1() - .border_color(gpui::rgb(if checked { - theme::accent() - } else { - theme::text_muted() - })) - .bg(gpui::rgb(if checked { - theme::accent() - } else { - theme::bg_input() - })) - .flex() - .items_center() - .justify_center() - .when(checked, |square| { - square.child(icon("check", px(14.), theme::on_accent())) - }), - ) + .child(motion::animated( + "checkbox-mark", + if checked { 1. } else { 0. }, + motion::TOGGLE, + motion::ease_out_cubic, + move |checked| { + let scale = 0.6 + 0.4 * checked; + div() + .flex_none() + .size(px(18.)) + .rounded(px(4.)) + .border_1() + .border_color(motion::mix(unchecked_border, accent, checked)) + .bg(motion::mix(unchecked_fill, accent, checked)) + .flex() + .items_center() + .justify_center() + .when(checked > 0., |square| { + square.child(div().flex().opacity(checked).child( + icon("check", px(14.), theme::on_accent()).with_transformation( + gpui::Transformation::scale(gpui::size(scale, scale)), + ), + )) + }) + .into_any_element() + }, + )) .child(label) } +/// How far a [`switch`] knob travels: the track's width, less its padding +/// and the knob. +const KNOB_TRAVEL: Pixels = px(34. - 2. * 3. - 14.); + /// The look of a [`switch`] without its role or input, for a row that is -/// itself the control, such as a switch item in a popup menu. +/// itself the control, such as a switch item in a popup menu. Its knob +/// slides and its track cross-fades over [`motion::TOGGLE`], reversing +/// from wherever it is; it is still when it first appears. The enclosing +/// element's id keys the motion. pub fn switch_track(on: bool) -> Div { + let off_track: Hsla = gpui::rgb(theme::bg_sidebar_row_selected()).into(); + let on_track = accent(); + let knob: Hsla = gpui::rgb(theme::on_accent()).into(); div() .flex_none() .w(px(34.)) .h(px(20.)) - .p(px(3.)) .rounded_full() - .bg(gpui::rgb(if on { - theme::accent() - } else { - theme::bg_sidebar_row_selected() - })) - .flex() - .items_center() - .when(on, |track| track.justify_end()) - .child( - div() - .size(px(14.)) - .rounded_full() - .bg(gpui::rgb(theme::on_accent())) - .shadow_2xs(), - ) + .child(motion::animated( + "switch-knob", + if on { 1. } else { 0. }, + motion::TOGGLE, + motion::ease_out_cubic, + move |on| { + div() + .size_full() + .p(px(3.)) + .rounded_full() + .bg(motion::mix(off_track, on_track, on)) + .flex() + .items_center() + .child( + motion::shifted( + div() + .debug_selector(|| "switch-knob".into()) + .size(px(14.)) + .rounded_full() + .bg(knob) + .shadow_2xs(), + ) + .offset(gpui::point(KNOB_TRAVEL * on, px(0.))), + ) + .into_any_element() + }, + )) } /// Small status pill beside a card's title (an integration's availability, @@ -547,10 +588,45 @@ pub fn notice( /// Icon size in a popup menu row or an [`icon_button`] in a list row. pub const ROW_ICON: Pixels = px(14.); +// ---- Dialogs -------------------------------------------------------------- + +/// How far a dialog card rises as it opens. +const DIALOG_RISE: Pixels = px(8.); + +/// The dimmed layer behind a modal card. Put it first inside the dialog's +/// full-window backdrop, which keeps the pointer handling and centers the +/// card: the scrim fades in over [`motion::ENTER`] on its own, so the +/// card's fade is not multiplied by it. A dialog closes at once. +pub fn dialog_scrim() -> impl IntoElement { + use gpui::AnimationExt as _; + div() + .absolute() + .inset_0() + .bg(theme::scrim()) + .with_animation( + "dialog-scrim", + gpui::Animation::new(motion::ENTER).with_easing(motion::ease_out_quint), + |scrim, shown| scrim.opacity(shown), + ) +} + +/// A modal card arriving: it fades in and rises from 8 px below over +/// [`motion::ENTER`]. Layout uses its resting place throughout, and it +/// takes keys and focus from its first frame. +pub fn dialog_card(card: E) -> impl IntoElement { + motion::slide_in( + card, + "dialog-card", + motion::ENTER, + gpui::point(px(0.), DIALOG_RISE), + ) +} + // ---- Tooltips ------------------------------------------------------------- /// Small label shown above the pointer after gpui's hover delay, with an -/// optional fixed shortcut hint. Attach with `.tooltip(widgets::tooltip(..))`. +/// optional fixed shortcut hint. It fades in over [`motion::REVEAL`] and +/// goes at once. Attach with `.tooltip(widgets::tooltip(..))`. /// Prefer [`tooltip_for_action`] when the control fires an action: that /// reads the live keymap instead of a literal that a rebind would outdate. pub fn tooltip( @@ -676,7 +752,7 @@ const TOOLTIP_GAP: Pixels = px(16.); const TOOLTIP_CURSOR_CLEARANCE: Pixels = px(20.); impl Render for Tooltip { - fn render(&mut self, _window: &mut Window, _cx: &mut gpui::Context) -> impl IntoElement { + fn render(&mut self, _window: &mut Window, cx: &mut gpui::Context) -> impl IntoElement { // gpui puts a tooltip's corner just past the pointer, where the // cursor covers it. The view stays zero-sized there and anchors the // label at the pointer itself: centered, 16 px above it. @@ -717,7 +793,10 @@ impl Render for Tooltip { div() .pt(TOOLTIP_CURSOR_CLEARANCE) .pb(TOOLTIP_GAP) - .child(label), + .child(motion::fade_in( + label, + ElementId::NamedInteger("tooltip".into(), cx.entity_id().as_u64()), + )), ), ) } @@ -759,7 +838,7 @@ pub fn copy_button( text: SharedString, reveal: Option<&SharedString>, view: Option, -) -> Stateful
{ +) -> super::motion::HoverBackground { let id = id.into(); let copied = copied_recently(&id); let click_id = id.clone(); @@ -787,7 +866,6 @@ pub fn copy_button( .focus_visible(focus_ring) .hover(|style| { style - .bg(theme::overlay_hover()) .text_color(gpui::rgb(theme::text_secondary())) .cursor_pointer() }) @@ -821,6 +899,13 @@ pub fn copy_button( } else { "common-copy" })) + .map(|button| { + super::motion::hover_background( + button, + gpui::transparent_black(), + theme::overlay_hover(), + ) + }) } #[cfg(test)] @@ -945,4 +1030,83 @@ mod tests { ); } } + + /// A lone switch and checkbox the test turns on and off. + struct Toggles { + on: bool, + } + + impl Render for Toggles { + fn render( + &mut self, + _window: &mut Window, + _cx: &mut gpui::Context, + ) -> impl IntoElement { + div() + .size_full() + .p(px(20.)) + .child(switch("test-switch", self.on)) + .child(checkbox("test-checkbox", self.on, "Check")) + } + } + + /// A switch turned back mid-flight reverses from where its knob is + /// instead of jumping to an end, settles, and then asks for no more + /// frames. It is still when it first appears, and reduced motion moves + /// it at once. + #[gpui::test] + fn a_switch_reversed_mid_flight_turns_back_from_its_knob(cx: &mut TestAppContext) { + let start = Instant::now(); + motion::set_test_now(Some(start)); + cx.update(|cx| cx.set_reduce_motion(false)); + let (host, cx) = cx.add_window_view(|_, _| Toggles { on: false }); + cx.run_until_parked(); + let knob = + |cx: &mut VisualTestContext| cx.debug_bounds("switch-knob").expect("knob").left(); + let frames = + |cx: &mut VisualTestContext| cx.update(|window, cx| window.simulate_next_frame(cx)); + let frame_at = |at: Instant, cx: &mut VisualTestContext| { + motion::set_test_now(Some(at)); + cx.update(|window, cx| { + window.simulate_next_frame(cx); + }); + cx.run_until_parked(); + }; + let turn = |on: bool, cx: &mut VisualTestContext| { + host.update(cx, |host, cx| { + host.on = on; + cx.notify(); + }); + cx.run_until_parked(); + }; + let off = knob(cx); + assert_eq!(frames(cx), 0, "a switch is still when it first appears"); + + turn(true, cx); + assert_eq!(knob(cx), off, "the knob sets out from where it is"); + frame_at(start + motion::TOGGLE / 3, cx); + let partway = knob(cx); + assert!( + off < partway && partway < off + KNOB_TRAVEL, + "the knob {partway:?} is on its way from {off:?}" + ); + + turn(false, cx); + assert_eq!(knob(cx), partway, "turning back starts from the knob"); + frame_at(start + motion::TOGGLE / 3 + motion::TOGGLE / 4, cx); + let returning = knob(cx); + assert!( + off < returning && returning < partway, + "the knob {returning:?} heads back from {partway:?}" + ); + frame_at(start + motion::TOGGLE * 2, cx); + assert_eq!(knob(cx), off); + assert_eq!(frames(cx), 0, "a settled switch asks for no frames"); + + cx.update(|_, cx| cx.set_reduce_motion(true)); + turn(true, cx); + assert_eq!(knob(cx), off + KNOB_TRAVEL, "reduced motion moves at once"); + assert_eq!(frames(cx), 0); + motion::set_test_now(None); + } } diff --git a/apps/maple-agent/docs/brand.md b/apps/maple-agent/docs/brand.md index cae893655..bf3602174 100644 --- a/apps/maple-agent/docs/brand.md +++ b/apps/maple-agent/docs/brand.md @@ -251,8 +251,8 @@ hover overlay). All share 8 px vertical and 20 px horizontal padding The coral fill replaces the kit's translucent "glass" gradient, which is designed to sit on a Pebble 300 panel and washes out on the app's white and near-black surfaces. The hover and press scale motion is not applied: -gpui has no transition primitive, and a stepped scale change on hover -reads as a flicker. +gpui cannot scale a `div`. Hover eases the background instead, and press +stays immediate; see [motion](motion.md). ### Status banners diff --git a/apps/maple-agent/docs/motion.md b/apps/maple-agent/docs/motion.md new file mode 100644 index 000000000..fae1b5cf0 --- /dev/null +++ b/apps/maple-agent/docs/motion.md @@ -0,0 +1,128 @@ +# Motion + +Maple Work moves only to explain a change: where something came from, what +state it is in now, or that the app heard the user. Motion never stands +between the user and the next action. This page records the shared decisions; +`app/src/ui/motion.rs` implements them. + +## Rules + +- **Purpose first.** Each motion shows feedback, a change of state, or where + something went. If removing it loses nothing, remove it. +- **Never delay input.** Content is clickable and typeable the moment it is + drawn. Sends, keyboard shortcuts, Escape and Stop act on the frame they + arrive; nothing waits for an animation to finish. +- **Interruptible.** Every transition that can reverse (hover, reveal, + switches, chevrons, the composer, the sidebar) retargets from the value on + screen. A second click never jumps back to an endpoint or restarts. +- **Fast in, faster out.** Entrances ease out. Menus, popovers and dialogs + close at once: dismissal is the user's decision and the next action must + not wait for it. Reversible state changes run the same curve both ways. +- **Opacity first, small distances.** gpui cannot scale or transform a `div`, + so content enters with opacity and a short rise (6 px; 8 px for dialog + cards), drawn as a paint offset: layout stays put, and the hitbox moves + with the paint. Only SVG icons scale or rotate. + Height animates only where a box truly changes size: text fields, the + expanded composer, the sidebar, and a row arriving at the end of the + thread, which opens so older rows glide up rather than jump. +- **High-frequency work stays still.** Streaming tokens, typed characters, + keyboard navigation inside menus and lists, and history that loads or + scrolls into view do not animate. Rows animate once, when they arrive + live, never again when they scroll back into view. +- **No bounce, no stagger.** No overshoot or elastic curves anywhere; items + that arrive together appear together. +- **Reduced motion.** Settings → General → Reduce motion settles every + transition at its end state on the next frame and holds looping + indicators still. Every primitive in `motion.rs` honors it; new motion + must use those primitives rather than reading time itself. + +## Tokens + +| Token | Duration | Curve | Used for | +|---|---|---|---| +| `HOVER` | 120 ms | smoothstep | hover plates, controls that appear on hover | +| `REVEAL` | 140 ms | ease-out quint | menus, popovers, tooltips, page and pane changes | +| `TOGGLE` | 150 ms | ease-out cubic | switches, checkboxes, chevrons, icon swaps, status changes | +| `ENTER` | 180 ms | ease-out quint | live transcript rows, notices and cards above the composer, dialogs | +| `PANEL` | 200 ms | ease-out cubic | sidebar, composer expand and shrink | +| `resize_duration` | 120–200 ms | ease-out cubic | text fields growing and shrinking with their text, by distance | + +Press feedback is immediate (`.active()`), and focus rings appear at once. +Looping indicators (spinners, the waiting dots, the running ring) use the +shared 15 fps `ticker` clock and pause in background windows. + +## Where motion applies + +| Surface | In | Out | +|---|---|---| +| Hover on buttons, rows, menu items | background eases in, `HOVER` | eases back, `HOVER` | +| Menus, dropdowns, popovers | pointer: fade and 4 px slide away from the trigger, `REVEAL`; keyboard: at once | immediate | +| Tooltips | fade, `REVEAL`, after the existing delay | immediate | +| Dialogs and confirmations | scrim fades, card fades and rises, `ENTER` | immediate | +| Screen change (Chat ↔ Settings) and Settings sections | new content fades in, `REVEAL` | immediate | +| Empty state ↔ conversation (first message, opening a task, New Task) | the composer glides from where it was drawn to its new place, `PANEL` | same, reversed | +| Switching tasks | transcript fades in when its snapshot lands, `REVEAL` | immediate | +| Live transcript rows at the end of the thread (sent message, reply, thinking, tool card, error, stop notice) | height grows from 0 and the row fades in, `ENTER`, so older rows glide up; scrolled up, a fade and 6 px rise | — | +| Sent message | the bubble rises in; the real row takes its exact place, and "Sending…" and the waiting dots share one slot under it | — | +| Tool status | spinner leaves at once, the outcome fades in, `TOGGLE` | — | +| Disclosed details (tool output, thinking) | fade in, `REVEAL` | immediate | +| Streaming text | grows in place, no animation | — | +| Waiting dots | fade in, `REVEAL` | immediate | +| Notices, queued messages, cards above the composer | fade and rise, `ENTER` | immediate | +| Files attached to the draft | fade and 6 px rise, `ENTER` | immediate | +| Composer and multi-line fields | height eases to the new line count, `resize_duration` | same | +| Composer expand / shrink | height eases, `PANEL`; maximize and minimize icons cross-fade and scale, `TOGGLE` | same, reversed | +| A field a choice reveals (Buy credits → Custom amount) | box unfolds to the field's height and the field fades in, `PANEL` | folds the same way, reversed | +| Send ↔ Stop | icons cross-fade and scale, `TOGGLE` | same | +| Switches and checkboxes | knob slides, fill cross-fades, `TOGGLE` | same, reversed | +| Disclosure chevrons | rotate 90°, `TOGGLE` | same, reversed | +| Sidebar collapse | width eases, `PANEL` | same, reversed | +| Task status in the sidebar, project folders | indicators and folder icons cross-fade, `TOGGLE` | same | + +Loading spinners for work that usually finishes quickly (opening a task) +appear only after 300 ms, so fast loads never flash a spinner. + +## Implementation + +- `Tween` is the one retargetable value: it starts from the value on screen + and settles under reduced motion. Views that own a transition (the sidebar, + the composer) keep a `Tween` in their state, sample it in `render`, and call + `window.request_animation_frame()` only while it moves. +- `animated(id, target, ...)` keeps a `Tween` in element state for render code + that owns no state (chevrons, switches, icon swaps). It never animates on + mount. +- `unfold(id, open, content)` opens content in place: its box eases between + nothing and the content's height while the content fades, so what follows + glides, and it folds away the same way. Use it for in-flow content a + choice shows or hides, not for menus or dialogs, which close at once. +- `fade_in`, `rise_in` and `slide_in` are one-shot entrances keyed by element + id; a new id replays them. `swap_in(element, id, key, cover)` fades content + in whenever `key` changes but draws its first appearance at once, for + content that replaces other content in one place (the window's screen, a + Settings section). +- Never fade an ancestor of a cached view (`Entity::cached`, the sidebar): + gpui replays a cached view's last paint with the opacity it was painted + at, so it would stay as faint as its first frame. `swap_in` paints a cover + in the background color over the content instead, so the content always + paints at full opacity. The one exception is a fade during which the + cached view's bounds or content mask change every frame and change again + when it settles: the sidebar collapse clips its column only while it + moves, which forces a fresh paint each frame and a full-opacity one at + rest. +- Covers and fades never block input. `swap_in`'s cover paints without a + hitbox, and a fading transcript or an entering card takes clicks and keys + from its first frame. Do not add a hit-blocking cover to hide a change. +- Menus open from their trigger: the panel's fade and slide are drawn inside + the deferred draw, because opacity does not reach into `deferred()`. + A menu the keyboard opens appears at once, and keyboard highlight moves + inside a menu settle at once; pointer openings and hover ease. +- Transcript rows sit in a `gpui::list`, whose items lose element state when + they scroll away. Their entrance is driven by the arrival time kept in view + state, so a row animates once and never replays. A row that replaces the + slot under the transcript (the waiting dots, a sent message, a failed + send) opens from the slot's height, so nothing above it jumps. +- Every animated frame re-renders the window. Keep animations short, request + frames only while something moves, and never animate inside cached views + without an element id that is stable across frames. +- Tests that assert settled layout opt into reduced motion + (`cx.set_reduce_motion(true)`); motion tests sample deterministic time. From e4306d6a2c2cac1a3b4dc554fb39bf9f220f5d10 Mon Sep 17 00:00:00 2001 From: Anthony Ronning <101225832+AnthonyRonning@users.noreply.github.com> Date: Wed, 11 Nov 2026 13:20:18 -0800 Subject: [PATCH 05/19] Agent: move reversible motion onto springs, with timing in one place Every reversible transition (hover, switches, chevrons, the composer, the sidebar, unfolding, text fields growing) now runs on a spring from gpui's integrator instead of restarting an easing curve. A spring keeps the speed it has when its target changes, so turning back mid-way has no corner in it. Springs are critically damped: they do not overshoot from rest. Timing lives in one place. Each token in ui/motion.rs (HOVER, REVEAL, TOGGLE, ENTER, PANEL) is one constant holding the duration and curve its one-shot entrances run and the time its spring takes to settle, and DAMPING_RATIO sets how every spring is damped. Editing a token retunes every animation of that kind. Call sites pass a token; none names a curve. - Tween keeps its interface and becomes a spring. The sidebar and the composer retarget the Tween they have instead of starting a new one, which is what lets them keep their speed. Tween::pixels stops a length within a quarter pixel. - MAPLE_MOTION=eased runs reversible values on their token's duration and curve, as before, to compare the two in one build. - swap_in fades its content instead of painting a cover over it. gpui now repaints a cached view when the opacity it inherits changes, so the cover and the rule against fading above a cached view are gone. - The two tests that asserted the old curve's exact shape now pin the eased style; new tests cover a spring leaving from rest, not overshooting, settling within its token, and keeping its position and speed through a reversal. Co-Authored-By: Claude --- apps/maple-agent/CLAUDE.md | 9 +- apps/maple-agent/app/src/desktop.rs | 3 +- apps/maple-agent/app/src/ui/chat/composer.rs | 51 +- apps/maple-agent/app/src/ui/chat/mod.rs | 57 +- apps/maple-agent/app/src/ui/chat/sidebar.rs | 3 +- .../maple-agent/app/src/ui/chat/transcript.rs | 52 +- apps/maple-agent/app/src/ui/motion.rs | 629 +++++++++++++----- apps/maple-agent/app/src/ui/popup.rs | 10 +- apps/maple-agent/app/src/ui/settings.rs | 4 - apps/maple-agent/app/src/ui/text_input.rs | 21 +- apps/maple-agent/app/src/ui/widgets.rs | 19 +- apps/maple-agent/docs/motion.md | 78 ++- 12 files changed, 591 insertions(+), 345 deletions(-) diff --git a/apps/maple-agent/CLAUDE.md b/apps/maple-agent/CLAUDE.md index af5880640..e38791728 100644 --- a/apps/maple-agent/CLAUDE.md +++ b/apps/maple-agent/CLAUDE.md @@ -125,11 +125,10 @@ tokens and rules. Motion never delays input, retargets from the value on screen, closes menus and dialogs at once, and settles immediately under reduced motion. Streaming text, typing, and keyboard navigation do not animate. Rows inside `gpui::list` time their entrance from view state, not -element state, so they never replay when scrolled back into view. Never put -opacity on an ancestor of a cached view: its replayed paint keeps the -opacity of its first frame. Paint a cover over it instead, as `swap_in` -does, unless its bounds or content mask change on every frame of the fade -and again at rest, as in the sidebar collapse. +element state, so they never replay when scrolled back into view. Timing +comes from the tokens in `ui/motion.rs` and nowhere else: a reversible value +is a `Tween` on a token's spring, kept and retargeted rather than replaced, +and a one-shot entrance runs a token's duration and curve. ## Accessibility diff --git a/apps/maple-agent/app/src/desktop.rs b/apps/maple-agent/app/src/desktop.rs index e01349fdc..8bc1342bf 100644 --- a/apps/maple-agent/app/src/desktop.rs +++ b/apps/maple-agent/app/src/desktop.rs @@ -2458,7 +2458,6 @@ impl Render for MapleApp { }), "maple-screen", screen_kind, - gpui::rgb(ui::theme::bg_app()), )); #[cfg(target_os = "linux")] let root = root.children(self.restart_confirmation.clone()); @@ -5411,7 +5410,7 @@ mod tests { cx.run_until_parked(); // Let the screen fade and anything the sidebar eases settle. for step in 1..=4 { - ui::motion::set_test_now(Some(start + ui::motion::PANEL * step)); + ui::motion::set_test_now(Some(start + ui::motion::PANEL.settle * step)); cx.update(|window, cx| { window.simulate_next_frame(cx); }); diff --git a/apps/maple-agent/app/src/ui/chat/composer.rs b/apps/maple-agent/app/src/ui/chat/composer.rs index 5cddd0ad4..631b7bee5 100644 --- a/apps/maple-agent/app/src/ui/chat/composer.rs +++ b/apps/maple-agent/app/src/ui/chat/composer.rs @@ -1308,7 +1308,7 @@ impl ChatScreen { self.controls_revealed = Some((std::time::Instant::now(), generation)); } let row = match self.controls_revealed { - Some((at, generation)) if at.elapsed() < motion::REVEAL * 2 => { + Some((at, generation)) if at.elapsed() < motion::REVEAL.duration * 2 => { motion::fade_in(row, ("composer-controls-reveal", generation as usize)) .into_any_element() } @@ -1520,13 +1520,7 @@ impl ChatScreen { let now = motion::now(); let reduced = cx.reduce_motion(); let step = |tween: &mut motion::Tween, on: bool| { - tween.step( - if on { 1. } else { 0. }, - motion::TOGGLE, - motion::ease_out_cubic, - now, - reduced, - ) + tween.step(if on { 1. } else { 0. }, motion::TOGGLE, now, reduced) }; let (stop, stop_moving) = step(&mut self.send_stop, show_stop); let (ready, ready_moving) = step(&mut self.send_ready, can_send); @@ -2329,10 +2323,10 @@ mod resize_tests { rest, "starts from the height on screen" ); - frame_at(start + motion::PANEL - Duration::from_millis(1), cx); + frame_at(start + motion::PANEL.settle - Duration::from_millis(1), cx); let landing = composer_height(cx); assert_eq!(tail_gap(cx), pinned, "the transcript keeps its tail"); - frame_at(start + motion::PANEL, cx); + frame_at(start + motion::PANEL.settle, cx); let expanded = composer_height(cx); assert!(expanded > rest * 2., "expanded: {expanded:?}"); assert!( @@ -2342,10 +2336,10 @@ mod resize_tests { assert_eq!(tail_gap(cx), pinned, "the transcript keeps its tail"); // Shrink, then expand again halfway down. - let shrink = start + motion::PANEL * 2; + let shrink = start + motion::PANEL.settle * 2; motion::set_test_now(Some(shrink)); toggle(&chat, cx); - frame_at(shrink + motion::PANEL / 2, cx); + frame_at(shrink + motion::PANEL.settle / 2, cx); let partway = composer_height(cx); assert!(partway > rest && partway < expanded, "partway: {partway:?}"); assert_eq!(tail_gap(cx), pinned, "the tail stays put mid-flight"); @@ -2355,9 +2349,12 @@ mod resize_tests { partway, "a reversal starts where it is" ); - frame_at(shrink + motion::PANEL / 2 + Duration::from_millis(30), cx); + frame_at( + shrink + motion::PANEL.settle / 2 + Duration::from_millis(30), + cx, + ); assert!(composer_height(cx) > partway, "heading back up"); - frame_at(shrink + motion::PANEL * 2, cx); + frame_at(shrink + motion::PANEL.settle * 2, cx); assert_eq!(composer_height(cx), expanded); assert!(chat.read_with(cx, |chat, _| chat.composer_resize.is_none())); @@ -2383,12 +2380,12 @@ mod resize_tests { Some(rest), "the heading and the note are still there on the first frame" ); - frame_at(start + motion::PANEL / 2, cx); + frame_at(start + motion::PANEL.settle / 2, cx); let partway = composer_height(cx); assert!(partway > rest.size.height, "partway: {partway:?}"); - frame_at(start + motion::PANEL - Duration::from_millis(1), cx); + frame_at(start + motion::PANEL.settle - Duration::from_millis(1), cx); let landing = cx.debug_bounds("composer-box").expect("composer"); - frame_at(start + motion::PANEL, cx); + frame_at(start + motion::PANEL.settle, cx); let expanded = cx.debug_bounds("composer-box").expect("composer"); assert!( (expanded.top() - landing.top()).abs() < px(1.), @@ -2399,14 +2396,14 @@ mod resize_tests { "{landing:?} {expanded:?}" ); - let shrink = start + motion::PANEL * 2; + let shrink = start + motion::PANEL.settle * 2; motion::set_test_now(Some(shrink)); toggle(&chat, cx); assert_eq!(cx.debug_bounds("composer-box"), Some(expanded)); // On the way back the heading rides above the composer at its full // size: the folding box never cuts it against the composer's edge. for step in 1..8 { - frame_at(shrink + motion::PANEL * step / 8, cx); + frame_at(shrink + motion::PANEL.settle * step / 8, cx); let composer = cx.debug_bounds("composer-box").expect("composer"); let title = cx .debug_bounds("empty-title") @@ -2416,9 +2413,9 @@ mod resize_tests { "the heading stays clear of the composer: {title:?} {composer:?}" ); } - frame_at(shrink + motion::PANEL - Duration::from_millis(1), cx); + frame_at(shrink + motion::PANEL.settle - Duration::from_millis(1), cx); let landing = cx.debug_bounds("composer-box").expect("composer"); - frame_at(shrink + motion::PANEL, cx); + frame_at(shrink + motion::PANEL.settle, cx); assert!( (rest.top() - landing.top()).abs() < px(1.), "{landing:?} {rest:?}" @@ -2443,14 +2440,14 @@ mod resize_tests { cx.run_until_parked(); let rest = cx.debug_bounds("composer-box").expect("composer"); toggle(&chat, cx); - frame_at(start + motion::PANEL * 2, cx); + frame_at(start + motion::PANEL.settle * 2, cx); let expanded = cx.debug_bounds("composer-box").expect("composer"); assert!( expanded.size.height > rest.size.height, "{rest:?} {expanded:?}" ); - let shrink = start + motion::PANEL * 3; + let shrink = start + motion::PANEL.settle * 3; motion::set_test_now(Some(shrink)); toggle(&chat, cx); assert_eq!( @@ -2460,7 +2457,7 @@ mod resize_tests { ); let mut heights = vec![expanded.size.height]; for step in 1..8 { - frame_at(shrink + motion::PANEL * step / 8, cx); + frame_at(shrink + motion::PANEL.settle * step / 8, cx); heights.push(composer_height(cx)); } assert!( @@ -2471,7 +2468,7 @@ mod resize_tests { heights[1] > rest.size.height, "it eases rather than snapping to rest: {heights:?}" ); - frame_at(shrink + motion::PANEL * 2, cx); + frame_at(shrink + motion::PANEL.settle * 2, cx); assert_eq!( cx.debug_bounds("composer-box"), Some(rest), @@ -2523,12 +2520,12 @@ mod resize_tests { ); let mut last = first.top(); for step in 1..=12 { - frame_at(start + motion::PANEL * step / 12, cx); + frame_at(start + motion::PANEL.settle * step / 12, cx); let top = cx.debug_bounds("composer-box").expect("composer").top(); assert!(top >= last, "only moves down: {last:?} then {top:?}"); last = top; } - frame_at(start + motion::PANEL * 2, cx); + frame_at(start + motion::PANEL.settle * 2, cx); let rest = cx.debug_bounds("composer-box").expect("composer"); assert!(rest.top() > hero.top() + px(100.), "{hero:?} {rest:?}"); assert_eq!(cx.update(|window, app| window.simulate_next_frame(app)), 0); diff --git a/apps/maple-agent/app/src/ui/chat/mod.rs b/apps/maple-agent/app/src/ui/chat/mod.rs index 2f3ff5ca8..fbcba9e91 100644 --- a/apps/maple-agent/app/src/ui/chat/mod.rs +++ b/apps/maple-agent/app/src/ui/chat/mod.rs @@ -1200,25 +1200,18 @@ impl ChatScreen { return; } let now = crate::ui::motion::now(); - let from = self - .sidebar_transition - .as_ref() - .map(|transition| transition.value(now)) - .unwrap_or(if self.sidebar_collapsed { 0. } else { 1. }); + let rest = if self.sidebar_collapsed { 0. } else { 1. }; let to = if collapsed { 0. } else { 1. }; self.sidebar_collapsed = collapsed; - let distance = (to - from).abs(); - self.sidebar_transition = (!cx.reduce_motion() && distance > f32::EPSILON).then(|| { - let mut transition = crate::ui::motion::Tween::new(from); - transition.set( - to, - crate::ui::motion::PANEL.mul_f32(distance), - crate::ui::motion::ease_out_cubic, - now, - false, - ); - transition - }); + // Retarget the transition under way rather than starting another, + // so a second press turns back from where the sidebar is, at the + // speed it has. + let mut transition = self + .sidebar_transition + .take() + .unwrap_or(crate::ui::motion::Tween::new(rest)); + transition.set(to, crate::ui::motion::PANEL, now, cx.reduce_motion()); + self.sidebar_transition = transition.is_moving(now).then_some(transition); if self.popup.is_open(&ChatPopup::Settings) { self.popup.close(cx); } @@ -4309,30 +4302,21 @@ impl ChatScreen { fn toggle_composer_expanded(&mut self, cx: &mut Context) { let now = motion::now(); - let from = self - .composer_resize - .map(|transition| transition.value(now)) - .unwrap_or(if self.composer_expanded { 1. } else { 0. }); + let rest = if self.composer_expanded { 1. } else { 0. }; self.composer_expanded = !self.composer_expanded; let expanded = self.composer_expanded; let to = if expanded { 1. } else { 0. }; - let distance = (to - from).abs(); - // Eases between heights measured on screen, so it needs a frame - // drawn first; reduced motion switches at once. + // Moves between heights measured on screen, so it needs a frame + // drawn first; reduced motion switches at once. A transition under + // way is retargeted, so it turns back at the speed it has. let frame = self.composer_frame.get(); let measured = frame.region.is_some() && frame.room.is_some(); - self.composer_resize = - (!cx.reduce_motion() && measured && distance > f32::EPSILON).then(|| { - let mut transition = motion::Tween::new(from); - transition.set( - to, - motion::PANEL.mul_f32(distance), - motion::ease_out_cubic, - now, - false, - ); - transition - }); + let mut transition = self + .composer_resize + .take() + .unwrap_or(motion::Tween::new(rest)); + transition.set(to, motion::PANEL, now, cx.reduce_motion() || !measured); + self.composer_resize = transition.is_moving(now).then_some(transition); // The field fills the box while it moves, so typed text stays put // and the box's text height can be read off the field. let fill = self.composer_fills(); @@ -7822,7 +7806,6 @@ impl ChatScreen { "settings-menu-chevron", if open { 1. } else { 0. }, motion::TOGGLE, - motion::ease_out_cubic, |open| { // Points up at the menu above while closed, and // turns down once it is open. diff --git a/apps/maple-agent/app/src/ui/chat/sidebar.rs b/apps/maple-agent/app/src/ui/chat/sidebar.rs index ba523c648..10c6cdd44 100644 --- a/apps/maple-agent/app/src/ui/chat/sidebar.rs +++ b/apps/maple-agent/app/src/ui/chat/sidebar.rs @@ -4608,7 +4608,6 @@ fn activity_indicator(spinner_id: &SharedString, activity: SessionActivity) -> A name, if activity == state { 1. } else { 0. }, motion::TOGGLE, - motion::ease_out_cubic, move |shown| { if shown <= 0. { return div().into_any_element(); @@ -5037,7 +5036,7 @@ mod tests { cx.run_until_parked(); assert!(frames(cx) > 0, "the new status fades in"); cx.run_until_parked(); - motion::set_test_now(Some(start + motion::TOGGLE)); + motion::set_test_now(Some(start + motion::TOGGLE.settle)); frames(cx); cx.run_until_parked(); assert_eq!(frames(cx), 0, "settled, the cached sidebar goes idle"); diff --git a/apps/maple-agent/app/src/ui/chat/transcript.rs b/apps/maple-agent/app/src/ui/chat/transcript.rs index 89b4fd7ad..8529802a8 100644 --- a/apps/maple-agent/app/src/ui/chat/transcript.rs +++ b/apps/maple-agent/app/src/ui/chat/transcript.rs @@ -420,14 +420,14 @@ impl ChatScreen { } else if appeared { // A send opens it; a task switch or history load shows it at // once. - slot.slot_open = (!snap).then(|| motion::Tween::new(0.)); + slot.slot_open = (!snap).then(|| motion::Tween::pixels(0.)); slot.slot_since = Some(now); } let cap = match (&mut slot.slot_open, natural) { (None, None) => None, (None, Some(natural)) => { if !reduced { - slot.slot_open = Some(motion::Tween::new(natural)); + slot.slot_open = Some(motion::Tween::pixels(natural)); } None } @@ -441,19 +441,13 @@ impl ChatScreen { // The first opening runs from when the slot appeared, not // from the frame its content was first measured. if natural < open.value(now) { - *open = motion::Tween::new(natural); + *open = motion::Tween::pixels(natural); } let start = match slot.slot_since.take() { Some(since) if open.target() == 0. => since, _ => now, }; - open.set( - natural, - motion::ENTER, - motion::ease_out_cubic, - start, - reduced, - ); + open.set(natural, motion::ENTER, start, reduced); if open.is_moving(now) { window.request_animation_frame(); } @@ -721,12 +715,15 @@ impl RowMotion { } let running = |at: &Instant, duration| now.saturating_duration_since(*at) < duration; self.arrived - .retain(|_, arrival| running(&arrival.at, motion::ENTER)); + .retain(|_, arrival| running(&arrival.at, motion::ENTER.duration)); self.heights .borrow_mut() .retain(|id, _| self.arrived.contains_key(id)); - self.disclosed.retain(|_, at| running(at, motion::REVEAL)); - self.switched = self.switched.filter(|at| running(at, motion::REVEAL)); + self.disclosed + .retain(|_, at| running(at, motion::REVEAL.duration)); + self.switched = self + .switched + .filter(|at| running(at, motion::REVEAL.duration)); !self.arrived.is_empty() || !self.disclosed.is_empty() || self.switched.is_some() } } @@ -1246,7 +1243,6 @@ fn tool_status(item_id: &str, running: bool, label: SharedString, color: u32) -> SharedString::from(format!("tool-status-{item_id}")), if running { 0. } else { 1. }, motion::TOGGLE, - motion::ease_out_cubic, move |done| { div() .flex() @@ -2819,7 +2815,7 @@ mod motion_tests { ) -> Vec> { let mut tops = vec![Vec::new(); selectors.len()]; let mut at = Duration::ZERO; - while at <= motion::ENTER + Duration::from_millis(16) { + while at <= motion::ENTER.settle + Duration::from_millis(16) { clock.at(start + at); redraw(chat, cx); for (selector, tops) in selectors.iter().zip(&mut tops) { @@ -2858,7 +2854,7 @@ mod motion_tests { redraw(&chat, cx); let entering = bounds(cx, "timeline-row-live"); - let midway = clock.at(motion::ENTER / 2); + let midway = clock.at(motion::ENTER.settle / 2); let progress = chat.update(cx, |chat, _| chat.row_motion.arrival("live", midway, false)); assert!( progress > 0. && progress < 1., @@ -2866,7 +2862,7 @@ mod motion_tests { ); assert!(in_flight(&chat, midway, cx), "frames continue mid-entrance"); - let done = clock.at(motion::ENTER); + let done = clock.at(motion::ENTER.settle); redraw(&chat, cx); let settled = bounds(cx, "timeline-row-live"); assert_eq!(entering.size, settled.size, "the rise never changes layout"); @@ -2914,7 +2910,7 @@ mod motion_tests { "older rows only rise: {tops:?}" ); assert_glides(&tops, "an older row"); - assert!(!in_flight(&chat, clock.at(motion::ENTER), cx)); + assert!(!in_flight(&chat, clock.at(motion::ENTER.settle), cx)); // The settled layout is the one without motion. let older = bounds(cx, "timeline-row-h29"); @@ -2936,7 +2932,7 @@ mod motion_tests { chat.apply_incoming_item("s1", item("reply", "message", Some("Answer:")), cx); }); redraw(&chat, cx); - clock.at(motion::ENTER / 3); + clock.at(motion::ENTER.settle / 3); redraw(&chat, cx); chat.update(cx, |chat, cx| { chat.apply_incoming_item( @@ -2949,7 +2945,11 @@ mod motion_tests { cx, ); }); - for step in [motion::ENTER / 2, motion::ENTER * 3 / 4, motion::ENTER] { + for step in [ + motion::ENTER.settle / 2, + motion::ENTER.settle * 3 / 4, + motion::ENTER.settle, + ] { clock.at(step); redraw(&chat, cx); } @@ -2976,7 +2976,7 @@ mod motion_tests { redraw(&chat, cx); let entering = bounds(cx, "pending-send-body"); let status = bounds(cx, "pending-send-status"); - clock.at(motion::ENTER); + clock.at(motion::ENTER.settle); redraw(&chat, cx); let settled = bounds(cx, "pending-send-body"); assert_eq!(entering.origin.y - settled.origin.y, motion::RISE); @@ -3053,7 +3053,7 @@ mod motion_tests { chat.read_with(cx, |chat, _| chat.row_motion.slot_shown.get()) }; let sent = shown(&chat, cx); - clock.at(motion::ENTER * 2); + clock.at(motion::ENTER.settle * 2); redraw(&chat, cx); let open = shown(&chat, cx); assert!(open > px(0.), "the slot shows its status"); @@ -3073,7 +3073,7 @@ mod motion_tests { ) -> (Pixels, Vec) { // The slot appears, then opens over ENTER. redraw(chat, cx); - let start = motion::ENTER * 2; + let start = motion::ENTER.settle * 2; clock.at(start); redraw(chat, cx); assert!( @@ -3186,7 +3186,7 @@ mod motion_tests { chat.sending_previews.insert("send-1".into(), preview); }); redraw(&chat, cx); - let start = motion::ENTER * 2; + let start = motion::ENTER.settle * 2; clock.at(start); redraw(&chat, cx); let bubble = bounds(cx, "pending-send-body"); @@ -3311,11 +3311,11 @@ mod motion_tests { }; chat.update(cx, |chat, cx| { chat.apply_incoming_item("s1", item("reply", "message", Some("Hi")), cx); - let midway = clock.at(motion::ENTER / 2); + let midway = clock.at(motion::ENTER.settle / 2); let before = chat.row_motion.arrival("reply", midway, false); chat.apply_incoming_item("s1", chunk(), cx); assert_eq!(chat.row_motion.arrival("reply", midway, false), before); - let done = clock.at(motion::ENTER); + let done = clock.at(motion::ENTER.settle); assert!(!chat.row_motion.settle(done, false)); chat.apply_incoming_item("s1", chunk(), cx); assert_eq!(chat.timeline[0].text.as_deref(), Some("Hi more more")); diff --git a/apps/maple-agent/app/src/ui/motion.rs b/apps/maple-agent/app/src/ui/motion.rs index bac31d401..ce4f1d90f 100644 --- a/apps/maple-agent/app/src/ui/motion.rs +++ b/apps/maple-agent/app/src/ui/motion.rs @@ -27,32 +27,112 @@ use std::time::{Duration, Instant}; use gpui::{ AnimationElement, AnimationExt, AnyElement, App, Bounds, Element, ElementId, EntityId, GlobalElementId, InspectorElementId, IntoElement, LayoutId, ParentElement, Pixels, Point, - Styled, Window, px, + SpringConfig, SpringState, Styled, Window, px, }; /// Frames per second a looping effect asks for. Twelve to fifteen steps a /// second still read as motion at a fraction of the display rate. pub const LOOP_FPS: u32 = 15; -/// Pointer hover: background and opacity only, the same both ways. -pub const HOVER: Duration = Duration::from_millis(120); +/// One kind of motion. Everything of that kind takes its timing from the +/// token, so editing a token here retunes every animation that uses it. +/// +/// A token carries two timings because the app moves in two ways. A +/// one-shot entrance (a row arriving, a menu opening) runs `duration` on +/// `easing` and nothing interrupts it. A reversible value (a hover plate, a +/// switch, the composer's height) is a spring that takes `settle` to come +/// to rest from a standstill; it keeps its speed when its target changes, so +/// turning back mid-way has no corner in it. +#[derive(Clone, Copy, Debug)] +pub struct Token { + /// How long a one-shot entrance of this kind takes. + pub duration: Duration, + /// The curve a one-shot entrance of this kind follows. + pub easing: fn(f32) -> f32, + /// How long a reversible value of this kind takes to settle from rest. + pub settle: Duration, +} + +/// Pointer hover: background and opacity only. +pub const HOVER: Token = Token { + duration: Duration::from_millis(120), + easing: smoothstep, + settle: Duration::from_millis(180), +}; /// Menus, popovers, tooltips, notices, and content that replaces other /// content (a Settings section, another task). -pub const REVEAL: Duration = Duration::from_millis(140); +pub const REVEAL: Token = Token { + duration: Duration::from_millis(140), + easing: ease_out_quint, + settle: Duration::from_millis(210), +}; /// A control changing state in place: switches, chevrons, icon swaps. -pub const TOGGLE: Duration = Duration::from_millis(150); +pub const TOGGLE: Token = Token { + duration: Duration::from_millis(150), + easing: ease_out_cubic, + settle: Duration::from_millis(230), +}; /// Content arriving: live transcript rows, cards, dialogs. -pub const ENTER: Duration = Duration::from_millis(180); +pub const ENTER: Token = Token { + duration: Duration::from_millis(180), + easing: ease_out_quint, + settle: Duration::from_millis(270), +}; /// Panels changing size: the sidebar and the expanded composer. -pub const PANEL: Duration = Duration::from_millis(200); +pub const PANEL: Token = Token { + duration: Duration::from_millis(200), + easing: ease_out_cubic, + settle: Duration::from_millis(320), +}; + +/// How every spring is damped. At 1 a spring is the fastest that does not +/// overshoot from rest; below 1 it overshoots and comes back, above 1 it +/// settles more slowly. +pub const DAMPING_RATIO: f32 = 1.; + /// How far arriving content travels before it settles. pub const RISE: Pixels = px(6.); +/// How close a value in `[0, 1]` comes to its target before it counts as +/// arrived, and the travel a token's `settle` is measured over. +const TOLERANCE: f32 = 0.001; + +impl Token { + /// The same kind of motion, slower or faster by `factor`. + pub fn scaled(self, factor: f32) -> Self { + Self { + duration: self.duration.mul_f32(factor), + easing: self.easing, + settle: self.settle.mul_f32(factor), + } + } + + /// A one-shot gpui animation of this kind. + pub fn animation(self) -> gpui::Animation { + gpui::Animation::new(self.duration).with_easing(self.easing) + } + + /// The spring that settles from rest in `settle`. + fn spring(self) -> SpringConfig { + // A spring's settling time scales with one over its natural + // frequency, so the time a unit-frequency spring takes gives the + // frequency that lands on `settle`. + static UNIT_SETTLE: OnceLock = OnceLock::new(); + let unit = *UNIT_SETTLE.get_or_init(|| { + SpringConfig::new(1., 2. * DAMPING_RATIO, 1.) + .settle_time(SpringState::default(), 1., TOLERANCE) + .as_secs_f32() + }); + let frequency = unit / self.settle.as_secs_f32().max(f32::EPSILON); + SpringConfig::new(frequency * frequency, 2. * DAMPING_RATIO * frequency, 1.) + } +} + /// Time for a box to grow or shrink by `distance`: about 500 px a second, -/// so one line of text takes the shortest time and a large jump [`PANEL`]. -pub fn resize_duration(distance: Pixels) -> Duration { - let millis = (distance.as_f32().abs() * 2.).clamp(120., PANEL.as_millis() as f32); - Duration::from_millis(millis as u64) +/// so one line of text takes the shortest time and a large jump [`PANEL`]'s. +pub fn resize(distance: Pixels) -> Token { + let millis = (distance.as_f32().abs() * 2.).clamp(120., PANEL.duration.as_millis() as f32); + PANEL.scaled(millis / PANEL.duration.as_millis() as f32) } /// Entrances and fades: a fast start and a long settle. @@ -71,6 +151,39 @@ pub fn smoothstep(t: f32) -> f32 { t * t * (3. - 2. * t) } +/// How reversible values move. Springs are what ships; `MAPLE_MOTION=eased` +/// runs each token's `duration` and `easing` instead, restarting the curve +/// from the value on screen, to compare the two in one build. +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +pub enum Style { + Spring, + Eased, +} + +#[cfg(test)] +thread_local! { + static TEST_STYLE: std::cell::Cell> = const { std::cell::Cell::new(None) }; +} + +/// The style reversible values move in. +pub fn style() -> Style { + #[cfg(test)] + if let Some(style) = TEST_STYLE.with(std::cell::Cell::get) { + return style; + } + static STYLE: OnceLock