Editable text
A name that turns into a field when clicked, keeps the new name on Enter or a click elsewhere and gives it up on Escape.
Click the name to rename it
EditableText::new(&mut state.title)
.id_salt("title")
.font(egui::FontId::proportional(22.0))
.show(ui);
Rows: double-click, or right-click for Rename
ui.vertical(|ui| {
ui.set_width(280.0);
for (index, name) in state.playlists.iter_mut().enumerate() {
let start = state.rename == Some(index);
let shown = EditableText::new(name)
.id_salt(("playlist", index))
.width(280.0)
.activation(EditableTextActivation::DoubleClick)
.start_editing(start)
.show(ui);
if start {
state.rename = None;
}
shown.response.context_menu(|ui| {
if ui.button("Rename").clicked() {
state.rename = Some(index);
ui.close();
}
});
}
});
Underline style, typed in place
ui.editable_text_style(editable_text_styles::Underline, |ui| {
ui.horizontal(|ui| {
ui.label("At");
EditableText::new(&mut state.venue)
.id_salt("venue")
.placeholder("a venue")
.show(ui);
ui.label("on");
EditableText::new(&mut state.date)
.id_salt("date")
.placeholder("a date")
.show(ui);
ui.label("by");
EditableText::new(&mut state.author)
.id_salt("author")
.placeholder("who made it")
.show(ui);
});
});
Your own style
EditableText::new(&mut state.own)
.id_salt("own")
.style(&Dotted)
.show(ui);
The story above is gallery/src/stories/editable_text.rs, running in your browser. Every snippet on this page is cut from it.