From dffab1c737710ea74b4df40c3f4163865882aa99 Mon Sep 17 00:00:00 2001 From: Zachary Kohnen Date: Wed, 6 Apr 2022 18:47:46 +0200 Subject: [PATCH] Add Shape::galley_with_color (#1461) --- egui/src/painter.rs | 7 ++----- epaint/CHANGELOG.md | 1 + epaint/src/shape.rs | 14 ++++++++++++++ 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/egui/src/painter.rs b/egui/src/painter.rs index a3159081..5605ddf2 100644 --- a/egui/src/painter.rs +++ b/egui/src/painter.rs @@ -6,7 +6,7 @@ use crate::{ use epaint::{ mutex::{Arc, RwLockReadGuard, RwLockWriteGuard}, text::{Fonts, Galley}, - CircleShape, RectShape, Rounding, Shape, Stroke, TextShape, + CircleShape, RectShape, Rounding, Shape, Stroke, }; /// Helper to paint shapes and text to a specific region on a specific layer. @@ -403,10 +403,7 @@ impl Painter { #[inline(always)] pub fn galley_with_color(&self, pos: Pos2, galley: Arc, text_color: Color32) { if !galley.is_empty() { - self.add(TextShape { - override_text_color: Some(text_color), - ..TextShape::new(pos, galley) - }); + self.add(Shape::galley_with_color(pos, galley, text_color)); } } } diff --git a/epaint/CHANGELOG.md b/epaint/CHANGELOG.md index 56fd4b7b..94f1c8ca 100644 --- a/epaint/CHANGELOG.md +++ b/epaint/CHANGELOG.md @@ -17,6 +17,7 @@ All notable changes to the epaint crate will be documented in this file. * Renamed `AlphaImage` to `FontImage` to discourage any other use for it ([#1412](https://github.com/emilk/egui/pull/1412)). * Dark text is darker and more readable on bright backgrounds ([#1412](https://github.com/emilk/egui/pull/1412)). * Fix panic when tessellating a [`Shape::Vec`] containing meshes with differing `TextureId`:s ([#1445](https://github.com/emilk/egui/pull/1445)). +* Added `Shape::galley_with_color` which adds the functionality of `Painter::galley_with_color` into the Shape enum. ([#1461](https://github.com/emilk/egui/pull/1461)) ## 0.17.0 - 2022-02-22 diff --git a/epaint/src/shape.rs b/epaint/src/shape.rs index 4fbd8457..46d6f104 100644 --- a/epaint/src/shape.rs +++ b/epaint/src/shape.rs @@ -179,6 +179,20 @@ impl Shape { TextShape::new(pos, galley).into() } + #[inline] + /// The text color in the [`Galley`] will be replaced with the given color. + pub fn galley_with_color( + pos: Pos2, + galley: crate::mutex::Arc, + text_color: Color32, + ) -> Self { + TextShape { + override_text_color: Some(text_color), + ..TextShape::new(pos, galley) + } + .into() + } + pub fn mesh(mesh: Mesh) -> Self { crate::epaint_assert!(mesh.is_valid()); Self::Mesh(mesh)