diff --git a/crates/egui/src/widgets/hyperlink.rs b/crates/egui/src/widgets/hyperlink.rs index 361b21bb..0ef0ee48 100644 --- a/crates/egui/src/widgets/hyperlink.rs +++ b/crates/egui/src/widgets/hyperlink.rs @@ -83,6 +83,7 @@ impl Widget for Link { pub struct Hyperlink { url: String, text: WidgetText, + new_tab: bool, } impl Hyperlink { @@ -92,6 +93,7 @@ impl Hyperlink { Self { url: url.clone(), text: url.into(), + new_tab: false, } } @@ -100,13 +102,20 @@ impl Hyperlink { Self { url: url.to_string(), text: text.into(), + new_tab: false, } } + + /// Always open this hyperlink in a new browser tab. + pub fn open_in_new_tab(mut self, new_tab: bool) -> Self { + self.new_tab = new_tab; + self + } } impl Widget for Hyperlink { fn ui(self, ui: &mut Ui) -> Response { - let Self { url, text } = self; + let Self { url, text, new_tab } = self; let response = ui.add(Link::new(text)); if response.clicked() { @@ -114,7 +123,7 @@ impl Widget for Hyperlink { ui.ctx().output_mut(|o| { o.open_url = Some(crate::output::OpenUrl { url: url.clone(), - new_tab: modifiers.any(), + new_tab: new_tab || modifiers.any(), }); }); }