pub struct CompletionPopup<'a> { /* private fields */ }egui only.Expand description
A code completion popup over a TextEdit.
Shows a list of suggestions for the word under the cursor. Use the arrow keys to select one, and Enter or Tab to accept it. Escape closes the popup until the word changes. Clicking a suggestion also accepts it.
Keyboard focus stays in the TextEdit the whole time.
The popup starts intercepting keys the frame after it opens,
so an accept key pressed in the same frame as the popup appears goes to the TextEdit.
let commands = ["/help", "/clear", "/quit"];
let output = egui::CompletionPopup::new(ui.make_persistent_id("prompt")).show(
ui,
egui::TextEdit::singleline(&mut text).hint_text("Type / for commands"),
|query| {
if !query.is_at_start() {
return vec![];
}
commands
.iter()
.filter(|command| command.starts_with(query.word))
.map(|command| egui::Suggestion::new(format!("{command} ")))
.collect()
},
);
if let Some(accepted) = output.accepted {
println!("Accepted {}", accepted.insert);
}Implementations§
Source§impl<'a> CompletionPopup<'a>
impl<'a> CompletionPopup<'a>
Sourcepub const CLASS_SUGGESTION: ClassName
pub const CLASS_SUGGESTION: ClassName
Present on every suggestion button in the popup, so they can be styled.
Sourcepub fn new(id: Id) -> CompletionPopup<'a>
pub fn new(id: Id) -> CompletionPopup<'a>
The id is given to the TextEdit, and is also used to store the popup state.
It must be unique, so if you show several completion popups (e.g. one per tab),
use e.g. Ui::make_persistent_id rather than a constant Id.
Sourcepub fn word_boundary(
self,
is_word_boundary: impl Fn(char) -> bool + 'a,
) -> CompletionPopup<'a>
pub fn word_boundary( self, is_word_boundary: impl Fn(char) -> bool + 'a, ) -> CompletionPopup<'a>
Which characters separate words? The current word is the text between the last such character and the cursor.
Default: char::is_whitespace.
Sourcepub fn align(self, align: RectAlign) -> CompletionPopup<'a>
pub fn align(self, align: RectAlign) -> CompletionPopup<'a>
Where to place the popup relative to the TextEdit.
If there is no room, the vertically flipped alignment is used instead.
Default: RectAlign::TOP_START.
Sourcepub fn max_height(self, max_height: f32) -> CompletionPopup<'a>
pub fn max_height(self, max_height: f32) -> CompletionPopup<'a>
Maximum height of the popup before it starts to scroll.
Default: 200.0.
Sourcepub fn accept_keys(
self,
accept_keys: impl Into<Vec<Key>>,
) -> CompletionPopup<'a>
pub fn accept_keys( self, accept_keys: impl Into<Vec<Key>>, ) -> CompletionPopup<'a>
Which keys accept the selected suggestion?
Default: Enter and Tab.
Sourcepub fn show(
self,
ui: &mut Ui,
text_edit: TextEdit<'_>,
suggest: impl FnOnce(&CompletionQuery<'_>) -> Vec<Suggestion>,
) -> CompletionOutput
pub fn show( self, ui: &mut Ui, text_edit: TextEdit<'_>, suggest: impl FnOnce(&CompletionQuery<'_>) -> Vec<Suggestion>, ) -> CompletionOutput
Show the TextEdit and, when suggest returns anything for the word under the cursor, the popup.
The TextEdit is given the Id of this popup.
Its TextEdit::event_filter is respected, except that Tab and Escape
are also captured while the popup is open.
suggest is called once per frame, after the TextEdit has handled input.
Auto Trait Implementations§
impl<'a> !RefUnwindSafe for CompletionPopup<'a>
impl<'a> !Send for CompletionPopup<'a>
impl<'a> !Sync for CompletionPopup<'a>
impl<'a> !UnwindSafe for CompletionPopup<'a>
impl<'a> Forget for CompletionPopup<'a>
impl<'a> Freeze for CompletionPopup<'a>
impl<'a> Move for CompletionPopup<'a>
impl<'a> Unpin for CompletionPopup<'a>
impl<'a> UnsafeUnpin for CompletionPopup<'a>where
NonZeroU64Inner: UnsafeUnpin,
*const dyn Fn(char) -> bool + 'a is !null: UnsafeUnpin,
PhantomData<dyn Fn(char) -> bool + 'a>: UnsafeUnpin,
*const u8 is !null: UnsafeUnpin,
PhantomData<Key>: UnsafeUnpin,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more