Elide the connection string in the middle

set_subtitle_lines(1) also sets the subtitle label's ellipsize to END, and
the row exposes no setter for the mode, so a long bunker:// string was cut
at the end. Pre-shortening only moved the threshold, because a character
count cannot follow the font or the window width.

plain::middle_ellipsis finds the subtitle label in the row's widget tree
and sets MIDDLE; set_subtitle does not reset it. The row then keeps the
head and the secret tail and drops the middle at whatever width it gets.
This commit is contained in:
raucao committed 2026-11-25 20:24:22 +04:00
1 parent 487be47d48
commit 5643249423
3 files changed
+49

No files matched your search

+10
View File
@@ -557,6 +557,16 @@ UI lives in `data/resources/ui/*.blp` (Blueprint) and is compiled to `.ui` by
`pack_end` ends up rightmost. The main window puts every control on the left
with `pack_start`, laid out `[menu][identity switcher][lock] …` in call
order. Remember the prepend if a control is ever moved back to `pack_end`.
13. An `AdwActionRow`'s `subtitle-lines` decides both the line count **and** the
ellipsis mode: `set_subtitle_lines(1)` makes libadwaita set the subtitle
label's `PANGO_ELLIPSIZE_END`, and the row exposes no setter for the mode. A
long subtitle (the `bunker://` connection string) therefore truncates at the
end, and pre-shortening it with `plain::shorten` only moves the threshold —
it is a character count, so the row still end-ellipsizes as soon as the font
or window width differs. `plain::middle_ellipsis(row)` finds the subtitle
label in the row's own widget tree and sets `MIDDLE`; `set_subtitle` does not
reset it, so once at construction is enough. The row then elides the middle
at whatever width it gets.
## Blueprint / Meson traps
+7
View File
@@ -84,6 +84,11 @@ impl ConnectDialog {
// --- The signer-initiated direction: hidden until asked for. ---
let uri = plain::row("Connection string", "—");
// The connection string is long and stays on one line, ellipsized in
// the middle: the head and the secret tail are what identify it, and
// the middle is dropped as the row narrows.
uri.set_subtitle_lines(1);
plain::middle_ellipsis(&uri);
let copy = gtk::Button::builder()
.icon_name("edit-copy-symbolic")
.tooltip_text("Copy connection string")
@@ -301,6 +306,8 @@ impl ConnectDialog {
self.reveal.set_sensitive(true);
self.reveal
.set_subtitle("The connection string embeds the pairing secret.");
// Display only: the copy button and the QR code still use the
// full string. The row ellipsizes it in the middle.
self.uri.set_subtitle(signer.bunker_uri());
if self.reveal.is_expanded() {
self.show_qr(signer.bunker_uri());
+32
View File
@@ -58,6 +58,38 @@ pub fn expander(title: &str, subtitle: &str) -> adw::ExpanderRow {
row
}
/// Make an `ActionRow`'s subtitle ellipsize in the middle instead of at the end.
///
/// `set_subtitle_lines(1)` is what keeps the subtitle on one line, but
/// libadwaita then hard-codes `PANGO_ELLIPSIZE_END`, and the row exposes no
/// setter for the mode. The subtitle label is reachable in the row's own widget
/// tree; `set_subtitle` does not reset the mode, so setting it once is enough. A
/// row whose subtitle label cannot be found is left as it is.
pub fn middle_ellipsis(row: &adw::ActionRow) {
let Some(subtitle) = row.subtitle() else {
return;
};
if let Some(label) = find_label(row.upcast_ref(), subtitle.as_str()) {
label.set_ellipsize(gtk::pango::EllipsizeMode::Middle);
}
}
fn find_label(widget: &gtk::Widget, text: &str) -> Option<gtk::Label> {
if let Some(label) = widget.downcast_ref::<gtk::Label>() {
if label.text().as_str() == text {
return Some(label.clone());
}
}
let mut child = widget.first_child();
while let Some(widget) = child {
if let Some(found) = find_label(&widget, text) {
return Some(found);
}
child = widget.next_sibling();
}
None
}
/// `value` shortened to `head…tail` characters, for one-line subtitles.
pub fn shorten(value: &str, head: usize, tail: usize) -> String {
let chars: Vec<char> = value.chars().collect();