Skip to content

Commit 813c8aa

Browse files
committed
Add "Diff fill color" option to Appearance
Allows configuring the background color of lines with a diff. Resolves encounter#230
1 parent 0f0aaab commit 813c8aa

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

objdiff-gui/src/views/appearance.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ pub struct Appearance {
1111
pub ui_font: FontId,
1212
pub code_font: FontId,
1313
pub diff_colors: Vec<Color32>,
14+
pub diff_bg_color: Option<Color32>,
1415
pub theme: egui::Theme,
1516

1617
// Applied by theme
@@ -67,6 +68,7 @@ impl Default for Appearance {
6768
replace_color: Color32::LIGHT_BLUE,
6869
insert_color: Color32::GREEN,
6970
delete_color: Color32::from_rgb(200, 40, 41),
71+
diff_bg_color: None,
7072
utc_offset: UtcOffset::UTC,
7173
fonts: FontState::default(),
7274
next_ui_font: None,
@@ -103,6 +105,9 @@ impl Appearance {
103105
match self.theme {
104106
egui::Theme::Dark => {
105107
style.visuals = egui::Visuals::dark();
108+
if let Some(diff_bg_color) = self.diff_bg_color {
109+
style.visuals.faint_bg_color = diff_bg_color;
110+
}
106111
self.text_color = Color32::GRAY;
107112
self.emphasized_text_color = Color32::LIGHT_GRAY;
108113
self.deemphasized_text_color = Color32::DARK_GRAY;
@@ -114,6 +119,9 @@ impl Appearance {
114119
}
115120
egui::Theme::Light => {
116121
style.visuals = egui::Visuals::light();
122+
if let Some(diff_bg_color) = self.diff_bg_color {
123+
style.visuals.faint_bg_color = diff_bg_color;
124+
}
117125
self.text_color = Color32::GRAY;
118126
self.emphasized_text_color = Color32::DARK_GRAY;
119127
self.deemphasized_text_color = Color32::LIGHT_GRAY;
@@ -294,6 +302,21 @@ pub fn appearance_window(ctx: &egui::Context, show: &mut bool, appearance: &mut
294302
appearance,
295303
);
296304
ui.separator();
305+
ui.horizontal(|ui| {
306+
ui.label("Diff fill color:");
307+
let mut diff_bg_color =
308+
appearance.diff_bg_color.unwrap_or_else(|| match appearance.theme {
309+
egui::Theme::Dark => egui::Visuals::dark().faint_bg_color,
310+
egui::Theme::Light => egui::Visuals::light().faint_bg_color,
311+
});
312+
if ui.color_edit_button_srgba(&mut diff_bg_color).changed() {
313+
appearance.diff_bg_color = Some(diff_bg_color);
314+
}
315+
if ui.button("Reset").clicked() {
316+
appearance.diff_bg_color = None;
317+
}
318+
});
319+
ui.separator();
297320
ui.label("Diff colors:");
298321
if ui.button("Reset").clicked() {
299322
appearance.diff_colors = DEFAULT_COLOR_ROTATION.to_vec();

0 commit comments

Comments
 (0)