gpui-component/crates/wef/src/dpi.rs
Sunli b70b229370
wef: Added a new WebView component named "Wef" based on CEF. (#877)
Wef is a Rust library for embedding WebView functionality using Chromium
Embedded Framework (CEF3) with offscreen rendering support.
2025-06-17 18:57:44 +08:00

43 lines
1.3 KiB
Rust

/// A physical pixel unit.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub struct PhysicalUnit<T>(pub T);
macro_rules! impl_to_logical {
($($unit:ty),*) => {
$(
impl PhysicalUnit<$unit> {
/// Converts the physical unit to a logical unit using the device scale
/// factor.
#[inline]
pub fn to_logical(&self, device_scale_factor: f32) -> LogicalUnit<$unit> {
LogicalUnit((self.0 as f32 / device_scale_factor) as $unit)
}
}
)*
};
() => {};
}
impl_to_logical!(i32, u32, i64, u64, f32, f64);
/// A logical pixel unit.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub struct LogicalUnit<T>(pub T);
macro_rules! impl_to_physical {
($($unit:ty),*) => {
$(
impl LogicalUnit<$unit> {
/// Converts the logical unit to a physical unit using the device scale
/// factor.
#[inline]
pub fn to_physical(&self, device_scale_factor: f32) -> PhysicalUnit<$unit> {
PhysicalUnit((self.0 as f32 * device_scale_factor) as $unit)
}
}
)*
};
() => {};
}
impl_to_physical!(i32, u32, i64, u64, f32, f64);