paiagram/interface/
side_panel.rs1use egui::{RichText, Ui, vec2};
2use strum::IntoEnumIterator;
3use strum_macros::EnumIter;
4
5pub mod interval_stats;
6pub mod station_stats;
7pub mod vehicle_stats;
8
9#[derive(PartialEq, Eq, Clone, Copy, Default, EnumIter)]
10pub enum CurrentTab {
11 #[default]
12 Edit,
13 Details,
14}
15
16impl CurrentTab {
17 pub fn name(self) -> &'static str {
18 match self {
19 CurrentTab::Edit => "Edit",
20 CurrentTab::Details => "Details",
21 }
22 }
23}
24
25pub fn show_side_panel(ui: &mut Ui, selected_tab: &mut CurrentTab) {
26 const SEGMENT_SPACING: f32 = 5.0;
28 let segment_width = (ui.available_width() - SEGMENT_SPACING) / CurrentTab::iter().len() as f32;
29 let segment_size = vec2(segment_width, 30.0);
30 ui.horizontal(|ui| {
31 ui.spacing_mut().item_spacing.x = SEGMENT_SPACING;
32 for tab in CurrentTab::iter() {
33 let is_selected = *selected_tab == tab;
34 let resp = ui.add_sized(
35 segment_size,
36 egui::Button::selectable(is_selected, RichText::new(tab.name())),
37 );
38 if resp.clicked() {
39 *selected_tab = tab;
40 }
41 }
42 });
43}