pub struct Context { /* private fields */ }
Expand description
An object that holds the app’s global state.
Implementations§
Source§impl Context
impl Context
Sourcepub fn load_file<F>(&self, path: impl AsRef<str>, on_loaded: F)
pub fn load_file<F>(&self, path: impl AsRef<str>, on_loaded: F)
Load file from the filesystem (desktop) or do an HTTP request (web).
path
is a filesystem path on PC and an URL on web.
Sourcepub async fn load_file_async(
&self,
path: impl AsRef<str>,
) -> Result<Vec<u8>, Error>
pub async fn load_file_async( &self, path: impl AsRef<str>, ) -> Result<Vec<u8>, Error>
Load file from the filesystem (desktop) or do an HTTP request (web).
path
is a filesystem path on PC and an URL on web.
Sourcepub fn load_file_channel(
&self,
path: impl AsRef<str>,
) -> Receiver<Result<Vec<u8>, Error>>
pub fn load_file_channel( &self, path: impl AsRef<str>, ) -> Receiver<Result<Vec<u8>, Error>>
Load file from the filesystem (desktop) or do an HTTP request (web).
path
is a filesystem path on PC and an URL on web.
The result is sent to the Receiver
.
Sourcepub fn display_width(&self) -> f32
pub fn display_width(&self) -> f32
Display width (in screen coordinates).
Accounts for dpi scale.
Sourcepub fn display_height(&self) -> f32
pub fn display_height(&self) -> f32
Display height (in screen coordinates).
Accounts for dpi scale.
Sourcepub fn buffer_width(&self) -> u32
pub fn buffer_width(&self) -> u32
Framebuffer width (in pixels).
Sourcepub fn buffer_height(&self) -> u32
pub fn buffer_height(&self) -> u32
Framebuffer height (in pixels).
Sourcepub fn dpi_scale(&self) -> f32
pub fn dpi_scale(&self) -> f32
The dpi scaling factor (screen coords to framebuffer pixels). See https://docs.rs/miniquad/latest/miniquad/conf/index.html#high-dpi-rendering for details.
Always 1.0 if high_dpi
in Config
is set to false
.
Sourcepub fn delta_time_secs(&self) -> f64
pub fn delta_time_secs(&self) -> f64
Time passed between previous and current frame (in seconds).
Sourcepub fn delta_time(&self) -> Duration
pub fn delta_time(&self) -> Duration
Time passed between previous and current frame (as std::time::Duration
).
Sourcepub fn clear_color(&mut self, color: RGBA8)
pub fn clear_color(&mut self, color: RGBA8)
Set clear/background color.
The framebuffer isn’t cleared automatically, use Context::clear()
for that.
Sourcepub fn get_key_state(&self, key: KeyCode) -> Option<InputState>
pub fn get_key_state(&self, key: KeyCode) -> Option<InputState>
Returns current input state of a key or None
if it isn’t held.
Note that InputState::Released
means that the key has just been released, not that it isn’t held.
Sourcepub fn get_all_keys(&self) -> &FxHashMap<KeyCode, InputState>
pub fn get_all_keys(&self) -> &FxHashMap<KeyCode, InputState>
Returns all keys that are down or have just been pressed/released.
Sourcepub fn is_key_down(&self, key: KeyCode) -> bool
pub fn is_key_down(&self, key: KeyCode) -> bool
Returns true
if a key is down.
Sourcepub fn is_key_pressed(&self, key: KeyCode) -> bool
pub fn is_key_pressed(&self, key: KeyCode) -> bool
Returns true
if a key has just been pressed.
Sourcepub fn is_key_released(&self, key: KeyCode) -> bool
pub fn is_key_released(&self, key: KeyCode) -> bool
Returns true
if a key has just been released.
Sourcepub fn get_key_mods(&self) -> KeyMods
pub fn get_key_mods(&self) -> KeyMods
Returns currently held key modifiers.
Sourcepub fn get_screen_mouse_pos(&self) -> (f32, f32)
pub fn get_screen_mouse_pos(&self) -> (f32, f32)
Returns current mouse position in the window (in screen coords).
Sourcepub fn get_framebuffer_mouse_pos(&self) -> (i32, i32)
pub fn get_framebuffer_mouse_pos(&self) -> (i32, i32)
Returns current mouse position in the window (in framebuffer pixels).
Sourcepub fn get_mouse_wheel(&self) -> (f32, f32)
pub fn get_mouse_wheel(&self) -> (f32, f32)
Get current mouse wheel movement.
Returns current input state of a mouse button or None
if it isn’t held.
Note that InputState::Released
means that the key has just been released, not that it isn’t held.
Returns all mouse buttons that are down or have just been pressed/released.
Returns true
if a mouse button is down.
Returns true
if a mouse button has just been pressed.
Returns true
if a mouse button has just been released.
Sourcepub fn show_mouse(&self, shown: bool)
pub fn show_mouse(&self, shown: bool)
Show or hide the mouse cursor.
Sourcepub fn show_keyboard(&self, shown: bool)
pub fn show_keyboard(&self, shown: bool)
Show or hide onscreen keyboard. This only works on Android.
Sourcepub fn set_mouse_cursor(&self, cursor_icon: CursorIcon)
pub fn set_mouse_cursor(&self, cursor_icon: CursorIcon)
Set the mouse cursor icon.
Sourcepub fn set_fullscreen(&self, fullscreen: bool)
pub fn set_fullscreen(&self, fullscreen: bool)
Set window to fullscreen or not.
Sourcepub fn get_clipboard(&self) -> Option<String>
pub fn get_clipboard(&self) -> Option<String>
Get current OS clipboard value.
Sourcepub fn set_clipboard(&self, data: impl AsRef<str>)
pub fn set_clipboard(&self, data: impl AsRef<str>)
Save value to OS clipboard.
Sourcepub fn set_window_size(&mut self, new_width: u32, new_height: u32)
pub fn set_window_size(&mut self, new_width: u32, new_height: u32)
Set the application’s window size.
Note: resizing the window does not resize the framebuffer.
It will be scaled to the whole window.
You can use Context::set_framebuffer_size()
for resizing the framebuffer.
Sourcepub fn set_framebuffer_size(&mut self, new_width: u32, new_height: u32)
pub fn set_framebuffer_size(&mut self, new_width: u32, new_height: u32)
Set the framebuffer size. The buffer will be cleared.
This doesn’t change the window size. The framebuffer will be scaled to the whole window.
Sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Clear the screen framebuffer with the current Context::clear_color()
.
Sourcepub fn draw_pixel(&mut self, x: i32, y: i32, color: RGBA8)
pub fn draw_pixel(&mut self, x: i32, y: i32, color: RGBA8)
Draw a pixels at (x, y).
Does nothing if the position is outside the screen.
Sourcepub fn draw_rect(
&mut self,
x: i32,
y: i32,
width: u32,
height: u32,
color: RGBA8,
)
pub fn draw_rect( &mut self, x: i32, y: i32, width: u32, height: u32, color: RGBA8, )
Draw a colored rectangle.
Does not panic if a part of the rectangle isn’t on screen, just draws the part that is.
Sourcepub fn draw_pixels(
&mut self,
x: i32,
y: i32,
width: u32,
height: u32,
pixels: &[RGBA8],
)
pub fn draw_pixels( &mut self, x: i32, y: i32, width: u32, height: u32, pixels: &[RGBA8], )
Fill a rectangle with provided pixels (row-major order).
Does not panic if a part of the rectangle isn’t on screen, just draws the part that is.
Sourcepub fn draw_screen(&mut self, pixels: &[RGBA8])
pub fn draw_screen(&mut self, pixels: &[RGBA8])
Fill the entire screen framebuffer at once.
Does not panic if a part of the rectangle isn’t on screen, just draws the part that is.
Sourcepub fn get_draw_buffer(&self) -> &[RGBA8] ⓘ
pub fn get_draw_buffer(&self) -> &[RGBA8] ⓘ
Returns the framebuffer’s contents.
Sourcepub fn get_mut_draw_buffer(&mut self) -> &mut [RGBA8] ⓘ
pub fn get_mut_draw_buffer(&mut self) -> &mut [RGBA8] ⓘ
Returns the framebuffer’s contents.
Can be used for drawing.
Sourcepub fn as_surface(&self) -> GenericSurface<&[RGBA8], RGBA8>
pub fn as_surface(&self) -> GenericSurface<&[RGBA8], RGBA8>
Get the draw framebuffer as a simple_blit::GenericSurface
.
Sourcepub fn as_mut_surface(&mut self) -> GenericSurface<&mut [RGBA8], RGBA8>
pub fn as_mut_surface(&mut self) -> GenericSurface<&mut [RGBA8], RGBA8>
Get the draw framebuffer as a mutable simple_blit::GenericSurface
.
Sourcepub fn set_texture_filter(&mut self, filter: FilterMode)
pub fn set_texture_filter(&mut self, filter: FilterMode)
Set the filter for the texture that is used for rendering.
Sourcepub fn get_rendering_backend(&self) -> &dyn RenderingBackend
pub fn get_rendering_backend(&self) -> &dyn RenderingBackend
Get the underlying RenderingBackend
.
Sourcepub fn get_mut_rendering_backend(&mut self) -> &mut dyn RenderingBackend
pub fn get_mut_rendering_backend(&mut self) -> &mut dyn RenderingBackend
Get the underlying RenderingBackend
.