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 Engine::run
, you can open
additional windows with various configurations and render to them using the
PixState::set_window_target
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()
.title("New Window")
.dimensions(800, 600)
.position(10, 10)
.resizable()
.borderless()
.build()?;
self.windows.push(window_id);
return Ok(true);
}
Ok(false)
}
Implementations§
source§impl<'a> WindowBuilder<'a>
impl<'a> WindowBuilder<'a>
sourcepub fn dimensions(&mut self, width: u32, height: u32) -> &mut Self
pub fn dimensions(&mut self, width: u32, height: u32) -> &mut Self
Set window dimensions.
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.