Skip to content

Commit

Permalink
Add window level (#116)
Browse files Browse the repository at this point in the history
* set window level

* fmt fixes
  • Loading branch information
niknbr authored Nov 19, 2023
1 parent 0f64a84 commit e3bbb93
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
44 changes: 44 additions & 0 deletions src/appkit/window/enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,3 +134,47 @@ impl From<WindowToolbarStyle> for NSUInteger {
}
}
}

/// Describe the level of the window. Stacking of window levels take precedence over stacking
/// of windows withing each level.
#[derive(Clone, Copy, Debug)]
pub enum WindowLevel {
/// The default level for NSWindow objects.
Normal,

/// Useful for floating palettes.
Floating,

/// The level for a modal panel.
ModalPanel,

/// Reserved for the application’s main menu.
MainMenu,

/// The level for a status window.
Status,

/// The level for the dock.
DockWindow,

/// The level for a pop-up menu.
PopUpMenu,

/// The level for a screen saver.
ScreenSaver
}

impl From<WindowLevel> for NSInteger {
fn from(mode: WindowLevel) -> Self {
match mode {
WindowLevel::Normal => 0,
WindowLevel::Floating => 3,
WindowLevel::ModalPanel => 8,
WindowLevel::MainMenu => 24,
WindowLevel::Status => 25,
WindowLevel::DockWindow => 100,
WindowLevel::PopUpMenu => 101,
WindowLevel::ScreenSaver => 1000
}
}
}
15 changes: 15 additions & 0 deletions src/appkit/window/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,21 @@ impl<T> Window<T> {
}
}

/// Sets the window level, which determines the stacking order of windows on the screen.
pub fn set_level(&self, value: WindowLevel) {
let value: NSInteger = value.into();
unsafe {
let _: () = msg_send![&*self.objc, setLevel: value];
}
}

/// Removes window from the screen making it effectively hidden.
pub fn order_out(&self) {
unsafe {
let _: () = msg_send![&*self.objc, orderOut: nil];
}
}

/// Set whether the toolbar toggle button is shown. Has no effect if no toolbar exists on this
/// window.
pub fn set_shows_toolbar_button(&self, shows: bool) {
Expand Down

0 comments on commit e3bbb93

Please sign in to comment.