Skip to content

Commit 527138b

Browse files
authored
Fix flicker in egui virtual list when in a egui_router animation (#92)
1 parent 3c4c512 commit 527138b

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

crates/egui_router/src/transition.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ impl TransitionTrait for SlideTransition {
9494
fn create_child_ui(&self, ui: &mut Ui, t: f32, with_id: Id) -> Ui {
9595
let available_size = ui.available_size();
9696
let offset = available_size * (1.0 - t) * self.amount;
97+
// Round to pixels to prevent sub-pixel jitter and flickering in child components
98+
let offset = Vec2::new(offset.x.round(), offset.y.round());
9799
let child_rect = ui.max_rect().translate(offset);
98100

99101
ui.new_child(UiBuilder::new().max_rect(child_rect).id_salt(with_id))

crates/egui_virtual_list/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,9 @@ impl VirtualList {
130130
) -> VirtualListResponse {
131131
let mut scroll_to_item_index_visibility = None;
132132
{
133-
let available_width_rounded = (ui.available_width() * 10.0).round() / 10.0;
133+
let available_width_rounded = (ui.max_rect().width() * 10.0).round() / 10.0;
134134
if let Some(last_width) = self.last_width {
135-
if available_width_rounded != last_width {
135+
if (available_width_rounded - last_width).abs() > 1.0 {
136136
self.last_width = Some(available_width_rounded);
137137
if self.check_for_resize {
138138
self.last_known_row_index = None;

0 commit comments

Comments
 (0)