Skip to content

Commit

Permalink
window task for setting resize increments
Browse files Browse the repository at this point in the history
  • Loading branch information
JL710 committed Oct 11, 2024
1 parent 886f472 commit 5a6fd77
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
12 changes: 12 additions & 0 deletions runtime/src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,9 @@ pub enum Action {

/// Set the window to be resizable or not.
SetResizable(Id, bool),

/// Set the window size increment.
SetResizeIncrements(Id, Option<Size>),
}

/// Subscribes to the frames of the window of the running application.
Expand Down Expand Up @@ -404,6 +407,15 @@ pub fn set_min_size<T>(id: Id, size: Option<Size>) -> Task<T> {
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.
///
/// [system menu]: https://en.wikipedia.org/wiki/Common_menus_in_Microsoft_Windows#System_menu
Expand Down
10 changes: 10 additions & 0 deletions winit/src/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1315,6 +1315,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) => {
if let Some(window) = window_manager.get_mut(id) {
window.raw.set_title(&title);
Expand Down

0 comments on commit 5a6fd77

Please sign in to comment.