Use euclid::Scale to convert between physical and logical coord spaces

This commit is contained in:
meehl committed 2026-08-24 23:57:19 +02:00
1 parent 8ba72fd7df
commit 8d17f8e64f
12 files changed
+70 -155

No files matched your search

+7 -5
View File
@@ -10,7 +10,7 @@ pub fn get_screen_size(l: &Lua, _: ()) -> LuaResult<(u32, u32)> {
let PhysicalSize { width, height, .. } = ctx.window_state.size;
(width, height)
} else {
let LogicalSize { width, height, .. } = ctx.window_state.logical_size();
let LogicalSize { width, height, .. } = ctx.window_state.logical_size().cast();
(width, height)
};
Ok(size)
@@ -19,7 +19,7 @@ pub fn get_screen_size(l: &Lua, _: ()) -> LuaResult<(u32, u32)> {
pub fn get_screen_scale(l: &Lua, _: ()) -> LuaResult<f32> {
let ctx = l.app_data_ref::<Context>().unwrap();
let scale_factor = ctx.window_state.scale_factor();
Ok(scale_factor)
Ok(scale_factor.get())
}
pub fn set_window_title(l: &Lua, title: String) -> LuaResult<()> {
@@ -37,8 +37,10 @@ pub fn set_foreground(l: &Lua, _: ()) -> LuaResult<()> {
pub fn set_dpi_scale_override(l: &Lua, percent: i32) -> LuaResult<()> {
let mut ctx = l.app_data_mut::<Context>().unwrap();
match percent {
0 => ctx.window_state.scale_factor_override = None,
p if p > 0 => ctx.window_state.scale_factor_override = Some(p as f32 / 100.0),
0 => ctx.window_state.set_scale_factor_override(None),
p if p > 0 => ctx
.window_state
.set_scale_factor_override(Some(p as f32 / 100.0)),
_ => {}
}
Ok(())
@@ -46,7 +48,7 @@ pub fn set_dpi_scale_override(l: &Lua, percent: i32) -> LuaResult<()> {
pub fn get_dpi_scale_override(l: &Lua, _: ()) -> LuaResult<i32> {
let ctx = l.app_data_ref::<Context>().unwrap();
match ctx.window_state.scale_factor_override {
match ctx.window_state.scale_factor_override() {
Some(scale_factor) => Ok((scale_factor * 100.0) as i32),
None => Ok(0),
}