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);
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())
}
SymbolKind::Section => {
@ -305,7 +305,7 @@ fn line_info(obj_file: &File<'_>) -> Result<Option<BTreeMap<u32, u32>>> {
let address_delta = reader.read_u32::<BigEndian>()?;
map.insert(base_address + address_delta, line_number);
}
println!("Line info: {:#X?}", map);
println!("Line info: {map:#X?}");
return Ok(Some(map));
}
Ok(None)

View File

@ -1,7 +1,7 @@
use std::{cmp::min, default::Default, mem::take};
use egui::{text::LayoutJob, Color32, Label, Sense};
use egui_extras::{Size, StripBuilder, TableBuilder};
use egui::{text::LayoutJob, Align, Color32, Label, Layout, Sense, Vec2};
use egui_extras::{Column, TableBuilder};
use time::format_description;
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 {
return rebuild;
};
StripBuilder::new(ui)
.size(Size::exact(20.0))
.size(Size::exact(40.0))
.size(Size::remainder())
.vertical(|mut strip| {
strip.strip(|builder| {
builder.sizes(Size::remainder(), 2).horizontal(|mut strip| {
strip.cell(|ui| {
ui.horizontal(|ui| {
// Header
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);
if ui.button("Back").clicked() {
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| {
if ui.button("Build").clicked() {
rebuild = true;
}
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);
if view_state.jobs.iter().any(|job| job.job_type == Job::ObjDiff) {
ui.label("Building...");
} else {
ui.label("Last built:");
let format =
format_description::parse("[hour]:[minute]:[second]")
.unwrap();
format_description::parse("[hour]:[minute]:[second]").unwrap();
ui.label(
result
.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.style_mut().override_text_style = Some(egui::TextStyle::Monospace);
ui.style_mut().wrap = Some(false);
ui.label("");
ui.label("Diff base:");
});
},
);
},
);
ui.separator();
});
});
});
});
strip.cell(|ui| {
// Table
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)
.striped(false)
.cell_layout(egui::Layout::left_to_right(egui::Align::Min))
.column(Size::relative(0.5))
.column(Size::relative(0.5))
.resizable(false);
data_table_ui(
table,
left_obj,
right_obj,
selected_symbol,
&view_state.view_config,
);
.cell_layout(Layout::left_to_right(Align::Min))
.columns(Column::exact(column_width).clip(true), 2)
.resizable(false)
.auto_shrink([false, false])
.min_scrolled_height(available_height);
data_table_ui(table, left_obj, right_obj, selected_symbol, &view_state.view_config);
}
});
});
rebuild
}

View File

@ -1,8 +1,9 @@
use std::default::Default;
use cwdemangle::demangle;
use egui::{text::LayoutJob, Color32, FontId, Label, Sense};
use egui_extras::{Size, StripBuilder, TableBuilder};
use eframe::emath::Align;
use egui::{text::LayoutJob, Color32, FontId, Label, Layout, Sense, Vec2};
use egui_extras::{Column, TableBuilder};
use ppc750cl::Argument;
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 {
return rebuild;
};
StripBuilder::new(ui)
.size(Size::exact(20.0))
.size(Size::exact(40.0))
.size(Size::remainder())
.vertical(|mut strip| {
strip.strip(|builder| {
builder.sizes(Size::remainder(), 2).horizontal(|mut strip| {
strip.cell(|ui| {
ui.horizontal(|ui| {
// Header
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);
if ui.button("Back").clicked() {
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| {
if ui.button("Build").clicked() {
rebuild = true;
}
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);
if view_state.jobs.iter().any(|job| job.job_type == Job::ObjDiff) {
ui.label("Building...");
} else {
ui.label("Last built:");
let format =
format_description::parse("[hour]:[minute]:[second]")
.unwrap();
format_description::parse("[hour]:[minute]:[second]").unwrap();
ui.label(
result
.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.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
.second_obj
.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),
&format!("{match_percent:.0}%"),
);
} else {
ui.label("");
}
ui.label("Diff base:");
});
},
);
},
);
ui.separator();
});
});
});
});
strip.cell(|ui| {
// Table
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)
.striped(false)
.cell_layout(egui::Layout::left_to_right(egui::Align::Min))
.column(Size::relative(0.5))
.column(Size::relative(0.5))
.resizable(false);
asm_table_ui(
table,
left_obj,
right_obj,
selected_symbol,
&view_state.view_config,
);
.cell_layout(Layout::left_to_right(Align::Min))
.columns(Column::exact(column_width).clip(true), 2)
.resizable(false)
.auto_shrink([false, false])
.min_scrolled_height(available_height);
asm_table_ui(table, left_obj, right_obj, selected_symbol, &view_state.view_config);
}
});
});
rebuild
}

View File

@ -9,5 +9,5 @@ pub(crate) mod symbol_diff;
const COLOR_RED: Color32 = Color32::from_rgb(200, 40, 41);
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::{
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};
@ -135,12 +136,9 @@ fn symbol_list_ui(
selected_symbol: &mut Option<SymbolReference>,
current_view: &mut View,
reverse_function_order: bool,
search: &mut String,
lower_search: &str,
config: &ViewConfig,
) {
ui.text_edit_singleline(search);
let lower_search = search.to_ascii_lowercase();
ScrollArea::both().auto_shrink([false, false]).show(ui, |ui| {
ui.scope(|ui| {
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) {
if let (Some(result), highlighted_symbol, selected_symbol, current_view, search) = (
let (Some(result), highlighted_symbol, selected_symbol, current_view, search) = (
&view_state.build,
&mut view_state.highlighted_symbol,
&mut view_state.selected_symbol,
&mut view_state.current_view,
&mut view_state.search,
) {
StripBuilder::new(ui).size(Size::exact(40.0)).size(Size::remainder()).vertical(
|mut strip| {
strip.strip(|builder| {
builder.sizes(Size::remainder(), 2).horizontal(|mut strip| {
strip.cell(|ui| {
) else {
return;
};
// Header
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.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.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.separator();
});
strip.cell(|ui| {
TextEdit::singleline(search).hint_text("Filter symbols").ui(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.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.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.separator();
});
});
});
// Table
let lower_search = search.to_ascii_lowercase();
StripBuilder::new(ui).size(Size::remainder()).vertical(|mut strip| {
strip.strip(|builder| {
builder.sizes(Size::remainder(), 2).horizontal(|mut strip| {
strip.cell(|ui| {
@ -271,7 +293,7 @@ pub fn symbol_diff_ui(ui: &mut Ui, view_state: &mut ViewState) {
selected_symbol,
current_view,
view_state.reverse_fn_order,
search,
&lower_search,
&view_state.view_config,
);
});
@ -291,7 +313,7 @@ pub fn symbol_diff_ui(ui: &mut Ui, view_state: &mut ViewState) {
selected_symbol,
current_view,
view_state.reverse_fn_order,
search,
&lower_search,
&view_state.view_config,
);
});
@ -302,7 +324,5 @@ pub fn symbol_diff_ui(ui: &mut Ui, view_state: &mut ViewState) {
});
});
});
},
);
}
});
}