From 7b83aec3be3a4de318b9e2888f1827b52cbd3f55 Mon Sep 17 00:00:00 2001 From: Aleksandr Bogomiakov Date: Thu, 26 Nov 2026 02:57:38 +0200 Subject: [PATCH] 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. --- crates/tsunagi-ui/src/home/card.rs | 67 ++++++++++++--------- crates/tsunagi-ui/src/presentation_tests.rs | 55 +++++++++++++++++ 2 files changed, 95 insertions(+), 27 deletions(-) diff --git a/crates/tsunagi-ui/src/home/card.rs b/crates/tsunagi-ui/src/home/card.rs index c5df4a6..f4fb17b 100644 --- a/crates/tsunagi-ui/src/home/card.rs +++ b/crates/tsunagi-ui/src/home/card.rs @@ -88,39 +88,52 @@ pub(super) fn header( let left = dot.x + 9.; let mut right = rect.right() - 2.; let quiet = ui.visuals().weak_text_color(); - // Preserve a useful piece of the name even on the narrow landscape selector. - if right - left > 98. { - let width = (rect.width() * 0.15).clamp(26., 64.); + let title_font = FontId::new(font.size + 4., egui::FontFamily::Name("Bold".into())); + let strong = ui.visuals().strong_text_color(); + 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.)); 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| { - let galley = painter.layout_no_wrap(text, font.clone(), ink); - if right - left - galley.size().x >= reserved { - right -= galley.size().x; - 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.); + for galley in [peers, clients, ip].into_iter().flatten() { + right -= galley.size().x; + painter.galley(pos2(right, center - galley.size().y / 2.), galley, ink); + right -= GAP; } - if let Some(addr) = net.overlay.as_ref().and_then(|o| o.address.as_deref()) { - field(addr.to_owned(), 110.); - } - let mut job = egui::text::LayoutJob::simple_singleline( - net.name.clone(), - FontId::new(font.size + 4., egui::FontFamily::Name("Bold".into())), - ui.visuals().strong_text_color(), + widgets::single_line( + &painter, + Rect::from_min_max(pos2(left, rect.top()), pos2(right.max(left), rect.bottom())), + Align::Min, + &net.name, + title_font, + 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); + if let Some(address) = address { + hint.push_str(&format!("\n{address}")); + } if users > 0 { hint.push_str(&format!("\n{}", user_count(users))); } diff --git a/crates/tsunagi-ui/src/presentation_tests.rs b/crates/tsunagi-ui/src/presentation_tests.rs index 3dcd427..50d5394 100644 --- a/crates/tsunagi-ui/src/presentation_tests.rs +++ b/crates/tsunagi-ui/src/presentation_tests.rs @@ -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] fn exit_users_scroll_a_row_inside_the_existing_card_and_disappear_on_deselection() { for (width, os) in [