add theme titlebar height and app-owned strip dragging
This commit is contained in:
@@ -4,6 +4,10 @@ use crate::system::SystemTheme;
|
||||
use crate::{ColorTokens, Elevations, Motion, Radius, Scrollbar, SizeTable, ThemeVariant};
|
||||
use gpui::px;
|
||||
|
||||
/// The floor of a custom titlebar's height, in px at 100% scaling: the height
|
||||
/// macOS and Linux titlebars draw at regardless of the control scale.
|
||||
const TITLEBAR_HEIGHT_MIN_PX: f32 = 34.0;
|
||||
|
||||
/// Derived state shades for the colors that get pressed and hovered.
|
||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||
pub struct Ramps {
|
||||
@@ -25,6 +29,8 @@ pub struct ResolvedTheme {
|
||||
pub elevations: Elevations,
|
||||
pub motion: Motion,
|
||||
pub scrollbar: Scrollbar,
|
||||
/// The height the window's titlebar strips draw at, per the platform.
|
||||
pub titlebar_height: gpui::Pixels,
|
||||
/// The platform's native root font size; the fallback theme uses 16.
|
||||
pub root_font_size: gpui::Pixels,
|
||||
pub sizes: SizeTable,
|
||||
@@ -196,6 +202,11 @@ pub(crate) fn resolve(
|
||||
sizes.set_input_height(input_height);
|
||||
}
|
||||
|
||||
// A platform that states its titlebar height wins.
|
||||
let titlebar_height = system
|
||||
.titlebar_height
|
||||
.unwrap_or_else(|| sizes.medium.control_height.max(px(TITLEBAR_HEIGHT_MIN_PX)));
|
||||
|
||||
let mut radius = Radius::default();
|
||||
if let Some(control) = preset
|
||||
.and_then(|def| def.control_radius)
|
||||
@@ -228,6 +239,7 @@ pub(crate) fn resolve(
|
||||
elevations: Elevations::for_platform(system.source, variant),
|
||||
motion: Motion::default(),
|
||||
scrollbar: Scrollbar::default(),
|
||||
titlebar_height,
|
||||
root_font_size,
|
||||
sizes,
|
||||
accessibility,
|
||||
@@ -255,6 +267,7 @@ mod tests {
|
||||
palette,
|
||||
control_radius: None,
|
||||
input_height: None,
|
||||
titlebar_height: None,
|
||||
root_font_size: None,
|
||||
accessibility: AccessibilityPreferences::default(),
|
||||
source: SourceKind::Macos,
|
||||
@@ -303,9 +316,17 @@ mod tests {
|
||||
assert_eq!(resolved.sizes.medium.dense_padding_x, px(16. * 0.75));
|
||||
assert_eq!(resolved.sizes.medium.plate_inset, px(4.));
|
||||
assert_eq!(resolved.sizes.medium.strip_height, px(32.));
|
||||
assert_eq!(resolved.titlebar_height, px(34.));
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_stated_titlebar_height_wins_over_the_control_scale() {
|
||||
let mut stated = system(ThemeVariant::Dark, PartialPalette::default(), None);
|
||||
stated.titlebar_height = Some(px(32.));
|
||||
assert_eq!(resolve(&stated, None, None).titlebar_height, px(32.));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_stated_root_font_size_scales_the_size_table() {
|
||||
// macOS states 13pt; the medium control shrinks to native proportions.
|
||||
|
||||
Reference in New Issue
Block a user