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;
@ -21,8 +21,8 @@ impl WindowHandler for OpenWindowExample {
fn main() {
let window_open_options = baseview::WindowOpenOptions {
title: "baseview".into(),
size: WindowSize::Logical(baseview::Size::new(512.0, 512.0)),
scale: WindowScalePolicy::TrySystemScaleFactor,
size: baseview::Size::new(512.0, 512.0),
scale: WindowScalePolicy::SystemScaleFactor,
parent: baseview::Parent::None,
};

View file

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

View file

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

View file

@ -1,25 +1,12 @@
use crate::{WindowInfo, Parent, Size, PhySize};
/// The size of the window
#[derive(Debug)]
pub enum WindowSize {
/// Use logical width and height
Logical(Size),
/// Use physical width and height
Physical(PhySize),
}
use crate::{Parent, Size};
/// The dpi scaling policy of the window
#[derive(Debug)]
pub enum WindowScalePolicy {
/// Try using the system scale factor
TrySystemScaleFactor,
/// Try using the system scale factor in addition to the given scale factor
TrySystemScaleFactorTimes(f64),
/// Use the given scale factor
UseScaleFactor(f64),
/// No scaling
NoScaling,
/// Use the system's dpi scale factor
SystemScaleFactor,
/// Use the given dpi scale factor (e.g. `1.0` = 96 dpi)
ScaleFactor(f64),
}
/// The options for opening a new window
@ -27,20 +14,14 @@ pub enum WindowScalePolicy {
pub struct WindowOpenOptions {
pub title: String,
/// The size information about the window
pub size: WindowSize,
/// The logical size of the window.
///
/// 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 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 {
WindowScalePolicy::TrySystemScaleFactor =>
xcb_connection.get_scaling().unwrap_or(1.0),
WindowScalePolicy::TrySystemScaleFactorTimes(user_scale) =>
xcb_connection.get_scaling().unwrap_or(1.0) * user_scale,
WindowScalePolicy::UseScaleFactor(user_scale) => user_scale,
WindowScalePolicy::NoScaling => 1.0,
WindowScalePolicy::SystemScaleFactor => xcb_connection.get_scaling().unwrap_or(1.0),
WindowScalePolicy::ScaleFactor(scale) => scale
};
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();
xcb::create_window(