-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TextEdit autocompletion example #777
Conversation
I implemented the bare features to showcase what I want to achieve. Here is a video of how it looks like, and it's available to try as a demo. I now welcome feedback on how to integrate this functionality into egui proper. |
2b1aa5c
to
7c5ffdf
Compare
oop seems i've been accidentally spamming this PR from my fork of egui. my apologizes |
7c5ffdf
to
8d78ad0
Compare
As of this point, no modifications to egui are needed for at least basic autocomplete support, thanks to |
I finally got around to test this now - very nice work! There are some issues though - when I press enter to select a word, the suggestion box lingers, and the focus is not returned to the TextEdit. |
yeah, it's kind of messed up, since it went through multiple stages of egui updates. I'll try cleaning it up tomorrow if an autocompletion example is desirable. |
I find it very desirable, and a good starting point for others to continue from. Sorry for taking so long before taking a look at this |
8d78ad0
to
dbe6cfb
Compare
I force pushed a more functional version, and removed the draft status of the PR. |
The functionality is nice, but the code is quite complicated imho. The purpose of most demos and examples is to show "This is how easy doing X is!" and this doesn't feel very simple to be honest :) Perhaps it could be refactored into shorter and more reusable functions? |
I'll try doing some refactoring tomorrow. If you have an idea of how to make it shorter and more reusable, feel free to give input. |
I have decided to adopt a different strategy. Originally, I opened this pull request because changes needed to be made to egui to make a functioning autocomplete popup. This caused this pull request to instead try to add an example for autocompletion. So instead, I'm going to create an egui autocompletion library. Thank you for your patience! |
@crumblingstatue |
Sorry, I haven't had the motivation to finish creating one. |
No worries, Thanks for getting back to me. |
For anyone reading this in the future, I'm extracting the relevant part of the code for setting the cursor position to the end: fn set_cursor_pos(ui: &mut Ui, te_id: Id, char_pos: usize) {
let mut state = TextEdit::load_state(ui.ctx(), te_id).unwrap();
let ccursor = text::CCursor::new(char_pos);
state.set_ccursor_range(Some(text::CCursorRange::one(ccursor)));
TextEdit::store_state(ui.ctx(), te_id, state);
} Which can be used like let input_id = ui.make_persistent_id("cmd_input_id");
TextEdit::singleline(&mut user_input)
.id(input_id)
.ui(ui);
//will set the cursor to the end of user_input
set_cursor_pos(ui, input_id, user_input.chars().count()); |
I'm opening this pull request for experimenting and getting early feedback on how to implement autocompletion for TextEdit.
It adds an autocomplete demo for easy experimentation.
This is very much a heavy work in progress, the only thing I managed to implement so far is setting the cursor to end in a crude way.
Main problems I identified with autocompletion:
I implemented the bare functionality I want for autocomplete to work properly, but I'm looking for feedback and guidance of how to integrate this into egui properly.