Struct 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 8-12)
7fn main() {
8    let _ = Sdl2Window::new(
9        &WindowSettings::new("SDL Window", (640, 480))
10            .fullscreen(false)
11            .vsync(true), // etc
12    )
13    .unwrap();
14}
More examples
Hide additional examples
examples/window_opengl.rs (lines 10-15)
9fn main() {
10    let _ = Sdl2Window::new(
11        &WindowSettings::new("SDL Window", (640, 480))
12            .fullscreen(false)
13            .vsync(true)
14            .graphics_api(OpenGL::V2_1), // etc
15    )
16    .unwrap();
17}
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 12-17)
8fn main() {
9    let sdl = sdl2::init().unwrap();
10    let video_subsystem = sdl.video().unwrap();
11
12    let _ = Sdl2Window::with_subsystem(
13        video_subsystem,
14        &WindowSettings::new("SDL Window", (640, 480))
15            .fullscreen(false)
16            .vsync(true), // etc
17    )
18    .unwrap();
19}
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) -> Self
where 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 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>,

Source§

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>,

Source§

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.