From 76d48a1bd14e008f214835ac9c9caa88865feba9 Mon Sep 17 00:00:00 2001 From: darkfi Date: Sat, 6 Jul 2024 11:27:11 +0200 Subject: [PATCH] wallet: replace ((a, b), c) in foo1.iter().zip(foo2.iter()).zip(foo3.iter()) with custom zip3(...) util --- bin/darkwallet/src/mesh.rs | 8 +++---- bin/darkwallet/src/ui/editbox.rs | 5 +++-- bin/darkwallet/src/ui/text.rs | 5 +++-- bin/darkwallet/src/util.rs | 36 ++++++++++++++++++++++++++++++++ 4 files changed, 46 insertions(+), 8 deletions(-) diff --git a/bin/darkwallet/src/mesh.rs b/bin/darkwallet/src/mesh.rs index 1e8992c47..7965fb56c 100644 --- a/bin/darkwallet/src/mesh.rs +++ b/bin/darkwallet/src/mesh.rs @@ -61,16 +61,16 @@ impl MeshBuilder { assert!(obj.h >= clipped.h); let i = (clipped.x - obj.x) / obj.w; - let clip_u1 = u1 + i*(u2 - u1); + let clip_u1 = u1 + i * (u2 - u1); let i = (clipped.rhs() - obj.x) / obj.w; - let clip_u2 = u1 + i*(u2 - u1); + let clip_u2 = u1 + i * (u2 - u1); let i = (clipped.y - obj.y) / obj.h; - let clip_v1 = v1 + i*(v2 - v1); + let clip_v1 = v1 + i * (v2 - v1); let i = (clipped.bhs() - obj.y) / obj.h; - let clip_v2 = v1 + i*(v2 - v1); + let clip_v2 = v1 + i * (v2 - v1); let (u1, u2) = (clip_u1, clip_u2); let (v1, v2) = (clip_v1, clip_v2); diff --git a/bin/darkwallet/src/ui/editbox.rs b/bin/darkwallet/src/ui/editbox.rs index 3a0267b85..d27388579 100644 --- a/bin/darkwallet/src/ui/editbox.rs +++ b/bin/darkwallet/src/ui/editbox.rs @@ -18,6 +18,7 @@ use crate::{ pubsub::Subscription, scene::{Pimpl, SceneGraph, SceneGraphPtr2, SceneNodeId}, text2::{self, Glyph, GlyphPositionIter, RenderedAtlas, SpritePtr, TextShaper, TextShaperPtr}, + util::zip3, }; use super::{eval_rect, get_parent_rect, read_rect, DrawUpdate, OnModify, Stoppable}; @@ -262,8 +263,8 @@ impl EditBox { let mut mesh = MeshBuilder::with_clip(clip.clone()); let mut glyph_pos_iter = GlyphPositionIter::new(font_size, &glyphs, baseline); - for ((uv_rect, glyph_rect), glyph) in - atlas.uv_rects.into_iter().zip(glyph_pos_iter).zip(glyphs.iter()) + for (glyph_idx, uv_rect, glyph_rect, glyph) in + zip3(atlas.uv_rects.into_iter(), glyph_pos_iter, glyphs.iter()) { //mesh.draw_outline(&glyph_rect, COLOR_BLUE, 2.); let mut color = text_color.clone(); diff --git a/bin/darkwallet/src/ui/text.rs b/bin/darkwallet/src/ui/text.rs index eb3170dae..dd36d6e91 100644 --- a/bin/darkwallet/src/ui/text.rs +++ b/bin/darkwallet/src/ui/text.rs @@ -11,6 +11,7 @@ use crate::{ }, scene::{Pimpl, SceneGraph, SceneGraphPtr2, SceneNodeId}, text2::{self, Glyph, GlyphPositionIter, RenderedAtlas, SpritePtr, TextShaper, TextShaperPtr}, + util::zip3, }; use super::{eval_rect, get_parent_rect, read_rect, DrawUpdate, OnModify, Stoppable}; @@ -120,8 +121,8 @@ impl Text { let mut mesh = MeshBuilder::new(); let mut glyph_pos_iter = GlyphPositionIter::new(font_size, &glyphs, baseline); - for ((uv_rect, glyph_rect), glyph) in - atlas.uv_rects.into_iter().zip(glyph_pos_iter).zip(glyphs.iter()) + for (_, uv_rect, glyph_rect, glyph) in + zip3(atlas.uv_rects.into_iter(), glyph_pos_iter, glyphs.iter()) { //mesh.draw_outline(&glyph_rect, COLOR_BLUE, 2.); let mut color = text_color.clone(); diff --git a/bin/darkwallet/src/util.rs b/bin/darkwallet/src/util.rs index fcd325391..7a474646b 100644 --- a/bin/darkwallet/src/util.rs +++ b/bin/darkwallet/src/util.rs @@ -58,3 +58,39 @@ pub fn ansi_texture(width: usize, height: usize, data: &Vec) -> String { out } + +pub struct TupleIterStruct3 { + idx: usize, + i1: I1, + i2: I2, + i3: I3, +} + +impl Iterator for TupleIterStruct3 +where + I1: Iterator, + I2: Iterator, + I3: Iterator, +{ + type Item = (usize, I1::Item, I2::Item, I3::Item); + + fn next(&mut self) -> Option { + let Some(x1) = self.i1.next() else { return None }; + let Some(x2) = self.i2.next() else { return None }; + let Some(x3) = self.i3.next() else { return None }; + + let res = (self.idx, x1, x2, x3); + self.idx += 1; + + Some(res) + } +} + +pub fn zip3(i1: I1, i2: I2, i3: I3) -> TupleIterStruct3 +where + I1: Iterator, + I2: Iterator, + I3: Iterator, +{ + TupleIterStruct3 { idx: 0, i1, i2, i3 } +}