Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update ImGui and use event-based io #688

Merged
merged 18 commits into from Jan 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 2 additions & 3 deletions imgui-examples/examples/keyboard.rs
Expand Up @@ -116,8 +116,7 @@ fn main() {
// `winit::VirtualKeyCode`. So we can query if a key
// is down based on it's virtual key code,

let home_key_idx = 65; // Hardcoded for imgui-examples only, instead use `winit::event::VirtualKeyCode::Home`
if ui.io().keys_down[home_key_idx as usize] {
if ui.is_key_down(Key::Home) {
home_counter += 1;
}
ui.text(format!("Home has been pressed for {} frames", home_counter));
Expand All @@ -134,7 +133,7 @@ fn main() {
// with arbitrary key indexes. For example, to check
// if the F1 key is been pressed

if ui.is_key_index_released(37) {
if ui.is_key_released(Key::F1) {
// Index is hardcoded for imgui-examples only, instead do this:
//if ui.is_key_index_released(winit::event::VirtualKeyCode::F1 as i32) {
f1_release_count += 1;
Expand Down
2 changes: 1 addition & 1 deletion imgui-sdl2-support/src/lib.rs
Expand Up @@ -141,7 +141,7 @@ impl SdlPlatform {
io[Key::Space] = Scancode::Space as _;
io[Key::Enter] = Scancode::Return as _;
io[Key::Escape] = Scancode::Escape as _;
io[Key::KeyPadEnter] = Scancode::KpEnter as _;
io[Key::KeypadEnter] = Scancode::KpEnter as _;
io[Key::A] = Scancode::A as _;
io[Key::C] = Scancode::C as _;
io[Key::V] = Scancode::V as _;
Expand Down
4 changes: 2 additions & 2 deletions imgui-sys/Cargo.toml
Expand Up @@ -14,8 +14,8 @@ links = "imgui"
# exclude json, lua, and the imgui subdirs (imgui/examples, imgui/docs, etc)
# ..but we need imgui/misc/freetype/ for the freetype feature
exclude = [
"third-party/*.json",
"third-party/*.lua",
"third-party/*/*.json",
"third-party/*/*.lua",
"third-party/imgui/backends/",
"third-party/imgui/docs/",
"third-party/imgui/examples/",
Expand Down
28 changes: 17 additions & 11 deletions imgui-sys/build.rs
Expand Up @@ -21,13 +21,15 @@ fn main() -> std::io::Result<()> {
// Feature flags - no extra dependencies, so these are queried as
// env-vars to avoid recompilation of build.rs
let docking_enabled = std::env::var_os("CARGO_FEATURE_DOCKING").is_some();
let freetype_enabled = std::env::var_os("CARGO_FEATURE_FREETYPE").is_some();
let wasm_enabled = std::env::var_os("CARGO_FEATURE_WASM").is_some();

let cimgui_dir = if docking_enabled {
manifest_dir.join("third-party/imgui-docking")
} else {
manifest_dir.join("third-party/imgui-master")
};
let cimgui_dir = manifest_dir.join(match (docking_enabled, freetype_enabled) {
(false, false) => "third-party/imgui-master",
(true, false) => "third-party/imgui-docking",
(false, true) => "third-party/imgui-master-freetype",
(true, true) => "third-party/imgui-docking-freetype",
});

// For projects like implot-rs we expose the path to our cimgui
// files, via `DEP_IMGUI_THIRD_PARTY` env-var, so they can build
Expand All @@ -40,6 +42,9 @@ fn main() -> std::io::Result<()> {
let mut build = cc::Build::new();
build.cpp(true);

// imgui uses C++11 stuff from v1.87 onwards
build.flag_if_supported("-std=c++11");

// Set defines for compiler
for (key, value) in DEFINES.iter() {
build.define(key, *value);
Expand All @@ -55,18 +60,20 @@ fn main() -> std::io::Result<()> {
}
// Set flag for dear imgui
build.define("IMGUI_ENABLE_FREETYPE", None);
build.define("CIMGUI_FREETYPE", None);
println!("cargo:DEFINE_IMGUI_ENABLE_FREETYPE=");

// imgui_freetype.cpp needs access to `#include "imgui.h"`.
// So we include something like '[...]/third-party/imgui-master/imgui/'
build.include(cimgui_dir.join("imgui"));
build.include(dbg!(cimgui_dir.join("imgui")));
}

// Which "all imgui" file to use
let imgui_cpp = if docking_enabled {
"include_imgui_docking.cpp"
} else {
"include_imgui_master.cpp"
let imgui_cpp = match (docking_enabled, freetype_enabled) {
(false, false) => "include_imgui_master.cpp",
(true, false) => "include_imgui_docking.cpp",
(false, true) => "include_imgui_master_freetype.cpp",
(true, true) => "include_imgui_docking_freetype.cpp",
};

// Set up compiler
Expand All @@ -79,7 +86,6 @@ fn main() -> std::io::Result<()> {
}

// Build imgui lib, suppressing warnings.
// TODO: disable linking C++ stdlib? Not sure if it's allowed.
build.warnings(false).file(imgui_cpp).compile("libcimgui.a");
}
Ok(())
Expand Down
6 changes: 0 additions & 6 deletions imgui-sys/include_imgui_docking.cpp
Expand Up @@ -8,9 +8,3 @@
#include "./third-party/imgui-docking/imgui/imgui_widgets.cpp"
#include "./third-party/imgui-docking/imgui/imgui_tables.cpp"
#include "./third-party/imgui-docking/cimgui.cpp"

#ifdef IMGUI_ENABLE_FREETYPE
#include "./third-party/imgui-docking/imgui/misc/freetype/imgui_freetype.cpp"
#endif


12 changes: 12 additions & 0 deletions imgui-sys/include_imgui_docking_freetype.cpp
@@ -0,0 +1,12 @@
// This improves build speed by only compiling a single file, and performance by
// allowing the optimizer to inline across separate object files (note that even
// when rust is built with LTO, unless the steps are taken to allow cross-lang
// LTO (tricky), the C/C++ code won't be LTOed).
#include "./third-party/imgui-docking-freetype/imgui/imgui.cpp"
#include "./third-party/imgui-docking-freetype/imgui/imgui_demo.cpp"
#include "./third-party/imgui-docking-freetype/imgui/imgui_draw.cpp"
#include "./third-party/imgui-docking-freetype/imgui/imgui_widgets.cpp"
#include "./third-party/imgui-docking-freetype/imgui/imgui_tables.cpp"
#include "./third-party/imgui-docking-freetype/cimgui.cpp"

#include "./third-party/imgui-docking-freetype/imgui/misc/freetype/imgui_freetype.cpp"
6 changes: 0 additions & 6 deletions imgui-sys/include_imgui_master.cpp
Expand Up @@ -8,9 +8,3 @@
#include "./third-party/imgui-master/imgui/imgui_widgets.cpp"
#include "./third-party/imgui-master/imgui/imgui_tables.cpp"
#include "./third-party/imgui-master/cimgui.cpp"

#ifdef IMGUI_ENABLE_FREETYPE
#include "./third-party/imgui-master/imgui/misc/freetype/imgui_freetype.cpp"
#endif


12 changes: 12 additions & 0 deletions imgui-sys/include_imgui_master_freetype.cpp
@@ -0,0 +1,12 @@
// This improves build speed by only compiling a single file, and performance by
// allowing the optimizer to inline across separate object files (note that even
// when rust is built with LTO, unless the steps are taken to allow cross-lang
// LTO (tricky), the C/C++ code won't be LTOed).
#include "./third-party/imgui-master-freetype/imgui/imgui.cpp"
#include "./third-party/imgui-master-freetype/imgui/imgui_demo.cpp"
#include "./third-party/imgui-master-freetype/imgui/imgui_draw.cpp"
#include "./third-party/imgui-master-freetype/imgui/imgui_widgets.cpp"
#include "./third-party/imgui-master-freetype/imgui/imgui_tables.cpp"
#include "./third-party/imgui-master-freetype/cimgui.cpp"

#include "./third-party/imgui-master-freetype/imgui/misc/freetype/imgui_freetype.cpp"