2018-06-14 19:42:18 -04:00
|
|
|
#![allow(non_camel_case_types, non_snake_case, non_upper_case_globals)]
|
|
|
|
|
|
2022-09-08 21:03:25 +02:00
|
|
|
use std::convert::TryInto;
|
2015-06-05 16:38:21 +03:00
|
|
|
|
2022-09-08 20:30:34 +02:00
|
|
|
use objc2::encode::{Encode, Encoding};
|
|
|
|
|
use objc2::foundation::{NSInteger, NSUInteger};
|
2015-06-05 16:38:21 +03:00
|
|
|
|
2022-12-28 18:36:32 +01:00
|
|
|
use crate::platform::ios::{Idiom, ScreenEdge};
|
2019-05-25 18:10:41 -07:00
|
|
|
|
|
|
|
|
#[repr(C)]
|
|
|
|
|
#[derive(Clone, Debug)]
|
|
|
|
|
pub struct NSOperatingSystemVersion {
|
|
|
|
|
pub major: NSInteger,
|
|
|
|
|
pub minor: NSInteger,
|
|
|
|
|
pub patch: NSInteger,
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-02 15:48:02 +02:00
|
|
|
unsafe impl Encode for NSOperatingSystemVersion {
|
|
|
|
|
const ENCODING: Encoding = Encoding::Struct(
|
|
|
|
|
"NSOperatingSystemVersion",
|
|
|
|
|
&[
|
|
|
|
|
NSInteger::ENCODING,
|
|
|
|
|
NSInteger::ENCODING,
|
|
|
|
|
NSInteger::ENCODING,
|
|
|
|
|
],
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-25 18:10:41 -07:00
|
|
|
#[repr(transparent)]
|
|
|
|
|
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
|
|
|
|
pub struct UIUserInterfaceIdiom(NSInteger);
|
|
|
|
|
|
|
|
|
|
unsafe impl Encode for UIUserInterfaceIdiom {
|
2022-09-02 15:48:02 +02:00
|
|
|
const ENCODING: Encoding = NSInteger::ENCODING;
|
2019-05-25 18:10:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl UIUserInterfaceIdiom {
|
|
|
|
|
pub const Unspecified: UIUserInterfaceIdiom = UIUserInterfaceIdiom(-1);
|
|
|
|
|
pub const Phone: UIUserInterfaceIdiom = UIUserInterfaceIdiom(0);
|
|
|
|
|
pub const Pad: UIUserInterfaceIdiom = UIUserInterfaceIdiom(1);
|
|
|
|
|
pub const TV: UIUserInterfaceIdiom = UIUserInterfaceIdiom(2);
|
|
|
|
|
pub const CarPlay: UIUserInterfaceIdiom = UIUserInterfaceIdiom(3);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl From<Idiom> for UIUserInterfaceIdiom {
|
|
|
|
|
fn from(idiom: Idiom) -> UIUserInterfaceIdiom {
|
|
|
|
|
match idiom {
|
|
|
|
|
Idiom::Unspecified => UIUserInterfaceIdiom::Unspecified,
|
|
|
|
|
Idiom::Phone => UIUserInterfaceIdiom::Phone,
|
|
|
|
|
Idiom::Pad => UIUserInterfaceIdiom::Pad,
|
|
|
|
|
Idiom::TV => UIUserInterfaceIdiom::TV,
|
|
|
|
|
Idiom::CarPlay => UIUserInterfaceIdiom::CarPlay,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-06-10 13:43:33 +03:00
|
|
|
impl From<UIUserInterfaceIdiom> for Idiom {
|
|
|
|
|
fn from(ui_idiom: UIUserInterfaceIdiom) -> Idiom {
|
|
|
|
|
match ui_idiom {
|
2019-05-25 18:10:41 -07:00
|
|
|
UIUserInterfaceIdiom::Unspecified => Idiom::Unspecified,
|
|
|
|
|
UIUserInterfaceIdiom::Phone => Idiom::Phone,
|
|
|
|
|
UIUserInterfaceIdiom::Pad => Idiom::Pad,
|
|
|
|
|
UIUserInterfaceIdiom::TV => Idiom::TV,
|
|
|
|
|
UIUserInterfaceIdiom::CarPlay => Idiom::CarPlay,
|
|
|
|
|
_ => unreachable!(),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-30 23:57:31 -07:00
|
|
|
#[repr(transparent)]
|
|
|
|
|
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
|
|
|
|
pub struct UIRectEdge(NSUInteger);
|
|
|
|
|
|
|
|
|
|
unsafe impl Encode for UIRectEdge {
|
2022-09-02 15:48:02 +02:00
|
|
|
const ENCODING: Encoding = NSUInteger::ENCODING;
|
2019-07-30 23:57:31 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl From<ScreenEdge> for UIRectEdge {
|
|
|
|
|
fn from(screen_edge: ScreenEdge) -> UIRectEdge {
|
|
|
|
|
assert_eq!(
|
|
|
|
|
screen_edge.bits() & !ScreenEdge::ALL.bits(),
|
|
|
|
|
0,
|
|
|
|
|
"invalid `ScreenEdge`"
|
|
|
|
|
);
|
|
|
|
|
UIRectEdge(screen_edge.bits().into())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-10 13:43:33 +03:00
|
|
|
impl From<UIRectEdge> for ScreenEdge {
|
|
|
|
|
fn from(ui_rect_edge: UIRectEdge) -> ScreenEdge {
|
|
|
|
|
let bits: u8 = ui_rect_edge.0.try_into().expect("invalid `UIRectEdge`");
|
2019-07-30 23:57:31 -07:00
|
|
|
ScreenEdge::from_bits(bits).expect("invalid `ScreenEdge`")
|
|
|
|
|
}
|
|
|
|
|
}
|