Ensure nested AtomLayouts have unique ids (#8556)

Buttons with nested atoms weren't fully clickable


https://github.com/user-attachments/assets/c9bc7075-9b32-4edc-9949-5eb047234e07
This commit is contained in:
Lucas Meurer authored and GitHub committed 2026-09-21 13:09:01 +00:00
1 parent 4146d6366a
commit b30d20bca7
3 files changed
+35 -2

No files matched your search

+9 -1
View File
@@ -188,7 +188,15 @@ impl<'a> ContainerAtom<'a> {
intrinsic_main += gap_space;
}
for (idx, item) in atoms.into_iter().enumerate() {
// A nested `WidgetAtom` with no explicit id falls back to `Ui::next_auto_id`, which does
// not advance, so several of them in the same container would all get the same id, and
// only the last would be interactable. Give each one an id of its own:
let auto_id = ui.next_auto_id();
for (idx, mut item) in atoms.into_iter().enumerate() {
if let AtomKind::Widget(widget) = &mut item.kind {
widget.id.get_or_insert_with(|| auto_id.with(idx));
}
if item.grow {
grow_count += 1;
}
+1 -1
View File
@@ -24,7 +24,7 @@ use smallvec::SmallVec;
/// [`AllocatedWidgetAtom`] for interaction styling.
#[derive(Clone)]
pub struct WidgetAtom<'a> {
id: Option<Id>,
pub(crate) id: Option<Id>,
pub(crate) sense: Sense,
selectable: bool,
pub container: ContainerAtom<'a>,
+25
View File
@@ -5,6 +5,31 @@ use egui::{
};
use egui_kittest::{HarnessBuilder, SnapshotResult, SnapshotResults};
/// Two nested [`WidgetAtom`]s without explicit ids must not share an id,
/// or the parent button is only clickable where the last of them is.
#[test]
fn test_button_with_nested_widget_atoms_is_clickable() {
use egui_kittest::kittest::Queryable as _;
let mut harness = HarnessBuilder::default().build_ui_state(
|ui, clicks| {
// The text lives in the nested atoms, so name the button itself:
if ui
.button((WidgetAtom::new("abcdef"), WidgetAtom::new("123")))
.accessible_name("abcdef 123")
.clicked()
{
*clicks += 1;
}
},
0,
);
harness.get_by_role(egui::accesskit::Role::Button).click();
harness.run();
assert_eq!(*harness.state(), 1);
}
#[test]
fn test_atoms() {
let mut results = SnapshotResults::new();