Diff
Two texts compared line by line, unified or side by side, the changed words highlighted and unchanged runs folded, from the fastframe-ui-diff crate.
Unified
ui.vertical(|ui| {
ui.set_width(width);
summary(ui, &state.document);
Diff::new(&mut state.document)
.id_salt("unified")
.max_height(320.0)
.show(ui);
});
Side by side
ui.vertical(|ui| {
ui.set_width(width);
Diff::new(&mut state.side_by_side)
.id_salt("side-by-side")
.layout(DiffLayout::SideBySide)
.max_height(320.0)
.show(ui);
});
Five thousand lines
ui.vertical(|ui| {
ui.set_width(width);
ui.horizontal(|ui| {
summary(ui, &state.long);
if ui.add(Button::new("Expand all").small()).clicked() {
state.long.expand_all();
}
if ui.add(Button::new("Collapse all").small()).clicked() {
state.long.collapse_all();
}
});
Diff::new(&mut state.long)
.id_salt("long")
.max_height(320.0)
.show(ui);
});
Gutter style, from the environment
ui.vertical(|ui| {
ui.set_width(width);
ui.diff_style(diff_styles::Gutter, |ui| {
Diff::new(&mut state.gutter)
.id_salt("gutter")
.max_height(240.0)
.show(ui);
});
});
Your own style
ui.vertical(|ui| {
ui.set_width(width);
Diff::new(&mut state.own)
.id_salt("own")
.style(&Ink)
.max_height(240.0)
.show(ui);
});
The story above is gallery/src/stories/diff.rs, running in your browser. Every snippet on this page is cut from it.