Skip to content

Commit

Permalink
update egui
Browse files Browse the repository at this point in the history
  • Loading branch information
woelper committed Mar 14, 2022
1 parent 966e068 commit f59309b
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 45 deletions.
2 changes: 1 addition & 1 deletion linetest-gui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ license = "MIT"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
eframe = "0.13.0" # Gives us egui, epi and web+native backends
eframe = "0.17.0" # Gives us egui, epi and web+native backends
serde = { version = "1", features = ["derive"], optional = true }
linetest = { path = "../"}
anyhow = "1.0.42"
Expand Down
Binary file added linetest-gui/src/Roboto-Regular.ttf
Binary file not shown.
90 changes: 46 additions & 44 deletions linetest-gui/src/app.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use eframe::egui::plot::{Legend, Points};
use eframe::egui::{Color32, FontDefinitions, FontFamily, TextStyle, Visuals};
use eframe::egui::{Color32, FontData, FontDefinitions, FontFamily, TextStyle, Visuals};
use eframe::{egui, epi};
use egui::plot::{HLine, Line, Plot, Value, Values};
use linetest::{self, Datapoint, Evaluation, MeasurementBuilder};
Expand Down Expand Up @@ -53,36 +53,37 @@ impl epi::App for LinetestApp {

fn setup(
&mut self,
ctx: &egui::CtxRef,
_frame: &mut epi::Frame<'_>,
ctx: &egui::Context,
_frame: &epi::Frame,
_storage: Option<&dyn epi::Storage>,
) {
let mut fonts = FontDefinitions::default();

// fonts.font_data.insert(key, value)

fonts.font_data.insert(
"plex".to_owned(),
std::borrow::Cow::Borrowed(include_bytes!("IBMPlexSans-Regular.ttf")),
FontData::from_static(include_bytes!("IBMPlexSans-Regular.ttf")), // std::borrow::Cow::Borrowed(include_bytes!("IBMPlexSans-Regular.ttf")),
);

fonts
.family_and_size
.insert(TextStyle::Body, (FontFamily::Proportional, 18.0));

fonts
.family_and_size
.insert(TextStyle::Button, (FontFamily::Proportional, 18.0));

fonts
.fonts_for_family
.families
.get_mut(&FontFamily::Proportional)
.unwrap()
.insert(0, "plex".to_owned());
.insert(0, "plex".into());

let mut style: egui::Style = (*ctx.style()).clone();


style.text_styles.get_mut(&TextStyle::Body).unwrap().size = 20.;
style.text_styles.get_mut(&TextStyle::Button).unwrap().size = 20.;
style.text_styles.get_mut(&TextStyle::Small).unwrap().size = 15.;
ctx.set_style(style);
ctx.set_fonts(fonts);
}

/// Called each time the UI needs repainting, which may be many times per second.
fn update(&mut self, ctx: &egui::CtxRef, frame: &mut epi::Frame<'_>) {
fn update(&mut self, ctx: &egui::Context, _frame: &epi::Frame) {
let Self {
receiver,
datapoints,
Expand Down Expand Up @@ -113,14 +114,14 @@ impl epi::App for LinetestApp {
egui::TopBottomPanel::top("top_panel").show(ctx, |ui| {
// The top panel is often a good place for a menu bar:
egui::menu::bar(ui, |ui| {
egui::menu::menu(ui, "File", |ui| {
if ui.button("Quit").clicked() {
frame.quit();
}
if ui.button("Toggle light/dark").clicked() {
*dark_mode = !*dark_mode;
}
});
// egui::menu::menu(ui, "File", |ui| {
// if ui.button("Quit").clicked() {
// frame.quit();
// }
// if ui.button("Toggle light/dark").clicked() {
// *dark_mode = !*dark_mode;
// }
// });
});
});

Expand All @@ -141,7 +142,7 @@ impl epi::App for LinetestApp {
));

ui.with_layout(egui::Layout::bottom_up(egui::Align::Center), |ui| {
ui.add(egui::Hyperlink::new("https://github.com/woelper/linetest/").text("github"));
ui.add(egui::Hyperlink::new("https://github.com/woelper/linetest/"));
});
});

Expand Down Expand Up @@ -213,36 +214,37 @@ impl epi::App for LinetestApp {
let timeouts = Points::new(Values::from_values(timeout_values))
.filled(true)
.radius(8.)
.highlight()
.name("timeout")
.shape(egui::plot::MarkerShape::Down);

let mut latency_plot = Plot::new("latency")
.hline(
HLine::new(datapoints.mean_latency().as_millis() as f64)
.name(format!(
"Mean latency ({}ms)",
datapoints.mean_latency().as_millis()
))
.color(line_color.linear_multiply(0.1)),
)
.points(latency_points)
.points(timeouts)
Plot::new("latency")
.view_aspect(5.0)
.legend(Legend::default().text_style(TextStyle::Small))
.view_aspect(5.0);

// add a line to the plot if it is not dense
if datapoints.len() < 100 {
latency_plot = latency_plot.line(latency_line);
}
.show(ui, |plot_ui| {
plot_ui.points(latency_points);

ui.add(latency_plot);
// add a line to the plot if it is not dense
if datapoints.len() < 100 {
plot_ui.line(latency_line);
}
plot_ui.points(timeouts);
plot_ui.hline(
HLine::new(datapoints.mean_latency().as_millis() as f64)
.name(format!(
"Mean latency ({}ms)",
datapoints.mean_latency().as_millis()
))
.color(line_color.linear_multiply(0.1)),
);
});

ui.label("Download speed (Mbit/s)");
let download_line = Line::new(Values::from_values(dl_values))
.color(line_color)
.fill(0.0);
ui.add(Plot::new("dl").line(download_line).view_aspect(4.0));
Plot::new("dl").view_aspect(4.0).show(ui, |plot_ui| {
plot_ui.line(download_line);
});

if receiver.is_none() {
if ui.button("⏺ Start recording").clicked() {
Expand Down

0 comments on commit f59309b

Please sign in to comment.