1
0
Fork 0

Merge pull request #50 from BillyDM/master

Clean up dpi features
This commit is contained in:
william light 2020-10-21 02:25:53 +02:00 committed by GitHub
commit cd5c91f8a8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 26 additions and 55 deletions

View file

@ -1,4 +1,4 @@
use baseview::{Event, Window, WindowHandler, WindowSize, WindowScalePolicy}; use baseview::{Event, Window, WindowHandler, WindowScalePolicy};
struct OpenWindowExample; struct OpenWindowExample;
@ -21,8 +21,8 @@ impl WindowHandler for OpenWindowExample {
fn main() { fn main() {
let window_open_options = baseview::WindowOpenOptions { let window_open_options = baseview::WindowOpenOptions {
title: "baseview".into(), title: "baseview".into(),
size: WindowSize::Logical(baseview::Size::new(512.0, 512.0)), size: baseview::Size::new(512.0, 512.0),
scale: WindowScalePolicy::TrySystemScaleFactor, scale: WindowScalePolicy::SystemScaleFactor,
parent: baseview::Parent::None, parent: baseview::Parent::None,
}; };

View file

@ -12,7 +12,7 @@ use raw_window_handle::{macos::MacOSHandle, HasRawWindowHandle, RawWindowHandle}
use crate::{ use crate::{
Event, KeyboardEvent, MouseButton, MouseEvent, ScrollDelta, WindowEvent, WindowHandler, Event, KeyboardEvent, MouseButton, MouseEvent, ScrollDelta, WindowEvent, WindowHandler,
WindowOpenOptions, WindowScalePolicy, WindowOpenOptions, WindowScalePolicy, WindowInfo,
}; };
pub struct Window { pub struct Window {
@ -42,14 +42,11 @@ impl Window {
let _pool = NSAutoreleasePool::new(nil); let _pool = NSAutoreleasePool::new(nil);
let scaling = match options.scale { let scaling = match options.scale {
// TODO: Find system scale factor WindowScalePolicy::SystemScaleFactor => get_scaling().unwrap_or(1.0),
WindowScalePolicy::TrySystemScaleFactor => get_scaling().unwrap_or(1.0), WindowScalePolicy::ScaleFactor(scale) => scale
WindowScalePolicy::TrySystemScaleFactorTimes(user_scale) => get_scaling().unwrap_or(1.0) * user_scale,
WindowScalePolicy::UseScaleFactor(user_scale) => user_scale,
WindowScalePolicy::NoScaling => 1.0,
}; };
let window_info = options.window_info_from_scale(scaling); let window_info = WindowInfo::from_logical_size(options.size, scaling);
let rect = NSRect::new( let rect = NSRect::new(
NSPoint::new(0.0, 0.0), NSPoint::new(0.0, 0.0),

View file

@ -195,14 +195,11 @@ impl Window {
| WS_CLIPSIBLINGS; | WS_CLIPSIBLINGS;
let scaling = match options.scale { let scaling = match options.scale {
// TODO: Find system scale factor WindowScalePolicy::SystemScaleFactor => get_scaling().unwrap_or(1.0),
WindowScalePolicy::TrySystemScaleFactor => get_scaling().unwrap_or(1.0), WindowScalePolicy::ScaleFactor(scale) => scale
WindowScalePolicy::TrySystemScaleFactorTimes(user_scale) => get_scaling().unwrap_or(1.0) * user_scale,
WindowScalePolicy::UseScaleFactor(user_scale) => user_scale,
WindowScalePolicy::NoScaling => 1.0,
}; };
let window_info = options.window_info_from_scale(scaling); let window_info = WindowInfo::from_logical_size(options.size, scaling);
let mut rect = RECT { let mut rect = RECT {
left: 0, left: 0,

View file

@ -1,25 +1,12 @@
use crate::{WindowInfo, Parent, Size, PhySize}; use crate::{Parent, Size};
/// The size of the window
#[derive(Debug)]
pub enum WindowSize {
/// Use logical width and height
Logical(Size),
/// Use physical width and height
Physical(PhySize),
}
/// The dpi scaling policy of the window /// The dpi scaling policy of the window
#[derive(Debug)] #[derive(Debug)]
pub enum WindowScalePolicy { pub enum WindowScalePolicy {
/// Try using the system scale factor /// Use the system's dpi scale factor
TrySystemScaleFactor, SystemScaleFactor,
/// Try using the system scale factor in addition to the given scale factor /// Use the given dpi scale factor (e.g. `1.0` = 96 dpi)
TrySystemScaleFactorTimes(f64), ScaleFactor(f64),
/// Use the given scale factor
UseScaleFactor(f64),
/// No scaling
NoScaling,
} }
/// The options for opening a new window /// The options for opening a new window
@ -27,20 +14,14 @@ pub enum WindowScalePolicy {
pub struct WindowOpenOptions { pub struct WindowOpenOptions {
pub title: String, pub title: String,
/// The size information about the window /// The logical size of the window.
pub size: WindowSize, ///
/// These dimensions will be scaled by the scaling policy specified in `scale`. Mouse
/// position will be passed back as logical coordinates.
pub size: Size,
/// The scaling of the window /// The dpi scaling policy
pub scale: WindowScalePolicy, pub scale: WindowScalePolicy,
pub parent: Parent, pub parent: Parent,
}
impl WindowOpenOptions {
pub(crate) fn window_info_from_scale(&self, scale: f64) -> WindowInfo {
match self.size {
WindowSize::Logical(size) => WindowInfo::from_logical_size(size, scale),
WindowSize::Physical(size) => WindowInfo::from_physical_size(size, scale),
}
}
} }

View file

@ -100,15 +100,11 @@ impl Window {
); );
let scaling = match options.scale { let scaling = match options.scale {
WindowScalePolicy::TrySystemScaleFactor => WindowScalePolicy::SystemScaleFactor => xcb_connection.get_scaling().unwrap_or(1.0),
xcb_connection.get_scaling().unwrap_or(1.0), WindowScalePolicy::ScaleFactor(scale) => scale
WindowScalePolicy::TrySystemScaleFactorTimes(user_scale) =>
xcb_connection.get_scaling().unwrap_or(1.0) * user_scale,
WindowScalePolicy::UseScaleFactor(user_scale) => user_scale,
WindowScalePolicy::NoScaling => 1.0,
}; };
let window_info = options.window_info_from_scale(scaling); let window_info = WindowInfo::from_logical_size(options.size, scaling);
let window_id = xcb_connection.conn.generate_id(); let window_id = xcb_connection.conn.generate_id();
xcb::create_window( xcb::create_window(