Skip to content

Commit 7b46052

Browse files
committed
allow not displaying values in left side
1 parent bf46926 commit 7b46052

File tree

1 file changed

+25
-36
lines changed

1 file changed

+25
-36
lines changed

extra/mem_reader/src/main.rs

Lines changed: 25 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,11 @@ impl eframe::App for App {
9090
DisplayType::Str,
9191
"Str",
9292
);
93+
ui.selectable_value(
94+
&mut self.display_type,
95+
DisplayType::None,
96+
"None",
97+
);
9398
});
9499
});
95100
},
@@ -188,6 +193,7 @@ pub enum DisplayType {
188193
SignedNum,
189194
Float,
190195
Str,
196+
None,
191197
}
192198
pub enum Data {
193199
Struct(Vec<(u32, u32)>),
@@ -571,76 +577,46 @@ impl Elem {
571577
"[{e}]{}usize{}({})",
572578
"&".repeat(count),
573579
array.map(|a| format!("[{}]", a.len())).unwrap_or_default(),
574-
array
575-
.map(|b| b
576-
.iter()
577-
.map(|v| display_type.print(v))
578-
.collect::<Vec<String>>()
579-
.join(","))
580-
.unwrap_or(display_type.print(v)),
580+
display_type.print_opt(array, v)
581581
)
582582
}
583583
Elem::Recursive(v) => {
584584
format!(
585585
"[{e}]{}recursive{}({})",
586586
"&".repeat(count),
587587
array.map(|a| format!("[{}]", a.len())).unwrap_or_default(),
588-
array
589-
.map(|b| b
590-
.iter()
591-
.map(|v| display_type.print(v))
592-
.collect::<Vec<String>>()
593-
.join(","))
594-
.unwrap_or(display_type.print(v)),
588+
display_type.print_opt(array, v)
595589
)
596590
}
597591
Elem::VFTable(v) => {
598592
format!(
599593
"[{e}]{}VFTable{}({})",
600594
"&".repeat(count),
601595
array.map(|a| format!("[{}]", a.len())).unwrap_or_default(),
602-
array
603-
.map(|b| b
604-
.iter()
605-
.map(|v| display_type.print(v))
606-
.collect::<Vec<String>>()
607-
.join(","))
608-
.unwrap_or(display_type.print(v)),
596+
display_type.print_opt(array, v)
609597
)
610598
}
611599
Elem::TooLarge(v) => {
612600
format!(
613601
"[{e}]{}TooLarge{}({})",
614602
"&".repeat(count),
615603
array.map(|a| format!("[{}]", a.len())).unwrap_or_default(),
616-
array
617-
.map(|b| b
618-
.iter()
619-
.map(|v| display_type.print(v))
620-
.collect::<Vec<String>>()
621-
.join(","))
622-
.unwrap_or(display_type.print(v)),
604+
display_type.print_opt(array, v)
623605
)
624606
}
625607
Elem::Failed(v) => {
626608
format!(
627609
"[{e}]{}Failed{}({})",
628610
"&".repeat(count),
629611
array.map(|a| format!("[{}]", a.len())).unwrap_or_default(),
630-
array
631-
.map(|b| b
632-
.iter()
633-
.map(|v| display_type.print(v))
634-
.collect::<Vec<String>>()
635-
.join(","))
636-
.unwrap_or(display_type.print(v)),
612+
display_type.print_opt(array, v)
637613
)
638614
}
639615
}
640616
}
641617
}
642618
impl DisplayType {
643-
fn print(&self, n: &u32) -> String {
619+
fn print(self, n: &u32) -> String {
644620
match self {
645621
DisplayType::Hex => {
646622
format!("{n:08x}")
@@ -658,6 +634,19 @@ impl DisplayType {
658634
format!("{}", f32::from_bits(*n))
659635
}
660636
DisplayType::Str => String::from_utf8(n.to_le_bytes().to_vec()).unwrap_or_default(),
637+
DisplayType::None => String::new(),
661638
}
662639
}
640+
fn print_opt(self, a: Option<&[u32]>, v: &u32) -> String {
641+
if DisplayType::None == self {
642+
return String::new();
643+
}
644+
a.map(|b| {
645+
b.iter()
646+
.map(|v| self.print(v))
647+
.collect::<Vec<String>>()
648+
.join(",")
649+
})
650+
.unwrap_or(self.print(v))
651+
}
663652
}

0 commit comments

Comments
 (0)