Changes for egui/object upgrades

This commit is contained in:
Luke Street 2023-01-21 01:11:40 -05:00
parent 4b58f69461
commit a8c2514377
5 changed files with 285 additions and 256 deletions

View File

@ -250,7 +250,7 @@ fn relocations_by_section(
}; };
// println!("Reloc: {:?}, symbol: {:?}", reloc, symbol); // println!("Reloc: {:?}, symbol: {:?}", reloc, symbol);
let target = match symbol.kind() { let target = match symbol.kind() {
SymbolKind::Text | SymbolKind::Data | SymbolKind::Unknown => { SymbolKind::Text | SymbolKind::Data | SymbolKind::Label | SymbolKind::Unknown => {
to_obj_symbol(obj_file, &symbol, reloc.addend()) to_obj_symbol(obj_file, &symbol, reloc.addend())
} }
SymbolKind::Section => { SymbolKind::Section => {
@ -305,7 +305,7 @@ fn line_info(obj_file: &File<'_>) -> Result<Option<BTreeMap<u32, u32>>> {
let address_delta = reader.read_u32::<BigEndian>()?; let address_delta = reader.read_u32::<BigEndian>()?;
map.insert(base_address + address_delta, line_number); map.insert(base_address + address_delta, line_number);
} }
println!("Line info: {:#X?}", map); println!("Line info: {map:#X?}");
return Ok(Some(map)); return Ok(Some(map));
} }
Ok(None) Ok(None)

View File

@ -1,7 +1,7 @@
use std::{cmp::min, default::Default, mem::take}; use std::{cmp::min, default::Default, mem::take};
use egui::{text::LayoutJob, Color32, Label, Sense}; use egui::{text::LayoutJob, Align, Color32, Label, Layout, Sense, Vec2};
use egui_extras::{Size, StripBuilder, TableBuilder}; use egui_extras::{Column, TableBuilder};
use time::format_description; use time::format_description;
use crate::{ use crate::{
@ -166,36 +166,54 @@ pub fn data_diff_ui(ui: &mut egui::Ui, view_state: &mut ViewState) -> bool {
let (Some(result), Some(selected_symbol)) = (&view_state.build, &view_state.selected_symbol) else { let (Some(result), Some(selected_symbol)) = (&view_state.build, &view_state.selected_symbol) else {
return rebuild; return rebuild;
}; };
StripBuilder::new(ui)
.size(Size::exact(20.0)) // Header
.size(Size::exact(40.0)) let available_width = ui.available_width();
.size(Size::remainder()) let column_width = available_width / 2.0;
.vertical(|mut strip| { ui.allocate_ui_with_layout(
strip.strip(|builder| { Vec2 { x: available_width, y: 100.0 },
builder.sizes(Size::remainder(), 2).horizontal(|mut strip| { Layout::left_to_right(Align::Min),
strip.cell(|ui| { |ui| {
ui.horizontal(|ui| { // Left column
ui.allocate_ui_with_layout(
Vec2 { x: column_width, y: 100.0 },
Layout::top_down(Align::Min),
|ui| {
ui.set_width(column_width);
if ui.button("Back").clicked() { if ui.button("Back").clicked() {
view_state.current_view = View::SymbolDiff; view_state.current_view = View::SymbolDiff;
} }
ui.scope(|ui| {
ui.style_mut().override_text_style = Some(egui::TextStyle::Monospace);
ui.style_mut().wrap = Some(false);
ui.colored_label(Color32::WHITE, &selected_symbol.symbol_name);
ui.label("Diff target:");
}); });
}); },
strip.cell(|ui| { );
// Right column
ui.allocate_ui_with_layout(
Vec2 { x: column_width, y: 100.0 },
Layout::top_down(Align::Min),
|ui| {
ui.set_width(column_width);
ui.horizontal(|ui| { ui.horizontal(|ui| {
if ui.button("Build").clicked() { if ui.button("Build").clicked() {
rebuild = true; rebuild = true;
} }
ui.scope(|ui| { ui.scope(|ui| {
ui.style_mut().override_text_style = ui.style_mut().override_text_style = Some(egui::TextStyle::Monospace);
Some(egui::TextStyle::Monospace);
ui.style_mut().wrap = Some(false); ui.style_mut().wrap = Some(false);
if view_state.jobs.iter().any(|job| job.job_type == Job::ObjDiff) { if view_state.jobs.iter().any(|job| job.job_type == Job::ObjDiff) {
ui.label("Building..."); ui.label("Building...");
} else { } else {
ui.label("Last built:"); ui.label("Last built:");
let format = let format =
format_description::parse("[hour]:[minute]:[second]") format_description::parse("[hour]:[minute]:[second]").unwrap();
.unwrap();
ui.label( ui.label(
result result
.time .time
@ -206,48 +224,31 @@ pub fn data_diff_ui(ui: &mut egui::Ui, view_state: &mut ViewState) -> bool {
} }
}); });
}); });
});
});
});
strip.strip(|builder| {
builder.sizes(Size::remainder(), 2).horizontal(|mut strip| {
strip.cell(|ui| {
ui.scope(|ui| {
ui.style_mut().override_text_style = Some(egui::TextStyle::Monospace);
ui.style_mut().wrap = Some(false);
ui.colored_label(Color32::WHITE, &selected_symbol.symbol_name);
ui.label("Diff target:");
ui.separator();
});
});
strip.cell(|ui| {
ui.scope(|ui| { ui.scope(|ui| {
ui.style_mut().override_text_style = Some(egui::TextStyle::Monospace); ui.style_mut().override_text_style = Some(egui::TextStyle::Monospace);
ui.style_mut().wrap = Some(false); ui.style_mut().wrap = Some(false);
ui.label(""); ui.label("");
ui.label("Diff base:"); ui.label("Diff base:");
});
},
);
},
);
ui.separator(); ui.separator();
});
}); // Table
});
});
strip.cell(|ui| {
if let (Some(left_obj), Some(right_obj)) = (&result.first_obj, &result.second_obj) { if let (Some(left_obj), Some(right_obj)) = (&result.first_obj, &result.second_obj) {
let available_height = ui.available_height();
let table = TableBuilder::new(ui) let table = TableBuilder::new(ui)
.striped(false) .striped(false)
.cell_layout(egui::Layout::left_to_right(egui::Align::Min)) .cell_layout(Layout::left_to_right(Align::Min))
.column(Size::relative(0.5)) .columns(Column::exact(column_width).clip(true), 2)
.column(Size::relative(0.5)) .resizable(false)
.resizable(false); .auto_shrink([false, false])
data_table_ui( .min_scrolled_height(available_height);
table, data_table_ui(table, left_obj, right_obj, selected_symbol, &view_state.view_config);
left_obj,
right_obj,
selected_symbol,
&view_state.view_config,
);
} }
});
});
rebuild rebuild
} }

View File

@ -1,8 +1,9 @@
use std::default::Default; use std::default::Default;
use cwdemangle::demangle; use cwdemangle::demangle;
use egui::{text::LayoutJob, Color32, FontId, Label, Sense}; use eframe::emath::Align;
use egui_extras::{Size, StripBuilder, TableBuilder}; use egui::{text::LayoutJob, Color32, FontId, Label, Layout, Sense, Vec2};
use egui_extras::{Column, TableBuilder};
use ppc750cl::Argument; use ppc750cl::Argument;
use time::format_description; use time::format_description;
@ -332,36 +333,64 @@ pub fn function_diff_ui(ui: &mut egui::Ui, view_state: &mut ViewState) -> bool {
let (Some(result), Some(selected_symbol)) = (&view_state.build, &view_state.selected_symbol) else { let (Some(result), Some(selected_symbol)) = (&view_state.build, &view_state.selected_symbol) else {
return rebuild; return rebuild;
}; };
StripBuilder::new(ui)
.size(Size::exact(20.0)) // Header
.size(Size::exact(40.0)) let available_width = ui.available_width();
.size(Size::remainder()) let column_width = available_width / 2.0;
.vertical(|mut strip| { ui.allocate_ui_with_layout(
strip.strip(|builder| { Vec2 { x: available_width, y: 100.0 },
builder.sizes(Size::remainder(), 2).horizontal(|mut strip| { Layout::left_to_right(Align::Min),
strip.cell(|ui| { |ui| {
ui.horizontal(|ui| { // Left column
ui.allocate_ui_with_layout(
Vec2 { x: column_width, y: 100.0 },
Layout::top_down(Align::Min),
|ui| {
ui.set_width(column_width);
if ui.button("Back").clicked() { if ui.button("Back").clicked() {
view_state.current_view = View::SymbolDiff; view_state.current_view = View::SymbolDiff;
} }
let demangled = demangle(&selected_symbol.symbol_name, &Default::default());
let name = demangled.as_deref().unwrap_or(&selected_symbol.symbol_name);
let mut job = LayoutJob::simple(
name.to_string(),
view_state.view_config.code_font.clone(),
Color32::WHITE,
column_width,
);
job.wrap.break_anywhere = true;
job.wrap.max_rows = 1;
ui.label(job);
ui.scope(|ui| {
ui.style_mut().override_text_style = Some(egui::TextStyle::Monospace);
ui.label("Diff target:");
}); });
}); },
strip.cell(|ui| { );
// Right column
ui.allocate_ui_with_layout(
Vec2 { x: column_width, y: 100.0 },
Layout::top_down(Align::Min),
|ui| {
ui.set_width(column_width);
ui.horizontal(|ui| { ui.horizontal(|ui| {
if ui.button("Build").clicked() { if ui.button("Build").clicked() {
rebuild = true; rebuild = true;
} }
ui.scope(|ui| { ui.scope(|ui| {
ui.style_mut().override_text_style = ui.style_mut().override_text_style = Some(egui::TextStyle::Monospace);
Some(egui::TextStyle::Monospace);
ui.style_mut().wrap = Some(false); ui.style_mut().wrap = Some(false);
if view_state.jobs.iter().any(|job| job.job_type == Job::ObjDiff) { if view_state.jobs.iter().any(|job| job.job_type == Job::ObjDiff) {
ui.label("Building..."); ui.label("Building...");
} else { } else {
ui.label("Last built:"); ui.label("Last built:");
let format = let format =
format_description::parse("[hour]:[minute]:[second]") format_description::parse("[hour]:[minute]:[second]").unwrap();
.unwrap();
ui.label( ui.label(
result result
.time .time
@ -372,28 +401,9 @@ pub fn function_diff_ui(ui: &mut egui::Ui, view_state: &mut ViewState) -> bool {
} }
}); });
}); });
});
});
});
strip.strip(|builder| {
builder.sizes(Size::remainder(), 2).horizontal(|mut strip| {
let demangled = demangle(&selected_symbol.symbol_name, &Default::default());
strip.cell(|ui| {
ui.scope(|ui| { ui.scope(|ui| {
ui.style_mut().override_text_style = Some(egui::TextStyle::Monospace); ui.style_mut().override_text_style = Some(egui::TextStyle::Monospace);
ui.style_mut().wrap = Some(false);
ui.colored_label(
Color32::WHITE,
demangled.as_ref().unwrap_or(&selected_symbol.symbol_name),
);
ui.label("Diff target:");
ui.separator();
});
});
strip.cell(|ui| {
ui.scope(|ui| {
ui.style_mut().override_text_style = Some(egui::TextStyle::Monospace);
ui.style_mut().wrap = Some(false);
if let Some(match_percent) = result if let Some(match_percent) = result
.second_obj .second_obj
.as_ref() .as_ref()
@ -404,30 +414,28 @@ pub fn function_diff_ui(ui: &mut egui::Ui, view_state: &mut ViewState) -> bool {
match_color_for_symbol(match_percent), match_color_for_symbol(match_percent),
&format!("{match_percent:.0}%"), &format!("{match_percent:.0}%"),
); );
} else {
ui.label("");
} }
ui.label("Diff base:"); ui.label("Diff base:");
});
},
);
},
);
ui.separator(); ui.separator();
});
}); // Table
});
});
strip.cell(|ui| {
if let (Some(left_obj), Some(right_obj)) = (&result.first_obj, &result.second_obj) { if let (Some(left_obj), Some(right_obj)) = (&result.first_obj, &result.second_obj) {
let available_height = ui.available_height();
let table = TableBuilder::new(ui) let table = TableBuilder::new(ui)
.striped(false) .striped(false)
.cell_layout(egui::Layout::left_to_right(egui::Align::Min)) .cell_layout(Layout::left_to_right(Align::Min))
.column(Size::relative(0.5)) .columns(Column::exact(column_width).clip(true), 2)
.column(Size::relative(0.5)) .resizable(false)
.resizable(false); .auto_shrink([false, false])
asm_table_ui( .min_scrolled_height(available_height);
table, asm_table_ui(table, left_obj, right_obj, selected_symbol, &view_state.view_config);
left_obj,
right_obj,
selected_symbol,
&view_state.view_config,
);
} }
});
});
rebuild rebuild
} }

View File

@ -9,5 +9,5 @@ pub(crate) mod symbol_diff;
const COLOR_RED: Color32 = Color32::from_rgb(200, 40, 41); const COLOR_RED: Color32 = Color32::from_rgb(200, 40, 41);
fn write_text(str: &str, color: Color32, job: &mut LayoutJob, font_id: FontId) { fn write_text(str: &str, color: Color32, job: &mut LayoutJob, font_id: FontId) {
job.append(str, 0.0, TextFormat { font_id, color, ..Default::default() }); job.append(str, 0.0, TextFormat::simple(font_id, color));
} }

View File

@ -1,5 +1,6 @@
use egui::{ use egui::{
text::LayoutJob, CollapsingHeader, Color32, Rgba, ScrollArea, SelectableLabel, Ui, Widget, text::LayoutJob, Align, CollapsingHeader, Color32, Layout, Rgba, ScrollArea, SelectableLabel,
TextEdit, Ui, Vec2, Widget,
}; };
use egui_extras::{Size, StripBuilder}; use egui_extras::{Size, StripBuilder};
@ -135,12 +136,9 @@ fn symbol_list_ui(
selected_symbol: &mut Option<SymbolReference>, selected_symbol: &mut Option<SymbolReference>,
current_view: &mut View, current_view: &mut View,
reverse_function_order: bool, reverse_function_order: bool,
search: &mut String, lower_search: &str,
config: &ViewConfig, config: &ViewConfig,
) { ) {
ui.text_edit_singleline(search);
let lower_search = search.to_ascii_lowercase();
ScrollArea::both().auto_shrink([false, false]).show(ui, |ui| { ScrollArea::both().auto_shrink([false, false]).show(ui, |ui| {
ui.scope(|ui| { ui.scope(|ui| {
ui.style_mut().override_text_style = Some(egui::TextStyle::Monospace); ui.style_mut().override_text_style = Some(egui::TextStyle::Monospace);
@ -215,21 +213,32 @@ fn build_log_ui(ui: &mut Ui, status: &BuildStatus) {
} }
pub fn symbol_diff_ui(ui: &mut Ui, view_state: &mut ViewState) { pub fn symbol_diff_ui(ui: &mut Ui, view_state: &mut ViewState) {
if let (Some(result), highlighted_symbol, selected_symbol, current_view, search) = ( let (Some(result), highlighted_symbol, selected_symbol, current_view, search) = (
&view_state.build, &view_state.build,
&mut view_state.highlighted_symbol, &mut view_state.highlighted_symbol,
&mut view_state.selected_symbol, &mut view_state.selected_symbol,
&mut view_state.current_view, &mut view_state.current_view,
&mut view_state.search, &mut view_state.search,
) { ) else {
StripBuilder::new(ui).size(Size::exact(40.0)).size(Size::remainder()).vertical( return;
|mut strip| { };
strip.strip(|builder| {
builder.sizes(Size::remainder(), 2).horizontal(|mut strip| { // Header
strip.cell(|ui| { let available_width = ui.available_width();
let column_width = available_width / 2.0;
ui.allocate_ui_with_layout(
Vec2 { x: available_width, y: 100.0 },
Layout::left_to_right(Align::Min),
|ui| {
// Left column
ui.allocate_ui_with_layout(
Vec2 { x: column_width, y: 100.0 },
Layout::top_down(Align::Min),
|ui| {
ui.set_width(column_width);
ui.scope(|ui| { ui.scope(|ui| {
ui.style_mut().override_text_style = ui.style_mut().override_text_style = Some(egui::TextStyle::Monospace);
Some(egui::TextStyle::Monospace);
ui.style_mut().wrap = Some(false); ui.style_mut().wrap = Some(false);
ui.label("Build target:"); ui.label("Build target:");
@ -239,12 +248,20 @@ pub fn symbol_diff_ui(ui: &mut Ui, view_state: &mut ViewState) {
ui.colored_label(Rgba::from_rgb(1.0, 0.0, 0.0), "Fail"); ui.colored_label(Rgba::from_rgb(1.0, 0.0, 0.0), "Fail");
} }
}); });
ui.separator();
}); TextEdit::singleline(search).hint_text("Filter symbols").ui(ui);
strip.cell(|ui| { },
);
// Right column
ui.allocate_ui_with_layout(
Vec2 { x: column_width, y: 100.0 },
Layout::top_down(Align::Min),
|ui| {
ui.set_width(column_width);
ui.scope(|ui| { ui.scope(|ui| {
ui.style_mut().override_text_style = ui.style_mut().override_text_style = Some(egui::TextStyle::Monospace);
Some(egui::TextStyle::Monospace);
ui.style_mut().wrap = Some(false); ui.style_mut().wrap = Some(false);
ui.label("Build base:"); ui.label("Build base:");
@ -254,10 +271,15 @@ pub fn symbol_diff_ui(ui: &mut Ui, view_state: &mut ViewState) {
ui.colored_label(Rgba::from_rgb(1.0, 0.0, 0.0), "Fail"); ui.colored_label(Rgba::from_rgb(1.0, 0.0, 0.0), "Fail");
} }
}); });
},
);
},
);
ui.separator(); ui.separator();
});
}); // Table
}); let lower_search = search.to_ascii_lowercase();
StripBuilder::new(ui).size(Size::remainder()).vertical(|mut strip| {
strip.strip(|builder| { strip.strip(|builder| {
builder.sizes(Size::remainder(), 2).horizontal(|mut strip| { builder.sizes(Size::remainder(), 2).horizontal(|mut strip| {
strip.cell(|ui| { strip.cell(|ui| {
@ -271,7 +293,7 @@ pub fn symbol_diff_ui(ui: &mut Ui, view_state: &mut ViewState) {
selected_symbol, selected_symbol,
current_view, current_view,
view_state.reverse_fn_order, view_state.reverse_fn_order,
search, &lower_search,
&view_state.view_config, &view_state.view_config,
); );
}); });
@ -291,7 +313,7 @@ pub fn symbol_diff_ui(ui: &mut Ui, view_state: &mut ViewState) {
selected_symbol, selected_symbol,
current_view, current_view,
view_state.reverse_fn_order, view_state.reverse_fn_order,
search, &lower_search,
&view_state.view_config, &view_state.view_config,
); );
}); });
@ -302,7 +324,5 @@ pub fn symbol_diff_ui(ui: &mut Ui, view_state: &mut ViewState) {
}); });
}); });
}); });
}, });
);
}
} }