Scrollable
A scroll area with thin overlay scrollbars that show while scrolling and widen under the pointer.
Vertical
ui.vertical(|ui| {
ui.set_width(320.0);
Scrollable::vertical()
.id_salt("vertical")
.max_height(200.0)
.auto_shrink([false, true])
.show(ui, |ui| {
for index in 1..=50 {
ui.label(format!("Line {index} of a long page"));
}
});
});
Both directions
ui.vertical(|ui| {
ui.set_width(420.0);
Scrollable::both()
.id_salt("both")
.max_height(200.0)
.auto_shrink([false, true])
.show(ui, |ui| {
egui::Grid::new("cells")
.spacing([24.0, 8.0])
.show(ui, |ui| {
for row in 0..30 {
for column in 0..12 {
ui.label(format!("Cell {row}:{column}"));
}
ui.end_row();
}
});
});
});
Modes
for (name, mode) in [
("Scrolling", ScrollbarMode::Scrolling),
("Hover", ScrollbarMode::Hover),
("Always", ScrollbarMode::Always),
("Hidden", ScrollbarMode::Hidden),
] {
ui.vertical(|ui| {
ui.set_width(150.0);
ui.label(name);
Scrollable::vertical()
.id_salt(name)
.mode(mode)
.max_height(120.0)
.auto_shrink([false, true])
.show(ui, |ui| {
for index in 1..=20 {
ui.label(format!("Item {index}"));
}
});
});
}
Edge fade
ui.vertical(|ui| {
ui.set_width(360.0);
ui.label("A chip row that scrolls with the plain wheel and fades where it is cut off.");
Scrollable::horizontal()
.id_salt("chips")
.mode(ScrollbarMode::Hidden)
.edge_fade()
.wheel_scrolls_only_direction()
.show(ui, |ui| {
ui.horizontal(|ui| {
for genre in [
"Ambient",
"Blues",
"Classical",
"Disco",
"Electro",
"Folk",
"Funk",
"House",
"Jazz",
"Metal",
"Pop",
"Reggae",
"Soul",
"Techno",
] {
ui.add(Tag::new(genre));
}
});
});
});
Wheel steps
ui.vertical(|ui| {
ui.set_width(320.0);
ui.label("Each wheel notch moves exactly one 24-point row.");
Scrollable::vertical()
.id_salt("notches")
.wheel_step(24.0)
.max_height(24.0 * 6.0)
.auto_shrink([false, true])
.show(ui, |ui| {
ui.spacing_mut().item_spacing.y = 0.0;
for index in 1..=40 {
let (rect, _) = ui.allocate_exact_size(
egui::vec2(ui.available_width(), 24.0),
egui::Sense::hover(),
);
let color = if index % 2 == 0 {
tokens(ui.ctx()).muted
} else {
egui::Color32::TRANSPARENT
};
ui.painter().rect_filled(rect, 0.0, color);
ui.painter().text(
rect.left_center() + egui::vec2(8.0, 0.0),
egui::Align2::LEFT_CENTER,
format!("Row {index}"),
egui::FontId::proportional(14.0),
tokens(ui.ctx()).foreground,
);
}
});
});
The story above is gallery/src/stories/scrollable.rs, running in your browser. Every snippet on this page is cut from it.