diff --git a/crates/egui/src/widgets/button.rs b/crates/egui/src/widgets/button.rs index af31b40af..ccb1db69f 100644 --- a/crates/egui/src/widgets/button.rs +++ b/crates/egui/src/widgets/button.rs @@ -223,22 +223,29 @@ impl<'a> Button<'a> { /// /// See also [`Self::right_text`]. #[inline] - pub fn shortcut_text(mut self, shortcut_text: impl Into>) -> Self { - let mut atom = shortcut_text.into(); - atom.kind = match atom.kind { - AtomKind::Text(text) => AtomKind::Text(text.weak()), - other => other, - }; + pub fn shortcut_text(mut self, shortcut_text: impl IntoAtoms<'a>) -> Self { self.layout.push_right(Atom::grow()); - self.layout.push_right(atom); + + for mut atom in shortcut_text.into_atoms() { + atom.kind = match atom.kind { + AtomKind::Text(text) => AtomKind::Text(text.weak()), + other => other, + }; + self.layout.push_right(atom); + } + self } /// Show some text on the right side of the button. #[inline] - pub fn right_text(mut self, right_text: impl Into>) -> Self { + pub fn right_text(mut self, right_text: impl IntoAtoms<'a>) -> Self { self.layout.push_right(Atom::grow()); - self.layout.push_right(right_text.into()); + + for atom in right_text.into_atoms() { + self.layout.push_right(atom); + } + self } diff --git a/tests/egui_tests/tests/snapshots/button_shortcut.png b/tests/egui_tests/tests/snapshots/button_shortcut.png new file mode 100644 index 000000000..7f39196b8 --- /dev/null +++ b/tests/egui_tests/tests/snapshots/button_shortcut.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5befd84158b582c79a968f36e43c7017187b364824eb4470b048d133e62f9360 +size 1600 diff --git a/tests/egui_tests/tests/test_atoms.rs b/tests/egui_tests/tests/test_atoms.rs index cf2abbe1a..6f4b694e6 100644 --- a/tests/egui_tests/tests/test_atoms.rs +++ b/tests/egui_tests/tests/test_atoms.rs @@ -108,3 +108,14 @@ fn test_intrinsic_size() { } } } + +#[test] +fn test_button_shortcut_text() { + let mut harness = HarnessBuilder::default().build_ui(|ui| { + ui.add(egui::Button::new("Click me").shortcut_text(("1", "2", "3"))); + }); + harness.run(); + harness.fit_contents(); + + harness.snapshot("button_shortcut"); +}