@ -108,12 +108,6 @@ impl CCursorPair {
}
}
#[ derive(Clone, Copy, Debug, Default) ]
#[ cfg_attr(feature = " persistence " , derive(serde::Deserialize, serde::Serialize)) ]
pub struct CodingConfig {
pub tab_moves_focus : bool ,
}
/// A text region that the user can edit the contents of.
///
/// See also [`Ui::text_edit_singleline`] and [`Ui::text_edit_multiline`].
@ -146,7 +140,7 @@ pub struct TextEdit<'t> {
enabled : bool ,
desired_width : Option < f32 > ,
desired_height_rows : usize ,
tab_moves _focus : bool ,
lock _focus : bool ,
}
impl < 't > TextEdit < 't > {
pub fn cursor ( ui : & Ui , id : Id ) -> Option < CursorPair > {
@ -178,7 +172,7 @@ impl<'t> TextEdit<'t> {
enabled : true ,
desired_width : None ,
desired_height_rows : 1 ,
tab_moves _focus : true ,
lock _focus : true ,
}
}
@ -197,37 +191,19 @@ impl<'t> TextEdit<'t> {
enabled : true ,
desired_width : None ,
desired_height_rows : 4 ,
tab_moves _focus : true ,
lock _focus : true ,
}
}
/// When this is true, then pass focus to the next
/// widget.
pub fn tab_moves_focus ( mut self , b : bool ) -> Self {
self . tab_moves_focus = b ;
self
}
/// Build a `TextEdit` focused on code editing.
/// By default it comes with:
/// - monospaced font
/// - focus lock
pub fn code_editor ( self ) -> Self {
self . text_style ( TextStyle ::Monospace ) . tab_moves_focus ( false )
}
/// Build a `TextEdit` focused on code editing with configurable `Tab` management.
///
/// Shortcut for:
/// ```rust, ignore
/// egui::TextEdit::multiline(code_snippet)
/// .code_editor()
/// .tab_moves_focus(tab_moves_focus);
/// ```
pub fn code_editor_with_config ( self , config : CodingConfig ) -> Self {
self . code_editor ( ) . tab_moves_focus ( config . tab_moves_focus )
self . text_style ( TextStyle ::Monospace ) . lock_focus ( true )
}
/// Use if you want to set an explicit `Id` for this widget.
pub fn id ( mut self , id : Id ) -> Self {
self . id = Some ( id ) ;
self
@ -292,6 +268,16 @@ impl<'t> TextEdit<'t> {
self . desired_height_rows = desired_height_rows ;
self
}
/// When `false` (default), pressing TAB will move focus
/// to the next widget.
///
/// When `true`, the widget will keep the focus and pressing TAB
/// will insert the `'\t'` character.
pub fn lock_focus ( mut self , b : bool ) -> Self {
self . lock_focus = b ;
self
}
}
impl < 't > Widget for TextEdit < 't > {
@ -348,7 +334,7 @@ impl<'t> TextEdit<'t> {
enabled ,
desired_width ,
desired_height_rows ,
tab_moves _focus,
lock _focus,
} = self ;
let text_style = text_style . unwrap_or_else ( | | ui . style ( ) . body_text_style ) ;
@ -454,7 +440,7 @@ impl<'t> TextEdit<'t> {
let mut text_cursor = None ;
if ui . memory ( ) . has_focus ( id ) & & enabled {
ui . memory ( ) . lock_focus ( id , ! tab_moves _focus) ;
ui . memory ( ) . lock_focus ( id , lock _focus) ;
let mut cursorp = state
. cursorp