|
1 | 1 | use crate::{
|
2 | 2 | emath::{Align2, Pos2, Rect, Vec2},
|
3 | 3 | layers::{LayerId, PaintList, ShapeIdx},
|
4 |
| - Color32, CtxRef, |
| 4 | + Color32, CtxRef, WidgetText, |
5 | 5 | };
|
6 | 6 | use epaint::{
|
7 | 7 | mutex::Mutex,
|
@@ -195,41 +195,34 @@ impl Painter {
|
195 | 195 |
|
196 | 196 | /// ## Debug painting
|
197 | 197 | impl Painter {
|
198 |
| - #[allow(clippy::needless_pass_by_value)] |
199 |
| - pub fn debug_rect(&mut self, rect: Rect, color: Color32, text: impl ToString) { |
| 198 | + pub fn debug_rect(&mut self, rect: Rect, color: Color32, text: impl Into<WidgetText>) { |
200 | 199 | self.rect_stroke(rect, 0.0, (1.0, color));
|
201 | 200 | let text_style = TextStyle::Monospace;
|
202 |
| - self.text( |
203 |
| - rect.min, |
204 |
| - Align2::LEFT_TOP, |
205 |
| - text.to_string(), |
206 |
| - text_style, |
207 |
| - color, |
208 |
| - ); |
| 201 | + self.text(rect.min, Align2::LEFT_TOP, text, text_style, color); |
209 | 202 | }
|
210 | 203 |
|
211 | 204 | pub fn error(&self, pos: Pos2, text: impl std::fmt::Display) -> Rect {
|
212 | 205 | self.debug_text(pos, Align2::LEFT_TOP, Color32::RED, format!("🔥 {}", text))
|
213 | 206 | }
|
214 | 207 |
|
215 | 208 | /// text with a background
|
216 |
| - #[allow(clippy::needless_pass_by_value)] |
217 | 209 | pub fn debug_text(
|
218 | 210 | &self,
|
219 | 211 | pos: Pos2,
|
220 | 212 | anchor: Align2,
|
221 | 213 | color: Color32,
|
222 |
| - text: impl ToString, |
| 214 | + text: impl Into<WidgetText>, |
223 | 215 | ) -> Rect {
|
224 |
| - let galley = self.layout_no_wrap(text.to_string(), TextStyle::Monospace, color); |
225 |
| - let rect = anchor.anchor_rect(Rect::from_min_size(pos, galley.size())); |
| 216 | + let text = text.into(); |
| 217 | + let text_galley = text.into_galley_raw(self.ctx(), f32::INFINITY, TextStyle::Monospace); |
| 218 | + let rect = anchor.anchor_rect(Rect::from_min_size(pos, text_galley.size())); |
226 | 219 | let frame_rect = rect.expand(2.0);
|
227 | 220 | self.add(Shape::rect_filled(
|
228 | 221 | frame_rect,
|
229 | 222 | 0.0,
|
230 | 223 | Color32::from_black_alpha(240),
|
231 | 224 | ));
|
232 |
| - self.galley(rect.min, galley); |
| 225 | + text_galley.paint_with_fallback_color(self, rect.min, color); |
233 | 226 | frame_rect
|
234 | 227 | }
|
235 | 228 | }
|
@@ -332,18 +325,18 @@ impl Painter {
|
332 | 325 | /// [`Self::layout`] or [`Self::layout_no_wrap`].
|
333 | 326 | ///
|
334 | 327 | /// Returns where the text ended up.
|
335 |
| - #[allow(clippy::needless_pass_by_value)] |
336 | 328 | pub fn text(
|
337 | 329 | &self,
|
338 | 330 | pos: Pos2,
|
339 | 331 | anchor: Align2,
|
340 |
| - text: impl ToString, |
| 332 | + text: impl Into<WidgetText>, |
341 | 333 | text_style: TextStyle,
|
342 | 334 | text_color: Color32,
|
343 | 335 | ) -> Rect {
|
344 |
| - let galley = self.layout_no_wrap(text.to_string(), text_style, text_color); |
345 |
| - let rect = anchor.anchor_rect(Rect::from_min_size(pos, galley.size())); |
346 |
| - self.galley(rect.min, galley); |
| 336 | + let text = text.into(); |
| 337 | + let text_galley = text.into_galley_raw(self.ctx(), f32::INFINITY, text_style); |
| 338 | + let rect = anchor.anchor_rect(Rect::from_min_size(pos, text_galley.size())); |
| 339 | + text_galley.paint_with_fallback_color(self, rect.min, text_color); |
347 | 340 | rect
|
348 | 341 | }
|
349 | 342 |
|
|
0 commit comments