custom_frame/
custom_frame.rs

1use 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) // Make the whole window draggable
17        )
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() // Make sure we don't paint anything behind the rounded corners and shadow
26  }
27
28  fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
29    // Display contents in the custom frame
30    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  // Create test window
41  let options = eframe::NativeOptions {
42      viewport: egui::ViewportBuilder::default()
43                  .with_inner_size([320.0, 120.0])
44                  .with_decorations(false) // Custom frame
45                  .with_transparent(true), // For rounded corners and shadow effects
46      ..Default::default()
47  };
48
49  // Run test app
50  eframe::run_native(
51      "Custom Frame Test", // window title
52      options, // viewport options
53      Box::new(|cc| {
54          // Create test app instance
55          Ok(Box::new(TestApp::new(cc)))
56      }),
57  )
58}