Struct pix_engine::window::WindowBuilder
source · [−]pub struct WindowBuilder<'a> { /* private fields */ }
Expand description
Opens a new window by providing several window configuration functions.
In addition to the primary window created for you when calling PixEngine::run
, you can open
additional windows with various configurations and render to them using the
PixState::with_window
method.
Example
fn on_key_pressed(&mut self, s: &mut PixState, event: KeyEvent) -> PixResult<bool> {
if let Key::O = event.key {
let window_id = s.window()
.with_title("New Window")
.with_dimensions(800, 600)
.position(10, 10)
.resizable()
.borderless()
.build()?;
self.windows.push(window_id);
return Ok(true);
}
Ok(false)
}
Implementations
sourceimpl<'a> WindowBuilder<'a>
impl<'a> WindowBuilder<'a>
sourcepub fn with_dimensions(&mut self, width: u32, height: u32) -> &mut Self
pub fn with_dimensions(&mut self, width: u32, height: u32) -> &mut Self
Set window dimensions.
sourcepub fn with_title<S: Into<String>>(&mut self, title: S) -> &mut Self
pub fn with_title<S: Into<String>>(&mut self, title: S) -> &mut Self
Set a window title.
sourcepub fn position(&mut self, x: i32, y: i32) -> &mut Self
pub fn position(&mut self, x: i32, y: i32) -> &mut Self
Position the window at the given (x, y)
coordinates of the display.
sourcepub fn position_centered(&mut self) -> &mut Self
pub fn position_centered(&mut self) -> &mut Self
Position the window in the center of the display.
sourcepub fn fullscreen(&mut self) -> &mut Self
pub fn fullscreen(&mut self) -> &mut Self
Start window in fullscreen mode.
sourcepub fn borderless(&mut self) -> &mut Self
pub fn borderless(&mut self) -> &mut Self
Removes the window decoration.
sourcepub fn build(&mut self) -> PixResult<WindowId>
pub fn build(&mut self) -> PixResult<WindowId>
Create a new window from the WindowBuilder
and return its id.
Errors
If the renderer fails to create a new window, then an error is returned.
Possible errors include the title containing a nul
character, the position or dimensions
being invalid values or overlowing and an internal renderer error such as running out of
memory or a software driver issue.
Trait Implementations
Auto Trait Implementations
impl<'a> !RefUnwindSafe for WindowBuilder<'a>
impl<'a> !Send for WindowBuilder<'a>
impl<'a> !Sync for WindowBuilder<'a>
impl<'a> Unpin for WindowBuilder<'a>
impl<'a> !UnwindSafe for WindowBuilder<'a>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more