Reconfigure window Surface on any resize event
This commit is contained in:
parent
9d4ef528d8
commit
f53bee4225
3 changed files with 21 additions and 31 deletions
|
|
@ -697,7 +697,7 @@ async fn run_instance<P>(
|
||||||
id,
|
id,
|
||||||
core::Event::Window(window::Event::Opened {
|
core::Event::Window(window::Event::Opened {
|
||||||
position: window.position(),
|
position: window.position(),
|
||||||
size: window.size(),
|
size: window.logical_size(),
|
||||||
}),
|
}),
|
||||||
));
|
));
|
||||||
|
|
||||||
|
|
@ -796,7 +796,9 @@ async fn run_instance<P>(
|
||||||
}
|
}
|
||||||
|
|
||||||
// Window was resized between redraws
|
// Window was resized between redraws
|
||||||
if window.surface_size != physical_size {
|
if window.surface_version
|
||||||
|
!= window.state.surface_version()
|
||||||
|
{
|
||||||
let ui = user_interfaces
|
let ui = user_interfaces
|
||||||
.remove(&id)
|
.remove(&id)
|
||||||
.expect("Remove user interface");
|
.expect("Remove user interface");
|
||||||
|
|
@ -814,7 +816,8 @@ async fn run_instance<P>(
|
||||||
physical_size.height,
|
physical_size.height,
|
||||||
);
|
);
|
||||||
|
|
||||||
window.surface_size = physical_size;
|
window.surface_version =
|
||||||
|
window.state.surface_version();
|
||||||
}
|
}
|
||||||
|
|
||||||
let redraw_event = core::Event::Window(
|
let redraw_event = core::Event::Window(
|
||||||
|
|
@ -1483,11 +1486,7 @@ fn run_action<'a, P, C>(
|
||||||
}
|
}
|
||||||
window::Action::GetSize(id, channel) => {
|
window::Action::GetSize(id, channel) => {
|
||||||
if let Some(window) = window_manager.get_mut(id) {
|
if let Some(window) = window_manager.get_mut(id) {
|
||||||
let size = window
|
let size = window.logical_size();
|
||||||
.raw
|
|
||||||
.inner_size()
|
|
||||||
.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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1761,7 +1760,7 @@ fn run_action<'a, P, C>(
|
||||||
};
|
};
|
||||||
|
|
||||||
let cache = ui.into_cache();
|
let cache = ui.into_cache();
|
||||||
let size = window.size();
|
let size = window.logical_size();
|
||||||
|
|
||||||
let _ = interfaces.insert(
|
let _ = interfaces.insert(
|
||||||
id,
|
id,
|
||||||
|
|
|
||||||
|
|
@ -58,6 +58,7 @@ where
|
||||||
) -> &mut Window<P, C> {
|
) -> &mut Window<P, C> {
|
||||||
let state = State::new(program, id, &window, system_theme);
|
let state = State::new(program, id, &window, system_theme);
|
||||||
let surface_size = state.physical_size();
|
let surface_size = state.physical_size();
|
||||||
|
let surface_version = state.surface_version();
|
||||||
let surface = compositor.create_surface(
|
let surface = compositor.create_surface(
|
||||||
window.clone(),
|
window.clone(),
|
||||||
surface_size.width,
|
surface_size.width,
|
||||||
|
|
@ -74,7 +75,7 @@ where
|
||||||
state,
|
state,
|
||||||
exit_on_close_request,
|
exit_on_close_request,
|
||||||
surface,
|
surface,
|
||||||
surface_size,
|
surface_version,
|
||||||
renderer,
|
renderer,
|
||||||
mouse_interaction: mouse::Interaction::None,
|
mouse_interaction: mouse::Interaction::None,
|
||||||
redraw_at: None,
|
redraw_at: None,
|
||||||
|
|
@ -166,7 +167,7 @@ where
|
||||||
pub exit_on_close_request: bool,
|
pub exit_on_close_request: bool,
|
||||||
pub mouse_interaction: mouse::Interaction,
|
pub mouse_interaction: mouse::Interaction,
|
||||||
pub surface: C::Surface,
|
pub surface: C::Surface,
|
||||||
pub surface_size: Size<u32>,
|
pub surface_version: u64,
|
||||||
pub renderer: P::Renderer,
|
pub renderer: P::Renderer,
|
||||||
pub redraw_at: Option<Instant>,
|
pub redraw_at: Option<Instant>,
|
||||||
preedit: Option<Preedit<P::Renderer>>,
|
preedit: Option<Preedit<P::Renderer>>,
|
||||||
|
|
@ -190,10 +191,8 @@ where
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn size(&self) -> Size {
|
pub fn logical_size(&self) -> Size {
|
||||||
let size = self.raw.inner_size().to_logical(self.raw.scale_factor());
|
self.state.logical_size()
|
||||||
|
|
||||||
Size::new(size.width, size.height)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn request_redraw(&mut self, redraw_request: RedrawRequest) {
|
pub fn request_redraw(&mut self, redraw_request: RedrawRequest) {
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@ where
|
||||||
title: String,
|
title: String,
|
||||||
scale_factor: f32,
|
scale_factor: f32,
|
||||||
viewport: Viewport,
|
viewport: Viewport,
|
||||||
|
surface_version: u64,
|
||||||
cursor_position: Option<winit::dpi::PhysicalPosition<f64>>,
|
cursor_position: Option<winit::dpi::PhysicalPosition<f64>>,
|
||||||
modifiers: winit::keyboard::ModifiersState,
|
modifiers: winit::keyboard::ModifiersState,
|
||||||
theme: Option<P::Theme>,
|
theme: Option<P::Theme>,
|
||||||
|
|
@ -72,6 +73,7 @@ where
|
||||||
title,
|
title,
|
||||||
scale_factor,
|
scale_factor,
|
||||||
viewport,
|
viewport,
|
||||||
|
surface_version: 0,
|
||||||
cursor_position: None,
|
cursor_position: None,
|
||||||
modifiers: winit::keyboard::ModifiersState::default(),
|
modifiers: winit::keyboard::ModifiersState::default(),
|
||||||
theme,
|
theme,
|
||||||
|
|
@ -81,27 +83,26 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the current [`Viewport`] of the [`State`].
|
|
||||||
pub fn viewport(&self) -> &Viewport {
|
pub fn viewport(&self) -> &Viewport {
|
||||||
&self.viewport
|
&self.viewport
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the physical [`Size`] of the [`Viewport`] of the [`State`].
|
pub fn surface_version(&self) -> u64 {
|
||||||
|
self.surface_version
|
||||||
|
}
|
||||||
|
|
||||||
pub fn physical_size(&self) -> Size<u32> {
|
pub fn physical_size(&self) -> Size<u32> {
|
||||||
self.viewport.physical_size()
|
self.viewport.physical_size()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the logical [`Size`] of the [`Viewport`] of the [`State`].
|
|
||||||
pub fn logical_size(&self) -> Size<f32> {
|
pub fn logical_size(&self) -> Size<f32> {
|
||||||
self.viewport.logical_size()
|
self.viewport.logical_size()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the current scale factor of the [`Viewport`] of the [`State`].
|
|
||||||
pub fn scale_factor(&self) -> f32 {
|
pub fn scale_factor(&self) -> f32 {
|
||||||
self.viewport.scale_factor()
|
self.viewport.scale_factor()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the current cursor position of the [`State`].
|
|
||||||
pub fn cursor(&self) -> mouse::Cursor {
|
pub fn cursor(&self) -> mouse::Cursor {
|
||||||
self.cursor_position
|
self.cursor_position
|
||||||
.map(|cursor_position| {
|
.map(|cursor_position| {
|
||||||
|
|
@ -114,32 +115,26 @@ where
|
||||||
.unwrap_or(mouse::Cursor::Unavailable)
|
.unwrap_or(mouse::Cursor::Unavailable)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the current keyboard modifiers of the [`State`].
|
|
||||||
pub fn modifiers(&self) -> winit::keyboard::ModifiersState {
|
pub fn modifiers(&self) -> winit::keyboard::ModifiersState {
|
||||||
self.modifiers
|
self.modifiers
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the current theme of the [`State`].
|
|
||||||
pub fn theme(&self) -> &P::Theme {
|
pub fn theme(&self) -> &P::Theme {
|
||||||
self.theme.as_ref().unwrap_or(&self.default_theme)
|
self.theme.as_ref().unwrap_or(&self.default_theme)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the current [`theme::Mode`] of the [`State`].
|
|
||||||
pub fn theme_mode(&self) -> theme::Mode {
|
pub fn theme_mode(&self) -> theme::Mode {
|
||||||
self.theme_mode
|
self.theme_mode
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the current background [`Color`] of the [`State`].
|
|
||||||
pub fn background_color(&self) -> Color {
|
pub fn background_color(&self) -> Color {
|
||||||
self.style.background_color
|
self.style.background_color
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the current text [`Color`] of the [`State`].
|
|
||||||
pub fn text_color(&self) -> Color {
|
pub fn text_color(&self) -> Color {
|
||||||
self.style.text_color
|
self.style.text_color
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Processes the provided window event and updates the [`State`] accordingly.
|
|
||||||
pub fn update(
|
pub fn update(
|
||||||
&mut self,
|
&mut self,
|
||||||
program: &program::Instance<P>,
|
program: &program::Instance<P>,
|
||||||
|
|
@ -154,6 +149,7 @@ where
|
||||||
size,
|
size,
|
||||||
window.scale_factor() as f32 * self.scale_factor,
|
window.scale_factor() as f32 * self.scale_factor,
|
||||||
);
|
);
|
||||||
|
self.surface_version += 1;
|
||||||
}
|
}
|
||||||
WindowEvent::ScaleFactorChanged {
|
WindowEvent::ScaleFactorChanged {
|
||||||
scale_factor: new_scale_factor,
|
scale_factor: new_scale_factor,
|
||||||
|
|
@ -165,6 +161,7 @@ where
|
||||||
size,
|
size,
|
||||||
*new_scale_factor as f32 * self.scale_factor,
|
*new_scale_factor as f32 * self.scale_factor,
|
||||||
);
|
);
|
||||||
|
self.surface_version += 1;
|
||||||
}
|
}
|
||||||
WindowEvent::CursorMoved { position, .. }
|
WindowEvent::CursorMoved { position, .. }
|
||||||
| WindowEvent::Touch(Touch {
|
| WindowEvent::Touch(Touch {
|
||||||
|
|
@ -192,11 +189,6 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Synchronizes the [`State`] with its [`Program`] and its respective
|
|
||||||
/// window.
|
|
||||||
///
|
|
||||||
/// Normally, a [`Program`] should be synchronized with its [`State`]
|
|
||||||
/// and window after calling [`Program::update`].
|
|
||||||
pub fn synchronize(
|
pub fn synchronize(
|
||||||
&mut self,
|
&mut self,
|
||||||
program: &program::Instance<P>,
|
program: &program::Instance<P>,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue