Skip to content

Commit 9ab2463

Browse files
authored
Add buttons to collapse or expand all sections in the symbol list view for an object simultaneously (#149)
* Add buttons to expand/collapse all sections to symbol list view * Add buttons to expand/collapse all sections to the split view
1 parent dcafe51 commit 9ab2463

File tree

2 files changed

+84
-24
lines changed

2 files changed

+84
-24
lines changed

objdiff-gui/src/views/function_diff.rs

Lines changed: 43 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::{cmp::Ordering, default::Default};
22

3-
use egui::{text::LayoutJob, Id, Label, Response, RichText, Sense, Widget};
3+
use egui::{text::LayoutJob, Id, Label, Layout, Response, RichText, Sense, Widget};
44
use egui_extras::TableRow;
55
use objdiff_core::{
66
diff::{
@@ -414,6 +414,7 @@ fn asm_col_ui(
414414
}
415415

416416
#[must_use]
417+
#[expect(clippy::too_many_arguments)]
417418
fn asm_table_ui(
418419
ui: &mut egui::Ui,
419420
available_width: f32,
@@ -422,6 +423,7 @@ fn asm_table_ui(
422423
appearance: &Appearance,
423424
ins_view_state: &FunctionViewState,
424425
symbol_state: &SymbolViewState,
426+
open_sections: (Option<bool>, Option<bool>),
425427
) -> Option<DiffViewAction> {
426428
let mut ret = None;
427429
let left_len = left_ctx.and_then(|ctx| {
@@ -512,6 +514,7 @@ fn asm_table_ui(
512514
SymbolFilter::Mapping(right_symbol_ref),
513515
appearance,
514516
column,
517+
open_sections.0,
515518
) {
516519
match action {
517520
DiffViewAction::Navigate(DiffViewNavigation {
@@ -570,6 +573,7 @@ fn asm_table_ui(
570573
SymbolFilter::Mapping(left_symbol_ref),
571574
appearance,
572575
column,
576+
open_sections.1,
573577
) {
574578
match action {
575579
DiffViewAction::Navigate(DiffViewNavigation {
@@ -683,6 +687,7 @@ pub fn function_diff_ui(
683687

684688
// Header
685689
let available_width = ui.available_width();
690+
let mut open_sections = (None, None);
686691
render_header(ui, available_width, 2, |ui, column| {
687692
if column == 0 {
688693
// Left column
@@ -736,11 +741,24 @@ pub fn function_diff_ui(
736741
.font(appearance.code_font.clone())
737742
.color(appearance.replace_color),
738743
);
739-
ui.label(
740-
RichText::new("Choose target symbol")
741-
.font(appearance.code_font.clone())
742-
.color(appearance.highlight_color),
743-
);
744+
745+
ui.horizontal(|ui| {
746+
ui.label(
747+
RichText::new("Choose target symbol")
748+
.font(appearance.code_font.clone())
749+
.color(appearance.highlight_color),
750+
);
751+
752+
ui.with_layout(Layout::right_to_left(egui::Align::TOP), |ui| {
753+
if ui.small_button("⏷").on_hover_text_at_pointer("Expand all").clicked() {
754+
open_sections.0 = Some(true);
755+
}
756+
if ui.small_button("⏶").on_hover_text_at_pointer("Collapse all").clicked()
757+
{
758+
open_sections.0 = Some(false);
759+
}
760+
})
761+
});
744762
}
745763
} else if column == 1 {
746764
// Right column
@@ -812,11 +830,24 @@ pub fn function_diff_ui(
812830
.font(appearance.code_font.clone())
813831
.color(appearance.replace_color),
814832
);
815-
ui.label(
816-
RichText::new("Choose base symbol")
817-
.font(appearance.code_font.clone())
818-
.color(appearance.highlight_color),
819-
);
833+
834+
ui.horizontal(|ui| {
835+
ui.label(
836+
RichText::new("Choose base symbol")
837+
.font(appearance.code_font.clone())
838+
.color(appearance.highlight_color),
839+
);
840+
841+
ui.with_layout(Layout::right_to_left(egui::Align::TOP), |ui| {
842+
if ui.small_button("⏷").on_hover_text_at_pointer("Expand all").clicked() {
843+
open_sections.1 = Some(true);
844+
}
845+
if ui.small_button("⏶").on_hover_text_at_pointer("Collapse all").clicked()
846+
{
847+
open_sections.1 = Some(false);
848+
}
849+
})
850+
});
820851
}
821852
}
822853
});
@@ -834,6 +865,7 @@ pub fn function_diff_ui(
834865
appearance,
835866
&state.function_state,
836867
&state.symbol_state,
868+
open_sections,
837869
)
838870
})
839871
.inner

objdiff-gui/src/views/symbol_diff.rs

Lines changed: 41 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use std::{collections::BTreeMap, mem::take, ops::Bound};
22

33
use egui::{
4-
style::ScrollAnimation, text::LayoutJob, CollapsingHeader, Color32, Id, OpenUrl, ScrollArea,
5-
SelectableLabel, TextEdit, Ui, Widget,
4+
style::ScrollAnimation, text::LayoutJob, CollapsingHeader, Color32, Id, Layout, OpenUrl,
5+
ScrollArea, SelectableLabel, TextEdit, Ui, Widget,
66
};
77
use objdiff_core::{
88
arch::ObjArch,
@@ -605,6 +605,7 @@ pub enum SymbolFilter<'a> {
605605
}
606606

607607
#[must_use]
608+
#[expect(clippy::too_many_arguments)]
608609
pub fn symbol_list_ui(
609610
ui: &mut Ui,
610611
ctx: SymbolDiffContext<'_>,
@@ -613,6 +614,7 @@ pub fn symbol_list_ui(
613614
filter: SymbolFilter<'_>,
614615
appearance: &Appearance,
615616
column: usize,
617+
open_sections: Option<bool>,
616618
) -> Option<DiffViewAction> {
617619
let mut ret = None;
618620
ScrollArea::both().auto_shrink([false, false]).show(ui, |ui| {
@@ -766,6 +768,7 @@ pub fn symbol_list_ui(
766768
CollapsingHeader::new(header)
767769
.id_salt(Id::new(section.name.clone()).with(section.orig_index))
768770
.default_open(true)
771+
.open(open_sections)
769772
.show(ui, |ui| {
770773
if section.kind == ObjSectionKind::Code && state.reverse_fn_order {
771774
for (symbol, symbol_diff) in mapping
@@ -873,6 +876,7 @@ pub fn symbol_diff_ui(
873876

874877
// Header
875878
let available_width = ui.available_width();
879+
let mut open_sections = (None, None);
876880
render_header(ui, available_width, 2, |ui, column| {
877881
if column == 0 {
878882
// Left column
@@ -891,14 +895,25 @@ pub fn symbol_diff_ui(
891895
}
892896
});
893897

894-
let mut search = state.search.clone();
895-
let response = TextEdit::singleline(&mut search).hint_text("Filter symbols").ui(ui);
896-
if hotkeys::consume_symbol_filter_shortcut(ui.ctx()) {
897-
response.request_focus();
898-
}
899-
if response.changed() {
900-
ret = Some(DiffViewAction::SetSearch(search));
901-
}
898+
ui.horizontal(|ui| {
899+
let mut search = state.search.clone();
900+
let response = TextEdit::singleline(&mut search).hint_text("Filter symbols").ui(ui);
901+
if hotkeys::consume_symbol_filter_shortcut(ui.ctx()) {
902+
response.request_focus();
903+
}
904+
if response.changed() {
905+
ret = Some(DiffViewAction::SetSearch(search));
906+
}
907+
908+
ui.with_layout(Layout::right_to_left(egui::Align::TOP), |ui| {
909+
if ui.small_button("⏷").on_hover_text_at_pointer("Expand all").clicked() {
910+
open_sections.0 = Some(true);
911+
}
912+
if ui.small_button("⏶").on_hover_text_at_pointer("Collapse all").clicked() {
913+
open_sections.0 = Some(false);
914+
}
915+
})
916+
});
902917
} else if column == 1 {
903918
// Right column
904919
ui.horizontal(|ui| {
@@ -930,9 +945,20 @@ pub fn symbol_diff_ui(
930945
}
931946
});
932947

933-
if ui.add_enabled(!state.build_running, egui::Button::new("Build")).clicked() {
934-
ret = Some(DiffViewAction::Build);
935-
}
948+
ui.horizontal(|ui| {
949+
if ui.add_enabled(!state.build_running, egui::Button::new("Build")).clicked() {
950+
ret = Some(DiffViewAction::Build);
951+
}
952+
953+
ui.with_layout(Layout::right_to_left(egui::Align::TOP), |ui| {
954+
if ui.small_button("⏷").on_hover_text_at_pointer("Expand all").clicked() {
955+
open_sections.1 = Some(true);
956+
}
957+
if ui.small_button("⏶").on_hover_text_at_pointer("Collapse all").clicked() {
958+
open_sections.1 = Some(false);
959+
}
960+
})
961+
});
936962
}
937963
});
938964

@@ -957,6 +983,7 @@ pub fn symbol_diff_ui(
957983
filter,
958984
appearance,
959985
column,
986+
open_sections.0,
960987
) {
961988
ret = Some(result);
962989
}
@@ -981,6 +1008,7 @@ pub fn symbol_diff_ui(
9811008
filter,
9821009
appearance,
9831010
column,
1011+
open_sections.1,
9841012
) {
9851013
ret = Some(result);
9861014
}

0 commit comments

Comments
 (0)