@@ -54,6 +54,11 @@ impl RichText {
54
54
}
55
55
}
56
56
57
+ #[ inline]
58
+ pub fn is_empty ( & self ) -> bool {
59
+ self . text . is_empty ( )
60
+ }
61
+
57
62
#[ inline]
58
63
pub fn text ( & self ) -> & str {
59
64
& self . text
@@ -285,6 +290,15 @@ impl Default for WidgetText {
285
290
}
286
291
287
292
impl WidgetText {
293
+ #[ inline]
294
+ pub fn is_empty ( & self ) -> bool {
295
+ match self {
296
+ Self :: RichText ( text) => text. is_empty ( ) ,
297
+ Self :: LayoutJob ( job) => job. is_empty ( ) ,
298
+ Self :: Galley ( galley) => galley. is_empty ( ) ,
299
+ }
300
+ }
301
+
288
302
#[ inline]
289
303
pub fn text ( & self ) -> & str {
290
304
match self {
@@ -583,15 +597,39 @@ impl WidgetTextGalley {
583
597
& self . galley
584
598
}
585
599
586
- pub fn paint ( self , painter : & crate :: Painter , text_pos : Pos2 , visuals : & WidgetVisuals ) {
600
+ /// Use the colors in the original [`WidgetText`] if any,
601
+ /// else fall back to the one specified by the [`WidgetVisuals`].
602
+ pub fn paint_with_visuals (
603
+ self ,
604
+ painter : & crate :: Painter ,
605
+ text_pos : Pos2 ,
606
+ visuals : & WidgetVisuals ,
607
+ ) {
608
+ self . paint_with_fallback_color ( painter, text_pos, visuals. text_color ( ) ) ;
609
+ }
610
+
611
+ /// Use the colors in the original [`WidgetText`] if any,
612
+ /// else fall back to the given color.
613
+ pub fn paint_with_fallback_color (
614
+ self ,
615
+ painter : & crate :: Painter ,
616
+ text_pos : Pos2 ,
617
+ text_color : Color32 ,
618
+ ) {
587
619
if self . galley_has_color {
588
620
painter. galley ( text_pos, self . galley ) ;
589
621
} else {
590
- painter. galley_with_color ( text_pos, self . galley , visuals . text_color ( ) ) ;
622
+ painter. galley_with_color ( text_pos, self . galley , text_color) ;
591
623
}
592
624
}
593
625
594
- pub fn paint_with_color ( self , painter : & crate :: Painter , text_pos : Pos2 , text_color : Color32 ) {
626
+ /// Paint with this specific color.
627
+ pub fn paint_with_color_override (
628
+ self ,
629
+ painter : & crate :: Painter ,
630
+ text_pos : Pos2 ,
631
+ text_color : Color32 ,
632
+ ) {
595
633
painter. galley_with_color ( text_pos, self . galley , text_color) ;
596
634
}
597
635
}
0 commit comments