From c665f9be9df2c8e4220e2585c4eec33280b105c8 Mon Sep 17 00:00:00 2001 From: 42Pupusas <133644935+42Pupusas@users.noreply.github.com> Date: Tue, 11 Aug 2026 05:52:12 -0600 Subject: [PATCH 01/20] Don't busy-loop a CPU core while waiting for a redraw (#8398) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Closes #8326 `check_redraw_requests` switched the event loop to `ControlFlow::Poll` every time it called `request_redraw`, and only ever restored a sleeping control flow when a *timed* repaint was still pending. Once the last scheduled repaint had been consumed the `Poll` was never undone, so the loop kept spinning. This is most visible on Wayland, where `RedrawRequested` is only delivered after the compositor sends a frame callback: between the request and the callback eframe burns 100% of a CPU core, so simply moving the mouse over a reactive app pegs a core. `request_redraw` already wakes the event loop on its own, so the `Poll` is not needed. Drop it, and always set an explicit sleeping control flow at the end of `check_redraw_requests`: `WaitUntil` for the earliest scheduled repaint, `Wait` when nothing is scheduled. **Measured effect of this patch** Two byte-identical eframe apps (a 400-row scrolling page, free-running at 60fps), toggling only whether `eframe` resolves to stock 0.36.0 or this patch. Same machine and session, native Wayland (niri, wgpu/Vulkan). Whole-process CPU is `utime+stime` from `/proc/self/stat`, so it counts every thread — what a system monitor sees. | configuration | whole process | |---|---| | eframe 0.34.3, Wayland | ~12% of a core | | stock 0.36.0, Wayland | **99–100% of a core** | | stock 0.36.0, XWayland (same binary) | ~15% of a core | | **0.36.0 + this patch, Wayland** | **15–16% of a core** | The patch restores the 0.34 baseline and matches the XWayland figure for the same binary — ~6.5× less CPU — with frame delivery unchanged at 60fps. Two details worth noting: the same 0.36 binary is already fine on XWayland, so this isn't application repaint behaviour; and the per-frame *closure* cost rises slightly (1.55 to 2.15 ms) because those frames now run on a CPU that isn't being held at max clocks by the spin loop. * [X] I have followed the instructions in the PR template --- crates/eframe/src/native/run.rs | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/crates/eframe/src/native/run.rs b/crates/eframe/src/native/run.rs index 53979591..7c38aba4 100644 --- a/crates/eframe/src/native/run.rs +++ b/crates/eframe/src/native/run.rs @@ -207,7 +207,12 @@ impl WinitAppWrapper { invisible_window_ids.push(*window_id); } else { log::trace!("request_redraw for {window_id:?}"); - event_loop.set_control_flow(ControlFlow::Poll); + // Don't switch to `ControlFlow::Poll` here. `request_redraw` + // is enough to wake the event loop, and on Wayland the + // `RedrawRequested` event is only delivered once the + // compositor sends a frame callback. Polling in the meantime + // busy-loops a whole CPU core. + // See https://github.com/emilk/egui/issues/8326. window.request_redraw(); } } else { @@ -237,10 +242,16 @@ impl WinitAppWrapper { } } + // Always set an explicit, sleeping control flow. Previously we only set + // `WaitUntil` when a repaint was already scheduled, which meant that a + // `ControlFlow::Poll` set earlier was never undone once the last timed + // repaint had been consumed, leaving the loop spinning. + // See https://github.com/emilk/egui/issues/8326. let next_repaint_time = self.windows_next_repaint_times.values().min().copied(); - if let Some(next_repaint_time) = next_repaint_time { - event_loop.set_control_flow(ControlFlow::WaitUntil(next_repaint_time)); - } + event_loop.set_control_flow(match next_repaint_time { + Some(next_repaint_time) => ControlFlow::WaitUntil(next_repaint_time), + None => ControlFlow::Wait, + }); } } From 0226fef3d44d93b8ceca1135175ef5152b45c483 Mon Sep 17 00:00:00 2001 From: rustbasic <127506429+rustbasic@users.noreply.github.com> Date: Tue, 11 Aug 2026 21:03:53 +0900 Subject: [PATCH 02/20] Fallback `window_title_frame` to `window_frame` when unspecified (#8400) ### Summary When `title_frame` is not explicitly set, fall back to `window_frame` instead of `Frame::window(&style)`. ### Motivation If a custom `frame` is provided for a window, `window_title_frame` should maintain visual consistency with it by default unless a separate `title_frame` is specified. * Related #8154 * Related #8353 --- crates/egui/src/containers/window.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/egui/src/containers/window.rs b/crates/egui/src/containers/window.rs index 69d3f0bf..c3f4dcb2 100644 --- a/crates/egui/src/containers/window.rs +++ b/crates/egui/src/containers/window.rs @@ -627,8 +627,8 @@ impl Window<'_> { let style = ctx.global_style(); // We get or create the Frame for the title and content - let window_title_frame = title_frame.unwrap_or_else(|| Frame::window(&style)); let window_frame = frame.unwrap_or_else(|| Frame::window(&style)); + let window_title_frame = title_frame.unwrap_or(window_frame); // We apply the window margin by using the `ScrollArea::content_margin`. let window_content_margin = window_frame.inner_margin; From 1e618c2f54e325e5ebc800a733fefcb0e8cce6d3 Mon Sep 17 00:00:00 2001 From: Teddy Tennant Date: Tue, 11 Aug 2026 08:04:09 -0400 Subject: [PATCH 03/20] Don't revert external changes to a focused `DragValue` (#8403) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Closes * [x] I have followed the instructions in the PR template ## The bug While a `DragValue` has focus it is rendered as a `TextEdit`, and the text being edited is stored in `Memory::data` between frames. That is needed so that half-finished input such as `"1."` or `"-"` isn't thrown away just because it doesn't parse to the current value. The stored text was only discarded when the widget *gained* focus or when the widget itself changed the value. If something else changed the value while the `DragValue` was focused, the stored text was kept, shown to the user, and written back to the value when focus was lost — silently undoing the external change: ```rust ui.add(egui::DragValue::new(&mut self.value)); if ui.button("increment").clicked() { self.value += 1; } ``` Click into the `DragValue` so it has focus, then press "increment": the value goes up for one frame and then snaps back. `Slider` shows the same behaviour, since it uses a `DragValue` for its value field. ## The fix Store the value the text belongs to next to the text, and discard the text when the value no longer matches it. The remembered value is read back from the get/set closure *after* the widget has applied its own edits, so a change the widget made itself never looks like an external one — this matters for values that can't represent what was typed, e.g. `"12.5"` in a `DragValue`. This keeps the reason the text is stored in the first place intact: as long as nothing else touches the value, the text the user is typing is preserved verbatim. ## Tests Three tests in `crates/egui_kittest/tests/regression_tests.rs`: * `drag_value_should_not_revert_external_changes_while_focused` — the actual regression. Fails on `main`: ``` ---- drag_value_should_not_revert_external_changes_while_focused stdout ---- assertion `left == right` failed left: Some("0") right: Some("42") ``` and, with the display assertion removed so the test reaches the blur, on the value itself: ``` assertion `left == right` failed left: 0 right: 42 ``` * `drag_value_should_keep_text_while_typing` and `drag_value_should_keep_text_the_value_cannot_represent` — guards for the behaviour the stored text exists for. Both pass on `main` and after the fix, and both fail if the text is re-read from the value too eagerly. `cargo test -p egui_kittest` and `cargo test -p egui` pass, as do `cargo fmt --all --check`, `scripts/lint.py` and `cargo clippy -p egui -p egui_kittest --all-targets --all-features -- -D warnings`. ## Not changed `DragValue` still ignores the stored text when Escape is pressed, and `update_while_editing` still decides when typed text is applied — neither is touched here. --- crates/egui/src/widgets/drag_value.rs | 48 +++++++-- crates/egui_kittest/tests/regression_tests.rs | 97 +++++++++++++++++++ 2 files changed, 137 insertions(+), 8 deletions(-) diff --git a/crates/egui/src/widgets/drag_value.rs b/crates/egui/src/widgets/drag_value.rs index 81f686fe..eed264a8 100644 --- a/crates/egui/src/widgets/drag_value.rs +++ b/crates/egui/src/widgets/drag_value.rs @@ -25,6 +25,24 @@ fn set(get_set_value: &mut GetSetValue<'_>, value: f64) { (get_set_value)(Some(value)); } +// ---------------------------------------------------------------------------- + +/// What the user has typed into a [`DragValue`] that is being edited as text. +/// +/// Stored in [`crate::Memory::data`] between frames, because the text can be +/// something that doesn't (yet) parse to a number, e.g. `"1."` or `"-"`. +#[derive(Clone, Default)] +struct EditState { + /// The text the user is editing. + text: String, + + /// The value of the [`DragValue`] the last time we stored `text`. + /// + /// If the value has changed since then it was changed by something other than + /// this widget, and `text` is stale and must not be written back to the value. + value: f64, +} + /// A numeric value that you can change by dragging the number. More compact than a [`crate::Slider`]. /// /// ``` @@ -466,7 +484,7 @@ impl Widget for DragValue<'_> { }); if ui.memory_mut(|mem| mem.gained_focus(id)) { - ui.data_mut(|data| data.remove::(id)); + ui.data_mut(|data| data.remove::(id)); } let old_value = get(&mut get_set_value); @@ -524,7 +542,7 @@ impl Widget for DragValue<'_> { if old_value != value { set(&mut get_set_value, value); - ui.data_mut(|data| data.remove::(id)); + ui.data_mut(|data| data.remove::(id)); } let value_text = match custom_formatter { @@ -538,8 +556,13 @@ impl Widget for DragValue<'_> { let text_style = ui.style().drag_value_text_style.clone(); if ui.memory(|mem| mem.lost_focus(id)) && !ui.input(|i| i.key_pressed(Key::Escape)) { - let value_text = ui.data_mut(|data| data.remove_temp::(id)); - if let Some(value_text) = value_text { + let edit_state = ui.data_mut(|data| data.remove_temp::(id)); + // Ignore the text if the value was changed by something else while we were editing it, + // or we would revert that change. + if let Some(value_text) = edit_state + .filter(|edit_state| edit_state.value == old_value) + .map(|edit_state| edit_state.text) + { // We were editing the value as text last frame, but lost focus. // Make sure we applied the last text value: let parsed_value = parse(custom_parser.as_ref(), &value_text); @@ -552,9 +575,12 @@ impl Widget for DragValue<'_> { } let mut response = if is_kb_editing { + // Keep editing the text from last frame, unless the value was changed by + // something else in the meantime, in which case the text is stale. let mut value_text = ui - .data_mut(|data| data.remove_temp::(id)) - .unwrap_or_else(|| value_text.clone()); + .data_mut(|data| data.remove_temp::(id)) + .filter(|edit_state| edit_state.value == old_value) + .map_or_else(|| value_text.clone(), |edit_state| edit_state.text); let response = ui.add( TextEdit::singleline(&mut value_text) .clip_text(false) @@ -589,7 +615,13 @@ impl Widget for DragValue<'_> { set(&mut get_set_value, parsed_value); } } - ui.data_mut(|data| data.insert_temp(id, value_text)); + // Remember the value the text belongs to, so that next frame we can tell + // whether the value was changed by us or by something else. + let edit_state = EditState { + text: value_text, + value: get(&mut get_set_value), + }; + ui.data_mut(|data| data.insert_temp(id, edit_state)); response } else { atoms.map_atoms(|atom| { @@ -631,7 +663,7 @@ impl Widget for DragValue<'_> { } if response.clicked() { - ui.data_mut(|data| data.remove::(id)); + ui.data_mut(|data| data.remove::(id)); ui.memory_mut(|mem| mem.request_focus(id)); select_all_text(ui, id, response.id, &value_text); } else if response.dragged() { diff --git a/crates/egui_kittest/tests/regression_tests.rs b/crates/egui_kittest/tests/regression_tests.rs index 12e66ac5..1f47cd42 100644 --- a/crates/egui_kittest/tests/regression_tests.rs +++ b/crates/egui_kittest/tests/regression_tests.rs @@ -814,3 +814,100 @@ pub fn textedit_hint_text_should_follow_text_alignment() { edit_center_x={edit_center_x}, edit_rect={edit_rect:?}", ); } + +/// A focused `DragValue` keeps the text the user is editing in memory. +/// +/// If something else changes the value while the `DragValue` has focus, +/// that memorized text is stale, and must not be written back to the value. +/// +/// Regression test for . +#[test] +pub fn drag_value_should_not_revert_external_changes_while_focused() { + let mut harness = Harness::new_ui_state( + |ui, value: &mut i32| { + ui.add(egui::DragValue::new(value)); + }, + 0, + ); + + // Focus the `DragValue`, putting it in text-edit mode. + harness.key_press(egui::Key::Tab); + harness.run(); + + // Something else changes the value while the `DragValue` is focused. + *harness.state_mut() = 42; + harness.run(); + + assert_eq!(harness.state(), &42); + let drag_value = harness.get_by_role(accesskit::Role::SpinButton); + assert_eq!(drag_value.value(), Some("42".to_owned())); + + // Losing focus must not restore the value the `DragValue` had when it gained focus. + harness.key_press(egui::Key::Tab); + harness.run(); + + assert_eq!(harness.state(), &42); +} + +/// While the user is typing into a `DragValue`, the half-finished text must be kept +/// between frames, even though it doesn't always parse back to the same text. +#[test] +pub fn drag_value_should_keep_text_while_typing() { + let mut harness = Harness::new_ui_state( + |ui, value: &mut f64| { + ui.add(egui::DragValue::new(value)); + }, + 0.0, + ); + + // Focus the `DragValue`, putting it in text-edit mode with the old text selected. + harness.key_press(egui::Key::Tab); + harness.run(); + + // Type one character per frame. `"1."` parses to `1`, which is formatted as `"1"`, + // so re-reading the text from the value would eat the decimal point. + for character in "1.25".chars() { + harness + .get_by_role(accesskit::Role::SpinButton) + .type_text(&character.to_string()); + harness.run(); + } + + harness.key_press(egui::Key::Enter); + harness.run(); + + assert_eq!(harness.state(), &1.25); +} + +/// An integer `DragValue` cannot represent everything the user types into it, +/// but the text must still survive until the user is done typing. +#[test] +pub fn drag_value_should_keep_text_the_value_cannot_represent() { + let mut harness = Harness::new_ui_state( + |ui, value: &mut i32| { + ui.add(egui::DragValue::new(value)); + }, + 0, + ); + + // Focus the `DragValue`, putting it in text-edit mode with the old text selected. + harness.key_press(egui::Key::Tab); + harness.run(); + + // `"12.5"` is stored as `12`, which is formatted as `"12"`. + harness + .get_by_role(accesskit::Role::SpinButton) + .type_text("12.5"); + harness.run(); + + // If the text was re-read from the value now, this would append to `"12"`. + harness + .get_by_role(accesskit::Role::SpinButton) + .type_text("9"); + harness.run(); + + harness.key_press(egui::Key::Enter); + harness.run(); + + assert_eq!(harness.state(), &12, "The text should have been \"12.59\""); +} From 99236d47bddb027d939a3e2321b8c03ec6bf6085 Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Mon, 17 Aug 2026 21:41:09 -0700 Subject: [PATCH 04/20] Match image file extensions case-insensitively (#8430) `image.PNG` and `cat.SVG` were not recognized as images. Adds `egui::load::has_extension(uri, extension)`, which ignores ASCII case and any `#fragment`, and uses it for the `.svg`, `.gif`, `.webp` and `.png` checks. Note: gif/webp URIs like `a#b.gif` no longer match, since the fragment is now excluded. * [x] I have followed the instructions in the PR template Co-authored-by: Claude Opus 5 (1M context) --- crates/eframe/src/native/glow_integration.rs | 2 +- crates/egui/src/load.rs | 24 ++++++++++++++++++++ crates/egui/src/load/texture_loader.rs | 2 +- crates/egui/src/widgets/image.rs | 4 ++-- crates/egui_extras/src/loaders/svg_loader.rs | 2 +- 5 files changed, 29 insertions(+), 5 deletions(-) diff --git a/crates/eframe/src/native/glow_integration.rs b/crates/eframe/src/native/glow_integration.rs index 1b9469cf..cca1d22c 100644 --- a/crates/eframe/src/native/glow_integration.rs +++ b/crates/eframe/src/native/glow_integration.rs @@ -1720,7 +1720,7 @@ fn save_screenshot_and_exit( screen_size_in_pixels: [u32; 2], ) { assert!( - path.ends_with(".png"), + egui::load::has_extension(path, "png"), "Expected EFRAME_SCREENSHOT_TO to end with '.png', got {path:?}" ); let screenshot = painter.read_screen_rgba(screen_size_in_pixels); diff --git a/crates/egui/src/load.rs b/crates/egui/src/load.rs index f3acbf6a..df390dc6 100644 --- a/crates/egui/src/load.rs +++ b/crates/egui/src/load.rs @@ -306,6 +306,19 @@ macro_rules! generate_loader_id { } pub use crate::generate_loader_id; +/// Does the given URI end with the given file extension? +/// +/// The comparison ignores ASCII case and any `#fragment` at the end of the URI, +/// so `has_extension("cat.GIF#frame=2", "gif")` is `true`. +/// +/// This is useful when implementing an [`ImageLoader`]. +pub fn has_extension(uri: &str, extension: &str) -> bool { + let path = uri.split('#').next().unwrap_or(uri); + std::path::Path::new(path) + .extension() + .is_some_and(|found| found.eq_ignore_ascii_case(extension)) +} + pub type BytesLoadResult = Result; /// Represents a loader capable of loading raw unstructured bytes from somewhere, @@ -639,3 +652,14 @@ impl Loaders { } } } + +#[test] +fn test_has_extension() { + assert!(has_extension("cat.svg", "svg")); + assert!(has_extension("cat.SVG", "svg")); + assert!(has_extension("http://example.com/cat.gif#frame=2", "gif")); + assert!(!has_extension("cat.svg.png", "svg")); + assert!(!has_extension("svg", "svg")); + assert!(!has_extension("cat.jpeg", "jpg")); + assert!(!has_extension("cat.svg?v=1", "svg")); +} diff --git a/crates/egui/src/load/texture_loader.rs b/crates/egui/src/load/texture_loader.rs index 2ab4d8a5..eb9b4503 100644 --- a/crates/egui/src/load/texture_loader.rs +++ b/crates/egui/src/load/texture_loader.rs @@ -150,5 +150,5 @@ impl TextureLoader for DefaultTextureLoader { } fn is_svg(uri: &str) -> bool { - uri.ends_with(".svg") + super::has_extension(uri, "svg") } diff --git a/crates/egui/src/widgets/image.rs b/crates/egui/src/widgets/image.rs index 0618e866..9bce8c4d 100644 --- a/crates/egui/src/widgets/image.rs +++ b/crates/egui/src/widgets/image.rs @@ -934,7 +934,7 @@ fn animated_image_frame_index(ctx: &Context, uri: &str) -> usize { /// Checks if uri is a gif file fn is_gif_uri(uri: &str) -> bool { - uri.ends_with(".gif") || uri.contains(".gif#") + crate::load::has_extension(uri, "gif") } /// Checks if bytes are gifs @@ -944,7 +944,7 @@ pub fn has_gif_magic_header(bytes: &[u8]) -> bool { /// Checks if uri is a webp file fn is_webp_uri(uri: &str) -> bool { - uri.ends_with(".webp") || uri.contains(".webp#") + crate::load::has_extension(uri, "webp") } /// Checks if bytes are webp diff --git a/crates/egui_extras/src/loaders/svg_loader.rs b/crates/egui_extras/src/loaders/svg_loader.rs index 91063f6b..53c87905 100644 --- a/crates/egui_extras/src/loaders/svg_loader.rs +++ b/crates/egui_extras/src/loaders/svg_loader.rs @@ -29,7 +29,7 @@ impl SvgLoader { } fn is_supported(uri: &str) -> bool { - uri.ends_with(".svg") + egui::load::has_extension(uri, "svg") } impl Default for SvgLoader { From 1700ce85f58fe65dd25c2c728c66478037da07af Mon Sep 17 00:00:00 2001 From: Zachary Harvie Date: Tue, 25 Aug 2026 05:16:33 -0700 Subject: [PATCH 05/20] Fix `egui-wgpu` build on `wasm32-unknown-emscripten` (#8454) Fix a build issue in the `egui-wgpu` crate when building for the `wasm32-unknown-emscripten` target. WGPU does not support the WebGPU backend on that target. --- crates/egui-wgpu/src/setup.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/crates/egui-wgpu/src/setup.rs b/crates/egui-wgpu/src/setup.rs index 3909a9b5..3c9ceae5 100644 --- a/crates/egui-wgpu/src/setup.rs +++ b/crates/egui-wgpu/src/setup.rs @@ -101,7 +101,10 @@ impl WgpuSetup { let mut backends = create_new.instance_descriptor.backends; // Don't try WebGPU if we're not in a secure context. - #[cfg(target_arch = "wasm32")] + // Emscripten is excluded: wgpu gates both its `webgpu` backend and + // its `web_sys` re-export on `not(Emscripten)` (see the cfg aliases + // in `wgpu/build.rs`). + #[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))] if backends.contains(wgpu::Backends::BROWSER_WEBGPU) { let is_secure_context = wgpu::web_sys::window().is_some_and(|w| w.is_secure_context()); From 5095d08436fb948884a50285681d9dfa5b3e61de Mon Sep 17 00:00:00 2001 From: taro <34352544+tarolling@users.noreply.github.com> Date: Tue, 25 Aug 2026 07:15:18 -0500 Subject: [PATCH 06/20] Hide drop shadow window decoration when in fullscreen mode (#8449) * Closes * [x] I have followed the instructions in the PR template --- crates/egui-winit/src/lib.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/crates/egui-winit/src/lib.rs b/crates/egui-winit/src/lib.rs index 0029a47b..c6c920cd 100644 --- a/crates/egui-winit/src/lib.rs +++ b/crates/egui-winit/src/lib.rs @@ -1867,7 +1867,9 @@ fn process_viewport_command( #[cfg(target_os = "windows")] { use winit::platform::windows::WindowExtWindows as _; - window.set_undecorated_shadow(!v); + + // don't request the undecorated-window drop shadow in fullscreen (#8399) + window.set_undecorated_shadow(!v && window.fullscreen().is_none()); } } ViewportCommand::WindowLevel(l) => window.set_window_level(match l { @@ -2171,7 +2173,10 @@ pub fn create_winit_window_attributes( if let Some(show) = _taskbar { window_attributes = window_attributes.with_skip_taskbar(!show); } - window_attributes = window_attributes.with_undecorated_shadow(!decorations.unwrap_or(true)); + + // don't request the undecorated-window drop shadow in fullscreen (#8399) + let want_undecorated_shadow = !decorations.unwrap_or(true) && !fullscreen.unwrap_or(false); + window_attributes = window_attributes.with_undecorated_shadow(want_undecorated_shadow); } #[cfg(target_os = "macos")] From 07b042b59f9b2b259514108abcc1c2cfa412ef86 Mon Sep 17 00:00:00 2001 From: rustbasic <127506429+rustbasic@users.noreply.github.com> Date: Mon, 24 Aug 2026 19:49:33 +0900 Subject: [PATCH 07/20] Fix transparent child viewports on `Windows` with `glow` (#8423) Fix transparent child viewports on `Windows` with `glow` * Closes #3632 * Related #4451 * Related #5072 * Closes #7543 * Related #8116 Transparent native child viewports could become opaque on Windows when the selected GL config reports that it does not support transparency. `glutin_winit::finalize_window` clears the native transparent window attribute in that case. However, on affected Windows GL paths, transparent native windows and their GL surfaces still composite correctly. This change preserves the transparent window attribute for explicitly transparent non-root viewports on Windows by creating those windows directly. Tested manually on Windows with glow: - root transparent viewport - deferred native child viewport - immediate native child viewport --- crates/eframe/src/native/glow_integration.rs | 31 ++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/crates/eframe/src/native/glow_integration.rs b/crates/eframe/src/native/glow_integration.rs index cca1d22c..28a1ee68 100644 --- a/crates/eframe/src/native/glow_integration.rs +++ b/crates/eframe/src/native/glow_integration.rs @@ -1268,11 +1268,30 @@ impl GlutinWindowContext { ); if window_attributes.transparent() && self.gl_config.supports_transparency() == Some(false) + && !cfg!(target_os = "windows") { log::error!("Cannot create transparent window: the GL config does not support it"); } - let window = - glutin_winit::finalize_window(event_loop, window_attributes, &self.gl_config)?; + + let window = cfg_select! { + target_os = "windows" => { + if viewport_id != ViewportId::ROOT && window_attributes.transparent() { + // Preserve explicitly requested transparent child viewports on Windows. + // Some GL paths report no transparency support although composition works. + event_loop.create_window(window_attributes)? + } else { + glutin_winit::finalize_window( + event_loop, + window_attributes, + &self.gl_config, + )? + } + } + _ => { + // Keep the normal platform-specific finalization path elsewhere. + glutin_winit::finalize_window(event_loop, window_attributes, &self.gl_config)? + } + }; egui_winit::apply_viewport_builder_to_window( &self.egui_ctx, &window, @@ -1497,9 +1516,17 @@ fn initialize_or_update_viewport( .and_then(|vp| vp.builder.icon.clone()); } + let root_transparent = viewports + .get(&ViewportId::ROOT) + .and_then(|viewport| viewport.builder.transparent); + match viewports.entry(ids.this) { Entry::Vacant(entry) => { // New viewport: + if ids.this != ViewportId::ROOT && builder.transparent.is_none() { + // Child viewports inherit the root setting unless they explicitly override it. + builder.transparent = root_transparent; + } log::debug!("Creating new viewport {:?} ({:?})", ids.this, builder.title); entry.insert(Viewport { ids, From ca7f0f298ca5c3f7430abd019e970e00a82bb413 Mon Sep 17 00:00:00 2001 From: Sylvain <67423638+Le-Syl21@users.noreply.github.com> Date: Tue, 25 Aug 2026 14:07:33 +0200 Subject: [PATCH 08/20] eframe: apply ViewportBuilder::with_monitor on the glow backend (#8302) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Problem `ViewportBuilder::with_monitor(idx)` is a **no-op on the glow backend**. A window built with `.with_monitor(...)` opens on the default monitor, not fullscreen — while the exact same code works on wgpu. The monitor → `Fullscreen::Borderless(Some(monitor))` resolution only lives in `egui_winit::create_window`, which the **wgpu** backend uses. The **glow** backend builds its windows straight from `egui_winit::create_winit_window_attributes` at two sites in `glow_integration.rs` — the initial window and per-viewport deferred windows — so the monitor is never applied there. ## Repro A multi-viewport app on the glow renderer with any viewport built via `ViewportBuilder::default().with_monitor(1)` opens that window on monitor 0, un-fullscreen. Switching to the wgpu renderer places it correctly. Seen on a 3-monitor GNOME/Wayland setup where the main window and secondary viewports all need to land borderless-fullscreen on specific outputs. ## Fix Extract the resolution into a public `apply_monitor_to_window_attributes` in `egui-winit` and call it from `create_window` (unchanged behaviour) plus both glow window-creation sites, so `with_monitor` behaves the same on glow and wgpu. No public API change beyond the new helper; no behaviour change on wgpu. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- crates/eframe/src/native/glow_integration.rs | 17 +++++---- crates/egui-winit/src/lib.rs | 36 +++++++++++++++----- 2 files changed, 38 insertions(+), 15 deletions(-) diff --git a/crates/eframe/src/native/glow_integration.rs b/crates/eframe/src/native/glow_integration.rs index 28a1ee68..82a150aa 100644 --- a/crates/eframe/src/native/glow_integration.rs +++ b/crates/eframe/src/native/glow_integration.rs @@ -1094,9 +1094,10 @@ impl GlutinWindowContext { // // The justification for FallbackEgl over PreferEgl is at https://github.com/emilk/egui/pull/2526#issuecomment-1400229576 . .with_preference(glutin_winit::ApiPreference::FallbackEgl) - .with_window_attributes(Some(egui_winit::create_winit_window_attributes( - egui_ctx, - viewport_builder.clone(), + .with_window_attributes(Some(egui_winit::apply_monitor_to_window_attributes( + egui_winit::create_winit_window_attributes(egui_ctx, viewport_builder.clone()), + &viewport_builder, + event_loop, ))); let (window, gl_config) = { @@ -1262,9 +1263,13 @@ impl GlutinWindowContext { window } else { log::debug!("Creating a window for viewport {viewport_id:?}"); - let window_attributes = egui_winit::create_winit_window_attributes( - &self.egui_ctx, - viewport.builder.clone(), + let window_attributes = egui_winit::apply_monitor_to_window_attributes( + egui_winit::create_winit_window_attributes( + &self.egui_ctx, + viewport.builder.clone(), + ), + &viewport.builder, + event_loop, ); if window_attributes.transparent() && self.gl_config.supports_transparency() == Some(false) diff --git a/crates/egui-winit/src/lib.rs b/crates/egui-winit/src/lib.rs index c6c920cd..5ca80010 100644 --- a/crates/egui-winit/src/lib.rs +++ b/crates/egui-winit/src/lib.rs @@ -1973,12 +1973,33 @@ pub fn create_window( ) -> Result { profiling::function_scope!(); - let mut window_attributes = create_winit_window_attributes(egui_ctx, viewport_builder.clone()); + let window_attributes = apply_monitor_to_window_attributes( + create_winit_window_attributes(egui_ctx, viewport_builder.clone()), + viewport_builder, + event_loop, + ); - // Resolve target monitor index → MonitorHandle, so the window is created - // directly in borderless fullscreen on the requested output. This is the - // only reliable way to target a specific monitor under Wayland, and also - // avoids the Mutter race where OuterPosition is ignored pre-mapping. + let window = event_loop.create_window(window_attributes)?; + apply_viewport_builder_to_window(egui_ctx, &window, viewport_builder); + Ok(window) +} + +/// Apply [`ViewportBuilder::with_monitor`] to freshly-built [`winit::window::WindowAttributes`]. +/// +/// Resolve the target monitor index → `MonitorHandle` and request borderless +/// fullscreen on that output, so the window is created directly on the right +/// monitor. This is the only reliable way to target a specific monitor under +/// Wayland, and also avoids the Mutter race where `OuterPosition` is ignored +/// pre-mapping. +/// +/// Must be called by every backend that builds its own window from +/// [`create_winit_window_attributes`] (the glow backend and per-viewport window +/// creation do this) — otherwise `with_monitor` silently does nothing there. +pub fn apply_monitor_to_window_attributes( + mut window_attributes: winit::window::WindowAttributes, + viewport_builder: &ViewportBuilder, + event_loop: &ActiveEventLoop, +) -> winit::window::WindowAttributes { if let Some(idx) = viewport_builder.monitor { if let Some(monitor) = event_loop.available_monitors().nth(idx) { window_attributes = window_attributes @@ -1990,10 +2011,7 @@ pub fn create_window( ); } } - - let window = event_loop.create_window(window_attributes)?; - apply_viewport_builder_to_window(egui_ctx, &window, viewport_builder); - Ok(window) + window_attributes } pub fn create_winit_window_attributes( From 75056927a995ffc72bdc7dc905c4267667351015 Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Wed, 2 Sep 2026 21:23:52 +0200 Subject: [PATCH 09/20] Fix rendering of thin, angled rectangles (#8482) We had a fast path for very thin rectangles, but it did not heed the angle of the rect --- crates/epaint/src/tessellator.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/epaint/src/tessellator.rs b/crates/epaint/src/tessellator.rs index 7b207abe..f9f2b06b 100644 --- a/crates/epaint/src/tessellator.rs +++ b/crates/epaint/src/tessellator.rs @@ -1807,7 +1807,7 @@ impl Tessellator { } } - if stroke.is_empty() && out.texture_id == TextureId::default() { + if angle == 0.0 && stroke.is_empty() && out.texture_id == TextureId::default() { // Approximate thin rectangles with line segments. // This is important so that thin rectangles look good. if rect.width() <= 2.0 * self.feathering { From f63b4d037467fdf2bf44bee508d8bc6771f64cdb Mon Sep 17 00:00:00 2001 From: cui fliter Date: Thu, 3 Sep 2026 19:48:23 +0800 Subject: [PATCH 10/20] Fix zero-duration value animations returning the previous value (#8469) animate_value_with_time returned the previous value for one frame when called with a zero duration because it calculated the current value before updating the animation target. Handle zero-duration animations before interpolation so they immediately return and store the target value. Add a regression test covering consecutive target changes. * Closes * [x] I have followed the instructions in the PR template Signed-off-by: cuishuang Co-authored-by: Emil Ernerfeldt --- crates/egui/src/animation_manager.rs | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/crates/egui/src/animation_manager.rs b/crates/egui/src/animation_manager.rs index 4dc21df0..211873bd 100644 --- a/crates/egui/src/animation_manager.rs +++ b/crates/egui/src/animation_manager.rs @@ -85,6 +85,13 @@ impl AnimationManager { value } Some(anim) => { + if animation_time == 0.0 { + anim.from_value = value; + anim.to_value = value; + anim.toggle_time = input.time; + return value; + } + let time_since_toggle = (input.time - anim.toggle_time) as f32; // On the frame we toggle we don't want to return the old value, // so we extrapolate forwards by half a frame: @@ -99,12 +106,25 @@ impl AnimationManager { anim.to_value = value; anim.toggle_time = input.time; } - if animation_time == 0.0 { - anim.from_value = value; - anim.to_value = value; - } current_value } } } } + +#[cfg(test)] +mod tests { + use super::AnimationManager; + use crate::{Id, InputState}; + + #[test] + fn zero_duration_value_animation_reaches_target_immediately() { + let mut animations = AnimationManager::default(); + let input = InputState::default(); + let id = Id::new("value_animation"); + + assert_eq!(animations.animate_value(&input, 0.0, id, 0.0), 0.0); + assert_eq!(animations.animate_value(&input, 0.0, id, 1.0), 1.0); + assert_eq!(animations.animate_value(&input, 0.0, id, 2.0), 2.0); + } +} From c0b9996d706cc416c64d24fea5b694e32d1b5e9d Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Thu, 3 Sep 2026 15:16:14 +0200 Subject: [PATCH 11/20] Fix panic in hit-test when a widget rect contains a NaN (#8479) * Closes * [x] I have followed the instructions in the PR template `WidgetRect` derives `PartialEq`, so a rect with a NaN coordinate is not equal even to itself, and `close.iter().position(|w| *w == hit_click).unwrap()` panicked. We now look the hit up by id. NaN rects got that far because `Rect::intersect` scrubs NaNs (`f32::max(NAN, x) == x`), so `interact_rect` can be finite while `rect` is not, sneaking past the existing NaN guard. Hit-testing now discards those widgets too. Finally, `Pos2` claims `Eq` while NaN breaks reflexivity, so `PartialEq` is now hand-written and panics on NaN in debug builds. --- crates/egui/src/context.rs | 2 ++ crates/egui/src/hit_test.rs | 16 +++++++++------- crates/emath/src/pos2.rs | 17 ++++++++++++++++- crates/emath/src/vec2.rs | 17 ++++++++++++++++- 4 files changed, 43 insertions(+), 9 deletions(-) diff --git a/crates/egui/src/context.rs b/crates/egui/src/context.rs index 45193e15..93b13df5 100644 --- a/crates/egui/src/context.rs +++ b/crates/egui/src/context.rs @@ -1251,6 +1251,8 @@ impl Context { allow_focus: bool, options: crate::InteractOptions, ) -> Response { + debug_assert!(!w.rect.any_nan(), "widget rect is NaN: {:?}", w.rect); + let interested_in_focus = w.enabled && w.sense.is_focusable() && self.memory(|mem| mem.allows_interaction(w.layer_id)); diff --git a/crates/egui/src/hit_test.rs b/crates/egui/src/hit_test.rs index f48c409b..2be646b4 100644 --- a/crates/egui/src/hit_test.rs +++ b/crates/egui/src/hit_test.rs @@ -65,7 +65,7 @@ pub fn hit_test( .filter(|layer| layer.order.allow_interaction()) .flat_map(|&layer_id| widgets.get_layer(layer_id)) .filter(|&w| { - if w.interact_rect.is_negative() || w.interact_rect.any_nan() { + if w.interact_rect.is_negative() || w.rect.any_nan() || w.interact_rect.any_nan() { return false; } @@ -91,7 +91,10 @@ pub fn hit_test( } } - close.retain(|rect| !rect.interact_rect.any_nan()); // Protect against bad input and transforms + // Protect against bad input and transforms. + // NOTE: `Rect::intersect` scrubs NaNs (`f32::max(NAN, x) == x`), + // so `interact_rect` can be finite even when `rect` is not. + close.retain(|w| !w.rect.any_nan() && !w.interact_rect.any_nan()); // When using layer transforms it is common to stack layers close to each other. // For instance, you may have a resize-separator on a panel, with two @@ -359,11 +362,10 @@ fn hit_test_on_close(close: &[WidgetRect], pos: Pos2) -> WidgetHits { (Some(hit_click), Some(hit_drag)) => { // We have a perfect hit on both click and drag. Which is the topmost? - #[expect(clippy::unwrap_used)] - let click_idx = close.iter().position(|w| *w == hit_click).unwrap(); - - #[expect(clippy::unwrap_used)] - let drag_idx = close.iter().position(|w| *w == hit_drag).unwrap(); + // We look them up by id, because a `WidgetRect` with a NaN coordinate + // is not equal even to itself. + let click_idx = close.iter().position(|w| w.id == hit_click.id); + let drag_idx = close.iter().position(|w| w.id == hit_drag.id); let click_is_on_top_of_drag = drag_idx < click_idx; if click_is_on_top_of_drag { diff --git a/crates/emath/src/pos2.rs b/crates/emath/src/pos2.rs index d331769d..ce56bddd 100644 --- a/crates/emath/src/pos2.rs +++ b/crates/emath/src/pos2.rs @@ -12,7 +12,7 @@ use crate::{Div, Mul, Vec2, lerp}; /// Mathematically this is known as a "point", but the term position was chosen so not to /// conflict with the unit (one point = X physical pixels). #[repr(C)] -#[derive(Clone, Copy, Default, PartialEq)] +#[derive(Clone, Copy, Default)] #[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] #[cfg_attr(feature = "bytemuck", derive(bytemuck::Pod, bytemuck::Zeroable))] pub struct Pos2 { @@ -230,6 +230,21 @@ impl core::ops::IndexMut for Pos2 { } } +impl PartialEq for Pos2 { + #[track_caller] + #[inline] + fn eq(&self, other: &Self) -> bool { + debug_assert!( + !self.any_nan() && !other.any_nan(), + "Comparing NaN positions ({self:?} and {other:?}). \ + A NaN is not even equal to itself, which leads to very confusing bugs." + ); + self.x == other.x && self.y == other.y + } +} + +/// This is a lie for NaN positions, which are not equal to themselves. +/// [`PartialEq`] catches those in debug builds. impl Eq for Pos2 {} impl AddAssign for Pos2 { diff --git a/crates/emath/src/vec2.rs b/crates/emath/src/vec2.rs index 5422aa79..7cf38e53 100644 --- a/crates/emath/src/vec2.rs +++ b/crates/emath/src/vec2.rs @@ -10,7 +10,7 @@ use crate::Vec2b; /// /// Normally the units are points (logical pixels). #[repr(C)] -#[derive(Clone, Copy, Default, PartialEq)] +#[derive(Clone, Copy, Default)] #[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] #[cfg_attr(feature = "bytemuck", derive(bytemuck::Pod, bytemuck::Zeroable))] pub struct Vec2 { @@ -346,6 +346,21 @@ impl core::ops::IndexMut for Vec2 { } } +impl PartialEq for Vec2 { + #[track_caller] + #[inline] + fn eq(&self, other: &Self) -> bool { + debug_assert!( + !self.any_nan() && !other.any_nan(), + "Comparing NaN vectors ({self:?} and {other:?}). \ + A NaN is not even equal to itself, which leads to very confusing bugs." + ); + self.x == other.x && self.y == other.y + } +} + +/// This is a lie for NaN vectors, which are not equal to themselves. +/// [`PartialEq`] catches those in debug builds. impl Eq for Vec2 {} impl Neg for Vec2 { From d417c2f74df40f9e5c2c009b2f27b5d5944ce2d7 Mon Sep 17 00:00:00 2001 From: Keith Date: Thu, 20 Aug 2026 13:36:39 -0700 Subject: [PATCH 12/20] Simplify and optimize `Color32::from_rgba_unmultiplied` (#8427) So I first noticed that this function was using a large lookup table behind a OnceLock. I initially thought about just making it a const, but when looking at things further. I realized it could be made much simpler. If we just treated the numbers as fixed point we can get rid of any of the floating point calculations and especially divisions. You can see how efficiently this can compile down here: https://llvm.godbolt.org/z/K83jEjvdq You can see all three versions here: https://godbolt.org/z/nWc1as1nq * First one is basically the original essentially being called by: `ColorImage::from_rgba_unmultiplied()` * Second is the const Lookup table instead of the OnceLock and runtime generation. * Third is the fixed point implementation. At least looking at the bytes reported compiler explorer the OnceLock and the const Table results are in similar size, and the const table is surprisingly smaller when I compile to a binary object in compiler explorer. However though the oncelock is producing a lot SIMD instructions for initialization so I guess not too surprised. The fixed point math is much smaller than both. The const table is probably faster, but does bloat the binary images, and again when it's this fast to compute: https://llvm.godbolt.org/z/K83jEjvdq I am not sure the extra bytes are worth it. Next, what I did was merge `from_rgba_unmultiplied` and `from_rgba_unmultiplied_const`. Moreover with the fixed point math the `from_rgba_unmultiplied_const` is probably not necessary anymore, but it's part of the public API so I left it. Lastly, I just added a sanity test to make sure the math checks out which it does. You can even sweep the 2^16 inputs to be sure. --- crates/ecolor/src/color32.rs | 47 ++++++++++++------------------------ crates/ecolor/src/lib.rs | 11 +++++++++ 2 files changed, 27 insertions(+), 31 deletions(-) diff --git a/crates/ecolor/src/color32.rs b/crates/ecolor/src/color32.rs index 68a8fc3d..7a9cf72b 100644 --- a/crates/ecolor/src/color32.rs +++ b/crates/ecolor/src/color32.rs @@ -1,4 +1,4 @@ -use crate::{Rgba, fast_round, linear_f32_from_linear_u8}; +use crate::{Rgba, fast_round, mul_frac_round}; /// This format is used for space-efficient color representation (32 bits). /// @@ -131,35 +131,10 @@ impl Color32 { /// but for transparent colors what you get back might be slightly different (rounding errors). #[inline] pub fn from_rgba_unmultiplied(r: u8, g: u8, b: u8, a: u8) -> Self { - use std::sync::OnceLock; - match a { - // common-case optimization: - 0 => Self::TRANSPARENT, - - // common-case optimization: - 255 => Self::from_rgb(r, g, b), - - a => { - static LOOKUP_TABLE: OnceLock> = OnceLock::new(); - let lut = LOOKUP_TABLE.get_or_init(|| { - (0..=u16::MAX) - .map(|i| { - let [value, alpha] = i.to_ne_bytes(); - fast_round(value as f32 * linear_f32_from_linear_u8(alpha)) - }) - .collect() - }); - - let [r, g, b] = - [r, g, b].map(|value| lut[usize::from(u16::from_ne_bytes([value, a]))]); - Self::from_rgba_premultiplied(r, g, b, a) - } - } + Self::from_rgba_unmultiplied_const(r, g, b, a) } - /// Same as [`Self::from_rgba_unmultiplied`], but can be used in a const context. - /// - /// It is slightly slower when operating on non-const data. + /// This is the same as [`Self::from_rgba_unmultiplied`], but for const contexts. #[inline] pub const fn from_rgba_unmultiplied_const(r: u8, g: u8, b: u8, a: u8) -> Self { match a { @@ -170,9 +145,9 @@ impl Color32 { 255 => Self::from_rgb(r, g, b), a => { - let r = fast_round(r as f32 * linear_f32_from_linear_u8(a)); - let g = fast_round(g as f32 * linear_f32_from_linear_u8(a)); - let b = fast_round(b as f32 * linear_f32_from_linear_u8(a)); + let r = mul_frac_round(r, a); + let g = mul_frac_round(g, a); + let b = mul_frac_round(b, a); Self::from_rgba_premultiplied(r, g, b, a) } } @@ -535,4 +510,14 @@ mod test { Color32::from_rgba_unmultiplied(255, 0, 0, 128) ); } + + #[test] + fn mul_frac_round_vs_old() { + for x in (0..=255u8).step_by(4) { + for a in (1..=255u8).step_by(4) { + let old = fast_round(x as f32 * crate::linear_f32_from_linear_u8(a)); + assert_eq!(old, mul_frac_round(x, a)); + } + } + } } diff --git a/crates/ecolor/src/lib.rs b/crates/ecolor/src/lib.rs index ea7cff6f..02ea96c5 100644 --- a/crates/ecolor/src/lib.rs +++ b/crates/ecolor/src/lib.rs @@ -134,6 +134,17 @@ const fn fast_round(r: f32) -> u8 { (r + 0.5) as _ // rust does a saturating cast since 1.45 } +/// Compute val * (frac/255) with no floating point or divisions. +#[inline] +const fn mul_frac_round(val: u8, frac: u8) -> u8 { + // Treat this as a simple fixed point calculation + let p = (val as u16) * (frac as u16) + 128; + ((p + (p >> 8)) >> 8) as u8 + // Logic split out a bit more. + //let p = (val as u16) * (frac as u16) + 127; // + 127 to round or remove to truncate. + //return ((p + 1 + (p >> 8)) >> 8) as u8; +} + #[test] pub fn test_srgba_conversion() { for b in 0..=255 { From a3146e7327fc6b90b9f72c782b9a1747718ecfd4 Mon Sep 17 00:00:00 2001 From: Lucas Meurer Date: Tue, 1 Sep 2026 11:39:32 +0200 Subject: [PATCH 13/20] Properly respect `min_size` in `TextEdit` (#8420) TextEdit has a min_size field but we completely ignored in the y direciton. (I probably broke it in #7140). --------- Co-authored-by: emilk <1148717+emilk@users.noreply.github.com> --- crates/egui/src/widgets/text_edit/builder.rs | 5 +++-- tests/egui_tests/tests/snapshots/visuals/button.png | 4 ++-- tests/egui_tests/tests/snapshots/visuals/button_image.png | 4 ++-- .../tests/snapshots/visuals/button_image_shortcut.png | 4 ++-- .../snapshots/visuals/button_image_shortcut_selected.png | 4 ++-- tests/egui_tests/tests/snapshots/visuals/checkbox.png | 4 ++-- .../egui_tests/tests/snapshots/visuals/checkbox_checked.png | 4 ++-- tests/egui_tests/tests/snapshots/visuals/drag_value.png | 4 ++-- tests/egui_tests/tests/snapshots/visuals/radio.png | 4 ++-- tests/egui_tests/tests/snapshots/visuals/radio_checked.png | 4 ++-- .../egui_tests/tests/snapshots/visuals/selectable_value.png | 4 ++-- .../tests/snapshots/visuals/selectable_value_selected.png | 4 ++-- tests/egui_tests/tests/snapshots/visuals/slider.png | 4 ++-- tests/egui_tests/tests/snapshots/visuals/text_edit.png | 4 ++-- tests/egui_tests/tests/snapshots/visuals/text_edit_clip.png | 4 ++-- .../egui_tests/tests/snapshots/visuals/text_edit_no_clip.png | 4 ++-- .../tests/snapshots/visuals/text_edit_placeholder_clip.png | 4 ++-- .../tests/snapshots/visuals/text_edit_prefix_suffix.png | 4 ++-- tests/egui_tests/tests/test_widgets.rs | 2 +- 19 files changed, 38 insertions(+), 37 deletions(-) diff --git a/crates/egui/src/widgets/text_edit/builder.rs b/crates/egui/src/widgets/text_edit/builder.rs index 41220ed8..90d2de0d 100644 --- a/crates/egui/src/widgets/text_edit/builder.rs +++ b/crates/egui/src/widgets/text_edit/builder.rs @@ -478,7 +478,8 @@ impl TextEdit<'_> { let desired_width = desired_width .unwrap_or_else(|| ui.spacing().text_edit_width) .at_least(min_size.x); - let allocate_width = desired_width.at_most(available_width); + // `min_size` overrides available width + let allocate_width = desired_width.at_most(available_width).at_least(min_size.x); let font_id_clone = font_id.clone(); let mut default_layouter = move |ui: &Ui, text: &dyn TextBuffer, wrap_width: f32| { @@ -695,7 +696,7 @@ impl TextEdit<'_> { let custom_frame = frame.is_some(); let frame = frame.unwrap_or_else(|| Frame::new().inner_margin(margin)); - let min_height = min_inner_height + frame.total_margin().sum().y; + let min_height = (min_inner_height + frame.total_margin().sum().y).at_least(min_size.y); // This wrap mode only affects the hint_text let wrap_mode = if multiline { diff --git a/tests/egui_tests/tests/snapshots/visuals/button.png b/tests/egui_tests/tests/snapshots/visuals/button.png index 4978b5a3..5db43dc1 100644 --- a/tests/egui_tests/tests/snapshots/visuals/button.png +++ b/tests/egui_tests/tests/snapshots/visuals/button.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:2eb21d7b99171d249127377698225f0b2e103733864f6809785dfba169e133bf -size 11213 +oid sha256:86669a44b841a667154037a784cd52fd4df579c39445566479039b1a79677ffe +size 11056 diff --git a/tests/egui_tests/tests/snapshots/visuals/button_image.png b/tests/egui_tests/tests/snapshots/visuals/button_image.png index 9d366959..e3fbecaa 100644 --- a/tests/egui_tests/tests/snapshots/visuals/button_image.png +++ b/tests/egui_tests/tests/snapshots/visuals/button_image.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:3322b616a292f685f6051d2bf9be0df28ca7472e8fc3c982cd094ca44dc47ff8 -size 12117 +oid sha256:44efd277b842e9552b139397e4976afe284ed444de68e84cbb2a51e7676f6c84 +size 11961 diff --git a/tests/egui_tests/tests/snapshots/visuals/button_image_shortcut.png b/tests/egui_tests/tests/snapshots/visuals/button_image_shortcut.png index 41d88992..22811d59 100644 --- a/tests/egui_tests/tests/snapshots/visuals/button_image_shortcut.png +++ b/tests/egui_tests/tests/snapshots/visuals/button_image_shortcut.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:2021446525a7b1090aaa6b3f12fdd9295c67cde00de61c7f0d36838b6dfc2593 -size 15148 +oid sha256:3728220a44691967f8dc6e536334db153e2f7728cc6f401915e06009ca9f0205 +size 15012 diff --git a/tests/egui_tests/tests/snapshots/visuals/button_image_shortcut_selected.png b/tests/egui_tests/tests/snapshots/visuals/button_image_shortcut_selected.png index 3bb097ae..449c03e5 100644 --- a/tests/egui_tests/tests/snapshots/visuals/button_image_shortcut_selected.png +++ b/tests/egui_tests/tests/snapshots/visuals/button_image_shortcut_selected.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:e341f6d3fb3d9d09bd573584f68e4ada4e9af0dcb27cf1bc164797f62865c398 -size 14734 +oid sha256:8a65b2f34ade7fd4933bcd8b0dfc2c9283a74273a3314b37bdc956ea2e0f202c +size 14588 diff --git a/tests/egui_tests/tests/snapshots/visuals/checkbox.png b/tests/egui_tests/tests/snapshots/visuals/checkbox.png index e45ea9fb..b6624404 100644 --- a/tests/egui_tests/tests/snapshots/visuals/checkbox.png +++ b/tests/egui_tests/tests/snapshots/visuals/checkbox.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:9fd43ec4633a59798d2077d9fd3ad8292d5da66678a2d75d33c957a062d7848a -size 13218 +oid sha256:fb4a4d1ed28dd8e40631d6c6532e40b9ab52fc234824ff2902a6c804e24d31ce +size 13034 diff --git a/tests/egui_tests/tests/snapshots/visuals/checkbox_checked.png b/tests/egui_tests/tests/snapshots/visuals/checkbox_checked.png index 31f84dbe..861ea10b 100644 --- a/tests/egui_tests/tests/snapshots/visuals/checkbox_checked.png +++ b/tests/egui_tests/tests/snapshots/visuals/checkbox_checked.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:3e2252dbe6b26cc6b484d09c57a47f4ecd0d75df88f2279a7dd95ca43b597e9d -size 14282 +oid sha256:0c47f8200c9b760f6645f2605ec2cf3811939eab9c5f9baf792b834ca7a2342f +size 14123 diff --git a/tests/egui_tests/tests/snapshots/visuals/drag_value.png b/tests/egui_tests/tests/snapshots/visuals/drag_value.png index b327692c..bee29f82 100644 --- a/tests/egui_tests/tests/snapshots/visuals/drag_value.png +++ b/tests/egui_tests/tests/snapshots/visuals/drag_value.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:75e5610bd64f6beda7abb005344eff1f5ee23220272077d3b6ee5345baa616aa -size 9095 +oid sha256:6e1639b7b14086d14a124a5c9db641cb3e946c36ddc60c7b88835fc7a34a9309 +size 8870 diff --git a/tests/egui_tests/tests/snapshots/visuals/radio.png b/tests/egui_tests/tests/snapshots/visuals/radio.png index d8d6a052..28702387 100644 --- a/tests/egui_tests/tests/snapshots/visuals/radio.png +++ b/tests/egui_tests/tests/snapshots/visuals/radio.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:bceb25ddc48567a79389d8333eeffa3db4f083d47488a05772602d6145faf2ea -size 11830 +oid sha256:e31ef6a2ab778ceb81d8cc7c53902156848675a70328a739c4b6a5f52ea6372d +size 11639 diff --git a/tests/egui_tests/tests/snapshots/visuals/radio_checked.png b/tests/egui_tests/tests/snapshots/visuals/radio_checked.png index c746c028..457b1d4f 100644 --- a/tests/egui_tests/tests/snapshots/visuals/radio_checked.png +++ b/tests/egui_tests/tests/snapshots/visuals/radio_checked.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:30e17cfb5c21e3fd6f850e022f301787bd04d1e6453e3bd30ff695de1f61b8c1 -size 12524 +oid sha256:cabad94d00cf0705c5def54bf4c792da41e6724722ce18cf796c2e33c659b6fc +size 12326 diff --git a/tests/egui_tests/tests/snapshots/visuals/selectable_value.png b/tests/egui_tests/tests/snapshots/visuals/selectable_value.png index bb2b2a32..42856464 100644 --- a/tests/egui_tests/tests/snapshots/visuals/selectable_value.png +++ b/tests/egui_tests/tests/snapshots/visuals/selectable_value.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:b42c8d774d1ecb50f5bde1aa358a37cbb669b59d934786fb1cc4c6f0c3400701 -size 13711 +oid sha256:3f574151ea074ef70af25691055c8f2291a522026a8f2502fb28d72584c438a6 +size 13558 diff --git a/tests/egui_tests/tests/snapshots/visuals/selectable_value_selected.png b/tests/egui_tests/tests/snapshots/visuals/selectable_value_selected.png index 87163dd9..2c076742 100644 --- a/tests/egui_tests/tests/snapshots/visuals/selectable_value_selected.png +++ b/tests/egui_tests/tests/snapshots/visuals/selectable_value_selected.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:7037f694fef1211f2ea9d8e7e60836d8eb97c9242c7b396efeb8390eaf0852f1 -size 13730 +oid sha256:d91bf44102ee59824bf962b31ba3aa8ea8fe830260dfe65558ee43e453ee6bde +size 13578 diff --git a/tests/egui_tests/tests/snapshots/visuals/slider.png b/tests/egui_tests/tests/snapshots/visuals/slider.png index 8b758e10..2e3f5849 100644 --- a/tests/egui_tests/tests/snapshots/visuals/slider.png +++ b/tests/egui_tests/tests/snapshots/visuals/slider.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:2d09706e0dbbbf6d07e39470285dc8bcd1b3c6d09bedd91cd20d86c96dba1131 -size 9911 +oid sha256:ec1b69decaea772abb6ad8514e4222f519e542ae4b5a5ce065efff5a6799668c +size 9781 diff --git a/tests/egui_tests/tests/snapshots/visuals/text_edit.png b/tests/egui_tests/tests/snapshots/visuals/text_edit.png index 2cd2c737..e1062faa 100644 --- a/tests/egui_tests/tests/snapshots/visuals/text_edit.png +++ b/tests/egui_tests/tests/snapshots/visuals/text_edit.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:bf723b58802e9cf5aefb0a06689ed2bfaa45afff9f0fc48d37e742244da097e6 -size 8149 +oid sha256:923c11d8c5e6fe714c4e13872c64ac0b92b511cc1529632c87da64bf87991dc1 +size 7984 diff --git a/tests/egui_tests/tests/snapshots/visuals/text_edit_clip.png b/tests/egui_tests/tests/snapshots/visuals/text_edit_clip.png index 666364d6..e8a93d56 100644 --- a/tests/egui_tests/tests/snapshots/visuals/text_edit_clip.png +++ b/tests/egui_tests/tests/snapshots/visuals/text_edit_clip.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:e900a4004a1fc808bf74bef7b1ece7c98e16582c40155e222c04f759d229fc70 -size 10125 +oid sha256:5ec59ad084462293af619d2f5ef677f6b6b2d2cc4d948116b30f8feaf9a4e6f0 +size 9953 diff --git a/tests/egui_tests/tests/snapshots/visuals/text_edit_no_clip.png b/tests/egui_tests/tests/snapshots/visuals/text_edit_no_clip.png index fff21ac1..9e2262eb 100644 --- a/tests/egui_tests/tests/snapshots/visuals/text_edit_no_clip.png +++ b/tests/egui_tests/tests/snapshots/visuals/text_edit_no_clip.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:2119fd3aa9aefe8198e7b79968f7fafc4aa93294ba4c2577dc55929302067996 -size 21827 +oid sha256:bc819b970edba83b7402302ae768c7bb0f4855a640cca015df93f1688c4d3cbb +size 21668 diff --git a/tests/egui_tests/tests/snapshots/visuals/text_edit_placeholder_clip.png b/tests/egui_tests/tests/snapshots/visuals/text_edit_placeholder_clip.png index 0fb7a470..aadefacf 100644 --- a/tests/egui_tests/tests/snapshots/visuals/text_edit_placeholder_clip.png +++ b/tests/egui_tests/tests/snapshots/visuals/text_edit_placeholder_clip.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:02a333af5e58c53a89d436c4540579d3ea0c1e99c1cad4c019db1da34ff9de10 -size 8840 +oid sha256:bdf44d27b706413c9690be94266dbe0dc24f4864205223b23612b32e031497a7 +size 8668 diff --git a/tests/egui_tests/tests/snapshots/visuals/text_edit_prefix_suffix.png b/tests/egui_tests/tests/snapshots/visuals/text_edit_prefix_suffix.png index e00868b1..a36fb82b 100644 --- a/tests/egui_tests/tests/snapshots/visuals/text_edit_prefix_suffix.png +++ b/tests/egui_tests/tests/snapshots/visuals/text_edit_prefix_suffix.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:a37ed30425967301ffa7dda3fdc8f316dfd7f4665c731b17778e3e5942783e81 -size 10534 +oid sha256:3c333351ff6afdc0729077f49b7776d8fd4d303818f4d9d649e600f5d2c0afb8 +size 10370 diff --git a/tests/egui_tests/tests/test_widgets.rs b/tests/egui_tests/tests/test_widgets.rs index 5283b21d..f95cd58a 100644 --- a/tests/egui_tests/tests/test_widgets.rs +++ b/tests/egui_tests/tests/test_widgets.rs @@ -337,7 +337,7 @@ impl<'a> VisualTests<'a> { modifiers: Default::default(), }); }); - self.add_node("focussed", |node| { + self.add_node("focused", |node| { node.focus(); }); self.add_disabled(); From d19ed821b89a856d3fcd750b7c53bf1dff37e29c Mon Sep 17 00:00:00 2001 From: Lucas Meurer Date: Thu, 3 Sep 2026 16:54:51 +0200 Subject: [PATCH 14/20] Add new `render_every_step` flag to egui_kittest (#8487) Some applications / test depend on specific gpu state and may be doing gpu-readback. This adds a `always_render` flag, which calls `render` every frame so that the gpu dependent logic will work correctly. It also saves the last render result so we don't have to render the same frame twice. --- crates/egui_kittest/src/builder.rs | 16 ++++++++ crates/egui_kittest/src/lib.rs | 60 +++++++++++++++++++++++++++++- 2 files changed, 75 insertions(+), 1 deletion(-) diff --git a/crates/egui_kittest/src/builder.rs b/crates/egui_kittest/src/builder.rs index 23109544..dfaa7af3 100644 --- a/crates/egui_kittest/src/builder.rs +++ b/crates/egui_kittest/src/builder.rs @@ -18,6 +18,9 @@ pub struct HarnessBuilder { pub(crate) renderer: Box, pub(crate) wait_for_pending_images: bool, + #[cfg(any(feature = "wgpu", feature = "snapshot"))] + pub(crate) render_every_step: bool, + #[cfg(feature = "snapshot")] pub(crate) default_snapshot_options: crate::SnapshotOptions, @@ -36,6 +39,9 @@ impl Default for HarnessBuilder { max_steps: 4, step_dt: 1.0 / 4.0, wait_for_pending_images: true, + + #[cfg(any(feature = "wgpu", feature = "snapshot"))] + render_every_step: false, os: egui::os::OperatingSystem::Nix, #[cfg(feature = "snapshot")] @@ -127,6 +133,16 @@ impl HarnessBuilder { self } + /// Should every step be rendered? + /// + /// Useful when test logic requires some specific gpu logic, e.g. reading data back from the gpu. + #[cfg(any(feature = "wgpu", feature = "snapshot"))] + #[inline] + pub fn with_render_every_step(mut self, render_every_step: bool) -> Self { + self.render_every_step = render_every_step; + self + } + /// Configures the [`egui_wgpu::RendererOptions`] used by this harness. /// /// The default is [`egui_wgpu::RendererOptions::PREDICTABLE`]. diff --git a/crates/egui_kittest/src/lib.rs b/crates/egui_kittest/src/lib.rs index fa8f2631..ab6cba19 100644 --- a/crates/egui_kittest/src/lib.rs +++ b/crates/egui_kittest/src/lib.rs @@ -78,6 +78,19 @@ pub struct Harness<'a, State = ()> { response: Option, state: State, renderer: Box, + + /// The image of a pass we already rendered, keyed by [`egui::Context::cumulative_pass_nr`]. + /// + /// A pass should be rendered at most once. A paint callback can do GPU work of its own — + /// schedule a readback, say — and running it a second time for the same pass corrupts that + /// work. + #[cfg(any(feature = "wgpu", feature = "snapshot"))] + last_render: Option<(u64, image::RgbaImage)>, + + /// Render every pass. See [`HarnessBuilder::with_render_every_step`]. + #[cfg(any(feature = "wgpu", feature = "snapshot"))] + render_every_step: bool, + max_steps: u64, step_dt: f32, wait_for_pending_images: bool, @@ -114,6 +127,9 @@ impl<'a, State> Harness<'a, State> { mut renderer, wait_for_pending_images, + #[cfg(any(feature = "wgpu", feature = "snapshot"))] + render_every_step, + #[cfg(feature = "snapshot")] default_snapshot_options, @@ -164,6 +180,13 @@ impl<'a, State> Harness<'a, State> { response, state, renderer, + + #[cfg(any(feature = "wgpu", feature = "snapshot"))] + last_render: None, + + #[cfg(any(feature = "wgpu", feature = "snapshot"))] + render_every_step, + max_steps, step_dt, wait_for_pending_images, @@ -272,6 +295,12 @@ impl<'a, State> Harness<'a, State> { self.renderer.handle_delta(&mut output.textures_delta); self.output = output; + #[cfg(any(feature = "wgpu", feature = "snapshot"))] + if self.render_every_step { + self.render() + .expect("Failed to render during `render_every_step`"); + } + self.handle_viewport_commands(); } @@ -630,18 +659,45 @@ impl<'a, State> Harness<'a, State> { /// This will add a [`RectShape`] to the output shapes, for the current frame. /// Will be overwritten on the next call to [`Self::run`]. pub fn mask(&mut self, rect: Rect) { + #[cfg(any(feature = "wgpu", feature = "snapshot"))] + { + // This changes what a render of this pass looks like. + self.last_render = None; + } + self.output.shapes.push(ClippedShape { clip_rect: Rect::EVERYTHING, shape: Shape::Rect(RectShape::filled(rect, 0.0, Color32::MAGENTA)), }); } + /// Should every step be rendered? + /// + /// Useful when test logic requires some specific gpu logic, e.g. reading data back from the gpu. + #[cfg(any(feature = "wgpu", feature = "snapshot"))] + #[inline] + pub fn set_render_every_step(&mut self, render_every_step: bool) { + self.render_every_step = render_every_step; + } + /// Render the last output to an image. /// + /// When calling this multiple times on the same frame, or when [`Self::set_render_every_step`] is + /// true, this will return the already-rendered frame. + /// /// # Errors /// Returns an error if the rendering fails. #[cfg(any(feature = "wgpu", feature = "snapshot"))] pub fn render(&mut self) -> Result { + let pass_nr = self.ctx.cumulative_pass_nr(); + + // Rendering a pass twice would run its paint callbacks twice. See `last_render`. + if let Some((rendered_pass_nr, image)) = &self.last_render + && *rendered_pass_nr == pass_nr + { + return Ok(image.clone()); + } + let mut output = self.output.clone(); if let Some(mouse_pos) = self.ctx.input(|i| i.pointer.hover_pos()) { @@ -663,7 +719,9 @@ impl<'a, State> Harness<'a, State> { }); } - self.renderer.render(&self.ctx, &output) + let image = self.renderer.render(&self.ctx, &output)?; + self.last_render = Some((pass_nr, image.clone())); + Ok(image) } /// Apply the [`egui::ViewportCommand`]s the app emitted during the last frame. From 459f98a73e257e9b6371fa0a8652882ed5867023 Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Tue, 8 Sep 2026 15:45:49 +0200 Subject: [PATCH 15/20] Add `TextEdit::event_filter` (#8530) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Lets you control which keys a `TextEdit` captures while it has focus, instead of letting egui use them for focus navigation. Needed e.g. for a completion popup, where Tab and Escape should act on the popup rather than move focus away. Split out from: * https://github.com/emilk/egui/pull/8529 * [x] I have followed the instructions in the PR template 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Fable 5.1 --- crates/egui/src/widgets/text_edit/builder.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/crates/egui/src/widgets/text_edit/builder.rs b/crates/egui/src/widgets/text_edit/builder.rs index 90d2de0d..7f35f792 100644 --- a/crates/egui/src/widgets/text_edit/builder.rs +++ b/crates/egui/src/widgets/text_edit/builder.rs @@ -343,6 +343,22 @@ impl<'t> TextEdit<'t> { self } + /// Set which key presses this [`TextEdit`] captures while it has focus. + /// + /// Keys not captured by the filter are instead used by egui for + /// keyboard navigation (tab and arrows move focus, escape surrenders focus). + /// + /// The default captures the arrow keys, but not tab or escape. + /// This is useful e.g. to implement a code completion popup, + /// where tab and escape should act on the popup instead of moving focus away. + /// + /// See also [`Self::lock_focus`]. + #[inline] + pub fn event_filter(mut self, event_filter: EventFilter) -> Self { + self.event_filter = event_filter; + self + } + /// When `true` (default), the cursor will initially be placed at the end of the text. /// /// When `false`, the cursor will initially be placed at the beginning of the text. From 49682f8baa058bf49e011035cfbd6e825f88a5ef Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Tue, 8 Sep 2026 16:40:19 +0200 Subject: [PATCH 16/20] Release 0.36.2 - Assorted fixes Bump all crates to 0.36.2 and generate changelogs with `scripts/generate_changelog.py --version 0.36.2 --write`. Co-Authored-By: Claude Opus 5 (1M context) --- CHANGELOG.md | 16 +++++++++++ Cargo.lock | 34 ++++++++++++------------ Cargo.toml | 28 +++++++++---------- crates/ecolor/CHANGELOG.md | 4 +++ crates/eframe/CHANGELOG.md | 7 +++++ crates/egui-wgpu/CHANGELOG.md | 4 +++ crates/egui-winit/CHANGELOG.md | 4 +++ crates/egui_extras/CHANGELOG.md | 4 +++ crates/egui_glow/CHANGELOG.md | 4 +++ crates/egui_inspection/CHANGELOG.md | 4 +++ crates/egui_kittest/CHANGELOG.md | 4 +++ crates/emath/CHANGELOG.md | 4 +++ crates/epaint/CHANGELOG.md | 5 ++++ crates/epaint_default_fonts/CHANGELOG.md | 4 +++ 14 files changed, 95 insertions(+), 31 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 39727969..a4ee2f16 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,22 @@ This file is updated upon each release. Changes since the last release can be found at or by running the `scripts/generate_changelog.py` script. +## 0.36.2 - 2026-09-08 +### ⭐ Added +* Add `TextEdit::event_filter` [#8530](https://github.com/emilk/egui/pull/8530) by [@emilk](https://github.com/emilk) + +### 🔧 Changed +* Fallback `window_title_frame` to `window_frame` when unspecified [#8400](https://github.com/emilk/egui/pull/8400) by [@rustbasic](https://github.com/rustbasic) +* Don't revert external changes to a focused `DragValue` [#8403](https://github.com/emilk/egui/pull/8403) by [@teddytennant](https://github.com/teddytennant) + +### 🐛 Fixed +* Match image file extensions case-insensitively [#8430](https://github.com/emilk/egui/pull/8430) by [@emilk](https://github.com/emilk) +* Fix rendering of thin, angled rectangles [#8482](https://github.com/emilk/egui/pull/8482) by [@emilk](https://github.com/emilk) +* Fix zero-duration value animations returning the previous value [#8469](https://github.com/emilk/egui/pull/8469) by [@cuishuang](https://github.com/cuishuang) +* Fix panic in hit-test when a widget rect contains a NaN [#8479](https://github.com/emilk/egui/pull/8479) by [@emilk](https://github.com/emilk) +* Properly respect `min_size` in `TextEdit` [#8420](https://github.com/emilk/egui/pull/8420) by [@lucasmerlin](https://github.com/lucasmerlin) + + ## 0.36.1 - 2026-08-07 * Fix `Sense::drag` detecting drags when clicking widget above it [#8396](https://github.com/emilk/egui/pull/8396) by [@lucasmerlin](https://github.com/lucasmerlin) diff --git a/Cargo.lock b/Cargo.lock index e472f7c3..c32287fa 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1243,7 +1243,7 @@ checksum = "d8b14ccef22fc6f5a8f4d7d768562a182c04ce9a3b3157b91390b52ddfdf1a76" [[package]] name = "ecolor" -version = "0.36.1" +version = "0.36.2" dependencies = [ "bytemuck", "cint", @@ -1255,7 +1255,7 @@ dependencies = [ [[package]] name = "eframe" -version = "0.36.1" +version = "0.36.2" dependencies = [ "ahash", "bytemuck", @@ -1293,7 +1293,7 @@ dependencies = [ [[package]] name = "egui" -version = "0.36.1" +version = "0.36.2" dependencies = [ "accesskit", "ahash", @@ -1315,7 +1315,7 @@ dependencies = [ [[package]] name = "egui-wgpu" -version = "0.36.1" +version = "0.36.2" dependencies = [ "ahash", "bytemuck", @@ -1333,7 +1333,7 @@ dependencies = [ [[package]] name = "egui-winit" -version = "0.36.1" +version = "0.36.2" dependencies = [ "accesskit_winit", "arboard", @@ -1356,7 +1356,7 @@ dependencies = [ [[package]] name = "egui_demo_app" -version = "0.36.1" +version = "0.36.2" dependencies = [ "accesskit", "accesskit_consumer", @@ -1385,7 +1385,7 @@ dependencies = [ [[package]] name = "egui_demo_lib" -version = "0.36.1" +version = "0.36.2" dependencies = [ "criterion", "document-features", @@ -1403,7 +1403,7 @@ dependencies = [ [[package]] name = "egui_extras" -version = "0.36.1" +version = "0.36.2" dependencies = [ "ahash", "document-features", @@ -1423,7 +1423,7 @@ dependencies = [ [[package]] name = "egui_glow" -version = "0.36.1" +version = "0.36.2" dependencies = [ "bytemuck", "document-features", @@ -1439,7 +1439,7 @@ dependencies = [ [[package]] name = "egui_inspection" -version = "0.36.1" +version = "0.36.2" dependencies = [ "document-features", "egui", @@ -1452,7 +1452,7 @@ dependencies = [ [[package]] name = "egui_kittest" -version = "0.36.1" +version = "0.36.2" dependencies = [ "dify", "document-features", @@ -1473,7 +1473,7 @@ dependencies = [ [[package]] name = "egui_tests" -version = "0.36.1" +version = "0.36.2" dependencies = [ "egui", "egui_extras", @@ -1503,7 +1503,7 @@ checksum = "91622ff5e7162018101f2fea40d6ebf4a78bbe5a49736a2020649edf9693679e" [[package]] name = "emath" -version = "0.36.1" +version = "0.36.2" dependencies = [ "bytemuck", "document-features", @@ -1601,7 +1601,7 @@ dependencies = [ [[package]] name = "epaint" -version = "0.36.1" +version = "0.36.2" dependencies = [ "ahash", "bytemuck", @@ -1630,7 +1630,7 @@ dependencies = [ [[package]] name = "epaint_default_fonts" -version = "0.36.1" +version = "0.36.2" [[package]] name = "equivalent" @@ -3594,7 +3594,7 @@ dependencies = [ [[package]] name = "popups" -version = "0.36.1" +version = "0.36.2" dependencies = [ "eframe", "env_logger", @@ -5903,7 +5903,7 @@ checksum = "ec7a2a501ed189703dba8b08142f057e887dfc4b2cc4db2d343ac6376ba3e0b9" [[package]] name = "xtask" -version = "0.36.1" +version = "0.36.2" [[package]] name = "yaml-rust" diff --git a/Cargo.toml b/Cargo.toml index 5f087c30..3224f281 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,7 +25,7 @@ members = [ edition = "2024" license = "MIT OR Apache-2.0" rust-version = "1.95" -version = "0.36.1" +version = "0.36.2" [profile.release] @@ -56,19 +56,19 @@ opt-level = 2 [workspace.dependencies] -emath = { version = "0.36.1", path = "crates/emath", default-features = false } -ecolor = { version = "0.36.1", path = "crates/ecolor", default-features = false } -epaint = { version = "0.36.1", path = "crates/epaint", default-features = false } -epaint_default_fonts = { version = "0.36.1", path = "crates/epaint_default_fonts" } -egui = { version = "0.36.1", path = "crates/egui", default-features = false } -egui-winit = { version = "0.36.1", path = "crates/egui-winit", default-features = false } -egui_extras = { version = "0.36.1", path = "crates/egui_extras", default-features = false } -egui-wgpu = { version = "0.36.1", path = "crates/egui-wgpu", default-features = false } -egui_demo_lib = { version = "0.36.1", path = "crates/egui_demo_lib", default-features = false } -egui_glow = { version = "0.36.1", path = "crates/egui_glow", default-features = false } -egui_inspection = { version = "0.36.1", path = "crates/egui_inspection", default-features = false } -egui_kittest = { version = "0.36.1", path = "crates/egui_kittest", default-features = false } -eframe = { version = "0.36.1", path = "crates/eframe", default-features = false } +emath = { version = "0.36.2", path = "crates/emath", default-features = false } +ecolor = { version = "0.36.2", path = "crates/ecolor", default-features = false } +epaint = { version = "0.36.2", path = "crates/epaint", default-features = false } +epaint_default_fonts = { version = "0.36.2", path = "crates/epaint_default_fonts" } +egui = { version = "0.36.2", path = "crates/egui", default-features = false } +egui-winit = { version = "0.36.2", path = "crates/egui-winit", default-features = false } +egui_extras = { version = "0.36.2", path = "crates/egui_extras", default-features = false } +egui-wgpu = { version = "0.36.2", path = "crates/egui-wgpu", default-features = false } +egui_demo_lib = { version = "0.36.2", path = "crates/egui_demo_lib", default-features = false } +egui_glow = { version = "0.36.2", path = "crates/egui_glow", default-features = false } +egui_inspection = { version = "0.36.2", path = "crates/egui_inspection", default-features = false } +egui_kittest = { version = "0.36.2", path = "crates/egui_kittest", default-features = false } +eframe = { version = "0.36.2", path = "crates/eframe", default-features = false } accesskit = "0.24.1" accesskit_consumer = "0.35.0" # Can't update to 0.36+: kittest 0.4 pins accesskit_consumer 0.35, so bumping splits it into two versions diff --git a/crates/ecolor/CHANGELOG.md b/crates/ecolor/CHANGELOG.md index 31300e17..fbb56d5f 100644 --- a/crates/ecolor/CHANGELOG.md +++ b/crates/ecolor/CHANGELOG.md @@ -6,6 +6,10 @@ This file is updated upon each release. Changes since the last release can be found at or by running the `scripts/generate_changelog.py` script. +## 0.36.2 - 2026-09-08 +Nothing new + + ## 0.36.1 - 2026-08-07 Nothing new diff --git a/crates/eframe/CHANGELOG.md b/crates/eframe/CHANGELOG.md index eb3dcb35..e3dd5d91 100644 --- a/crates/eframe/CHANGELOG.md +++ b/crates/eframe/CHANGELOG.md @@ -7,6 +7,13 @@ This file is updated upon each release. Changes since the last release can be found at or by running the `scripts/generate_changelog.py` script. +## 0.36.2 - 2026-09-08 +* Don't busy-loop a CPU core while waiting for a redraw [#8398](https://github.com/emilk/egui/pull/8398) by [@42Pupusas](https://github.com/42Pupusas) +* Hide drop shadow window decoration when in fullscreen mode [#8449](https://github.com/emilk/egui/pull/8449) by [@tarolling](https://github.com/tarolling) +* Fix transparent child viewports on `Windows` with `glow` [#8423](https://github.com/emilk/egui/pull/8423) by [@rustbasic](https://github.com/rustbasic) +* Apply ViewportBuilder::with_monitor on the glow backend [#8302](https://github.com/emilk/egui/pull/8302) by [@Le-Syl21](https://github.com/Le-Syl21) + + ## 0.36.1 - 2026-08-07 Nothing new diff --git a/crates/egui-wgpu/CHANGELOG.md b/crates/egui-wgpu/CHANGELOG.md index b2d1063b..82bc4e52 100644 --- a/crates/egui-wgpu/CHANGELOG.md +++ b/crates/egui-wgpu/CHANGELOG.md @@ -6,6 +6,10 @@ This file is updated upon each release. Changes since the last release can be found at or by running the `scripts/generate_changelog.py` script. +## 0.36.2 - 2026-09-08 +* Fix `egui-wgpu` build on `wasm32-unknown-emscripten` [#8454](https://github.com/emilk/egui/pull/8454) by [@bfeip](https://github.com/bfeip) + + ## 0.36.1 - 2026-08-07 Nothing new diff --git a/crates/egui-winit/CHANGELOG.md b/crates/egui-winit/CHANGELOG.md index f7ed2fa0..2c9c8ddd 100644 --- a/crates/egui-winit/CHANGELOG.md +++ b/crates/egui-winit/CHANGELOG.md @@ -5,6 +5,10 @@ This file is updated upon each release. Changes since the last release can be found at or by running the `scripts/generate_changelog.py` script. +## 0.36.2 - 2026-09-08 +* Hide drop shadow window decoration when in fullscreen mode [#8449](https://github.com/emilk/egui/pull/8449) by [@tarolling](https://github.com/tarolling) + + ## 0.36.1 - 2026-08-07 Nothing new diff --git a/crates/egui_extras/CHANGELOG.md b/crates/egui_extras/CHANGELOG.md index db7464d9..f2dfe160 100644 --- a/crates/egui_extras/CHANGELOG.md +++ b/crates/egui_extras/CHANGELOG.md @@ -5,6 +5,10 @@ This file is updated upon each release. Changes since the last release can be found at or by running the `scripts/generate_changelog.py` script. +## 0.36.2 - 2026-09-08 +Nothing new + + ## 0.36.1 - 2026-08-07 Nothing new diff --git a/crates/egui_glow/CHANGELOG.md b/crates/egui_glow/CHANGELOG.md index 959f16b5..28318630 100644 --- a/crates/egui_glow/CHANGELOG.md +++ b/crates/egui_glow/CHANGELOG.md @@ -6,6 +6,10 @@ Changes since the last release can be found at or by running the `scripts/generate_changelog.py` script. +## 0.36.2 - 2026-09-08 +Nothing new + + ## 0.36.1 - 2026-08-07 Nothing new diff --git a/crates/egui_kittest/CHANGELOG.md b/crates/egui_kittest/CHANGELOG.md index fe999ffc..369bf91a 100644 --- a/crates/egui_kittest/CHANGELOG.md +++ b/crates/egui_kittest/CHANGELOG.md @@ -6,6 +6,10 @@ This file is updated upon each release. Changes since the last release can be found at or by running the `scripts/generate_changelog.py` script. +## 0.36.2 - 2026-09-08 +* Add new `render_every_step` flag to egui_kittest [#8487](https://github.com/emilk/egui/pull/8487) by [@lucasmerlin](https://github.com/lucasmerlin) + + ## 0.36.1 - 2026-08-07 Nothing new diff --git a/crates/emath/CHANGELOG.md b/crates/emath/CHANGELOG.md index 2361112d..2aed4718 100644 --- a/crates/emath/CHANGELOG.md +++ b/crates/emath/CHANGELOG.md @@ -6,6 +6,10 @@ This file is updated upon each release. Changes since the last release can be found at or by running the `scripts/generate_changelog.py` script. +## 0.36.2 - 2026-09-08 +Nothing new + + ## 0.36.1 - 2026-08-07 Nothing new diff --git a/crates/epaint/CHANGELOG.md b/crates/epaint/CHANGELOG.md index d0db754f..f437c402 100644 --- a/crates/epaint/CHANGELOG.md +++ b/crates/epaint/CHANGELOG.md @@ -5,6 +5,11 @@ This file is updated upon each release. Changes since the last release can be found at or by running the `scripts/generate_changelog.py` script. +## 0.36.2 - 2026-09-08 +* Fix rendering of thin, angled rectangles [#8482](https://github.com/emilk/egui/pull/8482) by [@emilk](https://github.com/emilk) +* Simplify and optimize `Color32::from_rgba_unmultiplied` [#8427](https://github.com/emilk/egui/pull/8427) by [@Keith-Cancel](https://github.com/Keith-Cancel) + + ## 0.36.1 - 2026-08-07 Nothing new diff --git a/crates/epaint_default_fonts/CHANGELOG.md b/crates/epaint_default_fonts/CHANGELOG.md index 0d6af564..a2d8db17 100644 --- a/crates/epaint_default_fonts/CHANGELOG.md +++ b/crates/epaint_default_fonts/CHANGELOG.md @@ -5,6 +5,10 @@ This file is updated upon each release. Changes since the last release can be found at or by running the `scripts/generate_changelog.py` script. +## 0.36.2 - 2026-09-08 +Nothing new + + ## 0.36.1 - 2026-08-07 Nothing new From e7e37ad580bd2e6cd1e3be80f5f8c78af9c0c9d8 Mon Sep 17 00:00:00 2001 From: skylartaylor <26588250+skylartaylor@users.noreply.github.com> Date: Tue, 20 Oct 2026 04:08:22 +0200 Subject: [PATCH 17/20] E1: eframe: ViewportHooks for per-viewport windows and raw input NativeOptions::viewport_hooks reports each viewport's native window when eframe creates it (root, deferred and immediate; glow reports a window once even though its initialize_window runs every frame) and when the viewport is removed, and receives every viewport's raw input before egui processes it, including immediate viewports, which skip App::raw_input_hook. Needed by craft-tablet to route native Wayland pen events. Not proposed upstream yet. --- crates/eframe/src/epi.rs | 10 ++++++ crates/eframe/src/lib.rs | 5 +++ crates/eframe/src/native/epi_integration.rs | 1 + crates/eframe/src/native/glow_integration.rs | 16 +++++++-- crates/eframe/src/native/mod.rs | 2 ++ crates/eframe/src/native/viewport_hooks.rs | 38 ++++++++++++++++++++ crates/eframe/src/native/wgpu_integration.rs | 20 +++++++++-- 7 files changed, 87 insertions(+), 5 deletions(-) create mode 100644 crates/eframe/src/native/viewport_hooks.rs diff --git a/crates/eframe/src/epi.rs b/crates/eframe/src/epi.rs index a971097a..ef01e338 100644 --- a/crates/eframe/src/epi.rs +++ b/crates/eframe/src/epi.rs @@ -400,6 +400,10 @@ pub struct NativeOptions { /// [`with_android_app`]: winit::platform::android::EventLoopBuilderExtAndroid::with_android_app #[cfg(target_os = "android")] pub android_app: Option, + + /// Per-viewport window and raw-input callbacks, see [`crate::ViewportHooks`]. + #[cfg(any(feature = "glow", feature = "wgpu_no_default_features"))] + pub viewport_hooks: Option>, } #[cfg(not(target_arch = "wasm32"))] @@ -425,6 +429,9 @@ impl Clone for NativeOptions { #[cfg(target_os = "android")] android_app: self.android_app.clone(), + #[cfg(any(feature = "glow", feature = "wgpu_no_default_features"))] + viewport_hooks: self.viewport_hooks.clone(), + ..*self } } @@ -468,6 +475,9 @@ impl Default for NativeOptions { #[cfg(target_os = "android")] android_app: None, + + #[cfg(any(feature = "glow", feature = "wgpu_no_default_features"))] + viewport_hooks: None, } } } diff --git a/crates/eframe/src/lib.rs b/crates/eframe/src/lib.rs index 55caffdd..10e0abda 100644 --- a/crates/eframe/src/lib.rs +++ b/crates/eframe/src/lib.rs @@ -197,6 +197,10 @@ pub use native::macos::WindowChromeMetrics; #[cfg(any(feature = "glow", feature = "wgpu_no_default_features"))] pub use native::run::EframeWinitApplication; +#[cfg(not(target_arch = "wasm32"))] +#[cfg(any(feature = "glow", feature = "wgpu_no_default_features"))] +pub use native::viewport_hooks::ViewportHooks; + #[cfg(not(any(target_arch = "wasm32", target_os = "ios")))] #[cfg(any(feature = "glow", feature = "wgpu_no_default_features"))] pub use native::run::EframePumpStatus; @@ -310,6 +314,7 @@ pub fn run_native_ext( app_creator: AppCreator<'_>, ) -> Result { let renderer = init_native(app_name, &mut native_options); + native::viewport_hooks::install(native_options.viewport_hooks.clone()); match renderer { #[cfg(feature = "glow")] diff --git a/crates/eframe/src/native/epi_integration.rs b/crates/eframe/src/native/epi_integration.rs index b8122563..55167524 100644 --- a/crates/eframe/src/native/epi_integration.rs +++ b/crates/eframe/src/native/epi_integration.rs @@ -359,6 +359,7 @@ impl EpiIntegration { raw_input.time = Some(self.beginning.elapsed().as_secs_f64()); + super::viewport_hooks::with(|hooks| hooks.raw_input(&self.egui_ctx, &mut raw_input)); app.raw_input_hook(&self.egui_ctx, &mut raw_input); raw_input diff --git a/crates/eframe/src/native/glow_integration.rs b/crates/eframe/src/native/glow_integration.rs index 82a150aa..873039b5 100644 --- a/crates/eframe/src/native/glow_integration.rs +++ b/crates/eframe/src/native/glow_integration.rs @@ -1173,6 +1173,7 @@ impl GlutinWindowContext { let mut viewport_info = ViewportInfo::default(); if let Some(window) = &window { viewport_from_window.insert(window.id(), ViewportId::ROOT); + super::viewport_hooks::with(|hooks| hooks.window_created(ViewportId::ROOT, window)); window_from_viewport.insert(ViewportId::ROOT, window.id()); egui_winit::update_viewport_info(&mut viewport_info, egui_ctx, window, true); @@ -1374,7 +1375,10 @@ impl GlutinWindowContext { self.current_gl_context = Some(current_gl_context); } - self.viewport_from_window.insert(window.id(), viewport_id); + // This runs on every frame; report a window only when it is new for this viewport. + if self.viewport_from_window.insert(window.id(), viewport_id) != Some(viewport_id) { + super::viewport_hooks::with(|hooks| hooks.window_created(viewport_id, &window)); + } self.window_from_viewport.insert(viewport_id, window.id()); Ok(()) @@ -1442,8 +1446,13 @@ impl GlutinWindowContext { viewport_output: &OrderedViewportIdMap, ) { // GC old viewports - self.viewports - .retain(|id, _| viewport_output.contains_key(id)); + self.viewports.retain(|id, _| { + let keep = viewport_output.contains_key(id); + if !keep { + super::viewport_hooks::with(|hooks| hooks.window_destroyed(*id)); + } + keep + }); self.viewport_from_window .retain(|_, id| viewport_output.contains_key(id)); self.window_from_viewport @@ -1658,6 +1667,7 @@ fn render_immediate_viewport( .map(|(id, viewport)| (*id, viewport.info.clone())) .collect(); raw_input.time = Some(beginning.elapsed().as_secs_f64()); + super::viewport_hooks::with(|hooks| hooks.raw_input(egui_ctx, &mut raw_input)); raw_input }; diff --git a/crates/eframe/src/native/mod.rs b/crates/eframe/src/native/mod.rs index 771964ae..aa75505b 100644 --- a/crates/eframe/src/native/mod.rs +++ b/crates/eframe/src/native/mod.rs @@ -3,6 +3,8 @@ mod epi_integration; mod event_loop_context; pub mod run; +pub mod viewport_hooks; + #[cfg(target_os = "macos")] pub(crate) mod macos; diff --git a/crates/eframe/src/native/viewport_hooks.rs b/crates/eframe/src/native/viewport_hooks.rs new file mode 100644 index 00000000..bc1c8e4a --- /dev/null +++ b/crates/eframe/src/native/viewport_hooks.rs @@ -0,0 +1,38 @@ +//! Per-viewport native window and raw-input hooks. +//! +//! eframe exposes the root window's handles through [`crate::CreationContext`] only, and runs +//! [`crate::App::raw_input_hook`] for the root and deferred viewports but not for immediate ones. +//! Integrations that need every viewport's native window (for example to match Wayland surfaces +//! named by a protocol the windowing layer doesn't implement) or that must add input to every +//! viewport before egui processes it can set [`crate::NativeOptions::viewport_hooks`]. + +use std::sync::{Arc, PoisonError, RwLock}; + +/// Callbacks eframe makes for every viewport. All methods have empty defaults. +/// +/// They run on the event loop thread, inside eframe's frame handling: keep them short and don't +/// call back into eframe or block. +pub trait ViewportHooks: Send + Sync { + /// eframe created the native window of `viewport` (root, deferred or immediate). + fn window_created(&self, _viewport: egui::ViewportId, _window: &winit::window::Window) {} + + /// eframe dropped `viewport`; its window is about to be (or has been) destroyed. + fn window_destroyed(&self, _viewport: egui::ViewportId) {} + + /// The raw input of one viewport (`raw_input.viewport_id`), before egui processes it. Runs for + /// root, deferred and immediate viewports, before [`crate::App::raw_input_hook`]. + fn raw_input(&self, _ctx: &egui::Context, _raw_input: &mut egui::RawInput) {} +} + +static HOOKS: RwLock>> = RwLock::new(None); + +pub(crate) fn install(hooks: Option>) { + *HOOKS.write().unwrap_or_else(PoisonError::into_inner) = hooks; +} + +pub(crate) fn with(f: impl FnOnce(&dyn ViewportHooks)) { + let hooks = HOOKS.read().unwrap_or_else(PoisonError::into_inner).clone(); + if let Some(hooks) = hooks { + f(&*hooks); + } +} diff --git a/crates/eframe/src/native/wgpu_integration.rs b/crates/eframe/src/native/wgpu_integration.rs index 4a94a5d4..a56a57c3 100644 --- a/crates/eframe/src/native/wgpu_integration.rs +++ b/crates/eframe/src/native/wgpu_integration.rs @@ -335,6 +335,7 @@ impl<'app> WgpuWinitApp<'app> { let mut viewport_from_window = HashMap::default(); viewport_from_window.insert(window.id(), ViewportId::ROOT); + super::viewport_hooks::with(|hooks| hooks.window_created(ViewportId::ROOT, &window)); let mut viewports = Viewports::default(); viewports.insert( @@ -861,7 +862,13 @@ impl WgpuWinitRunning<'_> { ); // Prune dead viewports: - viewports.retain(|id, _| active_viewports_ids.contains(id)); + viewports.retain(|id, _| { + let keep = active_viewports_ids.contains(id); + if !keep { + super::viewport_hooks::with(|hooks| hooks.window_destroyed(*id)); + } + keep + }); viewport_from_window.retain(|_, id| active_viewports_ids.contains(id)); painter.gc_viewports(&active_viewports_ids); @@ -1067,6 +1074,7 @@ impl Viewport { match egui_winit::create_window(egui_ctx, event_loop, &self.builder) { Ok(window) => { windows_id.insert(window.id(), viewport_id); + super::viewport_hooks::with(|hooks| hooks.window_created(viewport_id, &window)); let window = Arc::new(window); @@ -1183,6 +1191,8 @@ fn render_immediate_viewport( .map(|(id, viewport)| (*id, viewport.info.clone())) .collect(); input.time = Some(beginning.elapsed().as_secs_f64()); + let egui_ctx = egui_ctx.clone(); + super::viewport_hooks::with(|hooks| hooks.raw_input(&egui_ctx, &mut input)); input }; @@ -1265,7 +1275,13 @@ pub(crate) fn remove_viewports_not_in( let active_viewports_ids: ViewportIdSet = viewport_output.keys().copied().collect(); // Prune dead viewports: - viewports.retain(|id, _| active_viewports_ids.contains(id)); + viewports.retain(|id, _| { + let keep = active_viewports_ids.contains(id); + if !keep { + super::viewport_hooks::with(|hooks| hooks.window_destroyed(*id)); + } + keep + }); viewport_from_window.retain(|_, id| active_viewports_ids.contains(id)); painter.gc_viewports(&active_viewports_ids); } From b02321d7405585d2ab76076d3bc2b199fedb4d0a Mon Sep 17 00:00:00 2001 From: jcl-bit <336218001+jcl-bit@users.noreply.github.com> Date: Tue, 20 Oct 2026 04:09:07 +0200 Subject: [PATCH 18/20] E2+E3: egui-wgpu: fit oversized surfaces, and report surface/renderer setup errors E2 (storytold/pdfcraft#609, fixes pdfcraft#577): a window's surface is configured within the device's max_texture_dimension_2d, both sides shrunk by one factor that egui then draws at, so a window wider or taller than the GPU limit (a restored HiDPI window, a window across three monitors) no longer panics in Surface::configure. Same failure as storytold/gridcraft#760. E3 (storytold/pdfcraft#617, fixes pdfcraft#519; follow-up #1042): a new window's first surface configure, and renderer creation, run inside wgpu error scopes and are returned as WgpuError::ConfigureSurface / CreateRenderer, so the app can fall back to another renderer instead of aborting. Later reconfigures, a device lost during the first configure, and a zero-size first window are unchanged. Taken from storytold/pdfcraft vendor/egui-wgpu; no upstream egui PR yet. Co-authored-by: aAffliu <164289069+huferyliu@users.noreply.github.com> --- crates/egui-wgpu/src/lib.rs | 17 ++++ crates/egui-wgpu/src/winit.rs | 146 +++++++++++++++++++++++++++++++--- 2 files changed, 151 insertions(+), 12 deletions(-) diff --git a/crates/egui-wgpu/src/lib.rs b/crates/egui-wgpu/src/lib.rs index 1eb975ae..80b09a04 100644 --- a/crates/egui-wgpu/src/lib.rs +++ b/crates/egui-wgpu/src/lib.rs @@ -62,6 +62,17 @@ pub enum WgpuError { #[cfg(feature = "winit")] #[error(transparent)] HandleError(#[from] ::winit::raw_window_handle::HandleError), + + /// PdfCraft patch (#519): the device raised an error while a new window's surface was + /// configured (see [`winit::catch_errors`]). + #[cfg(feature = "winit")] + #[error("The window's surface couldn't be configured: {0}")] + ConfigureSurface(wgpu::Error), + + /// The device rejected renderer resources before the app was created. + #[cfg(feature = "winit")] + #[error("The egui renderer couldn't be created: {0}")] + CreateRenderer(wgpu::Error), } /// Runtime-mutable subset of [`WgpuConfiguration`]. @@ -277,6 +288,12 @@ impl RenderState { }; let target_format = crate::preferred_framebuffer_format(&surface_formats)?; + // Return startup pipeline errors so eframe's caller can retry with another renderer. + #[cfg(feature = "winit")] + let renderer = winit::catch_errors(&device, || Renderer::new(&device, target_format, options)) + .await + .map_err(WgpuError::CreateRenderer)?; + #[cfg(not(feature = "winit"))] let renderer = Renderer::new(&device, target_format, options); // On wasm, depending on feature flags, wgpu objects may or may not implement sync. diff --git a/crates/egui-wgpu/src/winit.rs b/crates/egui-wgpu/src/winit.rs index 84b32927..62db8b0f 100644 --- a/crates/egui-wgpu/src/winit.rs +++ b/crates/egui-wgpu/src/winit.rs @@ -17,11 +17,87 @@ struct SurfaceState { alpha_mode: wgpu::CompositeAlphaMode, width: u32, height: u32, + // PdfCraft patch (#577): `width` and `height` are the size the surface is configured at, + // which `surface_fit` keeps within the device's `max_texture_dimension_2d`; these are the + // window's own size, and `render_scale` is how much smaller the surface is drawn. + window_width: u32, + window_height: u32, + render_scale: f32, resizing: bool, needs_reconfigure: bool, needs_recreate: bool, } +/// PdfCraft patch (#577): the size to configure a window's surface at, and the factor egui +/// draws it at, so that neither side exceeds `max_side` (the device's +/// `max_texture_dimension_2d`). +/// +/// `Surface::configure` rejects a larger surface, and wgpu reports that as an uncaptured +/// validation error, which panics: a window bigger than the GPU's limit (restored at another +/// monitor's scale, stretched across monitors, …) closed the app before it opened. Both sides +/// shrink by the same factor and egui draws at that factor, so the whole window is drawn into +/// the surface. Where the swapchain is stretched over the window (DX12 uses +/// `DXGI_SCALING_STRETCH`) it fills the window and lines up with the pointer, only softer; +/// wgpu's GL backend copies it unscaled into a corner instead. Degraded either way, but not a +/// crash. A window within the limit is returned unchanged, with a factor of 1. The longer side +/// becomes exactly `max_side`, and a side that isn't zero never becomes zero (an empty surface +/// can't be configured either). +pub fn surface_fit(width: u32, height: u32, max_side: u32) -> (u32, u32, f32) { + let max_side = max_side.max(1); + if width <= max_side && height <= max_side { + return (width, height, 1.0); + } + let longest = width.max(height); + let scale = (f64::from(max_side) / f64::from(longest)).min(1.0); + // `as` saturates and `scale` is finite and in (0, 1]: no overflow, NaN or panic. The longer + // side is set rather than computed, so floating-point rounding can't leave it a pixel short. + let fit = |side: u32| { + if side == 0 { + 0 + } else if side == longest { + max_side + } else { + ((f64::from(side) * scale).floor() as u32).clamp(1, max_side) + } + }; + (fit(width), fit(height), scale as f32) +} + +/// PdfCraft patch (#519): runs `f` and returns an error it raises on `device`, instead of +/// handing it to wgpu's uncaptured-error handler, which panics by default. +/// +/// eframe configures a window's surface before the app is created, so no app code can install +/// a handler in time, and a surface the device can't configure closed the app before its window +/// appeared: wgpu's GL backend on a 2015 Intel driver timed out waiting for the GPU to go idle +/// (`ConfigureSurfaceError::GpuWaitTimeout`). Returned as an error instead, eframe returns +/// `Error::Wgpu` and the app can fall back (PdfCraft retries with OpenGL). +/// +/// Validation, out-of-memory and internal errors are caught, one scope each; each scope keeps +/// the first error of its kind, and a validation error is returned before an out-of-memory one, +/// which is returned before an internal one. Not caught: a lost device (wgpu reports that only +/// to the device-lost callback, so `f` seems to succeed), a panic inside `f`, and errors raised +/// on other threads (wgpu's error scopes belong to the calling thread). +pub async fn catch_errors( + device: &wgpu::Device, + f: impl FnOnce() -> T, +) -> Result { + let validation = device.push_error_scope(wgpu::ErrorFilter::Validation); + let out_of_memory = device.push_error_scope(wgpu::ErrorFilter::OutOfMemory); + let internal = device.push_error_scope(wgpu::ErrorFilter::Internal); + // Should `f` panic, the guards pop their scopes as they drop, innermost first. + let value = f(); + // Popped innermost first, as wgpu requires; each pop takes effect at once. + let internal = internal.pop(); + let out_of_memory = out_of_memory.pop(); + let validation = validation.pop(); + let (validation, out_of_memory, internal) = + (validation.await, out_of_memory.await, internal.await); + match validation.or(out_of_memory).or(internal) { + Some(error) => Err(error), + None => Ok(value), + } +} + /// Everything you need to paint egui with [`wgpu`] on [`winit`]. /// /// Alternatively you can use [`crate::Renderer`] directly. @@ -155,11 +231,12 @@ impl Painter { }; let surface = self.instance.create_surface(Arc::clone(window))?; + // PdfCraft patch (#577): the window's size; `width` and `height` may have been fitted. self.install_surface( surface, viewport_id, - old_state.width, - old_state.height, + old_state.window_width, + old_state.window_height, old_state.resizing, ); Ok(()) @@ -241,13 +318,31 @@ impl Painter { viewport_id: ViewportId, size: winit::dpi::PhysicalSize, ) -> Result<(), crate::WgpuError> { - if self.render_state.is_none() { - let render_state = + // PdfCraft patch (#519): the device is kept for `catch_errors` below. + let render_state = match self.render_state.take() { + Some(render_state) => render_state, + None => { RenderState::create(&self.config, &self.instance, Some(&surface), self.options) - .await?; - self.render_state = Some(render_state); + .await? + } + }; + let device = render_state.device.clone(); + self.render_state = Some(render_state); + // PdfCraft patch (#519): a surface the device can't configure is returned as an error + // instead of wgpu's default handler panicking; for the root window at start-up, eframe + // returns it as `Error::Wgpu` before the app is created, and the app can fall back. + // Nothing is kept for the window. A window whose size is zero here is first configured + // later, on resize, outside this. + let installed = catch_errors(&device, || { + self.install_surface(surface, viewport_id, size.width, size.height, false); + }) + .await; + if let Err(error) = installed { + self.surfaces.remove(&viewport_id); + self.depth_texture_view.remove(&viewport_id); + self.msaa_texture_view.remove(&viewport_id); + return Err(crate::WgpuError::ConfigureSurface(error)); } - self.install_surface(surface, viewport_id, size.width, size.height, false); Ok(()) } @@ -288,12 +383,18 @@ impl Painter { wgpu::CompositeAlphaMode::Auto } }; + // PdfCraft patch (#577): store the fitted size, so nothing configures the window's own. + // `render_scale` starts at 1 so that the resize below, which sets it, logs the fit once. + let (fit_width, fit_height, _) = surface_fit(width, height, self.max_surface_side()); self.surfaces.insert( viewport_id, SurfaceState { surface, - width, - height, + width: fit_width, + height: fit_height, + window_width: width, + window_height: height, + render_scale: 1.0, alpha_mode, resizing, needs_reconfigure: false, @@ -322,6 +423,14 @@ impl Painter { .map(|rs| rs.device.limits().max_texture_dimension_2d as usize) } + /// PdfCraft patch (#577): the largest side a surface may be configured at, or no limit + /// before the device exists (nothing is configured then). + fn max_surface_side(&self) -> u32 { + self.render_state + .as_ref() + .map_or(u32::MAX, |rs| rs.device.limits().max_texture_dimension_2d) + } + fn resize_and_generate_depth_texture_view_and_msaa_view( &mut self, viewport_id: ViewportId, @@ -330,14 +439,26 @@ impl Painter { ) { profiling::function_scope!(); - let width = width_in_pixels.get(); - let height = height_in_pixels.get(); + // PdfCraft patch (#577): configure the surface, and size the depth and MSAA textures, + // within the device's limit; `surface_fit` keeps a non-zero side non-zero. + let max_side = self.max_surface_side(); + let (window_width, window_height) = (width_in_pixels.get(), height_in_pixels.get()); + let (width, height, render_scale) = surface_fit(window_width, window_height, max_side); let render_state = self.render_state.as_ref().unwrap(); let surface_state = self.surfaces.get_mut(&viewport_id).unwrap(); + if render_scale < 1.0 && surface_state.render_scale >= 1.0 { + log::warn!( + "the window is {window_width} × {window_height} pixels, more than this GPU draws \ + ({max_side} a side): drawing it at {width} × {height} and scaling it up" + ); + } surface_state.width = width; surface_state.height = height; + surface_state.window_width = window_width; + surface_state.window_height = window_height; + surface_state.render_scale = render_scale; Self::configure_surface(surface_state, render_state, &self.config.surface); @@ -558,9 +679,10 @@ impl Painter { }); // Upload all resources for the GPU. + // PdfCraft patch (#577): a surface fitted within the GPU's limit is drawn smaller. let screen_descriptor = renderer::ScreenDescriptor { size_in_pixels: [surface_state.width, surface_state.height], - pixels_per_point, + pixels_per_point: pixels_per_point * surface_state.render_scale, }; let user_cmd_bufs = { From c01acc2acd2514f8830ba779dbbfc901b9931ff5 Mon Sep 17 00:00:00 2001 From: Carmine Paolino Date: Tue, 20 Oct 2026 04:09:35 +0200 Subject: [PATCH 19/20] E4: egui-winit: use winit's Wayland clipboard instead of smithay-clipboard when available Port of emilk/egui#8657 (draft) to 0.36.2, the companion of W15 (rust-windowing/winit#4729): winit now binds a wl_data_device per seat for file drops, and a second device from smithay-clipboard loses the selection on compositors that serve only the first device per client (Hyprland). With winit's clipboard available, smithay-clipboard is not started. Only the clipboard.rs change is taken; the PR's temporary [patch] of egui's own winit is not. --- crates/egui-winit/src/clipboard.rs | 124 +++++++++++++++++++++++++++++ 1 file changed, 124 insertions(+) diff --git a/crates/egui-winit/src/clipboard.rs b/crates/egui-winit/src/clipboard.rs index 2410c3ee..a974ec1a 100644 --- a/crates/egui-winit/src/clipboard.rs +++ b/crates/egui-winit/src/clipboard.rs @@ -23,6 +23,21 @@ pub struct Clipboard { ))] smithay: Option, + /// The clipboard of winit's Wayland event loop, which uses winit's own data device. + /// When it is set, smithay-clipboard is not started. + #[cfg(all( + any( + target_os = "linux", + target_os = "dragonfly", + target_os = "freebsd", + target_os = "netbsd", + target_os = "openbsd" + ), + feature = "wayland", + feature = "clipboard", + ))] + winit_wayland: Option, + /// Fallback manual clipboard. clipboard: String, } @@ -30,6 +45,33 @@ pub struct Clipboard { impl Clipboard { /// Construct a new instance pub fn new(_raw_display_handle: Option) -> Self { + #[cfg(all( + any( + target_os = "linux", + target_os = "dragonfly", + target_os = "freebsd", + target_os = "netbsd", + target_os = "openbsd" + ), + feature = "wayland", + feature = "clipboard", + ))] + if let Some(winit_wayland) = init_winit_wayland_clipboard(_raw_display_handle) { + // Binding a second data device for smithay-clipboard would take the selection away + // from winit's on compositors that serve only one device per client (Hyprland). + return Self { + #[cfg(all( + not(any(target_os = "android", target_os = "ios")), + feature = "arboard", + ))] + arboard: init_arboard(), + #[cfg(feature = "smithay-clipboard")] + smithay: None, + winit_wayland: Some(winit_wayland), + clipboard: Default::default(), + }; + } + Self { #[cfg(all( not(any(target_os = "android", target_os = "ios")), @@ -49,11 +91,51 @@ impl Clipboard { ))] smithay: init_smithay_clipboard(_raw_display_handle), + #[cfg(all( + any( + target_os = "linux", + target_os = "dragonfly", + target_os = "freebsd", + target_os = "netbsd", + target_os = "openbsd" + ), + feature = "wayland", + feature = "clipboard", + ))] + winit_wayland: None, + clipboard: Default::default(), } } pub fn get(&mut self) -> Option { + #[cfg(all( + any( + target_os = "linux", + target_os = "dragonfly", + target_os = "freebsd", + target_os = "netbsd", + target_os = "openbsd" + ), + feature = "wayland", + feature = "clipboard", + ))] + if let Some(clipboard) = &self.winit_wayland { + match clipboard.load_text() { + Ok(text) => return Some(text), + // The clipboard is empty, or holds no text (perhaps an image for arboard). + Err(err) + if matches!( + err.kind(), + std::io::ErrorKind::NotFound | std::io::ErrorKind::InvalidData + ) => {} + Err(err) => { + // Not fatal: we fall back to arboard below. + log::debug!("winit Wayland paste error: {err}"); + } + } + } + #[cfg(all( any( target_os = "linux", @@ -91,6 +173,24 @@ impl Clipboard { } pub fn set_text(&mut self, text: String) { + #[cfg(all( + any( + target_os = "linux", + target_os = "dragonfly", + target_os = "freebsd", + target_os = "netbsd", + target_os = "openbsd" + ), + feature = "wayland", + feature = "clipboard", + ))] + if let Some(clipboard) = &self.winit_wayland { + if let Err(err) = clipboard.store_text(text) { + log::error!("Wayland copy/cut error: {err}"); + } + return; + } + #[cfg(all( any( target_os = "linux", @@ -144,6 +244,30 @@ impl Clipboard { } } +#[cfg(all( + any( + target_os = "linux", + target_os = "dragonfly", + target_os = "freebsd", + target_os = "netbsd", + target_os = "openbsd" + ), + feature = "wayland", + feature = "clipboard", +))] +fn init_winit_wayland_clipboard( + raw_display_handle: Option, +) -> Option { + let Some(RawDisplayHandle::Wayland(display)) = raw_display_handle else { + return None; + }; + let clipboard = winit::platform::wayland::Clipboard::for_display(display.display); + if clipboard.is_some() { + log::trace!("Using the clipboard of winit's Wayland event loop"); + } + clipboard +} + #[cfg(all( not(any(target_os = "android", target_os = "ios")), feature = "arboard", From 767b1cad294120689a514bb4bd68c077e46679b9 Mon Sep 17 00:00:00 2001 From: skylartaylor <26588250+skylartaylor@users.noreply.github.com> Date: Wed, 21 Oct 2026 18:16:56 +0200 Subject: [PATCH 20/20] PATCHES.md: the suite's patch list --- PATCHES.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 PATCHES.md diff --git a/PATCHES.md b/PATCHES.md new file mode 100644 index 00000000..9e1f31f6 --- /dev/null +++ b/PATCHES.md @@ -0,0 +1,14 @@ +# Craft suite patches on egui 0.36.2 (`craft/0.36.2`) + +Base: upstream tag `0.36.2` (`49682f8b`); eframe, egui-wgpu and egui-winit sources match crates.io +0.36.2 exactly. Apps patch every egui-workspace crate they use to this checkout, so only one egui +resolves. One commit per patch; drop it when an egui release in use contains it. + +| # | Commit | Crate | Change | Upstream | Source in the suite | +|---|---|---|---|---|---| +| E1 | `e7e37ad` | eframe | `NativeOptions::viewport_hooks` (`ViewportHooks`): each viewport's native window on create/remove, and every viewport's raw input before egui (immediate viewports included) | not proposed upstream yet | needed by craft-tablet (native Wayland pen input) | +| E2+E3 | `b02321d` | egui-wgpu | fit a surface within `max_texture_dimension_2d`; first configure and renderer creation inside wgpu error scopes, returned as `WgpuError::ConfigureSurface` / `CreateRenderer` | not proposed | pdfcraft#609 (#577), #617 (#519), #1042; gridcraft#761 | +| E4 | `c01acc2` | egui-winit | use winit's Wayland clipboard when available instead of starting smithay-clipboard (Hyprland serves only one data device per client) | emilk/egui#8657 (draft), ported to 0.36.2 | companion of winit W15 | + +E4 was ported by hand: on 0.36.2 `Clipboard::new` is a safe fn with a different body, so the early +return was placed before the struct literal; `get`/`set_text` changes applied as in the PR.