use redgold_gui::state::local_state::LocalState;
use eframe::egui;
use eframe::egui::{ComboBox, Context, RichText};
use redgold_common::external_resources::ExternalNetworkResources;
use redgold_gui::common::copy_button;
use redgold_schema::structs::NetworkEnvironment;
use redgold_schema::util::times::ToTimeString;
fn round_down_to_minute(time_millis: i64) -> i64 {
time_millis - (time_millis % 60000)
}
pub struct RenderTopEvent {
pub(crate) refresh_all_clicked: bool
}
impl Default for RenderTopEvent {
fn default() -> Self {
Self {
refresh_all_clicked: false
}
}
}
pub fn render_top<E>
(ctx: &Context, local_state: &mut LocalState<E>) -> RenderTopEvent
where E: ExternalNetworkResources + 'static + Sync + Send + Clone {
let mut event = RenderTopEvent::default();
egui::TopBottomPanel::top("top_panel").show(ctx, |ui| {
ui.horizontal(|ui| {
let cur = ctx.pixels_per_point();
let string = format!("Pixels per point: {}", cur);
if ui.small_button("+Text")
.on_hover_text(string.clone()).clicked() {
ctx.set_pixels_per_point(cur + 0.25);
}
if ui.small_button("-Text")
.on_hover_text(string).clicked() {
ctx.set_pixels_per_point(cur - 0.25);
}
ui.label("Network: ");
ComboBox::from_label("")
.width(80.0)
.selected_text(local_state.node_config.network.to_std_string())
.show_ui(ui, |ui| {
for style in NetworkEnvironment::gui_networks() {
ui.selectable_value(&mut local_state.node_config.network, style.clone(), style.to_std_string());
}
});
ui.label("Network Health:");
match local_state.home_state.network_healthy {
true => {
ui.label(RichText::new("Healthy").color(egui::Color32::GREEN));
}
false => {
ui.label(RichText::new("Unhealthy").color(egui::Color32::RED));
}
}
ui.label("Date:");
let time_str = local_state.current_time.to_time_string_shorter_no_seconds_am_pm();
ui.label(RichText::new(time_str.clone()).color(egui::Color32::LIGHT_BLUE));
copy_button(ui, local_state.current_time.to_time_string_shorter());
ui.hyperlink_to("Explorer Link", local_state.node_config.network.explorer_link());
if ui.button("Refresh All").clicked() {
event.refresh_all_clicked = true;
}
});
});
event
}