Struct ContextBuilder

Source
pub struct ContextBuilder { /* private fields */ }
Expand description

The entry point of the ds2d library that sets up the various subsystems, and in particular a window with a graphics context.

Implementations§

Source§

impl ContextBuilder

Source

pub fn new() -> Self

Examples found in repository?
examples/hello_world.rs (line 24)
21fn main() {
22    stderrlog::new().quiet(false).verbosity(5).init().unwrap();
23
24    let (event_loop, context) = match ds2d::ContextBuilder::new()
25        .debug(true)
26        .title("Hello World!")
27        .build()
28    {
29        Ok(ok) => ok,
30        Err(err) => {
31            error!("Could not create context: {:?}", err);
32            std::process::exit(1);
33        }
34    };
35
36    let game = HelloGame;
37
38    ds2d::run(event_loop, context, game)
39}
More examples
Hide additional examples
examples/input_keyboard.rs (line 44)
41fn main() {
42    stderrlog::new().quiet(false).verbosity(5).init().unwrap();
43
44    let (event_loop, context) = match ds2d::ContextBuilder::new()
45        .debug(true)
46        .title("Hello World!")
47        .build()
48    {
49        Ok(ok) => ok,
50        Err(err) => {
51            error!("Could not create context: {:?}", err);
52            std::process::exit(1);
53        }
54    };
55
56    let game = InputGame::new();
57
58    ds2d::run(event_loop, context, game)
59}
examples/input_mouse.rs (line 38)
35fn main() {
36    stderrlog::new().quiet(false).verbosity(5).init().unwrap();
37
38    let (event_loop, context) = match ds2d::ContextBuilder::new()
39        .debug(true)
40        .title("Hello World!")
41        .build()
42    {
43        Ok(ok) => ok,
44        Err(err) => {
45            error!("Could not create context: {:?}", err);
46            std::process::exit(1);
47        }
48    };
49
50    let game = InputGame::new();
51
52    ds2d::run(event_loop, context, game)
53}
Source

pub fn title<T: Into<String>>(self, title: T) -> Self

Set the title of the game window.

Examples found in repository?
examples/hello_world.rs (line 26)
21fn main() {
22    stderrlog::new().quiet(false).verbosity(5).init().unwrap();
23
24    let (event_loop, context) = match ds2d::ContextBuilder::new()
25        .debug(true)
26        .title("Hello World!")
27        .build()
28    {
29        Ok(ok) => ok,
30        Err(err) => {
31            error!("Could not create context: {:?}", err);
32            std::process::exit(1);
33        }
34    };
35
36    let game = HelloGame;
37
38    ds2d::run(event_loop, context, game)
39}
More examples
Hide additional examples
examples/input_keyboard.rs (line 46)
41fn main() {
42    stderrlog::new().quiet(false).verbosity(5).init().unwrap();
43
44    let (event_loop, context) = match ds2d::ContextBuilder::new()
45        .debug(true)
46        .title("Hello World!")
47        .build()
48    {
49        Ok(ok) => ok,
50        Err(err) => {
51            error!("Could not create context: {:?}", err);
52            std::process::exit(1);
53        }
54    };
55
56    let game = InputGame::new();
57
58    ds2d::run(event_loop, context, game)
59}
examples/input_mouse.rs (line 40)
35fn main() {
36    stderrlog::new().quiet(false).verbosity(5).init().unwrap();
37
38    let (event_loop, context) = match ds2d::ContextBuilder::new()
39        .debug(true)
40        .title("Hello World!")
41        .build()
42    {
43        Ok(ok) => ok,
44        Err(err) => {
45            error!("Could not create context: {:?}", err);
46            std::process::exit(1);
47        }
48    };
49
50    let game = InputGame::new();
51
52    ds2d::run(event_loop, context, game)
53}
Source

pub fn logical_size(self, size: LogicalSize<f64>) -> Self

Set the logical size of the game window (before being scaled by the DPI factor). TODO: is there a way of providing a physical size for initialization?

