Skip to content

External drawing of imgui-rs is carried out on the running windows platform, supporting d3d11 and vulkan backends

Notifications You must be signed in to change notification settings

lngex/imgui-rs-overlay

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

39 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

imgui-rs-overlay

依赖imgui-rswindows-rs

平台

仅支持windows

版本

示例

Cargo.toml

imgui-rs-overlay={git = "https://github.com/lngex/imgui-rs-overlay"}
imgui = "0.12.0"

EXE

img_1.png

main.rs

use imgui::Condition;
use std::borrow::Cow;
use imgui_rs_overlay::{Result, window::{Windows, WindowsOptions}};


fn main() -> Result<()> {
    let mut index = 2usize;
    let items = ["深色", "高亮", "经典"];
    let mut app = Windows::new(&WindowsOptions::default())?;
    app.run(move |ui, style| {
        ui.window("imgui")
            .resizable(false)
            .size([150.0, 100.0], Condition::FirstUseEver)
            .movable(true)
            .build(|| {
                if ui.combo("主题", &mut index, &items, |item| {
                    Cow::Owned(String::from(*item))
                }) {
                    match index {
                        0 => { style.use_dark_colors() }
                        1 => { style.use_light_colors() }
                        2 => { style.use_classic_colors() }
                        _ => { style }
                    };
                }
                ui.text(format!("FPS: {:.2}", ui.io().framerate));
                ui.text("你好世界!");
            });
        true
    })?;
    Ok(())
}

DLL

img_2.png

lib.rs

use imgui_rs_overlay::window::{GetCurrentProcessId, WindowsOptions};
use imgui_rs_overlay::{key_down, OverlayTarget};
use std::os::raw::c_void;

#[no_mangle]
pub unsafe extern "stdcall" fn DllMain(hinst_dll: *mut c_void, fdw_reason: u32, _lpv_reserved: *mut c_void) -> i32 {
    match fdw_reason {
        1 => {
            let dll = hinst_dll as usize;
            std::thread::spawn(move || {
                let result = imgui_rs_overlay::window::Windows::new(&WindowsOptions {
                    title: "pva".to_string(),
                    overlay_target: OverlayTarget::WindowOfProcess(GetCurrentProcessId()), // 获取当前窗口
                    dll_hinstance:dll, // 模块句柄 释放时使用
                    ..WindowsOptions::default()
                });
                let mut windows = result.unwrap();
                let _ = windows.run(|ui, _style| {
                    ui.show_demo_window(&mut true);
                    !key_down!(35) // end退出后DLL也会自动卸载
                });
                true
            });
            1
        }
        _ => {
            1
        }
    }
}

About

External drawing of imgui-rs is carried out on the running windows platform, supporting d3d11 and vulkan backends

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages