Skip to content

Commit 7f09ff7

Browse files
committed
clean up
1 parent cae5cc2 commit 7f09ff7

File tree

4 files changed

+32
-48
lines changed

4 files changed

+32
-48
lines changed

src/color_picker.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use eframe::egui::{
2-
self, lerp, pos2, remap_clamp, vec2, Align2, Color32, Mesh, Pos2, Response, Sense, Shape,
3-
Stroke, Ui, Vec2,
2+
self, lerp, pos2, remap_clamp, vec2, Align2, Color32, Mesh, Response, Sense, Shape, Stroke, Ui,
3+
Vec2,
44
};
55

66
// Ten colors that are distinguishable and suitable for colorblind people
@@ -217,11 +217,3 @@ fn hsv_to_rgb(hue: f32, saturation: f32, value: f32) -> Color32 {
217217
((b + m) * 255.0) as u8,
218218
)
219219
}
220-
221-
// Function to interpolate between two colors
222-
fn lerp_color(c1: Color32, c2: Color32, t: f32) -> Color32 {
223-
let r = (c1.r() as f32 * (1.0 - t) + c2.r() as f32 * t).round() as u8;
224-
let g = (c1.g() as f32 * (1.0 - t) + c2.g() as f32 * t).round() as u8;
225-
let b = (c1.b() as f32 * (1.0 - t) + c2.b() as f32 * t).round() as u8;
226-
Color32::from_rgb(r, g, b)
227-
}

src/data.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
use crate::color_picker::COLORS;
2-
use eframe::egui::Color32;
31
use std::fmt;
42
use std::time::{SystemTime, UNIX_EPOCH};
53

src/gui.rs

Lines changed: 30 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ use std::sync::{Arc, RwLock};
77
use std::time::Duration;
88

99
use eframe::egui::panel::Side;
10-
use eframe::egui::{Align2, Color32, FontFamily, FontId, KeyboardShortcut, Pos2, Sense, Vec2, Visuals};
10+
use eframe::egui::{
11+
Align2, Color32, FontFamily, FontId, KeyboardShortcut, Pos2, Sense, Vec2, Visuals,
12+
};
1113
use eframe::{egui, Storage};
1214
use egui::ThemePreference;
1315
use egui_plot::{log_grid_spacer, GridMark, Legend, Line, Plot, PlotPoint, PlotPoints};
@@ -16,12 +18,12 @@ use preferences::Preferences;
1618
use serde::{Deserialize, Serialize};
1719
use serialport::{DataBits, FlowControl, Parity, StopBits};
1820

21+
use crate::color_picker::{color_picker_widget, color_picker_window, COLORS};
1922
use crate::data::{DataContainer, SerialDirection};
2023
use crate::serial::{clear_serial_settings, save_serial_settings, Device, SerialDevices};
2124
use crate::toggle::toggle;
2225
use crate::FileOptions;
2326
use crate::{APP_INFO, PREFS_KEY};
24-
use crate::color_picker::{color_picker_widget, color_picker_window, COLORS};
2527

2628
const MAX_FPS: f64 = 60.0;
2729

@@ -71,9 +73,9 @@ impl Print {
7173
Print::Empty => None,
7274
Print::Message(s) => {
7375
let color = if gui_conf.dark_mode {
74-
egui::Color32::WHITE
76+
Color32::WHITE
7577
} else {
76-
egui::Color32::BLACK
78+
Color32::BLACK
7779
};
7880
Some(ScrollAreaMessage {
7981
label: "[MSG] ".to_owned(),
@@ -82,7 +84,7 @@ impl Print {
8284
})
8385
}
8486
Print::Error(s) => {
85-
let color = egui::Color32::RED;
87+
let color = Color32::RED;
8688
Some(ScrollAreaMessage {
8789
label: "[ERR] ".to_owned(),
8890
content: s.to_owned(),
@@ -91,9 +93,9 @@ impl Print {
9193
}
9294
Print::Debug(s) => {
9395
let color = if gui_conf.dark_mode {
94-
egui::Color32::YELLOW
96+
Color32::YELLOW
9597
} else {
96-
egui::Color32::LIGHT_RED
98+
Color32::LIGHT_RED
9799
};
98100
Some(ScrollAreaMessage {
99101
label: "[DBG] ".to_owned(),
@@ -102,7 +104,7 @@ impl Print {
102104
})
103105
}
104106
Print::Ok(s) => {
105-
let color = egui::Color32::GREEN;
107+
let color = Color32::GREEN;
106108
Some(ScrollAreaMessage {
107109
label: "[OK] ".to_owned(),
108110
content: s.to_owned(),
@@ -117,7 +119,7 @@ impl Print {
117119
pub struct ScrollAreaMessage {
118120
label: String,
119121
content: String,
120-
color: egui::Color32,
122+
color: Color32,
121123
}
122124

123125
pub fn print_to_console(print_lock: &Arc<RwLock<Vec<Print>>>, message: Print) {
@@ -171,7 +173,7 @@ pub fn load_gui_settings() -> GuiSettingsContainer {
171173

172174
pub enum ColorWindow {
173175
NoShow,
174-
ColorIndex(usize)
176+
ColorIndex(usize),
175177
}
176178

177179
pub struct MyApp {
@@ -193,7 +195,6 @@ pub struct MyApp {
193195
devices_lock: Arc<RwLock<Vec<String>>>,
194196
connected_lock: Arc<RwLock<bool>>,
195197
data_lock: Arc<RwLock<DataContainer>>,
196-
names_tx: Sender<Vec<String>>,
197198
save_tx: Sender<FileOptions>,
198199
send_tx: Sender<String>,
199200
clear_tx: Sender<bool>,
@@ -221,7 +222,6 @@ impl MyApp {
221222
devices: SerialDevices,
222223
connected_lock: Arc<RwLock<bool>>,
223224
gui_conf: GuiSettingsContainer,
224-
names_tx: Sender<Vec<String>>,
225225
save_tx: Sender<FileOptions>,
226226
send_tx: Sender<String>,
227227
clear_tx: Sender<bool>,
@@ -243,7 +243,6 @@ impl MyApp {
243243
print_lock,
244244
gui_conf,
245245
data_lock,
246-
names_tx,
247246
save_tx,
248247
send_tx,
249248
clear_tx,
@@ -254,7 +253,7 @@ impl MyApp {
254253
show_timestamps: true,
255254
save_raw: false,
256255
eol: "\\r\\n".to_string(),
257-
colors: vec![COLORS[0]],
256+
colors: vec![COLORS[0]],
258257
color_vals: vec![0.0],
259258
labels: vec!["Column 0".to_string()],
260259
history: vec![],
@@ -343,9 +342,8 @@ impl MyApp {
343342
self.colors = (0..max(self.data.dataset.len(), 1))
344343
.map(|i| COLORS[i % COLORS.len()])
345344
.collect();
346-
self.color_vals = (0..max(self.data.dataset.len(), 1))
347-
.map(|i| 0.0)
348-
.collect();
345+
self.color_vals =
346+
(0..max(self.data.dataset.len(), 1)).map(|_| 0.0).collect();
349347
}
350348

351349
let mut graphs: Vec<Vec<PlotPoint>> = vec![vec![]; self.data.dataset.len()];
@@ -386,9 +384,9 @@ impl MyApp {
386384
// this check needs to be here for when we change devices (not very elegant)
387385
if i < self.labels.len() {
388386
signal_plot_ui.line(
389-
Line::new(PlotPoints::Owned(graph.to_vec())).name(
390-
&self.labels[i],
391-
).color(self.colors[i]),
387+
Line::new(PlotPoints::Owned(graph.to_vec()))
388+
.name(&self.labels[i])
389+
.color(self.colors[i]),
392390
);
393391
}
394392
}
@@ -426,9 +424,9 @@ impl MyApp {
426424
let row_height = ui.text_style_height(&egui::TextStyle::Body);
427425

428426
let color = if self.gui_conf.dark_mode {
429-
egui::Color32::WHITE
427+
Color32::WHITE
430428
} else {
431-
egui::Color32::BLACK
429+
Color32::BLACK
432430
};
433431

434432
egui::ScrollArea::vertical()
@@ -803,7 +801,7 @@ impl MyApp {
803801
}
804802
// need to clear the data here in order to prevent errors in the gui (plot)
805803
self.data = DataContainer::default();
806-
self.names_tx.send(self.serial_devices.labels[self.device_idx].clone()).expect("Failed to send names");
804+
// self.names_tx.send(self.serial_devices.labels[self.device_idx].clone()).expect("Failed to send names");
807805

808806
}
809807
ui.end_row();
@@ -821,7 +819,6 @@ impl MyApp {
821819
if ui.add(ThemeSwitch::new(&mut self.gui_conf.theme_preference)).changed() {
822820
ui.ctx().set_theme(self.gui_conf.theme_preference);
823821
};
824-
825822
ui.add_space(25.0);
826823
self.gui_conf.dark_mode = ui.visuals() == &Visuals::dark();
827824
ui.horizontal( |ui| {
@@ -844,15 +841,15 @@ impl MyApp {
844841
for i in 0..self.labels.len().min(10) {
845842
// if init, set names to what has been stored in the device last time
846843
if init {
847-
self.names_tx.send(self.labels.clone()).expect("Failed to send names");
844+
// self.names_tx.send(self.labels.clone()).expect("Failed to send names");
848845
init = false;
849846
}
850847

851848
if self.labels.len() <= i {
852849
break;
853850
}
854851
ui.horizontal(|ui| {
855-
852+
856853
let response = color_picker_widget(ui,"", &mut self.colors,i );
857854

858855
// Check if the square was clicked and toggle color picker window
@@ -864,20 +861,20 @@ impl MyApp {
864861
egui::TextEdit::singleline(&mut self.labels[i])
865862
.desired_width(0.95 * RIGHT_PANEL_WIDTH)
866863
).on_hover_text("Use custom names for your Datasets.").changed() {
867-
self.names_tx.send(self.labels.clone()).expect("Failed to send names");
864+
// self.names_tx.send(self.labels.clone()).expect("Failed to send names");
868865
};
869866
});
870867
}
871-
872-
match self.show_color_window {
873-
ColorWindow::NoShow => {}
868+
match self.show_color_window {ColorWindow::NoShow => {
869+
870+
}
874871
ColorWindow::ColorIndex(index) => {
875872
if color_picker_window(ui.ctx(), &mut self.colors[index], &mut self.color_vals[index]) {
876873
self.show_color_window = ColorWindow::NoShow;
877874
}
878875
}
879876
}
880-
877+
881878
if self.labels.len() > 10 {
882879
ui.label("Only renaming up to 10 Datasets is currently supported.");
883880
}
@@ -920,9 +917,9 @@ impl MyApp {
920917
fn paint_connection_indicator(&self, ui: &mut egui::Ui) {
921918
let (color, color_stroke) = if !self.connected_to_device {
922919
ui.add(egui::Spinner::new());
923-
(egui::Color32::DARK_RED, egui::Color32::RED)
920+
(Color32::DARK_RED, Color32::RED)
924921
} else {
925-
(egui::Color32::DARK_GREEN, egui::Color32::GREEN)
922+
(Color32::DARK_GREEN, Color32::GREEN)
926923
};
927924

928925
let radius = ui.spacing().interact_size.y * 0.375;

src/main.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ use std::sync::{mpsc, Arc, RwLock};
1111
use std::thread;
1212
use std::time::Duration;
1313

14-
use crate::color_picker::COLORS;
1514
use crate::data::{DataContainer, Packet};
1615
use crate::gui::{load_gui_settings, print_to_console, MyApp, Print, RIGHT_PANEL_WIDTH};
1716
use crate::io::{save_to_csv, FileOptions};
@@ -134,7 +133,6 @@ fn main() {
134133
let (save_tx, save_rx): (Sender<FileOptions>, Receiver<FileOptions>) = mpsc::channel();
135134
let (send_tx, send_rx): (Sender<String>, Receiver<String>) = mpsc::channel();
136135
let (clear_tx, clear_rx): (Sender<bool>, Receiver<bool>) = mpsc::channel();
137-
let (names_tx, names_rx): (Sender<Vec<String>>, Receiver<Vec<String>>) = mpsc::channel();
138136
let (raw_data_tx, raw_data_rx): (Sender<Packet>, Receiver<Packet>) = mpsc::channel();
139137

140138
let serial_device_lock = device_lock.clone();
@@ -201,7 +199,6 @@ fn main() {
201199
saved_serial_device_configs,
202200
gui_connected_lock,
203201
gui_settings,
204-
names_tx,
205202
save_tx,
206203
send_tx,
207204
clear_tx,

0 commit comments

Comments
 (0)