egui/crates/epaint/src
GiGaGon 668abc2838
Add `expand_bg` to customize size of text background (#5365)
This removes the `expand(1.0)` on text background colors, since it makes
translucent background colors have bad looking bleeding.

There is probably a smarter solution than disabling the highlighting
entirely, but I don't see a way to do that while keeping the area
consumed consistent between translucent/solid colors, or adding a decent
step up in complexity.

Since this makes it impossible to tell if selected text is highlighted,
this also adds a blanket `0.5` gamma multiply to the text selection
background color. If that is undesirable because it's a bad arbitrary
number choice, or if it's too much of an unexpected change and just the
default values should be changed, please let me know.

These changes cause the tests that use screenshots with highlighted text
to fail, though I am not sure how to update those tests to match the
changes.

<details>
<summary>Comparison Images</summary>

Current:


![image](https://github.com/user-attachments/assets/6dc85492-4f8e-4e7a-84b4-3ee10a48b8b3)

After changes:


![image](https://github.com/user-attachments/assets/9b35bbd3-159d-42a9-b22f-80febb707cfa)
 

</details>

<details>
<summary>Code used to make comparison images</summary>

```rs
fn color_text_format(ui: &Ui, color: Color32) -> TextFormat {
    TextFormat { font_id: FontId::monospace(ui.text_style_height(&egui::TextStyle::Monospace)), background: color, ..Default::default() }
}

fn color_sequence_galley(ui: &Ui, text: &str, colors: [Color32; 3]) -> Arc<Galley> {
    let mut layout_job = LayoutJob::default();
    for color in colors {
        layout_job.append(text, 0.0, color_text_format(ui, color));
    }
    ui.fonts(|f| f.layout_job(layout_job))
}

fn color_sequence_row(ui: &mut Ui, label_text: &str, text: &str, colors: [Color32; 3]) {
    ui.label(label_text);
    ui.label(color_sequence_galley(ui, text, colors));
    ui.end_row();
}

egui::Grid::new("comparison display").show(ui, |ui| {
    ui.ctx().set_pixels_per_point(2.0);
    let transparent = Color32::TRANSPARENT;
    let solid = Color32::RED;
    let solid_2 = Color32::GREEN;
    let translucent_1 = Color32::GRAY.gamma_multiply(0.5);
    let translucent_2 = Color32::GREEN.gamma_multiply(0.5);
    color_sequence_row(ui, "Transparent to Solid:", " ", [transparent, solid, transparent]);
    color_sequence_row(ui, "Translucent to Transparent:", " ", [transparent, translucent_1, transparent]);
    color_sequence_row(ui, "Solid to Transparent:", " ", [solid, solid_2, solid]);
    color_sequence_row(ui, "Solid to Solid:", " ", [solid, transparent, solid]);
    color_sequence_row(ui, "Solid to Translucent:", " ", [solid, translucent_1, solid]);
    color_sequence_row(ui, "Translucent to Translucent:", " ", [translucent_1, translucent_2, translucent_1]);
    
    color_sequence_row(ui, "Transparent to Solid:", "a", [transparent, solid, transparent]);
    color_sequence_row(ui, "Translucent to Transparent:", "a", [transparent, translucent_1, transparent]);
    color_sequence_row(ui, "Solid to Transparent:", "a", [solid, solid_2, solid]);
    color_sequence_row(ui, "Solid to Solid:", "a", [solid, transparent, solid]);
    color_sequence_row(ui, "Solid to Translucent:", "a", [solid, translucent_1, solid]);
    color_sequence_row(ui, "Translucent to Translucent:", "a", [translucent_1, translucent_2, translucent_1]);
})
```
</details>

* [x] I have followed the instructions in the PR template

---------

Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
2025-03-21 13:45:34 +01:00
..
shapes ⚠️ Rename `Rounding` to `CornerRadius` (#5673) 2025-02-04 12:53:18 +01:00
text Add `expand_bg` to customize size of text background (#5365) 2025-03-21 13:45:34 +01:00
util Add `emath::OrderedFloat` (moved from `epaint::util::OrderedFloat`) (#4389) 2024-04-21 20:36:32 +02:00
brush.rs Add `epaint::Brush` for controlling `RectShape` texturing (#5565) 2025-01-02 15:34:28 +01:00
color.rs Added ability to define colors at UV coordinates along a path (#4353) 2024-04-22 18:35:09 +02:00
corner_radius.rs ⚠️ Rename `Rounding` to `CornerRadius` (#5673) 2025-02-04 12:53:18 +01:00
corner_radius_f32.rs ⚠️ Rename `Rounding` to `CornerRadius` (#5673) 2025-02-04 12:53:18 +01:00
image.rs Improve text sharpness (#5838) 2025-03-21 12:56:47 +01:00
lib.rs Rename `Marginf` to `MarginF32` for consistency with `CornerRadiusF32` (#5677) 2025-02-11 11:23:59 +01:00
margin.rs Rename `Marginf` to `MarginF32` for consistency with `CornerRadiusF32` (#5677) 2025-02-11 11:23:59 +01:00
margin_f32.rs Rename `Marginf` to `MarginF32` for consistency with `CornerRadiusF32` (#5677) 2025-02-11 11:23:59 +01:00
mesh.rs Improve tessellation quality (#5669) 2025-02-04 11:30:12 +01:00
mutex.rs Fix some clippy issues found by 1.84.0 (#5603) 2025-01-13 08:29:13 +01:00
shadow.rs Rename `Marginf` to `MarginF32` for consistency with `CornerRadiusF32` (#5677) 2025-02-11 11:23:59 +01:00
shape_transform.rs ⚠️ Rename `Rounding` to `CornerRadius` (#5673) 2025-02-04 12:53:18 +01:00
stats.rs Remove wildcard imports (#5018) 2024-08-28 12:18:42 +02:00
stroke.rs Improve tessellation quality (#5669) 2025-02-04 11:30:12 +01:00
tessellator.rs Fix panic when rendering thin textured rectangles (#5692) 2025-02-06 21:37:32 +01:00
texture_atlas.rs Expand max font atlas size from 8k to 16k (#5257) 2024-10-29 10:42:28 +01:00
texture_handle.rs Update MSRV to 1.80 (#5457) 2024-12-10 16:09:03 +01:00
textures.rs Add support for mipmap textures. (#5146) 2024-09-22 19:16:16 +02:00
viewport.rs Refactor: put each shape into its own file (#5564) 2025-01-02 14:55:49 +01:00