support view

Signed-off-by: kernelkind <kernelkind@gmail.com>
This commit is contained in:
kernelkind
2024-10-21 17:56:54 -04:00
parent 03bfb34172
commit 309477dca4
12 changed files with 356 additions and 3 deletions

View File

@@ -0,0 +1,49 @@
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
}
}
}

View File

@@ -2,12 +2,14 @@ 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;
pub mod profile;
pub mod relay;
pub mod side_panel;
pub mod support;
pub mod thread;
pub mod timeline;
pub mod username;

View File

@@ -7,6 +7,7 @@ use crate::{
column::{Column, Columns},
imgcache::ImageCache,
route::Route,
support::Support,
user_account::UserAccount,
Damus,
};
@@ -41,6 +42,7 @@ pub enum SidePanelAction {
ComposeNote,
Search,
ExpandSidePanel,
Support,
}
pub struct SidePanelResponse {
@@ -114,6 +116,8 @@ impl<'a> DesktopSidePanel<'a> {
let pfp_resp = self.pfp_button(ui);
let settings_resp = ui.add(settings_button(dark_mode));
let support_resp = ui.add(support_button());
let optional_inner = if pfp_resp.clicked() {
Some(egui::InnerResponse::new(
SidePanelAction::Account,
@@ -124,6 +128,11 @@ impl<'a> DesktopSidePanel<'a> {
SidePanelAction::Settings,
settings_resp,
))
} else if support_resp.clicked() {
Some(egui::InnerResponse::new(
SidePanelAction::Support,
support_resp,
))
} else {
None
};
@@ -162,7 +171,7 @@ impl<'a> DesktopSidePanel<'a> {
helper.take_animation_response()
}
pub fn perform_action(columns: &mut Columns, action: SidePanelAction) {
pub fn perform_action(columns: &mut Columns, support: &mut Support, action: SidePanelAction) {
let router = columns.get_first_router();
match action {
SidePanelAction::Panel => {} // TODO
@@ -208,6 +217,14 @@ impl<'a> DesktopSidePanel<'a> {
// TODO
info!("Clicked expand side panel button");
}
SidePanelAction::Support => {
if router.routes().iter().any(|&r| r == Route::Support) {
router.go_back();
} else {
support.refresh();
router.route_to(Route::Support);
}
}
}
}
}
@@ -352,6 +369,28 @@ fn expand_side_panel_button() -> impl Widget {
}
}
fn support_button() -> impl Widget {
|ui: &mut egui::Ui| -> egui::Response {
let img_size = 16.0;
let max_size = ICON_WIDTH * ICON_EXPANSION_MULTIPLE; // max size of the widget
let img_data = egui::include_image!("../../assets/icons/help_icon_dark_4x.png");
let img = egui::Image::new(img_data).max_width(img_size);
let helper = AnimationHelper::new(ui, "help-button", vec2(max_size, max_size));
let cur_img_size = helper.scale_1d_pos(img_size);
img.paint_at(
ui,
helper
.get_animation_rect()
.shrink((max_size - cur_img_size) / 2.0),
);
helper.take_animation_response()
}
}
mod preview {
use egui_extras::{Size, StripBuilder};
@@ -390,7 +429,11 @@ mod preview {
);
let response = panel.show(ui);
DesktopSidePanel::perform_action(&mut self.app.columns, response.action);
DesktopSidePanel::perform_action(
&mut self.app.columns,
&mut self.app.support,
response.action,
);
});
});
}

76
src/ui/support.rs Normal file
View File

@@ -0,0 +1,76 @@
use egui::{vec2, Button, Label, Layout, RichText};
use crate::{
app_style::{get_font_size, NotedeckTextStyle},
colors::PINK,
fonts::NamedFontFamily,
support::Support,
};
use super::{button_hyperlink::ButtonHyperlink, padding};
pub struct SupportView<'a> {
support: &'a mut Support,
}
impl<'a> SupportView<'a> {
pub fn new(support: &'a mut Support) -> Self {
Self { support }
}
pub fn show(&mut self, ui: &mut egui::Ui) {
padding(8.0, ui, |ui| {
ui.spacing_mut().item_spacing = egui::vec2(0.0, 8.0);
let font = egui::FontId::new(
get_font_size(ui.ctx(), &NotedeckTextStyle::Body),
egui::FontFamily::Name(NamedFontFamily::Bold.as_str().into()),
);
ui.add(Label::new(RichText::new("Running into a bug?").font(font)));
ui.label(RichText::new("Step 1").text_style(NotedeckTextStyle::Heading3.text_style()));
padding(8.0, ui, |ui| {
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(),
));
})
});
ui.add_space(8.0);
if let Some(logs) = self.support.get_most_recent_log() {
ui.label(
RichText::new("Step 2").text_style(NotedeckTextStyle::Heading3.text_style()),
);
let size = vec2(80.0, 40.0);
let copy_button = Button::new(
RichText::new("Copy").size(get_font_size(ui.ctx(), &NotedeckTextStyle::Body)),
)
.fill(PINK)
.min_size(size);
padding(8.0, ui, |ui| {
ui.add(Label::new("Press the button below to copy your most recent logs to your system's clipboard. Then paste it into your email.").wrap());
ui.allocate_ui_with_layout(size, Layout::top_down(egui::Align::Center), |ui| {
if ui.add(copy_button).clicked() {
ui.output_mut(|w| {
w.copied_text = logs.to_string();
});
}
});
});
} else {
ui.label(
egui::RichText::new("ERROR: Could not find logs on system")
.color(egui::Color32::RED),
);
}
});
}
}