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