1
0
Fork 0
baseview/src/window_open_options.rs

74 lines
2.3 KiB
Rust
Raw Normal View History

use crate::{WindowInfo, Parent, Size, PhySize};
2020-10-17 13:35:39 -05:00
/// The size of the window
#[derive(Debug)]
pub enum WindowSize {
/// Use logical width and height
2020-10-17 14:01:03 -05:00
Logical(Size),
2020-10-17 13:35:39 -05:00
/// Use physical width and height
Physical(PhySize),
2020-10-17 13:35:39 -05:00
/// Use minimum and maximum logical width and height
MinMaxLogical {
/// The initial logical width and height
2020-10-17 14:01:03 -05:00
initial_size: Size,
2020-10-17 13:35:39 -05:00
/// The minimum logical width and height
2020-10-17 14:01:03 -05:00
min_size: Size,
2020-10-17 13:35:39 -05:00
/// The maximum logical width and height
2020-10-17 14:01:03 -05:00
max_size: Size,
2020-10-17 13:35:39 -05:00
/// Whether to keep the aspect ratio when resizing (true), or not (false)
keep_aspect: bool,
},
/// Use minimum and maximum physical width and height
MinMaxPhysical {
/// The initial physical width and height
initial_size: PhySize,
2020-10-17 13:35:39 -05:00
/// The minimum physical width and height
min_size: PhySize,
2020-10-17 13:35:39 -05:00
/// The maximum physical width and height
max_size: PhySize,
2020-10-17 13:35:39 -05:00
/// Whether to keep the aspect ratio when resizing (true), or not (false)
keep_aspect: bool,
},
}
/// 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,
}
/// The options for opening a new window
#[derive(Debug)]
pub struct WindowOpenOptions {
pub title: String,
/// The size information about the window
pub size: WindowSize,
/// The scaling of the window
pub scale: WindowScalePolicy,
pub parent: Parent,
}
impl WindowOpenOptions {
pub(crate) fn window_info_from_scale(&self, scale: f64) -> WindowInfo {
match self.size {
2020-10-17 14:01:03 -05:00
WindowSize::Logical(size) => WindowInfo::from_logical_size(size, scale),
WindowSize::Physical(size) => WindowInfo::from_physical_size(size, scale),
2020-10-17 13:35:39 -05:00
WindowSize::MinMaxLogical { initial_size, .. } => {
2020-10-17 14:01:03 -05:00
WindowInfo::from_logical_size(initial_size, scale)
2020-10-17 13:35:39 -05:00
},
WindowSize::MinMaxPhysical { initial_size, .. } => {
2020-10-17 15:42:16 -05:00
WindowInfo::from_physical_size(initial_size, scale)
2020-10-17 13:35:39 -05:00
}
}
}
}