pub const TEXT_SIZE: f32 = 12.5;
pub const SMALL_TEXT_SIZE: f32 = 11.5;
pub const TITLE_TEXT_SIZE: f32 = 14.0;
pub fn ui_font() -> &'static str {
if cfg!(target_os = "macos") {
".SystemUIFont"
} else if cfg!(target_os = "windows") {
"Segoe UI"
} else {
"sans-serif"
}
}
pub fn text_width(cx: &gpui::App, text: &str, size: f32, weight: gpui::FontWeight) -> f32 {
let system = cx.text_system();
let mut font = gpui::font(ui_font());
font.weight = weight;
let font = system.resolve_font(&font);
let pixels = gpui::px(size);
text.chars()
.map(|ch| {
system
.advance(font, pixels, ch)
.map_or(size * 0.6, |advance| f32::from(advance.width))
})
.sum()
}