use crate::core::{Color, Rect};
use crate::render::RenderContext;
use crate::widget::metrics::{FocusRing, FOCUS_RING_WIDTH};
use crate::widget::BaseWidget;
pub const MAC_SEGMENTED_CONTROL_HEIGHT: u32 = 24;
pub const MAC_SEGMENTED_DEFAULT_WIDTH: u32 = 240;
pub const MAC_SEGMENT_LABEL_INSET: i32 = 10;
pub const MAC_STEPPER_WIDTH: u32 = 19;
pub fn mac_stepper_height() -> u32 {
crate::widget::metrics::profile_metrics(crate::widget::metrics::ControlMetricsProfile::Macos)
.button_min
.height
}
pub const MAC_TOOLBAR_HEIGHT: u32 = 38;
pub const MAC_TOOLBAR_DEFAULT_WIDTH: u32 = 320;
pub const MAC_TOOLBAR_INSET: i32 = 8;
pub const MAC_TOOLBAR_ITEM_PADDING: i32 = 8;
pub const MAC_SOURCE_LIST_ROW_HEIGHT: u32 = 24;
pub const MAC_SOURCE_LIST_SECTION_HEIGHT: u32 = 22;
pub const MAC_SOURCE_LIST_DEFAULT_WIDTH: u32 = 220;
pub const MAC_SOURCE_LIST_DEFAULT_HEIGHT: u32 = 240;
pub const MAC_TITLE_BAR_HEIGHT: u32 = 28;
pub const MAC_TRAFFIC_LIGHT_INSET: i32 = 12;
pub const MAC_TRAFFIC_LIGHT_GAP: i32 = 8;
#[derive(Debug, Clone, Copy, PartialEq)]
pub(crate) struct MacPalette {
pub(crate) surface: Color,
pub(crate) raised: Color,
pub(crate) ink: Color,
pub(crate) accent: Color,
pub(crate) separator: Color,
pub(crate) muted: Color,
pub(crate) close: Color,
pub(crate) minimize: Color,
pub(crate) zoom: Color,
pub(crate) inactive_surface: Color,
pub(crate) inactive_ink: Color,
}
pub(crate) fn palette() -> MacPalette {
let manager = crate::style::theme_manager();
match manager.current_theme() {
Some(theme) => MacPalette {
surface: theme.colors.surface_container,
raised: theme.colors.surface_container_high,
ink: theme.colors.foreground,
accent: theme.colors.primary,
separator: theme.colors.outline,
muted: theme.colors.secondary,
close: theme.colors.error,
minimize: theme.colors.warning,
zoom: theme.colors.success,
inactive_surface: theme.colors.surface_container.blend(&theme.colors.foreground, 0.05),
inactive_ink: theme.colors.foreground.blend(&theme.colors.surface_container, 0.42),
},
None => MacPalette {
surface: Color::rgb(236, 236, 238),
raised: Color::rgb(246, 246, 248),
ink: Color::rgb(29, 29, 31),
accent: Color::rgb(0, 122, 255),
separator: Color::rgb(209, 209, 214),
muted: Color::rgb(142, 142, 147),
close: Color::rgb(255, 95, 87),
minimize: Color::rgb(255, 189, 46),
zoom: Color::rgb(40, 200, 64),
inactive_surface: Color::rgb(242, 242, 244),
inactive_ink: Color::rgb(110, 110, 115),
},
}
}
pub(crate) fn centred_band(rect: Rect, height: u32) -> Rect {
let height = height.min(rect.height);
let top = rect.y + ((rect.height - height) / 2) as i32;
Rect::new(rect.x, top, rect.width, height)
}
pub(crate) fn centred_size(rect: Rect, width: u32, height: u32) -> Rect {
let width = width.min(rect.width);
let height = height.min(rect.height);
Rect::new(
rect.x + ((rect.width - width) / 2) as i32,
rect.y + ((rect.height - height) / 2) as i32,
width,
height,
)
}
pub(crate) fn draw_focus_ring(
context: &mut RenderContext,
rect: Rect,
radius: u32,
base: &BaseWidget,
ring_color: Color,
) {
if !base.draws_focus_ring() {
return;
}
let ring = FocusRing::for_control(rect, radius);
if ring.is_drawable() {
context.draw_rounded_rect_stroke(ring.rect, ring.radius, ring_color, FOCUS_RING_WIDTH);
}
}