use custom_callback::{comms::viewer::ControlViewer, panel::Control};
use rerun::external::{eframe, re_log, re_memory, re_sdk_comms, re_viewer};
use std::net::Ipv4Addr;
#[global_allocator]
static GLOBAL: re_memory::AccountingAllocator<mimalloc::MiMalloc> =
re_memory::AccountingAllocator::new(mimalloc::MiMalloc);
const CONTROL_PORT: u16 = 8888;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let main_thread_token = re_viewer::MainThreadToken::i_promise_i_am_on_the_main_thread();
re_log::setup_logging();
re_crash_handler::install_crash_handlers(re_viewer::build_info());
let rx = re_sdk_comms::serve(
&Ipv4Addr::UNSPECIFIED.to_string(),
re_sdk_comms::DEFAULT_SERVER_PORT + 1,
Default::default(),
)?;
let viewer = ControlViewer::connect(format!("127.0.0.1:{CONTROL_PORT}")).await?;
let handle = viewer.handle();
tokio::spawn(async move {
viewer.run().await;
});
let mut native_options = re_viewer::native::eframe_options(None);
native_options.viewport = native_options
.viewport
.with_app_id("rerun_custom_callback_example");
let app_env = re_viewer::AppEnvironment::Custom("My Custom Callback".to_owned());
let startup_options = re_viewer::StartupOptions::default();
let window_title = "Rerun Control Panel";
eframe::run_native(
window_title,
native_options,
Box::new(move |cc| {
re_viewer::customize_eframe_and_setup_renderer(cc)?;
let mut rerun_app = re_viewer::App::new(
main_thread_token,
re_viewer::build_info(),
&app_env,
startup_options,
cc,
);
rerun_app.add_receiver(rx);
Ok(Box::new(Control::new(rerun_app, handle)))
}),
)?;
Ok(())
}