use open instead of egui OpenUrl for mailto link
Signed-off-by: kernelkind <kernelkind@gmail.com>
This commit is contained in:
@@ -1,49 +0,0 @@
|
||||
use egui::{Button, Response, Ui, Widget};
|
||||
|
||||
pub struct ButtonHyperlink<'a> {
|
||||
url: String,
|
||||
button: Button<'a>,
|
||||
new_tab: bool,
|
||||
}
|
||||
|
||||
impl<'a> ButtonHyperlink<'a> {
|
||||
pub fn new(button: Button<'a>, url: impl ToString) -> Self {
|
||||
let url = url.to_string();
|
||||
Self {
|
||||
url: url.clone(),
|
||||
button,
|
||||
new_tab: false,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn open_in_new_tab(mut self, new_tab: bool) -> Self {
|
||||
self.new_tab = new_tab;
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Widget for ButtonHyperlink<'a> {
|
||||
fn ui(self, ui: &mut Ui) -> Response {
|
||||
let response = ui.add(self.button);
|
||||
|
||||
if response.clicked() {
|
||||
let modifiers = ui.ctx().input(|i| i.modifiers);
|
||||
ui.ctx().open_url(egui::OpenUrl {
|
||||
url: self.url.clone(),
|
||||
new_tab: self.new_tab || modifiers.any(),
|
||||
});
|
||||
}
|
||||
if response.middle_clicked() {
|
||||
ui.ctx().open_url(egui::OpenUrl {
|
||||
url: self.url.clone(),
|
||||
new_tab: true,
|
||||
});
|
||||
}
|
||||
|
||||
if ui.style().url_in_tooltip {
|
||||
response.on_hover_text(self.url)
|
||||
} else {
|
||||
response
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,6 @@ pub mod account_login_view;
|
||||
pub mod account_management;
|
||||
pub mod add_column;
|
||||
pub mod anim;
|
||||
pub mod button_hyperlink;
|
||||
pub mod mention;
|
||||
pub mod note;
|
||||
pub mod preview;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
use egui::{vec2, Button, Label, Layout, RichText};
|
||||
use tracing::error;
|
||||
|
||||
use crate::{
|
||||
app_style::{get_font_size, NotedeckTextStyle},
|
||||
@@ -7,7 +8,7 @@ use crate::{
|
||||
support::Support,
|
||||
};
|
||||
|
||||
use super::{button_hyperlink::ButtonHyperlink, padding};
|
||||
use super::padding;
|
||||
|
||||
pub struct SupportView<'a> {
|
||||
support: &'a mut Support,
|
||||
@@ -31,15 +32,18 @@ impl<'a> SupportView<'a> {
|
||||
ui.label("Open your default email client to get help from the Damus team");
|
||||
let size = vec2(120.0, 40.0);
|
||||
ui.allocate_ui_with_layout(size, Layout::top_down(egui::Align::Center), |ui| {
|
||||
ui.add(ButtonHyperlink::new(
|
||||
Button::new(
|
||||
RichText::new("Open Email")
|
||||
.size(get_font_size(ui.ctx(), &NotedeckTextStyle::Body)),
|
||||
)
|
||||
.fill(PINK)
|
||||
.min_size(size),
|
||||
self.support.get_mailto_url(),
|
||||
));
|
||||
let font_size = get_font_size(ui.ctx(), &NotedeckTextStyle::Body);
|
||||
let button_resp = ui.add(open_email_button(font_size, size));
|
||||
if button_resp.clicked() {
|
||||
if let Err(e) = open::that(self.support.get_mailto_url()) {
|
||||
error!(
|
||||
"Failed to open URL {} because: {}",
|
||||
self.support.get_mailto_url(),
|
||||
e
|
||||
);
|
||||
};
|
||||
};
|
||||
button_resp.on_hover_text_at_pointer(self.support.get_mailto_url());
|
||||
})
|
||||
});
|
||||
|
||||
@@ -74,3 +78,9 @@ impl<'a> SupportView<'a> {
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
fn open_email_button(font_size: f32, size: egui::Vec2) -> impl egui::Widget {
|
||||
Button::new(RichText::new("Open Email").size(font_size))
|
||||
.fill(PINK)
|
||||
.min_size(size)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user