Renderer

Struct Renderer 

Source
pub struct Renderer<'a> { /* private fields */ }
Expand description

Represents the context for the renderer

Implementations§

Source§

impl<'a> Renderer<'a>

Source

pub fn new( texture_creator: &'a TextureCreator<impl Any>, imgui_context: &mut Context, ) -> Result<Self, RenderError>

Constructs a new Renderer

§Examples

Make sure to call after setting the imgui font.

let sdl_context = sdl3::init().unwrap();
let video_subsystem = sdl_context.video().unwrap();

let window = video_subsystem
    .window("rust-sdl3 example", 800, 600)
    .position_centered()
    .resizable()
    .high_pixel_density()
    .build()
    .unwrap();
let mut canvas = window.into_canvas();
let texture_creator = canvas.texture_creator();

let mut imgui_context = imgui::Context::create();
imgui_context.set_ini_filename(None);

imgui_context.fonts().add_font(&[imgui::FontSource::DefaultFontData { config: None, }]);

let mut renderer = imgui_sdl3_renderer::Renderer::new(&texture_creator, &mut imgui_context).unwrap();
Source

pub fn render( &mut self, draw_data: &DrawData, canvas: &mut Canvas<impl RenderTarget>, ) -> Result<(), RenderError>

Renders the draw_data to the canvas

The canvas must be the canvas that owns the [TextureCreator] that was passed to Self::new and must be the same canvas on each call

§Examples
/* ... */
let mut canvas = window.into_canvas();
let texture_creator = canvas.texture_creator();

/* ... */
let mut renderer = imgui_sdl3_renderer::Renderer::new(&texture_creator, &mut imgui_context).unwrap();

'main loop {
canvas.clear();
/* ... */
let ui = imgui_context.new_frame();
ui.show_demo_window(&mut true);
renderer.render(imgui_context.render(), &mut canvas).unwrap();
/* ... */
canvas.present();
}

Auto Trait Implementations§

§

impl<'a> Freeze for Renderer<'a>

§

impl<'a> RefUnwindSafe for Renderer<'a>

§

impl<'a> !Send for Renderer<'a>

§

impl<'a> !Sync for Renderer<'a>

§

impl<'a> Unpin for Renderer<'a>

§

impl<'a> UnwindSafe for Renderer<'a>

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.