2 个版本
0.1.2 | 2022年12月26日 |
---|---|
0.1.1 | 2022年12月26日 |
#2 in #im-gui
665KB
17K SLoC
reaper-imgui
cfillion ReaImGui Reaper 扩展的绑定。
由于所有都是 c 类型,它们不安全且难以使用。但至少,它能够工作,并且可以像在 rea-rs
crate 中一样直接使用,也可以在 reaper-rs
中使用。但最后一个应该使用最新版本发布,以便可以选配功能。最小示例 crate 可以在 GitHub 仓库中找到:[https://github.com/Levitanus/reaper-imgui/tree/master/hello_world_example](https://github.com/Levitanus/reaper-imgui/tree/master/hello_world_example)
use rea_rs::{PluginContext, Reaper, Timer};
use rea_rs_macros::reaper_extension_plugin;
use reaper_imgui::{
Context, DrawList, DrawListSplitter, Font, ImGui, Image, ImageSet, ListClipper, Resource,
TextFilter, Viewport,
};
use std::{error::Error, mem::MaybeUninit};
use c_str_macro::c_str;
#[derive(Debug)]
struct GuiRunner {
imgui: ImGui,
ctx: Context,
}
impl Timer for GuiRunner {
fn run(&mut self) -> Result<(), Box<dyn Error>> {
let (mut open, mut flags) = (MaybeUninit::new(true), MaybeUninit::zeroed());
unsafe {
self.imgui.Begin(
self.ctx,
c_str!("my window").as_ptr(),
open.as_mut_ptr(),
flags.as_mut_ptr(),
)
};
let open = unsafe { open.assume_init() };
println!("ctx: {:?} open: {:?}", self.ctx, open);
if open {
unsafe {
self.imgui.Text(self.ctx, c_str!("Hello World!").as_ptr());
}
unsafe { self.imgui.End(self.ctx) };
} else {
unsafe { self.imgui.End(self.ctx) };
self.stop();
}
Ok(())
}
fn id_string(&self) -> String {
"im_gui_example".to_string()
}
}
#[reaper_extension_plugin]
fn plugin_main(context: PluginContext) -> Result<(), Box<dyn Error>> {
println!("plugin main");
Reaper::init_global(context);
let rpr = Reaper::get_mut();
let imgui = ImGui::load(context);
let mut zero = MaybeUninit::zeroed();
let ctx = unsafe { imgui.CreateContext(c_str!("my context").as_ptr(), zero.as_mut_ptr()) };
rpr.register_timer(Box::new(GuiRunner { imgui, ctx }));
Ok(())
}
依赖
~12MB
~236K SLoC