Keep the network address visible as peers reconnect

The collapsed card allocated the graph and peer count before the address and reserved a fixed 110 points for every network name. A growing count could hide an assigned address, even beside a short name. Measure the title and reserve the address first. Use the remaining space for counts and the sparkline, and include the address in the card tooltip.

Reproduced the old layout failure and verified the vpn card at 320 and 359 points as its online count grows from 1 to 14. Confirmed the agent and macOS interface still had the reported address.
This commit is contained in:
Aleksandr Bogomiakov committed 2026-11-26 02:57:38 +02:00
1 parent 21de427c62
commit 7b83aec3be
2 files changed
+95 -27

No files matched your search

+40 -27
View File
@@ -88,39 +88,52 @@ pub(super) fn header(
let left = dot.x + 9.; let left = dot.x + 9.;
let mut right = rect.right() - 2.; let mut right = rect.right() - 2.;
let quiet = ui.visuals().weak_text_color(); let quiet = ui.visuals().weak_text_color();
// Preserve a useful piece of the name even on the narrow landscape selector. let title_font = FontId::new(font.size + 4., egui::FontFamily::Name("Bold".into()));
if right - left > 98. { let strong = ui.visuals().strong_text_color();
let width = (rect.width() * 0.15).clamp(26., 64.); let title = painter.layout_no_wrap(net.name.clone(), title_font.clone(), strong);
let mut spare = right - left - title.size().x.min(64.);
const GAP: f32 = 8.;
let mut reserve = |text| {
let galley = painter.layout_no_wrap(text, font.clone(), ink);
let width = galley.size().x + GAP;
if width > spare {
return None;
}
spare -= width;
Some(galley)
};
// Reserve the address first. Peer counts grow as sessions reconnect.
let address = net.overlay.as_ref().and_then(|o| o.address.as_deref());
let ip = address.and_then(|s| reserve(s.to_owned()));
let peers = reserve(format!("{} {online}/{known}", icon::DEVICES));
let clients = if users > 0 {
reserve(format!("{} {users}", icon::SIGN_IN))
} else {
None
};
let width = (rect.width() * 0.15).min(64.).min(spare - GAP);
if width >= 26. {
let plot = Rect::from_center_size(pos2(right - width / 2., center), vec2(width, 14.)); let plot = Rect::from_center_size(pos2(right - width / 2., center), vec2(width, 14.));
format::mini_traffic(&painter, plot, series, unit, quiet, net.active); format::mini_traffic(&painter, plot, series, unit, quiet, net.active);
right = plot.left() - 7.; right = plot.left() - GAP;
} }
let mut field = |text: String, reserved: f32| { for galley in [peers, clients, ip].into_iter().flatten() {
let galley = painter.layout_no_wrap(text, font.clone(), ink); right -= galley.size().x;
if right - left - galley.size().x >= reserved { painter.galley(pos2(right, center - galley.size().y / 2.), galley, ink);
right -= galley.size().x; right -= GAP;
painter.galley(pos2(right, center - galley.size().y / 2.), galley, ink);
right -= 8.;
}
};
field(format!("{} {online}/{known}", icon::DEVICES), 45.);
if users > 0 {
field(format!("{} {users}", icon::SIGN_IN), 60.);
} }
if let Some(addr) = net.overlay.as_ref().and_then(|o| o.address.as_deref()) { widgets::single_line(
field(addr.to_owned(), 110.); &painter,
} Rect::from_min_max(pos2(left, rect.top()), pos2(right.max(left), rect.bottom())),
let mut job = egui::text::LayoutJob::simple_singleline( Align::Min,
net.name.clone(), &net.name,
FontId::new(font.size + 4., egui::FontFamily::Name("Bold".into())), title_font,
ui.visuals().strong_text_color(), strong,
); );
job.wrap.max_width = (right - left).max(1.);
job.wrap.max_rows = 1;
job.wrap.break_anywhere = true;
let name = painter.layout_job(job);
painter.galley(pos2(left, center - name.size().y / 2.), name, ink);
let mut hint = format!("{} · {status}\n{online} online · {known} known", net.name); let mut hint = format!("{} · {status}\n{online} online · {known} known", net.name);
if let Some(address) = address {
hint.push_str(&format!("\n{address}"));
}
if users > 0 { if users > 0 {
hint.push_str(&format!("\n{}", user_count(users))); hint.push_str(&format!("\n{}", user_count(users)));
} }
@@ -441,6 +441,61 @@ fn desktop_full_table_survives_long_names_and_compact_exit_icon_starts_and_stops
} }
} }
#[test]
fn collapsed_vpn_keeps_its_address_as_peers_reconnect() {
let ctx = Context::default();
ctx.set_fonts(crate::app_fonts());
let mut state = home::UiState::default();
let report = tsunagi::ipc::StatusReport::default();
let address = "10.78.107.201";
let mut network = NetworkReport {
name: "vpn".into(),
active: true,
overlay: Some(OverlayReport {
address: Some(address.into()),
..Default::default()
}),
members: (0..14)
.map(|i| MemberReport {
endpoint_id: format!("peer-{i}"),
..Default::default()
})
.collect(),
..Default::default()
};
for width in [320., 359.] {
for online in [1, 9, 10, 12, 14] {
for (i, member) in network.members.iter_mut().enumerate() {
member.online = i < online;
}
let out = frame(
&ctx,
egui::vec2(width, 240.),
online as f64,
vec![],
|ctx| {
egui::CentralPanel::default().show(ctx, |ui| {
home::draw_network(
ui,
&ReadOnly,
&mut state,
&Traffic::default(),
&network,
&report,
true,
);
});
},
);
let name = label(&out, "vpn").unwrap();
let address = label(&out, address).expect("the local address stays visible");
let count = label(&out, &format!("{} {online}/14", icon::DEVICES)).unwrap();
assert!(name.right() < address.left() && address.right() < count.left());
assert!(count.right() <= width);
}
}
}
#[test] #[test]
fn exit_users_scroll_a_row_inside_the_existing_card_and_disappear_on_deselection() { fn exit_users_scroll_a_row_inside_the_existing_card_and_disappear_on_deselection() {
for (width, os) in [ for (width, os) in [