Tray: split rate/plot columns, add unit toggle to the devices window
The connected-peers rate and sparkline shared one grid cell, so the plot still moved right as the rate text grew (e.g. "1.0 kB/s"). They are now two separate grid columns — the plot column starts at the same x on every row, since grid columns align. The devices window also gets its own pkts/bytes toggle, bound to the same unit setting as the main window so the two stay in step. Builds and is clippy-clean (-D warnings) on macOS; not run in this headless session. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
1 parent
db01c58a6f
commit
2a0a8abd60
2 files changed
+23
-14
No files matched your search
@@ -99,7 +99,6 @@ impl App {
|
|||||||
let Some(Ok(report)) = &snapshot.status else {
|
let Some(Ok(report)) = &snapshot.status else {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
let unit = self.state.unit;
|
|
||||||
let open: Vec<String> = self.state.open_devices.iter().cloned().collect();
|
let open: Vec<String> = self.state.open_devices.iter().cloned().collect();
|
||||||
for id in open {
|
for id in open {
|
||||||
let Some(network) = report.networks.iter().find(|n| n.network_id == id) else {
|
let Some(network) = report.networks.iter().find(|n| n.network_id == id) else {
|
||||||
@@ -114,6 +113,9 @@ impl App {
|
|||||||
.with_min_inner_size([480.0, 320.0]);
|
.with_min_inner_size([480.0, 320.0]);
|
||||||
let agent = &self.agent;
|
let agent = &self.agent;
|
||||||
let traffic = &self.traffic;
|
let traffic = &self.traffic;
|
||||||
|
// The window shares the single unit setting, so its toggle and the
|
||||||
|
// main window's stay in step.
|
||||||
|
let unit = &mut self.state.unit;
|
||||||
let keep = ctx.show_viewport_immediate(viewport_id, builder, |vctx, _class| {
|
let keep = ctx.show_viewport_immediate(viewport_id, builder, |vctx, _class| {
|
||||||
devices::show(vctx, agent, unit, network, traffic);
|
devices::show(vctx, agent, unit, network, traffic);
|
||||||
!vctx.input(|i| i.viewport().close_requested())
|
!vctx.input(|i| i.viewport().close_requested())
|
||||||
|
|||||||
@@ -24,12 +24,21 @@ pub(crate) fn title(network: &NetworkReport) -> String {
|
|||||||
pub(crate) fn show(
|
pub(crate) fn show(
|
||||||
ctx: &egui::Context,
|
ctx: &egui::Context,
|
||||||
_agent: &AgentClient,
|
_agent: &AgentClient,
|
||||||
unit: Unit,
|
unit: &mut Unit,
|
||||||
network: &NetworkReport,
|
network: &NetworkReport,
|
||||||
traffic: &Traffic,
|
traffic: &Traffic,
|
||||||
) {
|
) {
|
||||||
egui::CentralPanel::default().show(ctx, |ui| {
|
egui::CentralPanel::default().show(ctx, |ui| {
|
||||||
ui.heading(&network.name);
|
ui.horizontal(|ui| {
|
||||||
|
ui.heading(&network.name);
|
||||||
|
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
|
||||||
|
ui.selectable_value(unit, Unit::Bytes, "bytes");
|
||||||
|
ui.selectable_value(unit, Unit::Packets, "pkts");
|
||||||
|
ui.label("show:");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
// A copy of the chosen unit for the read-only rendering below.
|
||||||
|
let unit = *unit;
|
||||||
summary(ui, network);
|
summary(ui, network);
|
||||||
ui.add_space(6.0);
|
ui.add_space(6.0);
|
||||||
|
|
||||||
@@ -129,7 +138,7 @@ fn connected_table(
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
egui::Grid::new("connected")
|
egui::Grid::new("connected")
|
||||||
.num_columns(7)
|
.num_columns(8)
|
||||||
.striped(true)
|
.striped(true)
|
||||||
.spacing([10.0, 4.0])
|
.spacing([10.0, 4.0])
|
||||||
.show(ui, |ui| {
|
.show(ui, |ui| {
|
||||||
@@ -140,7 +149,8 @@ fn connected_table(
|
|||||||
"handshake",
|
"handshake",
|
||||||
"pkts",
|
"pkts",
|
||||||
"bytes",
|
"bytes",
|
||||||
"rate / plot",
|
"rate",
|
||||||
|
"plot",
|
||||||
] {
|
] {
|
||||||
ui.weak(header);
|
ui.weak(header);
|
||||||
}
|
}
|
||||||
@@ -169,15 +179,12 @@ fn connected_table(
|
|||||||
format::bytes(peer.rx_bytes as f64)
|
format::bytes(peer.rx_bytes as f64)
|
||||||
));
|
));
|
||||||
let series = traffic.peer(network_id, &peer.public_key);
|
let series = traffic.peer(network_id, &peer.public_key);
|
||||||
ui.horizontal(|ui| {
|
// Rate and plot are separate grid columns, so the plot column
|
||||||
// A fixed-width rate so the inline plot does not shift as
|
// starts at the same x on every row regardless of the rate's
|
||||||
// the number's length changes (e.g. "0 B/s" vs "1.1 kB/s").
|
// text width.
|
||||||
ui.allocate_ui(egui::vec2(64.0, 18.0), |ui| {
|
ui.add(egui::Label::new(format::series_rate(series, unit)).truncate());
|
||||||
ui.add(egui::Label::new(format::series_rate(series, unit)).truncate());
|
ui.allocate_ui(egui::vec2(100.0, 20.0), |ui| {
|
||||||
});
|
format::sparkline(ui, series, unit, 18.0);
|
||||||
ui.allocate_ui(egui::vec2(90.0, 20.0), |ui| {
|
|
||||||
format::sparkline(ui, series, unit, 18.0);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
ui.end_row();
|
ui.end_row();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user