#sdl3 #fyrox #renderer #graphics

fyrox-ui-sdl3

Integration of FyroxUI with SDL3

1 unstable release

Uses new Rust 2024

0.1.0 Aug 21, 2025

#1348 in GUI

MIT license

37KB
751 lines

fyrox-ui-sdl3

Rust library that integrates FyroxUI with SDL3.

Crates.io GitHub Actions Workflow Status API Docs dependency status GitHub License

Features

This crate provides an SDL3 backend platform and renderer for fyrox-ui.

  • The backend platform handles window/input device events,
  • The rendering backend use the SDL3 GPU API, and can be use as a render pass.

Full demo

use fyrox_ui_sdl3::FyroxUiSdl;
use sdl3::{event::Event, gpu::*, pixels};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    // initialize SDL and its video subsystem
    let sdl = sdl3::init().unwrap();
    let video_subsystem = sdl.video().unwrap();

    // create a new window
    let window = video_subsystem
        .window("Hello fyrox UI!", 1280, 720)
        .position_centered()
        .resizable()
        .build()
        .unwrap();

    let device = Device::new(ShaderFormat::SPIRV, true)
        .unwrap()
        .with_window(&window)
        .unwrap();

    // create platform and renderer
    let mut fyrox_ui = FyroxUiSdl::new(&device, &window);

    // start main loop
    let mut event_pump = sdl.event_pump().unwrap();

    'main: loop {
        for event in event_pump.poll_iter() {
            // pass all events to imgui platform
            fyrox_ui.handle_event(&event);

            if let Event::Quit { .. } = event {
                break 'main;
            }
        }

        fyrox_ui.update(1.0 / 60.0);

        let mut command_buffer = device.acquire_command_buffer()?;

        if let Ok(swapchain) = command_buffer.wait_and_acquire_swapchain_texture(&window) {
            let color_targets = [ColorTargetInfo::default()
                .with_texture(&swapchain)
                .with_load_op(LoadOp::CLEAR)
                .with_store_op(StoreOp::STORE)
                .with_clear_color(pixels::Color::RGB(128, 128, 128))];

            fyrox_ui.render(&device, &window, &event_pump, &mut command_buffer, &color_targets);

            command_buffer.submit()?;
        } else {
            println!("Swapchain unavailable, cancel work");
            command_buffer.cancel();
        }
    }

    Ok(())
}

Development

The project use just as command runner.

To check all available recipes, run:

just

To run formatters:

just fmt

Dependencies

~32–53MB
~803K SLoC