Add .id method and text_editor::focus task
This commit is contained in:
parent
41d930bd00
commit
0024fc0eb1
2 changed files with 17 additions and 4 deletions
|
|
@ -104,6 +104,7 @@ pub struct TextEditor<
|
|||
Theme: Catalog,
|
||||
Renderer: text::Renderer,
|
||||
{
|
||||
id: Option<widget::Id>,
|
||||
content: &'a Content<Renderer>,
|
||||
placeholder: Option<text::Fragment<'a>>,
|
||||
font: Option<Renderer::Font>,
|
||||
|
|
@ -135,6 +136,7 @@ where
|
|||
/// Creates new [`TextEditor`] with the given [`Content`].
|
||||
pub fn new(content: &'a Content<Renderer>) -> Self {
|
||||
Self {
|
||||
id: None,
|
||||
content,
|
||||
placeholder: None,
|
||||
font: None,
|
||||
|
|
@ -156,6 +158,12 @@ where
|
|||
last_status: None,
|
||||
}
|
||||
}
|
||||
|
||||
/// Sets the [`Id`](widget::Id) of the [`TextEditor`].
|
||||
pub fn id(mut self, id: impl Into<widget::Id>) -> Self {
|
||||
self.id = Some(id.into());
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, Highlighter, Message, Theme, Renderer>
|
||||
|
|
@ -275,6 +283,7 @@ where
|
|||
) -> highlighter::Format<Renderer::Font>,
|
||||
) -> TextEditor<'a, H, Message, Theme, Renderer> {
|
||||
TextEditor {
|
||||
id: self.id,
|
||||
content: self.content,
|
||||
placeholder: self.placeholder,
|
||||
font: self.font,
|
||||
|
|
@ -1057,7 +1066,7 @@ where
|
|||
) {
|
||||
let state = tree.state.downcast_mut::<State<Highlighter>>();
|
||||
|
||||
operation.focusable(None, layout.bounds(), state);
|
||||
operation.focusable(self.id.as_ref(), layout.bounds(), state);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue