Просмотр исходного кода

wallet: replace ((a, b), c) in foo1.iter().zip(foo2.iter()).zip(foo3.iter()) with custom zip3(...) util

darkfi 2 лет назад
Родитель
Сommit
76d48a1bd1

+ 4 - 4
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);

+ 3 - 2
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();

+ 3 - 2
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();

+ 36 - 0
bin/darkwallet/src/util.rs

@@ -58,3 +58,39 @@ pub fn ansi_texture(width: usize, height: usize, data: &Vec<u8>) -> String {
 
     out
 }
+
+pub struct TupleIterStruct3<I1, I2, I3> {
+    idx: usize,
+    i1: I1,
+    i2: I2,
+    i3: I3,
+}
+
+impl<I1, I2, I3> Iterator for TupleIterStruct3<I1, I2, I3>
+where
+    I1: Iterator,
+    I2: Iterator,
+    I3: Iterator,
+{
+    type Item = (usize, I1::Item, I2::Item, I3::Item);
+
+    fn next(&mut self) -> Option<Self::Item> {
+        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<X1, X2, X3, I1, I2, I3>(i1: I1, i2: I2, i3: I3) -> TupleIterStruct3<I1, I2, I3>
+where
+    I1: Iterator<Item = X1>,
+    I2: Iterator<Item = X2>,
+    I3: Iterator<Item = X3>,
+{
+    TupleIterStruct3 { idx: 0, i1, i2, i3 }
+}