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>

source

pub fn dimensions(&mut self, width: u32, height: u32) -> &mut Self

Set window dimensions.

source

pub fn title<S: Into<String>>(&mut self, title: S) -> &mut Self

Set a window title.

source

pub fn position(&mut self, x: i32, y: i32) -> &mut Self

Position the window at the given (x, y) coordinates of the display.

source

pub fn position_centered(&mut self) -> &mut Self

Position the window in the center of the display.

source

pub fn fullscreen(&mut self) -> &mut Self

Start window in fullscreen mode.

source

pub fn resizable(&mut self) -> &mut Self

Allow window resizing.

source

pub fn borderless(&mut self) -> &mut Self

Removes the window decoration.

source

pub fn icon<I>(&mut self, icon: I) -> &mut Self
where I: Into<Icon>,

Set a window icon.

source

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§

source§

impl<'a> Debug for WindowBuilder<'a>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V