window task for setting resize increments

This commit is contained in:
JL710 2024-10-11 12:24:05 +02:00 committed by Héctor Ramón Jiménez
parent f5f075e5cd
commit 00b60d819b
No known key found for this signature in database
GPG key ID: 7CC46565708259A7
2 changed files with 22 additions and 0 deletions

View file

@ -167,6 +167,9 @@ pub enum Action {
/// Set the window to be resizable or not. /// Set the window to be resizable or not.
SetResizable(Id, bool), SetResizable(Id, bool),
/// Set the window size increment.
SetResizeIncrements(Id, Option<Size>),
} }
/// Subscribes to the frames of the window of the running application. /// Subscribes to the frames of the window of the running application.
@ -400,6 +403,15 @@ pub fn set_min_size<T>(id: Id, size: Option<Size>) -> Task<T> {
task::effect(crate::Action::Window(Action::SetMinSize(id, size))) task::effect(crate::Action::Window(Action::SetMinSize(id, size)))
} }
/// Set the window size increment.
///
/// This is usually used by apps such as terminal emulators that need "blocky" resizing.
pub fn set_resize_increments<T>(id: Id, increments: Option<Size>) -> Task<T> {
task::effect(crate::Action::Window(Action::SetResizeIncrements(
id, increments,
)))
}
/// Show the [system menu] at cursor position. /// Show the [system menu] at cursor position.
/// ///
/// [system menu]: https://en.wikipedia.org/wiki/Common_menus_in_Microsoft_Windows#System_menu /// [system menu]: https://en.wikipedia.org/wiki/Common_menus_in_Microsoft_Windows#System_menu

View file

@ -1311,6 +1311,16 @@ fn run_action<P, C>(
})); }));
} }
} }
window::Action::SetResizeIncrements(id, increments) => {
if let Some(window) = window_manager.get_mut(id) {
window.raw.set_resize_increments(increments.map(|x| {
winit::dpi::LogicalSize {
width: x.width,
height: x.height,
}
}));
}
}
window::Action::ChangeTitle(id, title) => { window::Action::ChangeTitle(id, title) => {
if let Some(window) = window_manager.get_mut(id) { if let Some(window) = window_manager.get_mut(id) {
window.raw.set_title(&title); window.raw.set_title(&title);