From 644c124edf060b0d698e0e57808216325d286cd5 Mon Sep 17 00:00:00 2001 From: GiGaGon <107241144+MeGaGiGaGon@users.noreply.github.com> Date: Mon, 11 Nov 2024 22:29:09 -0800 Subject: [PATCH 1/6] Update text_layout.rs --- crates/epaint/src/text/text_layout.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/crates/epaint/src/text/text_layout.rs b/crates/epaint/src/text/text_layout.rs index 9db77f888af..a0f8d426d2d 100644 --- a/crates/epaint/src/text/text_layout.rs +++ b/crates/epaint/src/text/text_layout.rs @@ -756,7 +756,6 @@ fn add_row_backgrounds(job: &LayoutJob, row: &Row, mesh: &mut Mesh) { let mut end_run = |start: Option<(Color32, Rect)>, stop_x: f32| { if let Some((color, start_rect)) = start { let rect = Rect::from_min_max(start_rect.left_top(), pos2(stop_x, start_rect.bottom())); - let rect = rect.expand(1.0); // looks better mesh.add_colored_rect(rect, color); } }; From 1e12afc3229efdadf70dbf8af73a4e413ef0c9a5 Mon Sep 17 00:00:00 2001 From: GiGaGon <107241144+MeGaGiGaGon@users.noreply.github.com> Date: Mon, 11 Nov 2024 23:03:20 -0800 Subject: [PATCH 2/6] Update visuals.rs --- crates/egui/src/text_selection/visuals.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/egui/src/text_selection/visuals.rs b/crates/egui/src/text_selection/visuals.rs index d86f9dc56c2..106e2237dff 100644 --- a/crates/egui/src/text_selection/visuals.rs +++ b/crates/egui/src/text_selection/visuals.rs @@ -58,7 +58,7 @@ pub fn paint_text_selection( // Start by appending the selection rectangle to end of the mesh, as two triangles (= 6 indices): let num_indices_before = mesh.indices.len(); - mesh.add_colored_rect(rect, color); + mesh.add_colored_rect(rect, color.gamma_multiply(0.5)); assert_eq!(num_indices_before + 6, mesh.indices.len()); // Copy out the new triangles: From 67d78fa66cd1ad11a865a947520869f4dffb37f0 Mon Sep 17 00:00:00 2001 From: MeGaGiGaGon <107241144+megagigagon@users.noreply.github.com> Date: Tue, 12 Nov 2024 13:13:03 -0800 Subject: [PATCH 3/6] Add expand_bg and change select defaults --- crates/egui/src/style.rs | 4 ++-- crates/egui/src/text_selection/visuals.rs | 2 +- crates/egui/src/widget_text.rs | 3 +++ crates/epaint/src/text/text_layout.rs | 12 +++++++----- crates/epaint/src/text/text_layout_types.rs | 8 ++++++++ 5 files changed, 21 insertions(+), 8 deletions(-) diff --git a/crates/egui/src/style.rs b/crates/egui/src/style.rs index 0f6c9633ebd..41471a83e70 100644 --- a/crates/egui/src/style.rs +++ b/crates/egui/src/style.rs @@ -1387,14 +1387,14 @@ impl Default for Visuals { impl Selection { fn dark() -> Self { Self { - bg_fill: Color32::from_rgb(0, 92, 128), + bg_fill: Color32::from_rgb(0, 92, 128).gamma_multiply(0.75), stroke: Stroke::new(1.0, Color32::from_rgb(192, 222, 255)), } } fn light() -> Self { Self { - bg_fill: Color32::from_rgb(144, 209, 255), + bg_fill: Color32::from_rgb(144, 209, 255).gamma_multiply(0.75), stroke: Stroke::new(1.0, Color32::from_rgb(0, 83, 125)), } } diff --git a/crates/egui/src/text_selection/visuals.rs b/crates/egui/src/text_selection/visuals.rs index 106e2237dff..d86f9dc56c2 100644 --- a/crates/egui/src/text_selection/visuals.rs +++ b/crates/egui/src/text_selection/visuals.rs @@ -58,7 +58,7 @@ pub fn paint_text_selection( // Start by appending the selection rectangle to end of the mesh, as two triangles (= 6 indices): let num_indices_before = mesh.indices.len(); - mesh.add_colored_rect(rect, color.gamma_multiply(0.5)); + mesh.add_colored_rect(rect, color); assert_eq!(num_indices_before + 6, mesh.indices.len()); // Copy out the new triangles: diff --git a/crates/egui/src/widget_text.rs b/crates/egui/src/widget_text.rs index 011a4adcbb0..f0354cead15 100644 --- a/crates/egui/src/widget_text.rs +++ b/crates/egui/src/widget_text.rs @@ -29,6 +29,7 @@ pub struct RichText { family: Option, text_style: Option, background_color: Color32, + expand_bg: f32, text_color: Option, code: bool, strong: bool, @@ -360,6 +361,7 @@ impl RichText { family, text_style, background_color, + expand_bg, text_color: _, // already used by `get_text_color` code, strong: _, // already used by `get_text_color` @@ -425,6 +427,7 @@ impl RichText { underline, strikethrough, valign, + expand_bg, }, ) } diff --git a/crates/epaint/src/text/text_layout.rs b/crates/epaint/src/text/text_layout.rs index a0f8d426d2d..04d68efc964 100644 --- a/crates/epaint/src/text/text_layout.rs +++ b/crates/epaint/src/text/text_layout.rs @@ -753,9 +753,10 @@ fn add_row_backgrounds(job: &LayoutJob, row: &Row, mesh: &mut Mesh) { return; } - let mut end_run = |start: Option<(Color32, Rect)>, stop_x: f32| { - if let Some((color, start_rect)) = start { + let mut end_run = |start: Option<(Color32, Rect, f32)>, stop_x: f32| { + if let Some((color, start_rect, expand)) = start { let rect = Rect::from_min_max(start_rect.left_top(), pos2(stop_x, start_rect.bottom())); + let rect = rect.expand(expand); mesh.add_colored_rect(rect, color); } }; @@ -770,18 +771,19 @@ fn add_row_backgrounds(job: &LayoutJob, row: &Row, mesh: &mut Mesh) { if color == Color32::TRANSPARENT { end_run(run_start.take(), last_rect.right()); - } else if let Some((existing_color, start)) = run_start { + } else if let Some((existing_color, start, expand)) = run_start { if existing_color == color && start.top() == rect.top() && start.bottom() == rect.bottom() + && format.expand_bg == expand { // continue the same background rectangle } else { end_run(run_start.take(), last_rect.right()); - run_start = Some((color, rect)); + run_start = Some((color, rect, format.expand_bg)); } } else { - run_start = Some((color, rect)); + run_start = Some((color, rect, format.expand_bg)); } last_rect = rect; diff --git a/crates/epaint/src/text/text_layout_types.rs b/crates/epaint/src/text/text_layout_types.rs index 17826e6afb1..15a14eb84b9 100644 --- a/crates/epaint/src/text/text_layout_types.rs +++ b/crates/epaint/src/text/text_layout_types.rs @@ -271,6 +271,11 @@ pub struct TextFormat { pub background: Color32, + /// Amount to expand background fill by. + /// + /// Default: 1.0 + pub expand_bg: f32, + pub italics: bool, pub underline: Stroke, @@ -298,6 +303,7 @@ impl Default for TextFormat { line_height: None, color: Color32::GRAY, background: Color32::TRANSPARENT, + expand_bg: 1.0, italics: false, underline: Stroke::NONE, strikethrough: Stroke::NONE, @@ -315,6 +321,7 @@ impl std::hash::Hash for TextFormat { line_height, color, background, + expand_bg, italics, underline, strikethrough, @@ -327,6 +334,7 @@ impl std::hash::Hash for TextFormat { } color.hash(state); background.hash(state); + emath::OrderedFloat(*expand_bg).hash(state); italics.hash(state); underline.hash(state); strikethrough.hash(state); From 1ff763f9f7fe4fc3b4c2250effcaed8525e80fba Mon Sep 17 00:00:00 2001 From: GiGaGon <107241144+MeGaGiGaGon@users.noreply.github.com> Date: Tue, 12 Nov 2024 13:23:03 -0800 Subject: [PATCH 4/6] Fix formatting lint --- crates/epaint/src/text/text_layout_types.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/epaint/src/text/text_layout_types.rs b/crates/epaint/src/text/text_layout_types.rs index 15a14eb84b9..fa02a971f2e 100644 --- a/crates/epaint/src/text/text_layout_types.rs +++ b/crates/epaint/src/text/text_layout_types.rs @@ -272,7 +272,7 @@ pub struct TextFormat { pub background: Color32, /// Amount to expand background fill by. - /// + /// /// Default: 1.0 pub expand_bg: f32, From 959187b29280ebe9044ac2709cbd2bd494877def Mon Sep 17 00:00:00 2001 From: MeGaGiGaGon <107241144+megagigagon@users.noreply.github.com> Date: Tue, 12 Nov 2024 13:31:00 -0800 Subject: [PATCH 5/6] Fix RichText not getting the 1.0 default --- crates/egui/src/widget_text.rs | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/crates/egui/src/widget_text.rs b/crates/egui/src/widget_text.rs index f0354cead15..6aa6edcb4fb 100644 --- a/crates/egui/src/widget_text.rs +++ b/crates/egui/src/widget_text.rs @@ -20,7 +20,7 @@ use crate::{ /// RichText::new("colored").color(Color32::RED); /// RichText::new("Large and underlined").size(20.0).underline(); /// ``` -#[derive(Clone, Default, PartialEq)] +#[derive(Clone, PartialEq)] pub struct RichText { text: String, size: Option, @@ -40,6 +40,29 @@ pub struct RichText { raised: bool, } +impl Default for RichText { + fn default() -> Self { + Self { + text: Default::default(), + size: Default::default(), + extra_letter_spacing: Default::default(), + line_height: Default::default(), + family: Default::default(), + text_style: Default::default(), + background_color: Default::default(), + expand_bg: 1.0, + text_color: Default::default(), + code: Default::default(), + strong: Default::default(), + weak: Default::default(), + strikethrough: Default::default(), + underline: Default::default(), + italics: Default::default(), + raised: Default::default(), + } + } +} + impl From<&str> for RichText { #[inline] fn from(text: &str) -> Self { From d369786d417aec177996881b843c022fde55ef6e Mon Sep 17 00:00:00 2001 From: GiGaGon <107241144+MeGaGiGaGon@users.noreply.github.com> Date: Wed, 13 Nov 2024 13:18:20 -0800 Subject: [PATCH 6/6] Revert selection color changes --- crates/egui/src/style.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/egui/src/style.rs b/crates/egui/src/style.rs index 41471a83e70..0f6c9633ebd 100644 --- a/crates/egui/src/style.rs +++ b/crates/egui/src/style.rs @@ -1387,14 +1387,14 @@ impl Default for Visuals { impl Selection { fn dark() -> Self { Self { - bg_fill: Color32::from_rgb(0, 92, 128).gamma_multiply(0.75), + bg_fill: Color32::from_rgb(0, 92, 128), stroke: Stroke::new(1.0, Color32::from_rgb(192, 222, 255)), } } fn light() -> Self { Self { - bg_fill: Color32::from_rgb(144, 209, 255).gamma_multiply(0.75), + bg_fill: Color32::from_rgb(144, 209, 255), stroke: Stroke::new(1.0, Color32::from_rgb(0, 83, 125)), } }