1
0
mirror of https://github.com/emilk/egui.git synced 2026-06-27 07:03:14 -04:00

Add option to always open hyperlink in a new browser tab (#3242)

* add option to always open hyperlink in a new browser tab

* Fix logic error
This commit is contained in:
Frederic L
2023-08-12 14:05:49 +02:00
committed by GitHub
parent 1036cb1f7d
commit 1023f937a6

View File

@@ -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(),
});
});
}