custom_frame/
custom_frame.rs1use egui_custom_frame::CustomFrame;
2use egui::{Pos2, Rect};
3
4struct TestApp {
5 tip: String,
6 frame: CustomFrame,
7}
8
9impl TestApp {
10 fn new(_cc: &eframe::CreationContext<'_>) -> Self {
11 Self {
12 tip: "This window is for testing a custom frame window.".to_string(),
13 frame: CustomFrame::default().caption(
14 Rect::from_min_max(
15 Pos2::new(0.0, 0.0),
16 Pos2::new(f32::MAX, f32::MAX) )
18 ),
19 }
20 }
21}
22
23impl eframe::App for TestApp {
24 fn clear_color(&self, _visuals: &egui::Visuals) -> [f32; 4] {
25 egui::Rgba::TRANSPARENT.to_array() }
27
28 fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
29 self.frame.show(ctx, |ui| {
31 ui.heading(&self.tip);
32 if ui.button("Close").clicked() {
33 ui.ctx().send_viewport_cmd(egui::ViewportCommand::Close);
34 }
35 });
36 }
37}
38
39fn main() -> Result<(), eframe::Error> {
40 let options = eframe::NativeOptions {
42 viewport: egui::ViewportBuilder::default()
43 .with_inner_size([320.0, 120.0])
44 .with_decorations(false) .with_transparent(true), ..Default::default()
47 };
48
49 eframe::run_native(
51 "Custom Frame Test", options, Box::new(|cc| {
54 Ok(Box::new(TestApp::new(cc)))
56 }),
57 )
58}