### Example project creation and run Source: https://github.com/pxlsyl/egui-desktop/blob/main/cli/README.md A simple example demonstrating the creation of a new egui-desktop project and running it immediately. This sequence is typical for starting a new application. ```bash egui-desktop my-app cd my-app cargo run ``` -------------------------------- ### Run Multi-Window Example Source: https://github.com/pxlsyl/egui-desktop/blob/main/README.md Command to run the `multi_window` example, which demonstrates creating multiple native windows with independent TitleBar instances. ```bash cargo run --example multi_window ``` -------------------------------- ### Install and Run egui-desktop CLI Demo Source: https://github.com/pxlsyl/egui-desktop/blob/main/README.md Install the egui-desktop CLI tool and generate a comprehensive demo project to explore all framework features. This includes interactive theme switching and a professional project structure. ```bash # Install CLI from crates.io (if not already installed) cargo install egui-desktop-cli # Generate and run demo project egui-desktop mon-demo-projet cd my-demo-projet cargo run ``` -------------------------------- ### Run egui-desktop Examples Source: https://github.com/pxlsyl/egui-desktop/blob/main/README.md Execute various example applications to test different features of the egui-desktop framework. These commands are run from the project's root directory. ```bash cargo run --example basic_app ``` ```bash cargo run --example responsive_menu_demo ``` ```bash cargo run --example custom_title_bar ``` -------------------------------- ### Install egui-desktop CLI Source: https://github.com/pxlsyl/egui-desktop/blob/main/README.md Install the egui-desktop CLI tool globally from crates.io or from a local development path. ```bash cargo install egui-desktop-cli ``` ```bash # cargo install --path cli ``` -------------------------------- ### Complete egui-desktop Application Source: https://context7.com/pxlsyl/egui-desktop/llms.txt This example shows how to set up a complete egui-desktop application, including a custom title bar with menus, handling window resizing, and basic UI elements. It requires `egui`, `egui-desktop`, and `egui-extras` crates. ```rust use egui::{CentralPanel, Context, Vec2, ViewportBuilder, Visuals}; use egui_desktop::{ MenuItem, SubMenuItem, TitleBar, TitleBarOptions, ThemeMode, apply_rounded_corners, render_resize_handles, titlebar::HamburgerStyle, }; use egui_extras::install_image_loaders; struct DesktopApp { title_bar: TitleBar, previous_window_size: Vec2, counter: i32, } impl Default for DesktopApp { fn default() -> Self { let file_menu = MenuItem::new("File") .add_subitem(SubMenuItem::new("New").with_callback(Box::new(|| println!("New")))) .add_subitem(SubMenuItem::new("Open").with_callback(Box::new(|| println!("Open")))) .add_subitem(SubMenuItem::new("Save").with_separator()) .add_subitem(SubMenuItem::new("Exit").with_callback(Box::new(|| std::process::exit(0)))); let edit_menu = MenuItem::new("Edit") .add_subitem(SubMenuItem::new("Undo")) .add_subitem(SubMenuItem::new("Redo")); let title_bar = TitleBar::new( TitleBarOptions::new() .with_title("Desktop App") .with_theme_mode(ThemeMode::System) .with_hamburger_style(HamburgerStyle::Animated) ) .add_menu_with_submenu(file_menu) .add_menu_with_submenu(edit_menu) .add_menu_item("Help", Some(Box::new(|| println!("Help")))); Self { title_bar, previous_window_size: Vec2::new(800.0, 600.0), counter: 0, } } } impl eframe::App for DesktopApp { fn update(&mut self, ctx: &Context, frame: &mut eframe::Frame) { // Handle window resize - close menus to prevent positioning issues let current_size = ctx.input(|i| i.content_rect().size()); if current_size != self.previous_window_size { self.title_bar.close_all_menus(); self.previous_window_size = current_size; } apply_rounded_corners(frame); render_resize_handles(ctx); self.title_bar.show(ctx); CentralPanel::default().show(ctx, |ui| { ui.heading("egui-desktop Demo"); ui.separator(); ui.label("Keyboard navigation: Alt (Win/Linux) or Ctrl+F2 (macOS)"); ui.label("Arrow keys to navigate, Enter/Space to select, Escape to close"); ui.separator(); if ui.button("Increment").clicked() { self.counter += 1; } ui.label(format!("Counter: {}", self.counter)); }); } } fn main() -> Result<(), eframe::Error> { eframe::run_native( "Desktop App", eframe::NativeOptions { viewport: ViewportBuilder::default() .with_inner_size([800.0, 600.0]) .with_min_inner_size([400.0, 300.0]) .with_decorations(false), ..Default::default() }, Box::new(|cc| { install_image_loaders(&cc.egui_ctx); Ok(Box::new(DesktopApp::default())) }), ) } ``` -------------------------------- ### Install egui-desktop CLI Source: https://github.com/pxlsyl/egui-desktop/blob/main/cli/README.md Install the egui-desktop CLI tool using cargo. This command is used to set up new egui-desktop projects. ```bash cargo install egui-desktop-cli ``` -------------------------------- ### Generate New egui-desktop Project Source: https://github.com/pxlsyl/egui-desktop/blob/main/README.md Use the egui-desktop CLI to generate a new, complete starter project with a modular structure, configured dependencies, and a ready-to-run example. ```bash egui-desktop my-super-project ``` -------------------------------- ### Basic egui-desktop App Setup Source: https://context7.com/pxlsyl/egui-desktop/llms.txt Sets up a basic egui-desktop application with a custom title bar and resize handles. Ensure native decorations are disabled in `NativeOptions` and `install_image_loaders` is called to enable icon support. ```rust use eframe::egui; use egui::{Context, ViewportBuilder}; use egui_desktop::{TitleBar, TitleBarOptions, apply_rounded_corners, render_resize_handles}; use egui_extras::install_image_loaders; struct MyApp { name: String, } impl Default for MyApp { fn default() -> Self { Self { name: "My Desktop App".to_string(), } } } impl eframe::App for MyApp { fn update(&mut self, ctx: &Context, frame: &mut eframe::Frame) { // Apply native rounded corners (only called once internally) apply_rounded_corners(frame); // Render the title bar with default light theme TitleBar::new(TitleBarOptions::new().with_title(&self.name)).show(ctx); // Render resize handles for manual window resizing render_resize_handles(ctx); // Your app content egui::CentralPanel::default().show(ctx, |ui| { ui.heading("Hello from egui-desktop!"); }); } } fn main() -> Result<(), eframe::Error> { let options = eframe::NativeOptions { viewport: ViewportBuilder::default() .with_inner_size([800.0, 600.0]) .with_decorations(false), // Required: disable native decorations ..Default::default() }; eframe::run_native( "My App", options, Box::new(|cc| { install_image_loaders(&cc.egui_ctx); // Enable image loading for icons Ok(Box::new(MyApp::default())) }), ) } ``` -------------------------------- ### Initialize egui-desktop App with Custom Options Source: https://github.com/pxlsyl/egui-desktop/blob/main/README.md Initialize your egui application, disabling native window decorations and enabling image loaders. This setup is crucial for custom title bars and icon support. ```rust use egui_extras::install_image_loaders; fn main() -> Result<(), eframe::Error> { let options = eframe::NativeOptions { viewport: egui::ViewportBuilder::default() .with_decorations(false), // Disable native decorations ..Default::default() }; eframe::run_native( "My App", options, Box::new(|cc| { install_image_loaders(&cc.egui_ctx); // Enable image loading Ok(Box::new(MyApp::default())) }), ) } ``` -------------------------------- ### Configure Title Bar Theme and Mode Source: https://context7.com/pxlsyl/egui-desktop/llms.txt Demonstrates using system theme detection, built-in light/dark themes, and creating fully custom themes for the title bar. Includes an example of applying overrides to a dark theme. ```rust use egui::Color32; use egui_desktop::{TitleBar, TitleBarOptions, ThemeMode, TitleBarTheme, detect_system_dark_mode}; // Use system theme (auto-detects OS dark mode) let title_bar = TitleBar::new( TitleBarOptions::new() .with_title("System Theme App") .with_theme_mode(ThemeMode::System) ); // Check system dark mode manually let is_dark = detect_system_dark_mode(); println!("System is in dark mode: {}", is_dark); // Use built-in themes let light_theme = TitleBarTheme::light(); let dark_theme = TitleBarTheme::dark(); // Create a custom theme with all color options let custom_theme = TitleBarTheme { background_color: Color32::from_rgb(45, 45, 65), hover_color: Color32::from_rgb(65, 65, 85), close_hover_color: Color32::from_rgb(220, 20, 40), close_icon_color: Color32::from_rgb(180, 180, 180), maximize_icon_color: Color32::from_rgb(180, 180, 180), restore_icon_color: Color32::from_rgb(180, 180, 180), minimize_icon_color: Color32::from_rgb(180, 180, 180), title_color: Color32::from_rgb(220, 220, 220), menu_text_color: Color32::from_rgb(220, 220, 220), menu_text_size: 14.0, menu_hover_color: Color32::from_rgb(80, 80, 100), keyboard_selection_color: Color32::from_rgb(0, 120, 215), submenu_background_color: Color32::from_rgb(50, 50, 70), submenu_text_color: Color32::from_rgb(220, 220, 220), submenu_text_size: 14.0, submenu_hover_color: Color32::from_rgb(80, 80, 100), submenu_disabled_color: Color32::from_rgb(120, 120, 120), submenu_shortcut_color: Color32::from_rgb(150, 150, 150), submenu_border_color: Color32::from_rgb(200, 200, 200), submenu_keyboard_selection_color: Color32::from_rgb(0, 120, 215), }; // Use theme with overrides let themed = TitleBarTheme::dark_with_overrides( Some(Color32::from_rgb(30, 30, 50)), // background_color Some(Color32::from_rgb(50, 50, 70)), // hover_color None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, ); ``` -------------------------------- ### Custom Keyboard Selection Color Source: https://github.com/pxlsyl/egui-desktop/blob/main/README.md Set a custom highlight color for menu items when navigated using the keyboard. This example uses a semi-transparent red. ```rust TitleBar::new( TitleBarOptions::new() .with_title("My App") .with_keyboard_selection_color(Color32::from_rgba_premultiplied(255, 100, 100, 120)) // Custom red highlight ) .show(ctx); ``` -------------------------------- ### Create a new egui-desktop project Source: https://github.com/pxlsyl/egui-desktop/blob/main/cli/README.md Initialize a new egui-desktop project with a specified application name. This creates a directory with a complete modular starter template. ```bash egui-desktop my-awesome-app ``` -------------------------------- ### Test local egui-desktop crate version (explicit path) Source: https://github.com/pxlsyl/egui-desktop/blob/main/cli/README.md Initialize a project and specify an explicit path to the local egui-desktop crate. This is useful when the project is not created within the egui-desktop repository. ```bash egui-desktop my-app --path /path/to/egui-desktop-ui cd my-app && cargo run ``` -------------------------------- ### Apply Predefined Window Themes Source: https://github.com/pxlsyl/egui-desktop/blob/main/README.md Apply light, dark, or system-following themes to the window title bar. Ensure `ctx` is available in your scope. ```rust use egui_desktop::{TitleBar, ThemeMode, TitleBarTheme}; // Light theme TitleBar::new("My App") .with_theme_mode(ThemeMode::Light) .show(ctx); ``` ```rust // Dark theme TitleBar::new("My App") .with_theme_mode(ThemeMode::Dark) .show(ctx); ``` ```rust // System theme (follows OS) TitleBar::new("My App") .with_theme_mode(ThemeMode::System) .sync_with_system_theme() .show(ctx); ``` -------------------------------- ### Test local egui-desktop crate version (within repo) Source: https://github.com/pxlsyl/egui-desktop/blob/main/cli/README.md Run the CLI from the egui-desktop repository root to test a local version of the crate. This sets the Cargo.toml dependency to use a local path. ```bash cargo run --manifest-path cli/Cargo.toml -- my-app --local cd my-app && cargo run ``` -------------------------------- ### Build Title Bar Menus with Submenus Source: https://context7.com/pxlsyl/egui-desktop/llms.txt Shows how to create nested menus with keyboard shortcuts, callbacks, and conditional disabling. Demonstrates adding top-level menu items and sub-items. ```rust use egui_desktop::{TitleBar, TitleBarOptions, MenuItem, SubMenuItem, KeyboardShortcut}; // Create a File menu with submenus let file_menu = MenuItem::new("File") .add_subitem( SubMenuItem::new("New") .with_shortcut(KeyboardShortcut::parse("ctrl+n")) .with_callback(Box::new(|| println!("New file"))) ) .add_subitem( SubMenuItem::new("Open") .with_shortcut(KeyboardShortcut::parse("ctrl+o")) .with_callback(Box::new(|| println!("Open file"))) ) .add_subitem( SubMenuItem::new("Recent Files") .add_child( SubMenuItem::new("Document1.txt") .with_callback(Box::new(|| println!("Open Document1.txt"))) ) .add_child( SubMenuItem::new("Project") .add_child(SubMenuItem::new("main.rs").with_callback(Box::new(|| println!("Open main.rs")))) .add_child(SubMenuItem::new("lib.rs").with_callback(Box::new(|| println!("Open lib.rs")))) ) ) .add_subitem(SubMenuItem::new("Save").with_separator()) // Add separator after .add_subitem( SubMenuItem::new("Export") .disabled_if(true) // Conditionally disable ) .add_subitem( SubMenuItem::new("Exit") .with_shortcut(KeyboardShortcut::parse("alt+f4")) .with_callback(Box::new(|| std::process::exit(0))) ); let edit_menu = MenuItem::new("Edit") .add_subitem(SubMenuItem::new("Undo").with_shortcut(KeyboardShortcut::parse("ctrl+z"))) .add_subitem(SubMenuItem::new("Redo").with_shortcut(KeyboardShortcut::parse("ctrl+y"))) .add_subitem(SubMenuItem::new("Cut").disabled()); // Always disabled // Build title bar with menus let mut title_bar = TitleBar::new(TitleBarOptions::new().with_title("Menu Demo")) .add_menu_with_submenu(file_menu) .add_menu_with_submenu(edit_menu) .add_menu_item("View", Some(Box::new(|| println!("View clicked")))) .add_menu_item("Help", Some(Box::new(|| println!("Help clicked")))); ``` -------------------------------- ### Add egui-desktop Dependencies to Cargo.toml Source: https://github.com/pxlsyl/egui-desktop/blob/main/README.md Include these dependencies in your Cargo.toml file to use egui-desktop and related crates. ```toml [dependencies] egui-desktop = "0.2.4" egui_extras = { version = "0.33", features = ["all_loaders"] } eframe = "0.33" egui = "0.33" ``` -------------------------------- ### Parse Keyboard Shortcuts in Rust Source: https://github.com/pxlsyl/egui-desktop/blob/main/README.md Demonstrates parsing various keyboard shortcuts using the `KeyboardShortcut::parse` method. Supports simple keys, modifiers, function keys, and special keys. ```rust use egui_desktop::KeyboardShortcut; // Simple shortcuts with string parsing KeyboardShortcut::parse("s") // Single key KeyboardShortcut::parse("ctrl+s") // Ctrl+S KeyboardShortcut::parse("alt+s") // Alt+S KeyboardShortcut::parse("shift+s") // Shift+S KeyboardShortcut::parse("cmd+s") // Cmd+S (macOS) // Complex combinations KeyboardShortcut::parse("f3") // F3 KeyboardShortcut::parse("shift+f3") // Shift+F3 KeyboardShortcut::parse("ctrl+shift+f3") // Ctrl+Shift+F3 // Special keys KeyboardShortcut::parse("enter") // Enter KeyboardShortcut::parse("space") // Space KeyboardShortcut::parse("escape") // Escape KeyboardShortcut::parse("tab") // Tab KeyboardShortcut::parse("delete") // Delete // Numbers and punctuation KeyboardShortcut::parse("1") // Number 1 KeyboardShortcut::parse("ctrl+=") // Ctrl+= KeyboardShortcut::parse("ctrl+-") // Ctrl+- ``` -------------------------------- ### Basic egui-desktop Integration in eframe App Source: https://github.com/pxlsyl/egui-desktop/blob/main/README.md Integrate egui-desktop features like rounded corners, title bar, and resize handles into your eframe application. Ensure to call apply_rounded_corners once and render_resize_handles for interactive resizing. ```rust use egui_desktop::{TitleBar, apply_rounded_corners, render_resize_handles}; impl eframe::App for MyApp { fn update(&mut self, ctx: &egui::Context, frame: &mut eframe::Frame) { // Apply native rounded corners (call once) apply_rounded_corners(frame); // Render title bar with default light theme TitleBar::new("My App").show(ctx); // Add manual resize handles render_resize_handles(ctx); // Your app content here egui::CentralPanel::default().show(ctx, |ui| { ui.heading("Hello World!"); }); } } ``` -------------------------------- ### Customize TitleBar Appearance in Rust Source: https://github.com/pxlsyl/egui-desktop/blob/main/README.md Shows how to create and customize a `TitleBar` with options for title, background color, hover colors, title font size, and custom app icon. ```rust TitleBar::new( TitleBarOptions::new() .with_title("My App") .with_background_color(Color32::from_rgb(30, 30, 30)) .with_hover_color(Color32::from_rgb(60, 60, 60)) .with_close_hover_color(Color32::from_rgb(232, 17, 35)) .with_title_color(Color32::from_rgb(200, 200, 200)) .with_title_font_size(14.0) .with_title_visibility(true, true, false) // Platform-specific title visibility .with_custom_app_icon(include_bytes!("icon.svg"), "app-icon.svg") ) .show(ctx); ``` -------------------------------- ### Define a Custom Window Title Bar Theme Source: https://github.com/pxlsyl/egui-desktop/blob/main/README.md Create a completely custom theme for the title bar by specifying colors and sizes for various elements. Ensure `ctx` is available. ```rust use egui_desktop::{TitleBar, ThemeMode, TitleBarTheme}; // Custom theme TitleBar::new("My App") .with_theme(TitleBarTheme { background_color: Color32::from_rgb(45, 45, 65), hover_color: Color32::from_rgb(65, 65, 85), close_hover_color: Color32::from_rgb(220, 20, 40), close_icon_color: Color32::from_rgb(180, 180, 180), maximize_icon_color: Color32::from_rgb(180, 180, 180), restore_icon_color: Color32::from_rgb(180, 180, 180), minimize_icon_color: Color32::from_rgb(180, 180, 180), title_color: Color32::from_rgb(220, 220, 220), menu_text_color: Color32::from_rgb(220, 220, 220), menu_text_size: 14.0, menu_hover_color: Color32::from_rgb(80, 80, 100), keyboard_selection_color: Color32::from_rgb(0, 120, 215), submenu_background_color: Color32::from_rgb(50, 50, 70), submenu_text_color: Color32::from_rgb(220, 220, 220), submenu_text_size: 14.0, submenu_hover_color: Color32::from_rgb(80, 80, 100), submenu_disabled_color: Color32::from_rgb(120, 120, 120), submenu_shortcut_color: Color32::from_rgb(150, 150, 150), submenu_border_color: Color32::from_rgb(200, 200, 200), submenu_keyboard_selection_color: Color32::from_rgb(0, 120, 215), }) .show(ctx); ``` -------------------------------- ### Manually update Cargo.toml for local crate Source: https://github.com/pxlsyl/egui-desktop/blob/main/cli/README.md After generating a project, you can manually edit its Cargo.toml to point to a local egui-desktop crate. Adjust the path as necessary. ```toml egui-desktop = { path = "../egui-desktop-ui" } ``` -------------------------------- ### Add Menu Items to TitleBar Source: https://github.com/pxlsyl/egui-desktop/blob/main/README.md Create a menu bar by adding menu items with associated callbacks. The menu system is responsive and supports nested submenus. ```rust TitleBar::new("My App") .add_menu_item("File", Some(Box::new(|| println!("File clicked")))) .add_menu_item("Edit", Some(Box::new(|| println!("Edit clicked")))) .add_menu_item("Help", Some(Box::new(|| println!("Help clicked")))) .show(ctx); ``` -------------------------------- ### Parse and Detect Keyboard Shortcuts Source: https://context7.com/pxlsyl/egui-desktop/llms.txt Learn to parse keyboard shortcuts from strings and check if they were just pressed within the egui update loop. Supports modifiers like ctrl, alt, shift, cmd, and various keys. Use `from_string` for error handling. ```rust use egui::Context; use egui_desktop::KeyboardShortcut; // Parse shortcuts from strings let save = KeyboardShortcut::parse("ctrl+s"); let find = KeyboardShortcut::parse("ctrl+f"); let find_replace = KeyboardShortcut::parse("ctrl+shift+h"); let function_key = KeyboardShortcut::parse("f5"); let special = KeyboardShortcut::parse("ctrl+shift+f3"); // Supported modifiers: ctrl, alt, shift, cmd (macOS) // Supported keys: a-z, 0-9, f1-f12, enter, space, tab, escape, // backspace, delete, home, end, pageup, pagedown, arrows, punctuation // Check if shortcut was just pressed in update loop fn handle_shortcuts(ctx: &Context) { let save_shortcut = KeyboardShortcut::parse("ctrl+s"); if save_shortcut.just_pressed(ctx) { println!("Save triggered!"); } // Get display string for tooltips let display = save_shortcut.display_string(); // "Ctrl+S" } // Use from_string for error handling match KeyboardShortcut::from_string("ctrl+invalid") { Ok(shortcut) => println!("Valid: {}", shortcut.display_string()), Err(e) => println!("Error: {:?}", e), } ``` -------------------------------- ### Render Manual Window Resize Handles Source: https://context7.com/pxlsyl/egui-desktop/llms.txt Call `render_resize_handles` to add invisible resize handles around window edges for custom-decorated windows. This function shows the appropriate cursor on hover and sends `ViewportCommand::BeginResize` on drag. ```rust use egui::Context; use egui_desktop::render_resize_handles; impl eframe::App for MyApp { fn update(&mut self, ctx: &Context, _frame: &mut eframe::Frame) { // Render invisible resize handles on all edges and corners // Handles: top, bottom, left, right, and all four corners // Shows appropriate cursor on hover // Sends ViewportCommand::BeginResize on drag render_resize_handles(ctx); // Continue with normal rendering self.title_bar.show(ctx); egui::CentralPanel::default().show(ctx, |ui| { ui.label("Resizable window"); }); } } ``` -------------------------------- ### Global Shortcut State Management Source: https://github.com/pxlsyl/egui-desktop/blob/main/README.md This Rust code snippet demonstrates the use of `lazy_static` and `Mutex` to manage global state for keyboard shortcuts. It's crucial for detecting 'just pressed' events by tracking the previous frame's key states. ```rust lazy_static! { static ref SHORTCUT_STATES: Mutex> = Mutex::new(HashMap::new()); } ``` -------------------------------- ### Customize Control Button Colors Source: https://github.com/pxlsyl/egui-desktop/blob/main/README.md Set custom hover and icon colors for window control buttons like close, minimize, and maximize. ```rust // Custom control button colors let title_bar = TitleBar::new("My App") .with_custom_theme(TitleBarTheme { close_hover_color: egui::Color32::RED, // Red close button on hover minimize_icon_color: egui::Color32::BLUE, // Blue minimize icon maximize_icon_color: egui::Color32::GREEN, // Green maximize icon restore_icon_color: egui::Color32::YELLOW, // Yellow restore icon ..Default::default() }); ``` -------------------------------- ### Control Title Visibility Per Platform in Rust Source: https://github.com/pxlsyl/egui-desktop/blob/main/README.md Demonstrates how to control the visibility of the application title on macOS, Windows, and Linux using `TitleBarOptions::with_title_visibility`. ```rust use egui_desktop::{TitleBar, TitleBarOptions}; // Control title visibility per platform TitleBar::new( TitleBarOptions::new() .with_title("My App") .with_title_visibility( false, // macOS: hide title (follows macOS conventions) true, // Windows: show title true, // Linux: show title ) ) .show(ctx); ``` -------------------------------- ### Theme-Aware Custom Icon Coloring Source: https://github.com/pxlsyl/egui-desktop/blob/main/README.md Control custom icon colors using theme defaults or override them with specific `Color32` values. Pass `None` to revert to theme-driven coloring. ```rust title_bar.set_custom_icon_color(0, None); // use theme color // Or override: title_bar.set_custom_icon_color(0, Some(egui::Color32::from_rgb(255, 200, 0))); ``` -------------------------------- ### render_resize_handles - Manual Window Resizing Source: https://context7.com/pxlsyl/egui-desktop/llms.txt Adds invisible resize handles around window edges for custom-decorated windows. This function should be called within the `update` method of your `eframe::App`. ```APIDOC ## render_resize_handles - Manual Window Resizing ### Description Add invisible resize handles around window edges for custom-decorated windows. This function should be called within the `update` method of your `eframe::App`. ### Method (Implicitly called within the `update` method of an `eframe::App`) ### Endpoint N/A (This is a function call within an application's lifecycle) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```rust use egui::Context; use egui_desktop::render_resize_handles; // Inside your eframe::App implementation: render_resize_handles(ctx); ``` ### Response None (Renders UI elements for resizing) #### Success Response (200) N/A #### Response Example N/A ``` -------------------------------- ### Customizing TitleBar Appearance and Behavior Source: https://context7.com/pxlsyl/egui-desktop/llms.txt Configures a TitleBar using `TitleBarOptions` builder pattern for custom colors, themes, button visibility, and styling. This allows fine-grained control over the window's chrome. ```rust use egui::Color32; use egui_desktop::{TitleBar, TitleBarOptions, ThemeMode, titlebar::HamburgerStyle}; // Create a fully customized title bar let options = TitleBarOptions::new() .with_title("Custom App") .with_theme_mode(ThemeMode::Dark) .with_background_color(Color32::from_rgb(45, 45, 65)) .with_hover_color(Color32::from_rgb(65, 65, 85)) .with_close_hover_color(Color32::from_rgb(220, 20, 40)) .with_title_color(Color32::from_rgb(200, 200, 255)) .with_title_font_size(14.0) .with_menu_text_color(Color32::from_rgb(200, 200, 255)) .with_menu_hover_color(Color32::from_rgb(75, 75, 95)) .with_keyboard_selection_color(Color32::from_rgb(0, 120, 215)) .with_title_visibility(false, true, true) // macOS: hide, Windows: show, Linux: show .with_show_close_button(true) .with_show_maximize_button(true) .with_show_minimize_button(true) .with_icon_spacing(4.0) .with_hamburger_style(HamburgerStyle::Animated) .with_show_bottom_border(true); let title_bar = TitleBar::new(options); ``` -------------------------------- ### TitleBar API - Runtime Modifications Source: https://context7.com/pxlsyl/egui-desktop/llms.txt Provides methods to modify the title bar's appearance and behavior after its creation. This includes setting colors, fonts, and adding menu items dynamically. ```APIDOC ## TitleBar API - Runtime Modifications ### Description Chain methods to modify title bar appearance and behavior after creation. ### Method (Instance methods on `TitleBar` struct) ### Endpoint N/A (This is an API for constructing and modifying a UI element) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```rust use egui::Color32; use egui_desktop::{TitleBar, TitleBarOptions}; // Convenience constructors let title_bar = TitleBar::with_title("Quick Title Bar"); let icon_only = TitleBar::icon_only(); // Chain style modifications let styled = TitleBar::new(TitleBarOptions::new().with_title("Styled App")) .with_background_color(Color32::from_rgb(30, 30, 30)) .with_hover_color(Color32::from_rgb(50, 50, 50)) .with_close_hover_color(Color32::from_rgb(232, 17, 35)) .with_close_icon_color(Color32::from_rgb(200, 200, 200)) .with_title_color(Color32::from_rgb(255, 255, 255)) .with_title_font_size(13.0); // Add menus dynamically let with_menus = TitleBar::new(TitleBarOptions::new()) .add_menu_item("File", Some(Box::new(|| println!("File")))) .add_menu_item("Edit", Some(Box::new(|| println!("Edit")))) .add_menu_item("View", None); // Menu item without callback // Close all menus programmatically (e.g., on window resize) let mut title_bar = TitleBar::with_title("App"); title_bar.close_all_menus(); // Check if title should show based on platform settings if title_bar.should_show_title() { println!("Title is visible on this platform"); } ``` ### Response None (Modifies UI element behavior and appearance) #### Success Response (200) N/A #### Response Example N/A ``` -------------------------------- ### Apply Native Rounded Window Corners Source: https://context7.com/pxlsyl/egui-desktop/llms.txt Call `apply_rounded_corners` once after window creation for the main window. For secondary viewports, call `apply_rounded_corners_to_viewport` within the viewport callback. ```rust use eframe::Frame; use egui::Context; use egui_desktop::{apply_rounded_corners, apply_rounded_corners_to_viewport}; impl eframe::App for MyApp { fn update(&mut self, ctx: &Context, frame: &mut Frame) { // For main window - call once (internally guarded) apply_rounded_corners(frame); // For secondary viewports (multi-window apps) // Call in viewport callback ctx.show_viewport_deferred( egui::ViewportId::from_hash_of("settings"), egui::ViewportBuilder::default() .with_title("Settings") .with_decorations(false), move |ctx, _class| { apply_rounded_corners_to_viewport(ctx); // ... viewport UI } ); } } ``` -------------------------------- ### apply_rounded_corners - Native Window Corners Source: https://context7.com/pxlsyl/egui-desktop/llms.txt Applies platform-native rounded window corners. This function should be called once after the window is created. ```APIDOC ## apply_rounded_corners - Native Window Corners ### Description Apply platform-native rounded window corners. Call once after window creation. ### Method (Implicitly called within the `update` method of an `eframe::App`) ### Endpoint N/A (This is a function call within an application's lifecycle) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```rust use eframe::Frame; use egui::Context; use egui_desktop::apply_rounded_corners; // Inside your eframe::App implementation: apply_rounded_corners(frame); ``` ### Response None (Modifies window behavior directly) #### Success Response (200) N/A #### Response Example N/A ``` -------------------------------- ### TitleBar API - Runtime Modifications Source: https://context7.com/pxlsyl/egui-desktop/llms.txt Modify title bar appearance and behavior after creation by chaining methods. Supports convenience constructors, style modifications, dynamic menu additions, and checking platform-specific title visibility. ```rust use egui::Color32; use egui_desktop::{TitleBar, TitleBarOptions}; // Convenience constructors let title_bar = TitleBar::with_title("Quick Title Bar"); let icon_only = TitleBar::icon_only(); // Chain style modifications let styled = TitleBar::new(TitleBarOptions::new().with_title("Styled App")) .with_background_color(Color32::from_rgb(30, 30, 30)) .with_hover_color(Color32::from_rgb(50, 50, 50)) .with_close_hover_color(Color32::from_rgb(232, 17, 35)) .with_close_icon_color(Color32::from_rgb(200, 200, 200)) .with_title_color(Color32::from_rgb(255, 255, 255)) .with_title_font_size(13.0); // Add menus dynamically let with_menus = TitleBar::new(TitleBarOptions::new()) .add_menu_item("File", Some(Box::new(|| println!("File")))) .add_menu_item("Edit", Some(Box::new(|| println!("Edit")))) .add_menu_item("View", None); // Menu item without callback // Close all menus programmatically (e.g., on window resize) let mut title_bar = TitleBar::with_title("App"); title_bar.close_all_menus(); // Check if title should show based on platform settings if title_bar.should_show_title() { println!("Title is visible on this platform"); } ``` -------------------------------- ### apply_rounded_corners_to_viewport - Native Window Corners for Viewports Source: https://context7.com/pxlsyl/egui-desktop/llms.txt Applies platform-native rounded window corners to secondary viewports in multi-window applications. This should be called within the viewport's callback. ```APIDOC ## apply_rounded_corners_to_viewport - Native Window Corners for Viewports ### Description Apply platform-native rounded window corners to secondary viewports (multi-window apps). Call this within the viewport callback. ### Method (Implicitly called within a viewport callback) ### Endpoint N/A (This is a function call within an application's lifecycle) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```rust use egui::Context; use egui_desktop::apply_rounded_corners_to_viewport; // Inside your egui::Context::show_viewport_deferred callback: apply_rounded_corners_to_viewport(ctx); ``` ### Response None (Modifies window behavior directly) #### Success Response (200) N/A #### Response Example N/A ``` -------------------------------- ### Add Custom Icons to Title Bar Source: https://context7.com/pxlsyl/egui-desktop/llms.txt Integrate custom image, drawn, or animated icons into the title bar. Each icon can have an optional callback, tooltip, and keyboard shortcut for interaction. Animated icons allow for dynamic visual feedback. ```rust use egui::{Color32, ImageSource, Painter, Rect, Ui}; use egui_desktop::{TitleBar, TitleBarOptions, KeyboardShortcut}; use egui_desktop::titlebar::main::{CustomIcon, IconAnimationState, AnimationCtx}; let mut title_bar = TitleBar::new(TitleBarOptions::new().with_title("Icons Demo")) // Add image icon from embedded bytes .add_icon( CustomIcon::Image(ImageSource::Bytes { uri: std::borrow::Cow::Borrowed("settings.svg"), bytes: egui::load::Bytes::Static(include_bytes!("settings.svg")), }), Some(Box::new(|| println!("Settings clicked!"))), Some("Settings".to_string()), Some(KeyboardShortcut::parse("ctrl+,")) ) // Add custom drawn icon .add_icon( CustomIcon::Drawn(Box::new(|painter: &Painter, rect: Rect, color: Color32| { painter.circle_filled(rect.center(), rect.width() * 0.4, color); })), Some(Box::new(|| println!("Notification clicked!"))), Some("Notifications".to_string()), Some(KeyboardShortcut::parse("ctrl+n")) ) // Add animated icon with state management .add_animated_icon( Box::new(|painter, rect, color, state: &mut IconAnimationState, ctx: AnimationCtx| { // state.hover_t: 0..1 smooth hover transition // state.press_t: 0..1 smooth press transition // state.progress: generic progress you control // ctx.time, ctx.delta_seconds, ctx.hovered, ctx.pressed let scale = 1.0 + state.hover_t * 0.1; let radius = rect.width() * 0.3 * scale; painter.circle_filled(rect.center(), radius, color); }), Some(Box::new(|| println!("Animated icon clicked!"))), Some("Animated".to_string()), None ); // In update loop, handle icon shortcuts impl eframe::App for MyApp { fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) { self.title_bar.handle_icon_shortcuts(ctx); self.title_bar.show(ctx); } } // Override icon color at runtime title_bar.set_custom_icon_color(0, Some(Color32::from_rgb(255, 200, 0))); title_bar.set_custom_icon_color(0, None); // Revert to theme color ``` -------------------------------- ### Set Custom Application Icon in Title Bar Source: https://context7.com/pxlsyl/egui-desktop/llms.txt Configure a custom application icon for the title bar, supporting various image formats like SVG, PNG, and JPEG from embedded bytes. This feature is available on Windows and Linux. ```rust use egui_desktop::{TitleBar, TitleBarOptions}; // From embedded bytes (supports SVG, PNG, JPEG) let title_bar = TitleBar::new(TitleBarOptions::new().with_title("My App")) .with_app_icon(include_bytes!("app_icon.svg"), "app_icon.svg"); // Using TitleBarOptions builder let options = TitleBarOptions::new() .with_title("My App") .with_app_icon(include_bytes!("app_icon.png"), "app_icon.png"); let title_bar = TitleBar::new(options); // Inline SVG icon let title_bar = TitleBar::new(TitleBarOptions::new().with_title("Custom Icon")) .with_app_icon( b"", "custom-icon.svg" ); ``` -------------------------------- ### Add Custom Icons to Title Bar Source: https://github.com/pxlsyl/egui-desktop/blob/main/README.md Integrate custom image or drawn icons into the title bar, optionally with click callbacks and keyboard shortcuts. Ensure `ctx` is available and handle shortcuts in your app's update loop. ```rust use egui_desktop::{TitleBar, CustomIcon, KeyboardShortcut}; TitleBar::new("My App") // Custom app icon (supports SVG, PNG, JPEG, etc.) .with_custom_app_icon(include_bytes!("icon.svg"), "app-icon.svg") // Add custom icon with callback and tooltip .add_icon( CustomIcon::Image(ImageSource::from_bytes("settings.svg", include_bytes!("settings.svg"))), Some(Box::new(|| println!("Settings clicked!"))), Some("Settings".to_string()), None // No keyboard shortcut ) // Add custom icon with keyboard shortcut .add_icon( CustomIcon::Drawn(Box::new(|painter, rect, color| { // Custom drawing code for notification bell painter.circle_filled(rect.center(), rect.width() * 0.4, color); })), Some(Box::new(|| println!("Notifications clicked!"))), Some("Notifications".to_string()), Some(KeyboardShortcut::parse("ctrl+n")) // Ctrl+N shortcut ) .show(ctx); // Don't forget to handle shortcuts in your app's update loop impl eframe::App for MyApp { fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) { self.title_bar.handle_icon_shortcuts(ctx); // ... rest of your app logic } } ``` -------------------------------- ### Hamburger Style Options for Title Bar Source: https://github.com/pxlsyl/egui-desktop/blob/main/README.md Choose between a static (three lines) or animated (bars to dots transition) hamburger icon for the title bar's menu when space is limited. The static style is the default. ```rust use egui_desktop::{TitleBar, TitleBarOptions, titlebar::HamburgerStyle}; TitleBar::new( TitleBarOptions::new() .with_title("My App") .with_hamburger_style(HamburgerStyle::Static) // Three fixed lines (default) // .with_hamburger_style(HamburgerStyle::Animated) // Bars ↔ dots with transition when open ) .show(ctx); ``` -------------------------------- ### Dynamically Disable Menu Items Source: https://github.com/pxlsyl/egui-desktop/blob/main/README.md Conditionally disable menu items based on application state using the `.disabled_if()` method. Ensure to request a repaint when the condition changes to update the UI. ```rust use egui_desktop::{TitleBar, TitleBarOptions, menu::SubMenuItem}; let mut title_bar = TitleBar::new(TitleBarOptions::new().with_title("My App")); // Add menu items with conditional disabling title_bar.add_menu( MenuItem::new("File") .add_subitem(SubMenuItem::new("New") .with_callback(Box::new(|| println!("New file")))) .add_subitem(SubMenuItem::new("Save") .with_callback(Box::new(|| println!("Save file")))) .add_subitem(SubMenuItem::new("Export") .with_callback(Box::new(|| println!("Export file"))) .disabled_if(!has_unsaved_changes())) // Disable if no unsaved changes ); title_bar.show(ctx); ``` ```rust // In your app's update loop if some_condition_changed { // Request title bar redraw to update disabled states ctx.request_repaint(); } ``` -------------------------------- ### Hide Title Bar Bottom Border Source: https://github.com/pxlsyl/egui-desktop/blob/main/README.md Control the visibility of the title bar's bottom border to achieve a seamless integration with the main application content. Set to `false` to hide it. ```rust use egui_desktop::{TitleBar, TitleBarOptions}; TitleBar::new( TitleBarOptions::new() .with_title("My App") .with_show_bottom_border(false) // Hide bottom border for seamless integration ) .show(ctx); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.