summaryrefslogtreecommitdiff
path: root/engine/src
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2025-10-30 15:52:13 +0100
committerHampusM <hampus@hampusmat.com>2025-11-06 22:35:45 +0100
commita523c4308703c41215c8688c1c9bf1eb3908ddac (patch)
treed3958d8ae2b9dba5b206d41c803a366e20d394ad /engine/src
parent3cc7283a0452fe62939cc8ce7b52ff93e8781a2f (diff)
feat(engine): add scale factor to Window struct
Diffstat (limited to 'engine/src')
-rw-r--r--engine/src/windowing.rs30
-rw-r--r--engine/src/windowing/window.rs16
2 files changed, 44 insertions, 2 deletions
diff --git a/engine/src/windowing.rs b/engine/src/windowing.rs
index 69adae9..2bfdb31 100644
--- a/engine/src/windowing.rs
+++ b/engine/src/windowing.rs
@@ -195,6 +195,29 @@ fn update_stuff(
actions.remove_comps::<(Window,)>(*window_ent_id);
}
+ MessageFromApp::WindowScaleFactorChanged(window_id, scale_factor) => {
+ let Some(window_ent_id) =
+ windows.get(&window_id).map(|(_, ent_id)| ent_id)
+ else {
+ tracing::error!(
+ wid = ?window_id,
+ "Window does not exist in windowing context"
+ );
+ continue;
+ };
+
+ let Some(window_ent) = entity_obtainer.get_entity(*window_ent_id) else {
+ continue;
+ };
+
+ let Some(mut window) = window_ent.get_mut::<Window>() else {
+ continue;
+ };
+
+ window.set_scale_factor(scale_factor);
+
+ window.set_changed();
+ }
MessageFromApp::KeyboardKeyStateChanged(key, key_state) => {
keyboard.set_key_state(key, key_state);
}
@@ -405,6 +428,7 @@ enum MessageFromApp
WindowCreated(Uid, Arc<WinitWindow>, WindowCreationAttributes),
WindowResized(WindowId, Dimens<u32>),
WindowCloseRequested(WindowId),
+ WindowScaleFactorChanged(WindowId, f64),
KeyboardKeyStateChanged(Key, KeyState),
MouseMoved
{
@@ -605,6 +629,12 @@ impl ApplicationHandler for App
self.focused_window_id = None;
}
}
+ WindowEvent::ScaleFactorChanged { scale_factor, inner_size_writer: _ } => {
+ self.send_message(MessageFromApp::WindowScaleFactorChanged(
+ WindowId::from_inner(window_id),
+ scale_factor,
+ ));
+ }
_ => {}
}
}
diff --git a/engine/src/windowing/window.rs b/engine/src/windowing/window.rs
index 79b2102..627bdec 100644
--- a/engine/src/windowing/window.rs
+++ b/engine/src/windowing/window.rs
@@ -87,11 +87,12 @@ pub struct CreationReady;
#[non_exhaustive]
pub struct Window
{
- wid: Id,
pub title: Cow<'static, str>,
pub cursor_visible: bool,
pub cursor_grab_mode: CursorGrabMode,
+ wid: Id,
inner_size: Dimens<u32>,
+ scale_factor: f64,
}
impl Window
@@ -106,17 +107,23 @@ impl Window
&self.inner_size
}
+ pub fn scale_factor(&self) -> f64
+ {
+ self.scale_factor
+ }
+
pub(crate) fn new(
winit_window: &winit::window::Window,
creation_attrs: &CreationAttributes,
) -> Self
{
Self {
- wid: Id::from_inner(winit_window.id()),
title: creation_attrs.title().to_string().into(),
cursor_visible: true,
cursor_grab_mode: CursorGrabMode::None,
+ wid: Id::from_inner(winit_window.id()),
inner_size: winit_window.inner_size().into(),
+ scale_factor: winit_window.scale_factor(),
}
}
@@ -130,6 +137,11 @@ impl Window
{
self.inner_size = inner_size;
}
+
+ pub(crate) fn set_scale_factor(&mut self, scale_factor: f64)
+ {
+ self.scale_factor = scale_factor;
+ }
}
#[derive(Debug, Component)]