1
0
mirror of https://github.com/emilk/egui.git synced 2026-09-01 06:10:06 -04:00

Style: forbid .zip and .chain (#8188)

The `zip(a, b)` variant produces clearer code imho.

Downside: added dependency on `itertools`
This commit is contained in:
Emil Ernerfeldt
2026-05-22 12:25:34 +02:00
committed by GitHub
parent ac2496318f
commit 27373b06d0
18 changed files with 68 additions and 69 deletions

View File

@@ -74,6 +74,7 @@ epaint = { workspace = true, default-features = false }
accesskit.workspace = true
ahash.workspace = true
bitflags.workspace = true
itertools.workspace = true
log.workspace = true
nohash-hasher.workspace = true
profiling.workspace = true

View File

@@ -472,17 +472,15 @@ impl<'a> Popup<'a> {
RectAlign::find_best_align(
#[expect(clippy::iter_on_empty_collections)]
#[expect(clippy::or_fun_call)]
once(self.rect_align).chain(
std::iter::chain(
once(self.rect_align),
self.alternative_aligns
// Need the empty slice so the iters have the same type so we can unwrap_or
.map(|a| a.iter().copied().chain([].iter().copied()))
.unwrap_or(
self.rect_align
.symmetries()
.iter()
.copied()
.chain(RectAlign::MENU_ALIGNS.iter().copied()),
),
.map(|a| std::iter::chain(a.iter().copied(), [].iter().copied()))
.unwrap_or(std::iter::chain(
self.rect_align.symmetries().iter().copied(),
RectAlign::MENU_ALIGNS.iter().copied(),
)),
),
self.ctx.content_rect(),
anchor_rect,

View File

@@ -641,11 +641,7 @@ impl ContextImpl {
}
fn all_viewport_ids(&self) -> ViewportIdSet {
self.viewports
.keys()
.copied()
.chain([ViewportId::ROOT])
.collect()
std::iter::chain(self.viewports.keys().copied(), [ViewportId::ROOT]).collect()
}
/// The current active viewport

View File

@@ -232,20 +232,14 @@ pub(crate) fn interact(
// );
// }
let contains_pointer: IdSet = hits
.contains_pointer
.iter()
.chain(&hits.click)
.chain(&hits.drag)
.map(|w| w.id)
.collect();
let contains_pointer: IdSet =
itertools::chain!(&hits.contains_pointer, &hits.click, &hits.drag)
.map(|w| w.id)
.collect();
let hovered = if clicked.is_some() || dragged.is_some() || long_touched.is_some() {
// If currently clicking or dragging, only that and nothing else is hovered.
clicked
.iter()
.chain(&dragged)
.chain(&long_touched)
itertools::chain!(&clicked, &dragged, &long_touched)
.copied()
.collect()
} else {
@@ -268,7 +262,9 @@ pub(crate) fn interact(
let drag_order = hits.drag.and_then(|w| order(w.id)).unwrap_or(0);
let top_interactive_order = click_order.max(drag_order);
let mut hovered: IdSet = hits.click.iter().chain(&hits.drag).map(|w| w.id).collect();
let mut hovered: IdSet = std::iter::chain(&hits.click, &hits.drag)
.map(|w| w.id)
.collect();
for w in &hits.contains_pointer {
let is_interactive = w.sense.senses_click() || w.sense.senses_drag();

View File

@@ -1232,11 +1232,12 @@ impl Areas {
}
pub fn visible_layer_ids(&self) -> ahash::HashSet<LayerId> {
self.visible_areas_last_frame
.iter()
.copied()
.chain(self.visible_areas_current_frame.iter().copied())
.collect()
std::iter::chain(
&self.visible_areas_last_frame,
&self.visible_areas_current_frame,
)
.copied()
.collect()
}
pub(crate) fn visible_windows(&self) -> impl Iterator<Item = (LayerId, &area::AreaState)> {