Added Topmost (always on top) functionality to Windows (#159)

* Added always on top functionality for Windows

* Added always on top functionality for Windows

* Made topmost method in Window public so that the topmost attribute can be defined either at or after creation time as opposed to just at creation time. This allows the topmost functionality to be toggled during the programs runtime as opposed to only at window creation
This commit is contained in:
phillvancejr 2020-08-28 15:14:49 -04:00 committed by GitHub
parent de32daf2c1
commit 15bce84a4e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 47 additions and 19 deletions

View file

@ -352,6 +352,24 @@ impl Window {
self.0.set_position(x, y)
}
///
/// Makes the window the topmost window and makes it stay always on top. This is useful if you
/// want the window to float above all over windows
///
/// # Examples
///
/// ```no_run
/// # use minifb::*;
/// # let mut window = Window::new("Test", 640, 400, WindowOptions::default()).unwrap();
/// // Makes the window always on top
/// window.topmost(true);
/// ```
///
#[inline]
pub fn topmost(&self, topmost: bool) {
self.0.topmost(topmost)
}
///
/// Sets the background color that is used with update_with_buffer.
/// In some cases there will be a blank area around the buffer depending on the ScaleMode that has been set.

View file

@ -410,6 +410,11 @@ impl Window {
unsafe { mfb_set_position(self.window_handle, x as i32, y as i32) }
}
#[inline]
pub fn topmost(&self, topmost: bool) {
unsafe { mfb_topmost(self.window_handle, topmost) }
}
pub fn get_size(&self) -> (usize, usize) {
(
self.shared_data.width as usize,

View file

@ -129,6 +129,11 @@ impl Window {
}
}
pub fn topmost(&self, _topmost: bool) {
// We will just do nothing until it is implemented so that nothing breaks
()
}
pub fn get_size(&self) -> (usize, usize) {
match *self {
#[cfg(feature = "x11")]

View file

@ -646,6 +646,25 @@ impl Window {
}
}
#[inline]
pub fn topmost(&self, topmost: bool) {
unsafe {
winuser::SetWindowPos(
self.window.unwrap(),
if topmost == true {
winuser::HWND_TOPMOST
} else {
winuser::HWND_TOP
},
0,
0,
0,
0,
winuser::SWP_SHOWWINDOW | winuser::SWP_NOSIZE | winuser::SWP_NOMOVE,
)
};
}
#[inline]
pub fn get_size(&self) -> (usize, usize) {
(self.width as usize, self.height as usize)
@ -990,25 +1009,6 @@ impl Window {
Some(t)
}
}
#[inline]
fn topmost(&self, topmost: bool) {
unsafe {
winuser::SetWindowPos(
self.window.unwrap(),
if topmost == true {
winuser::HWND_TOPMOST
} else {
winuser::HWND_TOP
},
0,
0,
0,
0,
winuser::SWP_SHOWWINDOW | winuser::SWP_NOSIZE | winuser::SWP_NOMOVE,
);
}
}
}
#[derive(Clone)]