clean up dpi features
This commit is contained in:
parent
b0196b8c5f
commit
579dfee1eb
|
@ -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,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -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::UseScaleFactor(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),
|
||||||
|
|
|
@ -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::UseScaleFactor(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,
|
||||||
|
|
|
@ -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),
|
|
||||||
/// Use the given scale factor
|
|
||||||
UseScaleFactor(f64),
|
UseScaleFactor(f64),
|
||||||
/// No scaling
|
|
||||||
NoScaling,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The options for opening a new window
|
/// The options for opening a new window
|
||||||
|
@ -27,20 +14,11 @@ 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,
|
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),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -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::UseScaleFactor(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(
|
||||||
|
|
Loading…
Reference in a new issue