Struct sdl2_window::Sdl2Window

source ·
pub struct Sdl2Window {
    pub window: Window,
    pub context: GLContext,
    pub sdl_context: Sdl,
    pub video_subsystem: VideoSubsystem,
    /* private fields */
}
Expand description

A window implemented by SDL2 back-end.

Fields§

§window: Window

SDL window handle.

§context: GLContext

Allow dead code because this keeps track of the OpenGL context. Will be released on drop.

§sdl_context: Sdl

SDL context.

§video_subsystem: VideoSubsystem

Video subsystem.

Implementations§

source§

impl Sdl2Window

source

pub fn new(settings: &WindowSettings) -> Result<Self, Box<dyn Error>>

Creates a new game window for SDL2. This will initialize SDL and the video subsystem. You can retrieve both via the public fields on the Sdl2Window struct.

Examples found in repository?
examples/window_settings.rs (lines 9-13)
8
9
10
11
12
13
14
15
fn main() {
    let _ = Sdl2Window::new(
        &WindowSettings::new("SDL Window", (640, 480))
            .fullscreen(false)
            .vsync(true) // etc
    )
        .unwrap();
}
More examples
Hide additional examples
examples/window_opengl.rs (lines 11-16)
10
11
12
13
14
15
16
17
18
fn main() {
    let _ = Sdl2Window::new(
        &WindowSettings::new("SDL Window", (640, 480))
            .fullscreen(false)
            .vsync(true)
            .graphics_api(OpenGL::V2_1) // etc
    )
        .unwrap();
}
source

pub fn with_subsystem( video_subsystem: VideoSubsystem, settings: &WindowSettings ) -> Result<Self, Box<dyn Error>>

Creates a window with the supplied SDL Video subsystem.

Examples found in repository?
examples/window_subsystem.rs (lines 13-18)
9
10
11
12
13
14
15
16
17
18
19
20
fn main() {
    let sdl = sdl2::init().unwrap();
    let video_subsystem = sdl.video().unwrap();

    let _ = Sdl2Window::with_subsystem(
        video_subsystem,
        &WindowSettings::new("SDL Window", (640, 480))
            .fullscreen(false)
            .vsync(true) // etc
    )
        .unwrap();
}
source

pub fn init_joysticks(&mut self) -> Result<u32, String>

Initialize the joystick subsystem. Required before joystick input events will be returned. Returns the number available or error.

Trait Implementations§

source§

impl AdvancedWindow for Sdl2Window

source§

fn get_title(&self) -> String

Gets a copy of the title of the window.
source§

fn set_title(&mut self, value: String)

Sets the title of the window.
source§

fn get_automatic_close(&self) -> bool

Gets whether the window will automatically close when attempting to close it. Read more
source§

fn set_automatic_close(&mut self, value: bool)

Sets whether the window will automatically close when attempting to close it. If this is disabled, attempts to close the window can be detected via an Input::Close(..) event, and Window::set_should_close() can be called to actually close the window. Read more
source§

fn get_exit_on_esc(&self) -> bool

Gets whether to exit when pressing esc. Read more
source§

fn set_exit_on_esc(&mut self, value: bool)

Sets whether to exit when pressing esc. Read more
source§

fn set_capture_cursor(&mut self, value: bool)

Sets whether to capture/grab the cursor. Read more
source§

fn show(&mut self)

Shows the window. Read more
source§

fn hide(&mut self)

Hides the window. Read more
source§

fn get_position(&self) -> Option<Position>

Gets the position of window.
source§

fn set_position<P: Into<Position>>(&mut self, pos: P)

Sets the position of window. Read more
source§

fn set_size<S: Into<Size>>(&mut self, size: S)

Sets the window size. Read more
source§

fn title(self, value: String) -> Self

Sets title on window. Read more
source§

fn exit_on_esc(self, value: bool) -> Self

Sets whether to exit when pressing the Esc button. Read more
source§

fn automatic_close(self, value: bool) -> Self

Sets whether the window will automatically close when attempting to close it. If this is disabled, attempts to close the window can be detected via an Input::Close(..) event, and Window::set_should_close() can be called to actually close the window. Read more
source§

fn capture_cursor(self, value: bool) -> Self

Sets whether to capture/grab the cursor. Read more
source§

fn position<P>(self, val: P) -> Selfwhere P: Into<Position>,

Sets the position of window. Read more
source§

impl BuildFromWindowSettings for Sdl2Window

source§

fn build_from_window_settings( settings: &WindowSettings ) -> Result<Self, Box<dyn Error>>

Builds the window from a WindowSettings object. Read more
source§

impl Drop for Sdl2Window

source§

fn drop(&mut self)

Executes the destructor for this type. Read more
source§

impl OpenGLWindow for Sdl2Window

source§

fn get_proc_address(&mut self, proc_name: &str) -> ProcAddress

Returns the address of the specified OpenGL function if it exists. Read more
source§

fn is_current(&self) -> bool

Returns true if this window’s gl context is the current gl context.
source§

fn make_current(&mut self)

Make the window’s gl context the current gl context.
source§

impl Window for Sdl2Window

source§

fn should_close(&self) -> bool

Returns true if the window should close.
source§

fn set_should_close(&mut self, value: bool)

Tells the window to close or stay open.
source§

fn swap_buffers(&mut self)

Swaps render buffers. Read more
source§

fn size(&self) -> Size

Gets the size of the window.
source§

fn wait_event(&mut self) -> Event

Wait indefinitely for an input event to be available from the window.
source§

fn wait_event_timeout(&mut self, timeout: Duration) -> Option<Event>

Wait for an input event to be available from the window or for the specified timeout to be reached. Read more
source§

fn poll_event(&mut self) -> Option<Event>

Polls an input event from the window. Read more
source§

fn draw_size(&self) -> Size

Gets the draw size of the window. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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 Twhere 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 Twhere 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.