mirror of
https://github.com/eliasstepanik/imgui-rs.git
synced 2026-01-10 04:58:34 +00:00
Identified and implemented workaround for viewport callbacks not being triggered when windows are dragged outside the main window. Root cause: ConfigFlags::VIEWPORTS_ENABLE is reset after first render() call due to an issue in the imgui-rs bindings or Dear ImGui itself. Workaround: Re-apply the viewport flag before each new_frame() call using viewport_issue_fix::apply_viewport_fix(). Added: - viewport_issue_fix module with apply_viewport_fix() function - Debug and solution examples demonstrating the issue and fix - Integration tests for the workaround - Comprehensive documentation of findings in VIEWPORT_FIX_SUMMARY.md This is a temporary workaround until the root cause is fixed in imgui-rs or the Dear ImGui library. Co-Authored-By: Elias Stepanik <eliasstepanik@proton.me>
65 lines
2.5 KiB
Rust
65 lines
2.5 KiB
Rust
//! Test for viewport fix
|
|
|
|
#[test]
|
|
#[cfg(feature = "docking")]
|
|
fn test_viewport_fix_works() {
|
|
use imgui::*;
|
|
|
|
// Create context without using test helper to avoid premature new_frame
|
|
let mut ctx = Context::create();
|
|
|
|
// Initialize IO
|
|
ctx.io_mut().display_size = [1280.0, 720.0];
|
|
ctx.io_mut().delta_time = 1.0 / 60.0;
|
|
|
|
// Apply fix BEFORE any frames
|
|
viewport_issue_fix::apply_viewport_fix(&mut ctx);
|
|
|
|
// Set platform backend
|
|
struct TestBackend;
|
|
impl PlatformViewportBackend for TestBackend {
|
|
fn create_window(&mut self, _: &mut Viewport) {
|
|
println!("create_window called!");
|
|
}
|
|
fn destroy_window(&mut self, _: &mut Viewport) {}
|
|
fn show_window(&mut self, _: &mut Viewport) {}
|
|
fn set_window_pos(&mut self, _: &mut Viewport, _: [f32; 2]) {}
|
|
fn get_window_pos(&mut self, _: &mut Viewport) -> [f32; 2] { [0.0, 0.0] }
|
|
fn set_window_size(&mut self, _: &mut Viewport, _: [f32; 2]) {}
|
|
fn get_window_size(&mut self, _: &mut Viewport) -> [f32; 2] { [0.0, 0.0] }
|
|
fn set_window_focus(&mut self, _: &mut Viewport) {}
|
|
fn get_window_focus(&mut self, _: &mut Viewport) -> bool { false }
|
|
fn get_window_minimized(&mut self, _: &mut Viewport) -> bool { false }
|
|
fn set_window_title(&mut self, _: &mut Viewport, _: &str) {}
|
|
fn set_window_alpha(&mut self, _: &mut Viewport, _: f32) {}
|
|
fn update_window(&mut self, _: &mut Viewport) {}
|
|
fn render_window(&mut self, _: &mut Viewport) {}
|
|
fn swap_buffers(&mut self, _: &mut Viewport) {}
|
|
fn create_vk_surface(&mut self, _: &mut Viewport, _: u64, _: &mut u64) -> i32 { 0 }
|
|
}
|
|
|
|
ctx.set_platform_backend(TestBackend);
|
|
|
|
// Build fonts to avoid issues
|
|
ctx.fonts().build_rgba32_texture();
|
|
|
|
// First frame
|
|
assert!(ctx.io().config_flags.contains(ConfigFlags::VIEWPORTS_ENABLE));
|
|
let _ui = ctx.new_frame();
|
|
let _dd = ctx.render();
|
|
|
|
// Without fix, flags would be reset here
|
|
// With fix, we reapply them
|
|
viewport_issue_fix::apply_viewport_fix(&mut ctx);
|
|
|
|
// Second frame - flags should still be set
|
|
assert!(ctx.io().config_flags.contains(ConfigFlags::VIEWPORTS_ENABLE));
|
|
let _ui = ctx.new_frame();
|
|
let _dd = ctx.render();
|
|
|
|
// Verify fix continues to work
|
|
viewport_issue_fix::apply_viewport_fix(&mut ctx);
|
|
assert!(ctx.io().config_flags.contains(ConfigFlags::VIEWPORTS_ENABLE));
|
|
|
|
println!("Viewport fix test passed!");
|
|
} |