Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add window level #116

Merged
merged 2 commits into from
Nov 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading