### Simple egui_dnd Example Source: https://github.com/lucasmerlin/hello_egui/blob/main/crates/egui_dnd/README.md This is a basic example demonstrating the usage of egui_dnd. It requires setting up the drag and drop context and then using the provided widgets. ```rust use egui::*; use egui_dnd::{DragDropUi, State}; fn main() { let mut state = State::new(); egui_web::App::new(move |ctx| { egui::CentralPanel::default().show(ctx, |ui| { let mut drag_drop_ui = DragDropUi::new(&mut state); ui.label("Drag and drop example"); let mut items = vec!["item 1", "item 2", "item 3"]; drag_drop_ui.ui(ui, |ui, item| { ui.label(item); }); }); }); } ``` -------------------------------- ### Minimal egui_suspense Example Source: https://github.com/lucasmerlin/hello_egui/blob/main/crates/egui_suspense/README.md This example shows how to use EguiSuspense to display loading, error, and retry UI elements while waiting for asynchronous data. It requires the `eframe` and `egui_suspense` crates. The callback function simulates an asynchronous operation that can either succeed with data or fail with an error. ```rust use eframe::egui; use egui::CentralPanel; use egui_suspense::EguiSuspense; pub fn main() -> eframe::Result<()> { let mut suspense = EguiSuspense::reloadable(|cb| { std::thread::spawn(move || { std::thread::sleep(std::time::Duration::from_secs(1)); cb(if rand::random() { Ok("Hello".to_string()) } else { Err("OOPSIE WOOPSIE!".to_string()) }); }); }); eframe::run_simple_native( "DnD Simple Example", Default::default(), move |ctx, _frame| { CentralPanel::default().show(ctx, |ui| { // This will show a spinner while loading and an error message with a // retry button if the callback returns an error. suspense.ui(ui, |ui, data, state| { ui.label(format!("Data: {:?}", data)); if ui.button("Reload").clicked() { state.reload(); } }); }); }, ) } ``` -------------------------------- ### Basic egui_inbox Usage Example Source: https://github.com/lucasmerlin/hello_egui/blob/main/crates/egui_inbox/README.md Demonstrates how to use UiInbox to receive messages from a spawned thread within an egui application. It shows how to send a message from a thread and update the UI state upon reception. ```rust use eframe::egui; use egui::CentralPanel; use egui_inbox::UiInbox; pub fn main() -> eframe::Result<()> { let inbox = UiInbox::new(); let mut state = None; eframe::run_simple_native( "DnD Simple Example", Default::default(), move |ctx, _frame| { CentralPanel::default().show(ctx, |ui| { // `read` will return an iterator over all pending messages if let Some(last) = inbox.read(ui).last() { state = last; } // There also is a `replace` method that you can use as a shorthand for the above: // inbox.replace(ui, &mut state); ui.label(format!("State: {:?}", state)); if ui.button("Async Task").clicked() { state = Some("Waiting for async task to complete".to_string()); let tx = inbox.sender(); std::thread::spawn(move || { std::thread::sleep(std::time::Duration::from_secs(1)); // Send will return an error if the receiver has been dropped // but unless you have a long running task that will send multiple messages // you can just ignore the error tx.send(Some("Hello from another thread!".to_string())).ok(); }); } }); }, ) } ``` -------------------------------- ### Minimal egui_form Example with garde Source: https://github.com/lucasmerlin/hello_egui/blob/main/crates/egui_form/README.md Demonstrates a basic form with a single text input field using egui_form and the garde validation crate. Ensure garde is added as a dependency for validation. ```rust use eframe::NativeOptions; use egui::{TextEdit, Ui}; use egui_form::garde::{GardeReport, field_path}; use egui_form::{Form, FormField}; use garde::Validate; #[derive(Debug, Default, Validate)] struct Fields { #[garde(length(min = 2, max = 50))] user_name: String, } fn form_ui(ui: &mut Ui, fields: &mut Fields) { let mut form = Form::new().add_report(GardeReport::new(fields.validate())); FormField::new(&mut form, field_path!("user_name")) .label("User Name") .ui(ui, TextEdit::singleline(&mut fields.user_name)); if let Some(Ok(())) = form.handle_submit(&ui.button("Submit"), ui) { println!("Submitted: {:?}", fields); } } ``` -------------------------------- ### Minimal egui_pull_to_refresh Usage Source: https://github.com/lucasmerlin/hello_egui/blob/main/crates/egui_pull_to_refresh/README.md This is the minimal example for using the `PullToRefresh` widget. Wrap your UI content within `PullToRefresh::new(loading).ui(...)` and handle the refresh logic when `response.should_refresh()` returns true. ```rust use egui::{Ui}; use egui_pull_to_refresh::PullToRefresh; // This is the minimal example. Wrap some ui in a [`PullToRefresh`] widget // and refresh when should_refresh() returns true. fn my_ui(ui: &mut Ui, count: u64, loading: bool) -> bool { let response = PullToRefresh::new(loading).ui(ui, |ui| { ui.add_space(ui.available_size().y / 4.0); ui.vertical_centered(|ui| { ui.set_height(ui.available_size().y); ui.label("Pull to refresh demo"); ui.label(format!("Count: {}", count)); }); }); response.should_refresh() } ``` -------------------------------- ### Using Filled and Outlined Material Icons in egui Source: https://github.com/lucasmerlin/hello_egui/blob/main/crates/egui_material_icons/README.md This example demonstrates how to use both filled and outlined variants of material icons. Ensure the 'outline' feature is enabled to use the outlined versions. ```rust use egui_material_icons::icons::*; fn init(ctx: &egui::Context) { egui_material_icons::initialize(ctx); } fn my_ui(ui: &mut egui::Ui) { ui.button(ICON_ADD); // filled ui.button(ICON_ADD.outlined()); // outlined } ``` -------------------------------- ### Basic egui_flex Usage with Growing Buttons Source: https://github.com/lucasmerlin/hello_egui/blob/main/crates/egui_flex/README.md Demonstrates a basic horizontal flex layout with a growing button and a nested vertical flex container. Use this for creating responsive UIs where elements need to adapt to available space. Ensure `FlexAlignContent::Stretch` is used for nested flex items that should fill their parent's space. ```Rust use eframe::NativeOptions; use egui::{Button, CentralPanel}; use egui_flex::{item, Flex, FlexAlignContent}; fn main() -> eframe::Result { eframe::run_simple_native(file!(), NativeOptions::default(), |ctx, _frame| { CentralPanel::default().show(ctx, |ui| { Flex::horizontal().show(ui, |flex| { flex.add(item().grow(1.0), Button::new("Growing button")); flex.add(item(), Button::new("Non-growing button")); // Nested flex flex.add_flex( item().grow(1.0), // We need the FlexAlignContent::Stretch to make the buttons fill the space Flex::vertical().align_content(FlexAlignContent::Stretch), |flex| { flex.add(item(), Button::new("Vertical button")); flex.add(item(), Button::new("Another Vertical button")); }, ); }); }); }) } ``` -------------------------------- ### Update Changelogs for egui Updates Source: https://github.com/lucasmerlin/hello_egui/blob/main/RELEASE.md Run this command to update changelogs when egui is updated. Ensure the output is correct. ```bash cargo run -p scripts --bin update_changelogs -- "- Update egui to 0.x" ``` -------------------------------- ### Initialize and Use Material Icons in egui Source: https://github.com/lucasmerlin/hello_egui/blob/main/crates/egui_material_icons/README.md Register the material icons font with egui's context during initialization. Later, use the provided icon constants to display icons in UI elements such as buttons. ```rust // register the fonts: egui_material_icons::initialize(&cc.egui_ctx); // later in some ui: ui.button(egui_material_icons::icons::ICON_ADD); ``` -------------------------------- ### Release Minor Version for All Crates Source: https://github.com/lucasmerlin/hello_egui/blob/main/RELEASE.md Use this command to release a new minor version for all crates in the workspace. This is particularly useful when egui is updated. Avoid using this for releasing a new crate from 0.1.0 to 0.2.0. ```bash cargo release minor --workspace ``` -------------------------------- ### Update Badges Source: https://github.com/lucasmerlin/hello_egui/blob/main/RELEASE.md Execute this command to update project badges after making changes. ```bash cargo run -p scripts --bin update_badges ``` -------------------------------- ### CSS Styling for Page Elements Source: https://github.com/lucasmerlin/hello_egui/blob/main/crates/egui_webview/src/native_text_field.html Basic CSS to set the margin, padding, and dimensions for head, body, and the input element to 100% of their container. Also styles the input for resizing and borders. ```css head, body, #input { margin: 0; padding: 0; width: 100%; height: 100%; } #input { resize: none; border: transparent 2px solid; } #input:hover, #input:focus { border: darkgray 2px solid; } ``` -------------------------------- ### Handle Window Focus Out Event Source: https://github.com/lucasmerlin/hello_egui/blob/main/crates/egui_webview/src/native_text_field.html Adds an event listener to post a 'FocusOut' message via IPC when the window loses focus. ```javascript window.addEventListener("focusout", () => { window.ipc.postMessage(JSON.stringify({"type": "FocusOut"})); }); ``` -------------------------------- ### Handle Window Focus Event Source: https://github.com/lucasmerlin/hello_egui/blob/main/crates/egui_webview/src/native_text_field.html Adds an event listener to focus the HTML input element with the ID 'input' when the window gains focus. ```javascript window.addEventListener("focus", () => { document.getElementById("input").focus(); }) ``` -------------------------------- ### Release Single Crate Version Source: https://github.com/lucasmerlin/hello_egui/blob/main/RELEASE.md Command to release a new version (patch, minor, or major) for a specific crate. ```bash cargo release -p ``` -------------------------------- ### Release Individual Crates During Failure Source: https://github.com/lucasmerlin/hello_egui/blob/main/RELEASE.md A sequence of commands to release individual crates when a full workspace release fails. This is a workaround for issues like GitHub issue #829 in cargo-release. ```bash cargo release minor --workspace --execute # *fails* cargo release --execute -p hello_egui_utils_dev cargo release --execute -p egui_virtual_list cargo release --execute -p egui_inbox cargo release --execute -p egui_infinite_scroll ``` -------------------------------- ### Release Workspace with Specific Exclusions Source: https://github.com/lucasmerlin/hello_egui/blob/main/RELEASE.md This command releases all crates in the workspace except for the specified ones. It's part of a workaround for potential release failures. ```bash cargo release --workspace --execute --exclude hello_egui_utils_dev --exclude egui_inbox --exclude egui_virtual_list --exclude egui_infinite_scroll --exclude hello_egui_utils --exclude egui_animation ``` -------------------------------- ### HTML Input Element with Event Handling Source: https://github.com/lucasmerlin/hello_egui/blob/main/crates/egui_webview/src/native_text_field.html An HTML input element that triggers an IPC message with its current text value whenever the input event occurs. It also has autofocus enabled. ```html <_tag _parameters autofocus id="input" oninput="window.ipc.postMessage(JSON.stringify({ type: 'Input' , 'text': this.value }))"> ``` -------------------------------- ### Set Text Input Value Source: https://github.com/lucasmerlin/hello_egui/blob/main/crates/egui_webview/src/native_text_field.html JavaScript function to set the value of an HTML input element with the ID 'input'. ```javascript function set_text(text) { document.getElementById("input").value = text; } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.