Skip to main content

RaylibRender

Struct RaylibRender 

Source
pub struct RaylibRender {
    pub background_color: Color,
    /* private fields */
}
Expand description

Primary raylib-backed renderer for Cotis applications.

Owns the window handle (behind a mutex), the raylib drawing thread, loaded fonts, and a path-keyed texture cache. Implements CotisRenderer for crate::drawables::RaylibDrawable streams and Cotis context traits in crate::cotis.

§Construction

Fields§

§background_color: Color

Clear color used at the start of each frame.

Implementations§

Source§

impl RaylibRender

Source

pub fn auto_start() -> Self

Creates a renderer with a gray transparent background and a default 1000×1000 resizable window.

Source

pub fn new(background_color: Color) -> Self

Creates a renderer with the given background clear color and a default 1000×1000 resizable window.

Source

pub fn new_custom( raylib_builder: RaylibBuilder<'_>, background_color: Color, ) -> Self

Creates a renderer from a custom RaylibBuilder.

Source

pub fn get_handle(&mut self) -> MutexGuard<'_, RayRenderHandle>

Locks and returns the raylib handle.

§Panics

Panics if the mutex is poisoned.

Source

pub fn lock_handle(&self) -> MutexGuard<'_, RayRenderHandle>

Locks and returns the raylib handle (immutable receiver).

§Panics

Panics if the mutex is poisoned.

Source

pub fn get_thread(&self) -> &RaylibThread

Returns the raylib drawing thread.

Must be passed to drawing calls on the thread that created the window.

Source

pub fn thread(&self) -> &RaylibThread

Returns the raylib drawing thread.

Alias for Self::get_thread.

Source

pub fn get_raylib( &mut self, ) -> (MutexGuard<'_, RayRenderHandle>, &mut RaylibThread)

Returns the locked handle and drawing thread together for low-level drawing.

§Panics

Panics if the mutex is poisoned.

Source

pub fn window_should_close(&self) -> bool

Returns whether the window close flag is set.

§Panics

Panics if the mutex is poisoned.

Source

pub fn load_font_and_keep( &mut self, file_name: &str, ) -> Result<usize, RaylibError>

Loads a font at size 16 and registers it in the font table.

Returns a font ID to store in TextConfig::font_id. IDs are assigned in load order starting at 0 and are never reused.

§Errors

Returns RaylibError if raylib cannot load the font file.

Source

pub fn load_font_ex_and_keep( &mut self, file_name: &str, font_size: i32, chars: Option<&str>, filter: Option<TextureFilter>, ) -> Result<usize, RaylibError>

Loads a font with custom size, optional character subset, and texture filter.

Returns a font ID (0-based, monotonic) for use in TextConfig::font_id. Additional pixel sizes requested during drawing are queued and loaded at the start of the next frame.

§Errors

Returns RaylibError if raylib cannot load the font file.

Source

pub fn delta_time(&self) -> f32

Returns the elapsed time between the previous and current frame, in seconds.

§Panics

Panics if the mutex is poisoned.

Source

pub fn get_shared_handle(&self) -> SharedRaylibHandle

Returns a clone of the shared raylib handle for cross-thread input polling.

Pair with Self::thread when calling raylib drawing APIs from the owning thread.

Source

pub fn shared_handle(&self) -> SharedRaylibHandle

Returns a clone of the shared raylib handle.

Alias for Self::get_shared_handle.

Source

pub fn image_cache(&self) -> &HashMap<String, Arc<Texture2D>>

Returns the path-keyed texture cache populated by translate_generic_image.

Source

pub fn image_cache_mut(&mut self) -> &mut HashMap<String, Arc<Texture2D>>

Returns a mutable reference to the texture cache for manual preload or inspection.

Source

pub fn fonts(&self) -> Arc<Mutex<HashMap<usize, ScalableFont>>>

Returns the shared font table used during drawing and text measurement.

Source§

impl RaylibRender

Source

pub fn translate_generic_image( &mut self, image: &dyn RaylibLoadableImage, ) -> Box<dyn Texture2DHolder>

Loads a texture from a path-based image, caching the result by file path.

On cache hit, returns the existing texture. On miss, loads via raylib with TextureFilter::TEXTURE_FILTER_POINT filtering.

§Panics

Panics if raylib cannot load the file at the given path.

Trait Implementations§

Source§

impl CotisFrameContext for RaylibRender

Source§

fn get_delta_time(&self) -> f32

Returns delta time in seconds since the previous frame.
Source§

impl<'b> CotisRenderer<Box<dyn RaylibDrawable + 'b>> for RaylibRender

Source§

fn draw_frame( &mut self, render_commands: impl Iterator<Item = Box<dyn RaylibDrawable + 'b>>, )

Source§

impl<T: RaylibDrawable> CotisRenderer<RenderTList<T, ()>> for RaylibRender

Source§

fn draw_frame( &mut self, render_commands: impl Iterator<Item = RenderTList<T, ()>>, )

Source§

impl<T: RaylibDrawable, L: RaylibDrawable + IsRenderList> CotisRenderer<RenderTList<T, L>> for RaylibRender

Source§

fn draw_frame( &mut self, render_commands: impl Iterator<Item = RenderTList<T, L>>, )

Source§

impl<'b> CotisRendererAsync<Box<dyn RaylibDrawable + 'b>> for RaylibRender

Source§

async fn draw_frame( &mut self, render_commands: impl Iterator<Item = Box<dyn RaylibDrawable + 'b>>, )

Source§

impl<T: RaylibDrawable> CotisRendererAsync<RenderTList<T, ()>> for RaylibRender

Source§

async fn draw_frame( &mut self, render_commands: impl Iterator<Item = RenderTList<T, ()>>, )

Source§

impl<T: RaylibDrawable, L: RaylibDrawable + IsRenderList> CotisRendererAsync<RenderTList<T, L>> for RaylibRender

Source§

async fn draw_frame( &mut self, render_commands: impl Iterator<Item = RenderTList<T, L>>, )

Source§

impl CotisWindowContext for RaylibRender

Source§

fn window_dimensions(&self) -> Dimensions

Returns the current drawable window dimensions. Read more
Source§

impl MouseProvider for RaylibRender

Source§

fn get_mouse_position(&self) -> Vector2

Returns mouse position in pixel coordinates.
Source§

fn mouse_button_down(&self, button: MouseButton) -> bool

Returns whether the button is currently down.
Source§

fn get_mouse_wheel_move_v(&self) -> Vector2

Returns mouse wheel delta for the current frame. Read more
Source§

impl<Manager> RenderCompatibleWith<Manager> for RaylibRender

Source§

fn init(&mut self, _layout_manager: &mut Manager)

Source§

impl RendererTextMeasuringProvider<TextConfig> for RaylibRender

Source§

fn provide_measurer(&mut self) -> Box<TextMeasurer<'_, TextConfig>>

Returns a measuring function used by layout code.
Source§

impl SimpleKeyboardProvider for RaylibRender

Source§

fn get_pressed_keys(&self) -> IndexSet<KeyboardKey>

Returns keys currently pressed.
Source§

impl SimpleTextProvider for RaylibRender

Source§

fn get_pressed_chars(&self) -> Vec<char>

Returns entered characters in backend-provided order.

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> CotisRenderContext for T

Source§

impl<H, TailTarget, Source, Idx> Embed<RenderTList<H, TailTarget>, There<Idx>> for Source
where TailTarget: IsRenderList, Source: Embed<TailTarget, Idx>,

Source§

fn embed(self) -> RenderTList<H, TailTarget>

Converts self into Target.
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.