scrollbar: Adjust scrollbar style and add scrollbar_thumb_hover to theme. (#482)

<img width="297" alt="image"
src="https://github.com/user-attachments/assets/1779bf6c-2d01-4a12-9052-2ba571bff68b">

<img width="301" alt="image"
src="https://github.com/user-attachments/assets/9971b248-9a48-47ff-847c-00eafff17fe1">
This commit is contained in:
Jason Lee 2024-12-10 17:08:09 +08:00 committed by GitHub
parent 2836540260
commit 9f0f05af2d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 153 additions and 42 deletions

159
Cargo.lock generated
View file

@ -139,9 +139,9 @@ dependencies = [
[[package]]
name = "ashpd"
version = "0.9.2"
version = "0.10.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4d43c03d9e36dd40cab48435be0b09646da362c278223ca535493877b2c1dee9"
checksum = "e9c39d707614dbcc6bed00015539f488d8e3fe3e66ed60961efc0c90f4b380b3"
dependencies = [
"async-fs 2.1.2",
"async-net 2.0.0",
@ -152,7 +152,7 @@ dependencies = [
"serde",
"serde_repr",
"url",
"zbus",
"zbus 5.1.1",
]
[[package]]
@ -474,7 +474,7 @@ dependencies = [
"bitflags 2.6.0",
"cexpr",
"clang-sys",
"itertools 0.13.0",
"itertools 0.11.0",
"log",
"prettyplease",
"proc-macro2",
@ -950,7 +950,7 @@ dependencies = [
[[package]]
name = "collections"
version = "0.1.0"
source = "git+https://github.com/huacnlee/zed.git?branch=export-platform-window#54853c7ea3142578a9666c6723c09e92670aec71"
source = "git+https://github.com/huacnlee/zed.git?branch=export-platform-window#3612f36f8ade77ec19f22d0122edb653c8492a1b"
dependencies = [
"rustc-hash",
]
@ -1313,7 +1313,7 @@ dependencies = [
[[package]]
name = "derive_refineable"
version = "0.1.0"
source = "git+https://github.com/huacnlee/zed.git?branch=export-platform-window#54853c7ea3142578a9666c6723c09e92670aec71"
source = "git+https://github.com/huacnlee/zed.git?branch=export-platform-window#3612f36f8ade77ec19f22d0122edb653c8492a1b"
dependencies = [
"proc-macro2",
"quote",
@ -1458,9 +1458,9 @@ checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0"
[[package]]
name = "embed-resource"
version = "2.5.0"
version = "3.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f4e24052d7be71f0efb50c201557f6fe7d237cfd5a64fd5bcd7fd8fe32dbbffa"
checksum = "4762ce03154ba57ebaeee60cc631901ceae4f18219cbb874e464347471594742"
dependencies = [
"cc",
"memchr",
@ -2266,7 +2266,7 @@ dependencies = [
[[package]]
name = "gpui"
version = "0.1.0"
source = "git+https://github.com/huacnlee/zed.git?branch=export-platform-window#54853c7ea3142578a9666c6723c09e92670aec71"
source = "git+https://github.com/huacnlee/zed.git?branch=export-platform-window#3612f36f8ade77ec19f22d0122edb653c8492a1b"
dependencies = [
"anyhow",
"as-raw-xcb-connection",
@ -2366,7 +2366,7 @@ dependencies = [
[[package]]
name = "gpui_macros"
version = "0.1.0"
source = "git+https://github.com/huacnlee/zed.git?branch=export-platform-window#54853c7ea3142578a9666c6723c09e92670aec71"
source = "git+https://github.com/huacnlee/zed.git?branch=export-platform-window#3612f36f8ade77ec19f22d0122edb653c8492a1b"
dependencies = [
"proc-macro2",
"quote",
@ -2556,7 +2556,7 @@ dependencies = [
[[package]]
name = "http_client"
version = "0.1.0"
source = "git+https://github.com/huacnlee/zed.git?branch=export-platform-window#54853c7ea3142578a9666c6723c09e92670aec71"
source = "git+https://github.com/huacnlee/zed.git?branch=export-platform-window#3612f36f8ade77ec19f22d0122edb653c8492a1b"
dependencies = [
"anyhow",
"bytes",
@ -3072,11 +3072,12 @@ dependencies = [
[[package]]
name = "media"
version = "0.1.0"
source = "git+https://github.com/huacnlee/zed.git?branch=export-platform-window#54853c7ea3142578a9666c6723c09e92670aec71"
source = "git+https://github.com/huacnlee/zed.git?branch=export-platform-window#3612f36f8ade77ec19f22d0122edb653c8492a1b"
dependencies = [
"anyhow",
"bindgen",
"core-foundation 0.9.4",
"ctor",
"foreign-types",
"metal",
"objc",
@ -3380,7 +3381,7 @@ version = "0.7.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "af1844ef2428cc3e1cb900be36181049ef3d3193c63e43026cfe202983b27a56"
dependencies = [
"proc-macro-crate 3.2.0",
"proc-macro-crate 1.3.1",
"proc-macro2",
"quote",
"syn 2.0.86",
@ -3647,9 +3648,9 @@ dependencies = [
"serde",
"sha2",
"subtle",
"zbus",
"zbus 4.4.0",
"zeroize",
"zvariant",
"zvariant 4.2.0",
]
[[package]]
@ -4351,7 +4352,7 @@ dependencies = [
[[package]]
name = "refineable"
version = "0.1.0"
source = "git+https://github.com/huacnlee/zed.git?branch=export-platform-window#54853c7ea3142578a9666c6723c09e92670aec71"
source = "git+https://github.com/huacnlee/zed.git?branch=export-platform-window#3612f36f8ade77ec19f22d0122edb653c8492a1b"
dependencies = [
"derive_refineable",
]
@ -4672,7 +4673,7 @@ checksum = "d369a96f978623eb3dc28807c4852d6cc617fed53da5d3c400feff1ef34a714a"
[[package]]
name = "semantic_version"
version = "0.1.0"
source = "git+https://github.com/huacnlee/zed.git?branch=export-platform-window#54853c7ea3142578a9666c6723c09e92670aec71"
source = "git+https://github.com/huacnlee/zed.git?branch=export-platform-window#3612f36f8ade77ec19f22d0122edb653c8492a1b"
dependencies = [
"anyhow",
"serde",
@ -5091,7 +5092,7 @@ checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292"
[[package]]
name = "sum_tree"
version = "0.1.0"
source = "git+https://github.com/huacnlee/zed.git?branch=export-platform-window#54853c7ea3142578a9666c6723c09e92670aec71"
source = "git+https://github.com/huacnlee/zed.git?branch=export-platform-window#3612f36f8ade77ec19f22d0122edb653c8492a1b"
dependencies = [
"arrayvec",
"log",
@ -5756,12 +5757,13 @@ checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9"
[[package]]
name = "util"
version = "0.1.0"
source = "git+https://github.com/huacnlee/zed.git?branch=export-platform-window#54853c7ea3142578a9666c6723c09e92670aec71"
source = "git+https://github.com/huacnlee/zed.git?branch=export-platform-window#3612f36f8ade77ec19f22d0122edb653c8492a1b"
dependencies = [
"anyhow",
"async-fs 1.6.0",
"collections",
"dirs 4.0.0",
"dunce",
"futures",
"futures-lite 1.13.0",
"globset",
@ -6705,9 +6707,45 @@ dependencies = [
"uds_windows",
"windows-sys 0.52.0",
"xdg-home",
"zbus_macros",
"zbus_names",
"zvariant",
"zbus_macros 4.4.0",
"zbus_names 3.0.0",
"zvariant 4.2.0",
]
[[package]]
name = "zbus"
version = "5.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1162094dc63b1629fcc44150bcceeaa80798cd28bcbe7fa987b65a034c258608"
dependencies = [
"async-broadcast",
"async-executor",
"async-fs 2.1.2",
"async-io 2.3.4",
"async-lock 3.4.0",
"async-process 2.3.0",
"async-recursion",
"async-task",
"async-trait",
"blocking",
"enumflags2",
"event-listener 5.3.1",
"futures-core",
"futures-util",
"hex",
"nix",
"ordered-stream",
"serde",
"serde_repr",
"static_assertions",
"tracing",
"uds_windows",
"windows-sys 0.59.0",
"winnow 0.6.20",
"xdg-home",
"zbus_macros 5.1.1",
"zbus_names 4.1.0",
"zvariant 5.1.0",
]
[[package]]
@ -6720,7 +6758,22 @@ dependencies = [
"proc-macro2",
"quote",
"syn 2.0.86",
"zvariant_utils",
"zvariant_utils 2.1.0",
]
[[package]]
name = "zbus_macros"
version = "5.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2cd2dcdce3e2727f7d74b7e33b5a89539b3cc31049562137faf7ae4eb86cd16d"
dependencies = [
"proc-macro-crate 3.2.0",
"proc-macro2",
"quote",
"syn 2.0.86",
"zbus_names 4.1.0",
"zvariant 5.1.0",
"zvariant_utils 3.0.2",
]
[[package]]
@ -6731,7 +6784,19 @@ checksum = "4b9b1fef7d021261cc16cba64c351d291b715febe0fa10dc3a443ac5a5022e6c"
dependencies = [
"serde",
"static_assertions",
"zvariant",
"zvariant 4.2.0",
]
[[package]]
name = "zbus_names"
version = "4.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "856b7a38811f71846fd47856ceee8bccaec8399ff53fb370247e66081ace647b"
dependencies = [
"serde",
"static_assertions",
"winnow 0.6.20",
"zvariant 5.1.0",
]
[[package]]
@ -6810,13 +6875,28 @@ name = "zvariant"
version = "4.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2084290ab9a1c471c38fc524945837734fbf124487e105daec2bb57fd48c81fe"
dependencies = [
"endi",
"enumflags2",
"serde",
"static_assertions",
"zvariant_derive 4.2.0",
]
[[package]]
name = "zvariant"
version = "5.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a1200ee6ac32f1e5a312e455a949a4794855515d34f9909f4a3e082d14e1a56f"
dependencies = [
"endi",
"enumflags2",
"serde",
"static_assertions",
"url",
"zvariant_derive",
"winnow 0.6.20",
"zvariant_derive 5.1.0",
"zvariant_utils 3.0.2",
]
[[package]]
@ -6829,7 +6909,20 @@ dependencies = [
"proc-macro2",
"quote",
"syn 2.0.86",
"zvariant_utils",
"zvariant_utils 2.1.0",
]
[[package]]
name = "zvariant_derive"
version = "5.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "687e3b97fae6c9104fbbd36c73d27d149abf04fb874e2efbd84838763daa8916"
dependencies = [
"proc-macro-crate 3.2.0",
"proc-macro2",
"quote",
"syn 2.0.86",
"zvariant_utils 3.0.2",
]
[[package]]
@ -6842,3 +6935,17 @@ dependencies = [
"quote",
"syn 2.0.86",
]
[[package]]
name = "zvariant_utils"
version = "3.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "20d1d011a38f12360e5fcccceeff5e2c42a8eb7f27f0dcba97a0862ede05c9c6"
dependencies = [
"proc-macro2",
"quote",
"serde",
"static_assertions",
"syn 2.0.86",
"winnow 0.6.20",
]

View file

@ -27,7 +27,6 @@ const THUMB_RADIUS: Pixels = Pixels(3.0);
const THUMB_INSET: Pixels = Pixels(4.);
const FADE_OUT_DURATION: f32 = 3.0;
const FADE_OUT_DELAY: f32 = 2.0;
const NORMAL_OPACITY: f32 = 0.6;
pub trait ScrollHandleOffsetable {
fn offset(&self) -> Point<Pixels>;
@ -294,9 +293,9 @@ impl Scrollbar {
self
}
fn style_for_default(cx: &AppContext) -> (Hsla, Hsla, Hsla, Pixels, Pixels) {
fn style_for_active(cx: &AppContext) -> (Hsla, Hsla, Hsla, Pixels, Pixels) {
(
cx.theme().scrollbar_thumb,
cx.theme().scrollbar_thumb_hover,
cx.theme().scrollbar,
cx.theme().border,
THUMB_INSET - px(1.),
@ -306,7 +305,7 @@ impl Scrollbar {
fn style_for_hovered_thumb(cx: &AppContext) -> (Hsla, Hsla, Hsla, Pixels, Pixels) {
(
cx.theme().scrollbar_thumb,
cx.theme().scrollbar_thumb_hover,
cx.theme().scrollbar,
cx.theme().border,
THUMB_INSET - px(1.),
@ -322,8 +321,8 @@ impl Scrollbar {
};
(
cx.theme().scrollbar_thumb.opacity(NORMAL_OPACITY),
gpui::transparent_black(),
cx.theme().scrollbar_thumb,
cx.theme().scrollbar,
gpui::transparent_black(),
inset,
radius,
@ -477,7 +476,7 @@ impl Element for Scrollbar {
let (thumb_bg, bar_bg, bar_border, inset, radius) =
if state.get().dragged_axis == Some(axis) {
Self::style_for_default(cx)
Self::style_for_active(cx)
} else if is_hover_to_show && is_hovered_on_bar {
if is_hovered_on_thumb {
Self::style_for_hovered_thumb(cx)
@ -498,13 +497,14 @@ impl Element for Scrollbar {
Self::style_for_hovered_bar(cx)
};
} else {
let y_value = if elapsed < FADE_OUT_DELAY {
NORMAL_OPACITY
if elapsed < FADE_OUT_DELAY {
idle_state.0 = cx.theme().scrollbar_thumb;
} else {
// y = 1 - (x - 2)^10
NORMAL_OPACITY - (elapsed - FADE_OUT_DELAY).powi(10)
// opacity = 1 - (x - 2)^10
let opacity = 1.0 - (elapsed - FADE_OUT_DELAY).powi(10);
idle_state.0 = cx.theme().scrollbar_thumb.opacity(opacity);
};
idle_state.0 = cx.theme().scrollbar_thumb.opacity(y_value);
cx.request_animation_frame();
}
}

View file

@ -183,6 +183,7 @@ pub struct ThemeColor {
pub ring: Hsla,
pub scrollbar: Hsla,
pub scrollbar_thumb: Hsla,
pub scrollbar_thumb_hover: Hsla,
pub secondary: Hsla,
pub secondary_active: Hsla,
pub secondary_foreground: Hsla,
@ -255,8 +256,9 @@ impl ThemeColor {
primary_hover: hsl(223.0, 5.9, 15.0),
progress_bar: hsl(223.0, 5.9, 10.0),
ring: hsl(240.0, 5.9, 65.0),
scrollbar: hsl(0., 0., 97.).opacity(0.3),
scrollbar_thumb: hsl(0., 0., 69.),
scrollbar: hsl(0., 0., 97.).opacity(0.75),
scrollbar_thumb: hsl(0., 0., 69.).opacity(0.9),
scrollbar_thumb_hover: hsl(0., 0., 59.),
secondary: hsl(240.0, 5.9, 96.9),
secondary_active: hsl(240.0, 5.9, 93.),
secondary_foreground: hsl(240.0, 59.0, 10.),
@ -329,8 +331,9 @@ impl ThemeColor {
primary_hover: hsl(223.0, 0.0, 90.0),
progress_bar: hsl(223.0, 0.0, 98.0),
ring: hsl(240.0, 4.9, 83.9),
scrollbar: hsl(240., 1., 15.).opacity(0.3),
scrollbar_thumb: hsl(0., 0., 68.),
scrollbar: hsl(240., 1., 15.).opacity(0.75),
scrollbar_thumb: hsl(0., 0., 48.).opacity(0.9),
scrollbar_thumb_hover: hsl(0., 0., 68.),
secondary: hsl(240.0, 0., 13.0),
secondary_active: hsl(240.0, 0., 10.),
secondary_foreground: hsl(0.0, 0.0, 78.0),
@ -438,6 +441,7 @@ impl Theme {
// self.selection = self.selection.apply(mask_color);
self.scrollbar = self.scrollbar.apply(mask_color);
self.scrollbar_thumb = self.scrollbar_thumb.apply(mask_color);
self.scrollbar_thumb_hover = self.scrollbar_thumb_hover.apply(mask_color);
self.panel = self.panel.apply(mask_color);
self.drag_border = self.drag_border.apply(mask_color);
self.drop_target = self.drop_target.apply(mask_color);