Render dynamic text as plain text, not Pango markup

This commit is contained in:
raucao committed 2026-11-13 21:03:53 +04:00
1 parent bbe32b3c96
commit 993b691ceb
7 files changed
+55 -28

No files matched your search

+1
View File
@@ -36,6 +36,7 @@ cargo_build = custom_target(binary_name,
'src/ui/approval.rs',
'src/ui/keys_view.rs',
'src/ui/mod.rs',
'src/ui/plain.rs',
'src/ui/qr.rs',
'src/ui/signer_view.rs',
'src/window.rs',
+4 -4
View File
@@ -13,6 +13,7 @@ use gtk::prelude::*;
use libadwaita as adw;
use crate::signer::approval::{ApprovalRequest, Decision, Request};
use crate::ui::plain;
/// Start draining questions: each one becomes a dialog, and the answer goes back
/// to the responder. Anything unanswered is a denial.
@@ -43,10 +44,6 @@ async fn present(widget: &gtk::Widget, question: &ApprovalRequest) -> Decision {
};
let dialog = adw::AlertDialog::builder()
// Heading and body are plain text too: the heading carries no client
// data today, but the extra child is where all of it belongs.
.heading_use_markup(false)
.body_use_markup(false)
.heading(heading(&question.request))
.body(story(&question.request))
// Narrower than the 420px default window: a floating `AdwDialog` is
@@ -55,6 +52,9 @@ async fn present(widget: &gtk::Widget, question: &ApprovalRequest) -> Decision {
.content_width(360)
.extra_child(&details(question))
.build();
// Heading and body are plain text too: the heading carries no client data
// today, but the extra child is where all of it belongs.
plain::dialog(&dialog);
dialog.add_response("deny", "Deny");
dialog.set_close_response("deny");
+8 -12
View File
@@ -13,6 +13,7 @@ use libadwaita as adw;
use crate::runtime;
use crate::state::AppState;
use crate::store::keys::KeyStore;
use crate::ui::plain;
/// Handles the callbacks need; cloned per closure.
#[derive(Clone)]
@@ -35,14 +36,8 @@ impl KeysView {
pub fn new(state: Rc<AppState>) -> Self {
let handles = Handles {
stack: gtk::Stack::builder().vexpand(true).build(),
identity: adw::ActionRow::builder()
.title("Identity key")
.subtitle("—")
.build(),
device: adw::ActionRow::builder()
.title("Device key")
.subtitle("—")
.build(),
identity: plain::row("Identity key", "—"),
device: plain::row("Device key", "—"),
};
let loading = adw::StatusPage::builder()
@@ -90,10 +85,7 @@ impl KeysView {
.valign(gtk::Align::Center)
.css_classes(["flat"])
.build();
let export_row = adw::ActionRow::builder()
.title("Export identity key")
.subtitle("Encrypted with a password (NIP-49)")
.build();
let export_row = plain::row("Export identity key", "Encrypted with a password (NIP-49)");
export_row.add_suffix(&export);
export_row.set_activatable_widget(Some(&export));
@@ -231,6 +223,7 @@ fn present_import_dialog(handles: Handles, state: Rc<AppState>) {
.body("This replaces the identity key Regent currently uses.")
.extra_child(&list)
.build();
plain::dialog(&dialog);
dialog.add_response("cancel", "Cancel");
dialog.add_response("import", "Import");
dialog.set_default_response(Some("import"));
@@ -284,6 +277,7 @@ fn present_export_dialog(handles: Handles, state: Rc<AppState>) {
)
.extra_child(&list)
.build();
plain::dialog(&dialog);
dialog.add_response("cancel", "Cancel");
dialog.add_response("export", "Export");
dialog.set_default_response(Some("export"));
@@ -322,6 +316,7 @@ fn present_export_dialog(handles: Handles, state: Rc<AppState>) {
)
.extra_child(&label)
.build();
plain::dialog(&done);
done.add_response("close", "Close");
done.set_default_response(Some("close"));
done.present(window.as_ref());
@@ -340,6 +335,7 @@ fn report_error(handles: &Handles, message: &str) {
.title("Something went wrong")
.body(message)
.build();
plain::dialog(&dialog);
dialog.add_response("close", "Close");
dialog.set_default_response(Some("close"));
dialog.present(toplevel(handles).as_ref());
+1
View File
@@ -2,5 +2,6 @@
pub mod approval;
pub mod keys_view;
pub mod plain;
pub mod qr;
pub mod signer_view;
+34
View File
@@ -0,0 +1,34 @@
//! Adwaita widgets that default to Pango markup, built as plain text.
//!
//! `AdwActionRow` subtitles (`AdwPreferencesRow:use-markup`), `AdwBanner` titles
//! and `AdwAlertDialog` heading/body all default to **Pango markup**. Feeding
//! them dynamic text — a `bunker://…&secret=…` connection string, an error
//! message, a client-supplied name — fails to parse at best (a bare `&` is an
//! entity error, and the text silently does not render) and, worse, lets that
//! text forge formatting that looks like our UI.
//!
//! These constructors make "plain" the obvious choice. `gtk::Label` already
//! defaults to plain text, so it needs no wrapper.
use adw::prelude::*;
use libadwaita as adw;
/// An `ActionRow` whose title and subtitle are plain text.
pub fn row(title: &str, subtitle: &str) -> adw::ActionRow {
adw::ActionRow::builder()
.title(title)
.subtitle(subtitle)
.use_markup(false)
.build()
}
/// Turn off markup on a banner, whose title defaults to markup.
pub fn banner(banner: &adw::Banner) {
banner.set_use_markup(false);
}
/// Turn off markup on an `AlertDialog`'s heading and body.
pub fn dialog(dialog: &adw::AlertDialog) {
dialog.set_heading_use_markup(false);
dialog.set_body_use_markup(false);
}
+5 -12
View File
@@ -18,6 +18,7 @@ use crate::config::Config;
use crate::runtime;
use crate::signer::{Signer, SignerConfig};
use crate::state::AppState;
use crate::ui::plain;
use crate::ui::qr;
/// Handles the callbacks need; cloned per closure.
@@ -57,14 +58,8 @@ impl SignerView {
.build();
stack.add_named(&empty, Some("empty"));
let status = adw::ActionRow::builder()
.title("Status")
.subtitle("Stopped")
.build();
let uri = adw::ActionRow::builder()
.title("Connection string")
.subtitle("—")
.build();
let status = plain::row("Status", "Stopped");
let uri = plain::row("Connection string", "—");
let copy = gtk::Button::builder()
.icon_name("edit-copy-symbolic")
.tooltip_text("Copy connection string")
@@ -72,10 +67,7 @@ impl SignerView {
.css_classes(["flat"])
.build();
uri.add_suffix(&copy);
let device = adw::ActionRow::builder()
.title("Device key")
.subtitle("—")
.build();
let device = plain::row("Device key", "—");
let group = adw::PreferencesGroup::builder()
.title("Pairing")
@@ -304,6 +296,7 @@ fn report_error(handles: &Handles, message: &str) {
.title("Something went wrong")
.body(message)
.build();
plain::dialog(&dialog);
dialog.add_response("close", "Close");
dialog.set_default_response(Some("close"));
dialog.present(toplevel(handles).as_ref());
+2
View File
@@ -11,6 +11,7 @@ use libadwaita as adw;
use crate::config::Config;
use crate::state::AppState;
use crate::ui::keys_view::KeysView;
use crate::ui::plain;
use crate::ui::signer_view::SignerView;
use crate::RESOURCE_PATH;
@@ -35,6 +36,7 @@ impl Window {
let banner: adw::Banner = builder
.object("banner")
.expect("ui/window.blp must contain an object with id \"banner\"");
plain::banner(&banner);
let state = AppState::new();
let keys_view = KeysView::new(Rc::clone(&state));