Support icon links in About dialogs

This commit is contained in:
Dylan M. Taylor
2026-11-21 13:04:56 -05:00
parent 810e552707
commit 8bf462750b
2 changed files with 17 additions and 3 deletions
@@ -331,10 +331,15 @@ impl Shown<'_> {
});
Row::new().align(RowAlign::Center).show(ui, |ui, _| {
for (at, item) in info.links.iter().enumerate() {
if at > 0 {
if at > 0 && item.icon.is_none() && info.links.get(at - 1).is_some_and(|previous| previous.icon.is_none()) {
Text::new("·").shade(Shade::Faint).show(ui);
}
if clicked(&Link::new(item.label.clone()).id_salt(("link", at)).show(ui)) {
let activated = if let Some(icon) = &item.icon {
clicked(&IconButton::new(icon.clone()).label(item.label.clone()).tooltip(item.label.clone()).id_salt(("link", at)).show(ui))
} else {
clicked(&Link::new(item.label.clone()).id_salt(("link", at)).show(ui))
};
if activated {
*link.borrow_mut() = Some(item.url.clone());
}
}
@@ -12,12 +12,21 @@ pub struct AboutLink {
pub label: Label,
/// The target URL, reported in the output for the app to open.
pub url: String,
/// An icon to show in place of link text, with the label retained for accessibility.
pub icon: Option<craft_behavior::IconId>,
}
impl AboutLink {
/// A link showing `label` to `url`.
pub fn new(label: impl Into<Label>, url: impl Into<String>) -> Self {
AboutLink { label: label.into(), url: url.into() }
AboutLink { label: label.into(), url: url.into(), icon: None }
}
/// Shows this link as an icon button.
#[must_use]
pub fn icon(mut self, icon: craft_behavior::IconId) -> Self {
self.icon = Some(icon);
self
}
}