Skip to content

Commit

Permalink
Make a default target for open_url configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
mvlabat committed May 1, 2022
1 parent a3d113a commit ae5eb4a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
10 changes: 9 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,19 @@ pub struct EguiSettings {
/// }
/// ```
pub scale_factor: f64,
/// Will be used as a default value for hyperlink [target](https://www.w3schools.com/tags/att_a_target.asp) hints.
/// If not specified, `_self` will be used. Only matters in a web browser.
#[cfg(feature = "open_url")]
pub default_open_url_target: Option<String>,
}

impl Default for EguiSettings {
fn default() -> Self {
Self { scale_factor: 1.0 }
Self {
scale_factor: 1.0,
#[cfg(feature = "open_url")]
default_open_url_target: None,
}
}
}

Expand Down
12 changes: 11 additions & 1 deletion src/systems.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,9 @@ pub fn begin_frame(
}

pub fn process_output(
#[cfg_attr(not(feature = "open_url"), allow(unused_variables))] egui_settings: Res<
EguiSettings,
>,
mut egui_context: ResMut<EguiContext>,
mut egui_output: ResMut<HashMap<WindowId, EguiOutput>>,
mut egui_render_output: ResMut<HashMap<WindowId, EguiRenderOutput>>,
Expand Down Expand Up @@ -369,7 +372,14 @@ pub fn process_output(

#[cfg(feature = "open_url")]
if let Some(egui::output::OpenUrl { url, new_tab }) = platform_output.open_url {
let target = if new_tab { "_blank" } else { "_self" };
let target = if new_tab {
"_blank"
} else {
egui_settings
.default_open_url_target
.as_deref()
.unwrap_or("_self")
};
if let Err(err) = webbrowser::open_browser_with_options(
webbrowser::Browser::Default,
&url,
Expand Down

0 comments on commit ae5eb4a

Please sign in to comment.