Files
egui/tests/test_inline_glow_paint/src/main.rs
T
Emil Ernerfeldt 27559ef3fd Rename Panel methods (#8192)
The three methods for showing a `Panel` are now:

* `panel.show`: always show the panel.
* `panel.show_collapsible`: show or hide the panel, with a slide
animation in between.
* `Panel::show_switched`: animate between two different panels: a
thin/collapsed one and a thick/expanded one.
2026-05-24 12:22:32 +02:00

68 lines
2.0 KiB
Rust

#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] // hide console window on Windows in release
#![expect(
// it's a test:
clippy::undocumented_unsafe_blocks,
clippy::unwrap_used,
rustdoc::missing_crate_level_docs
)]
// Test that we can paint to the screen using glow directly.
use eframe::egui;
use eframe::glow;
fn main() -> Result<(), Box<dyn std::error::Error>> {
env_logger::init(); // Log to stderr (if you run with `RUST_LOG=debug`).
let options = eframe::NativeOptions {
renderer: eframe::Renderer::Glow,
..Default::default()
};
eframe::run_native(
"My test app",
options,
Box::new(|_cc| Ok(Box::<MyTestApp>::default())),
)?;
Ok(())
}
#[derive(Default)]
struct MyTestApp {}
impl eframe::App for MyTestApp {
fn ui(&mut self, ui: &mut egui::Ui, frame: &mut eframe::Frame) {
egui::Panel::top("top").show(ui, |ui| {
ui.label("This is a test of painting directly with glow.");
});
use glow::HasContext as _;
let gl = frame.gl().unwrap();
#[expect(unsafe_code)]
unsafe {
gl.disable(glow::SCISSOR_TEST);
gl.viewport(0, 0, 100, 100);
gl.clear_color(1.0, 0.0, 1.0, 1.0); // purple
gl.clear(glow::COLOR_BUFFER_BIT);
}
egui::Window::new("Floating Window").show(ui.ctx(), |ui| {
ui.label("The background should be purple.");
ui.label(format!(
"is_pointer_over_egui: {}",
ui.is_pointer_over_egui()
));
ui.label(format!(
"egui_wants_pointer_input: {}",
ui.egui_wants_pointer_input()
));
ui.label(format!(
"egui_is_using_pointer: {}",
ui.egui_is_using_pointer()
));
if let Some(pos) = ui.pointer_latest_pos() {
ui.label(format!("layer_id_at: {:?}", ui.layer_id_at(pos)));
}
});
}
}