use super::*;
pub fn enable_native_ime_ui() {
let _ = sdl3::hint::set("SDL_HINT_IME_SHOW_UI", "1");
}
#[cfg(feature = "opengl3-renderer")]
pub fn init_for_opengl(
imgui: &mut Context,
window: &Window,
gl_context: &GLContext,
glsl_version: &str,
) -> Result<(), Sdl3BackendError> {
let glsl = CString::new(glsl_version).map_err(|_| Sdl3BackendError::InvalidGlslVersion)?;
let sdl_window = window.raw();
let sdl_gl = unsafe { gl_context.raw() };
with_context(imgui, "init_for_opengl()", || {
unsafe {
if !ffi::ImGui_ImplSDL3_InitForOpenGL_Rust(sdl_window, sdl_gl as *mut c_void) {
return Err(Sdl3BackendError::Sdl3InitFailed);
}
}
init_opengl3_impl(glsl.as_ptr())
})
}
#[cfg(feature = "opengl3-renderer")]
pub fn init_for_opengl_default(
imgui: &mut Context,
window: &Window,
gl_context: &GLContext,
) -> Result<(), Sdl3BackendError> {
let sdl_window = window.raw();
let sdl_gl = unsafe { gl_context.raw() };
with_context(imgui, "init_for_opengl_default()", || {
unsafe {
if !ffi::ImGui_ImplSDL3_InitForOpenGL_Rust(sdl_window, sdl_gl as *mut c_void) {
return Err(Sdl3BackendError::Sdl3InitFailed);
}
}
init_opengl3_impl(std::ptr::null())
})
}
pub fn init_platform_for_opengl(
imgui: &mut Context,
window: &Window,
gl_context: &GLContext,
) -> Result<(), Sdl3BackendError> {
let sdl_window = window.raw();
let sdl_gl = unsafe { gl_context.raw() };
with_context(imgui, "init_platform_for_opengl()", || {
unsafe {
if !ffi::ImGui_ImplSDL3_InitForOpenGL_Rust(sdl_window, sdl_gl as *mut c_void) {
return Err(Sdl3BackendError::Sdl3InitFailed);
}
}
Ok(())
})
}
pub fn init_for_other(imgui: &mut Context, window: &Window) -> Result<(), Sdl3BackendError> {
let sdl_window = window.raw();
with_context(imgui, "init_for_other()", || {
unsafe {
if !ffi::ImGui_ImplSDL3_InitForOther_Rust(sdl_window) {
return Err(Sdl3BackendError::Sdl3InitFailed);
}
}
Ok(())
})
}
pub fn init_for_vulkan(imgui: &mut Context, window: &Window) -> Result<(), Sdl3BackendError> {
let sdl_window = window.raw();
with_context(imgui, "init_for_vulkan()", || {
unsafe {
if !ffi::ImGui_ImplSDL3_InitForVulkan_Rust(sdl_window) {
return Err(Sdl3BackendError::Sdl3InitFailed);
}
}
Ok(())
})
}
pub fn init_for_d3d(imgui: &mut Context, window: &Window) -> Result<(), Sdl3BackendError> {
let sdl_window = window.raw();
with_context(imgui, "init_for_d3d()", || {
unsafe {
if !ffi::ImGui_ImplSDL3_InitForD3D_Rust(sdl_window) {
return Err(Sdl3BackendError::Sdl3InitFailed);
}
}
Ok(())
})
}
pub fn init_for_metal(imgui: &mut Context, window: &Window) -> Result<(), Sdl3BackendError> {
let sdl_window = window.raw();
with_context(imgui, "init_for_metal()", || {
unsafe {
if !ffi::ImGui_ImplSDL3_InitForMetal_Rust(sdl_window) {
return Err(Sdl3BackendError::Sdl3InitFailed);
}
}
Ok(())
})
}
pub unsafe fn init_for_sdl_renderer(
imgui: &mut Context,
window: &Window,
renderer: *mut sdl3_sys::render::SDL_Renderer,
) -> Result<(), Sdl3BackendError> {
let sdl_window = window.raw();
with_context(imgui, "init_for_sdl_renderer()", || {
unsafe {
if !ffi::ImGui_ImplSDL3_InitForSDLRenderer_Rust(sdl_window, renderer) {
return Err(Sdl3BackendError::Sdl3InitFailed);
}
}
Ok(())
})
}
pub fn init_for_sdl_gpu(imgui: &mut Context, window: &Window) -> Result<(), Sdl3BackendError> {
let sdl_window = window.raw();
with_context(imgui, "init_for_sdl_gpu()", || {
unsafe {
if !ffi::ImGui_ImplSDL3_InitForSDLGPU_Rust(sdl_window) {
return Err(Sdl3BackendError::Sdl3InitFailed);
}
}
Ok(())
})
}
#[cfg(feature = "sdlrenderer3-renderer")]
pub fn init_for_canvas(
imgui: &mut Context,
window: &Window,
canvas: &WindowCanvas,
) -> Result<(), Sdl3BackendError> {
let sdl_window = window.raw();
let sdl_renderer = canvas.raw();
with_context(imgui, "init_for_canvas()", || {
unsafe {
if !ffi::ImGui_ImplSDL3_InitForSDLRenderer_Rust(sdl_window, sdl_renderer) {
return Err(Sdl3BackendError::Sdl3InitFailed);
}
if !sdlrenderer3_backend::dear_imgui_backend_sdlrenderer3_init(
sdl_renderer as *mut std::ffi::c_void,
) {
ffi::ImGui_ImplSDL3_Shutdown_Rust();
return Err(Sdl3BackendError::Renderer3InitFailed);
}
}
Ok(())
})
}
#[cfg(feature = "opengl3-renderer")]
pub fn shutdown_for_opengl(imgui: &mut Context) {
with_context(imgui, "shutdown_for_opengl()", shutdown_opengl3_impl);
}
pub fn shutdown(imgui: &mut Context) {
with_context(imgui, "shutdown()", shutdown_platform_impl);
}
#[cfg(feature = "sdlrenderer3-renderer")]
pub fn shutdown_for_canvas(imgui: &mut Context) {
with_context(imgui, "shutdown_for_canvas()", shutdown_sdlrenderer3_impl);
}
#[cfg(feature = "opengl3-renderer")]
pub fn new_frame(imgui: &mut Context) {
with_context(imgui, "new_frame()", new_frame_opengl3_impl);
}
pub fn sdl3_new_frame(imgui: &mut Context) {
with_context(imgui, "sdl3_new_frame()", sdl3_new_frame_impl);
}
#[cfg(feature = "sdlrenderer3-renderer")]
pub fn canvas_new_frame(imgui: &mut Context) {
with_context(imgui, "canvas_new_frame()", new_frame_sdlrenderer3_impl);
}