|
1 | | -use egui::{Align, Id, Image, Layout, Sense, ViewportCommand}; |
| 1 | +use egui::{Align, Id, Image, ImageButton, Layout, Sense, ViewportCommand}; |
2 | 2 |
|
3 | 3 | use crate::telemetry::TelemetryAnnotation; |
4 | 4 |
|
5 | | -use super::LiveTelemetryApp; |
| 5 | +use super::{config::AlertsLayout, LiveTelemetryApp}; |
6 | 6 |
|
7 | 7 | impl LiveTelemetryApp { |
8 | 8 | pub(crate) fn alerts_view(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) { |
9 | | - egui::CentralPanel::default().show(ctx, |ui| { |
10 | | - ui.with_layout(Layout::top_down(Align::TOP), |ui| { |
11 | | - // load warning based on telemetry data |
12 | | - let mut abs_image = egui::include_image!("../../assets/brake-green.png"); |
13 | | - let mut shift_image = egui::include_image!("../../assets/shift-orange.png"); |
14 | | - let mut wheelspin_image = egui::include_image!("../../assets/wheelspin-green.png"); |
15 | | - if let Some(back) = self.telemetry_points.back() { |
16 | | - if back.brake > 0.4 && !back.abs_active { |
17 | | - abs_image = egui::include_image!("../../assets/brake-orange.png"); |
18 | | - } |
19 | | - if back.abs_active { |
20 | | - abs_image = egui::include_image!("../../assets/brake-red.png"); |
21 | | - } |
22 | | - |
23 | | - if back.cur_rpm > back.car_shift_ideal_rpm - 100. |
24 | | - && back.cur_rpm < back.car_shift_ideal_rpm + 100. |
25 | | - { |
26 | | - shift_image = egui::include_image!("../../assets/shift-green.png"); |
27 | | - } |
28 | | - |
29 | | - if let Some(TelemetryAnnotation::Bool(true)) = back.annotations.get("wheelspin") |
30 | | - { |
31 | | - wheelspin_image = egui::include_image!("../../assets/wheelspin-red.png"); |
32 | | - } |
33 | | - } |
34 | | - |
35 | | - ui.label("ABS"); |
36 | | - ui.add(Image::new(abs_image)); |
37 | | - if ui |
38 | | - .interact(ui.max_rect(), Id::new("window-drag"), Sense::drag()) |
39 | | - .dragged() |
40 | | - { |
| 9 | + egui::TopBottomPanel::top("Controls") |
| 10 | + .min_height(30.) |
| 11 | + .show(ctx, |ui| { |
| 12 | + let drag_sense = ui.interact(ui.max_rect(), Id::new("window-drag"), Sense::drag()); |
| 13 | + if drag_sense.dragged() { |
41 | 14 | ui.ctx().send_viewport_cmd(ViewportCommand::StartDrag); |
42 | 15 | } |
43 | | - ui.separator(); |
44 | | - ui.label("Shift"); |
45 | | - ui.add(Image::new(shift_image)); |
46 | | - |
47 | | - ui.separator(); |
48 | | - ui.label("Traction"); |
49 | | - ui.add(Image::new(wheelspin_image)); |
50 | | - |
51 | | - if ui |
52 | | - .interact(ui.max_rect(), Id::new("window-drag"), Sense::drag()) |
53 | | - .dragged() |
54 | | - { |
55 | | - ui.ctx().send_viewport_cmd(ViewportCommand::StartDrag); |
| 16 | + if drag_sense.drag_stopped() { |
| 17 | + if let Some(outer_rect) = ui.input(|is| is.viewport().outer_rect) { |
| 18 | + self.app_config.alert_window_position = outer_rect.min.into(); |
| 19 | + }; |
| 20 | + } |
| 21 | + match self.app_config.alerts_layout { |
| 22 | + AlertsLayout::Vertical => { |
| 23 | + if ui |
| 24 | + .add(ImageButton::new(egui::include_image!( |
| 25 | + "../../assets/layout-horizontal-fill.png" |
| 26 | + ))) |
| 27 | + .clicked() |
| 28 | + { |
| 29 | + self.app_config.alerts_layout = AlertsLayout::Horizontal; |
| 30 | + } |
| 31 | + } |
| 32 | + AlertsLayout::Horizontal => { |
| 33 | + if ui |
| 34 | + .add(ImageButton::new(egui::include_image!( |
| 35 | + "../../assets/layout-vertical-fill.png" |
| 36 | + ))) |
| 37 | + .clicked() |
| 38 | + { |
| 39 | + self.app_config.alerts_layout = AlertsLayout::Vertical; |
| 40 | + } |
| 41 | + } |
56 | 42 | } |
57 | 43 | }); |
| 44 | + egui::CentralPanel::default().show(ctx, |ui| match self.app_config.alerts_layout { |
| 45 | + AlertsLayout::Vertical => { |
| 46 | + ui.with_layout(Layout::top_down(Align::TOP), |ui| { |
| 47 | + self.show_alerts(ui); |
| 48 | + }); |
| 49 | + } |
| 50 | + AlertsLayout::Horizontal => { |
| 51 | + ui.with_layout(Layout::left_to_right(Align::TOP), |ui| { |
| 52 | + self.show_alerts(ui); |
| 53 | + }); |
| 54 | + } |
58 | 55 | }); |
59 | 56 | } |
| 57 | + |
| 58 | + fn show_alerts(&mut self, ui: &mut egui::Ui) { |
| 59 | + // load warning based on telemetry data |
| 60 | + let mut abs_image = egui::include_image!("../../assets/brake-green.png"); |
| 61 | + let mut shift_image = egui::include_image!("../../assets/shift-orange.png"); |
| 62 | + let mut wheelspin_image = egui::include_image!("../../assets/wheelspin-green.png"); |
| 63 | + if let Some(back) = self.telemetry_points.back() { |
| 64 | + if back.brake > 0.4 && !back.abs_active { |
| 65 | + abs_image = egui::include_image!("../../assets/brake-orange.png"); |
| 66 | + } |
| 67 | + if back.abs_active { |
| 68 | + abs_image = egui::include_image!("../../assets/brake-red.png"); |
| 69 | + } |
| 70 | + |
| 71 | + if back.cur_rpm > back.car_shift_ideal_rpm - 100. |
| 72 | + && back.cur_rpm < back.car_shift_ideal_rpm + 100. |
| 73 | + { |
| 74 | + shift_image = egui::include_image!("../../assets/shift-green.png"); |
| 75 | + } |
| 76 | + |
| 77 | + if let Some(TelemetryAnnotation::Bool(true)) = back.annotations.get("wheelspin") { |
| 78 | + wheelspin_image = egui::include_image!("../../assets/wheelspin-red.png"); |
| 79 | + } |
| 80 | + } |
| 81 | + |
| 82 | + ui.label("ABS"); |
| 83 | + ui.add(Image::new(abs_image)); |
| 84 | + ui.separator(); |
| 85 | + ui.label("Shift"); |
| 86 | + ui.add(Image::new(shift_image)); |
| 87 | + |
| 88 | + ui.separator(); |
| 89 | + ui.label("Traction"); |
| 90 | + ui.add(Image::new(wheelspin_image)); |
| 91 | + } |
60 | 92 | } |
0 commit comments