@@ -59,7 +59,7 @@ use super::{TextEditOutput, TextEditState};
59
59
/// See [`TextEdit::show`].
60
60
///
61
61
/// ## Other
62
- /// The background color of a [`crate::TextEdit`] is [`crate::Visuals::extreme_bg_color`].
62
+ /// The background color of a [`crate::TextEdit`] is [`crate::Visuals::extreme_bg_color`] or can be set with [`crate::TextEdit::background_color`] .
63
63
#[ must_use = "You should put this widget in a ui with `ui.add(widget);`" ]
64
64
pub struct TextEdit < ' t > {
65
65
text : & ' t mut dyn TextBuffer ,
@@ -84,6 +84,7 @@ pub struct TextEdit<'t> {
84
84
clip_text : bool ,
85
85
char_limit : usize ,
86
86
return_key : Option < KeyboardShortcut > ,
87
+ background_color : Option < Color32 > ,
87
88
}
88
89
89
90
impl < ' t > WidgetWithState for TextEdit < ' t > {
@@ -142,6 +143,7 @@ impl<'t> TextEdit<'t> {
142
143
clip_text : false ,
143
144
char_limit : usize:: MAX ,
144
145
return_key : Some ( KeyboardShortcut :: new ( Modifiers :: NONE , Key :: Enter ) ) ,
146
+ background_color : None ,
145
147
}
146
148
}
147
149
@@ -201,6 +203,14 @@ impl<'t> TextEdit<'t> {
201
203
self
202
204
}
203
205
206
+ /// Set the background color of the [`TextEdit`]. The default is [`crate::Visuals::extreme_bg_color`].
207
+ // TODO(bircni): remove this once #3284 is implemented
208
+ #[ inline]
209
+ pub fn background_color ( mut self , color : Color32 ) -> Self {
210
+ self . background_color = Some ( color) ;
211
+ self
212
+ }
213
+
204
214
/// Set a specific style for the hint text.
205
215
#[ inline]
206
216
pub fn hint_text_font ( mut self , hint_text_font : impl Into < FontSelection > ) -> Self {
@@ -409,7 +419,9 @@ impl<'t> TextEdit<'t> {
409
419
let is_mutable = self . text . is_mutable ( ) ;
410
420
let frame = self . frame ;
411
421
let where_to_put_background = ui. painter ( ) . add ( Shape :: Noop ) ;
412
-
422
+ let background_color = self
423
+ . background_color
424
+ . unwrap_or ( ui. visuals ( ) . extreme_bg_color ) ;
413
425
let margin = self . margin ;
414
426
let mut output = self . show_content ( ui) ;
415
427
@@ -427,14 +439,14 @@ impl<'t> TextEdit<'t> {
427
439
epaint:: RectShape :: new (
428
440
frame_rect,
429
441
visuals. rounding ,
430
- ui . visuals ( ) . extreme_bg_color ,
442
+ background_color ,
431
443
ui. visuals ( ) . selection . stroke ,
432
444
)
433
445
} else {
434
446
epaint:: RectShape :: new (
435
447
frame_rect,
436
448
visuals. rounding ,
437
- ui . visuals ( ) . extreme_bg_color ,
449
+ background_color ,
438
450
visuals. bg_stroke , // TODO(emilk): we want to show something here, or a text-edit field doesn't "pop".
439
451
)
440
452
}
@@ -477,6 +489,7 @@ impl<'t> TextEdit<'t> {
477
489
clip_text,
478
490
char_limit,
479
491
return_key,
492
+ background_color : _,
480
493
} = self ;
481
494
482
495
let text_color = text_color
0 commit comments