#egui #frame #window #ui #eframe #client-side #shadow

egui_custom_frame

Custom your egui client-side window frame

2 releases

0.1.1 Oct 2, 2024
0.1.0 Sep 13, 2024

#1084 in GUI

MIT/Apache

27KB
175 lines

egui_custom_frame

Custom your egui client-side window frame.

Example Usage

use egui_custom_frame::CustomFrame;
use egui::{Pos2, Rect};

struct TestApp {
  tip: String,
  frame: CustomFrame,
}

impl TestApp {
  fn new(_cc: &eframe::CreationContext<'_>) -> Self {
    Self {
      tip: "This window is for testing a custom frame window.".to_string(),
      frame: CustomFrame::default().caption(
        Rect::from_min_max(
          Pos2::new(0.0, 0.0),
          Pos2::new(f32::MAX, f32::MAX) // Make the whole window draggable
        )
      ),
    }
  }
}

impl eframe::App for TestApp {  
  fn clear_color(&self, _visuals: &egui::Visuals) -> [f32; 4] {
    egui::Rgba::TRANSPARENT.to_array() // Make sure we don't paint anything behind the rounded corners and shadow
  }

  fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
    // Display contents in the custom frame
    self.frame.show(ctx, |ui| {
      ui.heading(&self.tip);
      if ui.button("Close").clicked() {
          ui.ctx().send_viewport_cmd(egui::ViewportCommand::Close);
      }
    });
  }
}

fn main() -> Result<(), eframe::Error> {
  // Create test window
  let options = eframe::NativeOptions {
      viewport: egui::ViewportBuilder::default()
                  .with_inner_size([320.0, 120.0])
                  .with_decorations(false) // Custom frame
                  .with_transparent(true), // For rounded corners and shadow effects
      ..Default::default()
  };

  // Run test app
  eframe::run_native(
      "Custom Frame Test", // window title
      options, // viewport options
      Box::new(|cc| {
          // Create test app instance
          Ok(Box::new(TestApp::new(cc)))
      }),
  )
}

Dependencies

~7–24MB
~393K SLoC