use crate::{
dpi::{PhysicalPosition, PhysicalSize},
platform_impl
};
#[derive(Clone, PartialEq, Eq, Hash)]
pub struct VideoMode {
pub(crate) video_mode: platform_impl::VideoMode
}
impl std::fmt::Debug for VideoMode {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
self.video_mode.fmt(f)
}
}
impl PartialOrd for VideoMode {
fn partial_cmp(&self, other: &VideoMode) -> Option<std::cmp::Ordering> {
Some(self.cmp(other))
}
}
impl Ord for VideoMode {
fn cmp(&self, other: &VideoMode) -> std::cmp::Ordering {
let size: (u32, u32) = self.size().into();
let other_size: (u32, u32) = other.size().into();
self.monitor().cmp(&other.monitor()).then(
size.cmp(&other_size)
.then(
self.refresh_rate()
.cmp(&other.refresh_rate())
.then(self.bit_depth().cmp(&other.bit_depth()))
)
.reverse()
)
}
}
impl VideoMode {
#[inline]
pub fn size(&self) -> PhysicalSize<u32> {
self.video_mode.size()
}
#[inline]
pub fn bit_depth(&self) -> u16 {
self.video_mode.bit_depth()
}
#[inline]
pub fn refresh_rate(&self) -> u16 {
self.video_mode.refresh_rate()
}
#[inline]
pub fn monitor(&self) -> MonitorHandle {
self.video_mode.monitor()
}
}
impl std::fmt::Display for VideoMode {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}x{} @ {} Hz ({} bpp)", self.size().width, self.size().height, self.refresh_rate(), self.bit_depth())
}
}
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
pub struct MonitorHandle {
pub(crate) inner: platform_impl::MonitorHandle
}
impl MonitorHandle {
#[inline]
pub fn name(&self) -> Option<String> {
self.inner.name()
}
#[inline]
pub fn size(&self) -> PhysicalSize<u32> {
self.inner.size()
}
#[inline]
pub fn position(&self) -> PhysicalPosition<i32> {
self.inner.position()
}
#[inline]
pub fn scale_factor(&self) -> f64 {
self.inner.scale_factor()
}
#[inline]
pub fn video_modes(&self) -> impl Iterator<Item = VideoMode> {
self.inner.video_modes()
}
}