Skip to content

Commit

Permalink
Cull widget draw calls in column and row
Browse files Browse the repository at this point in the history
  • Loading branch information
hecrj committed Oct 2, 2024
1 parent 509a0a5 commit d40aa64
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 26 deletions.
4 changes: 0 additions & 4 deletions core/src/widget/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,10 +334,6 @@ pub fn draw<Renderer>(
{
let bounds = layout.bounds();

if !bounds.intersects(viewport) {
return;
}

let x = match paragraph.horizontal_alignment() {
alignment::Horizontal::Left => bounds.x,
alignment::Horizontal::Center => bounds.center_x(),
Expand Down
19 changes: 8 additions & 11 deletions widget/src/column.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,24 +320,21 @@ where
viewport: &Rectangle,
) {
if let Some(clipped_viewport) = layout.bounds().intersection(viewport) {
let viewport = if self.clip {
&clipped_viewport
} else {
viewport
};

for ((child, state), layout) in self
.children
.iter()
.zip(&tree.children)
.zip(layout.children())
.filter(|(_, layout)| layout.bounds().intersects(viewport))
{
child.as_widget().draw(
state,
renderer,
theme,
style,
layout,
cursor,
if self.clip {
&clipped_viewport
} else {
viewport
},
state, renderer, theme, style, layout, cursor, viewport,
);
}
}
Expand Down
19 changes: 8 additions & 11 deletions widget/src/row.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,24 +316,21 @@ where
viewport: &Rectangle,
) {
if let Some(clipped_viewport) = layout.bounds().intersection(viewport) {
let viewport = if self.clip {
&clipped_viewport
} else {
viewport
};

for ((child, state), layout) in self
.children
.iter()
.zip(&tree.children)
.zip(layout.children())
.filter(|(_, layout)| layout.bounds().intersects(viewport))
{
child.as_widget().draw(
state,
renderer,
theme,
style,
layout,
cursor,
if self.clip {
&clipped_viewport
} else {
viewport
},
state, renderer, theme, style, layout, cursor, viewport,
);
}
}
Expand Down

0 comments on commit d40aa64

Please sign in to comment.