Add get_scale_factor task to window module
This commit is contained in:
parent
043f030214
commit
0dcec519be
3 changed files with 22 additions and 1 deletions
|
|
@ -63,6 +63,9 @@ pub enum Action {
|
||||||
/// Get the current logical coordinates of the window.
|
/// Get the current logical coordinates of the window.
|
||||||
GetPosition(Id, oneshot::Sender<Option<Point>>),
|
GetPosition(Id, oneshot::Sender<Option<Point>>),
|
||||||
|
|
||||||
|
/// Get the current scale factor (DPI) of the window.
|
||||||
|
GetScaleFactor(Id, oneshot::Sender<f32>),
|
||||||
|
|
||||||
/// Move the window to the given logical coordinates.
|
/// Move the window to the given logical coordinates.
|
||||||
///
|
///
|
||||||
/// Unsupported on Wayland.
|
/// Unsupported on Wayland.
|
||||||
|
|
@ -292,6 +295,13 @@ pub fn get_position(id: Id) -> Task<Option<Point>> {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Gets the scale factor of the window with the given [`Id`].
|
||||||
|
pub fn get_scale_factor(id: Id) -> Task<f32> {
|
||||||
|
task::oneshot(move |channel| {
|
||||||
|
crate::Action::Window(Action::GetScaleFactor(id, channel))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
/// Moves the window to the given logical coordinates.
|
/// Moves the window to the given logical coordinates.
|
||||||
pub fn move_to<T>(id: Id, position: Point) -> Task<T> {
|
pub fn move_to<T>(id: Id, position: Point) -> Task<T> {
|
||||||
task::effect(crate::Action::Window(Action::Move(id, position)))
|
task::effect(crate::Action::Window(Action::Move(id, position)))
|
||||||
|
|
|
||||||
|
|
@ -1291,7 +1291,7 @@ fn run_action<P, C>(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
window::Action::GetPosition(id, channel) => {
|
window::Action::GetPosition(id, channel) => {
|
||||||
if let Some(window) = window_manager.get_mut(id) {
|
if let Some(window) = window_manager.get(id) {
|
||||||
let position = window
|
let position = window
|
||||||
.raw
|
.raw
|
||||||
.inner_position()
|
.inner_position()
|
||||||
|
|
@ -1306,6 +1306,13 @@ fn run_action<P, C>(
|
||||||
let _ = channel.send(position);
|
let _ = channel.send(position);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
window::Action::GetScaleFactor(id, channel) => {
|
||||||
|
if let Some(window) = window_manager.get_mut(id) {
|
||||||
|
let scale_factor = window.raw.scale_factor();
|
||||||
|
|
||||||
|
let _ = channel.send(scale_factor as f32);
|
||||||
|
}
|
||||||
|
}
|
||||||
window::Action::Move(id, position) => {
|
window::Action::Move(id, position) => {
|
||||||
if let Some(window) = window_manager.get_mut(id) {
|
if let Some(window) = window_manager.get_mut(id) {
|
||||||
window.raw.set_outer_position(
|
window.raw.set_outer_position(
|
||||||
|
|
|
||||||
|
|
@ -80,6 +80,10 @@ where
|
||||||
self.entries.iter_mut().map(|(k, v)| (*k, v))
|
self.entries.iter_mut().map(|(k, v)| (*k, v))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get(&self, id: Id) -> Option<&Window<P, C>> {
|
||||||
|
self.entries.get(&id)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn get_mut(&mut self, id: Id) -> Option<&mut Window<P, C>> {
|
pub fn get_mut(&mut self, id: Id) -> Option<&mut Window<P, C>> {
|
||||||
self.entries.get_mut(&id)
|
self.entries.get_mut(&id)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue