mirror of
https://github.com/italicsjenga/rust_minifb.git
synced 2024-12-23 11:21:30 +11:00
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:
parent
de32daf2c1
commit
15bce84a4e
18
src/lib.rs
18
src/lib.rs
|
@ -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.
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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")]
|
||||
|
|
|
@ -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)]
|
||||
|
|
Loading…
Reference in a new issue