mirror of https://github.com/terhechte/postsack
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
102 lines
3.2 KiB
Rust
102 lines
3.2 KiB
Rust
3 years ago
|
use eframe::egui::{self, Color32, Label, Widget};
|
||
3 years ago
|
use eyre::Report;
|
||
3 years ago
|
use num_format::{Locale, ToFormattedString};
|
||
3 years ago
|
use ps_core::model::Engine;
|
||
3 years ago
|
|
||
3 years ago
|
use super::app_state::UIState;
|
||
3 years ago
|
use super::platform::navigation_button;
|
||
3 years ago
|
use super::widgets::{FilterPanel, FilterState};
|
||
3 years ago
|
|
||
3 years ago
|
pub struct NavigationBar<'a> {
|
||
3 years ago
|
engine: &'a mut Engine,
|
||
3 years ago
|
#[allow(unused)]
|
||
3 years ago
|
error: &'a mut Option<Report>,
|
||
3 years ago
|
state: &'a mut UIState,
|
||
3 years ago
|
filter_state: &'a mut FilterState,
|
||
3 years ago
|
total_mails: usize,
|
||
3 years ago
|
}
|
||
|
|
||
3 years ago
|
impl<'a> NavigationBar<'a> {
|
||
3 years ago
|
pub fn new(
|
||
|
engine: &'a mut Engine,
|
||
|
error: &'a mut Option<Report>,
|
||
|
state: &'a mut UIState,
|
||
3 years ago
|
filter_state: &'a mut FilterState,
|
||
3 years ago
|
total_mails: usize,
|
||
3 years ago
|
) -> Self {
|
||
3 years ago
|
NavigationBar {
|
||
3 years ago
|
engine,
|
||
|
error,
|
||
|
state,
|
||
3 years ago
|
filter_state,
|
||
3 years ago
|
total_mails,
|
||
3 years ago
|
}
|
||
3 years ago
|
}
|
||
|
}
|
||
|
|
||
3 years ago
|
impl<'a> Widget for NavigationBar<'a> {
|
||
3 years ago
|
fn ui(self, ui: &mut egui::Ui) -> egui::Response {
|
||
3 years ago
|
// Override the button spacing
|
||
|
ui.spacing_mut().button_padding = (6.0, 3.0).into();
|
||
|
|
||
3 years ago
|
ui.visuals_mut().widgets.inactive.corner_radius = 5.0;
|
||
|
ui.visuals_mut().widgets.active.corner_radius = 5.0;
|
||
|
ui.visuals_mut().widgets.hovered.corner_radius = 5.0;
|
||
3 years ago
|
|
||
3 years ago
|
ui.horizontal(|ui| {
|
||
|
ui.set_height(40.0);
|
||
|
|
||
|
ui.add_space(15.0);
|
||
|
|
||
|
let close_text = "Close";
|
||
|
if ui.add(navigation_button(close_text)).clicked() {
|
||
|
self.state.action_close = true;
|
||
|
}
|
||
|
|
||
|
let filter_text = "\u{1f50D} Filters";
|
||
|
let filter_response = ui.add(navigation_button(filter_text));
|
||
|
let popup_id = ui.make_persistent_id("filter_panel_id");
|
||
|
|
||
|
super::widgets::popover(ui, popup_id, &filter_response, |ui| {
|
||
|
ui.add(FilterPanel::new(self.engine, self.filter_state, self.error));
|
||
|
});
|
||
|
|
||
|
ui.add(Label::new(format!(
|
||
|
"{} Mails",
|
||
|
self.total_mails.to_formatted_string(&Locale::en)
|
||
|
)));
|
||
|
|
||
|
// This is a hack to get right-alignment.
|
||
|
// we can't size the button, we can only size text. We will size text
|
||
|
// and then use ~that for these buttons
|
||
|
let mut w = ui.available_width();
|
||
|
|
||
|
let mail_text = "\u{1F4E7} Mails";
|
||
|
let mail_galley = ui.painter().layout_no_wrap(
|
||
|
mail_text.to_owned(),
|
||
|
egui::TextStyle::Button,
|
||
|
Color32::WHITE,
|
||
|
);
|
||
|
|
||
|
// FIXME: Add support for exporting the selected mails as deletion rules
|
||
|
// let filter_text = "\u{1F5B9} Export";
|
||
|
// let filter_galley = ui.painter().layout_no_wrap(
|
||
|
// filter_text.to_owned(),
|
||
|
// egui::TextStyle::Button,
|
||
|
// Color32::WHITE,
|
||
|
// );
|
||
|
|
||
|
w -= mail_galley.size().x + ui.spacing().button_padding.x * 4.0;
|
||
|
//w -= filter_galley.size().x + ui.spacing().button_padding.x * 4.0;
|
||
|
ui.add_space(w);
|
||
|
|
||
|
//ui.add(navigation_button(filter_text));
|
||
|
|
||
|
if ui.add(navigation_button(mail_text)).clicked() {
|
||
|
self.state.show_emails = !self.state.show_emails;
|
||
|
}
|
||
|
})
|
||
|
.response
|
||
3 years ago
|
}
|
||
3 years ago
|
}
|