Files
zed/crates/ui/src/utils.rs
T
Kirill Bulatov 8a54abc4b9 Improve outline fonts and colors (#63325)
Closes https://github.com/zed-industries/zed/issues/58580

* Outline modal and panel now use buffer fonts for the contents:

<img width="1728" height="1117" alt="modal"
src="https://github.com/user-attachments/assets/5e0ef6e3-be39-4949-bc32-7087a51a02ec"
/>
<img width="1728" height="1092" alt="panel"
src="https://github.com/user-attachments/assets/5cf9edbf-5ff3-402d-a2ca-bc915bd10e8e"
/>

* Gutter colors are now fall-backed to tree-sitter better, if no
semantic tokens could be retrieved due to multi buffer shenanigans:

<img width="1728" height="426" alt="gutter"
src="https://github.com/user-attachments/assets/a175b2c8-843e-4632-b030-3edfbd350982"
/>

Release Notes:

- Improved outline fonts and colors
2026-08-28 03:28:04 +00:00

76 lines
2.1 KiB
Rust

//! UI-related utilities
use gpui::App;
use theme::ActiveTheme;
mod apca_contrast;
mod color_contrast;
mod constants;
mod control_characters;
mod corner_solver;
mod format_distance;
mod search_input;
mod with_rem_size;
pub use apca_contrast::*;
pub use color_contrast::*;
pub use constants::*;
pub use control_characters::*;
pub use corner_solver::{CornerSolver, inner_corner_radius};
pub use format_distance::*;
pub use search_input::*;
pub use with_rem_size::*;
/// Returns true if the current theme is light or vibrant light.
pub fn is_light(cx: &mut App) -> bool {
cx.theme().appearance.is_light()
}
pub fn buffer_text_style(cx: &App) -> gpui::TextStyle {
let settings = theme::theme_settings(cx);
let buffer_font = settings.buffer_font(cx);
gpui::TextStyle {
color: cx.theme().colors().text,
font_family: buffer_font.family.clone(),
font_features: buffer_font.features.clone(),
font_fallbacks: buffer_font.fallbacks.clone(),
font_size: gpui::AbsoluteLength::from(settings.buffer_font_size(cx)),
font_weight: buffer_font.weight,
line_height: gpui::relative(1.),
..gpui::TextStyle::default()
}
}
/// Returns the platform-appropriate label for the "reveal in file manager" action.
pub fn reveal_in_file_manager_label(is_remote: bool) -> &'static str {
if cfg!(target_os = "macos") && !is_remote {
"Reveal in Finder"
} else if cfg!(target_os = "windows") && !is_remote {
"Reveal in File Explorer"
} else {
"Reveal in File Manager"
}
}
/// Capitalizes the first character of a string.
///
/// This function takes a string slice as input and returns a new `String` with the first character
/// capitalized.
///
/// # Examples
///
/// ```
/// use ui::utils::capitalize;
///
/// assert_eq!(capitalize("hello"), "Hello");
/// assert_eq!(capitalize("WORLD"), "WORLD");
/// assert_eq!(capitalize(""), "");
/// ```
pub fn capitalize(str: &str) -> String {
let mut chars = str.chars();
match chars.next() {
None => String::new(),
Some(first_char) => first_char.to_uppercase().collect::<String>() + chars.as_str(),
}
}