Elide npub bylines in the middle

A long npub was either shown in full (wrapping to a second line) or pre-cut
with plain::shorten, a fixed character count that still end-ellipsizes as the
width changes. Give every npub row the bunker URI's treatment instead: one
line, ellipsized in the middle, which adapts to the width. This covers the
identities list, the Apps details (including the expander byline, via a new
plain::middle_ellipsis_text for non-ActionRows), "Signing as" in the Connect
dialog, and the approval dialog's client key.

It also fixes the Connect dialog clipping its content: the scroller sizes
itself to the content's natural height measured at the *unwrapped* width, so
the wrapping npub made it ~13px taller than the dialog, pushing the bottom
below the fold. A single-line npub removes the discrepancy.
This commit is contained in:
raucao committed 2026-11-26 12:30:35 +04:00
1 parent e2785afa37
commit 6b40ceb854
6 files changed
+49 -15

No files matched your search

+9 -4
View File
@@ -595,13 +595,18 @@ UI lives in `data/resources/ui/*.blp` (Blueprint) and is compiled to `.ui` by
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.
at whatever width it gets. Every npub byline/row uses it (identities, Apps
details, "Signing as", the approval dialog's client key) — and a wrapped npub
is also what made the "Connect an app" dialog clip its bottom: the scroller
measures natural height at the *unwrapped* width (trap 15), so a long token
must stay on one line.
14. `AdwExpanderRow` is **not** an `AdwActionRow`: both derive from
`AdwPreferencesRow`, but neither is a subclass of the other, and the two do
not share a `subtitle` accessor trait. `plain::middle_ellipsis` therefore
takes an `&AdwActionRow` and cannot be applied to an expander's subtitle —
`set_subtitle_lines(1)` there means end-ellipsis, which is fine for a short
byline but not for a long token.
takes an `&AdwActionRow`; for an expander's subtitle use
`plain::middle_ellipsis_text(&row, &subtitle)`, which finds the label by its
text. `set_subtitle_lines(1)` alone there means end-ellipsis, which is fine
for a short byline but not for a long token.
15. A `GtkScrolledWindow`'s **natural height is 0** unless
`propagate_natural_height` is set, and `AdwDialog` sizes itself to its child's
natural height. So a dialog whose child is a scroller collapses to just its
+5 -2
View File
@@ -481,10 +481,13 @@ fn details(question: &Question) -> gtk::Box {
fn more_details(question: &Question) -> gtk::ListBox {
let client = &question.client;
let row = plain::expander("Details", "Key and request metadata");
row.add_row(&plain::row(
let client_key = plain::row(
"Client key",
&client.public_key.to_bech32().unwrap_or_default(),
));
);
client_key.set_subtitle_lines(1);
plain::middle_ellipsis(&client_key);
row.add_row(&client_key);
if let Some(url) = &client.url {
row.add_row(&plain::row("Declared URL", url));
}
+12 -3
View File
@@ -244,11 +244,17 @@ impl Ui {
// client-supplied URL is display data only — it proves nothing.
let byline = match app.url.as_deref() {
Some(url) => declared_host(url),
None => plain::shorten(&npub, 12, 6),
None => npub.clone(),
};
let row = plain::expander(&name, &byline);
row.set_subtitle_lines(1);
row.add_row(&plain::row("Public key", &npub));
// An `AdwExpanderRow` is not an `AdwActionRow`, so it needs the
// text-based helper. The full npub is kept; the label ellipsizes it.
plain::middle_ellipsis_text(&row, &byline);
let public_key = plain::row("Public key", &npub);
public_key.set_subtitle_lines(1);
plain::middle_ellipsis(&public_key);
row.add_row(&public_key);
if let Some(url) = &app.url {
row.add_row(&plain::row("Declared URL", url));
}
@@ -266,7 +272,10 @@ impl Ui {
"paired before identities existed".to_string(),
),
};
row.add_row(&plain::row(&signing_as, &signing_npub));
let signing_as_row = plain::row(&signing_as, &signing_npub);
signing_as_row.set_subtitle_lines(1);
plain::middle_ellipsis(&signing_as_row);
row.add_row(&signing_as_row);
if app.policy.kinds.is_empty() && app.policy.methods.is_empty() {
row.add_row(&plain::row(
+6
View File
@@ -58,6 +58,8 @@ impl ConnectDialog {
.title("The app shows a code")
.build();
let signing_as = plain::row("Signing as", "");
// The npub beneath is a long token: one line, ellipsized in the middle.
signing_as.set_subtitle_lines(1);
identity_group.add(&signing_as);
let entry = adw::EntryRow::builder().title("Pairing code").build();
// Insensitive until there is something to pair: an empty submit would
@@ -272,6 +274,10 @@ impl ConnectDialog {
self.signing_as.set_subtitle("Add an identity key first.");
}
}
// Re-applied each time: the subtitle changes, and this is what keeps the
// npub on one line (also what keeps the dialog from clipping its
// bottom — a wrapped npub is taller than the natural-height measure).
plain::middle_ellipsis(&self.signing_as);
match self.runner.status() {
Status::Stopped => {
+5 -2
View File
@@ -182,10 +182,13 @@ fn key_row(
.map(|key| key.to_bech32().unwrap_or_default())
.unwrap_or_else(|| hex.to_string());
let subtitle = match profile {
Some(profile) => format!("{profile} · {}", plain::shorten(&npub, 12, 6)),
None => plain::shorten(&npub, 12, 6),
Some(profile) => format!("{profile} · {npub}"),
None => npub.clone(),
};
let row = plain::row(name, &subtitle);
// The npub is a long token: one line, ellipsized in the middle.
row.set_subtitle_lines(1);
plain::middle_ellipsis(&row);
// Initials avatar, from the kind-0 name when there is one.
row.add_prefix(&adw::Avatar::new(32, Some(profile.unwrap_or(name)), true));
+12 -4
View File
@@ -73,10 +73,18 @@ pub fn expander(title: &str, subtitle: &str) -> adw::ExpanderRow {
/// 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()) {
if let Some(subtitle) = row.subtitle() {
middle_ellipsis_text(row, subtitle.as_str());
}
}
/// [`middle_ellipsis`] for a row that is not an `AdwActionRow`.
///
/// An `AdwExpanderRow`'s subtitle is the same trap: it is not an
/// `AdwActionRow` (trap 14), so it has no `subtitle()` accessor shared with one.
/// `text` is the subtitle currently set, which is how the label is found.
pub fn middle_ellipsis_text(row: &impl IsA<gtk::Widget>, text: &str) {
if let Some(label) = find_label(row.upcast_ref(), text) {
label.set_ellipsize(gtk::pango::EllipsizeMode::Middle);
}
}