Use f32 for scale_factor
This commit is contained in:
parent
ad0e4c53cf
commit
74b792b608
14 changed files with 56 additions and 51 deletions
|
|
@ -15,7 +15,7 @@ pub struct Screenshot {
|
||||||
pub size: Size<u32>,
|
pub size: Size<u32>,
|
||||||
/// The scale factor of the [`Screenshot`]. This can be useful when converting between widget
|
/// The scale factor of the [`Screenshot`]. This can be useful when converting between widget
|
||||||
/// bounds (which are in logical pixels) to crop screenshots.
|
/// bounds (which are in logical pixels) to crop screenshots.
|
||||||
pub scale_factor: f64,
|
pub scale_factor: f32,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Debug for Screenshot {
|
impl Debug for Screenshot {
|
||||||
|
|
@ -35,7 +35,7 @@ impl Screenshot {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
bytes: impl Into<Bytes>,
|
bytes: impl Into<Bytes>,
|
||||||
size: Size<u32>,
|
size: Size<u32>,
|
||||||
scale_factor: f64,
|
scale_factor: f32,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self {
|
Self {
|
||||||
bytes: bytes.into(),
|
bytes: bytes.into(),
|
||||||
|
|
|
||||||
|
|
@ -98,7 +98,7 @@ where
|
||||||
state.style(&self.program, theme)
|
state.style(&self.program, theme)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn scale_factor(&self, state: &Self::State, window: window::Id) -> f64 {
|
fn scale_factor(&self, state: &Self::State, window: window::Id) -> f32 {
|
||||||
state.scale_factor(&self.program, window)
|
state.scale_factor(&self.program, window)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -397,7 +397,7 @@ where
|
||||||
program.style(self.state(), theme)
|
program.style(self.state(), theme)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn scale_factor(&self, program: &P, window: window::Id) -> f64 {
|
fn scale_factor(&self, program: &P, window: window::Id) -> f32 {
|
||||||
program.scale_factor(self.state(), window)
|
program.scale_factor(self.state(), window)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -67,7 +67,7 @@ pub fn main() -> Result<(), winit::error::EventLoopError> {
|
||||||
let physical_size = window.inner_size();
|
let physical_size = window.inner_size();
|
||||||
let viewport = Viewport::with_physical_size(
|
let viewport = Viewport::with_physical_size(
|
||||||
Size::new(physical_size.width, physical_size.height),
|
Size::new(physical_size.width, physical_size.height),
|
||||||
window.scale_factor(),
|
window.scale_factor() as f32,
|
||||||
);
|
);
|
||||||
let clipboard = Clipboard::connect(window.clone());
|
let clipboard = Clipboard::connect(window.clone());
|
||||||
|
|
||||||
|
|
@ -212,7 +212,7 @@ pub fn main() -> Result<(), winit::error::EventLoopError> {
|
||||||
|
|
||||||
*viewport = Viewport::with_physical_size(
|
*viewport = Viewport::with_physical_size(
|
||||||
Size::new(size.width, size.height),
|
Size::new(size.width, size.height),
|
||||||
window.scale_factor(),
|
window.scale_factor() as f32,
|
||||||
);
|
);
|
||||||
|
|
||||||
surface.configure(
|
surface.configure(
|
||||||
|
|
@ -345,7 +345,7 @@ pub fn main() -> Result<(), winit::error::EventLoopError> {
|
||||||
// Map window event to iced event
|
// Map window event to iced event
|
||||||
if let Some(event) = conversion::window_event(
|
if let Some(event) = conversion::window_event(
|
||||||
event,
|
event,
|
||||||
window.scale_factor(),
|
window.scale_factor() as f32,
|
||||||
*modifiers,
|
*modifiers,
|
||||||
) {
|
) {
|
||||||
events.push(event);
|
events.push(event);
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ struct Example {
|
||||||
struct Window {
|
struct Window {
|
||||||
title: String,
|
title: String,
|
||||||
scale_input: String,
|
scale_input: String,
|
||||||
current_scale: f64,
|
current_scale: f32,
|
||||||
theme: Theme,
|
theme: Theme,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -113,7 +113,7 @@ impl Example {
|
||||||
Message::ScaleChanged(id, scale) => {
|
Message::ScaleChanged(id, scale) => {
|
||||||
if let Some(window) = self.windows.get_mut(&id) {
|
if let Some(window) = self.windows.get_mut(&id) {
|
||||||
window.current_scale = scale
|
window.current_scale = scale
|
||||||
.parse::<f64>()
|
.parse()
|
||||||
.unwrap_or(window.current_scale)
|
.unwrap_or(window.current_scale)
|
||||||
.clamp(0.5, 5.0);
|
.clamp(0.5, 5.0);
|
||||||
}
|
}
|
||||||
|
|
@ -146,7 +146,7 @@ impl Example {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn scale_factor(&self, window: window::Id) -> f64 {
|
fn scale_factor(&self, window: window::Id) -> f32 {
|
||||||
self.windows
|
self.windows
|
||||||
.get(&window)
|
.get(&window)
|
||||||
.map(|window| window.current_scale)
|
.map(|window| window.current_scale)
|
||||||
|
|
|
||||||
|
|
@ -5,19 +5,19 @@ use crate::core::{Size, Transformation};
|
||||||
pub struct Viewport {
|
pub struct Viewport {
|
||||||
physical_size: Size<u32>,
|
physical_size: Size<u32>,
|
||||||
logical_size: Size<f32>,
|
logical_size: Size<f32>,
|
||||||
scale_factor: f64,
|
scale_factor: f32,
|
||||||
projection: Transformation,
|
projection: Transformation,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Viewport {
|
impl Viewport {
|
||||||
/// Creates a new [`Viewport`] with the given physical dimensions and scale
|
/// Creates a new [`Viewport`] with the given physical dimensions and scale
|
||||||
/// factor.
|
/// factor.
|
||||||
pub fn with_physical_size(size: Size<u32>, scale_factor: f64) -> Viewport {
|
pub fn with_physical_size(size: Size<u32>, scale_factor: f32) -> Viewport {
|
||||||
Viewport {
|
Viewport {
|
||||||
physical_size: size,
|
physical_size: size,
|
||||||
logical_size: Size::new(
|
logical_size: Size::new(
|
||||||
(size.width as f64 / scale_factor) as f32,
|
size.width as f32 / scale_factor,
|
||||||
(size.height as f64 / scale_factor) as f32,
|
size.height as f32 / scale_factor,
|
||||||
),
|
),
|
||||||
scale_factor,
|
scale_factor,
|
||||||
projection: Transformation::orthographic(size.width, size.height),
|
projection: Transformation::orthographic(size.width, size.height),
|
||||||
|
|
@ -45,7 +45,7 @@ impl Viewport {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the scale factor of the [`Viewport`].
|
/// Returns the scale factor of the [`Viewport`].
|
||||||
pub fn scale_factor(&self) -> f64 {
|
pub fn scale_factor(&self) -> f32 {
|
||||||
self.scale_factor
|
self.scale_factor
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -94,7 +94,7 @@ pub trait Program: Sized {
|
||||||
theme::Base::base(theme)
|
theme::Base::base(theme)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn scale_factor(&self, _state: &Self::State, _window: window::Id) -> f64 {
|
fn scale_factor(&self, _state: &Self::State, _window: window::Id) -> f32 {
|
||||||
1.0
|
1.0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -171,7 +171,7 @@ pub fn with_title<P: Program>(
|
||||||
self.program.style(state, theme)
|
self.program.style(state, theme)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn scale_factor(&self, state: &Self::State, window: window::Id) -> f64 {
|
fn scale_factor(&self, state: &Self::State, window: window::Id) -> f32 {
|
||||||
self.program.scale_factor(state, window)
|
self.program.scale_factor(state, window)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -250,7 +250,7 @@ pub fn with_subscription<P: Program>(
|
||||||
self.program.style(state, theme)
|
self.program.style(state, theme)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn scale_factor(&self, state: &Self::State, window: window::Id) -> f64 {
|
fn scale_factor(&self, state: &Self::State, window: window::Id) -> f32 {
|
||||||
self.program.scale_factor(state, window)
|
self.program.scale_factor(state, window)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -332,7 +332,7 @@ pub fn with_theme<P: Program>(
|
||||||
self.program.style(state, theme)
|
self.program.style(state, theme)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn scale_factor(&self, state: &Self::State, window: window::Id) -> f64 {
|
fn scale_factor(&self, state: &Self::State, window: window::Id) -> f32 {
|
||||||
self.program.scale_factor(state, window)
|
self.program.scale_factor(state, window)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -411,7 +411,7 @@ pub fn with_style<P: Program>(
|
||||||
self.program.theme(state, window)
|
self.program.theme(state, window)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn scale_factor(&self, state: &Self::State, window: window::Id) -> f64 {
|
fn scale_factor(&self, state: &Self::State, window: window::Id) -> f32 {
|
||||||
self.program.scale_factor(state, window)
|
self.program.scale_factor(state, window)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -422,7 +422,7 @@ pub fn with_style<P: Program>(
|
||||||
/// Decorates a [`Program`] with the given scale factor function.
|
/// Decorates a [`Program`] with the given scale factor function.
|
||||||
pub fn with_scale_factor<P: Program>(
|
pub fn with_scale_factor<P: Program>(
|
||||||
program: P,
|
program: P,
|
||||||
f: impl Fn(&P::State, window::Id) -> f64,
|
f: impl Fn(&P::State, window::Id) -> f32,
|
||||||
) -> impl Program<State = P::State, Message = P::Message, Theme = P::Theme> {
|
) -> impl Program<State = P::State, Message = P::Message, Theme = P::Theme> {
|
||||||
struct WithScaleFactor<P, F> {
|
struct WithScaleFactor<P, F> {
|
||||||
program: P,
|
program: P,
|
||||||
|
|
@ -431,7 +431,7 @@ pub fn with_scale_factor<P: Program>(
|
||||||
|
|
||||||
impl<P: Program, F> Program for WithScaleFactor<P, F>
|
impl<P: Program, F> Program for WithScaleFactor<P, F>
|
||||||
where
|
where
|
||||||
F: Fn(&P::State, window::Id) -> f64,
|
F: Fn(&P::State, window::Id) -> f32,
|
||||||
{
|
{
|
||||||
type State = P::State;
|
type State = P::State;
|
||||||
type Message = P::Message;
|
type Message = P::Message;
|
||||||
|
|
@ -490,7 +490,7 @@ pub fn with_scale_factor<P: Program>(
|
||||||
self.program.style(state, theme)
|
self.program.style(state, theme)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn scale_factor(&self, state: &Self::State, window: window::Id) -> f64 {
|
fn scale_factor(&self, state: &Self::State, window: window::Id) -> f32 {
|
||||||
(self.scale_factor)(state, window)
|
(self.scale_factor)(state, window)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -573,7 +573,7 @@ pub fn with_executor<P: Program, E: Executor>(
|
||||||
self.program.style(state, theme)
|
self.program.style(state, theme)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn scale_factor(&self, state: &Self::State, window: window::Id) -> f64 {
|
fn scale_factor(&self, state: &Self::State, window: window::Id) -> f32 {
|
||||||
self.program.scale_factor(state, window)
|
self.program.scale_factor(state, window)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -638,7 +638,7 @@ impl<P: Program> Instance<P> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the current scale factor of the [`Instance`].
|
/// Returns the current scale factor of the [`Instance`].
|
||||||
pub fn scale_factor(&self, window: window::Id) -> f64 {
|
pub fn scale_factor(&self, window: window::Id) -> f32 {
|
||||||
self.program.scale_factor(&self.state, window)
|
self.program.scale_factor(&self.state, window)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -387,7 +387,7 @@ impl<P: Program> Application<P> {
|
||||||
/// Sets the scale factor of the [`Application`].
|
/// Sets the scale factor of the [`Application`].
|
||||||
pub fn scale_factor(
|
pub fn scale_factor(
|
||||||
self,
|
self,
|
||||||
f: impl Fn(&P::State) -> f64,
|
f: impl Fn(&P::State) -> f32,
|
||||||
) -> Application<
|
) -> Application<
|
||||||
impl Program<State = P::State, Message = P::Message, Theme = P::Theme>,
|
impl Program<State = P::State, Message = P::Message, Theme = P::Theme>,
|
||||||
> {
|
> {
|
||||||
|
|
|
||||||
|
|
@ -232,7 +232,7 @@ impl<P: Program> Daemon<P> {
|
||||||
/// Sets the scale factor of the [`Daemon`].
|
/// Sets the scale factor of the [`Daemon`].
|
||||||
pub fn scale_factor(
|
pub fn scale_factor(
|
||||||
self,
|
self,
|
||||||
f: impl Fn(&P::State, window::Id) -> f64,
|
f: impl Fn(&P::State, window::Id) -> f32,
|
||||||
) -> Daemon<
|
) -> Daemon<
|
||||||
impl Program<State = P::State, Message = P::Message, Theme = P::Theme>,
|
impl Program<State = P::State, Message = P::Message, Theme = P::Theme>,
|
||||||
> {
|
> {
|
||||||
|
|
|
||||||
|
|
@ -462,7 +462,7 @@ where
|
||||||
screenshot: window::Screenshot::new(
|
screenshot: window::Screenshot::new(
|
||||||
rgba,
|
rgba,
|
||||||
physical_size,
|
physical_size,
|
||||||
f64::from(scale_factor),
|
scale_factor,
|
||||||
),
|
),
|
||||||
renderer: self.renderer.name(),
|
renderer: self.renderer.name(),
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -72,7 +72,7 @@ impl Renderer {
|
||||||
damage: &[Rectangle],
|
damage: &[Rectangle],
|
||||||
background_color: Color,
|
background_color: Color,
|
||||||
) {
|
) {
|
||||||
let scale_factor = viewport.scale_factor() as f32;
|
let scale_factor = viewport.scale_factor();
|
||||||
|
|
||||||
self.layers.flush();
|
self.layers.flush();
|
||||||
|
|
||||||
|
|
@ -405,8 +405,7 @@ impl renderer::Headless for Renderer {
|
||||||
scale_factor: f32,
|
scale_factor: f32,
|
||||||
background_color: Color,
|
background_color: Color,
|
||||||
) -> Vec<u8> {
|
) -> Vec<u8> {
|
||||||
let viewport =
|
let viewport = Viewport::with_physical_size(size, scale_factor);
|
||||||
Viewport::with_physical_size(size, f64::from(scale_factor));
|
|
||||||
|
|
||||||
window::compositor::screenshot(self, &viewport, background_color)
|
window::compositor::screenshot(self, &viewport, background_color)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -302,7 +302,7 @@ impl Renderer {
|
||||||
encoder: &mut wgpu::CommandEncoder,
|
encoder: &mut wgpu::CommandEncoder,
|
||||||
viewport: &Viewport,
|
viewport: &Viewport,
|
||||||
) {
|
) {
|
||||||
let scale_factor = viewport.scale_factor() as f32;
|
let scale_factor = viewport.scale_factor();
|
||||||
|
|
||||||
self.text_viewport
|
self.text_viewport
|
||||||
.update(&self.engine.queue, viewport.physical_size());
|
.update(&self.engine.queue, viewport.physical_size());
|
||||||
|
|
@ -464,7 +464,7 @@ impl Renderer {
|
||||||
#[cfg(any(feature = "svg", feature = "image"))]
|
#[cfg(any(feature = "svg", feature = "image"))]
|
||||||
let image_cache = self.image_cache.borrow();
|
let image_cache = self.image_cache.borrow();
|
||||||
|
|
||||||
let scale_factor = viewport.scale_factor() as f32;
|
let scale_factor = viewport.scale_factor();
|
||||||
let physical_bounds = Rectangle::<f32>::from(Rectangle::with_size(
|
let physical_bounds = Rectangle::<f32>::from(Rectangle::with_size(
|
||||||
viewport.physical_size(),
|
viewport.physical_size(),
|
||||||
));
|
));
|
||||||
|
|
@ -879,7 +879,7 @@ impl renderer::Headless for Renderer {
|
||||||
background_color: Color,
|
background_color: Color,
|
||||||
) -> Vec<u8> {
|
) -> Vec<u8> {
|
||||||
self.screenshot(
|
self.screenshot(
|
||||||
&Viewport::with_physical_size(size, f64::from(scale_factor)),
|
&Viewport::with_physical_size(size, scale_factor),
|
||||||
background_color,
|
background_color,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@ use crate::core::{Event, Point, Size};
|
||||||
pub fn window_attributes(
|
pub fn window_attributes(
|
||||||
settings: window::Settings,
|
settings: window::Settings,
|
||||||
title: &str,
|
title: &str,
|
||||||
|
scale_factor: f32,
|
||||||
primary_monitor: Option<winit::monitor::MonitorHandle>,
|
primary_monitor: Option<winit::monitor::MonitorHandle>,
|
||||||
_id: Option<String>,
|
_id: Option<String>,
|
||||||
) -> winit::window::WindowAttributes {
|
) -> winit::window::WindowAttributes {
|
||||||
|
|
@ -21,8 +22,8 @@ pub fn window_attributes(
|
||||||
attributes = attributes
|
attributes = attributes
|
||||||
.with_title(title)
|
.with_title(title)
|
||||||
.with_inner_size(winit::dpi::LogicalSize {
|
.with_inner_size(winit::dpi::LogicalSize {
|
||||||
width: settings.size.width,
|
width: settings.size.width * scale_factor,
|
||||||
height: settings.size.height,
|
height: settings.size.height * scale_factor,
|
||||||
})
|
})
|
||||||
.with_maximized(settings.maximized)
|
.with_maximized(settings.maximized)
|
||||||
.with_fullscreen(
|
.with_fullscreen(
|
||||||
|
|
@ -138,7 +139,7 @@ pub fn window_attributes(
|
||||||
/// Converts a winit window event into an iced event.
|
/// Converts a winit window event into an iced event.
|
||||||
pub fn window_event(
|
pub fn window_event(
|
||||||
event: winit::event::WindowEvent,
|
event: winit::event::WindowEvent,
|
||||||
scale_factor: f64,
|
scale_factor: f32,
|
||||||
modifiers: winit::keyboard::ModifiersState,
|
modifiers: winit::keyboard::ModifiersState,
|
||||||
) -> Option<Event> {
|
) -> Option<Event> {
|
||||||
use winit::event::Ime;
|
use winit::event::Ime;
|
||||||
|
|
@ -146,7 +147,7 @@ pub fn window_event(
|
||||||
|
|
||||||
match event {
|
match event {
|
||||||
WindowEvent::Resized(new_size) => {
|
WindowEvent::Resized(new_size) => {
|
||||||
let logical_size = new_size.to_logical(scale_factor);
|
let logical_size = new_size.to_logical(f64::from(scale_factor));
|
||||||
|
|
||||||
Some(Event::Window(window::Event::Resized(Size {
|
Some(Event::Window(window::Event::Resized(Size {
|
||||||
width: logical_size.width,
|
width: logical_size.width,
|
||||||
|
|
@ -157,7 +158,7 @@ pub fn window_event(
|
||||||
Some(Event::Window(window::Event::CloseRequested))
|
Some(Event::Window(window::Event::CloseRequested))
|
||||||
}
|
}
|
||||||
WindowEvent::CursorMoved { position, .. } => {
|
WindowEvent::CursorMoved { position, .. } => {
|
||||||
let position = position.to_logical::<f64>(scale_factor);
|
let position = position.to_logical::<f64>(f64::from(scale_factor));
|
||||||
|
|
||||||
Some(Event::Mouse(mouse::Event::CursorMoved {
|
Some(Event::Mouse(mouse::Event::CursorMoved {
|
||||||
position: Point::new(position.x as f32, position.y as f32),
|
position: Point::new(position.x as f32, position.y as f32),
|
||||||
|
|
@ -313,7 +314,7 @@ pub fn window_event(
|
||||||
}
|
}
|
||||||
WindowEvent::Moved(position) => {
|
WindowEvent::Moved(position) => {
|
||||||
let winit::dpi::LogicalPosition { x, y } =
|
let winit::dpi::LogicalPosition { x, y } =
|
||||||
position.to_logical(scale_factor);
|
position.to_logical(f64::from(scale_factor));
|
||||||
|
|
||||||
Some(Event::Window(window::Event::Moved(Point::new(x, y))))
|
Some(Event::Window(window::Event::Moved(Point::new(x, y))))
|
||||||
}
|
}
|
||||||
|
|
@ -513,9 +514,9 @@ pub fn modifiers(
|
||||||
/// Converts a physical cursor position to a logical `Point`.
|
/// Converts a physical cursor position to a logical `Point`.
|
||||||
pub fn cursor_position(
|
pub fn cursor_position(
|
||||||
position: winit::dpi::PhysicalPosition<f64>,
|
position: winit::dpi::PhysicalPosition<f64>,
|
||||||
scale_factor: f64,
|
scale_factor: f32,
|
||||||
) -> Point {
|
) -> Point {
|
||||||
let logical_position = position.to_logical(scale_factor);
|
let logical_position = position.to_logical(f64::from(scale_factor));
|
||||||
|
|
||||||
Point::new(logical_position.x, logical_position.y)
|
Point::new(logical_position.x, logical_position.y)
|
||||||
}
|
}
|
||||||
|
|
@ -526,11 +527,12 @@ pub fn cursor_position(
|
||||||
/// [`iced`]: https://github.com/iced-rs/iced/tree/0.12
|
/// [`iced`]: https://github.com/iced-rs/iced/tree/0.12
|
||||||
pub fn touch_event(
|
pub fn touch_event(
|
||||||
touch: winit::event::Touch,
|
touch: winit::event::Touch,
|
||||||
scale_factor: f64,
|
scale_factor: f32,
|
||||||
) -> touch::Event {
|
) -> touch::Event {
|
||||||
let id = touch::Finger(touch.id);
|
let id = touch::Finger(touch.id);
|
||||||
let position = {
|
let position = {
|
||||||
let location = touch.location.to_logical::<f64>(scale_factor);
|
let location =
|
||||||
|
touch.location.to_logical::<f64>(f64::from(scale_factor));
|
||||||
|
|
||||||
Point::new(location.x as f32, location.y as f32)
|
Point::new(location.x as f32, location.y as f32)
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -310,6 +310,7 @@ where
|
||||||
id,
|
id,
|
||||||
settings,
|
settings,
|
||||||
title,
|
title,
|
||||||
|
scale_factor,
|
||||||
monitor,
|
monitor,
|
||||||
on_open,
|
on_open,
|
||||||
} => {
|
} => {
|
||||||
|
|
@ -326,6 +327,7 @@ where
|
||||||
conversion::window_attributes(
|
conversion::window_attributes(
|
||||||
settings,
|
settings,
|
||||||
&title,
|
&title,
|
||||||
|
scale_factor,
|
||||||
monitor
|
monitor
|
||||||
.or(event_loop.primary_monitor()),
|
.or(event_loop.primary_monitor()),
|
||||||
self.id.clone(),
|
self.id.clone(),
|
||||||
|
|
@ -480,6 +482,7 @@ enum Control {
|
||||||
title: String,
|
title: String,
|
||||||
monitor: Option<winit::monitor::MonitorHandle>,
|
monitor: Option<winit::monitor::MonitorHandle>,
|
||||||
on_open: oneshot::Sender<window::Id>,
|
on_open: oneshot::Sender<window::Id>,
|
||||||
|
scale_factor: f32,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1130,6 +1133,7 @@ fn run_action<'a, P, C>(
|
||||||
id,
|
id,
|
||||||
settings,
|
settings,
|
||||||
title: program.title(id),
|
title: program.title(id),
|
||||||
|
scale_factor: program.scale_factor(id),
|
||||||
monitor,
|
monitor,
|
||||||
on_open: channel,
|
on_open: channel,
|
||||||
})
|
})
|
||||||
|
|
@ -1234,7 +1238,7 @@ fn run_action<'a, P, C>(
|
||||||
let size = window
|
let size = window
|
||||||
.raw
|
.raw
|
||||||
.inner_size()
|
.inner_size()
|
||||||
.to_logical(window.raw.scale_factor());
|
.to_logical(f64::from(window.state.scale_factor()));
|
||||||
|
|
||||||
let _ = channel.send(Size::new(size.width, size.height));
|
let _ = channel.send(Size::new(size.width, size.height));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ where
|
||||||
P::Theme: theme::Base,
|
P::Theme: theme::Base,
|
||||||
{
|
{
|
||||||
title: String,
|
title: String,
|
||||||
scale_factor: f64,
|
scale_factor: f32,
|
||||||
viewport: Viewport,
|
viewport: Viewport,
|
||||||
viewport_version: u64,
|
viewport_version: u64,
|
||||||
cursor_position: Option<winit::dpi::PhysicalPosition<f64>>,
|
cursor_position: Option<winit::dpi::PhysicalPosition<f64>>,
|
||||||
|
|
@ -60,7 +60,7 @@ where
|
||||||
|
|
||||||
Viewport::with_physical_size(
|
Viewport::with_physical_size(
|
||||||
Size::new(physical_size.width, physical_size.height),
|
Size::new(physical_size.width, physical_size.height),
|
||||||
window.scale_factor() * scale_factor,
|
window.scale_factor() as f32 * scale_factor,
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -99,7 +99,7 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the current scale factor of the [`Viewport`] of the [`State`].
|
/// Returns the current scale factor of the [`Viewport`] of the [`State`].
|
||||||
pub fn scale_factor(&self) -> f64 {
|
pub fn scale_factor(&self) -> f32 {
|
||||||
self.viewport.scale_factor()
|
self.viewport.scale_factor()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -144,7 +144,7 @@ where
|
||||||
|
|
||||||
self.viewport = Viewport::with_physical_size(
|
self.viewport = Viewport::with_physical_size(
|
||||||
size,
|
size,
|
||||||
window.scale_factor() * self.scale_factor,
|
window.scale_factor() as f32 * self.scale_factor,
|
||||||
);
|
);
|
||||||
|
|
||||||
self.viewport_version = self.viewport_version.wrapping_add(1);
|
self.viewport_version = self.viewport_version.wrapping_add(1);
|
||||||
|
|
@ -157,7 +157,7 @@ where
|
||||||
|
|
||||||
self.viewport = Viewport::with_physical_size(
|
self.viewport = Viewport::with_physical_size(
|
||||||
size,
|
size,
|
||||||
new_scale_factor * self.scale_factor,
|
*new_scale_factor as f32 * self.scale_factor,
|
||||||
);
|
);
|
||||||
|
|
||||||
self.viewport_version = self.viewport_version.wrapping_add(1);
|
self.viewport_version = self.viewport_version.wrapping_add(1);
|
||||||
|
|
@ -208,7 +208,7 @@ where
|
||||||
{
|
{
|
||||||
self.viewport = Viewport::with_physical_size(
|
self.viewport = Viewport::with_physical_size(
|
||||||
Size::new(new_size.width, new_size.height),
|
Size::new(new_size.width, new_size.height),
|
||||||
window.scale_factor() * new_scale_factor,
|
window.scale_factor() as f32 * new_scale_factor,
|
||||||
);
|
);
|
||||||
self.viewport_version = self.viewport_version.wrapping_add(1);
|
self.viewport_version = self.viewport_version.wrapping_add(1);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue