Message
A chat row: avatar, author and time, content, delivery status and actions that appear on hover.
Alignment
Message::new()
.avatar(Avatar::new().name("Alice"))
.author("Alice")
.time("10:24 AM")
.footer("Read")
.show(ui, |ui| {
ui.add(
Bubble::new()
.text("Can you review this?")
.variant(BubbleVariant::Secondary),
);
});
Message::new()
.alignment(MessageAlignment::End)
.avatar(Avatar::new().name("You"))
.author("You")
.time("10:25 AM")
.status(MessageStatus::Delivered)
.show(ui, |ui| {
ui.add(Bubble::new().text("Sure, I will send notes shortly."));
});
Avatar
Message::new()
.avatar(Avatar::new().name("Jordan Park"))
.author("Jordan Park")
.show(ui, |ui| {
ui.add(
Bubble::new()
.text("Initials stand in without an image.")
.variant(BubbleVariant::Muted),
);
});
Message::new().empty_avatar().show(ui, |ui| {
ui.add(
Bubble::new()
.text("An empty avatar slot keeps grouped responses aligned.")
.variant(BubbleVariant::Secondary),
);
});
Status
for status in [
MessageStatus::Sending,
MessageStatus::Sent,
MessageStatus::Delivered,
MessageStatus::Read,
MessageStatus::Played,
] {
Message::new()
.alignment(MessageAlignment::End)
.status(status)
.show(ui, |ui| {
ui.add(Bubble::new().text(status.label()));
});
}
Actions
let liked = state.liked;
let shown = Message::new()
.avatar(Avatar::new().name("Assistant"))
.author("Assistant")
.time("Just now")
.show_with_actions(
ui,
|ui| {
ui.add(
Bubble::new()
.text("Hover this message to see its actions.")
.variant(BubbleVariant::Muted),
);
},
|ui| {
ui.add(Button::ghost("Copy").xsmall());
ui.add(Button::ghost("Like").xsmall().selected(liked))
.clicked()
},
);
if shown.actions == Some(true) {
state.liked = !state.liked;
}
let retried = Message::new()
.alignment(MessageAlignment::End)
.status(MessageStatus::Failed)
.always_show_actions(true)
.show_with_actions(
ui,
|ui| {
ui.add(
Bubble::new()
.text("The response could not be sent.")
.variant(BubbleVariant::Destructive),
);
},
|ui| ui.add(Button::ghost("Retry").xsmall()).clicked(),
);
if retried.actions == Some(true) {
state.retried += 1;
}
Attachment
Message::new()
.avatar(Avatar::new().name("Alice"))
.show(ui, |ui| {
ui.add(
Bubble::new()
.text("Done. Here is the updated report.")
.variant(BubbleVariant::Secondary),
);
Attachment::new("sales-dashboard.pdf")
.bytes(2_400_000)
.show_with_actions(ui, |ui| ui.add(Button::ghost("Open").small()));
});
Ghost surface
Message::new()
.author("System")
.time("Just now")
.content_inset(false)
.show(ui, |ui| {
ui.add(
Bubble::new()
.text("Unframed content lines up with the header without an inset.")
.variant(BubbleVariant::Ghost),
);
});
The story above is gallery/src/stories/message.rs, running in your browser. Every snippet on this page is cut from it.