Source

pub fn debug(self, debug: bool) -> Self

Enable additional debug checks and output. Defaults to cfg!(debug_assertions).

Examples found in repository?
examples/hello_world.rs (line 25)
21fn main() {
22    stderrlog::new().quiet(false).verbosity(5).init().unwrap();
23
24    let (event_loop, context) = match ds2d::ContextBuilder::new()
25        .debug(true)
26        .title("Hello World!")
27        .build()
28    {
29        Ok(ok) => ok,
30        Err(err) => {
31            error!("Could not create context: {:?}", err);
32            std::process::exit(1);
33        }
34    };
35
36    let game = HelloGame;
37
38    ds2d::run(event_loop, context, game)
39}
More examples
Hide additional examples
examples/input_keyboard.rs (line 45)
41fn main() {
42    stderrlog::new().quiet(false).verbosity(5).init().unwrap();
43
44    let (event_loop, context) = match ds2d::ContextBuilder::new()
45        .debug(true)
46        .title("Hello World!")
47        .build()
48    {
49        Ok(ok) => ok,
50        Err(err) => {
51            error!("Could not create context: {:?}", err);
52            std::process::exit(1);
53        }
54    };
55
56    let game = InputGame::new();
57
58    ds2d::run(event_loop, context, game)
59}
examples/input_mouse.rs (line 39)
35fn main() {
36    stderrlog::new().quiet(false).verbosity(5).init().unwrap();
37
38    let (event_loop, context) = match ds2d::ContextBuilder::new()
39        .debug(true)
40        .title("Hello World!")
41        .build()
42    {
43        Ok(ok) => ok,
44        Err(err) => {
45            error!("Could not create context: {:?}", err);
46            std::process::exit(1);
47        }
48    };
49
50    let game = InputGame::new();
51
52    ds2d::run(event_loop, context, game)
53}
Source

pub fn build(self) -> Result<(EventLoop<()>, Context), InitError>

Create a window with an OpenGL context, and the corresponding event loop. The returned ds2d::Context can be used for initializing the Game state before starting the game loop.

Examples found in repository?
examples/hello_world.rs (line 27)
21fn main() {
22    stderrlog::new().quiet(false).verbosity(5).init().unwrap();
23
24    let (event_loop, context) = match ds2d::ContextBuilder::new()
25        .debug(true)
26        .title("Hello World!")
27        .build()
28    {
29        Ok(ok) => ok,
30        Err(err) => {
31            error!("Could not create context: {:?}", err);
32            std::process::exit(1);
33        }
34    };
35
36    let game = HelloGame;
37
38    ds2d::run(event_loop, context, game)
39}
More examples
Hide additional examples
examples/input_keyboard.rs (line 47)
41fn main() {
42    stderrlog::new().quiet(false).verbosity(5).init().unwrap();
43
44    let (event_loop, context) = match ds2d::ContextBuilder::new()
45        .debug(true)
46        .title("Hello World!")
47        .build()
48    {
49        Ok(ok) => ok,
50        Err(err) => {
51            error!("Could not create context: {:?}", err);
52            std::process::exit(1);
53        }
54    };
55
56    let game = InputGame::new();
57
58    ds2d::run(event_loop, context, game)
59}
examples/input_mouse.rs (line 41)
35fn main() {
36    stderrlog::new().quiet(false).verbosity(5).init().unwrap();
37
38    let (event_loop, context) = match ds2d::ContextBuilder::new()
39        .debug(true)
40        .title("Hello World!")
41        .build()
42    {
43        Ok(ok) => ok,
44        Err(err) => {
45            error!("Could not create context: {:?}", err);
46            std::process::exit(1);
47        }
48    };
49
50    let game = InputGame::new();
51
52    ds2d::run(event_loop, context, game)
53}

Trait Implementations§

Source§

impl Default for ContextBuilder

Source§

fn default() -> Self

Returns the “default value” for a type. 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.