fastframe-ui-diff
A text diff view for fastframe-ui: unified or side by side, changed lines tinted and the words that changed in them highlighted, long runs of unchanged lines folded away, in the theme’s colours.
It is a crate of its own so only apps that show diffs pull in
similar, which compares the texts.
The view is drawn by this crate, laying out only the rows in view (with
fastframe-ui’s VirtualList), so a diff of many thousands of lines scrolls
as quickly as a short one.
[dependencies]
fastframe-ui-diff = { git = "https://github.com/crmne/fastframe", tag = "v0.19.0" }
Use
Compare the texts once, when they change, and show the document every frame:
use fastframe_ui_diff::{Diff, DiffDocument, DiffLayout};
struct Review {
document: DiffDocument,
}
impl Review {
fn new(old: &str, new: &str) -> Self {
Self {
document: DiffDocument::new(old, new),
}
}
fn ui(&mut self, ui: &mut egui::Ui) {
Diff::new(&mut self.document)
.layout(DiffLayout::SideBySide)
.max_height(480.0)
.show(ui);
}
}
DiffDocument keeps three unchanged lines either side of each change
(with_context or set_context for another number) and folds the rest;
clicking a fold, or expand, expand_all and collapse_all, open them.
Changed lines that replace each other are compared word by word, and the
words that differ are highlighted, unless the lines share too little for
that to help. Lines longer than the view are clipped.
Styles
As everywhere in fastframe-ui, the view says what it shows and a style
decides how each row looks. diff_styles::Tinted (the default) washes
added lines green and removed ones red; diff_styles::Gutter leaves the
rows plain with a coloured bar down the gutter. Set one with
.style(&diff_styles::Gutter), or for a part of the window with
ui.diff_style(diff_styles::Gutter, |ui| ...). A style of your own
implements DiffStyle, whose DiffRowConfiguration has helpers for the
line numbers, the marker, the text with its highlights and the fold label.
Licence
MIT. similar is Apache-2.0; see NOTICE.
Related crates
Draws the interface, like this one:
- egui components and widgets: Buttons, tables, dialogs, pickers and the rest, with four looks, 21 bundled theme files, light and dark.
- Dockable panels: Drag tabs to move, split or float them, drawn in the look and theme of the rest.
- Code editor: Line numbers, syntax colours for common languages, the current line and find.
All 27 fastframe crates, by what they do for an app.