Add label for links
This commit is contained in:
+30
-5
@@ -107,18 +107,43 @@ fn node_section(
|
||||
set_file(doc, id, Some(path), Some(sub));
|
||||
}
|
||||
}
|
||||
NodeKind::Link { url } => {
|
||||
let mut buffer = url.clone();
|
||||
NodeKind::Link { url, label } => {
|
||||
let mut url_buffer = url.clone();
|
||||
ui.label(field_label(palette, "URL"));
|
||||
if ui
|
||||
.add(TextEdit::singleline(&mut buffer).desired_width(f32::INFINITY))
|
||||
.add(TextEdit::singleline(&mut url_buffer).desired_width(f32::INFINITY))
|
||||
.changed()
|
||||
{
|
||||
doc.begin_change("Edit URL");
|
||||
if let Some(NodeKind::Link { url }) = doc.canvas.node_mut(id).map(|n| &mut n.kind) {
|
||||
*url = buffer;
|
||||
if let Some(NodeKind::Link { url, .. }) =
|
||||
doc.canvas.node_mut(id).map(|n| &mut n.kind)
|
||||
{
|
||||
*url = url_buffer;
|
||||
}
|
||||
}
|
||||
|
||||
ui.add_space(6.0);
|
||||
ui.label(field_label(palette, "Display text"));
|
||||
let mut label_buffer = label.clone().unwrap_or_default();
|
||||
if ui
|
||||
.add(
|
||||
TextEdit::singleline(&mut label_buffer)
|
||||
.desired_width(f32::INFINITY)
|
||||
.hint_text("Shown instead of the URL"),
|
||||
)
|
||||
.changed()
|
||||
{
|
||||
doc.begin_change("Edit display text");
|
||||
if let Some(NodeKind::Link { label, .. }) =
|
||||
doc.canvas.node_mut(id).map(|n| &mut n.kind)
|
||||
{
|
||||
// Kept verbatim so a space typed mid-word is not trimmed
|
||||
// away under the cursor; blank labels simply go away.
|
||||
*label = (!label_buffer.is_empty()).then_some(label_buffer);
|
||||
}
|
||||
}
|
||||
|
||||
ui.add_space(6.0);
|
||||
if ui.button("Open in browser").clicked() {
|
||||
out.open_target = Some(url.clone());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user