| Crates.io | imgui-sfml-support |
| lib.rs | imgui-sfml-support |
| version | 0.1.3 |
| created_at | 2023-12-26 18:39:45.179689+00 |
| updated_at | 2023-12-27 12:09:00.444434+00 |
| description | A SFML backend for Rust's ImGui port |
| homepage | |
| repository | https://github.com/truenotzero/imgui-sfml-support |
| max_upload_size | |
| id | 1081107 |
| size | 22,513 |
A SFML backend for Rust's ImGui port
use imgui::Context;
use imgui_sfml_support::*;
use sfml::{graphics::{RenderWindow, RenderTarget, Color}, window::{Style, ContextSettings, Event}};
fn main() {
let mut wnd = RenderWindow::new((800, 800), "Rust: SFML-ImGui", Style::CLOSE, &ContextSettings::default());
let mut imgui = Context::create();
let mut renderer = SFMLRenderer::init(&mut imgui);
let mut platform = SFMLPlatform::init(&mut imgui, &wnd);
while wnd.is_open() {
while let Some(event) = wnd.poll_event() {
platform.handle_event(&mut imgui, event);
match event {
Event::Closed => wnd.close(),
_ => (),
}
platform.prepare_frame(&mut imgui);
let ui = imgui.new_frame();
// do your imgui work here
ui.show_demo_window(&mut true);
wnd.clear(Color::BLACK);
wnd.reset_gl_states();
renderer.render(&mut imgui, &mut wnd);
wnd.display();
}
}
}
Due to how crates.io handles versioning, you should use the workaround specified below to get this working.
To fix this, change in your crate's Cargo.toml under [dependencies]:
# change these lines
sfml = "0.21.0"
imgui-sfml-support = "0.1.1"
# to these lines
sfml = { git = "https://github.com/jeremyletang/rust-sfml.git" }
imgui-sfml-support = { git = "https://github.com/truenotzero/imgui-sfml-support.git", branch = "workaround" }
I have submitted a pull request in order to fix the issue, which has been accepted!
However, due to how dependencies and versioning are handled by cargo, until rust-sfml doesn't update to 0.22.0, the workaround is needed.
This is because rust-sfml version 0.21.0 doesn't provide sf::Context::getFunction() which is required by the renderer used.
imgui-opengl-renderer: For providing the renderer
imgui-sfml: A C++ library which does the same thing
Code is MIT licensed