egui_custom_frame

Crates.ioegui_custom_frame
lib.rsegui_custom_frame
version0.1.1
sourcesrc
created_at2024-09-13 07:36:21.522419
updated_at2024-10-02 17:23:42.990929
descriptionCustom your egui client-side window frame.
homepagehttps://github.com/a-littlebit/egui_custom_frame
repositoryhttps://github.com/a-littlebit/egui_custom_frame
max_upload_size
id1373451
size106,790
a-littlebit (a-littlebit)

documentation

README

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)))
      }),
  )
}
Commit count: 2

cargo fmt