1use objc2_foundation::{NSPoint, NSRect, NSSize};
2
3use nifty_runtime::{Frame, Size};
4
5pub(crate) fn to_ns_size(size: Size) -> NSSize {
6 NSSize::new(f64::from(size.width), f64::from(size.height))
7}
8
9pub(crate) fn to_ns_rect(frame: Frame) -> NSRect {
10 NSRect::new(
11 NSPoint::new(f64::from(frame.origin.x), f64::from(frame.origin.y)),
12 to_ns_size(frame.size),
13 )
14}
15
16pub(crate) fn to_size(size: NSSize) -> Size {
17 Size::new(to_points(size.width), to_points(size.height))
18}
19
20#[expect(
21 clippy::cast_possible_truncation,
22 reason = "AppKit uses f64 points and Taffy uses f32; on-screen sizes fit f32 exactly"
23)]
24pub(crate) fn to_points(value: f64) -> f32 {
25 value as f32
26}
27
28#[expect(
29 clippy::cast_precision_loss,
30 reason = "controls show values the checker keeps far inside f64's exact integers"
31)]
32pub(crate) fn to_double(value: i64) -> f64 {
33 value as f64
34}
35
36pub(crate) fn centered(left: f32, width: f32, size: Size, row_height: f32) -> NSRect {
39 NSRect::new(
40 NSPoint::new(f64::from(left), f64::from((row_height - size.height) / 2.0)),
41 NSSize::new(f64::from(width), f64::from(size.height)),
42 )
43}