Bubble
A chat surface for text and rich content: seven variants, tails, grouped runs, timestamps and reactions.
Variants
ui.add(Bubble::new().text("A strong primary bubble."));
ui.add(
Bubble::new()
.text("The neutral secondary bubble.")
.variant(BubbleVariant::Secondary),
);
ui.add(
Bubble::new()
.text("A lower-emphasis muted bubble.")
.variant(BubbleVariant::Muted),
);
ui.add(
Bubble::new()
.text("A softly tinted primary bubble.")
.variant(BubbleVariant::Tinted),
);
ui.add(
Bubble::new()
.text("A bordered bubble for rich content.")
.variant(BubbleVariant::Outline),
);
ui.add(
Bubble::new()
.text("A failed action with its reason in text.")
.variant(BubbleVariant::Destructive),
);
ui.add(
Bubble::new()
.text("Ghost content is unframed and can use the full row width.")
.variant(BubbleVariant::Ghost),
);
Alignment
ui.add(
Bubble::new()
.text("Incoming message")
.variant(BubbleVariant::Secondary),
);
ui.add(
Bubble::new()
.text("Outgoing message")
.alignment(MessageAlignment::End),
);
Tails
ui.add(
Bubble::new()
.text("A corner tail at the top, as WhatsApp draws it.")
.variant(BubbleVariant::Secondary)
.tail(BubbleTail::Top),
);
ui.add(
Bubble::new()
.text("Apple's Messages balloon.")
.alignment(MessageAlignment::End)
.tail(BubbleTail::Bottom),
);
ui.add(
Bubble::new()
.text("Outlined, the border follows the tail.")
.variant(BubbleVariant::Outline)
.tail(BubbleTail::Bottom),
);
Group
let incoming = [
"Can you tell me what changed?",
"The registry route was stale.",
];
for (index, text) in incoming.iter().enumerate() {
ui.add(
Bubble::new()
.text(*text)
.variant(BubbleVariant::Secondary)
.position(BubblePosition::in_run(index, incoming.len())),
);
}
ui.add_space(12.0);
let outgoing = [
"I removed the stale route.",
"The updated registry is ready to review.",
"Ship it?",
];
for (index, text) in outgoing.iter().enumerate() {
ui.add(
Bubble::new()
.text(*text)
.alignment(MessageAlignment::End)
.position(BubblePosition::in_run(index, outgoing.len())),
);
}
ui.add_space(12.0);
let tailed = ["Tails go on the run's first bubble", "and only there."];
for (index, text) in tailed.iter().enumerate() {
ui.add(
Bubble::new()
.text(*text)
.variant(BubbleVariant::Secondary)
.tail(BubbleTail::Top)
.position(BubblePosition::in_run(index, tailed.len())),
);
}
ui.add_space(12.0);
let balloons = ["Messages balloons", "curl the last one."];
for (index, text) in balloons.iter().enumerate() {
ui.add(
Bubble::new()
.text(*text)
.alignment(MessageAlignment::End)
.tail(BubbleTail::Bottom)
.position(BubblePosition::in_run(index, balloons.len())),
);
}
Timestamps
ui.add(
Bubble::new()
.text("See you at eight")
.variant(BubbleVariant::Secondary)
.timestamp("10:24"),
);
ui.add(
Bubble::new()
.text("Booked a table by the window.")
.alignment(MessageAlignment::End)
.timestamp("10:25")
.status(MessageStatus::Read),
);
ui.add(
Bubble::new()
.text("A longer message wraps within the bubble, and its time takes a line of its own when the last line is too full to hold it beside.")
.variant(BubbleVariant::Muted)
.timestamp("10:26"),
);
ui.add(
Bubble::new()
.text("Not delivered")
.alignment(MessageAlignment::End)
.variant(BubbleVariant::Destructive)
.timestamp("10:27")
.status(MessageStatus::Failed),
);
Reactions
let shown = Bubble::new()
.text("This bubble has reaction feedback.")
.variant(BubbleVariant::Outline)
.reaction(format!("👍 {}", state.likes))
.show(ui, |_| ());
if shown.reaction_clicked == Some(0) {
state.likes += 1;
}
ui.add_space(8.0);
ui.add(
Bubble::new()
.text("Reactions can attach to any edge.")
.alignment(MessageAlignment::End)
.reaction("✨ 1")
.reaction("❤ 3")
.reaction_side(BubbleReactionSide::Top)
.reaction_alignment(MessageAlignment::Start),
);
Rich content
Bubble::new()
.variant(BubbleVariant::Outline)
.show(ui, |ui| {
ui.label("The implementation guide is available online.");
ui.hyperlink_to(
"Open the component documentation",
"https://github.com/crmne/fastframe",
);
});
Bubble::new()
.variant(BubbleVariant::Muted)
.text("The accessibility review found two focus states that need more contrast.")
.show(ui, |ui| {
if state.expanded {
ui.label(
"Dialog and sheet controls already keep their focus rings visible.",
);
}
let label = if state.expanded {
"Show less"
} else {
"Show more"
};
if ui.add(Button::ghost(label).small()).clicked() {
state.expanded = !state.expanded;
}
});
Right to left
ui.add(
Bubble::new()
.text("שלום, מה שלומך?")
.variant(BubbleVariant::Secondary)
.rtl(true)
.tail(BubbleTail::Top)
.timestamp("09:12"),
);
ui.add(
Bubble::new()
.text("مرحبا")
.alignment(MessageAlignment::End)
.rtl(true)
.tail(BubbleTail::Top)
.timestamp("09:13"),
);
The story above is gallery/src/stories/bubble.rs, running in your browser. Every snippet on this page is cut from it.